diff options
Diffstat (limited to 'roms')
649 files changed, 5639 insertions, 61583 deletions
diff --git a/roms/Makefile b/roms/Makefile index 88b3709d4..7bd125273 100644 --- a/roms/Makefile +++ b/roms/Makefile @@ -1,13 +1,11 @@ vgabios_variants := stdvga cirrus vmware qxl isavga virtio vgabios_targets := $(subst -isavga,,$(patsubst %,vgabios-%.bin,$(vgabios_variants))) -pxerom_variants := e1000 e1000e eepro100 ne2k_pci pcnet rtl8139 virtio vmxnet3 -pxerom_targets := 8086100e 808610d3 80861209 10500940 10222000 10ec8139 1af41000 15ad07b0 +pxerom_variants := e1000 eepro100 ne2k_pci pcnet rtl8139 virtio +pxerom_targets := 8086100e 80861209 10500940 10222000 10ec8139 1af41000 pxe-rom-e1000 efi-rom-e1000 : VID := 8086 pxe-rom-e1000 efi-rom-e1000 : DID := 100e -pxe-rom-e1000e efi-rom-e1000e : VID := 8086 -pxe-rom-e1000e efi-rom-e1000e : DID := 10d3 pxe-rom-eepro100 efi-rom-eepro100 : VID := 8086 pxe-rom-eepro100 efi-rom-eepro100 : DID := 1209 pxe-rom-ne2k_pci efi-rom-ne2k_pci : VID := 1050 @@ -18,8 +16,6 @@ pxe-rom-rtl8139 efi-rom-rtl8139 : VID := 10ec pxe-rom-rtl8139 efi-rom-rtl8139 : DID := 8139 pxe-rom-virtio efi-rom-virtio : VID := 1af4 pxe-rom-virtio efi-rom-virtio : DID := 1000 -pxe-rom-vmxnet3 efi-rom-vmxnet3 : VID := 15ad -pxe-rom-vmxnet3 efi-rom-vmxnet3 : DID := 07b0 # # cross compiler auto detection diff --git a/roms/config.seabios-128k b/roms/config.seabios-128k index 93203af0d..0a9da77a5 100644 --- a/roms/config.seabios-128k +++ b/roms/config.seabios-128k @@ -2,11 +2,9 @@ # need to turn off features (xhci,uas) to make it fit into 128k CONFIG_QEMU=y CONFIG_ROM_SIZE=128 -CONFIG_BOOTSPLASH=n CONFIG_XEN=n CONFIG_USB_OHCI=n CONFIG_USB_XHCI=n CONFIG_USB_UAS=n CONFIG_SDCARD=n CONFIG_TCGBIOS=n -CONFIG_MPT_SCSI=n diff --git a/roms/ipxe/src/Makefile b/roms/ipxe/src/Makefile index 582ffe81c..2a9cc9e8f 100644 --- a/roms/ipxe/src/Makefile +++ b/roms/ipxe/src/Makefile @@ -9,7 +9,6 @@ ASFLAGS := LDFLAGS := HOST_CFLAGS := MAKEDEPS := Makefile -CROSS_COMPILE ?= $(CROSS) ############################################################################### # @@ -53,6 +52,9 @@ EINFO := ./util/einfo GENKEYMAP := ./util/genkeymap.pl DOXYGEN := doxygen LCAB := lcab +BINUTILS_DIR := /usr +BFD_DIR := $(BINUTILS_DIR) +ZLIB_DIR := /usr ############################################################################### # @@ -81,14 +83,6 @@ SRCDIRS += drivers/block SRCDIRS += drivers/nvs SRCDIRS += drivers/bitbash SRCDIRS += drivers/infiniband -SRCDIRS += drivers/infiniband/mlx_utils_flexboot/src -SRCDIRS += drivers/infiniband/mlx_utils/src/public -SRCDIRS += drivers/infiniband/mlx_utils/mlx_lib/mlx_reg_access -SRCDIRS += drivers/infiniband/mlx_utils/mlx_lib/mlx_nvconfig -SRCDIRS += drivers/infiniband/mlx_utils/mlx_lib/mlx_vmac -SRCDIRS += drivers/infiniband/mlx_utils/mlx_lib/mlx_blink_leds -SRCDIRS += drivers/infiniband/mlx_utils/mlx_lib/mlx_link_speed -SRCDIRS += drivers/infiniband/mlx_nodnic/src SRCDIRS += drivers/usb SRCDIRS += interface/pxe interface/efi interface/smbios SRCDIRS += interface/bofm @@ -157,9 +151,6 @@ all : $(ALL) everything : $(Q)$(MAKE) --no-print-directory $(ALL) \ bin/3c509.rom bin/intel.rom bin/intel.mrom \ - bin-x86_64-pcbios/8086100e.mrom bin-x86_64-pcbios/intel.rom \ - bin-x86_64-pcbios/ipxe.usb bin-x86_64-pcbios/ipxe.pxe \ - bin-x86_64-pcbios/undionly.kpxe \ bin-i386-efi/ipxe.efi bin-i386-efi/ipxe.efidrv \ bin-i386-efi/ipxe.efirom \ bin-x86_64-efi/ipxe.efi bin-x86_64-efi/ipxe.efidrv \ diff --git a/roms/ipxe/src/Makefile.efi b/roms/ipxe/src/Makefile.efi deleted file mode 100644 index 151b33186..000000000 --- a/roms/ipxe/src/Makefile.efi +++ /dev/null @@ -1,46 +0,0 @@ -# -*- makefile -*- : Force emacs to use Makefile mode - -# The EFI linker script -# -LDSCRIPT = scripts/efi.lds - -# Retain relocation information for elf2efi -# -LDFLAGS += -q -S - -# Media types. -# -NON_AUTO_MEDIA += efi -NON_AUTO_MEDIA += efidrv -NON_AUTO_MEDIA += drv.efi -NON_AUTO_MEDIA += efirom - -# Include SNP driver in the all-drivers build -# -DRIVERS_net += snp - -# Rules for building EFI files -# -$(BIN)/%.efi : $(BIN)/%.efi.tmp $(ELF2EFI) - $(QM)$(ECHO) " [FINISH] $@" - $(Q)$(ELF2EFI) --subsystem=10 $< $@ - -$(BIN)/%.efidrv : $(BIN)/%.efidrv.tmp $(ELF2EFI) - $(QM)$(ECHO) " [FINISH] $@" - $(Q)$(ELF2EFI) --subsystem=11 $< $@ - -$(BIN)/%.drv.efi : $(BIN)/%.efidrv - $(QM)$(ECHO) " [FINISH] $@" - $(Q)$(CP) $< $@ - -$(BIN)/%.efirom : $(BIN)/%.efidrv $(EFIROM) - $(QM)$(ECHO) " [FINISH] $@" - $(Q)$(EFIROM) -v $(TGT_PCI_VENDOR) -d $(TGT_PCI_DEVICE) $< $@ - -$(BIN)/efidrv.cab : $(BIN)/alldrv.efis # $(ALL_drv.efi) is not yet defined - $(QM)$(ECHO) " [CAB] $@" - $(Q)$(LCAB) -n -q $(ALL_drv.efi) $@ - -$(BIN)/%.usb : $(BIN)/%.efi - $(QM)$(ECHO) " [GENEFIDSK] $@" - $(Q)bash util/genefidsk -o $@ -b $(EFI_BOOT_FILE) $< diff --git a/roms/ipxe/src/Makefile.housekeeping b/roms/ipxe/src/Makefile.housekeeping index ceff81410..03800c8ef 100644 --- a/roms/ipxe/src/Makefile.housekeeping +++ b/roms/ipxe/src/Makefile.housekeeping @@ -491,11 +491,6 @@ LDFLAGS += -static # CFLAGS += -include include/compiler.h -# The section type character (e.g. "@" in "@progbits") varies by -# architecture. -# -CFLAGS += -DASM_TCHAR='$(ASM_TCHAR)' -DASM_TCHAR_OPS='$(ASM_TCHAR_OPS)' - # CFLAGS for specific object types # CFLAGS_c += @@ -739,8 +734,8 @@ $(DBGCOL_LIST) : $(MAKEDEPS) VERYCLEANUP += $(DBGCOL_LIST) DBGCOL_COLOURS := $(subst -, ,$(DBGCOL)) -DBGCOL_MIN := $(firstword $(DBGCOL_COLOURS)) -DBGCOL_MAX := $(lastword $(DBGCOL_COLOURS)) +DBGCOL_MIN := $(word 1,$(DBGCOL_COLOURS)) +DBGCOL_MAX := $(word 2,$(DBGCOL_COLOURS)) debug_DEPS += $(DBGCOL_LIST) @@ -901,7 +896,7 @@ endif # Device ID tables (using IDs from ROM definition file) # define obj_pci_id_asm - .section ".pci_devlist.$(1)", "a", $(ASM_TCHAR)progbits + .section ".pci_devlist.$(1)", "a", @progbits .globl pci_devlist_$(1) pci_devlist_$(1): .short ( 0x$(1) & 0xffff ) @@ -965,13 +960,13 @@ DRIVERS_ipxe = $(DRIVERS_net) $(DRIVERS_infiniband) \ # TGT_DRIVERS : the driver for each element (e.g. "rtl8139 prism2_pci") # TGT_ROM_NAME : the ROM name (e.g. "dfe538") # +CARD_DRIVER = $(firstword $(DRIVER_$(1)) $(1)) TGT_ELEMENTS = $(subst --, ,$(firstword $(subst ., ,$(notdir $@)))) TGT_ROM_NAME = $(firstword $(TGT_ELEMENTS)) -TGT_DRIVERS = $(strip $(foreach TGT_ELEMENT,$(TGT_ELEMENTS), \ - $(if $(DRIVERS_$(TGT_ELEMENT)), \ - $(DRIVERS_$(TGT_ELEMENT)), \ - $(firstword $(DRIVER_$(TGT_ELEMENT)) \ - $(TGT_ELEMENT))))) +TGT_DRIVERS = $(strip $(if $(DRIVERS_$(TGT_ROM_NAME)), \ + $(DRIVERS_$(TGT_ROM_NAME)), \ + $(foreach TGT_ELEMENT,$(TGT_ELEMENTS), \ + $(call CARD_DRIVER,$(TGT_ELEMENT))) )) TGT_PREFIX_NAME = $(word 2,$(subst ., ,$(notdir $@))) TGT_PREFIX = $(strip $(if $(filter rom,$(TGT_PREFIX_NAME)), \ $(ROM_TYPE_$(TGT_ROM_NAME))rom, \ @@ -1010,7 +1005,7 @@ TGT_LD_ENTRY = _$(TGT_PREFIX)_start # --defsym pci_vendor=0x1186 --defsym pci_device=0x1300") # TGT_LD_FLAGS = $(foreach SYM,$(TGT_LD_ENTRY) $(TGT_LD_DRIVERS) \ - $(TGT_LD_DEVLIST) obj_config obj_config_$(PLATFORM),\ + $(TGT_LD_DEVLIST) obj_config,\ -u $(SYM) --defsym check_$(SYM)=$(SYM) ) \ $(patsubst %,--defsym %,$(TGT_LD_IDS)) \ -e $(TGT_LD_ENTRY) @@ -1303,15 +1298,21 @@ CLEANUP += $(ZBIN) # # The EFI image converter # +ELF2EFI_CFLAGS := -I$(BINUTILS_DIR)/include -I$(BFD_DIR)/include \ + -I$(ZLIB_DIR)/include -idirafter include +ELF2EFI_LDFLAGS := -L$(BINUTILS_DIR)/lib -L$(BFD_DIR)/lib -L$(ZLIB_DIR)/lib \ + -lbfd -ldl -liberty -lz -Wl,--no-warn-search-mismatch $(ELF2EFI32) : util/elf2efi.c $(MAKEDEPS) $(QM)$(ECHO) " [HOSTCC] $@" - $(Q)$(HOST_CC) $(HOST_CFLAGS) -idirafter include -DEFI_TARGET32 $< -o $@ + $(Q)$(HOST_CC) $(HOST_CFLAGS) $(ELF2EFI_CFLAGS) -DEFI_TARGET_IA32 $< \ + $(ELF2EFI_LDFLAGS) -o $@ CLEANUP += $(ELF2EFI32) $(ELF2EFI64) : util/elf2efi.c $(MAKEDEPS) $(QM)$(ECHO) " [HOSTCC] $@" - $(Q)$(HOST_CC) $(HOST_CFLAGS) -idirafter include -DEFI_TARGET64 $< -o $@ + $(Q)$(HOST_CC) $(HOST_CFLAGS) $(ELF2EFI_CFLAGS) -DEFI_TARGET_X64 $< \ + $(ELF2EFI_LDFLAGS) -o $@ CLEANUP += $(ELF2EFI64) $(EFIROM) : util/efirom.c $(MAKEDEPS) diff --git a/roms/ipxe/src/arch/arm/Makefile b/roms/ipxe/src/arch/arm/Makefile deleted file mode 100644 index 3cee5f3ac..000000000 --- a/roms/ipxe/src/arch/arm/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# Assembler section type character -# -ASM_TCHAR := % -ASM_TCHAR_OPS := %% - -# Include common ARM headers -# -INCDIRS += arch/arm/include - -# ARM-specific directories containing source files -# -SRCDIRS += arch/arm/interface/efi diff --git a/roms/ipxe/src/arch/arm/Makefile.efi b/roms/ipxe/src/arch/arm/Makefile.efi deleted file mode 100644 index f04be425b..000000000 --- a/roms/ipxe/src/arch/arm/Makefile.efi +++ /dev/null @@ -1,6 +0,0 @@ -# -*- makefile -*- : Force emacs to use Makefile mode - -# Include generic EFI Makefile -# -MAKEDEPS += Makefile.efi -include Makefile.efi diff --git a/roms/ipxe/src/arch/arm/core/arm_io.c b/roms/ipxe/src/arch/arm/core/arm_io.c deleted file mode 100644 index 1ef571fc1..000000000 --- a/roms/ipxe/src/arch/arm/core/arm_io.c +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (C) 2016 Michael Brown <mbrown@fensystems.co.uk>. - * - * 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 <ipxe/io.h> -#include <ipxe/arm_io.h> - -/** @file - * - * iPXE I/O API for ARM - * - */ - -/** An ARM I/O qword */ -union arm32_io_qword { - uint64_t qword; - uint32_t dword[2]; -}; - -/** - * Read 64-bit qword from memory-mapped device - * - * @v io_addr I/O address - * @ret data Value read - * - * This is not atomic for ARM32. - */ -static 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; - - tmp.dword[0] = readl ( &ptr->dword[0] ); - tmp.dword[1] = readl ( &ptr->dword[1] ); - return tmp.qword; -} - -/** - * Write 64-bit qword to memory-mapped device - * - * @v data Value to write - * @v io_addr I/O address - * - * This is not atomic for ARM32. - */ -static 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; - - tmp.qword = data; - writel ( tmp.dword[0], &ptr->dword[0] ); - writel ( tmp.dword[1], &ptr->dword[1] ); -} - -PROVIDE_IOAPI_INLINE ( arm, phys_to_bus ); -PROVIDE_IOAPI_INLINE ( arm, bus_to_phys ); -PROVIDE_IOAPI_INLINE ( arm, readb ); -PROVIDE_IOAPI_INLINE ( arm, readw ); -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 ); -PROVIDE_IOAPI_INLINE ( arm, writeq ); -#else -PROVIDE_IOAPI ( arm, readq, arm32_readq ); -PROVIDE_IOAPI ( arm, writeq, arm32_writeq ); -#endif diff --git a/roms/ipxe/src/arch/arm/include/bits/endian.h b/roms/ipxe/src/arch/arm/include/bits/endian.h deleted file mode 100644 index 4506711ad..000000000 --- a/roms/ipxe/src/arch/arm/include/bits/endian.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef _BITS_ENDIAN_H -#define _BITS_ENDIAN_H - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -/* ARM may be either little-endian or big-endian */ -#ifdef __ARM_BIG_ENDIAN -#define __BYTE_ORDER __BIG_ENDIAN -#else -#define __BYTE_ORDER __LITTLE_ENDIAN -#endif - -#endif /* _BITS_ENDIAN_H */ diff --git a/roms/ipxe/src/arch/arm/include/bits/errfile.h b/roms/ipxe/src/arch/arm/include/bits/errfile.h deleted file mode 100644 index 65f7f719b..000000000 --- a/roms/ipxe/src/arch/arm/include/bits/errfile.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef _BITS_ERRFILE_H -#define _BITS_ERRFILE_H - -/** @file - * - * ARM-specific error file identifiers - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -/** - * @addtogroup errfile Error file identifiers - * @{ - */ - -/** @} */ - -#endif /* _BITS_ERRFILE_H */ diff --git a/roms/ipxe/src/arch/arm/include/bits/hyperv.h b/roms/ipxe/src/arch/arm/include/bits/hyperv.h deleted file mode 100644 index f0e0c8793..000000000 --- a/roms/ipxe/src/arch/arm/include/bits/hyperv.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _BITS_HYPERV_H -#define _BITS_HYPERV_H - -/** @file - * - * Hyper-V interface - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#endif /* _BITS_HYPERV_H */ diff --git a/roms/ipxe/src/arch/arm/include/bits/io.h b/roms/ipxe/src/arch/arm/include/bits/io.h deleted file mode 100644 index 90f6455ec..000000000 --- a/roms/ipxe/src/arch/arm/include/bits/io.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef _BITS_IO_H -#define _BITS_IO_H - -/** @file - * - * ARM-specific I/O API implementations - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#include <ipxe/arm_io.h> - -#endif /* _BITS_IO_H */ diff --git a/roms/ipxe/src/arch/arm/include/bits/iomap.h b/roms/ipxe/src/arch/arm/include/bits/iomap.h deleted file mode 100644 index ae953c450..000000000 --- a/roms/ipxe/src/arch/arm/include/bits/iomap.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _BITS_IOMAP_H -#define _BITS_IOMAP_H - -/** @file - * - * ARM-specific I/O mapping API implementations - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#endif /* _BITS_IOMAP_H */ diff --git a/roms/ipxe/src/arch/arm/include/bits/nap.h b/roms/ipxe/src/arch/arm/include/bits/nap.h deleted file mode 100644 index e30a7146b..000000000 --- a/roms/ipxe/src/arch/arm/include/bits/nap.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef _BITS_NAP_H -#define _BITS_NAP_H - -/** @file - * - * ARM-specific CPU sleeping API implementations - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#include <ipxe/efi/efiarm_nap.h> - -#endif /* _BITS_MAP_H */ diff --git a/roms/ipxe/src/arch/arm/include/bits/pci_io.h b/roms/ipxe/src/arch/arm/include/bits/pci_io.h deleted file mode 100644 index fba0eb979..000000000 --- a/roms/ipxe/src/arch/arm/include/bits/pci_io.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef _BITS_PCI_IO_H -#define _BITS_PCI_IO_H - -/** @file - * - * ARM PCI I/O API implementations - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#include <ipxe/io.h> - -#endif /* _BITS_PCI_IO_H */ diff --git a/roms/ipxe/src/arch/arm/include/bits/uart.h b/roms/ipxe/src/arch/arm/include/bits/uart.h deleted file mode 100644 index 6f85975f7..000000000 --- a/roms/ipxe/src/arch/arm/include/bits/uart.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _BITS_UART_H -#define _BITS_UART_H - -/** @file - * - * 16550-compatible UART - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#endif /* _BITS_UART_H */ diff --git a/roms/ipxe/src/arch/arm/include/bits/umalloc.h b/roms/ipxe/src/arch/arm/include/bits/umalloc.h deleted file mode 100644 index 27970d7b2..000000000 --- a/roms/ipxe/src/arch/arm/include/bits/umalloc.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _BITS_UMALLOC_H -#define _BITS_UMALLOC_H - -/** @file - * - * ARM-specific user memory allocation API implementations - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#endif /* _BITS_UMALLOC_H */ diff --git a/roms/ipxe/src/arch/arm/include/bits/xen.h b/roms/ipxe/src/arch/arm/include/bits/xen.h deleted file mode 100644 index 34f647903..000000000 --- a/roms/ipxe/src/arch/arm/include/bits/xen.h +++ /dev/null @@ -1,158 +0,0 @@ -#ifndef _BITS_XEN_H -#define _BITS_XEN_H - -/** @file - * - * Xen interface - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -/* Hypercall registers */ -#ifdef __aarch64__ -#define XEN_HC "x16" -#define XEN_REG1 "x0" -#define XEN_REG2 "x1" -#define XEN_REG3 "x2" -#define XEN_REG4 "x3" -#define XEN_REG5 "x4" -#else -#define XEN_HC "r12" -#define XEN_REG1 "r0" -#define XEN_REG2 "r1" -#define XEN_REG3 "r2" -#define XEN_REG4 "r3" -#define XEN_REG5 "r4" -#endif - -/** - * Issue hypercall with one argument - * - * @v xen Xen hypervisor - * @v hypercall Hypercall number - * @v arg1 First argument - * @ret retval Return value - */ -static inline __attribute__ (( always_inline )) unsigned long -xen_hypercall_1 ( struct xen_hypervisor *xen __unused, unsigned int hypercall, - unsigned long arg1 ) { - register unsigned long hc asm ( XEN_HC ) = hypercall; - register unsigned long reg1 asm ( XEN_REG1 ) = arg1; - - __asm__ __volatile__ ( "hvc %1" - : "+r" ( reg1 ) - : "i" ( XEN_HYPERCALL_TAG ), "r" ( hc ) - : "memory", "cc" ); - return reg1; -} - -/** - * Issue hypercall with two arguments - * - * @v xen Xen hypervisor - * @v hypercall Hypercall number - * @v arg1 First argument - * @v arg2 Second argument - * @ret retval Return value - */ -static inline __attribute__ (( always_inline )) unsigned long -xen_hypercall_2 ( struct xen_hypervisor *xen __unused, unsigned int hypercall, - unsigned long arg1, unsigned long arg2 ) { - register unsigned long hc asm ( XEN_HC ) = hypercall; - register unsigned long reg1 asm ( XEN_REG1 ) = arg1; - register unsigned long reg2 asm ( XEN_REG2 ) = arg2; - - __asm__ __volatile__ ( "hvc %2" - : "+r" ( reg1 ), "+r" ( reg2 ) - : "i" ( XEN_HYPERCALL_TAG ), "r" ( hc ) - : "memory", "cc" ); - return reg1; -} - -/** - * Issue hypercall with three arguments - * - * @v xen Xen hypervisor - * @v hypercall Hypercall number - * @v arg1 First argument - * @v arg2 Second argument - * @v arg3 Third argument - * @ret retval Return value - */ -static inline __attribute__ (( always_inline )) unsigned long -xen_hypercall_3 ( struct xen_hypervisor *xen __unused, unsigned int hypercall, - unsigned long arg1, unsigned long arg2, unsigned long arg3 ) { - register unsigned long hc asm ( XEN_HC ) = hypercall; - register unsigned long reg1 asm ( XEN_REG1 ) = arg1; - register unsigned long reg2 asm ( XEN_REG2 ) = arg2; - register unsigned long reg3 asm ( XEN_REG3 ) = arg3; - - __asm__ __volatile__ ( "hvc %3" - : "+r" ( reg1 ), "+r" ( reg2 ), "+r" ( reg3 ) - : "i" ( XEN_HYPERCALL_TAG ), "r" ( hc ) - : "memory", "cc" ); - return reg1; -} - -/** - * Issue hypercall with four arguments - * - * @v xen Xen hypervisor - * @v hypercall Hypercall number - * @v arg1 First argument - * @v arg2 Second argument - * @v arg3 Third argument - * @v arg4 Fourth argument - * @ret retval Return value - */ -static inline __attribute__ (( always_inline )) unsigned long -xen_hypercall_4 ( struct xen_hypervisor *xen __unused, unsigned int hypercall, - unsigned long arg1, unsigned long arg2, unsigned long arg3, - unsigned long arg4 ) { - register unsigned long hc asm ( XEN_HC ) = hypercall; - register unsigned long reg1 asm ( XEN_REG1 ) = arg1; - register unsigned long reg2 asm ( XEN_REG2 ) = arg2; - register unsigned long reg3 asm ( XEN_REG3 ) = arg3; - register unsigned long reg4 asm ( XEN_REG4 ) = arg4; - - __asm__ __volatile__ ( "hvc %4" - : "+r" ( reg1 ), "+r" ( reg2 ), "+r" ( reg3 ), - "+r" ( reg4 ) - : "i" ( XEN_HYPERCALL_TAG ), "r" ( hc ) - : "memory", "cc" ); - return reg1; -} - -/** - * Issue hypercall with five arguments - * - * @v xen Xen hypervisor - * @v hypercall Hypercall number - * @v arg1 First argument - * @v arg2 Second argument - * @v arg3 Third argument - * @v arg4 Fourth argument - * @v arg5 Fifth argument - * @ret retval Return value - */ -static inline __attribute__ (( always_inline )) unsigned long -xen_hypercall_5 ( struct xen_hypervisor *xen __unused, unsigned int hypercall, - unsigned long arg1, unsigned long arg2, unsigned long arg3, - unsigned long arg4, unsigned long arg5 ) { - register unsigned long hc asm ( XEN_HC ) = hypercall; - register unsigned long reg1 asm ( XEN_REG1 ) = arg1; - register unsigned long reg2 asm ( XEN_REG2 ) = arg2; - register unsigned long reg3 asm ( XEN_REG3 ) = arg3; - register unsigned long reg4 asm ( XEN_REG4 ) = arg4; - register unsigned long reg5 asm ( XEN_REG5 ) = arg5; - - __asm__ __volatile__ ( "hvc %5" - : "+r" ( reg1 ), "+r" ( reg2 ), "+r" ( reg3 ), - "+r" ( reg4 ), "+r" ( reg5 ) - : "i" ( XEN_HYPERCALL_TAG ), "r" ( hc ) - : "memory", "cc" ); - return reg1; -} - -#endif /* _BITS_XEN_H */ diff --git a/roms/ipxe/src/arch/arm/include/ipxe/arm_io.h b/roms/ipxe/src/arch/arm/include/ipxe/arm_io.h deleted file mode 100644 index f8765af75..000000000 --- a/roms/ipxe/src/arch/arm/include/ipxe/arm_io.h +++ /dev/null @@ -1,105 +0,0 @@ -#ifndef _IPXE_ARM_IO_H -#define _IPXE_ARM_IO_H - -/** @file - * - * iPXE I/O API for ARM - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#ifdef IOAPI_ARM -#define IOAPI_PREFIX_arm -#else -#define IOAPI_PREFIX_arm __arm_ -#endif - -/* - * Memory space mappings - * - */ - -/** Page shift */ -#define PAGE_SHIFT 12 - -/* - * Physical<->Bus address mappings - * - */ - -static inline __always_inline unsigned long -IOAPI_INLINE ( arm, phys_to_bus ) ( unsigned long phys_addr ) { - return phys_addr; -} - -static inline __always_inline unsigned long -IOAPI_INLINE ( arm, bus_to_phys ) ( unsigned long bus_addr ) { - return bus_addr; -} - -/* - * MMIO reads and writes up to native word size - * - */ - -#define ARM_READX( _api_func, _type, _insn_suffix, _reg_prefix ) \ -static inline __always_inline _type \ -IOAPI_INLINE ( arm, _api_func ) ( volatile _type *io_addr ) { \ - _type data; \ - __asm__ __volatile__ ( "ldr" _insn_suffix " %" _reg_prefix "0, %1" \ - : "=r" ( data ) : "Qo" ( *io_addr ) ); \ - return data; \ -} -#ifdef __aarch64__ -ARM_READX ( readb, uint8_t, "b", "w" ); -ARM_READX ( readw, uint16_t, "h", "w" ); -ARM_READX ( readl, uint32_t, "", "w" ); -ARM_READX ( readq, uint64_t, "", "" ); -#else -ARM_READX ( readb, uint8_t, "b", "" ); -ARM_READX ( readw, uint16_t, "h", "" ); -ARM_READX ( readl, uint32_t, "", "" ); -#endif - -#define ARM_WRITEX( _api_func, _type, _insn_suffix, _reg_prefix ) \ -static inline __always_inline void \ -IOAPI_INLINE ( arm, _api_func ) ( _type data, volatile _type *io_addr ) { \ - __asm__ __volatile__ ( "str" _insn_suffix " %" _reg_prefix "0, %1" \ - : : "r" ( data ), "Qo" ( *io_addr ) ); \ -} -#ifdef __aarch64__ -ARM_WRITEX ( writeb, uint8_t, "b", "w" ); -ARM_WRITEX ( writew, uint16_t, "h", "w" ); -ARM_WRITEX ( writel, uint32_t, "", "w" ); -ARM_WRITEX ( writeq, uint64_t, "", "" ); -#else -ARM_WRITEX ( writeb, uint8_t, "b", "" ); -ARM_WRITEX ( writew, uint16_t, "h", "" ); -ARM_WRITEX ( writel, uint32_t, "", "" ); -#endif - -/* - * Slow down I/O - * - */ -static inline __always_inline void -IOAPI_INLINE ( arm, iodelay ) ( void ) { - /* Nothing to do */ -} - -/* - * Memory barrier - * - */ -static inline __always_inline void -IOAPI_INLINE ( arm, mb ) ( void ) { - -#ifdef __aarch64__ - __asm__ __volatile__ ( "dmb sy" ); -#else - __asm__ __volatile__ ( "dmb" ); -#endif -} - -#endif /* _IPXE_ARM_IO_H */ diff --git a/roms/ipxe/src/arch/arm/include/ipxe/efi/efiarm_nap.h b/roms/ipxe/src/arch/arm/include/ipxe/efi/efiarm_nap.h deleted file mode 100644 index dcbdd3e20..000000000 --- a/roms/ipxe/src/arch/arm/include/ipxe/efi/efiarm_nap.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef _IPXE_EFIARM_NAP_H -#define _IPXE_EFIARM_NAP_H - -/** @file - * - * EFI CPU sleeping - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#ifdef NAP_EFIARM -#define NAP_PREFIX_efiarm -#else -#define NAP_PREFIX_efiarm __efiarm_ -#endif - -#endif /* _IPXE_EFIARM_NAP_H */ diff --git a/roms/ipxe/src/arch/arm/interface/efi/efiarm_nap.c b/roms/ipxe/src/arch/arm/interface/efi/efiarm_nap.c deleted file mode 100644 index 9ed638e9a..000000000 --- a/roms/ipxe/src/arch/arm/interface/efi/efiarm_nap.c +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2016 Michael Brown <mbrown@fensystems.co.uk>. - * - * 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 <ipxe/nap.h> -#include <ipxe/efi/efi.h> - -/** @file - * - * iPXE CPU sleeping API for EFI - * - */ - -/** - * Sleep until next interrupt - * - */ -static void efiarm_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__ ( "wfi" ); -} - -PROVIDE_NAP ( efiarm, cpu_nap, efiarm_cpu_nap ); diff --git a/roms/ipxe/src/arch/arm32/Makefile b/roms/ipxe/src/arch/arm32/Makefile deleted file mode 100644 index 3a7c09230..000000000 --- a/roms/ipxe/src/arch/arm32/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -# ARM32-specific directories containing source files -# -SRCDIRS += arch/arm32/core -SRCDIRS += arch/arm32/libgcc - -# ARM32-specific flags -# -CFLAGS += -mthumb -mcpu=cortex-a15 -mabi=aapcs -mfloat-abi=soft -CFLAGS += -mword-relocations -ASFLAGS += -mthumb -mcpu=cortex-a15 - -# EFI requires -fshort-wchar, and nothing else currently uses wchar_t -# -CFLAGS += -fshort-wchar - -# Include common ARM Makefile -MAKEDEPS += arch/arm/Makefile -include arch/arm/Makefile - -# Include platform-specific Makefile -# -MAKEDEPS += arch/arm32/Makefile.$(PLATFORM) -include arch/arm32/Makefile.$(PLATFORM) diff --git a/roms/ipxe/src/arch/arm32/Makefile.efi b/roms/ipxe/src/arch/arm32/Makefile.efi deleted file mode 100644 index a06354f1d..000000000 --- a/roms/ipxe/src/arch/arm32/Makefile.efi +++ /dev/null @@ -1,14 +0,0 @@ -# -*- makefile -*- : Force emacs to use Makefile mode - -# Specify EFI image builder -# -ELF2EFI = $(ELF2EFI32) - -# Specify EFI boot file -# -EFI_BOOT_FILE = bootarm.efi - -# Include generic EFI Makefile -# -MAKEDEPS += arch/arm/Makefile.efi -include arch/arm/Makefile.efi diff --git a/roms/ipxe/src/arch/arm32/core/arm32_bigint.c b/roms/ipxe/src/arch/arm32/core/arm32_bigint.c deleted file mode 100644 index 839bead18..000000000 --- a/roms/ipxe/src/arch/arm32/core/arm32_bigint.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (C) 2016 Michael Brown <mbrown@fensystems.co.uk>. - * - * 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 <stdint.h> -#include <string.h> -#include <ipxe/bigint.h> - -/** @file - * - * Big integer support - */ - -/** - * Multiply big integers - * - * @v multiplicand0 Element 0 of big integer to be multiplied - * @v multiplier0 Element 0 of big integer to be multiplied - * @v result0 Element 0 of big integer to hold result - * @v size Number of elements - */ -void bigint_multiply_raw ( const uint32_t *multiplicand0, - const uint32_t *multiplier0, - uint32_t *result0, unsigned int size ) { - const bigint_t ( size ) __attribute__ (( may_alias )) *multiplicand = - ( ( const void * ) multiplicand0 ); - const bigint_t ( size ) __attribute__ (( may_alias )) *multiplier = - ( ( const void * ) multiplier0 ); - bigint_t ( size * 2 ) __attribute__ (( may_alias )) *result = - ( ( void * ) result0 ); - unsigned int i; - unsigned int j; - uint32_t multiplicand_element; - uint32_t multiplier_element; - uint32_t *result_elements; - uint32_t discard_low; - uint32_t discard_high; - uint32_t discard_temp; - - /* Zero result */ - memset ( result, 0, sizeof ( *result ) ); - - /* Multiply integers one element at a time */ - for ( i = 0 ; i < size ; i++ ) { - multiplicand_element = multiplicand->element[i]; - for ( j = 0 ; j < size ; j++ ) { - multiplier_element = multiplier->element[j]; - result_elements = &result->element[ i + j ]; - /* Perform a single multiply, and add the - * resulting double-element into the result, - * carrying as necessary. The carry can - * never overflow beyond the end of the - * result, since: - * - * a < 2^{n}, b < 2^{n} => ab < 2^{2n} - */ - __asm__ __volatile__ ( "umull %1, %2, %5, %6\n\t" - "ldr %3, [%0]\n\t" - "adds %3, %1\n\t" - "stmia %0!, {%3}\n\t" - "ldr %3, [%0]\n\t" - "adcs %3, %2\n\t" - "stmia %0!, {%3}\n\t" - "bcc 2f\n\t" - "\n1:\n\t" - "ldr %3, [%0]\n\t" - "adcs %3, #0\n\t" - "stmia %0!, {%3}\n\t" - "bcs 1b\n\t" - "\n2:\n\t" - : "+l" ( result_elements ), - "=l" ( discard_low ), - "=l" ( discard_high ), - "=l" ( discard_temp ), - "+m" ( *result ) - : "l" ( multiplicand_element ), - "l" ( multiplier_element ) - : "cc" ); - } - } -} diff --git a/roms/ipxe/src/arch/arm32/core/setjmp.S b/roms/ipxe/src/arch/arm32/core/setjmp.S deleted file mode 100644 index 7e7b0fe58..000000000 --- a/roms/ipxe/src/arch/arm32/core/setjmp.S +++ /dev/null @@ -1,32 +0,0 @@ -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) - - .text - .arm - -/* - * Save stack context for non-local goto - */ - .globl setjmp - .type setjmp, %function -setjmp: - /* Store registers */ - stmia r0, { r4, r5, r6, r7, r8, r9, r10, fp, sp, lr } - /* Return 0 when returning as setjmp() */ - mov r0, #0 - bx lr - .size setjmp, . - setjmp - -/* - * Non-local jump to a saved stack context - */ - .globl longjmp - .type longjmp, %function -longjmp: - /* Restore registers */ - ldmia r0, { r4, r5, r6, r7, r8, r9, r10, fp, sp, lr } - /* Force result to non-zero */ - movs r0, r1 - moveq r0, #1 - /* Return to setjmp() caller */ - bx lr - .size longjmp, . - longjmp diff --git a/roms/ipxe/src/arch/arm32/include/bits/bigint.h b/roms/ipxe/src/arch/arm32/include/bits/bigint.h deleted file mode 100644 index 103c6c489..000000000 --- a/roms/ipxe/src/arch/arm32/include/bits/bigint.h +++ /dev/null @@ -1,316 +0,0 @@ -#ifndef _BITS_BIGINT_H -#define _BITS_BIGINT_H - -/** @file - * - * Big integer support - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#include <stdint.h> -#include <string.h> -#include <strings.h> - -/** Element of a big integer */ -typedef uint32_t bigint_element_t; - -/** - * Initialise big integer - * - * @v value0 Element 0 of big integer to initialise - * @v size Number of elements - * @v data Raw data - * @v len Length of raw data - */ -static inline __attribute__ (( always_inline )) void -bigint_init_raw ( uint32_t *value0, unsigned int size, - const void *data, size_t len ) { - size_t pad_len = ( sizeof ( bigint_t ( size ) ) - len ); - uint8_t *value_byte = ( ( void * ) value0 ); - const uint8_t *data_byte = ( data + len ); - - /* Copy raw data in reverse order, padding with zeros */ - while ( len-- ) - *(value_byte++) = *(--data_byte); - while ( pad_len-- ) - *(value_byte++) = 0; -} - -/** - * Add big integers - * - * @v addend0 Element 0 of big integer to add - * @v value0 Element 0 of big integer to be added to - * @v size Number of elements - */ -static inline __attribute__ (( always_inline )) void -bigint_add_raw ( const uint32_t *addend0, uint32_t *value0, - unsigned int size ) { - bigint_t ( size ) __attribute__ (( may_alias )) *value = - ( ( void * ) value0 ); - uint32_t *discard_addend; - uint32_t *discard_value; - uint32_t *discard_end; - uint32_t discard_addend_i; - uint32_t discard_value_i; - - __asm__ __volatile__ ( "adds %2, %0, %8, lsl #2\n\t" /* clear CF */ - "\n1:\n\t" - "ldmia %0!, {%3}\n\t" - "ldr %4, [%1]\n\t" - "adcs %4, %3\n\t" - "stmia %1!, {%4}\n\t" - "teq %0, %2\n\t" - "bne 1b\n\t" - : "=l" ( discard_addend ), - "=l" ( discard_value ), - "=l" ( discard_end ), - "=l" ( discard_addend_i ), - "=l" ( discard_value_i ), - "+m" ( *value ) - : "0" ( addend0 ), "1" ( value0 ), "l" ( size ) - : "cc" ); -} - -/** - * Subtract big integers - * - * @v subtrahend0 Element 0 of big integer to subtract - * @v value0 Element 0 of big integer to be subtracted from - * @v size Number of elements - */ -static inline __attribute__ (( always_inline )) void -bigint_subtract_raw ( const uint32_t *subtrahend0, uint32_t *value0, - unsigned int size ) { - bigint_t ( size ) __attribute__ (( may_alias )) *value = - ( ( void * ) value0 ); - uint32_t *discard_subtrahend; - uint32_t *discard_value; - uint32_t *discard_end; - uint32_t discard_subtrahend_i; - uint32_t discard_value_i; - - __asm__ __volatile__ ( "add %2, %0, %8, lsl #2\n\t" - "cmp %2, %0\n\t" /* set CF */ - "\n1:\n\t" - "ldmia %0!, {%3}\n\t" - "ldr %4, [%1]\n\t" - "sbcs %4, %3\n\t" - "stmia %1!, {%4}\n\t" - "teq %0, %2\n\t" - "bne 1b\n\t" - : "=l" ( discard_subtrahend ), - "=l" ( discard_value ), - "=l" ( discard_end ), - "=l" ( discard_subtrahend_i ), - "=l" ( discard_value_i ), - "+m" ( *value ) - : "0" ( subtrahend0 ), "1" ( value0 ), - "l" ( size ) - : "cc" ); -} - -/** - * Rotate big integer left - * - * @v value0 Element 0 of big integer - * @v size Number of elements - */ -static inline __attribute__ (( always_inline )) void -bigint_rol_raw ( uint32_t *value0, unsigned int size ) { - bigint_t ( size ) __attribute__ (( may_alias )) *value = - ( ( void * ) value0 ); - uint32_t *discard_value; - uint32_t *discard_end; - uint32_t discard_value_i; - - __asm__ __volatile__ ( "adds %1, %0, %5, lsl #2\n\t" /* clear CF */ - "\n1:\n\t" - "ldr %2, [%0]\n\t" - "adcs %2, %2\n\t" - "stmia %0!, {%2}\n\t" - "teq %0, %1\n\t" - "bne 1b\n\t" - : "=l" ( discard_value ), - "=l" ( discard_end ), - "=l" ( discard_value_i ), - "+m" ( *value ) - : "0" ( value0 ), "1" ( size ) - : "cc" ); -} - -/** - * Rotate big integer right - * - * @v value0 Element 0 of big integer - * @v size Number of elements - */ -static inline __attribute__ (( always_inline )) void -bigint_ror_raw ( uint32_t *value0, unsigned int size ) { - bigint_t ( size ) __attribute__ (( may_alias )) *value = - ( ( void * ) value0 ); - uint32_t *discard_value; - uint32_t *discard_end; - uint32_t discard_value_i; - - __asm__ __volatile__ ( "adds %1, %0, %5, lsl #2\n\t" /* clear CF */ - "\n1:\n\t" - "ldmdb %1!, {%2}\n\t" - "rrxs %2, %2\n\t" - "str %2, [%1]\n\t" - "teq %0, %1\n\t" - "bne 1b\n\t" - : "=l" ( discard_value ), - "=l" ( discard_end ), - "=l" ( discard_value_i ), - "+m" ( *value ) - : "0" ( value0 ), "1" ( size ) - : "cc" ); -} - -/** - * Test if big integer is equal to zero - * - * @v value0 Element 0 of big integer - * @v size Number of elements - * @ret is_zero Big integer is equal to zero - */ -static inline __attribute__ (( always_inline, pure )) int -bigint_is_zero_raw ( const uint32_t *value0, unsigned int size ) { - const uint32_t *value = value0; - uint32_t value_i; - - do { - value_i = *(value++); - if ( value_i ) - break; - } while ( --size ); - - return ( value_i == 0 ); -} - -/** - * Compare big integers - * - * @v value0 Element 0 of big integer - * @v reference0 Element 0 of reference big integer - * @v size Number of elements - * @ret geq Big integer is greater than or equal to the reference - */ -static inline __attribute__ (( always_inline, pure )) int -bigint_is_geq_raw ( const uint32_t *value0, const uint32_t *reference0, - unsigned int size ) { - const uint32_t *value = ( value0 + size ); - const uint32_t *reference = ( reference0 + size ); - uint32_t value_i; - uint32_t reference_i; - - do { - value_i = *(--value); - reference_i = *(--reference); - if ( value_i != reference_i ) - break; - } while ( --size ); - - return ( value_i >= reference_i ); -} - -/** - * Test if bit is set in big integer - * - * @v value0 Element 0 of big integer - * @v size Number of elements - * @v bit Bit to test - * @ret is_set Bit is set - */ -static inline __attribute__ (( always_inline )) int -bigint_bit_is_set_raw ( const uint32_t *value0, unsigned int size, - unsigned int bit ) { - const bigint_t ( size ) __attribute__ (( may_alias )) *value = - ( ( const void * ) value0 ); - unsigned int index = ( bit / ( 8 * sizeof ( value->element[0] ) ) ); - unsigned int subindex = ( bit % ( 8 * sizeof ( value->element[0] ) ) ); - - return ( value->element[index] & ( 1 << subindex ) ); -} - -/** - * Find highest bit set in big integer - * - * @v value0 Element 0 of big integer - * @v size Number of elements - * @ret max_bit Highest bit set + 1 (or 0 if no bits set) - */ -static inline __attribute__ (( always_inline )) int -bigint_max_set_bit_raw ( const uint32_t *value0, unsigned int size ) { - const uint32_t *value = ( value0 + size ); - int max_bit = ( 8 * sizeof ( bigint_t ( size ) ) ); - uint32_t value_i; - - do { - value_i = *(--value); - max_bit -= ( 32 - fls ( value_i ) ); - if ( value_i ) - break; - } while ( --size ); - - return max_bit; -} - -/** - * Grow big integer - * - * @v source0 Element 0 of source big integer - * @v source_size Number of elements in source big integer - * @v dest0 Element 0 of destination big integer - * @v dest_size Number of elements in destination big integer - */ -static inline __attribute__ (( always_inline )) void -bigint_grow_raw ( const uint32_t *source0, unsigned int source_size, - uint32_t *dest0, unsigned int dest_size ) { - unsigned int pad_size = ( dest_size - source_size ); - - memcpy ( dest0, source0, sizeof ( bigint_t ( source_size ) ) ); - memset ( ( dest0 + source_size ), 0, sizeof ( bigint_t ( pad_size ) ) ); -} - -/** - * Shrink big integer - * - * @v source0 Element 0 of source big integer - * @v source_size Number of elements in source big integer - * @v dest0 Element 0 of destination big integer - * @v dest_size Number of elements in destination big integer - */ -static inline __attribute__ (( always_inline )) void -bigint_shrink_raw ( const uint32_t *source0, unsigned int source_size __unused, - uint32_t *dest0, unsigned int dest_size ) { - - memcpy ( dest0, source0, sizeof ( bigint_t ( dest_size ) ) ); -} - -/** - * Finalise big integer - * - * @v value0 Element 0 of big integer to finalise - * @v size Number of elements - * @v out Output buffer - * @v len Length of output buffer - */ -static inline __attribute__ (( always_inline )) void -bigint_done_raw ( const uint32_t *value0, unsigned int size __unused, - void *out, size_t len ) { - const uint8_t *value_byte = ( ( const void * ) value0 ); - uint8_t *out_byte = ( out + len ); - - /* Copy raw data in reverse order */ - while ( len-- ) - *(--out_byte) = *(value_byte++); -} - -extern void bigint_multiply_raw ( const uint32_t *multiplicand0, - const uint32_t *multiplier0, - uint32_t *value0, unsigned int size ); - -#endif /* _BITS_BIGINT_H */ diff --git a/roms/ipxe/src/arch/arm32/include/bits/bitops.h b/roms/ipxe/src/arch/arm32/include/bits/bitops.h deleted file mode 100644 index 9a5fe14c2..000000000 --- a/roms/ipxe/src/arch/arm32/include/bits/bitops.h +++ /dev/null @@ -1,100 +0,0 @@ -#ifndef _BITS_BITOPS_H -#define _BITS_BITOPS_H - -/** @file - * - * ARM bit operations - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#include <stdint.h> - -/** - * Test and set bit atomically - * - * @v bit Bit to set - * @v bits Bit field - * @ret old Old value of bit (zero or non-zero) - */ -static inline __attribute__ (( always_inline )) int -test_and_set_bit ( unsigned int bit, volatile void *bits ) { - unsigned int index = ( bit / 32 ); - unsigned int offset = ( bit % 32 ); - volatile uint32_t *dword = ( ( ( volatile uint32_t * ) bits ) + index ); - uint32_t mask = ( 1UL << offset ); - uint32_t old; - uint32_t new; - uint32_t flag; - - __asm__ __volatile__ ( "\n1:\n\t" - "ldrex %0, %3\n\t" - "orr %1, %0, %4\n\t" - "strex %2, %1, %3\n\t" - "tst %2, %2\n\t" - "bne 1b\n\t" - : "=&r" ( old ), "=&r" ( new ), "=&l" ( flag ), - "+Q" ( *dword ) - : "r" ( mask ) - : "cc" ); - - return ( old & mask ); -} - -/** - * Test and clear bit atomically - * - * @v bit Bit to set - * @v bits Bit field - * @ret old Old value of bit (zero or non-zero) - */ -static inline __attribute__ (( always_inline )) int -test_and_clear_bit ( unsigned int bit, volatile void *bits ) { - unsigned int index = ( bit / 32 ); - unsigned int offset = ( bit % 32 ); - volatile uint32_t *dword = ( ( ( volatile uint32_t * ) bits ) + index ); - uint32_t mask = ( 1UL << offset ); - uint32_t old; - uint32_t new; - uint32_t flag; - - __asm__ __volatile__ ( "\n1:\n\t" - "ldrex %0, %3\n\t" - "bic %1, %0, %4\n\t" - "strex %2, %1, %3\n\t" - "tst %2, %2\n\t" - "bne 1b\n\t" - : "=&r" ( old ), "=&r" ( new ), "=&l" ( flag ), - "+Q" ( *dword ) - : "r" ( mask ) - : "cc" ); - - return ( old & mask ); -} - -/** - * Set bit atomically - * - * @v bit Bit to set - * @v bits Bit field - */ -static inline __attribute__ (( always_inline )) void -set_bit ( unsigned int bit, volatile void *bits ) { - - test_and_set_bit ( bit, bits ); -} - -/** - * Clear bit atomically - * - * @v bit Bit to set - * @v bits Bit field - */ -static inline __attribute__ (( always_inline )) void -clear_bit ( unsigned int bit, volatile void *bits ) { - - test_and_clear_bit ( bit, bits ); -} - -#endif /* _BITS_BITOPS_H */ diff --git a/roms/ipxe/src/arch/arm32/include/bits/byteswap.h b/roms/ipxe/src/arch/arm32/include/bits/byteswap.h deleted file mode 100644 index 1fc884bd8..000000000 --- a/roms/ipxe/src/arch/arm32/include/bits/byteswap.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef _BITS_BYTESWAP_H -#define _BITS_BYTESWAP_H - -/** @file - * - * Byte-order swapping functions - * - */ - -#include <stdint.h> - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -static inline __attribute__ (( always_inline, const )) uint16_t -__bswap_variable_16 ( uint16_t x ) { - __asm__ ( "rev16 %0, %1" : "=l" ( x ) : "l" ( x ) ); - return x; -} - -static inline __attribute__ (( always_inline )) void -__bswap_16s ( uint16_t *x ) { - *x = __bswap_variable_16 ( *x ); -} - -static inline __attribute__ (( always_inline, const )) uint32_t -__bswap_variable_32 ( uint32_t x ) { - __asm__ ( "rev %0, %1" : "=l" ( x ) : "l" ( x ) ); - return x; -} - -static inline __attribute__ (( always_inline )) void -__bswap_32s ( uint32_t *x ) { - *x = __bswap_variable_32 ( *x ); -} - -static inline __attribute__ (( always_inline, const )) uint64_t -__bswap_variable_64 ( uint64_t x ) { - uint32_t in_high = ( x >> 32 ); - uint32_t in_low = ( x & 0xffffffffUL ); - uint32_t out_high = __bswap_variable_32 ( in_low ); - uint32_t out_low = __bswap_variable_32 ( in_high ); - - return ( ( ( ( uint64_t ) out_high ) << 32 ) | - ( ( uint64_t ) out_low ) ); -} - -static inline __attribute__ (( always_inline )) void -__bswap_64s ( uint64_t *x ) { - *x = __bswap_variable_64 ( *x ); -} - -#endif diff --git a/roms/ipxe/src/arch/arm32/include/bits/compiler.h b/roms/ipxe/src/arch/arm32/include/bits/compiler.h deleted file mode 100644 index e420cf922..000000000 --- a/roms/ipxe/src/arch/arm32/include/bits/compiler.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef _BITS_COMPILER_H -#define _BITS_COMPILER_H - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -/** Dummy relocation type */ -#define RELOC_TYPE_NONE R_ARM_NONE - -#ifndef ASSEMBLY - -#define __asmcall -#define __libgcc - -#endif /* ASSEMBLY */ - -#endif /*_BITS_COMPILER_H */ diff --git a/roms/ipxe/src/arch/arm32/include/bits/profile.h b/roms/ipxe/src/arch/arm32/include/bits/profile.h deleted file mode 100644 index 2b15d1604..000000000 --- a/roms/ipxe/src/arch/arm32/include/bits/profile.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef _BITS_PROFILE_H -#define _BITS_PROFILE_H - -/** @file - * - * Profiling - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#include <stdint.h> - -/** - * Get profiling timestamp - * - * @ret timestamp Timestamp - */ -static inline __attribute__ (( always_inline )) uint64_t -profile_timestamp ( void ) { - uint32_t cycles; - - /* Read cycle counter */ - __asm__ __volatile__ ( "mcr p15, 0, %1, c9, c12, 0\n\t" - "mrc p15, 0, %0, c9, c13, 0\n\t" - : "=r" ( cycles ) : "r" ( 1 ) ); - return cycles; -} - -#endif /* _BITS_PROFILE_H */ diff --git a/roms/ipxe/src/arch/arm32/include/bits/stdint.h b/roms/ipxe/src/arch/arm32/include/bits/stdint.h deleted file mode 100644 index fe1f9946a..000000000 --- a/roms/ipxe/src/arch/arm32/include/bits/stdint.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef _BITS_STDINT_H -#define _BITS_STDINT_H - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -typedef __SIZE_TYPE__ size_t; -typedef signed long ssize_t; -typedef signed long off_t; - -typedef unsigned char uint8_t; -typedef unsigned short uint16_t; -typedef unsigned int uint32_t; -typedef unsigned long long uint64_t; - -typedef signed char int8_t; -typedef signed short int16_t; -typedef signed int int32_t; -typedef signed long long int64_t; - -typedef unsigned long physaddr_t; -typedef unsigned long intptr_t; - -#endif /* _BITS_STDINT_H */ diff --git a/roms/ipxe/src/arch/arm32/include/bits/string.h b/roms/ipxe/src/arch/arm32/include/bits/string.h deleted file mode 100644 index 5b1c1505d..000000000 --- a/roms/ipxe/src/arch/arm32/include/bits/string.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef BITS_STRING_H -#define BITS_STRING_H - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -/** @file - * - * String functions - * - */ - -/** - * Fill memory region - * - * @v dest Destination region - * @v character Fill character - * @v len Length - * @ret dest Destination region - */ -static inline __attribute__ (( always_inline )) void * -memset ( void *dest, int character, size_t len ) { - - /* Not yet optimised */ - generic_memset ( dest, character, len ); - return dest; -} - -/** - * Copy memory region - * - * @v dest Destination region - * @v src Source region - * @v len Length - * @ret dest Destination region - */ -static inline __attribute__ (( always_inline )) void * -memcpy ( void *dest, const void *src, size_t len ) { - - /* Not yet optimised */ - generic_memcpy ( dest, src, len ); - return dest; -} - -/** - * Copy (possibly overlapping) memory region - * - * @v dest Destination region - * @v src Source region - * @v len Length - * @ret dest Destination region - */ -static inline __attribute__ (( always_inline )) void * -memmove ( void *dest, const void *src, size_t len ) { - - /* Not yet optimised */ - generic_memmove ( dest, src, len ); - return dest; -} - -#endif /* BITS_STRING_H */ diff --git a/roms/ipxe/src/arch/arm32/include/bits/strings.h b/roms/ipxe/src/arch/arm32/include/bits/strings.h deleted file mode 100644 index adbd5f4b4..000000000 --- a/roms/ipxe/src/arch/arm32/include/bits/strings.h +++ /dev/null @@ -1,85 +0,0 @@ -#ifndef _BITS_STRINGS_H -#define _BITS_STRINGS_H - -/** @file - * - * String functions - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -/** - * Find first (i.e. least significant) set bit - * - * @v value Value - * @ret lsb Least significant bit set in value (LSB=1), or zero - */ -static inline __attribute__ (( always_inline )) int __ffsl ( long value ) { - unsigned long bits = value; - unsigned long lsb; - unsigned int lz; - - /* Extract least significant set bit */ - lsb = ( bits & -bits ); - - /* Count number of leading zeroes before LSB */ - __asm__ ( "clz %0, %1" : "=r" ( lz ) : "r" ( lsb ) ); - - return ( 32 - lz ); -} - -/** - * Find first (i.e. least significant) set bit - * - * @v value Value - * @ret lsb Least significant bit set in value (LSB=1), or zero - */ -static inline __attribute__ (( always_inline )) int __ffsll ( long long value ){ - unsigned long high = ( value >> 32 ); - unsigned long low = ( value >> 0 ); - - if ( low ) { - return ( __ffsl ( low ) ); - } else if ( high ) { - return ( 32 + __ffsl ( high ) ); - } else { - return 0; - } -} - -/** - * Find last (i.e. most significant) set bit - * - * @v value Value - * @ret msb Most significant bit set in value (LSB=1), or zero - */ -static inline __attribute__ (( always_inline )) int __flsl ( long value ) { - unsigned int lz; - - /* Count number of leading zeroes */ - __asm__ ( "clz %0, %1" : "=r" ( lz ) : "r" ( value ) ); - - return ( 32 - lz ); -} - -/** - * Find last (i.e. most significant) set bit - * - * @v value Value - * @ret msb Most significant bit set in value (LSB=1), or zero - */ -static inline __attribute__ (( always_inline )) int __flsll ( long long value ){ - unsigned long high = ( value >> 32 ); - unsigned long low = ( value >> 0 ); - - if ( high ) { - return ( 32 + __flsl ( high ) ); - } else if ( low ) { - return ( __flsl ( low ) ); - } else { - return 0; - } -} - -#endif /* _BITS_STRINGS_H */ diff --git a/roms/ipxe/src/arch/arm32/include/bits/tcpip.h b/roms/ipxe/src/arch/arm32/include/bits/tcpip.h deleted file mode 100644 index fc3c5b3ff..000000000 --- a/roms/ipxe/src/arch/arm32/include/bits/tcpip.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef _BITS_TCPIP_H -#define _BITS_TCPIP_H - -/** @file - * - * Transport-network layer interface - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -static inline __attribute__ (( always_inline )) uint16_t -tcpip_continue_chksum ( uint16_t partial, const void *data, size_t len ) { - - /* Not yet optimised */ - return generic_tcpip_continue_chksum ( partial, data, len ); -} - -#endif /* _BITS_TCPIP_H */ diff --git a/roms/ipxe/src/arch/arm32/include/efi/ipxe/dhcp_arch.h b/roms/ipxe/src/arch/arm32/include/efi/ipxe/dhcp_arch.h deleted file mode 100644 index f9baab4fa..000000000 --- a/roms/ipxe/src/arch/arm32/include/efi/ipxe/dhcp_arch.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2015 Michael Brown <mbrown@fensystems.co.uk>. - * - * 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 (at your option) 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. - */ - -#ifndef _DHCP_ARCH_H -#define _DHCP_ARCH_H - -/** @file - * - * Architecture-specific DHCP options - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#include <ipxe/dhcp.h> - -#define DHCP_ARCH_VENDOR_CLASS_ID \ - DHCP_STRING ( 'P', 'X', 'E', 'C', 'l', 'i', 'e', 'n', 't', ':', \ - 'A', 'r', 'c', 'h', ':', '0', '0', '0', '0', '7', ':', \ - 'U', 'N', 'D', 'I', ':', '0', '0', '3', '0', '1', '0' ) - -#define DHCP_ARCH_CLIENT_ARCHITECTURE \ - DHCP_WORD ( DHCP_CLIENT_ARCHITECTURE_ARM32 ) - -#define DHCP_ARCH_CLIENT_NDI DHCP_OPTION ( 1 /* UNDI */ , 3, 10 /* v3.10 */ ) - -#endif diff --git a/roms/ipxe/src/arch/arm32/include/gdbmach.h b/roms/ipxe/src/arch/arm32/include/gdbmach.h deleted file mode 100644 index cd152eedd..000000000 --- a/roms/ipxe/src/arch/arm32/include/gdbmach.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef GDBMACH_H -#define GDBMACH_H - -/** @file - * - * GDB architecture specifics - * - * This file declares functions for manipulating the machine state and - * debugging context. - * - */ - -#include <stdint.h> - -typedef unsigned long gdbreg_t; - -/* Register snapshot */ -enum { - /* Not yet implemented */ - GDBMACH_NREGS, -}; - -#define GDBMACH_SIZEOF_REGS ( GDBMACH_NREGS * sizeof ( gdbreg_t ) ) - -static inline void gdbmach_set_pc ( gdbreg_t *regs, gdbreg_t pc ) { - /* Not yet implemented */ - ( void ) regs; - ( void ) pc; -} - -static inline void gdbmach_set_single_step ( gdbreg_t *regs, int step ) { - /* Not yet implemented */ - ( void ) regs; - ( void ) step; -} - -static inline void gdbmach_breakpoint ( void ) { - /* Not yet implemented */ -} - -extern int gdbmach_set_breakpoint ( int type, unsigned long addr, size_t len, - int enable ); -extern void gdbmach_init ( void ); - -#endif /* GDBMACH_H */ diff --git a/roms/ipxe/src/arch/arm32/include/limits.h b/roms/ipxe/src/arch/arm32/include/limits.h deleted file mode 100644 index bb48b75ab..000000000 --- a/roms/ipxe/src/arch/arm32/include/limits.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef LIMITS_H -#define LIMITS_H 1 - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -/* Number of bits in a `char' */ -#define CHAR_BIT 8 - -/* Minimum and maximum values a `signed char' can hold */ -#define SCHAR_MIN (-128) -#define SCHAR_MAX 127 - -/* Maximum value an `unsigned char' can hold. (Minimum is 0.) */ -#define UCHAR_MAX 255 - -/* Minimum and maximum values a `char' can hold */ -#define CHAR_MIN SCHAR_MIN -#define CHAR_MAX SCHAR_MAX - -/* Minimum and maximum values a `signed short int' can hold */ -#define SHRT_MIN (-32768) -#define SHRT_MAX 32767 - -/* Maximum value an `unsigned short' can hold. (Minimum is 0.) */ -#define USHRT_MAX 65535 - - -/* Minimum and maximum values a `signed int' can hold */ -#define INT_MIN (-INT_MAX - 1) -#define INT_MAX 2147483647 - -/* Maximum value an `unsigned int' can hold. (Minimum is 0.) */ -#define UINT_MAX 4294967295U - - -/* Minimum and maximum values a `signed int' can hold */ -#define INT_MAX 2147483647 -#define INT_MIN (-INT_MAX - 1) - - -/* Maximum value an `unsigned int' can hold. (Minimum is 0.) */ -#define UINT_MAX 4294967295U - - -/* Minimum and maximum values a `signed long' can hold */ -#define LONG_MAX 2147483647 -#define LONG_MIN (-LONG_MAX - 1L) - -/* Maximum value an `unsigned long' can hold. (Minimum is 0.) */ -#define ULONG_MAX 4294967295UL - -/* Minimum and maximum values a `signed long long' can hold */ -#define LLONG_MAX 9223372036854775807LL -#define LLONG_MIN (-LONG_MAX - 1LL) - - -/* Maximum value an `unsigned long long' can hold. (Minimum is 0.) */ -#define ULLONG_MAX 18446744073709551615ULL - - -#endif /* LIMITS_H */ diff --git a/roms/ipxe/src/arch/arm32/include/setjmp.h b/roms/ipxe/src/arch/arm32/include/setjmp.h deleted file mode 100644 index 4828b47a2..000000000 --- a/roms/ipxe/src/arch/arm32/include/setjmp.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef _SETJMP_H -#define _SETJMP_H - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#include <stdint.h> - -/** A jump buffer */ -typedef struct { - /** Saved r4 */ - uint32_t r4; - /** Saved r5 */ - uint32_t r5; - /** Saved r6 */ - uint32_t r6; - /** Saved r7 */ - uint32_t r7; - /** Saved r8 */ - uint32_t r8; - /** Saved r9 */ - uint32_t r9; - /** Saved r10 */ - uint32_t r10; - /** Saved frame pointer (r11) */ - uint32_t fp; - /** Saved stack pointer (r13) */ - uint32_t sp; - /** Saved link register (r14) */ - uint32_t lr; -} jmp_buf[1]; - -extern int __asmcall __attribute__ (( returns_twice )) -setjmp ( jmp_buf env ); - -extern void __asmcall __attribute__ (( noreturn )) -longjmp ( jmp_buf env, int val ); - -#endif /* _SETJMP_H */ diff --git a/roms/ipxe/src/arch/arm32/libgcc/lldivmod.S b/roms/ipxe/src/arch/arm32/libgcc/lldivmod.S deleted file mode 100644 index 910be4b78..000000000 --- a/roms/ipxe/src/arch/arm32/libgcc/lldivmod.S +++ /dev/null @@ -1,50 +0,0 @@ -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) - - .text - .thumb - -/** - * Unsigned long long division - * - * @v r1:r0 Dividend - * @v r3:r2 Divisor - * @ret r1:r0 Quotient - * @ret r3:r2 Remainder - */ - .section ".text.__aeabi_uldivmod", "ax", %progbits - .globl __aeabi_uldivmod - .type __aeabi_uldivmod, %function -__aeabi_uldivmod: - /* Allocate stack space for remainder and pointer to remainder */ - push {r0, r1, r2, r3, r4, lr} - /* Call __udivmoddi4() */ - add r4, sp, #8 - str r4, [sp] - bl __udivmoddi4 - /* Retrieve remainder and return */ - add sp, sp, #8 - pop {r2, r3, r4, pc} - .size __aeabi_uldivmod, . - __aeabi_uldivmod - -/** - * Signed long long division - * - * @v r1:r0 Dividend - * @v r3:r2 Divisor - * @ret r1:r0 Quotient - * @ret r3:r2 Remainder - */ - .section ".text.__aeabi_ldivmod", "ax", %progbits - .globl __aeabi_ldivmod - .type __aeabi_ldivmod, %function -__aeabi_ldivmod: - /* Allocate stack space for remainder and pointer to remainder */ - push {r0, r1, r2, r3, r4, lr} - /* Call __divmoddi4() */ - add r4, sp, #8 - str r4, [sp] - bl __divmoddi4 - /* Retrieve remainder and return */ - add sp, sp, #8 - pop {r2, r3, r4, pc} - .size __aeabi_ldivmod, . - __aeabi_ldivmod diff --git a/roms/ipxe/src/arch/arm32/libgcc/llshift.S b/roms/ipxe/src/arch/arm32/libgcc/llshift.S deleted file mode 100644 index cc16e2615..000000000 --- a/roms/ipxe/src/arch/arm32/libgcc/llshift.S +++ /dev/null @@ -1,88 +0,0 @@ -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) - - .text - .arm - -/** - * Logical shift left - * - * @v r1:r0 Value to shift - * @v r2 Shift amount - * @ret r1:r0 Shifted value - */ - .section ".text.__aeabi_llsl", "ax", %progbits - .globl __aeabi_llsl - .type __aeabi_llsl, %function -__aeabi_llsl: - /* r3 = ( shift - 32 ) */ - subs r3, r2, #32 - /* If shift >= 32, then - * high = ( low << ( shift - 32 ) ) - */ - movpl r1, r0, lsl r3 - /* If shift < 32, then - * high = ( ( high << shift ) | ( low >> ( 32 - shift ) ) ) - */ - movmi r1, r1, lsl r2 - rsbmi r3, r2, #32 - orrmi r1, r1, r0, lsr r3 - /* low = ( low << shift ) */ - mov r0, r0, lsl r2 - bx lr - .size __aeabi_llsl, . - __aeabi_llsl - -/** - * Logical shift right - * - * @v r1:r0 Value to shift - * @v r2 Shift amount - * @ret r1:r0 Shifted value - */ - .section ".text.__aeabi_llsr", "ax", %progbits - .globl __aeabi_llsr - .type __aeabi_llsr, %function -__aeabi_llsr: - /* r3 = ( shift - 32 ) */ - subs r3, r2, #32 - /* If shift >= 32, then - * low = ( high >> ( shift - 32 ) ) - */ - movpl r0, r1, lsr r3 - /* If shift < 32, then - * low = ( ( low >> shift ) | ( high << ( 32 - shift ) ) ) - */ - movmi r0, r0, lsr r2 - rsbmi r3, r2, #32 - orrmi r0, r0, r1, lsl r3 - /* high = ( high >> shift ) */ - mov r1, r1, lsr r2 - bx lr - .size __aeabi_llsr, . - __aeabi_llsr - -/** - * Arithmetic shift right - * - * @v r1:r0 Value to shift - * @v r2 Shift amount - * @ret r1:r0 Shifted value - */ - .section ".text.__aeabi_lasr", "ax", %progbits - .globl __aeabi_lasr - .type __aeabi_lasr, %function -__aeabi_lasr: - /* r3 = ( shift - 32 ) */ - subs r3, r2, #32 - /* If shift >= 32, then - * low = ( high >> ( shift - 32 ) ) - */ - movpl r0, r1, asr r3 - /* If shift < 32, then - * low = ( ( low >> shift ) | ( high << ( 32 - shift ) ) ) - */ - movmi r0, r0, lsr r2 - rsbmi r3, r2, #32 - orrmi r0, r0, r1, lsl r3 - /* high = ( high >> shift ) */ - mov r1, r1, asr r2 - bx lr - .size __aeabi_lasr, . - __aeabi_lasr diff --git a/roms/ipxe/src/arch/arm64/Makefile b/roms/ipxe/src/arch/arm64/Makefile deleted file mode 100644 index d121871f7..000000000 --- a/roms/ipxe/src/arch/arm64/Makefile +++ /dev/null @@ -1,22 +0,0 @@ -# ARM64-specific directories containing source files -# -SRCDIRS += arch/arm64/core - -# ARM64-specific flags -# -CFLAGS += -mabi=lp64 -mlittle-endian -mcmodel=small -CFLAGS += -fomit-frame-pointer -ASFLAGS += -mabi=lp64 -EL - -# EFI requires -fshort-wchar, and nothing else currently uses wchar_t -# -CFLAGS += -fshort-wchar - -# Include common ARM Makefile -MAKEDEPS += arch/arm/Makefile -include arch/arm/Makefile - -# Include platform-specific Makefile -# -MAKEDEPS += arch/arm64/Makefile.$(PLATFORM) -include arch/arm64/Makefile.$(PLATFORM) diff --git a/roms/ipxe/src/arch/arm64/Makefile.efi b/roms/ipxe/src/arch/arm64/Makefile.efi deleted file mode 100644 index 998a64d03..000000000 --- a/roms/ipxe/src/arch/arm64/Makefile.efi +++ /dev/null @@ -1,14 +0,0 @@ -# -*- makefile -*- : Force emacs to use Makefile mode - -# Specify EFI image builder -# -ELF2EFI = $(ELF2EFI64) - -# Specify EFI boot file -# -EFI_BOOT_FILE = bootaa64.efi - -# Include generic EFI Makefile -# -MAKEDEPS += arch/arm/Makefile.efi -include arch/arm/Makefile.efi diff --git a/roms/ipxe/src/arch/arm64/core/arm64_bigint.c b/roms/ipxe/src/arch/arm64/core/arm64_bigint.c deleted file mode 100644 index bc4ee9a00..000000000 --- a/roms/ipxe/src/arch/arm64/core/arm64_bigint.c +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (C) 2016 Michael Brown <mbrown@fensystems.co.uk>. - * - * 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 <stdint.h> -#include <string.h> -#include <ipxe/bigint.h> - -/** @file - * - * Big integer support - */ - -/** - * Multiply big integers - * - * @v multiplicand0 Element 0 of big integer to be multiplied - * @v multiplier0 Element 0 of big integer to be multiplied - * @v result0 Element 0 of big integer to hold result - * @v size Number of elements - */ -void bigint_multiply_raw ( const uint64_t *multiplicand0, - const uint64_t *multiplier0, - uint64_t *result0, unsigned int size ) { - const bigint_t ( size ) __attribute__ (( may_alias )) *multiplicand = - ( ( const void * ) multiplicand0 ); - const bigint_t ( size ) __attribute__ (( may_alias )) *multiplier = - ( ( const void * ) multiplier0 ); - bigint_t ( size * 2 ) __attribute__ (( may_alias )) *result = - ( ( void * ) result0 ); - unsigned int i; - unsigned int j; - uint64_t multiplicand_element; - uint64_t multiplier_element; - uint64_t *result_elements; - uint64_t discard_low; - uint64_t discard_high; - uint64_t discard_temp_low; - uint64_t discard_temp_high; - - /* Zero result */ - memset ( result, 0, sizeof ( *result ) ); - - /* Multiply integers one element at a time */ - for ( i = 0 ; i < size ; i++ ) { - multiplicand_element = multiplicand->element[i]; - for ( j = 0 ; j < size ; j++ ) { - multiplier_element = multiplier->element[j]; - result_elements = &result->element[ i + j ]; - /* Perform a single multiply, and add the - * resulting double-element into the result, - * carrying as necessary. The carry can - * never overflow beyond the end of the - * result, since: - * - * a < 2^{n}, b < 2^{n} => ab < 2^{2n} - */ - __asm__ __volatile__ ( "mul %1, %6, %7\n\t" - "umulh %2, %6, %7\n\t" - "ldp %3, %4, [%0]\n\t" - "adds %3, %3, %1\n\t" - "adcs %4, %4, %2\n\t" - "stp %3, %4, [%0], #16\n\t" - "bcc 2f\n\t" - "\n1:\n\t" - "ldr %3, [%0]\n\t" - "adcs %3, %3, xzr\n\t" - "str %3, [%0], #8\n\t" - "bcs 1b\n\t" - "\n2:\n\t" - : "+r" ( result_elements ), - "=&r" ( discard_low ), - "=&r" ( discard_high ), - "=r" ( discard_temp_low ), - "=r" ( discard_temp_high ), - "+m" ( *result ) - : "r" ( multiplicand_element ), - "r" ( multiplier_element ) - : "cc" ); - } - } -} diff --git a/roms/ipxe/src/arch/arm64/core/arm64_string.c b/roms/ipxe/src/arch/arm64/core/arm64_string.c deleted file mode 100644 index 28a2b73bc..000000000 --- a/roms/ipxe/src/arch/arm64/core/arm64_string.c +++ /dev/null @@ -1,249 +0,0 @@ -/* - * Copyright (C) 2016 Michael Brown <mbrown@fensystems.co.uk>. - * - * 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 - * - * Optimised string operations - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#include <string.h> - -/** - * Copy memory area - * - * @v dest Destination address - * @v src Source address - * @v len Length - * @ret dest Destination address - */ -void arm64_memcpy ( void *dest, const void *src, size_t len ) { - void *discard_dest; - void *discard_end; - const void *discard_src; - size_t discard_offset; - unsigned long discard_data; - unsigned long discard_low; - unsigned long discard_high; - - /* If length is too short for an "ldp"/"stp" instruction pair, - * then just copy individual bytes. - */ - if ( len < 16 ) { - __asm__ __volatile__ ( "cbz %0, 2f\n\t" - "\n1:\n\t" - "sub %0, %0, #1\n\t" - "ldrb %w1, [%3, %0]\n\t" - "strb %w1, [%2, %0]\n\t" - "cbnz %0, 1b\n\t" - "\n2:\n\t" - : "=&r" ( discard_offset ), - "=&r" ( discard_data ) - : "r" ( dest ), "r" ( src ), "0" ( len ) - : "memory" ); - return; - } - - /* Use "ldp"/"stp" to copy 16 bytes at a time: one initial - * potentially unaligned access, multiple destination-aligned - * accesses, one final potentially unaligned access. - */ - __asm__ __volatile__ ( "ldp %3, %4, [%1], #16\n\t" - "stp %3, %4, [%0], #16\n\t" - "and %3, %0, #15\n\t" - "sub %0, %0, %3\n\t" - "sub %1, %1, %3\n\t" - "bic %2, %5, #15\n\t" - "b 2f\n\t" - "\n1:\n\t" - "ldp %3, %4, [%1], #16\n\t" - "stp %3, %4, [%0], #16\n\t" - "\n2:\n\t" - "cmp %0, %2\n\t" - "bne 1b\n\t" - "ldp %3, %4, [%6, #-16]\n\t" - "stp %3, %4, [%5, #-16]\n\t" - : "=&r" ( discard_dest ), - "=&r" ( discard_src ), - "=&r" ( discard_end ), - "=&r" ( discard_low ), - "=&r" ( discard_high ) - : "r" ( dest + len ), "r" ( src + len ), - "0" ( dest ), "1" ( src ) - : "memory", "cc" ); -} - -/** - * Zero memory region - * - * @v dest Destination region - * @v len Length - */ -void arm64_bzero ( void *dest, size_t len ) { - size_t discard_offset; - void *discard_dest; - void *discard_end; - - /* If length is too short for an "stp" instruction, then just - * zero individual bytes. - */ - if ( len < 16 ) { - __asm__ __volatile__ ( "cbz %0, 2f\n\t" - "\n1:\n\t" - "sub %0, %0, #1\n\t" - "strb wzr, [%1, %0]\n\t" - "cbnz %0, 1b\n\t" - "\n2:\n\t" - : "=&r" ( discard_offset ) - : "r" ( dest ), "0" ( len ) - : "memory" ); - return; - } - - /* Use "stp" to zero 16 bytes at a time: one initial - * potentially unaligned access, multiple aligned accesses, - * one final potentially unaligned access. - */ - __asm__ __volatile__ ( "stp xzr, xzr, [%0], #16\n\t" - "bic %0, %0, #15\n\t" - "bic %1, %2, #15\n\t" - "b 2f\n\t" - "\n1:\n\t" - "stp xzr, xzr, [%0], #16\n\t" - "\n2:\n\t" - "cmp %0, %1\n\t" - "bne 1b\n\t" - "stp xzr, xzr, [%2, #-16]\n\t" - : "=&r" ( discard_dest ), - "=&r" ( discard_end ) - : "r" ( dest + len ), "0" ( dest ) - : "memory", "cc" ); -} - -/** - * Fill memory region - * - * @v dest Destination region - * @v len Length - * @v character Fill character - * - * The unusual parameter order is to allow for more efficient - * tail-calling to arm64_memset() when zeroing a region. - */ -void arm64_memset ( void *dest, size_t len, int character ) { - size_t discard_offset; - - /* Use optimised zeroing code if applicable */ - if ( character == 0 ) { - arm64_bzero ( dest, len ); - return; - } - - /* Fill one byte at a time. Calling memset() with a non-zero - * value is relatively rare and unlikely to be - * performance-critical. - */ - __asm__ __volatile__ ( "cbz %0, 2f\n\t" - "\n1:\n\t" - "sub %0, %0, #1\n\t" - "strb %w2, [%1, %0]\n\t" - "cbnz %0, 1b\n\t" - "\n2:\n\t" - : "=&r" ( discard_offset ) - : "r" ( dest ), "r" ( character ), "0" ( len ) - : "memory" ); -} - -/** - * Copy (possibly overlapping) memory region forwards - * - * @v dest Destination region - * @v src Source region - * @v len Length - */ -void arm64_memmove_forwards ( void *dest, const void *src, size_t len ) { - void *discard_dest; - const void *discard_src; - unsigned long discard_data; - - /* Assume memmove() is not performance-critical, and perform a - * bytewise copy for simplicity. - */ - __asm__ __volatile__ ( "b 2f\n\t" - "\n1:\n\t" - "ldrb %w2, [%1], #1\n\t" - "strb %w2, [%0], #1\n\t" - "\n2:\n\t" - "cmp %0, %3\n\t" - "bne 1b\n\t" - : "=&r" ( discard_dest ), - "=&r" ( discard_src ), - "=&r" ( discard_data ) - : "r" ( dest + len ), "0" ( dest ), "1" ( src ) - : "memory" ); -} - -/** - * Copy (possibly overlapping) memory region backwards - * - * @v dest Destination region - * @v src Source region - * @v len Length - */ -void arm64_memmove_backwards ( void *dest, const void *src, size_t len ) { - size_t discard_offset; - unsigned long discard_data; - - /* Assume memmove() is not performance-critical, and perform a - * bytewise copy for simplicity. - */ - __asm__ __volatile__ ( "cbz %0, 2f\n\t" - "\n1:\n\t" - "sub %0, %0, #1\n\t" - "ldrb %w1, [%3, %0]\n\t" - "strb %w1, [%2, %0]\n\t" - "cbnz %0, 1b\n\t" - "\n2:\n\t" - : "=&r" ( discard_offset ), - "=&r" ( discard_data ) - : "r" ( dest ), "r" ( src ), "0" ( len ) - : "memory" ); -} - -/** - * Copy (possibly overlapping) memory region - * - * @v dest Destination region - * @v src Source region - * @v len Length - */ -void arm64_memmove ( void *dest, const void *src, size_t len ) { - - if ( dest <= src ) { - arm64_memmove_forwards ( dest, src, len ); - } else { - arm64_memmove_backwards ( dest, src, len ); - } -} diff --git a/roms/ipxe/src/arch/arm64/core/arm64_tcpip.c b/roms/ipxe/src/arch/arm64/core/arm64_tcpip.c deleted file mode 100644 index 0ef04ea42..000000000 --- a/roms/ipxe/src/arch/arm64/core/arm64_tcpip.c +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright (C) 2016 Michael Brown <mbrown@fensystems.co.uk>. - * - * 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 (at your option) 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 ); - -/** @file - * - * TCP/IP checksum - * - */ - -#include <strings.h> -#include <ipxe/tcpip.h> - -/** Alignment used by main checksumming loop */ -#define TCPIP_CHKSUM_ALIGN 16 - -/** Number of steps in each iteration of the unrolled main checksumming loop */ -#define TCPIP_CHKSUM_UNROLL 4 - -/** - * Calculate continued TCP/IP checkum - * - * @v sum Checksum of already-summed data, in network byte order - * @v data Data buffer - * @v len Length of data buffer - * @ret sum Updated checksum, in network byte order - */ -uint16_t tcpip_continue_chksum ( uint16_t sum, const void *data, - size_t len ) { - intptr_t start; - intptr_t end; - intptr_t mid; - unsigned int pre; - unsigned int post; - unsigned int first; - uint64_t discard_low; - uint64_t discard_high; - - /* Avoid potentially undefined shift operation */ - if ( len == 0 ) - return sum; - - /* Find maximally-aligned midpoint. For short blocks of data, - * this may be aligned to fewer than 16 bytes. - */ - start = ( ( intptr_t ) data ); - end = ( start + len ); - mid = ( end & - ~( ( ~( 1UL << 63 ) ) >> ( 64 - flsl ( start ^ end ) ) ) ); - - /* Calculate pre- and post-alignment lengths */ - pre = ( ( mid - start ) & ( TCPIP_CHKSUM_ALIGN - 1 ) ); - post = ( ( end - mid ) & ( TCPIP_CHKSUM_ALIGN - 1 ) ); - - /* Calculate number of steps in first iteration of unrolled loop */ - first = ( ( ( len - pre - post ) / TCPIP_CHKSUM_ALIGN ) & - ( TCPIP_CHKSUM_UNROLL - 1 ) ); - - /* Calculate checksum */ - __asm__ ( /* Invert sum */ - "eor %w0, %w0, #0xffff\n\t" - /* Clear carry flag */ - "cmn xzr, xzr\n\t" - /* Byteswap and sum pre-alignment byte, if applicable */ - "tbz %w4, #0, 1f\n\t" - "ldrb %w2, [%1], #1\n\t" - "rev16 %w0, %w0\n\t" - "rev16 %w2, %w2\n\t" - "adcs %0, %0, %2\n\t" - "\n1:\n\t" - /* Sum pre-alignment halfword, if applicable */ - "tbz %w4, #1, 1f\n\t" - "ldrh %w2, [%1], #2\n\t" - "adcs %0, %0, %2\n\t" - "\n1:\n\t" - /* Sum pre-alignment word, if applicable */ - "tbz %w4, #2, 1f\n\t" - "ldr %w2, [%1], #4\n\t" - "adcs %0, %0, %2\n\t" - "\n1:\n\t" - /* Sum pre-alignment doubleword, if applicable */ - "tbz %w4, #3, 1f\n\t" - "ldr %2, [%1], #8\n\t" - "adcs %0, %0, %2\n\t" - "\n1:\n\t" - /* Jump into unrolled (x4) main loop */ - "adr %2, 2f\n\t" - "sub %2, %2, %5, lsl #3\n\t" - "sub %2, %2, %5, lsl #2\n\t" - "br %2\n\t" - "\n1:\n\t" - "ldp %2, %3, [%1], #16\n\t" - "adcs %0, %0, %2\n\t" - "adcs %0, %0, %3\n\t" - "ldp %2, %3, [%1], #16\n\t" - "adcs %0, %0, %2\n\t" - "adcs %0, %0, %3\n\t" - "ldp %2, %3, [%1], #16\n\t" - "adcs %0, %0, %2\n\t" - "adcs %0, %0, %3\n\t" - "ldp %2, %3, [%1], #16\n\t" - "adcs %0, %0, %2\n\t" - "adcs %0, %0, %3\n\t" - "\n2:\n\t" - "sub %2, %1, %6\n\t" - "cbnz %2, 1b\n\t" - /* Sum post-alignment doubleword, if applicable */ - "tbz %w7, #3, 1f\n\t" - "ldr %2, [%1], #8\n\t" - "adcs %0, %0, %2\n\t" - "\n1:\n\t" - /* Sum post-alignment word, if applicable */ - "tbz %w7, #2, 1f\n\t" - "ldr %w2, [%1], #4\n\t" - "adcs %0, %0, %2\n\t" - "\n1:\n\t" - /* Sum post-alignment halfword, if applicable */ - "tbz %w7, #1, 1f\n\t" - "ldrh %w2, [%1], #2\n\t" - "adcs %0, %0, %2\n\t" - "\n1:\n\t" - /* Sum post-alignment byte, if applicable */ - "tbz %w7, #0, 1f\n\t" - "ldrb %w2, [%1], #1\n\t" - "adcs %0, %0, %2\n\t" - "\n1:\n\t" - /* Fold down to a uint32_t plus carry flag */ - "lsr %2, %0, #32\n\t" - "adcs %w0, %w0, %w2\n\t" - /* Fold down to a uint16_t plus carry in bit 16 */ - "ubfm %2, %0, #0, #15\n\t" - "ubfm %3, %0, #16, #31\n\t" - "adc %w0, %w2, %w3\n\t" - /* Fold down to a uint16_t */ - "tbz %w0, #16, 1f\n\t" - "mov %w2, #0xffff\n\t" - "sub %w0, %w0, %w2\n\t" - "tbz %w0, #16, 1f\n\t" - "sub %w0, %w0, %w2\n\t" - "\n1:\n\t" - /* Byteswap back, if applicable */ - "tbz %w4, #0, 1f\n\t" - "rev16 %w0, %w0\n\t" - "\n1:\n\t" - /* Invert sum */ - "eor %w0, %w0, #0xffff\n\t" - : "+r" ( sum ), "+r" ( data ), "=&r" ( discard_low ), - "=&r" ( discard_high ) - : "r" ( pre ), "r" ( first ), "r" ( end - post ), - "r" ( post ) - : "cc" ); - - return sum; -} diff --git a/roms/ipxe/src/arch/arm64/core/setjmp.S b/roms/ipxe/src/arch/arm64/core/setjmp.S deleted file mode 100644 index fa47aa0af..000000000 --- a/roms/ipxe/src/arch/arm64/core/setjmp.S +++ /dev/null @@ -1,56 +0,0 @@ -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) - - .text - - /* Must match jmp_buf structure layout */ - .struct 0 -env_x19_x20: .quad 0, 0 -env_x21_x22: .quad 0, 0 -env_x23_x24: .quad 0, 0 -env_x25_x26: .quad 0, 0 -env_x27_x28: .quad 0, 0 -env_x29_x30: .quad 0, 0 -env_sp: .quad 0 - .previous - -/* - * Save stack context for non-local goto - */ - .globl setjmp - .type setjmp, %function -setjmp: - /* Store registers */ - stp x19, x20, [x0, #env_x19_x20] - stp x21, x22, [x0, #env_x21_x22] - stp x23, x24, [x0, #env_x23_x24] - stp x25, x26, [x0, #env_x25_x26] - stp x27, x28, [x0, #env_x27_x28] - stp x29, x30, [x0, #env_x29_x30] - mov x16, sp - str x16, [x0, #env_sp] - /* Return 0 when returning as setjmp() */ - mov x0, #0 - ret - .size setjmp, . - setjmp - -/* - * Non-local jump to a saved stack context - */ - .globl longjmp - .type longjmp, %function -longjmp: - /* Restore registers */ - ldp x19, x20, [x0, #env_x19_x20] - ldp x21, x22, [x0, #env_x21_x22] - ldp x23, x24, [x0, #env_x23_x24] - ldp x25, x26, [x0, #env_x25_x26] - ldp x27, x28, [x0, #env_x27_x28] - ldp x29, x30, [x0, #env_x29_x30] - ldr x16, [x0, #env_sp] - mov sp, x16 - /* Force result to non-zero */ - cmp w1, #0 - csinc w0, w1, w1, ne - /* Return to setjmp() caller */ - br x30 - .size longjmp, . - longjmp diff --git a/roms/ipxe/src/arch/arm64/include/bits/bigint.h b/roms/ipxe/src/arch/arm64/include/bits/bigint.h deleted file mode 100644 index 79983b410..000000000 --- a/roms/ipxe/src/arch/arm64/include/bits/bigint.h +++ /dev/null @@ -1,317 +0,0 @@ -#ifndef _BITS_BIGINT_H -#define _BITS_BIGINT_H - -/** @file - * - * Big integer support - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#include <stdint.h> -#include <string.h> -#include <strings.h> - -/** Element of a big integer */ -typedef uint64_t bigint_element_t; - -/** - * Initialise big integer - * - * @v value0 Element 0 of big integer to initialise - * @v size Number of elements - * @v data Raw data - * @v len Length of raw data - */ -static inline __attribute__ (( always_inline )) void -bigint_init_raw ( uint64_t *value0, unsigned int size, - const void *data, size_t len ) { - size_t pad_len = ( sizeof ( bigint_t ( size ) ) - len ); - uint8_t *value_byte = ( ( void * ) value0 ); - const uint8_t *data_byte = ( data + len ); - - /* Copy raw data in reverse order, padding with zeros */ - while ( len-- ) - *(value_byte++) = *(--data_byte); - while ( pad_len-- ) - *(value_byte++) = 0; -} - -/** - * Add big integers - * - * @v addend0 Element 0 of big integer to add - * @v value0 Element 0 of big integer to be added to - * @v size Number of elements - */ -static inline __attribute__ (( always_inline )) void -bigint_add_raw ( const uint64_t *addend0, uint64_t *value0, - unsigned int size ) { - bigint_t ( size ) __attribute__ (( may_alias )) *value = - ( ( void * ) value0 ); - uint64_t *discard_addend; - uint64_t *discard_value; - uint64_t discard_addend_i; - uint64_t discard_value_i; - unsigned int discard_size; - - __asm__ __volatile__ ( "cmn xzr, xzr\n\t" /* clear CF */ - "\n1:\n\t" - "ldr %3, [%0], #8\n\t" - "ldr %4, [%1]\n\t" - "adcs %4, %4, %3\n\t" - "str %4, [%1], #8\n\t" - "sub %w2, %w2, #1\n\t" - "cbnz %w2, 1b\n\t" - : "=r" ( discard_addend ), - "=r" ( discard_value ), - "=r" ( discard_size ), - "=r" ( discard_addend_i ), - "=r" ( discard_value_i ), - "+m" ( *value ) - : "0" ( addend0 ), "1" ( value0 ), "2" ( size ) - : "cc" ); -} - -/** - * Subtract big integers - * - * @v subtrahend0 Element 0 of big integer to subtract - * @v value0 Element 0 of big integer to be subtracted from - * @v size Number of elements - */ -static inline __attribute__ (( always_inline )) void -bigint_subtract_raw ( const uint64_t *subtrahend0, uint64_t *value0, - unsigned int size ) { - bigint_t ( size ) __attribute__ (( may_alias )) *value = - ( ( void * ) value0 ); - uint64_t *discard_subtrahend; - uint64_t *discard_value; - uint64_t discard_subtrahend_i; - uint64_t discard_value_i; - unsigned int discard_size; - - __asm__ __volatile__ ( "cmp xzr, xzr\n\t" /* set CF */ - "\n1:\n\t" - "ldr %3, [%0], #8\n\t" - "ldr %4, [%1]\n\t" - "sbcs %4, %4, %3\n\t" - "str %4, [%1], #8\n\t" - "sub %w2, %w2, #1\n\t" - "cbnz %w2, 1b\n\t" - : "=r" ( discard_subtrahend ), - "=r" ( discard_value ), - "=r" ( discard_size ), - "=r" ( discard_subtrahend_i ), - "=r" ( discard_value_i ), - "+m" ( *value ) - : "0" ( subtrahend0 ), "1" ( value0 ), - "2" ( size ) - : "cc" ); -} - -/** - * Rotate big integer left - * - * @v value0 Element 0 of big integer - * @v size Number of elements - */ -static inline __attribute__ (( always_inline )) void -bigint_rol_raw ( uint64_t *value0, unsigned int size ) { - bigint_t ( size ) __attribute__ (( may_alias )) *value = - ( ( void * ) value0 ); - uint64_t *discard_value; - uint64_t discard_value_i; - unsigned int discard_size; - - __asm__ __volatile__ ( "cmn xzr, xzr\n\t" /* clear CF */ - "\n1:\n\t" - "ldr %2, [%0]\n\t" - "adcs %2, %2, %2\n\t" - "str %2, [%0], #8\n\t" - "sub %w1, %w1, #1\n\t" - "cbnz %w1, 1b\n\t" - : "=r" ( discard_value ), - "=r" ( discard_size ), - "=r" ( discard_value_i ), - "+m" ( *value ) - : "0" ( value0 ), "1" ( size ) - : "cc" ); -} - -/** - * Rotate big integer right - * - * @v value0 Element 0 of big integer - * @v size Number of elements - */ -static inline __attribute__ (( always_inline )) void -bigint_ror_raw ( uint64_t *value0, unsigned int size ) { - bigint_t ( size ) __attribute__ (( may_alias )) *value = - ( ( void * ) value0 ); - uint64_t *discard_value; - uint64_t discard_value_i; - uint64_t discard_value_j; - unsigned int discard_size; - - __asm__ __volatile__ ( "mov %3, #0\n\t" - "\n1:\n\t" - "sub %w1, %w1, #1\n\t" - "ldr %2, [%0, %1, lsl #3]\n\t" - "extr %3, %3, %2, #1\n\t" - "str %3, [%0, %1, lsl #3]\n\t" - "mov %3, %2\n\t" - "cbnz %w1, 1b\n\t" - : "=r" ( discard_value ), - "=r" ( discard_size ), - "=r" ( discard_value_i ), - "=r" ( discard_value_j ), - "+m" ( *value ) - : "0" ( value0 ), "1" ( size ) ); -} - -/** - * Test if big integer is equal to zero - * - * @v value0 Element 0 of big integer - * @v size Number of elements - * @ret is_zero Big integer is equal to zero - */ -static inline __attribute__ (( always_inline, pure )) int -bigint_is_zero_raw ( const uint64_t *value0, unsigned int size ) { - const uint64_t *value = value0; - uint64_t value_i; - - do { - value_i = *(value++); - if ( value_i ) - break; - } while ( --size ); - - return ( value_i == 0 ); -} - -/** - * Compare big integers - * - * @v value0 Element 0 of big integer - * @v reference0 Element 0 of reference big integer - * @v size Number of elements - * @ret geq Big integer is greater than or equal to the reference - */ -static inline __attribute__ (( always_inline, pure )) int -bigint_is_geq_raw ( const uint64_t *value0, const uint64_t *reference0, - unsigned int size ) { - const uint64_t *value = ( value0 + size ); - const uint64_t *reference = ( reference0 + size ); - uint64_t value_i; - uint64_t reference_i; - - do { - value_i = *(--value); - reference_i = *(--reference); - if ( value_i != reference_i ) - break; - } while ( --size ); - - return ( value_i >= reference_i ); -} - -/** - * Test if bit is set in big integer - * - * @v value0 Element 0 of big integer - * @v size Number of elements - * @v bit Bit to test - * @ret is_set Bit is set - */ -static inline __attribute__ (( always_inline )) int -bigint_bit_is_set_raw ( const uint64_t *value0, unsigned int size, - unsigned int bit ) { - const bigint_t ( size ) __attribute__ (( may_alias )) *value = - ( ( const void * ) value0 ); - unsigned int index = ( bit / ( 8 * sizeof ( value->element[0] ) ) ); - unsigned int subindex = ( bit % ( 8 * sizeof ( value->element[0] ) ) ); - - return ( !! ( value->element[index] & ( 1UL << subindex ) ) ); -} - -/** - * Find highest bit set in big integer - * - * @v value0 Element 0 of big integer - * @v size Number of elements - * @ret max_bit Highest bit set + 1 (or 0 if no bits set) - */ -static inline __attribute__ (( always_inline )) int -bigint_max_set_bit_raw ( const uint64_t *value0, unsigned int size ) { - const uint64_t *value = ( value0 + size ); - int max_bit = ( 8 * sizeof ( bigint_t ( size ) ) ); - uint64_t value_i; - - do { - value_i = *(--value); - max_bit -= ( 64 - fls ( value_i ) ); - if ( value_i ) - break; - } while ( --size ); - - return max_bit; -} - -/** - * Grow big integer - * - * @v source0 Element 0 of source big integer - * @v source_size Number of elements in source big integer - * @v dest0 Element 0 of destination big integer - * @v dest_size Number of elements in destination big integer - */ -static inline __attribute__ (( always_inline )) void -bigint_grow_raw ( const uint64_t *source0, unsigned int source_size, - uint64_t *dest0, unsigned int dest_size ) { - unsigned int pad_size = ( dest_size - source_size ); - - memcpy ( dest0, source0, sizeof ( bigint_t ( source_size ) ) ); - memset ( ( dest0 + source_size ), 0, sizeof ( bigint_t ( pad_size ) ) ); -} - -/** - * Shrink big integer - * - * @v source0 Element 0 of source big integer - * @v source_size Number of elements in source big integer - * @v dest0 Element 0 of destination big integer - * @v dest_size Number of elements in destination big integer - */ -static inline __attribute__ (( always_inline )) void -bigint_shrink_raw ( const uint64_t *source0, unsigned int source_size __unused, - uint64_t *dest0, unsigned int dest_size ) { - - memcpy ( dest0, source0, sizeof ( bigint_t ( dest_size ) ) ); -} - -/** - * Finalise big integer - * - * @v value0 Element 0 of big integer to finalise - * @v size Number of elements - * @v out Output buffer - * @v len Length of output buffer - */ -static inline __attribute__ (( always_inline )) void -bigint_done_raw ( const uint64_t *value0, unsigned int size __unused, - void *out, size_t len ) { - const uint8_t *value_byte = ( ( const void * ) value0 ); - uint8_t *out_byte = ( out + len ); - - /* Copy raw data in reverse order */ - while ( len-- ) - *(--out_byte) = *(value_byte++); -} - -extern void bigint_multiply_raw ( const uint64_t *multiplicand0, - const uint64_t *multiplier0, - uint64_t *value0, unsigned int size ); - -#endif /* _BITS_BIGINT_H */ diff --git a/roms/ipxe/src/arch/arm64/include/bits/bitops.h b/roms/ipxe/src/arch/arm64/include/bits/bitops.h deleted file mode 100644 index 4350f622a..000000000 --- a/roms/ipxe/src/arch/arm64/include/bits/bitops.h +++ /dev/null @@ -1,100 +0,0 @@ -#ifndef _BITS_BITOPS_H -#define _BITS_BITOPS_H - -/** @file - * - * ARM bit operations - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#include <stdint.h> - -/** - * Test and set bit atomically - * - * @v bit Bit to set - * @v bits Bit field - * @ret old Old value of bit (zero or non-zero) - */ -static inline __attribute__ (( always_inline )) int -test_and_set_bit ( unsigned int bit, volatile void *bits ) { - unsigned int index = ( bit / 64 ); - unsigned int offset = ( bit % 64 ); - volatile uint64_t *qword = ( ( ( volatile uint64_t * ) bits ) + index ); - uint64_t mask = ( 1UL << offset ); - uint64_t old; - uint64_t new; - uint32_t flag; - - __asm__ __volatile__ ( "\n1:\n\t" - "ldxr %0, %3\n\t" - "orr %1, %0, %4\n\t" - "stxr %w2, %1, %3\n\t" - "tst %w2, %w2\n\t" - "bne 1b\n\t" - : "=&r" ( old ), "=&r" ( new ), "=&r" ( flag ), - "+Q" ( *qword ) - : "r" ( mask ) - : "cc" ); - - return ( !! ( old & mask ) ); -} - -/** - * Test and clear bit atomically - * - * @v bit Bit to set - * @v bits Bit field - * @ret old Old value of bit (zero or non-zero) - */ -static inline __attribute__ (( always_inline )) int -test_and_clear_bit ( unsigned int bit, volatile void *bits ) { - unsigned int index = ( bit / 64 ); - unsigned int offset = ( bit % 64 ); - volatile uint64_t *qword = ( ( ( volatile uint64_t * ) bits ) + index ); - uint64_t mask = ( 1UL << offset ); - uint64_t old; - uint64_t new; - uint32_t flag; - - __asm__ __volatile__ ( "\n1:\n\t" - "ldxr %0, %3\n\t" - "bic %1, %0, %4\n\t" - "stxr %w2, %1, %3\n\t" - "tst %w2, %w2\n\t" - "bne 1b\n\t" - : "=&r" ( old ), "=&r" ( new ), "=&r" ( flag ), - "+Q" ( *qword ) - : "r" ( mask ) - : "cc" ); - - return ( !! ( old & mask ) ); -} - -/** - * Set bit atomically - * - * @v bit Bit to set - * @v bits Bit field - */ -static inline __attribute__ (( always_inline )) void -set_bit ( unsigned int bit, volatile void *bits ) { - - test_and_set_bit ( bit, bits ); -} - -/** - * Clear bit atomically - * - * @v bit Bit to set - * @v bits Bit field - */ -static inline __attribute__ (( always_inline )) void -clear_bit ( unsigned int bit, volatile void *bits ) { - - test_and_clear_bit ( bit, bits ); -} - -#endif /* _BITS_BITOPS_H */ diff --git a/roms/ipxe/src/arch/arm64/include/bits/byteswap.h b/roms/ipxe/src/arch/arm64/include/bits/byteswap.h deleted file mode 100644 index 169d6c20e..000000000 --- a/roms/ipxe/src/arch/arm64/include/bits/byteswap.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef _BITS_BYTESWAP_H -#define _BITS_BYTESWAP_H - -/** @file - * - * Byte-order swapping functions - * - */ - -#include <stdint.h> - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -static inline __attribute__ (( always_inline, const )) uint16_t -__bswap_variable_16 ( uint16_t x ) { - __asm__ ( "rev16 %0, %1" : "=r" ( x ) : "r" ( x ) ); - return x; -} - -static inline __attribute__ (( always_inline )) void -__bswap_16s ( uint16_t *x ) { - *x = __bswap_variable_16 ( *x ); -} - -static inline __attribute__ (( always_inline, const )) uint32_t -__bswap_variable_32 ( uint32_t x ) { - __asm__ ( "rev32 %0, %1" : "=r" ( x ) : "r" ( x ) ); - return x; -} - -static inline __attribute__ (( always_inline )) void -__bswap_32s ( uint32_t *x ) { - *x = __bswap_variable_32 ( *x ); -} - -static inline __attribute__ (( always_inline, const )) uint64_t -__bswap_variable_64 ( uint64_t x ) { - __asm__ ( "rev %0, %1" : "=r" ( x ) : "r" ( x ) ); - return x; -} - -static inline __attribute__ (( always_inline )) void -__bswap_64s ( uint64_t *x ) { - *x = __bswap_variable_64 ( *x ); -} - -#endif diff --git a/roms/ipxe/src/arch/arm64/include/bits/compiler.h b/roms/ipxe/src/arch/arm64/include/bits/compiler.h deleted file mode 100644 index 3b129c2fd..000000000 --- a/roms/ipxe/src/arch/arm64/include/bits/compiler.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef _BITS_COMPILER_H -#define _BITS_COMPILER_H - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -/** Dummy relocation type */ -#define RELOC_TYPE_NONE R_AARCH64_NULL - -#ifndef ASSEMBLY - -#define __asmcall -#define __libgcc - -#endif /* ASSEMBLY */ - -#endif /*_BITS_COMPILER_H */ diff --git a/roms/ipxe/src/arch/arm64/include/bits/profile.h b/roms/ipxe/src/arch/arm64/include/bits/profile.h deleted file mode 100644 index 62ffa3772..000000000 --- a/roms/ipxe/src/arch/arm64/include/bits/profile.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef _BITS_PROFILE_H -#define _BITS_PROFILE_H - -/** @file - * - * Profiling - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#include <stdint.h> - -/** - * Get profiling timestamp - * - * @ret timestamp Timestamp - */ -static inline __attribute__ (( always_inline )) uint64_t -profile_timestamp ( void ) { - uint64_t cycles; - - /* Read cycle counter */ - __asm__ __volatile__ ( "mrs %0, CNTVCT_EL0\n\t" : "=r" ( cycles ) ); - return cycles; -} - -#endif /* _BITS_PROFILE_H */ diff --git a/roms/ipxe/src/arch/arm64/include/bits/stdint.h b/roms/ipxe/src/arch/arm64/include/bits/stdint.h deleted file mode 100644 index 9eb72e9c4..000000000 --- a/roms/ipxe/src/arch/arm64/include/bits/stdint.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef _BITS_STDINT_H -#define _BITS_STDINT_H - -typedef __SIZE_TYPE__ size_t; -typedef signed long ssize_t; -typedef signed long off_t; - -typedef unsigned char uint8_t; -typedef unsigned short uint16_t; -typedef unsigned int uint32_t; -typedef unsigned long long uint64_t; - -typedef signed char int8_t; -typedef signed short int16_t; -typedef signed int int32_t; -typedef signed long long int64_t; - -typedef unsigned long physaddr_t; -typedef unsigned long intptr_t; - -#endif /* _BITS_STDINT_H */ diff --git a/roms/ipxe/src/arch/arm64/include/bits/string.h b/roms/ipxe/src/arch/arm64/include/bits/string.h deleted file mode 100644 index c05fbe346..000000000 --- a/roms/ipxe/src/arch/arm64/include/bits/string.h +++ /dev/null @@ -1,106 +0,0 @@ -#ifndef BITS_STRING_H -#define BITS_STRING_H - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -/** @file - * - * String functions - * - */ - -extern void arm64_bzero ( void *dest, size_t len ); -extern void arm64_memset ( void *dest, size_t len, int character ); -extern void arm64_memcpy ( void *dest, const void *src, size_t len ); -extern void arm64_memmove_forwards ( void *dest, const void *src, size_t len ); -extern void arm64_memmove_backwards ( void *dest, const void *src, size_t len ); -extern void arm64_memmove ( void *dest, const void *src, size_t len ); - -/** - * Fill memory region - * - * @v dest Destination region - * @v character Fill character - * @v len Length - * @ret dest Destination region - */ -static inline __attribute__ (( always_inline )) void * -memset ( void *dest, int character, size_t len ) { - - /* Allow gcc to generate inline "stX xzr" instructions for - * small, constant lengths. - */ - if ( __builtin_constant_p ( character ) && ( character == 0 ) && - __builtin_constant_p ( len ) && ( len <= 64 ) ) { - __builtin_memset ( dest, 0, len ); - return dest; - } - - /* For zeroing larger or non-constant lengths, use the - * optimised variable-length zeroing code. - */ - if ( __builtin_constant_p ( character ) && ( character == 0 ) ) { - arm64_bzero ( dest, len ); - return dest; - } - - /* Not necessarily zeroing: use basic variable-length code */ - arm64_memset ( dest, len, character ); - return dest; -} - -/** - * Copy memory region - * - * @v dest Destination region - * @v src Source region - * @v len Length - * @ret dest Destination region - */ -static inline __attribute__ (( always_inline )) void * -memcpy ( void *dest, const void *src, size_t len ) { - - /* Allow gcc to generate inline "ldX"/"stX" instructions for - * small, constant lengths. - */ - if ( __builtin_constant_p ( len ) && ( len <= 64 ) ) { - __builtin_memcpy ( dest, src, len ); - return dest; - } - - /* Otherwise, use variable-length code */ - arm64_memcpy ( dest, src, len ); - return dest; -} - -/** - * Copy (possibly overlapping) memory region - * - * @v dest Destination region - * @v src Source region - * @v len Length - * @ret dest Destination region - */ -static inline __attribute__ (( always_inline )) void * -memmove ( void *dest, const void *src, size_t len ) { - ssize_t offset = ( dest - src ); - - /* If required direction of copy is known at build time, then - * use the appropriate forwards/backwards copy directly. - */ - if ( __builtin_constant_p ( offset ) ) { - if ( offset <= 0 ) { - arm64_memmove_forwards ( dest, src, len ); - return dest; - } else { - arm64_memmove_backwards ( dest, src, len ); - return dest; - } - } - - /* Otherwise, use ambidirectional copy */ - arm64_memmove ( dest, src, len ); - return dest; -} - -#endif /* BITS_STRING_H */ diff --git a/roms/ipxe/src/arch/arm64/include/bits/strings.h b/roms/ipxe/src/arch/arm64/include/bits/strings.h deleted file mode 100644 index d5340f484..000000000 --- a/roms/ipxe/src/arch/arm64/include/bits/strings.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef _BITS_STRINGS_H -#define _BITS_STRINGS_H - -/** @file - * - * String functions - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -/** - * Find first (i.e. least significant) set bit - * - * @v value Value - * @ret lsb Least significant bit set in value (LSB=1), or zero - */ -static inline __attribute__ (( always_inline )) int __ffsll ( long long value ){ - unsigned long long bits = value; - unsigned long long lsb; - unsigned int lz; - - /* Extract least significant set bit */ - lsb = ( bits & -bits ); - - /* Count number of leading zeroes before LSB */ - __asm__ ( "clz %0, %1" : "=r" ( lz ) : "r" ( lsb ) ); - - return ( 64 - lz ); -} - -/** - * Find first (i.e. least significant) set bit - * - * @v value Value - * @ret lsb Least significant bit set in value (LSB=1), or zero - */ -static inline __attribute__ (( always_inline )) int __ffsl ( long value ) { - - return __ffsll ( value ); -} - -/** - * Find last (i.e. most significant) set bit - * - * @v value Value - * @ret msb Most significant bit set in value (LSB=1), or zero - */ -static inline __attribute__ (( always_inline )) int __flsll ( long long value ){ - unsigned int lz; - - /* Count number of leading zeroes */ - __asm__ ( "clz %0, %1" : "=r" ( lz ) : "r" ( value ) ); - - return ( 64 - lz ); -} - -/** - * Find last (i.e. most significant) set bit - * - * @v value Value - * @ret msb Most significant bit set in value (LSB=1), or zero - */ -static inline __attribute__ (( always_inline )) int __flsl ( long value ) { - - return __flsll ( value ); -} - -#endif /* _BITS_STRINGS_H */ diff --git a/roms/ipxe/src/arch/arm64/include/bits/tcpip.h b/roms/ipxe/src/arch/arm64/include/bits/tcpip.h deleted file mode 100644 index 68686534e..000000000 --- a/roms/ipxe/src/arch/arm64/include/bits/tcpip.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef _BITS_TCPIP_H -#define _BITS_TCPIP_H - -/** @file - * - * Transport-network layer interface - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -extern uint16_t tcpip_continue_chksum ( uint16_t sum, const void *data, - size_t len ); - -#endif /* _BITS_TCPIP_H */ diff --git a/roms/ipxe/src/arch/arm64/include/efi/ipxe/dhcp_arch.h b/roms/ipxe/src/arch/arm64/include/efi/ipxe/dhcp_arch.h deleted file mode 100644 index 48a36d052..000000000 --- a/roms/ipxe/src/arch/arm64/include/efi/ipxe/dhcp_arch.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2015 Michael Brown <mbrown@fensystems.co.uk>. - * - * 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 (at your option) 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. - */ - -#ifndef _DHCP_ARCH_H -#define _DHCP_ARCH_H - -/** @file - * - * Architecture-specific DHCP options - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#include <ipxe/dhcp.h> - -#define DHCP_ARCH_VENDOR_CLASS_ID \ - DHCP_STRING ( 'P', 'X', 'E', 'C', 'l', 'i', 'e', 'n', 't', ':', \ - 'A', 'r', 'c', 'h', ':', '0', '0', '0', '0', '7', ':', \ - 'U', 'N', 'D', 'I', ':', '0', '0', '3', '0', '1', '0' ) - -#define DHCP_ARCH_CLIENT_ARCHITECTURE \ - DHCP_WORD ( DHCP_CLIENT_ARCHITECTURE_ARM64 ) - -#define DHCP_ARCH_CLIENT_NDI DHCP_OPTION ( 1 /* UNDI */ , 3, 10 /* v3.10 */ ) - -#endif diff --git a/roms/ipxe/src/arch/arm64/include/gdbmach.h b/roms/ipxe/src/arch/arm64/include/gdbmach.h deleted file mode 100644 index cd152eedd..000000000 --- a/roms/ipxe/src/arch/arm64/include/gdbmach.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef GDBMACH_H -#define GDBMACH_H - -/** @file - * - * GDB architecture specifics - * - * This file declares functions for manipulating the machine state and - * debugging context. - * - */ - -#include <stdint.h> - -typedef unsigned long gdbreg_t; - -/* Register snapshot */ -enum { - /* Not yet implemented */ - GDBMACH_NREGS, -}; - -#define GDBMACH_SIZEOF_REGS ( GDBMACH_NREGS * sizeof ( gdbreg_t ) ) - -static inline void gdbmach_set_pc ( gdbreg_t *regs, gdbreg_t pc ) { - /* Not yet implemented */ - ( void ) regs; - ( void ) pc; -} - -static inline void gdbmach_set_single_step ( gdbreg_t *regs, int step ) { - /* Not yet implemented */ - ( void ) regs; - ( void ) step; -} - -static inline void gdbmach_breakpoint ( void ) { - /* Not yet implemented */ -} - -extern int gdbmach_set_breakpoint ( int type, unsigned long addr, size_t len, - int enable ); -extern void gdbmach_init ( void ); - -#endif /* GDBMACH_H */ diff --git a/roms/ipxe/src/arch/arm64/include/limits.h b/roms/ipxe/src/arch/arm64/include/limits.h deleted file mode 100644 index 8cf87b471..000000000 --- a/roms/ipxe/src/arch/arm64/include/limits.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef LIMITS_H -#define LIMITS_H 1 - -/* Number of bits in a `char' */ -#define CHAR_BIT 8 - -/* Minimum and maximum values a `signed char' can hold */ -#define SCHAR_MIN (-128) -#define SCHAR_MAX 127 - -/* Maximum value an `unsigned char' can hold. (Minimum is 0.) */ -#define UCHAR_MAX 255 - -/* Minimum and maximum values a `char' can hold */ -#define CHAR_MIN SCHAR_MIN -#define CHAR_MAX SCHAR_MAX - -/* Minimum and maximum values a `signed short int' can hold */ -#define SHRT_MIN (-32768) -#define SHRT_MAX 32767 - -/* Maximum value an `unsigned short' can hold. (Minimum is 0.) */ -#define USHRT_MAX 65535 - - -/* Minimum and maximum values a `signed int' can hold */ -#define INT_MIN (-INT_MAX - 1) -#define INT_MAX 2147483647 - -/* Maximum value an `unsigned int' can hold. (Minimum is 0.) */ -#define UINT_MAX 4294967295U - - -/* Minimum and maximum values a `signed int' can hold */ -#define INT_MAX 2147483647 -#define INT_MIN (-INT_MAX - 1) - - -/* Maximum value an `unsigned int' can hold. (Minimum is 0.) */ -#define UINT_MAX 4294967295U - - -/* Minimum and maximum values a `signed long' can hold */ -#define LONG_MAX 9223372036854775807L -#define LONG_MIN (-LONG_MAX - 1L) - -/* Maximum value an `unsigned long' can hold. (Minimum is 0.) */ -#define ULONG_MAX 18446744073709551615UL - -/* Minimum and maximum values a `signed long long' can hold */ -#define LLONG_MAX 9223372036854775807LL -#define LLONG_MIN (-LONG_MAX - 1LL) - - -/* Maximum value an `unsigned long long' can hold. (Minimum is 0.) */ -#define ULLONG_MAX 18446744073709551615ULL - - -#endif /* LIMITS_H */ diff --git a/roms/ipxe/src/arch/arm64/include/setjmp.h b/roms/ipxe/src/arch/arm64/include/setjmp.h deleted file mode 100644 index 85a7a9cad..000000000 --- a/roms/ipxe/src/arch/arm64/include/setjmp.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef _SETJMP_H -#define _SETJMP_H - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#include <stdint.h> - -/** A jump buffer */ -typedef struct { - /** Saved x19 */ - uint64_t x19; - /** Saved x20 */ - uint64_t x20; - /** Saved x21 */ - uint64_t x21; - /** Saved x22 */ - uint64_t x22; - /** Saved x23 */ - uint64_t x23; - /** Saved x24 */ - uint64_t x24; - /** Saved x25 */ - uint64_t x25; - /** Saved x26 */ - uint64_t x26; - /** Saved x27 */ - uint64_t x27; - /** Saved x28 */ - uint64_t x28; - /** Saved frame pointer (x29) */ - uint64_t x29; - /** Saved link register (x30) */ - uint64_t x30; - /** Saved stack pointer (x31) */ - uint64_t sp; -} jmp_buf[1]; - -extern int __asmcall __attribute__ (( returns_twice )) -setjmp ( jmp_buf env ); - -extern void __asmcall __attribute__ (( noreturn )) -longjmp ( jmp_buf env, int val ); - -#endif /* _SETJMP_H */ diff --git a/roms/ipxe/src/arch/i386/Makefile b/roms/ipxe/src/arch/i386/Makefile index fe3adc9ce..99f875314 100644 --- a/roms/ipxe/src/arch/i386/Makefile +++ b/roms/ipxe/src/arch/i386/Makefile @@ -80,10 +80,34 @@ PIE_FLAGS := $(shell $(PIE_TEST) && $(ECHO) '-fno-PIE -nopie') WORKAROUND_CFLAGS += $(PIE_FLAGS) endif +# Define version string for lkrnprefix.S +# +CFLAGS_lkrnprefix += -DVERSION="\"$(VERSION)\"" + +# Locations of utilities +# +ISOLINUX_BIN_LIST := \ + $(ISOLINUX_BIN) \ + /usr/lib/syslinux/isolinux.bin \ + /usr/lib/syslinux/bios/isolinux.bin \ + /usr/share/syslinux/isolinux.bin \ + /usr/share/syslinux/bios/isolinux.bin \ + /usr/local/share/syslinux/isolinux.bin \ + /usr/local/share/syslinux/bios/isolinux.bin \ + /usr/lib/ISOLINUX/isolinux.bin +ISOLINUX_BIN = $(firstword $(wildcard $(ISOLINUX_BIN_LIST))) + # i386-specific directories containing source files # -SRCDIRS += arch/i386/core -SRCDIRS += arch/i386/tests +SRCDIRS += arch/i386/core arch/i386/transitions arch/i386/prefix +SRCDIRS += arch/i386/firmware/pcbios +SRCDIRS += arch/i386/image +SRCDIRS += arch/i386/interface/pcbios +SRCDIRS += arch/i386/interface/pxe +SRCDIRS += arch/i386/interface/pxeparent +SRCDIRS += arch/i386/interface/syslinux +SRCDIRS += arch/i386/interface/vmware +SRCDIRS += arch/i386/hci/commands # Include common x86 Makefile # diff --git a/roms/ipxe/src/arch/i386/Makefile.efi b/roms/ipxe/src/arch/i386/Makefile.efi index 37ede65ac..aa809eb5d 100644 --- a/roms/ipxe/src/arch/i386/Makefile.efi +++ b/roms/ipxe/src/arch/i386/Makefile.efi @@ -8,10 +8,6 @@ ELF2EFI = $(ELF2EFI32) # CFLAGS += -malign-double -# Specify EFI boot file -# -EFI_BOOT_FILE = bootia32.efi - # Include generic EFI Makefile # MAKEDEPS += arch/x86/Makefile.efi diff --git a/roms/ipxe/src/arch/i386/Makefile.pcbios b/roms/ipxe/src/arch/i386/Makefile.pcbios index dfb8db0a0..ff823737d 100644 --- a/roms/ipxe/src/arch/i386/Makefile.pcbios +++ b/roms/ipxe/src/arch/i386/Makefile.pcbios @@ -1,6 +1,100 @@ # -*- makefile -*- : Force emacs to use Makefile mode -# Include generic BIOS Makefile +# The i386 linker script # -MAKEDEPS += arch/x86/Makefile.pcbios -include arch/x86/Makefile.pcbios +LDSCRIPT = arch/i386/scripts/i386.lds + +# Stop ld from complaining about our customised linker script +# +LDFLAGS += -N --no-check-sections + +# pcbios specific drivers +SRCDIRS += arch/i386/drivers +SRCDIRS += arch/i386/drivers/net + +# Media types. +# +MEDIA += rom +MEDIA += mrom +MEDIA += pcirom +MEDIA += isarom +MEDIA += pxe +MEDIA += kpxe +MEDIA += kkpxe +MEDIA += kkkpxe +MEDIA += lkrn +MEDIA += dsk +MEDIA += nbi +MEDIA += hd +MEDIA += raw +MEDIA += exe + +# Padding rules +# +PAD_rom = $(PERL) $(PADIMG) --blksize=512 --byte=0xff +PAD_mrom = $(PAD_rom) +PAD_pcirom = $(PAD_rom) +PAD_isarom = $(PAD_rom) +PAD_dsk = $(PERL) $(PADIMG) --blksize=512 +PAD_hd = $(PERL) $(PADIMG) --blksize=32768 +PAD_exe = $(PERL) $(PADIMG) --blksize=512 + +# Finalisation rules +# +FINALISE_rom = $(PERL) $(FIXROM) +FINALISE_mrom = $(FINALISE_rom) +FINALISE_pcirom = $(FINALISE_rom) +FINALISE_isarom = $(FINALISE_rom) + +# Use $(ROMS) rather than $(DRIVERS) for "allroms", "allmroms", etc. +# +LIST_NAME_rom := ROMS +LIST_NAME_mrom := ROMS +LIST_NAME_pcirom := ROMS +LIST_NAME_isarom := ROMS + +# rule to make a non-emulation ISO boot image +NON_AUTO_MEDIA += iso +%iso: %lkrn util/geniso + $(QM)$(ECHO) " [GENISO] $@" + $(Q)ISOLINUX_BIN=$(ISOLINUX_BIN) VERSION="$(VERSION)" bash util/geniso -o $@ $< + +# rule to make a floppy emulation ISO boot image +NON_AUTO_MEDIA += liso +%liso: %lkrn util/geniso + $(QM)$(ECHO) " [GENISO] $@" + $(Q)VERSION="$(VERSION)" bash util/geniso -l -o $@ $< + +# rule to make a syslinux floppy image (mountable, bootable) +NON_AUTO_MEDIA += sdsk +%sdsk: %lkrn util/gensdsk + $(QM)$(ECHO) " [GENSDSK] $@" + $(Q)bash util/gensdsk $@ $< + +# rule to write disk images to /dev/fd0 +NON_AUTO_MEDIA += fd0 +%fd0 : %dsk + $(QM)$(ECHO) " [DD] $@" + $(Q)dd if=$< bs=512 conv=sync of=/dev/fd0 + $(Q)sync + +# Special target for building Master Boot Record binary +$(BIN)/mbr.bin : $(BIN)/mbr.o + $(QM)$(ECHO) " [OBJCOPY] $@" + $(Q)$(OBJCOPY) -O binary $< $@ + +# rule to make a USB disk image +$(BIN)/usbdisk.bin : $(BIN)/usbdisk.o + $(QM)$(ECHO) " [OBJCOPY] $@" + $(Q)$(OBJCOPY) -O binary $< $@ + +NON_AUTO_MEDIA += usb +%usb: $(BIN)/usbdisk.bin %hd + $(QM)$(ECHO) " [FINISH] $@" + $(Q)cat $^ > $@ + +# Padded floppy image (e.g. for iLO) +NON_AUTO_MEDIA += pdsk +%pdsk : %dsk + $(Q)cp $< $@ + $(Q)$(PADIMG) --blksize=1474560 $@ diff --git a/roms/ipxe/src/arch/x86/core/basemem_packet.c b/roms/ipxe/src/arch/i386/core/basemem_packet.c index 9f5fbf330..9f5fbf330 100644 --- a/roms/ipxe/src/arch/x86/core/basemem_packet.c +++ b/roms/ipxe/src/arch/i386/core/basemem_packet.c diff --git a/roms/ipxe/src/arch/x86/core/cachedhcp.c b/roms/ipxe/src/arch/i386/core/cachedhcp.c index ff35b9256..a5c624035 100644 --- a/roms/ipxe/src/arch/x86/core/cachedhcp.c +++ b/roms/ipxe/src/arch/i386/core/cachedhcp.c @@ -58,7 +58,6 @@ static void cachedhcp_init ( void ) { struct dhcp_packet *dhcppkt; struct dhcp_packet *tmp; struct dhcphdr *dhcphdr; - size_t max_len; size_t len; /* Do nothing if no cached DHCPACK is present */ @@ -70,25 +69,23 @@ static void cachedhcp_init ( void ) { /* No reliable way to determine length before parsing packet; * start by assuming maximum length permitted by PXE. */ - max_len = sizeof ( BOOTPLAYER_t ); + len = sizeof ( BOOTPLAYER_t ); /* Allocate and populate DHCP packet */ - dhcppkt = zalloc ( sizeof ( *dhcppkt ) + max_len ); + dhcppkt = zalloc ( sizeof ( *dhcppkt ) + len ); if ( ! dhcppkt ) { DBGC ( colour, "CACHEDHCP could not allocate copy\n" ); return; } dhcphdr = ( ( ( void * ) dhcppkt ) + sizeof ( *dhcppkt ) ); copy_from_user ( dhcphdr, phys_to_user ( cached_dhcpack_phys ), 0, - max_len ); - dhcppkt_init ( dhcppkt, dhcphdr, max_len ); + len ); + dhcppkt_init ( dhcppkt, dhcphdr, len ); - /* Shrink packet to required length. If reallocation fails, - * just continue to use the original packet and waste the - * unused space. + /* Resize packet to required length. If reallocation fails, + * just continue to use the original packet. */ len = dhcppkt_len ( dhcppkt ); - assert ( len <= max_len ); tmp = realloc ( dhcppkt, ( sizeof ( *dhcppkt ) + len ) ); if ( tmp ) dhcppkt = tmp; diff --git a/roms/ipxe/src/arch/x86/core/dumpregs.c b/roms/ipxe/src/arch/i386/core/dumpregs.c index 37d62a7b6..82dc21847 100644 --- a/roms/ipxe/src/arch/x86/core/dumpregs.c +++ b/roms/ipxe/src/arch/i386/core/dumpregs.c @@ -6,8 +6,11 @@ void __asmcall _dump_regs ( struct i386_all_regs *ix86 ) { __asm__ __volatile__ ( TEXT16_CODE ( ".globl dump_regs\n\t" "\ndump_regs:\n\t" - VIRT_CALL ( _dump_regs ) - "ret\n\t" ) ); + "pushl $_dump_regs\n\t" + "pushw %%cs\n\t" + "call prot_call\n\t" + "addr32 leal 4(%%esp), %%esp\n\t" + "ret\n\t" ) : : ); printf ( "EAX=%08x EBX=%08x ECX=%08x EDX=%08x\n" "ESI=%08x EDI=%08x EBP=%08x ESP=%08x\n" diff --git a/roms/ipxe/src/arch/i386/core/gdbidt.S b/roms/ipxe/src/arch/i386/core/gdbidt.S index 666ecce3c..a1e309d7c 100644 --- a/roms/ipxe/src/arch/i386/core/gdbidt.S +++ b/roms/ipxe/src/arch/i386/core/gdbidt.S @@ -15,29 +15,41 @@ /* POSIX signal numbers for reporting traps to GDB */ #define SIGILL 4 #define SIGTRAP 5 +#define SIGBUS 7 #define SIGFPE 8 +#define SIGSEGV 11 #define SIGSTKFLT 16 - .globl gdbmach_sigfpe -gdbmach_sigfpe: + .globl gdbmach_nocode_sigfpe +gdbmach_nocode_sigfpe: pushl $SIGFPE jmp gdbmach_interrupt - .globl gdbmach_sigtrap -gdbmach_sigtrap: + .globl gdbmach_nocode_sigtrap +gdbmach_nocode_sigtrap: pushl $SIGTRAP jmp gdbmach_interrupt - .globl gdbmach_sigstkflt -gdbmach_sigstkflt: + .globl gdbmach_nocode_sigstkflt +gdbmach_nocode_sigstkflt: pushl $SIGSTKFLT jmp gdbmach_interrupt - .globl gdbmach_sigill -gdbmach_sigill: + .globl gdbmach_nocode_sigill +gdbmach_nocode_sigill: pushl $SIGILL jmp gdbmach_interrupt + .globl gdbmach_withcode_sigbus +gdbmach_withcode_sigbus: + movl $SIGBUS, (%esp) + jmp gdbmach_interrupt + + .globl gdbmach_withcode_sigsegv +gdbmach_withcode_sigsegv: + movl $SIGSEGV, (%esp) + jmp gdbmach_interrupt + /* When invoked, the stack contains: eflags, cs, eip, signo. */ #define IH_OFFSET_GDB_REGS ( 0 ) #define IH_OFFSET_GDB_EIP ( IH_OFFSET_GDB_REGS + SIZEOF_I386_REGS ) diff --git a/roms/ipxe/src/arch/i386/core/gdbmach.c b/roms/ipxe/src/arch/i386/core/gdbmach.c new file mode 100644 index 000000000..d92a4ac08 --- /dev/null +++ b/roms/ipxe/src/arch/i386/core/gdbmach.c @@ -0,0 +1,184 @@ +/* + * Copyright (C) 2008 Stefan Hajnoczi <stefanha@gmail.com>. + * + * 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 <stddef.h> +#include <stdio.h> +#include <assert.h> +#include <ipxe/uaccess.h> +#include <ipxe/gdbstub.h> +#include <librm.h> +#include <gdbmach.h> + +/** @file + * + * GDB architecture-specific bits for i386 + * + */ + +enum { + DR7_CLEAR = 0x00000400, /* disable hardware breakpoints */ + DR6_CLEAR = 0xffff0ff0, /* clear breakpoint status */ +}; + +/** Hardware breakpoint, fields stored in x86 bit pattern form */ +struct hwbp { + int type; /* type (1=write watchpoint, 3=access watchpoint) */ + unsigned long addr; /* linear address */ + size_t len; /* length (0=1-byte, 1=2-byte, 3=4-byte) */ + int enabled; +}; + +static struct hwbp hwbps [ 4 ]; +static gdbreg_t dr7 = DR7_CLEAR; + +static struct hwbp *gdbmach_find_hwbp ( int type, unsigned long addr, size_t len ) { + struct hwbp *available = NULL; + unsigned int i; + for ( i = 0; i < sizeof hwbps / sizeof hwbps [ 0 ]; i++ ) { + if ( hwbps [ i ].type == type && hwbps [ i ].addr == addr && hwbps [ i ].len == len ) { + return &hwbps [ i ]; + } + if ( !hwbps [ i ].enabled ) { + available = &hwbps [ i ]; + } + } + return available; +} + +static void gdbmach_commit_hwbp ( struct hwbp *bp ) { + unsigned int regnum = bp - hwbps; + + /* Set breakpoint address */ + assert ( regnum < ( sizeof hwbps / sizeof hwbps [ 0 ] ) ); + switch ( regnum ) { + case 0: + __asm__ __volatile__ ( "movl %0, %%dr0\n" : : "r" ( bp->addr ) ); + break; + case 1: + __asm__ __volatile__ ( "movl %0, %%dr1\n" : : "r" ( bp->addr ) ); + break; + case 2: + __asm__ __volatile__ ( "movl %0, %%dr2\n" : : "r" ( bp->addr ) ); + break; + case 3: + __asm__ __volatile__ ( "movl %0, %%dr3\n" : : "r" ( bp->addr ) ); + break; + } + + /* Set type */ + dr7 &= ~( 0x3 << ( 16 + 4 * regnum ) ); + dr7 |= bp->type << ( 16 + 4 * regnum ); + + /* Set length */ + dr7 &= ~( 0x3 << ( 18 + 4 * regnum ) ); + dr7 |= bp->len << ( 18 + 4 * regnum ); + + /* Set/clear local enable bit */ + dr7 &= ~( 0x3 << 2 * regnum ); + dr7 |= bp->enabled << 2 * regnum; +} + +int gdbmach_set_breakpoint ( int type, unsigned long addr, size_t len, int enable ) { + struct hwbp *bp; + + /* Check and convert breakpoint type to x86 type */ + switch ( type ) { + case GDBMACH_WATCH: + type = 0x1; + break; + case GDBMACH_AWATCH: + type = 0x3; + break; + default: + return 0; /* unsupported breakpoint type */ + } + + /* Only lengths 1, 2, and 4 are supported */ + if ( len != 2 && len != 4 ) { + len = 1; + } + len--; /* convert to x86 breakpoint length bit pattern */ + + /* Calculate linear address by adding segment base */ + addr += virt_offset; + + /* Set up the breakpoint */ + bp = gdbmach_find_hwbp ( type, addr, len ); + if ( !bp ) { + return 0; /* ran out of hardware breakpoints */ + } + bp->type = type; + bp->addr = addr; + bp->len = len; + bp->enabled = enable; + gdbmach_commit_hwbp ( bp ); + return 1; +} + +static void gdbmach_disable_hwbps ( void ) { + /* Store and clear hardware breakpoints */ + __asm__ __volatile__ ( "movl %0, %%dr7\n" : : "r" ( DR7_CLEAR ) ); +} + +static void gdbmach_enable_hwbps ( void ) { + /* Clear breakpoint status register */ + __asm__ __volatile__ ( "movl %0, %%dr6\n" : : "r" ( DR6_CLEAR ) ); + + /* Restore hardware breakpoints */ + __asm__ __volatile__ ( "movl %0, %%dr7\n" : : "r" ( dr7 ) ); +} + +__asmcall void gdbmach_handler ( int signo, gdbreg_t *regs ) { + gdbmach_disable_hwbps(); + gdbstub_handler ( signo, regs ); + gdbmach_enable_hwbps(); +} + +static void * gdbmach_interrupt_vectors[] = { + gdbmach_nocode_sigfpe, /* Divide by zero */ + gdbmach_nocode_sigtrap, /* Debug trap */ + NULL, /* Non-maskable interrupt */ + gdbmach_nocode_sigtrap, /* Breakpoint */ + gdbmach_nocode_sigstkflt, /* Overflow */ + gdbmach_nocode_sigstkflt, /* Bound range exceeded */ + gdbmach_nocode_sigill, /* Invalid opcode */ + NULL, /* Device not available */ + gdbmach_withcode_sigbus, /* Double fault */ + NULL, /* Coprocessor segment overrun */ + gdbmach_withcode_sigsegv, /* Invalid TSS */ + gdbmach_withcode_sigsegv, /* Segment not present */ + gdbmach_withcode_sigsegv, /* Stack segment fault */ + gdbmach_withcode_sigsegv, /* General protection fault */ + gdbmach_withcode_sigsegv, /* Page fault */ +}; + +void gdbmach_init ( void ) { + unsigned int i; + + for ( i = 0 ; i < ( sizeof ( gdbmach_interrupt_vectors ) / + sizeof ( gdbmach_interrupt_vectors[0] ) ) ; i++ ) { + set_interrupt_vector ( i, gdbmach_interrupt_vectors[i] ); + } +} diff --git a/roms/ipxe/src/arch/x86/core/patch_cf.S b/roms/ipxe/src/arch/i386/core/patch_cf.S index 4365563fe..4365563fe 100644 --- a/roms/ipxe/src/arch/x86/core/patch_cf.S +++ b/roms/ipxe/src/arch/i386/core/patch_cf.S diff --git a/roms/ipxe/src/arch/x86/core/pci_autoboot.c b/roms/ipxe/src/arch/i386/core/pci_autoboot.c index 337598091..337598091 100644 --- a/roms/ipxe/src/arch/x86/core/pci_autoboot.c +++ b/roms/ipxe/src/arch/i386/core/pci_autoboot.c diff --git a/roms/ipxe/src/arch/x86/core/rdtsc_timer.c b/roms/ipxe/src/arch/i386/core/rdtsc_timer.c index e720a239c..e720a239c 100644 --- a/roms/ipxe/src/arch/x86/core/rdtsc_timer.c +++ b/roms/ipxe/src/arch/i386/core/rdtsc_timer.c diff --git a/roms/ipxe/src/arch/x86/core/relocate.c b/roms/ipxe/src/arch/i386/core/relocate.c index 765d46560..54ad387e4 100644 --- a/roms/ipxe/src/arch/x86/core/relocate.c +++ b/roms/ipxe/src/arch/i386/core/relocate.c @@ -10,6 +10,14 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); +/* + * The linker passes in the symbol _max_align, which is the alignment + * that we must preserve, in bytes. + * + */ +extern char _max_align[]; +#define max_align ( ( unsigned int ) _max_align ) + /* Linker symbols */ extern char _textdata[]; extern char _etextdata[]; @@ -22,12 +30,6 @@ extern char _etextdata[]; */ #define MAX_ADDR (0xfff00000UL) -/* Preserve alignment to a 4kB page - * - * Required for x86_64, and doesn't hurt for i386. - */ -#define ALIGN 4096 - /** * Relocate iPXE * @@ -42,8 +44,8 @@ extern char _etextdata[]; */ __asmcall void relocate ( struct i386_all_regs *ix86 ) { struct memory_map memmap; - uint32_t start, end, size, padded_size, max; - uint32_t new_start, new_end; + unsigned long start, end, size, padded_size, max; + unsigned long new_start, new_end; unsigned i; /* Get memory map and current location */ @@ -51,17 +53,17 @@ __asmcall void relocate ( struct i386_all_regs *ix86 ) { start = virt_to_phys ( _textdata ); end = virt_to_phys ( _etextdata ); size = ( end - start ); - padded_size = ( size + ALIGN - 1 ); + padded_size = ( size + max_align - 1 ); - DBG ( "Relocate: currently at [%x,%x)\n" - "...need %x bytes for %d-byte alignment\n", - start, end, padded_size, ALIGN ); + DBG ( "Relocate: currently at [%lx,%lx)\n" + "...need %lx bytes for %d-byte alignment\n", + start, end, padded_size, max_align ); /* Determine maximum usable address */ max = MAX_ADDR; if ( ix86->regs.ebp < max ) { max = ix86->regs.ebp; - DBG ( "Limiting relocation to [0,%x)\n", max ); + DBG ( "Limiting relocation to [0,%lx)\n", max ); } /* Walk through the memory map and find the highest address @@ -70,7 +72,7 @@ __asmcall void relocate ( struct i386_all_regs *ix86 ) { new_end = end; for ( i = 0 ; i < memmap.count ; i++ ) { struct memory_region *region = &memmap.regions[i]; - uint32_t r_start, r_end; + unsigned long r_start, r_end; DBG ( "Considering [%llx,%llx)\n", region->start, region->end); @@ -79,17 +81,17 @@ __asmcall void relocate ( struct i386_all_regs *ix86 ) { * with using just 32-bit arithmetic after this stage. */ if ( region->start > max ) { - DBG ( "...starts after max=%x\n", max ); + DBG ( "...starts after max=%lx\n", max ); continue; } r_start = region->start; if ( region->end > max ) { - DBG ( "...end truncated to max=%x\n", max ); + DBG ( "...end truncated to max=%lx\n", max ); r_end = max; } else { r_end = region->end; } - DBG ( "...usable portion is [%x,%x)\n", r_start, r_end ); + DBG ( "...usable portion is [%lx,%lx)\n", r_start, r_end ); /* If we have rounded down r_end below r_ start, skip * this block. @@ -101,7 +103,7 @@ __asmcall void relocate ( struct i386_all_regs *ix86 ) { /* Check that there is enough space to fit in iPXE */ if ( ( r_end - r_start ) < size ) { - DBG ( "...too small (need %x bytes)\n", size ); + DBG ( "...too small (need %lx bytes)\n", size ); continue; } @@ -123,10 +125,10 @@ __asmcall void relocate ( struct i386_all_regs *ix86 ) { * required alignemnt. */ new_start = new_end - padded_size; - new_start += ( ( start - new_start ) & ( ALIGN - 1 ) ); + new_start += ( start - new_start ) & ( max_align - 1 ); new_end = new_start + size; - DBG ( "Relocating from [%x,%x) to [%x,%x)\n", + DBG ( "Relocating from [%lx,%lx) to [%lx,%lx)\n", start, end, new_start, new_end ); /* Let prefix know what to copy */ diff --git a/roms/ipxe/src/arch/x86/core/runtime.c b/roms/ipxe/src/arch/i386/core/runtime.c index d160fee04..d160fee04 100644 --- a/roms/ipxe/src/arch/x86/core/runtime.c +++ b/roms/ipxe/src/arch/i386/core/runtime.c diff --git a/roms/ipxe/src/arch/x86/core/stack.S b/roms/ipxe/src/arch/i386/core/stack.S index 995c397ca..98f1cd9b9 100644 --- a/roms/ipxe/src/arch/x86/core/stack.S +++ b/roms/ipxe/src/arch/i386/core/stack.S @@ -2,12 +2,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) .arch i386 -#ifdef __x86_64__ -#define STACK_SIZE 8192 -#else -#define STACK_SIZE 4096 -#endif - /**************************************************************************** * Internal stack **************************************************************************** @@ -16,6 +10,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) .align 8 .globl _stack _stack: - .space STACK_SIZE + .space 4096 .globl _estack _estack: diff --git a/roms/ipxe/src/arch/x86/core/stack16.S b/roms/ipxe/src/arch/i386/core/stack16.S index 4bc6f081a..4bc6f081a 100644 --- a/roms/ipxe/src/arch/x86/core/stack16.S +++ b/roms/ipxe/src/arch/i386/core/stack16.S diff --git a/roms/ipxe/src/arch/x86/core/video_subr.c b/roms/ipxe/src/arch/i386/core/video_subr.c index 3f701bd96..3f701bd96 100644 --- a/roms/ipxe/src/arch/x86/core/video_subr.c +++ b/roms/ipxe/src/arch/i386/core/video_subr.c diff --git a/roms/ipxe/src/arch/i386/core/virtaddr.S b/roms/ipxe/src/arch/i386/core/virtaddr.S new file mode 100644 index 000000000..425591570 --- /dev/null +++ b/roms/ipxe/src/arch/i386/core/virtaddr.S @@ -0,0 +1,145 @@ +/* + * Functions to support the virtual addressing method of relocation + * that Etherboot uses. + * + */ + +FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) + +#include "librm.h" + + .arch i386 + .text + .code32 + +/**************************************************************************** + * _virt_to_phys (virtual addressing) + * + * Switch from virtual to flat physical addresses. %esp is adjusted + * to a physical value. Segment registers are set to flat physical + * selectors. All other registers are preserved. Flags are + * preserved. + * + * Parameters: none + * Returns: none + **************************************************************************** + */ + .globl _virt_to_phys +_virt_to_phys: + /* Preserve registers and flags */ + pushfl + pushl %eax + pushl %ebp + + /* Change return address to a physical address */ + movl virt_offset, %ebp + addl %ebp, 12(%esp) + + /* Switch to physical code segment */ + cli + pushl $PHYSICAL_CS + leal 1f(%ebp), %eax + pushl %eax + lret +1: + /* Reload other segment registers and adjust %esp */ + movl $PHYSICAL_DS, %eax + movl %eax, %ds + movl %eax, %es + movl %eax, %fs + movl %eax, %gs + movl %eax, %ss + addl %ebp, %esp + + /* Restore registers and flags, and return */ + popl %ebp + popl %eax + popfl + ret + +/**************************************************************************** + * _phys_to_virt (flat physical addressing) + * + * Switch from flat physical to virtual addresses. %esp is adjusted + * to a virtual value. Segment registers are set to virtual + * selectors. All other registers are preserved. Flags are + * preserved. + * + * Parameters: none + * Returns: none + **************************************************************************** + */ + .globl _phys_to_virt +_phys_to_virt: + /* Preserve registers and flags */ + pushfl + pushl %eax + pushl %ebp + + /* Switch to virtual code segment */ + cli + ljmp $VIRTUAL_CS, $1f +1: + /* Reload data segment registers */ + movl $VIRTUAL_DS, %eax + movl %eax, %ds + movl %eax, %es + movl %eax, %fs + movl %eax, %gs + + /* Reload stack segment and adjust %esp */ + movl virt_offset, %ebp + movl %eax, %ss + subl %ebp, %esp + + /* Change the return address to a virtual address */ + subl %ebp, 12(%esp) + + /* Restore registers and flags, and return */ + popl %ebp + popl %eax + popfl + ret + +/**************************************************************************** + * _intr_to_virt (virtual code segment, virtual or physical stack segment) + * + * Switch from virtual code segment with either a virtual or physical + * stack segment to using virtual addressing. %esp is adjusted if + * necessary to a virtual value. Segment registers are set to virtual + * selectors. All other registers are preserved. Flags are + * preserved. + * + * Parameters: none + * Returns: none + **************************************************************************** + */ + .globl _intr_to_virt +_intr_to_virt: + /* Preserve registers and flags */ + pushfl + pushl %eax + pushl %ebp + + /* Check whether stack segment is physical or virtual */ + movl %ss, %eax + cmpw $VIRTUAL_DS, %ax + movl $VIRTUAL_DS, %eax + + /* Reload data segment registers */ + movl %eax, %ds + movl %eax, %es + movl %eax, %fs + movl %eax, %gs + + /* Reload stack segment and adjust %esp if necessary */ + je 1f + movl virt_offset, %ebp + movl %eax, %ss + subl %ebp, %esp +1: + /* Restore registers and flags, and return */ + popl %ebp + popl %eax + popfl + ret diff --git a/roms/ipxe/src/arch/x86/drivers/net/undi.c b/roms/ipxe/src/arch/i386/drivers/net/undi.c index 9820cf629..9820cf629 100644 --- a/roms/ipxe/src/arch/x86/drivers/net/undi.c +++ b/roms/ipxe/src/arch/i386/drivers/net/undi.c diff --git a/roms/ipxe/src/arch/x86/drivers/net/undiisr.S b/roms/ipxe/src/arch/i386/drivers/net/undiisr.S index b27effe1d..b27effe1d 100644 --- a/roms/ipxe/src/arch/x86/drivers/net/undiisr.S +++ b/roms/ipxe/src/arch/i386/drivers/net/undiisr.S diff --git a/roms/ipxe/src/arch/x86/drivers/net/undiload.c b/roms/ipxe/src/arch/i386/drivers/net/undiload.c index 7160ee384..7160ee384 100644 --- a/roms/ipxe/src/arch/x86/drivers/net/undiload.c +++ b/roms/ipxe/src/arch/i386/drivers/net/undiload.c diff --git a/roms/ipxe/src/arch/x86/drivers/net/undinet.c b/roms/ipxe/src/arch/i386/drivers/net/undinet.c index 091ef9254..6450665ff 100644 --- a/roms/ipxe/src/arch/x86/drivers/net/undinet.c +++ b/roms/ipxe/src/arch/i386/drivers/net/undinet.c @@ -143,7 +143,8 @@ static void undinet_hook_isr ( unsigned int irq ) { assert ( undiisr_irq == 0 ); undiisr_irq = irq; - hook_bios_interrupt ( IRQ_INT ( irq ), ( ( intptr_t ) undiisr ), + hook_bios_interrupt ( IRQ_INT ( irq ), + ( ( unsigned int ) undiisr ), &undiisr_next_handler ); } @@ -156,7 +157,8 @@ static void undinet_unhook_isr ( unsigned int irq ) { assert ( irq <= IRQ_MAX ); - unhook_bios_interrupt ( IRQ_INT ( irq ), ( ( intptr_t ) undiisr ), + unhook_bios_interrupt ( IRQ_INT ( irq ), + ( ( unsigned int ) undiisr ), &undiisr_next_handler ); undiisr_irq = 0; } @@ -591,8 +593,6 @@ static const struct undinet_irq_broken undinet_irq_broken_list[] = { /* HP XX70x laptops */ { .pci_vendor = 0x8086, .pci_device = 0x1502 }, { .pci_vendor = 0x8086, .pci_device = 0x1503 }, - /* HP 745 G3 laptop */ - { .pci_vendor = 0x14e4, .pci_device = 0x1687 }, }; /** diff --git a/roms/ipxe/src/arch/x86/drivers/net/undionly.c b/roms/ipxe/src/arch/i386/drivers/net/undionly.c index 70dbe4bfd..70dbe4bfd 100644 --- a/roms/ipxe/src/arch/x86/drivers/net/undionly.c +++ b/roms/ipxe/src/arch/i386/drivers/net/undionly.c diff --git a/roms/ipxe/src/arch/x86/drivers/net/undipreload.c b/roms/ipxe/src/arch/i386/drivers/net/undipreload.c index fca771843..fca771843 100644 --- a/roms/ipxe/src/arch/x86/drivers/net/undipreload.c +++ b/roms/ipxe/src/arch/i386/drivers/net/undipreload.c diff --git a/roms/ipxe/src/arch/x86/drivers/net/undirom.c b/roms/ipxe/src/arch/i386/drivers/net/undirom.c index b54c6170f..b54c6170f 100644 --- a/roms/ipxe/src/arch/x86/drivers/net/undirom.c +++ b/roms/ipxe/src/arch/i386/drivers/net/undirom.c diff --git a/roms/ipxe/src/arch/x86/interface/pcbios/basemem.c b/roms/ipxe/src/arch/i386/firmware/pcbios/basemem.c index 6a46081aa..6a46081aa 100644 --- a/roms/ipxe/src/arch/x86/interface/pcbios/basemem.c +++ b/roms/ipxe/src/arch/i386/firmware/pcbios/basemem.c diff --git a/roms/ipxe/src/arch/x86/interface/pcbios/bios_console.c b/roms/ipxe/src/arch/i386/firmware/pcbios/bios_console.c index c081a41e6..63413cdc1 100644 --- a/roms/ipxe/src/arch/x86/interface/pcbios/bios_console.c +++ b/roms/ipxe/src/arch/i386/firmware/pcbios/bios_console.c @@ -26,12 +26,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <assert.h> #include <realmode.h> #include <bios.h> -#include <biosint.h> #include <ipxe/console.h> #include <ipxe/ansiesc.h> -#include <ipxe/keys.h> #include <ipxe/keymap.h> -#include <ipxe/init.h> #include <config/console.h> #define ATTR_BOLD 0x08 @@ -69,17 +66,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); /** Current character attribute */ static unsigned int bios_attr = ATTR_DEFAULT; -/** Keypress injection lock */ -static uint8_t __text16 ( bios_inject_lock ); -#define bios_inject_lock __use_text16 ( bios_inject_lock ) - -/** Vector for chaining to other INT 16 handlers */ -static struct segoff __text16 ( int16_vector ); -#define int16_vector __use_text16 ( int16_vector ) - -/** Assembly wrapper */ -extern void int16_wrapper ( void ); - /** * Handle ANSI CUP (cursor position) * @@ -279,35 +265,30 @@ static void bios_putchar ( int character ) { * not in the middle of such a sequence, this will point to a NUL * (note: not "will be NULL"). */ -static const char *bios_ansi_input = ""; - -/** A BIOS key */ -struct bios_key { - /** Scancode */ - uint8_t scancode; - /** Key code */ - uint16_t key; -} __attribute__ (( packed )); - -/** 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 }, +static const char *ansi_input = ""; + +/** A mapping from a BIOS scan code to an ANSI escape sequence */ +#define BIOS_KEY( key, ansi ) key ansi "\0" + +/** Mapping from BIOS scan codes to ANSI escape sequences */ +static const char ansi_sequences[] = { + BIOS_KEY ( "\x53", "[3~" ) /* Delete */ + BIOS_KEY ( "\x48", "[A" ) /* Up arrow */ + BIOS_KEY ( "\x50", "[B" ) /* Down arrow */ + BIOS_KEY ( "\x4b", "[D" ) /* Left arrow */ + BIOS_KEY ( "\x4d", "[C" ) /* Right arrow */ + BIOS_KEY ( "\x47", "[H" ) /* Home */ + BIOS_KEY ( "\x4f", "[F" ) /* End */ + BIOS_KEY ( "\x49", "[5~" ) /* Page up */ + BIOS_KEY ( "\x51", "[6~" ) /* Page down */ + BIOS_KEY ( "\x3f", "[15~" ) /* F5 */ + BIOS_KEY ( "\x40", "[17~" ) /* F6 */ + BIOS_KEY ( "\x41", "[18~" ) /* F7 */ + BIOS_KEY ( "\x42", "[19~" ) /* F8 (required for PXE) */ + BIOS_KEY ( "\x43", "[20~" ) /* F9 */ + BIOS_KEY ( "\x44", "[21~" ) /* F10 */ + BIOS_KEY ( "\x85", "[23~" ) /* F11 */ + BIOS_KEY ( "\x86", "[24~" ) /* F12 */ }; /** @@ -316,35 +297,14 @@ static const struct bios_key bios_keys[] = { * @v scancode BIOS scancode * @ret ansi_seq ANSI escape sequence, if any, otherwise NULL */ -static const char * bios_ansi_seq ( unsigned int scancode ) { - static char buf[ 5 /* "[" + two digits + terminator + NUL */ ]; - unsigned int key; - unsigned int terminator; - unsigned int n; - unsigned int i; - char *tmp = buf; - - /* Construct ANSI escape sequence for scancode, if known */ - for ( i = 0 ; i < ( sizeof ( bios_keys ) / - sizeof ( bios_keys[0] ) ) ; i++ ) { - - /* Look for matching scancode */ - if ( bios_keys[i].scancode != scancode ) - continue; - - /* Construct escape sequence */ - key = bios_keys[i].key; - n = KEY_ANSI_N ( key ); - terminator = KEY_ANSI_TERMINATOR ( key ); - *(tmp++) = '['; - if ( n ) - tmp += sprintf ( tmp, "%d", n ); - *(tmp++) = terminator; - *(tmp++) = '\0'; - assert ( tmp <= &buf[ sizeof ( buf ) ] ); - return buf; - } +static const char * scancode_to_ansi_seq ( unsigned int scancode ) { + const char *seq = ansi_sequences; + while ( *seq ) { + if ( *(seq++) == ( ( char ) scancode ) ) + return seq; + seq += ( strlen ( seq ) + 1 ); + } DBG ( "Unrecognised BIOS scancode %02x\n", scancode ); return NULL; } @@ -376,23 +336,16 @@ static int bios_getchar ( void ) { const char *ansi_seq; /* If we are mid-sequence, pass out the next byte */ - if ( ( character = *bios_ansi_input ) ) { - bios_ansi_input++; + if ( ( character = *ansi_input ) ) { + ansi_input++; return character; } - /* Do nothing if injection is in progress */ - if ( bios_inject_lock ) - return 0; - /* Read character from real BIOS console */ - bios_inject_lock++; __asm__ __volatile__ ( REAL_CODE ( "sti\n\t" "int $0x16\n\t" "cli\n\t" ) - : "=a" ( keypress ) - : "a" ( 0x1000 ), "m" ( bios_inject_lock ) ); - bios_inject_lock--; + : "=a" ( keypress ) : "a" ( 0x1000 ) ); character = ( keypress & 0xff ); /* If it's a normal character, just map and return it */ @@ -400,9 +353,9 @@ static int bios_getchar ( void ) { return bios_keymap ( character ); /* Otherwise, check for a special key that we know about */ - if ( ( ansi_seq = bios_ansi_seq ( keypress >> 8 ) ) ) { + if ( ( ansi_seq = scancode_to_ansi_seq ( keypress >> 8 ) ) ) { /* Start of escape sequence: return ESC (0x1b) */ - bios_ansi_input = ansi_seq; + ansi_input = ansi_seq; return 0x1b; } @@ -420,143 +373,23 @@ static int bios_iskey ( void ) { unsigned int flags; /* If we are mid-sequence, we are always ready */ - if ( *bios_ansi_input ) + if ( *ansi_input ) return 1; - /* Do nothing if injection is in progress */ - if ( bios_inject_lock ) - return 0; - /* Otherwise check the real BIOS console */ - bios_inject_lock++; __asm__ __volatile__ ( REAL_CODE ( "sti\n\t" "int $0x16\n\t" "pushfw\n\t" "popw %w0\n\t" "cli\n\t" ) - : "=R" ( flags ), "=a" ( discard_a ) - : "a" ( 0x1100 ), "m" ( bios_inject_lock ) ); - bios_inject_lock--; + : "=r" ( flags ), "=a" ( discard_a ) + : "a" ( 0x1100 ) ); return ( ! ( flags & ZF ) ); } -/** BIOS console */ struct console_driver bios_console __console_driver = { .putchar = bios_putchar, .getchar = bios_getchar, .iskey = bios_iskey, .usage = CONSOLE_PCBIOS, }; - -/** - * Inject keypresses - * - * @v ix86 Registers as passed to INT 16 - */ -static __asmcall void bios_inject ( struct i386_all_regs *ix86 ) { - unsigned int discard_a; - unsigned int scancode; - unsigned int i; - uint16_t keypress; - int key; - - /* If this is a blocking call, then loop until the - * non-blocking variant of the call indicates that a keypress - * is available. Do this without acquiring the injection - * lock, so that injection may take place. - */ - if ( ( ix86->regs.ah & ~0x10 ) == 0x00 ) { - __asm__ __volatile__ ( REAL_CODE ( "sti\n\t" - "\n1:\n\t" - "pushw %%ax\n\t" - "int $0x16\n\t" - "popw %%ax\n\t" - "jc 2f\n\t" - "jz 1b\n\t" - "\n2:\n\t" - "cli\n\t" ) - : "=a" ( discard_a ) - : "a" ( ix86->regs.eax | 0x0100 ), - "m" ( bios_inject_lock ) ); - } - - /* Acquire injection lock */ - bios_inject_lock++; - - /* Check for keypresses */ - if ( iskey() ) { - - /* Get key */ - key = getkey ( 0 ); - - /* Reverse internal CR->LF mapping */ - if ( key == '\n' ) - key = '\r'; - - /* Convert to keypress */ - keypress = ( ( key << 8 ) | key ); - - /* Handle special keys */ - if ( key >= KEY_MIN ) { - for ( i = 0 ; i < ( sizeof ( bios_keys ) / - sizeof ( bios_keys[0] ) ) ; i++ ) { - if ( bios_keys[i].key == key ) { - scancode = bios_keys[i].scancode; - keypress = ( scancode << 8 ); - break; - } - } - } - - /* Inject keypress */ - DBGC ( &bios_console, "BIOS injecting keypress %04x\n", - keypress ); - __asm__ __volatile__ ( REAL_CODE ( "int $0x16\n\t" ) - : "=a" ( discard_a ) - : "a" ( 0x0500 ), "c" ( keypress ), - "m" ( bios_inject_lock ) ); - } - - /* Release injection lock */ - bios_inject_lock--; -} - -/** - * Start up keypress injection - * - */ -static void bios_inject_startup ( void ) { - - /* Assembly wrapper to call bios_inject() */ - __asm__ __volatile__ ( - TEXT16_CODE ( "\nint16_wrapper:\n\t" - "pushfw\n\t" - "cmpb $0, %cs:bios_inject_lock\n\t" - "jnz 1f\n\t" - VIRT_CALL ( bios_inject ) - "\n1:\n\t" - "popfw\n\t" - "ljmp *%cs:int16_vector\n\t" ) ); - - /* Hook INT 16 */ - hook_bios_interrupt ( 0x16, ( ( intptr_t ) int16_wrapper ), - &int16_vector ); -} - -/** - * Shut down keypress injection - * - * @v booting System is shutting down for OS boot - */ -static void bios_inject_shutdown ( int booting __unused ) { - - /* Unhook INT 16 */ - unhook_bios_interrupt ( 0x16, ( ( intptr_t ) int16_wrapper ), - &int16_vector ); -} - -/** Keypress injection startup function */ -struct startup_fn bios_inject_startup_fn __startup_fn ( STARTUP_NORMAL ) = { - .startup = bios_inject_startup, - .shutdown = bios_inject_shutdown, -}; diff --git a/roms/ipxe/src/arch/x86/interface/pcbios/e820mangler.S b/roms/ipxe/src/arch/i386/firmware/pcbios/e820mangler.S index d5d97b482..d5d97b482 100644 --- a/roms/ipxe/src/arch/x86/interface/pcbios/e820mangler.S +++ b/roms/ipxe/src/arch/i386/firmware/pcbios/e820mangler.S diff --git a/roms/ipxe/src/arch/x86/interface/pcbios/fakee820.c b/roms/ipxe/src/arch/i386/firmware/pcbios/fakee820.c index 8b083c4f0..15f4d772f 100644 --- a/roms/ipxe/src/arch/x86/interface/pcbios/fakee820.c +++ b/roms/ipxe/src/arch/i386/firmware/pcbios/fakee820.c @@ -88,11 +88,11 @@ void fake_e820 ( void ) { "ljmp *%%cs:real_int15_vector\n\t" ) : : "i" ( sizeof ( e820map ) ) ); - hook_bios_interrupt ( 0x15, ( intptr_t ) int15_fakee820, + hook_bios_interrupt ( 0x15, ( unsigned int ) int15_fakee820, &real_int15_vector ); } void unfake_e820 ( void ) { - unhook_bios_interrupt ( 0x15, ( intptr_t ) int15_fakee820, + unhook_bios_interrupt ( 0x15, ( unsigned int ) int15_fakee820, &real_int15_vector ); } diff --git a/roms/ipxe/src/arch/x86/interface/pcbios/hidemem.c b/roms/ipxe/src/arch/i386/firmware/pcbios/hidemem.c index a3728123c..253c601ff 100644 --- a/roms/ipxe/src/arch/x86/interface/pcbios/hidemem.c +++ b/roms/ipxe/src/arch/i386/firmware/pcbios/hidemem.c @@ -76,9 +76,9 @@ extern struct segoff __text16 ( int15_vector ); extern char _textdata[]; extern char _etextdata[]; extern char _text16_memsz[]; -#define _text16_memsz ( ( size_t ) _text16_memsz ) +#define _text16_memsz ( ( unsigned int ) _text16_memsz ) extern char _data16_memsz[]; -#define _data16_memsz ( ( size_t ) _data16_memsz ) +#define _data16_memsz ( ( unsigned int ) _data16_memsz ) /** * Hide region of memory from system memory map @@ -179,7 +179,8 @@ static void hide_etherboot ( void ) { } /* Hook INT 15 */ - hook_bios_interrupt ( 0x15, ( intptr_t ) int15, &int15_vector ); + hook_bios_interrupt ( 0x15, ( unsigned int ) int15, + &int15_vector ); /* Dump memory map after mangling */ DBG ( "Hidden iPXE from system memory map\n" ); @@ -209,7 +210,7 @@ static void unhide_etherboot ( int flags __unused ) { } /* Try to unhook INT 15 */ - if ( ( rc = unhook_bios_interrupt ( 0x15, ( intptr_t ) int15, + if ( ( rc = unhook_bios_interrupt ( 0x15, ( unsigned int ) int15, &int15_vector ) ) != 0 ) { DBG ( "Cannot unhook INT15: %s\n", strerror ( rc ) ); /* Leave it hooked; there's nothing else we can do, diff --git a/roms/ipxe/src/arch/x86/interface/pcbios/memmap.c b/roms/ipxe/src/arch/i386/firmware/pcbios/memmap.c index daae382b8..bcacecd6a 100644 --- a/roms/ipxe/src/arch/x86/interface/pcbios/memmap.c +++ b/roms/ipxe/src/arch/i386/firmware/pcbios/memmap.c @@ -92,7 +92,7 @@ static unsigned int extmemsize_e801 ( void ) { "int $0x15\n\t" "pushfw\n\t" "popw %w0\n\t" ) - : "=R" ( flags ), + : "=r" ( flags ), "=a" ( extmem_1m_to_16m_k ), "=b" ( extmem_16m_plus_64k ), "=c" ( confmem_1m_to_16m_k ), @@ -174,7 +174,7 @@ static int meme820 ( struct memory_map *memmap ) { struct memory_region *prev_region = NULL; uint32_t next = 0; uint32_t smap; - uint32_t size; + size_t size; unsigned int flags; unsigned int discard_D; @@ -216,7 +216,7 @@ static int meme820 ( struct memory_map *memmap ) { } if ( size < E820_MIN_SIZE ) { - DBG ( "INT 15,e820 returned only %d bytes\n", size ); + DBG ( "INT 15,e820 returned only %zd bytes\n", size ); return -EINVAL; } diff --git a/roms/ipxe/src/arch/x86/interface/pcbios/pnpbios.c b/roms/ipxe/src/arch/i386/firmware/pcbios/pnpbios.c index 20ec35d75..20ec35d75 100644 --- a/roms/ipxe/src/arch/x86/interface/pcbios/pnpbios.c +++ b/roms/ipxe/src/arch/i386/firmware/pcbios/pnpbios.c diff --git a/roms/ipxe/src/arch/x86/hci/commands/pxe_cmd.c b/roms/ipxe/src/arch/i386/hci/commands/pxe_cmd.c index 473b97f97..473b97f97 100644 --- a/roms/ipxe/src/arch/x86/hci/commands/pxe_cmd.c +++ b/roms/ipxe/src/arch/i386/hci/commands/pxe_cmd.c diff --git a/roms/ipxe/src/arch/x86/image/bootsector.c b/roms/ipxe/src/arch/i386/image/bootsector.c index 67dad04f8..dba87613c 100644 --- a/roms/ipxe/src/arch/x86/image/bootsector.c +++ b/roms/ipxe/src/arch/i386/image/bootsector.c @@ -71,9 +71,9 @@ int call_bootsector ( unsigned int segment, unsigned int offset, DBG ( "Booting from boot sector at %04x:%04x\n", segment, offset ); /* Hook INTs 18 and 19 to capture failure paths */ - hook_bios_interrupt ( 0x18, ( intptr_t ) bootsector_exec_fail, + hook_bios_interrupt ( 0x18, ( unsigned int ) bootsector_exec_fail, &int18_vector ); - hook_bios_interrupt ( 0x19, ( intptr_t ) bootsector_exec_fail, + hook_bios_interrupt ( 0x19, ( unsigned int ) bootsector_exec_fail, &int19_vector ); /* Boot the loaded sector @@ -132,9 +132,9 @@ int call_bootsector ( unsigned int segment, unsigned int offset, DBG ( "Booted disk returned via INT 18 or 19\n" ); /* Unhook INTs 18 and 19 */ - unhook_bios_interrupt ( 0x18, ( intptr_t ) bootsector_exec_fail, + unhook_bios_interrupt ( 0x18, ( unsigned int ) bootsector_exec_fail, &int18_vector ); - unhook_bios_interrupt ( 0x19, ( intptr_t ) bootsector_exec_fail, + unhook_bios_interrupt ( 0x19, ( unsigned int ) bootsector_exec_fail, &int19_vector ); return -ECANCELED; diff --git a/roms/ipxe/src/arch/x86/image/bzimage.c b/roms/ipxe/src/arch/i386/image/bzimage.c index d9b5ddc07..a64206cd3 100644 --- a/roms/ipxe/src/arch/x86/image/bzimage.c +++ b/roms/ipxe/src/arch/i386/image/bzimage.c @@ -631,9 +631,9 @@ static int bzimage_exec ( struct image *image ) { "pushw %w2\n\t" "pushw $0\n\t" "lret\n\t" ) - : : "R" ( bzimg.rm_kernel_seg ), - "R" ( bzimg.rm_heap ), - "R" ( bzimg.rm_kernel_seg + 0x20 ) ); + : : "r" ( bzimg.rm_kernel_seg ), + "r" ( bzimg.rm_heap ), + "r" ( bzimg.rm_kernel_seg + 0x20 ) ); /* There is no way for the image to return, since we provide * no return address. diff --git a/roms/ipxe/src/arch/x86/image/com32.c b/roms/ipxe/src/arch/i386/image/com32.c index 016652877..c12ffb684 100644 --- a/roms/ipxe/src/arch/x86/image/com32.c +++ b/roms/ipxe/src/arch/i386/image/com32.c @@ -40,7 +40,6 @@ FILE_LICENCE ( GPL2_OR_LATER ); #include <ipxe/segment.h> #include <ipxe/init.h> #include <ipxe/io.h> -#include <ipxe/console.h> /** * Execute COMBOOT image @@ -76,6 +75,8 @@ static int com32_exec_loop ( struct image *image ) { assert ( avail_mem_top != 0 ); + com32_external_esp = phys_to_virt ( avail_mem_top ); + /* Hook COMBOOT API interrupts */ hook_comboot_interrupts(); @@ -86,44 +87,34 @@ static int com32_exec_loop ( struct image *image ) { */ unregister_image ( image ); - __asm__ __volatile__ ( PHYS_CODE ( - /* Preserve registers */ - "pushal\n\t" - /* Preserve stack pointer */ - "subl $4, %k0\n\t" - "movl %%esp, (%k0)\n\t" - /* Switch to COM32 stack */ - "movl %k0, %%esp\n\t" - /* Enable interrupts */ - "sti\n\t" - /* Construct stack frame */ - "pushl %k1\n\t" - "pushl %k2\n\t" - "pushl %k3\n\t" - "pushl %k4\n\t" - "pushl %k5\n\t" - "pushl %k6\n\t" - "pushl $6\n\t" - /* Call COM32 entry point */ - "movl %k7, %k0\n\t" - "call *%k0\n\t" - /* Disable interrupts */ - "cli\n\t" - /* Restore stack pointer */ - "movl 24(%%esp), %%esp\n\t" - /* Restore registers */ - "popal\n\t" ) - : - : "r" ( avail_mem_top ), - "r" ( virt_to_phys ( com32_cfarcall_wrapper ) ), - "r" ( virt_to_phys ( com32_farcall_wrapper ) ), - "r" ( get_fbms() * 1024 - ( COM32_BOUNCE_SEG << 4 ) ), - "i" ( COM32_BOUNCE_SEG << 4 ), - "r" ( virt_to_phys ( com32_intcall_wrapper ) ), - "r" ( virt_to_phys ( image->cmdline ? - image->cmdline : "" ) ), - "i" ( COM32_START_PHYS ) - : "memory" ); + __asm__ __volatile__ ( + "movl %%esp, (com32_internal_esp)\n\t" /* Save internal virtual address space ESP */ + "movl (com32_external_esp), %%esp\n\t" /* Switch to COM32 ESP (top of available memory) */ + "call _virt_to_phys\n\t" /* Switch to flat physical address space */ + "sti\n\t" /* Enable interrupts */ + "pushl %0\n\t" /* Pointer to CDECL helper function */ + "pushl %1\n\t" /* Pointer to FAR call helper function */ + "pushl %2\n\t" /* Size of low memory bounce buffer */ + "pushl %3\n\t" /* Pointer to low memory bounce buffer */ + "pushl %4\n\t" /* Pointer to INT call helper function */ + "pushl %5\n\t" /* Pointer to the command line arguments */ + "pushl $6\n\t" /* Number of additional arguments */ + "call *%6\n\t" /* Execute image */ + "cli\n\t" /* Disable interrupts */ + "call _phys_to_virt\n\t" /* Switch back to internal virtual address space */ + "movl (com32_internal_esp), %%esp\n\t" /* Switch back to internal stack */ + : + : + /* %0 */ "r" ( virt_to_phys ( com32_cfarcall_wrapper ) ), + /* %1 */ "r" ( virt_to_phys ( com32_farcall_wrapper ) ), + /* %2 */ "r" ( get_fbms() * 1024 - (COM32_BOUNCE_SEG << 4) ), + /* %3 */ "i" ( COM32_BOUNCE_SEG << 4 ), + /* %4 */ "r" ( virt_to_phys ( com32_intcall_wrapper ) ), + /* %5 */ "r" ( virt_to_phys ( image->cmdline ? + image->cmdline : "" ) ), + /* %6 */ "r" ( COM32_START_PHYS ) + : + "memory" ); DBGC ( image, "COM32 %p: returned\n", image ); break; @@ -155,7 +146,7 @@ static int com32_exec_loop ( struct image *image ) { /** * Check image name extension - * + * * @v image COM32 image * @ret rc Return status code */ @@ -163,7 +154,7 @@ static int com32_identify ( struct image *image ) { const char *ext; static const uint8_t magic[] = { 0xB8, 0xFF, 0x4C, 0xCD, 0x21 }; uint8_t buf[5]; - + if ( image->len >= 5 ) { /* Check for magic number * mov eax,21cd4cffh @@ -290,9 +281,6 @@ static int com32_exec ( struct image *image ) { return rc; } - /* Reset console */ - console_reset(); - return com32_exec_loop ( image ); } diff --git a/roms/ipxe/src/arch/x86/image/comboot.c b/roms/ipxe/src/arch/i386/image/comboot.c index 9a847f0ff..1ec02331d 100644 --- a/roms/ipxe/src/arch/x86/image/comboot.c +++ b/roms/ipxe/src/arch/i386/image/comboot.c @@ -40,7 +40,6 @@ FILE_LICENCE ( GPL2_OR_LATER ); #include <ipxe/segment.h> #include <ipxe/init.h> #include <ipxe/features.h> -#include <ipxe/console.h> FEATURE ( FEATURE_IMAGE, "COMBOOT", DHCP_EB_FEATURE_COMBOOT, 1 ); @@ -64,7 +63,7 @@ struct comboot_psp { /** * Copy command line to PSP - * + * * @v image COMBOOT image */ static void comboot_copy_cmdline ( struct image * image, userptr_t seg_userptr ) { @@ -97,7 +96,7 @@ static void comboot_copy_cmdline ( struct image * image, userptr_t seg_userptr ) /** * Initialize PSP - * + * * @v image COMBOOT image * @v seg_userptr segment to initialize */ @@ -213,7 +212,7 @@ static int comboot_exec_loop ( struct image *image ) { /** * Check image name extension - * + * * @v image COMBOOT image * @ret rc Return status code */ @@ -254,7 +253,7 @@ static int comboot_prepare_segment ( struct image *image ) seg_userptr = real_to_user ( COMBOOT_PSP_SEG, 0 ); /* Allow etra 0x100 bytes before image for PSP */ - filesz = image->len + 0x100; + filesz = image->len + 0x100; /* Ensure the entire 64k segment is free */ memsz = 0xFFFF; @@ -289,7 +288,7 @@ static int comboot_probe ( struct image *image ) { /* Check if this is a COMBOOT image */ if ( ( rc = comboot_identify ( image ) ) != 0 ) { - + return rc; } @@ -304,7 +303,7 @@ static int comboot_probe ( struct image *image ) { */ static int comboot_exec ( struct image *image ) { int rc; - + /* Sanity check for filesize */ if( image->len >= 0xFF00 ) { DBGC( image, "COMBOOT %p: image too large\n", @@ -317,9 +316,6 @@ static int comboot_exec ( struct image *image ) { return rc; } - /* Reset console */ - console_reset(); - return comboot_exec_loop ( image ); } diff --git a/roms/ipxe/src/arch/x86/image/elfboot.c b/roms/ipxe/src/arch/i386/image/elfboot.c index dc3568929..dc3568929 100644 --- a/roms/ipxe/src/arch/x86/image/elfboot.c +++ b/roms/ipxe/src/arch/i386/image/elfboot.c diff --git a/roms/ipxe/src/arch/x86/image/initrd.c b/roms/ipxe/src/arch/i386/image/initrd.c index 80c197417..80c197417 100644 --- a/roms/ipxe/src/arch/x86/image/initrd.c +++ b/roms/ipxe/src/arch/i386/image/initrd.c diff --git a/roms/ipxe/src/arch/x86/image/multiboot.c b/roms/ipxe/src/arch/i386/image/multiboot.c index 0c85df708..0c85df708 100644 --- a/roms/ipxe/src/arch/x86/image/multiboot.c +++ b/roms/ipxe/src/arch/i386/image/multiboot.c diff --git a/roms/ipxe/src/arch/x86/image/nbi.c b/roms/ipxe/src/arch/i386/image/nbi.c index b691bee20..99046144d 100644 --- a/roms/ipxe/src/arch/x86/image/nbi.c +++ b/roms/ipxe/src/arch/i386/image/nbi.c @@ -241,7 +241,7 @@ static int nbi_process_segments ( struct image *image, */ static int nbi_boot16 ( struct image *image, struct imgheader *imgheader ) { int discard_D, discard_S, discard_b; - int32_t rc; + int rc; DBGC ( image, "NBI %p executing 16-bit image at %04x:%04x\n", image, imgheader->execaddr.segoff.segment, @@ -283,7 +283,7 @@ static int nbi_boot32 ( struct image *image, struct imgheader *imgheader ) { 0 }; int discard_D, discard_S, discard_b; - int32_t rc; + int rc; DBGC ( image, "NBI %p executing 32-bit image at %lx\n", image, imgheader->execaddr.linear ); diff --git a/roms/ipxe/src/arch/x86/image/pxe_image.c b/roms/ipxe/src/arch/i386/image/pxe_image.c index 297a618b8..5b0f6eb89 100644 --- a/roms/ipxe/src/arch/x86/image/pxe_image.c +++ b/roms/ipxe/src/arch/i386/image/pxe_image.c @@ -78,9 +78,6 @@ static int pxe_exec ( struct image *image ) { /* Activate PXE */ pxe_activate ( netdev ); - /* Construct fake DHCP packets */ - pxe_fake_cached_info(); - /* Set PXE command line */ pxe_cmdline = image->cmdline; diff --git a/roms/ipxe/src/arch/x86/image/sdi.c b/roms/ipxe/src/arch/i386/image/sdi.c index fa2d0b73f..fa2d0b73f 100644 --- a/roms/ipxe/src/arch/x86/image/sdi.c +++ b/roms/ipxe/src/arch/i386/image/sdi.c diff --git a/roms/ipxe/src/arch/x86/include/basemem.h b/roms/ipxe/src/arch/i386/include/basemem.h index 01c2ea917..01c2ea917 100644 --- a/roms/ipxe/src/arch/x86/include/basemem.h +++ b/roms/ipxe/src/arch/i386/include/basemem.h diff --git a/roms/ipxe/src/arch/x86/include/basemem_packet.h b/roms/ipxe/src/arch/i386/include/basemem_packet.h index def6dee31..def6dee31 100644 --- a/roms/ipxe/src/arch/x86/include/basemem_packet.h +++ b/roms/ipxe/src/arch/i386/include/basemem_packet.h diff --git a/roms/ipxe/src/arch/x86/include/bios.h b/roms/ipxe/src/arch/i386/include/bios.h index 988bbc62b..988bbc62b 100644 --- a/roms/ipxe/src/arch/x86/include/bios.h +++ b/roms/ipxe/src/arch/i386/include/bios.h diff --git a/roms/ipxe/src/arch/x86/include/bios_disks.h b/roms/ipxe/src/arch/i386/include/bios_disks.h index 0dd7c4ebb..0dd7c4ebb 100644 --- a/roms/ipxe/src/arch/x86/include/bios_disks.h +++ b/roms/ipxe/src/arch/i386/include/bios_disks.h diff --git a/roms/ipxe/src/arch/x86/include/biosint.h b/roms/ipxe/src/arch/i386/include/biosint.h index f47116f70..67d6a3811 100644 --- a/roms/ipxe/src/arch/x86/include/biosint.h +++ b/roms/ipxe/src/arch/i386/include/biosint.h @@ -29,6 +29,5 @@ extern void hook_bios_interrupt ( unsigned int interrupt, unsigned int handler, extern int unhook_bios_interrupt ( unsigned int interrupt, unsigned int handler, struct segoff *chain_vector ); -extern void check_bios_interrupts ( void ); #endif /* BIOSINT_H */ diff --git a/roms/ipxe/src/arch/i386/include/bits/compiler.h b/roms/ipxe/src/arch/i386/include/bits/compiler.h index 7c4a09396..87201135f 100644 --- a/roms/ipxe/src/arch/i386/include/bits/compiler.h +++ b/roms/ipxe/src/arch/i386/include/bits/compiler.h @@ -9,7 +9,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #ifndef ASSEMBLY /** Declare a function with standard calling conventions */ -#define __asmcall __attribute__ (( used, cdecl, regparm(0) )) +#define __asmcall __attribute__ (( cdecl, regparm(0) )) /** * Declare a function with libgcc implicit linkage diff --git a/roms/ipxe/src/arch/x86/include/bits/entropy.h b/roms/ipxe/src/arch/i386/include/bits/entropy.h index 5ac7fcd2e..bfeb5e3b5 100644 --- a/roms/ipxe/src/arch/x86/include/bits/entropy.h +++ b/roms/ipxe/src/arch/i386/include/bits/entropy.h @@ -3,7 +3,7 @@ /** @file * - * x86-specific entropy API implementations + * i386-specific entropy API implementations * */ diff --git a/roms/ipxe/src/arch/i386/include/bits/hyperv.h b/roms/ipxe/src/arch/i386/include/bits/hyperv.h index 0ba58afb7..3565c8a83 100644 --- a/roms/ipxe/src/arch/i386/include/bits/hyperv.h +++ b/roms/ipxe/src/arch/i386/include/bits/hyperv.h @@ -46,4 +46,27 @@ hv_call ( struct hv_hypervisor *hv, unsigned int code, const void *in, return result; } +/** + * Set bit atomically + * + * @v bits Bit field + * @v bit Bit to set + */ +static inline __attribute__ (( always_inline )) void +hv_set_bit ( void *bits, unsigned int bit ) { + struct { + uint32_t dword[ ( bit / 32 ) + 1 ]; + } *dwords = bits; + + /* Set bit using "lock bts". Inform compiler that any memory + * from the start of the bit field up to and including the + * dword containing this bit may be modified. (This is + * overkill but shouldn't matter in practice since we're + * unlikely to subsequently read other bits from the same bit + * field.) + */ + __asm__ __volatile__ ( "lock bts %1, %0" + : "+m" ( *dwords ) : "Ir" ( bit ) ); +} + #endif /* _BITS_HYPERV_H */ diff --git a/roms/ipxe/src/arch/x86/include/bits/nap.h b/roms/ipxe/src/arch/i386/include/bits/nap.h index 7103b94c0..e8bcfd13b 100644 --- a/roms/ipxe/src/arch/x86/include/bits/nap.h +++ b/roms/ipxe/src/arch/i386/include/bits/nap.h @@ -3,7 +3,7 @@ /** @file * - * x86-specific CPU sleeping API implementations + * i386-specific CPU sleeping API implementations * */ diff --git a/roms/ipxe/src/arch/x86/include/bits/reboot.h b/roms/ipxe/src/arch/i386/include/bits/reboot.h index e702dd3d0..803dacfe4 100644 --- a/roms/ipxe/src/arch/x86/include/bits/reboot.h +++ b/roms/ipxe/src/arch/i386/include/bits/reboot.h @@ -3,7 +3,7 @@ /** @file * - * x86-specific reboot API implementations + * i386-specific reboot API implementations * */ diff --git a/roms/ipxe/src/arch/x86/include/bits/sanboot.h b/roms/ipxe/src/arch/i386/include/bits/sanboot.h index 1b9924e64..f02d2e649 100644 --- a/roms/ipxe/src/arch/x86/include/bits/sanboot.h +++ b/roms/ipxe/src/arch/i386/include/bits/sanboot.h @@ -3,7 +3,7 @@ /** @file * - * x86-specific sanboot API implementations + * i386-specific sanboot API implementations * */ diff --git a/roms/ipxe/src/arch/x86/include/bits/smbios.h b/roms/ipxe/src/arch/i386/include/bits/smbios.h index 9977c87ac..2ab31e74b 100644 --- a/roms/ipxe/src/arch/x86/include/bits/smbios.h +++ b/roms/ipxe/src/arch/i386/include/bits/smbios.h @@ -3,7 +3,7 @@ /** @file * - * x86-specific SMBIOS API implementations + * i386-specific SMBIOS API implementations * */ diff --git a/roms/ipxe/src/arch/x86/include/bits/time.h b/roms/ipxe/src/arch/i386/include/bits/time.h index 556d96f64..6a5d63d32 100644 --- a/roms/ipxe/src/arch/x86/include/bits/time.h +++ b/roms/ipxe/src/arch/i386/include/bits/time.h @@ -3,7 +3,7 @@ /** @file * - * x86-specific time API implementations + * i386-specific time API implementations * */ diff --git a/roms/ipxe/src/arch/x86/include/bits/timer.h b/roms/ipxe/src/arch/i386/include/bits/timer.h index b0ff5ee11..f7d86d78c 100644 --- a/roms/ipxe/src/arch/x86/include/bits/timer.h +++ b/roms/ipxe/src/arch/i386/include/bits/timer.h @@ -3,7 +3,7 @@ /** @file * - * x86-specific timer API implementations + * i386-specific timer API implementations * */ diff --git a/roms/ipxe/src/arch/x86/include/bits/uaccess.h b/roms/ipxe/src/arch/i386/include/bits/uaccess.h index e9e7e5af5..aac09ba95 100644 --- a/roms/ipxe/src/arch/x86/include/bits/uaccess.h +++ b/roms/ipxe/src/arch/i386/include/bits/uaccess.h @@ -3,7 +3,7 @@ /** @file * - * x86-specific user access API implementations + * i386-specific user access API implementations * */ diff --git a/roms/ipxe/src/arch/x86/include/bits/umalloc.h b/roms/ipxe/src/arch/i386/include/bits/umalloc.h index 5d1f554d8..113f16fd1 100644 --- a/roms/ipxe/src/arch/x86/include/bits/umalloc.h +++ b/roms/ipxe/src/arch/i386/include/bits/umalloc.h @@ -3,7 +3,7 @@ /** @file * - * x86-specific user memory allocation API implementations + * i386-specific user memory allocation API implementations * */ diff --git a/roms/ipxe/src/arch/x86/include/bochs.h b/roms/ipxe/src/arch/i386/include/bochs.h index 9d090fc12..9d090fc12 100644 --- a/roms/ipxe/src/arch/x86/include/bochs.h +++ b/roms/ipxe/src/arch/i386/include/bochs.h diff --git a/roms/ipxe/src/arch/x86/include/bootsector.h b/roms/ipxe/src/arch/i386/include/bootsector.h index c5d35aae3..c5d35aae3 100644 --- a/roms/ipxe/src/arch/x86/include/bootsector.h +++ b/roms/ipxe/src/arch/i386/include/bootsector.h diff --git a/roms/ipxe/src/arch/x86/include/bzimage.h b/roms/ipxe/src/arch/i386/include/bzimage.h index 4933ce5b1..4933ce5b1 100644 --- a/roms/ipxe/src/arch/x86/include/bzimage.h +++ b/roms/ipxe/src/arch/i386/include/bzimage.h diff --git a/roms/ipxe/src/arch/x86/include/comboot.h b/roms/ipxe/src/arch/i386/include/comboot.h index 69c6ef024..2d2f04fe1 100644 --- a/roms/ipxe/src/arch/x86/include/comboot.h +++ b/roms/ipxe/src/arch/i386/include/comboot.h @@ -10,7 +10,7 @@ FILE_LICENCE ( GPL2_OR_LATER ); #include <stdint.h> -#include <rmsetjmp.h> +#include <setjmp.h> #include <ipxe/in.h> /** Segment used for COMBOOT PSP and image */ @@ -29,7 +29,7 @@ FILE_LICENCE ( GPL2_OR_LATER ); #define COMBOOT_FEATURE_LOCAL_BOOT (1 << 0) #define COMBOOT_FEATURE_IDLE_LOOP (1 << 1) -/** Maximum number of shuffle descriptors for +/** Maximum number of shuffle descriptors for * shuffle and boot functions * (INT 22h AX=0012h, 001Ah, 001Bh) */ @@ -102,7 +102,7 @@ typedef struct { extern void hook_comboot_interrupts ( ); extern void unhook_comboot_interrupts ( ); -/* These are not the correct prototypes, but it doens't matter, +/* These are not the correct prototypes, but it doens't matter, * as we only ever get the address of these functions; * they are only called from COM32 code running in PHYS_CODE */ @@ -116,6 +116,8 @@ extern int comboot_resolv ( const char *name, struct in_addr *address ); /* setjmp/longjmp context buffer used to return after loading an image */ extern rmjmp_buf comboot_return; +extern void *com32_external_esp; + #define COMBOOT_EXIT 1 #define COMBOOT_EXIT_RUN_KERNEL 2 #define COMBOOT_EXIT_COMMAND 3 diff --git a/roms/ipxe/src/arch/x86/include/fakee820.h b/roms/ipxe/src/arch/i386/include/fakee820.h index 552b1e48d..552b1e48d 100644 --- a/roms/ipxe/src/arch/x86/include/fakee820.h +++ b/roms/ipxe/src/arch/i386/include/fakee820.h diff --git a/roms/ipxe/src/arch/i386/include/gdbmach.h b/roms/ipxe/src/arch/i386/include/gdbmach.h index 52cce7833..416ae341a 100644 --- a/roms/ipxe/src/arch/i386/include/gdbmach.h +++ b/roms/ipxe/src/arch/i386/include/gdbmach.h @@ -47,10 +47,12 @@ enum { }; /* Interrupt vectors */ -extern void gdbmach_sigfpe ( void ); -extern void gdbmach_sigtrap ( void ); -extern void gdbmach_sigstkflt ( void ); -extern void gdbmach_sigill ( void ); +extern void gdbmach_nocode_sigfpe ( void ); +extern void gdbmach_nocode_sigtrap ( void ); +extern void gdbmach_nocode_sigstkflt ( void ); +extern void gdbmach_nocode_sigill ( void ); +extern void gdbmach_withcode_sigbus ( void ); +extern void gdbmach_withcode_sigsegv ( void ); static inline void gdbmach_set_pc ( gdbreg_t *regs, gdbreg_t pc ) { regs [ GDBMACH_EIP ] = pc; diff --git a/roms/ipxe/src/arch/x86/include/initrd.h b/roms/ipxe/src/arch/i386/include/initrd.h index ddb3e5a45..ddb3e5a45 100644 --- a/roms/ipxe/src/arch/x86/include/initrd.h +++ b/roms/ipxe/src/arch/i386/include/initrd.h diff --git a/roms/ipxe/src/arch/x86/include/int13.h b/roms/ipxe/src/arch/i386/include/int13.h index f82a583c6..f82a583c6 100644 --- a/roms/ipxe/src/arch/x86/include/int13.h +++ b/roms/ipxe/src/arch/i386/include/int13.h diff --git a/roms/ipxe/src/arch/x86/include/ipxe/bios_nap.h b/roms/ipxe/src/arch/i386/include/ipxe/bios_nap.h index c9b82c1e5..c9b82c1e5 100644 --- a/roms/ipxe/src/arch/x86/include/ipxe/bios_nap.h +++ b/roms/ipxe/src/arch/i386/include/ipxe/bios_nap.h diff --git a/roms/ipxe/src/arch/x86/include/ipxe/bios_reboot.h b/roms/ipxe/src/arch/i386/include/ipxe/bios_reboot.h index 3f6df9073..3f6df9073 100644 --- a/roms/ipxe/src/arch/x86/include/ipxe/bios_reboot.h +++ b/roms/ipxe/src/arch/i386/include/ipxe/bios_reboot.h diff --git a/roms/ipxe/src/arch/x86/include/ipxe/bios_sanboot.h b/roms/ipxe/src/arch/i386/include/ipxe/bios_sanboot.h index 85d698039..1a86b7d57 100644 --- a/roms/ipxe/src/arch/x86/include/ipxe/bios_sanboot.h +++ b/roms/ipxe/src/arch/i386/include/ipxe/bios_sanboot.h @@ -15,4 +15,15 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #define SANBOOT_PREFIX_pcbios __pcbios_ #endif +/** + * Get default SAN drive number + * + * @ret drive Default drive number + */ +static inline __always_inline unsigned int +SANBOOT_INLINE ( pcbios, san_default_drive ) ( void ) { + /* Default to booting from first hard disk */ + return 0x80; +} + #endif /* _IPXE_BIOS_SANBOOT_H */ diff --git a/roms/ipxe/src/arch/x86/include/ipxe/bios_smbios.h b/roms/ipxe/src/arch/i386/include/ipxe/bios_smbios.h index 9f7f9c8ff..9f7f9c8ff 100644 --- a/roms/ipxe/src/arch/x86/include/ipxe/bios_smbios.h +++ b/roms/ipxe/src/arch/i386/include/ipxe/bios_smbios.h diff --git a/roms/ipxe/src/arch/x86/include/ipxe/bios_timer.h b/roms/ipxe/src/arch/i386/include/ipxe/bios_timer.h index 6b88a623c..6b88a623c 100644 --- a/roms/ipxe/src/arch/x86/include/ipxe/bios_timer.h +++ b/roms/ipxe/src/arch/i386/include/ipxe/bios_timer.h diff --git a/roms/ipxe/src/arch/x86/include/ipxe/errno/pcbios.h b/roms/ipxe/src/arch/i386/include/ipxe/errno/pcbios.h index 6312adaa4..6312adaa4 100644 --- a/roms/ipxe/src/arch/x86/include/ipxe/errno/pcbios.h +++ b/roms/ipxe/src/arch/i386/include/ipxe/errno/pcbios.h diff --git a/roms/ipxe/src/arch/x86/include/ipxe/guestrpc.h b/roms/ipxe/src/arch/i386/include/ipxe/guestrpc.h index bc3d85506..bc3d85506 100644 --- a/roms/ipxe/src/arch/x86/include/ipxe/guestrpc.h +++ b/roms/ipxe/src/arch/i386/include/ipxe/guestrpc.h diff --git a/roms/ipxe/src/arch/x86/include/ipxe/memtop_umalloc.h b/roms/ipxe/src/arch/i386/include/ipxe/memtop_umalloc.h index dee055d16..dee055d16 100644 --- a/roms/ipxe/src/arch/x86/include/ipxe/memtop_umalloc.h +++ b/roms/ipxe/src/arch/i386/include/ipxe/memtop_umalloc.h diff --git a/roms/ipxe/src/arch/x86/include/ipxe/rdtsc_timer.h b/roms/ipxe/src/arch/i386/include/ipxe/rdtsc_timer.h index 598f4bb08..598f4bb08 100644 --- a/roms/ipxe/src/arch/x86/include/ipxe/rdtsc_timer.h +++ b/roms/ipxe/src/arch/i386/include/ipxe/rdtsc_timer.h diff --git a/roms/ipxe/src/arch/x86/include/ipxe/rtc_entropy.h b/roms/ipxe/src/arch/i386/include/ipxe/rtc_entropy.h index e214745d0..e214745d0 100644 --- a/roms/ipxe/src/arch/x86/include/ipxe/rtc_entropy.h +++ b/roms/ipxe/src/arch/i386/include/ipxe/rtc_entropy.h diff --git a/roms/ipxe/src/arch/x86/include/ipxe/rtc_time.h b/roms/ipxe/src/arch/i386/include/ipxe/rtc_time.h index cb8c7f49e..cb8c7f49e 100644 --- a/roms/ipxe/src/arch/x86/include/ipxe/rtc_time.h +++ b/roms/ipxe/src/arch/i386/include/ipxe/rtc_time.h diff --git a/roms/ipxe/src/arch/x86/include/ipxe/vesafb.h b/roms/ipxe/src/arch/i386/include/ipxe/vesafb.h index efc8f2cb8..efc8f2cb8 100644 --- a/roms/ipxe/src/arch/x86/include/ipxe/vesafb.h +++ b/roms/ipxe/src/arch/i386/include/ipxe/vesafb.h diff --git a/roms/ipxe/src/arch/x86/include/ipxe/vmware.h b/roms/ipxe/src/arch/i386/include/ipxe/vmware.h index 24f60a03a..24f60a03a 100644 --- a/roms/ipxe/src/arch/x86/include/ipxe/vmware.h +++ b/roms/ipxe/src/arch/i386/include/ipxe/vmware.h diff --git a/roms/ipxe/src/arch/x86/include/kir.h b/roms/ipxe/src/arch/i386/include/kir.h index 84633d26f..84633d26f 100644 --- a/roms/ipxe/src/arch/x86/include/kir.h +++ b/roms/ipxe/src/arch/i386/include/kir.h diff --git a/roms/ipxe/src/arch/x86/include/libkir.h b/roms/ipxe/src/arch/i386/include/libkir.h index 1f5b13504..1f5b13504 100644 --- a/roms/ipxe/src/arch/x86/include/libkir.h +++ b/roms/ipxe/src/arch/i386/include/libkir.h diff --git a/roms/ipxe/src/arch/x86/include/librm.h b/roms/ipxe/src/arch/i386/include/librm.h index 311748bec..a8a578a39 100644 --- a/roms/ipxe/src/arch/x86/include/librm.h +++ b/roms/ipxe/src/arch/i386/include/librm.h @@ -7,62 +7,19 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); * * Don't change these unless you really know what you're doing. */ + #define VIRTUAL_CS 0x08 #define VIRTUAL_DS 0x10 #define PHYSICAL_CS 0x18 #define PHYSICAL_DS 0x20 #define REAL_CS 0x28 #define REAL_DS 0x30 -#define P2R_DS 0x38 -#define LONG_CS 0x40 - -/* Calculate symbol address within VIRTUAL_CS or VIRTUAL_DS - * - * In a 64-bit build, we set the bases of VIRTUAL_CS and VIRTUAL_DS - * such that truncating a .textdata symbol value to 32 bits gives a - * valid 32-bit virtual address. - * - * The C code is compiled with -mcmodel=kernel and so we must place - * all .textdata symbols within the negative 2GB of the 64-bit address - * space. Consequently, all .textdata symbols will have the MSB set - * after truncation to 32 bits. This means that a straightforward - * R_X86_64_32 relocation record for the symbol will fail, since the - * truncated symbol value will not correctly zero-extend to the - * original 64-bit value. - * - * Using an R_X86_64_32S relocation record would work, but there is no - * (sensible) way to generate these relocation records within 32-bit - * or 16-bit code. - * - * The simplest solution is to generate an R_X86_64_32 relocation - * record with an addend of (-0xffffffff00000000). Since all - * .textdata symbols are within the negative 2GB of the 64-bit address - * space, this addend acts to effectively truncate the symbol to 32 - * bits, thereby matching the semantics of the R_X86_64_32 relocation - * records generated for 32-bit and 16-bit code. - * - * In a 32-bit build, this problem does not exist, and we can just use - * the .textdata symbol values directly. - */ -#ifdef __x86_64__ -#define VIRTUAL(address) ( (address) - 0xffffffff00000000 ) -#else -#define VIRTUAL(address) (address) +#if 0 +#define LONG_CS 0x38 +#define LONG_DS 0x40 #endif -#ifdef ASSEMBLY - -/** - * Call C function from real-mode code - * - * @v function C function - */ -.macro virtcall function - pushl $VIRTUAL(\function) - call virt_call -.endm - -#else /* ASSEMBLY */ +#ifndef ASSEMBLY #ifdef UACCESS_LIBRM #define UACCESS_PREFIX_librm @@ -70,17 +27,8 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #define UACCESS_PREFIX_librm __librm_ #endif -/** - * Call C function from real-mode code - * - * @v function C function - */ -#define VIRT_CALL( function ) \ - "pushl $( " _S2 ( VIRTUAL ( function ) ) " )\n\t" \ - "call virt_call\n\t" - /* Variables in librm.S */ -extern const unsigned long virt_offset; +extern unsigned long virt_offset; /** * Convert physical address to user pointer @@ -90,15 +38,6 @@ extern const unsigned long virt_offset; */ static inline __always_inline userptr_t UACCESS_INLINE ( librm, phys_to_user ) ( unsigned long phys_addr ) { - - /* In a 64-bit build, any valid physical address is directly - * usable as a virtual address, since the low 4GB is - * identity-mapped. - */ - if ( sizeof ( physaddr_t ) > sizeof ( uint32_t ) ) - return phys_addr; - - /* In a 32-bit build, subtract virt_offset */ return ( phys_addr - virt_offset ); } @@ -111,20 +50,7 @@ UACCESS_INLINE ( librm, phys_to_user ) ( unsigned long phys_addr ) { */ static inline __always_inline unsigned long UACCESS_INLINE ( librm, user_to_phys ) ( userptr_t userptr, off_t offset ) { - unsigned long addr = ( userptr + offset ); - - /* In a 64-bit build, any virtual address in the low 4GB is - * directly usable as a physical address, since the low 4GB is - * identity-mapped. - */ - if ( ( sizeof ( physaddr_t ) > sizeof ( uint32_t ) ) && - ( addr <= 0xffffffffUL ) ) - return addr; - - /* In a 32-bit build or in a 64-bit build with a virtual - * address above 4GB: add virt_offset - */ - return ( addr + virt_offset ); + return ( userptr + offset + virt_offset ); } static inline __always_inline userptr_t @@ -193,8 +119,8 @@ UACCESS_INLINE ( librm, memchr_user ) ( userptr_t buffer, off_t offset, * */ -extern char * const data16; -extern char * const text16; +extern char *data16; +extern char *text16; #define __data16( variable ) \ __attribute__ (( section ( ".data16" ) )) \ @@ -239,33 +165,27 @@ extern char * const text16; /* Variables in librm.S, present in the normal data segment */ extern uint16_t rm_sp; extern uint16_t rm_ss; -extern const uint16_t __text16 ( rm_cs ); +extern uint16_t __text16 ( rm_cs ); #define rm_cs __use_text16 ( rm_cs ) -extern const uint16_t __text16 ( rm_ds ); +extern uint16_t __text16 ( rm_ds ); #define rm_ds __use_text16 ( rm_ds ) extern uint16_t copy_user_to_rm_stack ( userptr_t data, size_t size ); 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" -#else -#define CODE_DEFAULT ".code32" -#endif - /* TEXT16_CODE: declare a fragment of code that resides in .text16 */ #define TEXT16_CODE( asm_code_str ) \ ".section \".text16\", \"ax\", @progbits\n\t" \ ".code16\n\t" \ asm_code_str "\n\t" \ - CODE_DEFAULT "\n\t" \ + ".code32\n\t" \ ".previous\n\t" /* REAL_CODE: declare a fragment of code that executes in real mode */ #define REAL_CODE( asm_code_str ) \ - "push $1f\n\t" \ + "pushl $1f\n\t" \ "call real_call\n\t" \ + "addl $4, %%esp\n\t" \ TEXT16_CODE ( "\n1:\n\t" \ asm_code_str \ "\n\t" \ @@ -273,38 +193,23 @@ 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" \ - "call phys_call\n\t" \ - ".section \".text.phys\", \"ax\", @progbits\n\t"\ - ".code32\n\t" \ - "\n1:\n\t" \ + "call _virt_to_phys\n\t" \ asm_code_str \ - "\n\t" \ - "ret\n\t" \ - CODE_DEFAULT "\n\t" \ - ".previous\n\t" + "call _phys_to_virt\n\t" /** Number of interrupts */ #define NUM_INT 256 -/** A 32-bit interrupt descriptor table register */ -struct idtr32 { +/** An interrupt descriptor table register */ +struct idtr { /** Limit */ uint16_t limit; /** Base */ uint32_t base; } __attribute__ (( packed )); -/** A 64-bit interrupt descriptor table register */ -struct idtr64 { - /** Limit */ - uint16_t limit; - /** Base */ - uint64_t base; -} __attribute__ (( packed )); - -/** A 32-bit interrupt descriptor table entry */ -struct interrupt32_descriptor { +/** An interrupt descriptor table entry */ +struct interrupt_descriptor { /** Low 16 bits of address */ uint16_t low; /** Code segment */ @@ -317,44 +222,23 @@ struct interrupt32_descriptor { uint16_t high; } __attribute__ (( packed )); -/** A 64-bit interrupt descriptor table entry */ -struct interrupt64_descriptor { - /** Low 16 bits of address */ - uint16_t low; - /** Code segment */ - uint16_t segment; - /** Unused */ - uint8_t unused; - /** Type and attributes */ - uint8_t attr; - /** Middle 16 bits of address */ - uint16_t mid; - /** High 32 bits of address */ - uint32_t high; - /** Reserved */ - uint32_t reserved; -} __attribute__ (( packed )); - /** Interrupt descriptor is present */ #define IDTE_PRESENT 0x80 /** Interrupt descriptor 32-bit interrupt gate type */ #define IDTE_TYPE_IRQ32 0x0e -/** Interrupt descriptor 64-bit interrupt gate type */ -#define IDTE_TYPE_IRQ64 0x0e - /** An interrupt vector * * Each interrupt vector comprises an eight-byte fragment of code: * - * 50 pushl %eax (or pushq %rax in long mode) + * 60 pushal * b0 xx movb $INT, %al * e9 xx xx xx xx jmp interrupt_wrapper */ struct interrupt_vector { - /** "push" instruction */ - uint8_t push; + /** "pushal" instruction */ + uint8_t pushal; /** "movb" instruction */ uint8_t movb; /** Interrupt number */ @@ -367,8 +251,8 @@ struct interrupt_vector { uint8_t next[0]; } __attribute__ (( packed )); -/** "push %eax" instruction */ -#define PUSH_INSN 0x50 +/** "pushal" instruction */ +#define PUSHAL_INSN 0x60 /** "movb" instruction */ #define MOVB_INSN 0xb0 @@ -378,51 +262,6 @@ struct interrupt_vector { extern void set_interrupt_vector ( unsigned int intr, void *vector ); -/** A page table */ -struct page_table { - /** Page address and flags */ - uint64_t page[512]; -}; - -/** Page flags */ -enum page_flags { - /** Page is present */ - PAGE_P = 0x01, - /** Page is writable */ - PAGE_RW = 0x02, - /** Page is accessible by user code */ - PAGE_US = 0x04, - /** Page-level write-through */ - PAGE_PWT = 0x08, - /** Page-level cache disable */ - PAGE_PCD = 0x10, - /** Page is a large page */ - PAGE_PS = 0x80, - /** Page is the last page in an allocation - * - * This bit is ignored by the hardware. We use it to track - * the size of allocations made by ioremap(). - */ - PAGE_LAST = 0x800, -}; - -/** The I/O space page table */ -extern struct page_table io_pages; - -/** I/O page size - * - * We choose to use 2MB pages for I/O space, to minimise the number of - * page table entries required. - */ -#define IO_PAGE_SIZE 0x200000UL - -/** I/O page base address - * - * We choose to place I/O space immediately above the identity-mapped - * 32-bit address space. - */ -#define IO_BASE ( ( void * ) 0x100000000ULL ) - #endif /* ASSEMBLY */ #endif /* LIBRM_H */ diff --git a/roms/ipxe/src/arch/x86/include/memsizes.h b/roms/ipxe/src/arch/i386/include/memsizes.h index f115f7574..f115f7574 100644 --- a/roms/ipxe/src/arch/x86/include/memsizes.h +++ b/roms/ipxe/src/arch/i386/include/memsizes.h diff --git a/roms/ipxe/src/arch/x86/include/multiboot.h b/roms/ipxe/src/arch/i386/include/multiboot.h index ae09df6c7..ae09df6c7 100644 --- a/roms/ipxe/src/arch/x86/include/multiboot.h +++ b/roms/ipxe/src/arch/i386/include/multiboot.h diff --git a/roms/ipxe/src/arch/x86/include/pnpbios.h b/roms/ipxe/src/arch/i386/include/pnpbios.h index d14873700..d14873700 100644 --- a/roms/ipxe/src/arch/x86/include/pnpbios.h +++ b/roms/ipxe/src/arch/i386/include/pnpbios.h diff --git a/roms/ipxe/src/arch/x86/include/pxe.h b/roms/ipxe/src/arch/i386/include/pxe.h index 54649b504..66d752683 100644 --- a/roms/ipxe/src/arch/x86/include/pxe.h +++ b/roms/ipxe/src/arch/i386/include/pxe.h @@ -192,7 +192,6 @@ extern struct net_device *pxe_netdev; extern const char *pxe_cmdline; extern void pxe_set_netdev ( struct net_device *netdev ); -extern void pxe_fake_cached_info ( void ); extern PXENV_EXIT_t pxenv_tftp_read_file ( struct s_PXENV_TFTP_READ_FILE *tftp_read_file ); extern PXENV_EXIT_t undi_loader ( struct s_UNDI_LOADER *undi_loader ); diff --git a/roms/ipxe/src/arch/x86/include/pxe_api.h b/roms/ipxe/src/arch/i386/include/pxe_api.h index 3110d26da..3110d26da 100644 --- a/roms/ipxe/src/arch/x86/include/pxe_api.h +++ b/roms/ipxe/src/arch/i386/include/pxe_api.h diff --git a/roms/ipxe/src/arch/x86/include/pxe_call.h b/roms/ipxe/src/arch/i386/include/pxe_call.h index 2ad0a9505..cbd548318 100644 --- a/roms/ipxe/src/arch/x86/include/pxe_call.h +++ b/roms/ipxe/src/arch/i386/include/pxe_call.h @@ -10,7 +10,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <pxe_api.h> #include <realmode.h> -#include <rmsetjmp.h> +#include <setjmp.h> struct net_device; diff --git a/roms/ipxe/src/arch/x86/include/pxe_error.h b/roms/ipxe/src/arch/i386/include/pxe_error.h index 51298e665..51298e665 100644 --- a/roms/ipxe/src/arch/x86/include/pxe_error.h +++ b/roms/ipxe/src/arch/i386/include/pxe_error.h diff --git a/roms/ipxe/src/arch/x86/include/pxe_types.h b/roms/ipxe/src/arch/i386/include/pxe_types.h index 483666e33..483666e33 100644 --- a/roms/ipxe/src/arch/x86/include/pxe_types.h +++ b/roms/ipxe/src/arch/i386/include/pxe_types.h diff --git a/roms/ipxe/src/arch/x86/include/pxeparent.h b/roms/ipxe/src/arch/i386/include/pxeparent.h index b31e24a76..b31e24a76 100644 --- a/roms/ipxe/src/arch/x86/include/pxeparent.h +++ b/roms/ipxe/src/arch/i386/include/pxeparent.h diff --git a/roms/ipxe/src/arch/x86/include/realmode.h b/roms/ipxe/src/arch/i386/include/realmode.h index 4defd3b97..4defd3b97 100644 --- a/roms/ipxe/src/arch/x86/include/realmode.h +++ b/roms/ipxe/src/arch/i386/include/realmode.h diff --git a/roms/ipxe/src/arch/x86/include/registers.h b/roms/ipxe/src/arch/i386/include/registers.h index dd3b59fd5..d9aa3c376 100644 --- a/roms/ipxe/src/arch/x86/include/registers.h +++ b/roms/ipxe/src/arch/i386/include/registers.h @@ -167,7 +167,7 @@ struct i386_seg_regs { * * @endcode * - * virt_call() and kir_call() create this data structure on the stack + * prot_call() and kir_call() create this data structure on the stack * and pass in a pointer to this structure. * */ diff --git a/roms/ipxe/src/arch/x86/include/rtc.h b/roms/ipxe/src/arch/i386/include/rtc.h index 6294b63e3..6294b63e3 100644 --- a/roms/ipxe/src/arch/x86/include/rtc.h +++ b/roms/ipxe/src/arch/i386/include/rtc.h diff --git a/roms/ipxe/src/arch/x86/include/sdi.h b/roms/ipxe/src/arch/i386/include/sdi.h index 806c3f194..806c3f194 100644 --- a/roms/ipxe/src/arch/x86/include/sdi.h +++ b/roms/ipxe/src/arch/i386/include/sdi.h diff --git a/roms/ipxe/src/arch/i386/include/setjmp.h b/roms/ipxe/src/arch/i386/include/setjmp.h index 98566696a..fe1a9ef4d 100644 --- a/roms/ipxe/src/arch/i386/include/setjmp.h +++ b/roms/ipxe/src/arch/i386/include/setjmp.h @@ -4,6 +4,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <stdint.h> +#include <realmode.h> /** A jump buffer */ typedef struct { @@ -21,10 +22,29 @@ typedef struct { uint32_t ebp; } jmp_buf[1]; +/** A real-mode-extended jump buffer */ +typedef struct { + /** Jump buffer */ + jmp_buf env; + /** Real-mode stack pointer */ + segoff_t rm_stack; +} rmjmp_buf[1]; + extern int __asmcall __attribute__ (( returns_twice )) setjmp ( jmp_buf env ); extern void __asmcall __attribute__ (( noreturn )) longjmp ( jmp_buf env, int val ); +#define rmsetjmp( _env ) ( { \ + (_env)->rm_stack.segment = rm_ss; \ + (_env)->rm_stack.offset = rm_sp; \ + setjmp ( (_env)->env ); } ) \ + +#define rmlongjmp( _env, _val ) do { \ + rm_ss = (_env)->rm_stack.segment; \ + rm_sp = (_env)->rm_stack.offset; \ + longjmp ( (_env)->env, (_val) ); \ + } while ( 0 ) + #endif /* _SETJMP_H */ diff --git a/roms/ipxe/src/arch/x86/include/undi.h b/roms/ipxe/src/arch/i386/include/undi.h index 7a5624f93..7a5624f93 100644 --- a/roms/ipxe/src/arch/x86/include/undi.h +++ b/roms/ipxe/src/arch/i386/include/undi.h diff --git a/roms/ipxe/src/arch/x86/include/undiload.h b/roms/ipxe/src/arch/i386/include/undiload.h index 235e7a79e..235e7a79e 100644 --- a/roms/ipxe/src/arch/x86/include/undiload.h +++ b/roms/ipxe/src/arch/i386/include/undiload.h diff --git a/roms/ipxe/src/arch/x86/include/undinet.h b/roms/ipxe/src/arch/i386/include/undinet.h index 2798c4466..2798c4466 100644 --- a/roms/ipxe/src/arch/x86/include/undinet.h +++ b/roms/ipxe/src/arch/i386/include/undinet.h diff --git a/roms/ipxe/src/arch/x86/include/undipreload.h b/roms/ipxe/src/arch/i386/include/undipreload.h index 57f493cec..57f493cec 100644 --- a/roms/ipxe/src/arch/x86/include/undipreload.h +++ b/roms/ipxe/src/arch/i386/include/undipreload.h diff --git a/roms/ipxe/src/arch/x86/include/undirom.h b/roms/ipxe/src/arch/i386/include/undirom.h index 1c530118d..1c530118d 100644 --- a/roms/ipxe/src/arch/x86/include/undirom.h +++ b/roms/ipxe/src/arch/i386/include/undirom.h diff --git a/roms/ipxe/src/arch/x86/include/vga.h b/roms/ipxe/src/arch/i386/include/vga.h index 01fc39d86..01fc39d86 100644 --- a/roms/ipxe/src/arch/x86/include/vga.h +++ b/roms/ipxe/src/arch/i386/include/vga.h diff --git a/roms/ipxe/src/arch/x86/interface/pcbios/apm.c b/roms/ipxe/src/arch/i386/interface/pcbios/apm.c index 50b19cb81..50b19cb81 100644 --- a/roms/ipxe/src/arch/x86/interface/pcbios/apm.c +++ b/roms/ipxe/src/arch/i386/interface/pcbios/apm.c diff --git a/roms/ipxe/src/arch/x86/interface/pcbios/bios_nap.c b/roms/ipxe/src/arch/i386/interface/pcbios/bios_nap.c index f1ba8297b..f1ba8297b 100644 --- a/roms/ipxe/src/arch/x86/interface/pcbios/bios_nap.c +++ b/roms/ipxe/src/arch/i386/interface/pcbios/bios_nap.c diff --git a/roms/ipxe/src/arch/x86/interface/pcbios/bios_reboot.c b/roms/ipxe/src/arch/i386/interface/pcbios/bios_reboot.c index ed18dde0b..10a1ecb89 100644 --- a/roms/ipxe/src/arch/x86/interface/pcbios/bios_reboot.c +++ b/roms/ipxe/src/arch/i386/interface/pcbios/bios_reboot.c @@ -46,7 +46,7 @@ static void bios_reboot ( int warm ) { put_real ( flag, BDA_SEG, BDA_REBOOT ); /* Jump to system reset vector */ - __asm__ __volatile__ ( REAL_CODE ( "ljmp $0xf000, $0xfff0" ) ); + __asm__ __volatile__ ( REAL_CODE ( "ljmp $0xf000, $0xfff0" ) : : ); } PROVIDE_REBOOT ( pcbios, reboot, bios_reboot ); diff --git a/roms/ipxe/src/arch/x86/interface/pcbios/bios_smbios.c b/roms/ipxe/src/arch/i386/interface/pcbios/bios_smbios.c index a8c0fc325..a8c0fc325 100644 --- a/roms/ipxe/src/arch/x86/interface/pcbios/bios_smbios.c +++ b/roms/ipxe/src/arch/i386/interface/pcbios/bios_smbios.c diff --git a/roms/ipxe/src/arch/x86/interface/pcbios/bios_timer.c b/roms/ipxe/src/arch/i386/interface/pcbios/bios_timer.c index 3299c9aae..3299c9aae 100644 --- a/roms/ipxe/src/arch/x86/interface/pcbios/bios_timer.c +++ b/roms/ipxe/src/arch/i386/interface/pcbios/bios_timer.c diff --git a/roms/ipxe/src/arch/x86/interface/pcbios/biosint.c b/roms/ipxe/src/arch/i386/interface/pcbios/biosint.c index 667e9ed81..3b8e80438 100644 --- a/roms/ipxe/src/arch/x86/interface/pcbios/biosint.c +++ b/roms/ipxe/src/arch/i386/interface/pcbios/biosint.c @@ -90,30 +90,3 @@ int unhook_bios_interrupt ( unsigned int interrupt, unsigned int handler, hooked_bios_interrupts--; return 0; } - -/** - * Dump changes to interrupt vector table (for debugging) - * - */ -void check_bios_interrupts ( void ) { - static struct segoff vectors[256]; - static uint8_t initialised; - struct segoff vector; - unsigned int i; - - /* Print any changed interrupt vectors */ - for ( i = 0; i < ( sizeof ( vectors ) / sizeof ( vectors[0] ) ); i++ ) { - copy_from_real ( &vector, 0, ( i * sizeof ( vector ) ), - sizeof ( vector ) ); - if ( memcmp ( &vector, &vectors[i], sizeof ( vector ) ) == 0 ) - continue; - if ( initialised ) { - dbg_printf ( "INT %02x changed %04x:%04x => " - "%04x:%04x\n", i, vectors[i].segment, - vectors[i].offset, vector.segment, - vector.offset ); - } - memcpy ( &vectors[i], &vector, sizeof ( vectors[i] ) ); - } - initialised = 1; -} diff --git a/roms/ipxe/src/arch/x86/interface/pcbios/int13.c b/roms/ipxe/src/arch/i386/interface/pcbios/int13.c index 6f16904df..f0450da90 100644 --- a/roms/ipxe/src/arch/x86/interface/pcbios/int13.c +++ b/roms/ipxe/src/arch/i386/interface/pcbios/int13.c @@ -44,8 +44,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <ipxe/pci.h> #include <ipxe/iso9660.h> #include <ipxe/eltorito.h> -#include <ipxe/dhcp.h> -#include <ipxe/settings.h> #include <realmode.h> #include <bios.h> #include <biosint.h> @@ -1482,7 +1480,9 @@ static void int13_hook_vector ( void ) { /* Clear OF, set CF, call int13() */ "orb $0, %%al\n\t" "stc\n\t" - VIRT_CALL ( int13 ) + "pushl %0\n\t" + "pushw %%cs\n\t" + "call prot_call\n\t" /* Chain if OF not set */ "jo 1f\n\t" "pushfw\n\t" @@ -1513,16 +1513,18 @@ static void int13_hook_vector ( void ) { "\n3:\n\t" "movw %%bp, %%sp\n\t" "popw %%bp\n\t" - "iret\n\t" ) : : ); + "iret\n\t" ) + : : "i" ( int13 ) ); - hook_bios_interrupt ( 0x13, ( intptr_t ) int13_wrapper, &int13_vector ); + hook_bios_interrupt ( 0x13, ( unsigned int ) int13_wrapper, + &int13_vector ); } /** * Unhook INT 13 handler */ static void int13_unhook_vector ( void ) { - unhook_bios_interrupt ( 0x13, ( intptr_t ) int13_wrapper, + unhook_bios_interrupt ( 0x13, ( unsigned int ) int13_wrapper, &int13_vector ); } @@ -1590,7 +1592,7 @@ static void int13_free ( struct refcnt *refcnt ) { * * @v uri URI * @v drive Drive number - * @ret drive Drive number, or negative error + * @ret rc Return status code * * Registers the drive with the INT 13 emulation subsystem, and hooks * the INT 13 interrupt vector (if not already hooked). @@ -1605,10 +1607,6 @@ static int int13_hook ( struct uri *uri, unsigned int drive ) { int13_sync_num_drives(); natural_drive = ( ( drive & 0x80 ) ? ( num_drives | 0x80 ) : num_fdds ); - /* Use natural drive number if directed to do so */ - if ( ( drive & 0x7f ) == 0x7f ) - drive = natural_drive; - /* Check that drive number is not in use */ list_for_each_entry ( int13, &int13s, list ) { if ( int13->drive == drive ) { @@ -1667,7 +1665,7 @@ static int int13_hook ( struct uri *uri, unsigned int drive ) { int13_sync_num_drives(); free ( scratch ); - return drive; + return 0; err_guess_geometry: err_parse_iso9660: @@ -1988,32 +1986,7 @@ static int int13_describe ( unsigned int drive ) { return 0; } -/** The "san-drive" setting */ -const struct setting san_drive_setting __setting ( SETTING_SANBOOT_EXTRA, - san-drive ) = { - .name = "san-drive", - .description = "SAN drive number", - .tag = DHCP_EB_SAN_DRIVE, - .type = &setting_type_uint8, -}; - -/** - * Get default SAN drive number - * - * @ret drive Default drive number - */ -static unsigned int int13_default_drive ( void ) { - unsigned long drive; - - /* Use "san-drive" setting, if specified */ - if ( fetch_uint_setting ( NULL, &san_drive_setting, &drive ) >= 0 ) - return drive; - - /* Otherwise, default to booting from first hard disk */ - return 0x80; -} - -PROVIDE_SANBOOT ( pcbios, san_default_drive, int13_default_drive ); +PROVIDE_SANBOOT_INLINE ( pcbios, san_default_drive ); PROVIDE_SANBOOT ( pcbios, san_hook, int13_hook ); PROVIDE_SANBOOT ( pcbios, san_unhook, int13_unhook ); PROVIDE_SANBOOT ( pcbios, san_boot, int13_boot ); diff --git a/roms/ipxe/src/arch/x86/interface/pcbios/int13con.c b/roms/ipxe/src/arch/i386/interface/pcbios/int13con.c index 2414c6909..2414c6909 100644 --- a/roms/ipxe/src/arch/x86/interface/pcbios/int13con.c +++ b/roms/ipxe/src/arch/i386/interface/pcbios/int13con.c diff --git a/roms/ipxe/src/arch/x86/interface/pcbios/memtop_umalloc.c b/roms/ipxe/src/arch/i386/interface/pcbios/memtop_umalloc.c index f1ab73e29..957f8e324 100644 --- a/roms/ipxe/src/arch/x86/interface/pcbios/memtop_umalloc.c +++ b/roms/ipxe/src/arch/i386/interface/pcbios/memtop_umalloc.c @@ -38,9 +38,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <ipxe/memblock.h> #include <ipxe/umalloc.h> -/** Maximum usable address for external allocated memory */ -#define EM_MAX_ADDRESS 0xffffffffUL - /** Alignment of external allocated memory */ #define EM_ALIGN ( 4 * 1024 ) @@ -65,56 +62,6 @@ static userptr_t bottom = UNULL; static size_t heap_size; /** - * Find largest usable memory region - * - * @ret start Start of region - * @ret len Length of region - */ -size_t largest_memblock ( userptr_t *start ) { - struct memory_map memmap; - struct memory_region *region; - physaddr_t max = EM_MAX_ADDRESS; - physaddr_t region_start; - physaddr_t region_end; - size_t region_len; - unsigned int i; - size_t len = 0; - - /* Avoid returning uninitialised data on error */ - *start = UNULL; - - /* Scan through all memory regions */ - get_memmap ( &memmap ); - for ( i = 0 ; i < memmap.count ; i++ ) { - region = &memmap.regions[i]; - DBG ( "Considering [%llx,%llx)\n", region->start, region->end ); - - /* Truncate block to maximum physical address */ - if ( region->start > max ) { - DBG ( "...starts after maximum address %lx\n", max ); - continue; - } - region_start = region->start; - if ( region->end > max ) { - DBG ( "...end truncated to maximum address %lx\n", max); - region_end = 0; /* =max, given the wraparound */ - } else { - region_end = region->end; - } - region_len = ( region_end - region_start ); - - /* Use largest block */ - if ( region_len > len ) { - DBG ( "...new best block found\n" ); - *start = phys_to_user ( region_start ); - len = region_len; - } - } - - return len; -} - -/** * Initialise external heap * */ diff --git a/roms/ipxe/src/arch/x86/interface/pcbios/pcibios.c b/roms/ipxe/src/arch/i386/interface/pcbios/pcibios.c index 07ac0c18d..34efa0b39 100644 --- a/roms/ipxe/src/arch/x86/interface/pcbios/pcibios.c +++ b/roms/ipxe/src/arch/i386/interface/pcbios/pcibios.c @@ -70,7 +70,7 @@ static int pcibios_num_bus ( void ) { */ int pcibios_read ( struct pci_device *pci, uint32_t command, uint32_t *value ){ int discard_b, discard_D; - uint16_t status; + int status; __asm__ __volatile__ ( REAL_CODE ( "stc\n\t" "int $0x1a\n\t" @@ -85,7 +85,7 @@ int pcibios_read ( struct pci_device *pci, uint32_t command, uint32_t *value ){ "b" ( pci->busdevfn ) : "edx" ); - return ( status >> 8 ); + return ( ( status >> 8 ) & 0xff ); } /** @@ -98,7 +98,7 @@ int pcibios_read ( struct pci_device *pci, uint32_t command, uint32_t *value ){ */ int pcibios_write ( struct pci_device *pci, uint32_t command, uint32_t value ){ int discard_b, discard_c, discard_D; - uint16_t status; + int status; __asm__ __volatile__ ( REAL_CODE ( "stc\n\t" "int $0x1a\n\t" @@ -111,7 +111,7 @@ int pcibios_write ( struct pci_device *pci, uint32_t command, uint32_t value ){ "b" ( pci->busdevfn ), "c" ( value ) : "edx" ); - return ( status >> 8 ); + return ( ( status >> 8 ) & 0xff ); } PROVIDE_PCIAPI ( pcbios, pci_num_bus, pcibios_num_bus ); diff --git a/roms/ipxe/src/arch/x86/interface/pcbios/rtc_entropy.c b/roms/ipxe/src/arch/i386/interface/pcbios/rtc_entropy.c index 83c2445f8..9aab03c03 100644 --- a/roms/ipxe/src/arch/x86/interface/pcbios/rtc_entropy.c +++ b/roms/ipxe/src/arch/i386/interface/pcbios/rtc_entropy.c @@ -36,6 +36,10 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <rtc.h> #include <ipxe/entropy.h> +/** RTC "interrupt triggered" flag */ +static uint8_t __text16 ( rtc_flag ); +#define rtc_flag __use_text16 ( rtc_flag ) + /** RTC interrupt handler */ extern void rtc_isr ( void ); @@ -54,27 +58,27 @@ static void rtc_hook_isr ( void ) { /* Preserve registers */ "pushw %%ax\n\t" /* Set "interrupt triggered" flag */ - "movb $0x01, %%cs:rtc_flag\n\t" + "cs movb $0x01, %c0\n\t" /* Read RTC status register C to * acknowledge interrupt */ - "movb %2, %%al\n\t" - "outb %%al, %0\n\t" - "inb %1\n\t" + "movb %3, %%al\n\t" + "outb %%al, %1\n\t" + "inb %2\n\t" /* Send EOI */ "movb $0x20, %%al\n\t" "outb %%al, $0xa0\n\t" "outb %%al, $0x20\n\t" /* Restore registers and return */ "popw %%ax\n\t" - "iret\n\t" - "\nrtc_flag:\n\t" - ".byte 0\n\t" ) + "iret\n\t" ) : - : "i" ( CMOS_ADDRESS ), "i" ( CMOS_DATA ), + : "p" ( __from_text16 ( &rtc_flag ) ), + "i" ( CMOS_ADDRESS ), "i" ( CMOS_DATA ), "i" ( RTC_STATUS_C ) ); - hook_bios_interrupt ( RTC_INT, ( intptr_t ) rtc_isr, &rtc_old_handler ); + hook_bios_interrupt ( RTC_INT, ( unsigned int ) rtc_isr, + &rtc_old_handler ); } /** @@ -84,7 +88,7 @@ static void rtc_hook_isr ( void ) { static void rtc_unhook_isr ( void ) { int rc; - rc = unhook_bios_interrupt ( RTC_INT, ( intptr_t ) rtc_isr, + rc = unhook_bios_interrupt ( RTC_INT, ( unsigned int ) rtc_isr, &rtc_old_handler ); assert ( rc == 0 ); /* Should always be able to unhook */ } @@ -164,9 +168,9 @@ uint8_t rtc_sample ( void ) { REAL_CODE ( /* Enable interrupts */ "sti\n\t" /* Wait for RTC interrupt */ - "movb %b2, %%cs:rtc_flag\n\t" + "cs movb %b2, %c4\n\t" "\n1:\n\t" - "xchgb %b2, %%cs:rtc_flag\n\t" /* Serialize */ + "cs xchgb %b2, %c4\n\t" /* Serialize */ "testb %b2, %b2\n\t" "jz 1b\n\t" /* Read "before" TSC */ @@ -175,9 +179,9 @@ uint8_t rtc_sample ( void ) { "pushl %0\n\t" /* Wait for another RTC interrupt */ "xorb %b2, %b2\n\t" - "movb %b2, %%cs:rtc_flag\n\t" + "cs movb %b2, %c4\n\t" "\n1:\n\t" - "xchgb %b2, %%cs:rtc_flag\n\t" /* Serialize */ + "cs xchgb %b2, %c4\n\t" /* Serialize */ "testb %b2, %b2\n\t" "jz 1b\n\t" /* Read "after" TSC */ @@ -187,8 +191,8 @@ uint8_t rtc_sample ( void ) { /* Disable interrupts */ "cli\n\t" ) - : "=a" ( after ), "=d" ( before ), "=Q" ( temp ) - : "2" ( 0 ) ); + : "=a" ( after ), "=d" ( before ), "=q" ( temp ) + : "2" ( 0 ), "p" ( __from_text16 ( &rtc_flag ) ) ); return ( after - before ); } diff --git a/roms/ipxe/src/arch/x86/interface/pcbios/rtc_time.c b/roms/ipxe/src/arch/i386/interface/pcbios/rtc_time.c index cdbeac8d5..cdbeac8d5 100644 --- a/roms/ipxe/src/arch/x86/interface/pcbios/rtc_time.c +++ b/roms/ipxe/src/arch/i386/interface/pcbios/rtc_time.c diff --git a/roms/ipxe/src/arch/x86/interface/pcbios/vesafb.c b/roms/ipxe/src/arch/i386/interface/pcbios/vesafb.c index 50e485852..9cf2bf29e 100644 --- a/roms/ipxe/src/arch/x86/interface/pcbios/vesafb.c +++ b/roms/ipxe/src/arch/i386/interface/pcbios/vesafb.c @@ -60,21 +60,12 @@ struct console_driver bios_console __attribute__ (( weak )); #define EIO_VBE( code ) \ EUNIQ ( EINFO_EIO, (code), EIO_FAILED, EIO_HARDWARE, EIO_MODE ) -/* Set default console usage if applicable - * - * We accept either CONSOLE_FRAMEBUFFER or CONSOLE_VESAFB. - */ -#if ( defined ( CONSOLE_FRAMEBUFFER ) && ! defined ( CONSOLE_VESAFB ) ) -#define CONSOLE_VESAFB CONSOLE_FRAMEBUFFER -#endif +/* Set default console usage if applicable */ #if ! ( defined ( CONSOLE_VESAFB ) && CONSOLE_EXPLICIT ( CONSOLE_VESAFB ) ) #undef CONSOLE_VESAFB #define CONSOLE_VESAFB ( CONSOLE_USAGE_ALL & ~CONSOLE_USAGE_LOG ) #endif -/** Character height */ -#define VESAFB_CHAR_HEIGHT 16 - /** Font corresponding to selected character width and height */ #define VESAFB_FONT VBE_FONT_8x16 @@ -89,12 +80,12 @@ struct vesafb { physaddr_t start; /** Pixel geometry */ struct fbcon_geometry pixel; + /** Margin */ + struct fbcon_margin margin; /** Colour mapping */ struct fbcon_colour_map map; /** Font definition */ struct fbcon_font font; - /** Character glyphs */ - struct segoff glyphs; /** Saved VGA mode */ uint8_t saved_mode; }; @@ -128,23 +119,11 @@ static int vesafb_rc ( unsigned int status ) { } /** - * Get character glyph - * - * @v character Character - * @v glyph Character glyph to fill in - */ -static void vesafb_glyph ( unsigned int character, uint8_t *glyph ) { - size_t offset = ( character * VESAFB_CHAR_HEIGHT ); - - copy_from_real ( glyph, vesafb.glyphs.segment, - ( vesafb.glyphs.offset + offset ), VESAFB_CHAR_HEIGHT); -} - -/** * Get font definition * */ static void vesafb_font ( void ) { + struct segoff font; /* Get font information * @@ -165,14 +144,13 @@ static void vesafb_font ( void ) { "movw %%es, %%cx\n\t" "movw %%bp, %%dx\n\t" "popw %%bp\n\t" /* gcc bug */ ) - : "=c" ( vesafb.glyphs.segment ), - "=d" ( vesafb.glyphs.offset ) + : "=c" ( font.segment ), + "=d" ( font.offset ) : "a" ( VBE_GET_FONT ), "b" ( VESAFB_FONT ) ); DBGC ( &vbe_buf, "VESAFB has font %04x at %04x:%04x\n", - VESAFB_FONT, vesafb.glyphs.segment, vesafb.glyphs.offset ); - vesafb.font.height = VESAFB_CHAR_HEIGHT; - vesafb.font.glyph = vesafb_glyph; + VESAFB_FONT, font.segment, font.offset ); + vesafb.font.start = real_to_user ( font.segment, font.offset ); } /** @@ -423,6 +401,12 @@ static void vesafb_restore ( void ) { static int vesafb_init ( struct console_configuration *config ) { uint32_t discard_b; uint16_t *mode_numbers; + unsigned int xgap; + unsigned int ygap; + unsigned int left; + unsigned int right; + unsigned int top; + unsigned int bottom; int mode_number; int rc; @@ -448,13 +432,31 @@ static int vesafb_init ( struct console_configuration *config ) { if ( ( rc = vesafb_set_mode ( mode_number ) ) != 0 ) goto err_set_mode; + /* Calculate margin. If the actual screen size is larger than + * the requested screen size, then update the margins so that + * the margin remains relative to the requested screen size. + * (As an exception, if a zero margin was specified then treat + * this as meaning "expand to edge of actual screen".) + */ + xgap = ( vesafb.pixel.width - config->width ); + ygap = ( vesafb.pixel.height - config->height ); + left = ( xgap / 2 ); + right = ( xgap - left ); + top = ( ygap / 2 ); + bottom = ( ygap - top ); + vesafb.margin.left = ( config->left + ( config->left ? left : 0 ) ); + vesafb.margin.right = ( config->right + ( config->right ? right : 0 ) ); + vesafb.margin.top = ( config->top + ( config->top ? top : 0 ) ); + vesafb.margin.bottom = + ( config->bottom + ( config->bottom ? bottom : 0 ) ); + /* Get font data */ vesafb_font(); /* Initialise frame buffer console */ if ( ( rc = fbcon_init ( &vesafb.fbcon, phys_to_user ( vesafb.start ), - &vesafb.pixel, &vesafb.map, &vesafb.font, - config ) ) != 0 ) + &vesafb.pixel, &vesafb.margin, &vesafb.map, + &vesafb.font, config->pixbuf ) ) != 0 ) goto err_fbcon_init; free ( mode_numbers ); diff --git a/roms/ipxe/src/arch/x86/interface/pxe/pxe_call.c b/roms/ipxe/src/arch/i386/interface/pxe/pxe_call.c index 671182991..104313666 100644 --- a/roms/ipxe/src/arch/x86/interface/pxe/pxe_call.c +++ b/roms/ipxe/src/arch/i386/interface/pxe/pxe_call.c @@ -26,8 +26,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <ipxe/uaccess.h> #include <ipxe/init.h> #include <ipxe/profile.h> -#include <ipxe/netdevice.h> -#include <rmsetjmp.h> +#include <setjmp.h> #include <registers.h> #include <biosint.h> #include <pxe.h> @@ -54,14 +53,6 @@ extern void pxe_int_1a ( void ); /** INT 1A hooked flag */ static int int_1a_hooked = 0; -/** Real-mode code segment size */ -extern char _text16_memsz[]; -#define _text16_memsz ( ( size_t ) _text16_memsz ) - -/** Real-mode data segment size */ -extern char _data16_memsz[]; -#define _data16_memsz ( ( size_t ) _data16_memsz ) - /** PXENV_UNDI_TRANSMIT API call profiler */ static struct profiler pxe_api_tx_profiler __profiler = { .name = "pxeapi.tx" }; @@ -274,13 +265,10 @@ struct init_fn pxe_init_fn __init_fn ( INIT_NORMAL ) = { * @v netdev Net device to use as PXE net device */ void pxe_activate ( struct net_device *netdev ) { - uint32_t discard_a; - uint32_t discard_b; - uint32_t discard_d; /* Ensure INT 1A is hooked */ if ( ! int_1a_hooked ) { - hook_bios_interrupt ( 0x1a, ( intptr_t ) pxe_int_1a, + hook_bios_interrupt ( 0x1a, ( unsigned int ) pxe_int_1a, &pxe_int_1a_vector ); devices_get(); int_1a_hooked = 1; @@ -288,15 +276,6 @@ void pxe_activate ( struct net_device *netdev ) { /* Set PXE network device */ pxe_set_netdev ( netdev ); - - /* Notify BIOS of installation */ - __asm__ __volatile__ ( REAL_CODE ( "pushw %%cs\n\t" - "popw %%es\n\t" - "int $0x1a\n\t" ) - : "=a" ( discard_a ), "=b" ( discard_b ), - "=d" ( discard_d ) - : "0" ( 0x564e ), - "1" ( __from_text16 ( &pxenv ) ) ); } /** @@ -313,10 +292,10 @@ int pxe_deactivate ( void ) { /* Ensure INT 1A is unhooked, if possible */ if ( int_1a_hooked ) { if ( ( rc = unhook_bios_interrupt ( 0x1a, - ( intptr_t ) pxe_int_1a, + (unsigned int) pxe_int_1a, &pxe_int_1a_vector ))!= 0){ - DBGC ( &pxe_netdev, "PXE could not unhook INT 1A: %s\n", - strerror ( rc ) ); + DBG ( "Could not unhook INT 1A: %s\n", + strerror ( rc ) ); return rc; } devices_put(); @@ -339,14 +318,10 @@ int pxe_start_nbp ( void ) { int discard_b, discard_c, discard_d, discard_D; uint16_t status; - DBGC ( &pxe_netdev, "PXE NBP starting with netdev %s, code %04x:%04zx, " - "data %04x:%04zx\n", ( pxe_netdev ? pxe_netdev->name : "<none>"), - rm_cs, _text16_memsz, rm_ds, _data16_memsz ); - /* Allow restarting NBP via PXENV_RESTART_TFTP */ jmp = rmsetjmp ( pxe_restart_nbp ); if ( jmp ) - DBGC ( &pxe_netdev, "PXE NBP restarting (%x)\n", jmp ); + DBG ( "Restarting NBP (%x)\n", jmp ); /* Far call to PXE NBP */ __asm__ __volatile__ ( REAL_CODE ( "pushl %%ebp\n\t" /* gcc bug */ @@ -371,31 +346,6 @@ int pxe_start_nbp ( void ) { return 0; } -/** - * Notify BIOS of existence of network device - * - * @v netdev Network device - * @ret rc Return status code - */ -static int pxe_notify ( struct net_device *netdev ) { - - /* Do nothing if we already have a network device */ - if ( pxe_netdev ) - return 0; - - /* Activate (and deactivate) PXE stack to notify BIOS */ - pxe_activate ( netdev ); - pxe_deactivate(); - - return 0; -} - -/** PXE BIOS notification driver */ -struct net_driver pxe_driver __net_driver = { - .name = "PXE", - .probe = pxe_notify, -}; - REQUIRING_SYMBOL ( pxe_api_call ); REQUIRE_OBJECT ( pxe_preboot ); REQUIRE_OBJECT ( pxe_undi ); diff --git a/roms/ipxe/src/arch/x86/interface/pxe/pxe_entry.S b/roms/ipxe/src/arch/i386/interface/pxe/pxe_entry.S index 663aa842e..07852cd50 100644 --- a/roms/ipxe/src/arch/x86/interface/pxe/pxe_entry.S +++ b/roms/ipxe/src/arch/i386/interface/pxe/pxe_entry.S @@ -24,8 +24,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) -#include <librm.h> - .arch i386 /**************************************************************************** @@ -122,7 +120,10 @@ pxenv_null_entry: .section ".text16", "ax", @progbits .code16 pxenv_entry: - virtcall pxe_api_call + pushl $pxe_api_call + pushw %cs + call prot_call + addl $4, %esp lret .size pxenv_entry, . - pxenv_entry diff --git a/roms/ipxe/src/arch/x86/interface/pxe/pxe_exit_hook.c b/roms/ipxe/src/arch/i386/interface/pxe/pxe_exit_hook.c index f92dae0d1..f92dae0d1 100644 --- a/roms/ipxe/src/arch/x86/interface/pxe/pxe_exit_hook.c +++ b/roms/ipxe/src/arch/i386/interface/pxe/pxe_exit_hook.c diff --git a/roms/ipxe/src/arch/x86/interface/pxe/pxe_file.c b/roms/ipxe/src/arch/i386/interface/pxe/pxe_file.c index 456ffb5fd..456ffb5fd 100644 --- a/roms/ipxe/src/arch/x86/interface/pxe/pxe_file.c +++ b/roms/ipxe/src/arch/i386/interface/pxe/pxe_file.c diff --git a/roms/ipxe/src/arch/x86/interface/pxe/pxe_loader.c b/roms/ipxe/src/arch/i386/interface/pxe/pxe_loader.c index e6a2e072a..e6a2e072a 100644 --- a/roms/ipxe/src/arch/x86/interface/pxe/pxe_loader.c +++ b/roms/ipxe/src/arch/i386/interface/pxe/pxe_loader.c diff --git a/roms/ipxe/src/arch/x86/interface/pxe/pxe_preboot.c b/roms/ipxe/src/arch/i386/interface/pxe/pxe_preboot.c index 09e721b34..6e09080bc 100644 --- a/roms/ipxe/src/arch/x86/interface/pxe/pxe_preboot.c +++ b/roms/ipxe/src/arch/i386/interface/pxe/pxe_preboot.c @@ -33,6 +33,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <stdint.h> #include <string.h> #include <stdlib.h> +#include <setjmp.h> #include <ipxe/uaccess.h> #include <ipxe/dhcp.h> #include <ipxe/fakedhcp.h> @@ -43,7 +44,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <ipxe/if_ether.h> #include <basemem_packet.h> #include <biosint.h> -#include <rmsetjmp.h> #include "pxe.h" #include "pxe_call.h" @@ -129,38 +129,6 @@ static union pxe_cached_info __bss16_array ( cached_info, [NUM_CACHED_INFOS] ); #define cached_info __use_data16 ( cached_info ) /** - * Construct cached DHCP packets - * - */ -void pxe_fake_cached_info ( void ) { - struct pxe_dhcp_packet_creator *creator; - union pxe_cached_info *info; - unsigned int i; - int rc; - - /* Sanity check */ - assert ( pxe_netdev != NULL ); - - /* Erase any stale packets */ - memset ( cached_info, 0, sizeof ( cached_info ) ); - - /* Construct all DHCP packets */ - for ( i = 0 ; i < ( sizeof ( pxe_dhcp_packet_creators ) / - sizeof ( pxe_dhcp_packet_creators[0] ) ) ; i++ ) { - - /* Construct DHCP packet */ - creator = &pxe_dhcp_packet_creators[i]; - info = &cached_info[i]; - if ( ( rc = creator->create ( pxe_netdev, info, - sizeof ( *info ) ) ) != 0 ) { - DBGC ( &pxe_netdev, " failed to build packet: %s\n", - strerror ( rc ) ); - /* Continue constructing remaining packets */ - } - } -} - -/** * UNLOAD BASE CODE STACK * * @v None - @@ -181,10 +149,12 @@ pxenv_unload_stack ( struct s_PXENV_UNLOAD_STACK *unload_stack ) { */ static PXENV_EXIT_t pxenv_get_cached_info ( struct s_PXENV_GET_CACHED_INFO *get_cached_info ) { + struct pxe_dhcp_packet_creator *creator; union pxe_cached_info *info; unsigned int idx; size_t len; userptr_t buffer; + int rc; DBGC ( &pxe_netdev, "PXENV_GET_CACHED_INFO %s to %04x:%04x+%x", pxenv_get_cached_info_name ( get_cached_info->PacketType ), @@ -192,15 +162,31 @@ pxenv_get_cached_info ( struct s_PXENV_GET_CACHED_INFO *get_cached_info ) { get_cached_info->Buffer.offset, get_cached_info->BufferSize ); /* Sanity check */ + if ( ! pxe_netdev ) { + DBGC ( &pxe_netdev, "PXENV_GET_CACHED_INFO called with no " + "network device\n" ); + get_cached_info->Status = PXENV_STATUS_UNDI_INVALID_STATE; + return PXENV_EXIT_FAILURE; + } + + /* Sanity check */ idx = ( get_cached_info->PacketType - 1 ); if ( idx >= NUM_CACHED_INFOS ) { DBGC ( &pxe_netdev, " bad PacketType %d\n", get_cached_info->PacketType ); - get_cached_info->Status = PXENV_STATUS_UNSUPPORTED; - return PXENV_EXIT_FAILURE; + goto err; } info = &cached_info[idx]; + /* Construct DHCP packet */ + creator = &pxe_dhcp_packet_creators[idx]; + if ( ( rc = creator->create ( pxe_netdev, info, + sizeof ( *info ) ) ) != 0 ) { + DBGC ( &pxe_netdev, " failed to build packet: %s\n", + strerror ( rc ) ); + goto err; + } + /* Copy packet (if applicable) */ len = get_cached_info->BufferSize; if ( len == 0 ) { @@ -252,6 +238,10 @@ pxenv_get_cached_info ( struct s_PXENV_GET_CACHED_INFO *get_cached_info ) { DBGC ( &pxe_netdev, "\n" ); get_cached_info->Status = PXENV_STATUS_SUCCESS; return PXENV_EXIT_SUCCESS; + + err: + get_cached_info->Status = PXENV_STATUS_OUT_OF_RESOURCES; + return PXENV_EXIT_FAILURE; } /* PXENV_RESTART_TFTP diff --git a/roms/ipxe/src/arch/x86/interface/pxe/pxe_tftp.c b/roms/ipxe/src/arch/i386/interface/pxe/pxe_tftp.c index 3b4c6d847..068d8a7b2 100644 --- a/roms/ipxe/src/arch/x86/interface/pxe/pxe_tftp.c +++ b/roms/ipxe/src/arch/i386/interface/pxe/pxe_tftp.c @@ -160,20 +160,25 @@ static struct pxe_tftp_connection pxe_tftp = { }; /** + * Maximum length of a PXE TFTP URI + * + * The PXE TFTP API provides 128 characters for the filename; the + * extra 128 bytes allow for the remainder of the URI. + */ +#define PXE_TFTP_URI_LEN 256 + +/** * Open PXE TFTP connection * * @v ipaddress IP address - * @v port TFTP server port (in network byte order) + * @v port TFTP server port * @v filename File name * @v blksize Requested block size * @ret rc Return status code */ static int pxe_tftp_open ( IP4_t ipaddress, UDP_PORT_t port, UINT8_t *filename, UINT16_t blksize ) { - union { - struct sockaddr sa; - struct sockaddr_in sin; - } server; + struct in_addr address; struct uri *uri; int rc; @@ -186,15 +191,12 @@ static int pxe_tftp_open ( IP4_t ipaddress, UDP_PORT_t port, pxe_tftp.rc = -EINPROGRESS; /* Construct URI */ - memset ( &server, 0, sizeof ( server ) ); - server.sin.sin_family = AF_INET; - server.sin.sin_addr.s_addr = ipaddress; - server.sin.sin_port = port; - DBG ( " %s", sock_ntoa ( &server.sa ) ); + address.s_addr = ipaddress; + DBG ( " %s", inet_ntoa ( address ) ); if ( port ) DBG ( ":%d", ntohs ( port ) ); DBG ( ":%s", filename ); - uri = pxe_uri ( &server.sa, ( ( char * ) filename ) ); + uri = tftp_uri ( address, ntohs ( port ), ( ( char * ) filename ) ); if ( ! uri ) { DBG ( " could not create URI\n" ); return -ENOMEM; diff --git a/roms/ipxe/src/arch/x86/interface/pxe/pxe_udp.c b/roms/ipxe/src/arch/i386/interface/pxe/pxe_udp.c index 5a04f0865..071cb59db 100644 --- a/roms/ipxe/src/arch/x86/interface/pxe/pxe_udp.c +++ b/roms/ipxe/src/arch/i386/interface/pxe/pxe_udp.c @@ -11,7 +11,6 @@ #include <ipxe/udp.h> #include <ipxe/uaccess.h> #include <ipxe/process.h> -#include <ipxe/netdevice.h> #include <realmode.h> #include <pxe.h> @@ -181,15 +180,6 @@ static PXENV_EXIT_t pxenv_udp_open ( struct s_PXENV_UDP_OPEN *pxenv_udp_open ) { pxe_udp.local.sin_addr.s_addr = pxenv_udp_open->src_ip; DBG ( " %s\n", inet_ntoa ( pxe_udp.local.sin_addr ) ); - /* Open network device, if necessary */ - if ( pxe_netdev && ( ! netdev_is_open ( pxe_netdev ) ) && - ( ( rc = netdev_open ( pxe_netdev ) ) != 0 ) ) { - DBG ( "PXENV_UDP_OPEN could not (implicitly) open %s: %s\n", - pxe_netdev->name, strerror ( rc ) ); - pxenv_udp_open->Status = PXENV_STATUS ( rc ); - return PXENV_EXIT_FAILURE; - } - /* Open promiscuous UDP connection */ intf_restart ( &pxe_udp.xfer, 0 ); if ( ( rc = udp_open_promisc ( &pxe_udp.xfer ) ) != 0 ) { diff --git a/roms/ipxe/src/arch/x86/interface/pxe/pxe_undi.c b/roms/ipxe/src/arch/i386/interface/pxe/pxe_undi.c index 2eb68178a..2eb68178a 100644 --- a/roms/ipxe/src/arch/x86/interface/pxe/pxe_undi.c +++ b/roms/ipxe/src/arch/i386/interface/pxe/pxe_undi.c diff --git a/roms/ipxe/src/arch/x86/interface/pxeparent/pxeparent.c b/roms/ipxe/src/arch/i386/interface/pxeparent/pxeparent.c index cc6101c1f..0b6be9a03 100644 --- a/roms/ipxe/src/arch/x86/interface/pxeparent/pxeparent.c +++ b/roms/ipxe/src/arch/i386/interface/pxeparent/pxeparent.c @@ -208,10 +208,8 @@ int pxeparent_call ( SEGOFF16_t entry, unsigned int function, void *params, size_t params_len ) { struct pxeparent_profiler *profiler = pxeparent_profiler ( function ); PXENV_EXIT_t exit; - uint32_t before; - uint32_t started; - uint32_t stopped; - uint32_t after; + unsigned long started; + unsigned long stopped; int discard_D; int rc; @@ -242,14 +240,12 @@ int pxeparent_call ( SEGOFF16_t entry, unsigned int function, "D" ( __from_data16 ( &pxeparent_params ) ) : "ecx", "esi" ); profile_stop ( &profiler->total ); - before = profile_started ( &profiler->total ); - after = profile_stopped ( &profiler->total ); - profile_start_at ( &profiler->p2r, before ); + profile_start_at ( &profiler->p2r, profile_started ( &profiler->total)); profile_stop_at ( &profiler->p2r, started ); profile_start_at ( &profiler->ext, started ); profile_stop_at ( &profiler->ext, stopped ); profile_start_at ( &profiler->r2p, stopped ); - profile_stop_at ( &profiler->r2p, after ); + profile_stop_at ( &profiler->r2p, profile_stopped ( &profiler->total )); /* Determine return status code based on PXENV_EXIT and * PXENV_STATUS diff --git a/roms/ipxe/src/arch/x86/interface/syslinux/com32_call.c b/roms/ipxe/src/arch/i386/interface/syslinux/com32_call.c index 19fdbaff9..75dcc238f 100644 --- a/roms/ipxe/src/arch/x86/interface/syslinux/com32_call.c +++ b/roms/ipxe/src/arch/i386/interface/syslinux/com32_call.c @@ -46,9 +46,6 @@ uint16_t __bss16 ( com32_saved_sp ); */ void __asmcall com32_intcall ( uint8_t interrupt, physaddr_t inregs_phys, physaddr_t outregs_phys ) { - DBGC ( &com32_regs, "COM32 INT%x in %#08lx out %#08lx\n", - interrupt, inregs_phys, outregs_phys ); - memcpy_user ( virt_to_user( &com32_regs ), 0, phys_to_user ( inregs_phys ), 0, sizeof(com32sys_t) ); @@ -79,7 +76,7 @@ void __asmcall com32_intcall ( uint8_t interrupt, physaddr_t inregs_phys, physad /* patch INT instruction */ "pushw %%ax\n\t" "movb %%ss:(com32_int_vector), %%al\n\t" - "movb %%al, %%cs:(com32_intcall_instr + 1)\n\t" + "movb %%al, %%cs:(com32_intcall_instr + 1)\n\t" /* perform a jump to avoid problems with cache * consistency in self-modifying code on some CPUs (486) */ @@ -109,7 +106,7 @@ void __asmcall com32_intcall ( uint8_t interrupt, physaddr_t inregs_phys, physad if ( outregs_phys ) { memcpy_user ( phys_to_user ( outregs_phys ), 0, - virt_to_user( &com32_regs ), 0, + virt_to_user( &com32_regs ), 0, sizeof(com32sys_t) ); } } @@ -119,9 +116,6 @@ void __asmcall com32_intcall ( uint8_t interrupt, physaddr_t inregs_phys, physad */ void __asmcall com32_farcall ( uint32_t proc, physaddr_t inregs_phys, physaddr_t outregs_phys ) { - DBGC ( &com32_regs, "COM32 farcall %04x:%04x in %#08lx out %#08lx\n", - ( proc >> 16 ), ( proc & 0xffff ), inregs_phys, outregs_phys ); - memcpy_user ( virt_to_user( &com32_regs ), 0, phys_to_user ( inregs_phys ), 0, sizeof(com32sys_t) ); @@ -171,7 +165,7 @@ void __asmcall com32_farcall ( uint32_t proc, physaddr_t inregs_phys, physaddr_t if ( outregs_phys ) { memcpy_user ( phys_to_user ( outregs_phys ), 0, - virt_to_user( &com32_regs ), 0, + virt_to_user( &com32_regs ), 0, sizeof(com32sys_t) ); } } @@ -182,16 +176,13 @@ void __asmcall com32_farcall ( uint32_t proc, physaddr_t inregs_phys, physaddr_t int __asmcall com32_cfarcall ( uint32_t proc, physaddr_t stack, size_t stacksz ) { int32_t eax; - DBGC ( &com32_regs, "COM32 cfarcall %04x:%04x params %#08lx+%#zx\n", - ( proc >> 16 ), ( proc & 0xffff ), stack, stacksz ); - copy_user_to_rm_stack ( phys_to_user ( stack ), stacksz ); com32_farcall_proc = proc; __asm__ __volatile__ ( REAL_CODE ( "lcall *%%ss:(com32_farcall_proc)\n\t" ) : "=a" (eax) - : + : : "ecx", "edx" ); remove_user_from_rm_stack ( 0, stacksz ); diff --git a/roms/ipxe/src/arch/x86/interface/syslinux/com32_wrapper.S b/roms/ipxe/src/arch/i386/interface/syslinux/com32_wrapper.S index d59a3392c..c9d1452b4 100644 --- a/roms/ipxe/src/arch/x86/interface/syslinux/com32_wrapper.S +++ b/roms/ipxe/src/arch/i386/interface/syslinux/com32_wrapper.S @@ -19,82 +19,79 @@ FILE_LICENCE ( GPL2_OR_LATER ) -#include "librm.h" - .text - + .arch i386 .code32 + .globl com32_farcall_wrapper com32_farcall_wrapper: - movl $VIRTUAL(com32_farcall), %eax - jmp com32_wrapper - .code32 + movl $com32_farcall, %eax + jmp com32_wrapper + + .globl com32_cfarcall_wrapper com32_cfarcall_wrapper: - movl $VIRTUAL(com32_cfarcall), %eax - jmp com32_wrapper - .code32 + movl $com32_cfarcall, %eax + jmp com32_wrapper + + .globl com32_intcall_wrapper com32_intcall_wrapper: - movl $VIRTUAL(com32_intcall), %eax - /* fall through */ - .code32 -com32_wrapper: + movl $com32_intcall, %eax + /*jmp com32_wrapper*/ /* fall through */ - /* Disable interrupts */ +com32_wrapper: cli /* Switch to internal virtual address space */ - call _phys_to_virt - -#ifdef __x86_64__ - - .code64 + call _phys_to_virt - /* Preserve registers which are callee-save for COM32 (i386 API) */ - pushq %rdi - pushq %rsi - pushq %rbp + mov %eax, (com32_helper_function) - /* Extract parameters from stack */ - movl 28(%rsp), %edi - movl 32(%rsp), %esi - movl 36(%rsp), %edx + /* Save external COM32 stack pointer */ + movl %esp, (com32_external_esp) - /* Align stack pointer */ - movq %rsp, %rbp - andq $~0x07, %rsp + /* Copy arguments to caller-save registers */ + movl 12(%esp), %eax + movl 8(%esp), %ecx + movl 4(%esp), %edx - /* Call helper function */ - movslq %eax, %rax - call *%rax + /* Switch to internal stack */ + movl (com32_internal_esp), %esp - /* Restore stack pointer */ - movq %rbp, %rsp + /* Copy arguments to internal stack */ + pushl %eax + pushl %ecx + pushl %edx - /* Restore registers */ - popq %rbp - popq %rsi - popq %rdi + call *(com32_helper_function) -#else /* _x86_64 */ + /* Clean up stack */ + addl $12, %esp - /* Call helper function */ - pushl 12(%esp) - pushl 12(%esp) - pushl 12(%esp) - call *%eax - addl $12, %esp - -#endif /* _x86_64 */ + /* Save internal stack pointer and restore external stack pointer */ + movl %esp, (com32_internal_esp) + movl (com32_external_esp), %esp /* Switch to external flat physical address space */ - call _virt_to_phys - .code32 + call _virt_to_phys - /* Reenable interrupts and return */ sti ret + + + .data + +/* Internal iPXE virtual address space %esp */ +.globl com32_internal_esp +.lcomm com32_internal_esp, 4 + +/* External flat physical address space %esp */ +.globl com32_external_esp +.lcomm com32_external_esp, 4 + +/* Function pointer of helper to call */ +.lcomm com32_helper_function, 4 diff --git a/roms/ipxe/src/arch/x86/interface/syslinux/comboot_call.c b/roms/ipxe/src/arch/i386/interface/syslinux/comboot_call.c index 2f5c252c1..69d94c407 100644 --- a/roms/ipxe/src/arch/x86/interface/syslinux/comboot_call.c +++ b/roms/ipxe/src/arch/i386/interface/syslinux/comboot_call.c @@ -32,7 +32,7 @@ FILE_LICENCE ( GPL2_OR_LATER ); #include <comboot.h> #include <bzimage.h> #include <pxe_call.h> -#include <rmsetjmp.h> +#include <setjmp.h> #include <string.h> #include <ipxe/posix_io.h> #include <ipxe/process.h> @@ -489,7 +489,7 @@ static __asmcall void int22 ( struct i386_all_regs *ix86 ) { struct in_addr addr; copy_from_user ( hostname, hostname_u, 0, len + 1 ); - + /* TODO: * "If the hostname does not contain a dot (.), the * local domain name is automatically appended." @@ -519,7 +519,7 @@ static __asmcall void int22 ( struct i386_all_regs *ix86 ) { /* Jump to real-mode entry point */ __asm__ __volatile__ ( - REAL_CODE ( + REAL_CODE ( "pushw %0\n\t" "popw %%ds\n\t" "pushl %1\n\t" @@ -660,30 +660,42 @@ void hook_comboot_interrupts ( ) { __asm__ __volatile__ ( TEXT16_CODE ( "\nint20_wrapper:\n\t" - VIRT_CALL ( int20 ) - "clc\n\t" + "pushl %0\n\t" + "pushw %%cs\n\t" + "call prot_call\n\t" + "addw $4, %%sp\n\t" "call patch_cf\n\t" - "iret\n\t" ) ); + "iret\n\t" ) + : : "i" ( int20 ) ); - hook_bios_interrupt ( 0x20, ( intptr_t ) int20_wrapper, &int20_vector ); + hook_bios_interrupt ( 0x20, ( unsigned int ) int20_wrapper, + &int20_vector ); __asm__ __volatile__ ( TEXT16_CODE ( "\nint21_wrapper:\n\t" - VIRT_CALL ( int21 ) - "clc\n\t" + "pushl %0\n\t" + "pushw %%cs\n\t" + "call prot_call\n\t" + "addw $4, %%sp\n\t" "call patch_cf\n\t" - "iret\n\t" ) ); + "iret\n\t" ) + : : "i" ( int21 ) ); - hook_bios_interrupt ( 0x21, ( intptr_t ) int21_wrapper, &int21_vector ); + hook_bios_interrupt ( 0x21, ( unsigned int ) int21_wrapper, + &int21_vector ); __asm__ __volatile__ ( TEXT16_CODE ( "\nint22_wrapper:\n\t" - VIRT_CALL ( int22 ) - "clc\n\t" + "pushl %0\n\t" + "pushw %%cs\n\t" + "call prot_call\n\t" + "addw $4, %%sp\n\t" "call patch_cf\n\t" - "iret\n\t" ) ); + "iret\n\t" ) + : : "i" ( int22) ); - hook_bios_interrupt ( 0x22, ( intptr_t ) int22_wrapper, &int22_vector ); + hook_bios_interrupt ( 0x22, ( unsigned int ) int22_wrapper, + &int22_vector ); } /** @@ -691,13 +703,13 @@ void hook_comboot_interrupts ( ) { */ void unhook_comboot_interrupts ( ) { - unhook_bios_interrupt ( 0x20, ( intptr_t ) int20_wrapper, + unhook_bios_interrupt ( 0x20, ( unsigned int ) int20_wrapper, &int20_vector ); - unhook_bios_interrupt ( 0x21, ( intptr_t ) int21_wrapper, + unhook_bios_interrupt ( 0x21, ( unsigned int ) int21_wrapper, &int21_vector ); - unhook_bios_interrupt ( 0x22, ( intptr_t ) int22_wrapper, + unhook_bios_interrupt ( 0x22, ( unsigned int ) int22_wrapper, &int22_vector ); } diff --git a/roms/ipxe/src/arch/x86/interface/syslinux/comboot_resolv.c b/roms/ipxe/src/arch/i386/interface/syslinux/comboot_resolv.c index 03bbfd04a..03bbfd04a 100644 --- a/roms/ipxe/src/arch/x86/interface/syslinux/comboot_resolv.c +++ b/roms/ipxe/src/arch/i386/interface/syslinux/comboot_resolv.c diff --git a/roms/ipxe/src/arch/x86/interface/vmware/guestinfo.c b/roms/ipxe/src/arch/i386/interface/vmware/guestinfo.c index a0530c8d1..a0530c8d1 100644 --- a/roms/ipxe/src/arch/x86/interface/vmware/guestinfo.c +++ b/roms/ipxe/src/arch/i386/interface/vmware/guestinfo.c diff --git a/roms/ipxe/src/arch/x86/interface/vmware/guestrpc.c b/roms/ipxe/src/arch/i386/interface/vmware/guestrpc.c index ef7ee8151..ef7ee8151 100644 --- a/roms/ipxe/src/arch/x86/interface/vmware/guestrpc.c +++ b/roms/ipxe/src/arch/i386/interface/vmware/guestrpc.c diff --git a/roms/ipxe/src/arch/x86/interface/vmware/vmconsole.c b/roms/ipxe/src/arch/i386/interface/vmware/vmconsole.c index f7df4f75b..f7df4f75b 100644 --- a/roms/ipxe/src/arch/x86/interface/vmware/vmconsole.c +++ b/roms/ipxe/src/arch/i386/interface/vmware/vmconsole.c diff --git a/roms/ipxe/src/arch/x86/interface/vmware/vmware.c b/roms/ipxe/src/arch/i386/interface/vmware/vmware.c index a415465fb..a415465fb 100644 --- a/roms/ipxe/src/arch/x86/interface/vmware/vmware.c +++ b/roms/ipxe/src/arch/i386/interface/vmware/vmware.c diff --git a/roms/ipxe/src/arch/x86/prefix/bootpart.S b/roms/ipxe/src/arch/i386/prefix/bootpart.S index 6d0c6034a..6d0c6034a 100644 --- a/roms/ipxe/src/arch/x86/prefix/bootpart.S +++ b/roms/ipxe/src/arch/i386/prefix/bootpart.S diff --git a/roms/ipxe/src/arch/x86/prefix/dskprefix.S b/roms/ipxe/src/arch/i386/prefix/dskprefix.S index 0503f113d..7aa017ccd 100644 --- a/roms/ipxe/src/arch/x86/prefix/dskprefix.S +++ b/roms/ipxe/src/arch/i386/prefix/dskprefix.S @@ -18,8 +18,6 @@ FILE_LICENCE ( GPL2_ONLY ) -#include <librm.h> - .equ BOOTSEG, 0x07C0 /* original address of boot-sector */ .equ SYSSEG, 0x1000 /* system loaded at SYSSEG<<4 */ @@ -372,8 +370,10 @@ start_runtime: lret .section ".text16", "awx", @progbits 1: - /* Run iPXE */ - virtcall main + pushl $main + pushw %cs + call prot_call + popl %ecx /* discard */ /* Uninstall iPXE */ call uninstall diff --git a/roms/ipxe/src/arch/x86/prefix/exeprefix.S b/roms/ipxe/src/arch/i386/prefix/exeprefix.S index c351456e2..5c648d51d 100644 --- a/roms/ipxe/src/arch/x86/prefix/exeprefix.S +++ b/roms/ipxe/src/arch/i386/prefix/exeprefix.S @@ -24,8 +24,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) -#include <librm.h> - /* Initial temporary stack size */ #define EXE_STACK_SIZE 0x400 @@ -150,7 +148,10 @@ _exe_start: movl %esi, cmdline_phys /* Run iPXE */ - virtcall main + pushl $main + pushw %cs + call prot_call + popl %ecx /* discard */ /* Uninstall iPXE */ call uninstall diff --git a/roms/ipxe/src/arch/x86/prefix/hdprefix.S b/roms/ipxe/src/arch/i386/prefix/hdprefix.S index 24f5d3850..1d012d80b 100644 --- a/roms/ipxe/src/arch/x86/prefix/hdprefix.S +++ b/roms/ipxe/src/arch/i386/prefix/hdprefix.S @@ -1,7 +1,5 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) -#include <librm.h> - .text .arch i386 .section ".prefix", "awx", @progbits @@ -101,8 +99,10 @@ start_image: lret .section ".text16", "awx", @progbits 1: - /* Run iPXE */ - virtcall main + pushl $main + pushw %cs + call prot_call + popl %ecx /* discard */ /* Uninstall iPXE */ call uninstall diff --git a/roms/ipxe/src/arch/x86/prefix/isaromprefix.S b/roms/ipxe/src/arch/i386/prefix/isaromprefix.S index fb49819ee..fb49819ee 100644 --- a/roms/ipxe/src/arch/x86/prefix/isaromprefix.S +++ b/roms/ipxe/src/arch/i386/prefix/isaromprefix.S diff --git a/roms/ipxe/src/arch/x86/prefix/kkkpxeprefix.S b/roms/ipxe/src/arch/i386/prefix/kkkpxeprefix.S index 6e43cd26a..6e43cd26a 100644 --- a/roms/ipxe/src/arch/x86/prefix/kkkpxeprefix.S +++ b/roms/ipxe/src/arch/i386/prefix/kkkpxeprefix.S diff --git a/roms/ipxe/src/arch/x86/prefix/kkpxeprefix.S b/roms/ipxe/src/arch/i386/prefix/kkpxeprefix.S index 3c17dbdb1..3c17dbdb1 100644 --- a/roms/ipxe/src/arch/x86/prefix/kkpxeprefix.S +++ b/roms/ipxe/src/arch/i386/prefix/kkpxeprefix.S diff --git a/roms/ipxe/src/arch/x86/prefix/kpxeprefix.S b/roms/ipxe/src/arch/i386/prefix/kpxeprefix.S index 200006d83..200006d83 100644 --- a/roms/ipxe/src/arch/x86/prefix/kpxeprefix.S +++ b/roms/ipxe/src/arch/i386/prefix/kpxeprefix.S diff --git a/roms/ipxe/src/arch/x86/prefix/libprefix.S b/roms/ipxe/src/arch/i386/prefix/libprefix.S index 533be981e..7d5c1ed53 100644 --- a/roms/ipxe/src/arch/x86/prefix/libprefix.S +++ b/roms/ipxe/src/arch/i386/prefix/libprefix.S @@ -24,8 +24,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) -#include <librm.h> - .arch i386 /* Image compression enabled */ @@ -71,7 +69,7 @@ progress_\@: * %ds:di : next character in output buffer (if applicable) ***************************************************************************** */ - .section ".prefix.print_character", "awx", @progbits + .section ".prefix.lib", "awx", @progbits .code16 .globl print_character print_character: @@ -109,7 +107,7 @@ print_character: * %ds:di : next character in output buffer (if applicable) ***************************************************************************** */ - .section ".prefix.print_space", "awx", @progbits + .section ".prefix.lib", "awx", @progbits .code16 .globl print_space print_space: @@ -134,7 +132,7 @@ print_space: * %ds:di : next character in output buffer (if applicable) ***************************************************************************** */ - .section ".prefix.print_message", "awx", @progbits + .section ".prefix.lib", "awx", @progbits .code16 .globl print_message print_message: @@ -164,7 +162,7 @@ print_message: * %ds:di : next character in output buffer (if applicable) ***************************************************************************** */ - .section ".prefix.print_hex", "awx", @progbits + .section ".prefix.lib", "awx", @progbits .code16 .globl print_hex_dword print_hex_dword: @@ -212,7 +210,7 @@ print_hex_nibble: * %ds:di : next character in output buffer (if applicable) ***************************************************************************** */ - .section ".prefix.print_pci_busdevfn", "awx", @progbits + .section ".prefix.lib", "awx", @progbits .code16 .globl print_pci_busdevfn print_pci_busdevfn: @@ -249,7 +247,7 @@ print_pci_busdevfn: * %ds:di : next character in output buffer (if applicable) ***************************************************************************** */ - .section ".prefix.print_kill_line", "awx", @progbits + .section ".prefix.lib", "awx", @progbits .code16 .globl print_kill_line print_kill_line: @@ -287,7 +285,7 @@ print_kill_line: * None **************************************************************************** */ - .section ".prefix.copy_bytes", "awx", @progbits + .section ".prefix.lib", "awx", @progbits .code16 copy_bytes: pushl %ecx @@ -310,7 +308,7 @@ copy_bytes: * None **************************************************************************** */ - .section ".prefix.zero_bytes", "awx", @progbits + .section ".prefix.lib", "awx", @progbits .code16 zero_bytes: pushl %ecx @@ -341,12 +339,11 @@ zero_bytes: * Returns: * %esi : next source physical address * %edi : next destination physical address - * CF : as returned by memcpy()-like function * Corrupts: * None **************************************************************************** */ - .section ".prefix.process_bytes", "awx", @progbits + .section ".prefix.lib", "awx", @progbits .code16 process_bytes: @@ -357,7 +354,6 @@ process_bytes: pushl %ebp /* Construct GDT on stack (since .prefix may not be writable) */ - .equ GDT_LEN, 0x20 .equ PM_DS, 0x18 /* Flat data segment */ pushl $0x00cf9300 pushl $0x0000ffff @@ -371,7 +367,7 @@ process_bytes: pushw $0xffff pushl $0 /* Base and length */ pushw %ss - pushw $( GDT_LEN - 1 ) + pushw $0x1f movzwl %sp, %ebp shll $4, 0x02(%bp) addl %ebp, 0x02(%bp) @@ -409,9 +405,7 @@ process_bytes: /* Return to (flat) real mode */ movl %cr0, %eax - pushfw andb $0!CR0_PE, %al - popfw movl %eax, %cr0 lret 2: /* lret will ljmp to here */ @@ -437,7 +431,7 @@ process_bytes: /* Restore GDT */ data32 lgdt -8(%bp) - leaw GDT_LEN(%bp), %sp + addw $( 8 /* saved GDT */ + ( PM_DS + 8 ) /* GDT on stack */ ), %sp /* Restore registers and return */ popl %ebp @@ -465,7 +459,6 @@ process_bytes: call *%bx /* Convert %ds:esi and %es:edi back to physical addresses */ - pushfw xorl %eax, %eax movw %ds, %ax shll $4, %eax @@ -474,7 +467,6 @@ process_bytes: movw %es, %ax shll $4, %eax addl %eax, %edi - popfw /* Restore registers and return */ popw %es @@ -499,12 +491,11 @@ process_bytes: * Returns: * %esi : next source physical address (will be a multiple of 16) * %edi : next destination physical address (will be a multiple of 16) - * CF set on failure * Corrupts: * none **************************************************************************** */ - .section ".prefix.install_block", "awx", @progbits + .section ".prefix.lib", "awx", @progbits .code16 install_block: /* Preserve registers */ @@ -518,7 +509,6 @@ install_block: movw $copy_bytes, %bx #endif call process_bytes - jc 99f /* Zero .bss portion */ negl %ecx @@ -530,9 +520,9 @@ install_block: addl $0xf, %esi andl $~0xf, %esi addl $0xf, %edi - andl $~0xf, %edi /* Will also clear CF */ + andl $~0xf, %edi -99: /* Restore registers and return */ + /* Restore registers and return */ popw %bx popl %ecx ret @@ -554,7 +544,7 @@ install_block: * none **************************************************************************** */ - .section ".prefix.alloc_basemem", "awx", @progbits + .section ".prefix.lib", "awx", @progbits .code16 .globl alloc_basemem alloc_basemem: @@ -568,11 +558,14 @@ alloc_basemem: shlw $6, %ax /* Calculate .data16 segment address */ - subw $_data16_memsz_ppgh, %ax + subw $_data16_memsz_pgh, %ax pushw %ax - /* Calculate .text16 segment address */ - subw $_text16_memsz_ppgh, %ax + /* Calculate .text16 segment address. Round down to ensure + * low bits are zero, to speed up mode transitions under KVM. + */ + subw $_text16_memsz_pgh, %ax + andb $~0x03, %al pushw %ax /* Update FBMS */ @@ -601,7 +594,7 @@ alloc_basemem: * none **************************************************************************** */ - .section ".text16.free_basemem", "ax", @progbits + .section ".text16", "ax", @progbits .code16 .globl free_basemem free_basemem: @@ -623,8 +616,8 @@ free_basemem: /* OK to free memory */ movw %cs, %ax - addw $_text16_memsz_ppgh, %ax - addw $_data16_memsz_ppgh, %ax + addw $_text16_memsz_pgh, %ax + addw $_data16_memsz_pgh, %ax shrw $6, %ax movw %ax, %fs:0x13 xorw %ax, %ax @@ -635,7 +628,7 @@ free_basemem: ret .size free_basemem, . - free_basemem - .section ".text16.data.hooked_bios_interrupts", "aw", @progbits + .section ".text16.data", "aw", @progbits .globl hooked_bios_interrupts hooked_bios_interrupts: .word 0 @@ -655,7 +648,7 @@ hooked_bios_interrupts: * none **************************************************************************** */ - .section ".prefix.install", "awx", @progbits + .section ".prefix.lib", "awx", @progbits .code16 .globl install install: @@ -698,7 +691,7 @@ install: * none **************************************************************************** */ - .section ".prefix.install_prealloc", "awx", @progbits + .section ".prefix.lib", "awx", @progbits .code16 .globl install_prealloc install_prealloc: @@ -738,7 +731,6 @@ install_prealloc: movl $_text16_early_filesz, %ecx movl $_text16_early_memsz, %edx call install_block /* .text16.early */ - jc install_block_death popl %ecx /* Calculate offset to next block */ subl %esi, %ecx negl %ecx @@ -757,8 +749,17 @@ install_prealloc: pushw $access_highmem lret 1: /* Die if we could not access high memory */ - jc access_highmem_death - + jnc 3f + movw $a20_death_message, %si + xorw %di, %di + call print_message +2: jmp 2b + .section ".prefix.data", "aw", @progbits +a20_death_message: + .asciz "\nHigh memory inaccessible - cannot continue\n" + .size a20_death_message, . - a20_death_message + .previous +3: #endif /* Open payload (which may not yet be in memory) */ @@ -769,7 +770,25 @@ install_prealloc: pushw $open_payload lret 1: /* Die if we could not access the payload */ - jc open_payload_death + jnc 3f + xorw %di, %di + movl %esi, %eax + call print_hex_dword + call print_space + movl %ecx, %eax + call print_hex_dword + movw $payload_death_message, %si + call print_message +2: /* Halt system */ + cli + hlt + jmp 2b + .section ".prefix.data", "aw", @progbits +payload_death_message: + .asciz "\nPayload inaccessible - cannot continue\n" + .size payload_death_message, . - payload_death_message + .previous +3: /* Calculate physical address of payload (i.e. first source) */ testl %esi, %esi @@ -783,14 +802,12 @@ install_prealloc: movl $_text16_late_filesz, %ecx movl $_text16_late_memsz, %edx call install_block /* .text16.late */ - jc install_block_death progress " .data16\n" movzwl %bx, %edi shll $4, %edi movl $_data16_filesz, %ecx movl $_data16_filesz, %edx /* do not zero our temporary stack */ call install_block /* .data16 */ - jc install_block_death /* Set up %ds for access to .data16 */ movw %bx, %ds @@ -813,7 +830,6 @@ install_prealloc: movw %ax, %di addl $0x400, %edi subl $_textdata_memsz_kb, %edi - andw $~0x03, %di shll $10, %edi /* Sanity check: if we have ended up below 1MB, use 1MB */ cmpl $0x100000, %edi @@ -830,7 +846,6 @@ install_prealloc: movl $_textdata_filesz, %ecx movl $_textdata_memsz, %edx call install_block - jc install_block_death popl %edi #endif /* KEEP_IT_REAL */ @@ -854,15 +869,6 @@ install_prealloc: movw %ax, (init_librm_vector+2) lcall *init_librm_vector - /* Prepare for return to .prefix segment */ - pushw %cs - - /* Jump to .text16 segment */ - pushw %ax - pushw $1f - lret - .section ".text16.install_prealloc", "ax", @progbits -1: /* Inhibit INT 15,e820 and INT 15,e801 if applicable */ testl %ebp, %ebp jnz 1f @@ -874,13 +880,11 @@ install_prealloc: * ready for the copy to the new location. */ progress " relocate\n" - virtcall relocate + movw %ax, (prot_call_vector+2) + pushl $relocate + lcall *prot_call_vector + popl %edx /* discard */ - /* Jump back to .prefix segment */ - pushw $1f - lret - .section ".prefix.install_prealloc", "awx", @progbits -1: /* Copy code to new location */ progress " copy\n" pushl %edi @@ -917,7 +921,7 @@ install_prealloc: /* Vectors for far calls to .text16 functions. Must be in * .data16, since .prefix may not be writable. */ - .section ".data16.install_prealloc", "aw", @progbits + .section ".data16", "aw", @progbits #ifdef KEEP_IT_REAL init_libkir_vector: .word init_libkir @@ -928,6 +932,10 @@ init_librm_vector: .word init_librm .word 0 .size init_librm_vector, . - init_librm_vector +prot_call_vector: + .word prot_call + .word 0 + .size prot_call_vector, . - prot_call_vector #endif close_payload_vector: .word close_payload @@ -935,7 +943,7 @@ close_payload_vector: .size close_payload_vector, . - close_payload_vector /* Dummy routines to open and close payload */ - .section ".text16.early.data.open_payload", "aw", @progbits + .section ".text16.early.data", "aw", @progbits .weak open_payload .weak close_payload open_payload: @@ -945,52 +953,6 @@ close_payload: .size open_payload, . - open_payload .size close_payload, . - close_payload - /* Report installation failure */ - .section ".prefix.install_death", "ax", @progbits -install_death: - pushw %cs - popw %ds - xorw %di, %di - call print_hex_dword - call print_space - movl %esi, %eax - call print_hex_dword - call print_space - movl %ecx, %eax - call print_hex_dword - movw $install_death_message, %si - call print_message -2: /* Halt system */ - cli - hlt - jmp 2b - .size install_death, . - install_death - .section ".prefix.data.install_death_message", "aw", @progbits -install_death_message: - .asciz "\nInstallation failed - cannot continue\n" - .size install_death_message, . - install_death_message - - /* Report failure to access high memory */ - .section ".prefix.install_block_death", "ax", @progbits -install_block_death: - movl $0x1b101b10, %eax - jmp install_death - .size install_block_death, . - install_block_death - - /* Report failure to access high memory */ - .section ".prefix.access_highmem_death", "ax", @progbits -access_highmem_death: - movl $0x0a200a20, %eax - jmp install_death - .size access_highmem_death, . - access_highmem_death - - /* Report failure to open payload */ - .section ".prefix.open_payload_death", "ax", @progbits -open_payload_death: - xorl %eax, %eax - jmp install_death - .size open_payload_death, . - open_payload_death - /**************************************************************************** * uninstall * @@ -1004,7 +966,7 @@ open_payload_death: * none **************************************************************************** */ - .section ".text16.uninstall", "ax", @progbits + .section ".text16", "ax", @progbits .code16 .globl uninstall uninstall: diff --git a/roms/ipxe/src/arch/x86/prefix/lkrnprefix.S b/roms/ipxe/src/arch/i386/prefix/lkrnprefix.S index 922181f0e..64135e14b 100644 --- a/roms/ipxe/src/arch/x86/prefix/lkrnprefix.S +++ b/roms/ipxe/src/arch/i386/prefix/lkrnprefix.S @@ -1,7 +1,5 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) -#include <librm.h> - #define BZI_LOAD_HIGH_ADDR 0x100000 .text @@ -199,7 +197,10 @@ no_cmd_line: movl %ecx, initrd_len /* Run iPXE */ - virtcall main + pushl $main + pushw %cs + call prot_call + popl %ecx /* discard */ /* Uninstall iPXE */ call uninstall diff --git a/roms/ipxe/src/arch/x86/prefix/mbr.S b/roms/ipxe/src/arch/i386/prefix/mbr.S index a1e237de8..a1e237de8 100644 --- a/roms/ipxe/src/arch/x86/prefix/mbr.S +++ b/roms/ipxe/src/arch/i386/prefix/mbr.S diff --git a/roms/ipxe/src/arch/x86/prefix/mromprefix.S b/roms/ipxe/src/arch/i386/prefix/mromprefix.S index b636b92af..b636b92af 100644 --- a/roms/ipxe/src/arch/x86/prefix/mromprefix.S +++ b/roms/ipxe/src/arch/i386/prefix/mromprefix.S diff --git a/roms/ipxe/src/arch/x86/prefix/nbiprefix.S b/roms/ipxe/src/arch/i386/prefix/nbiprefix.S index de38e4af6..16c79566c 100644 --- a/roms/ipxe/src/arch/x86/prefix/nbiprefix.S +++ b/roms/ipxe/src/arch/i386/prefix/nbiprefix.S @@ -1,7 +1,5 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) -#include <librm.h> - .text .arch i386 .code16 @@ -68,8 +66,10 @@ _nbi_start: lret .section ".text16", "awx", @progbits 1: - /* Run iPXE */ - virtcall main + pushl $main + pushw %cs + call prot_call + popl %ecx /* discard */ /* Uninstall iPXE */ call uninstall diff --git a/roms/ipxe/src/arch/x86/prefix/nullprefix.S b/roms/ipxe/src/arch/i386/prefix/nullprefix.S index bd0ff339e..bd0ff339e 100644 --- a/roms/ipxe/src/arch/x86/prefix/nullprefix.S +++ b/roms/ipxe/src/arch/i386/prefix/nullprefix.S diff --git a/roms/ipxe/src/arch/x86/prefix/pciromprefix.S b/roms/ipxe/src/arch/i386/prefix/pciromprefix.S index 5a5a49647..5a5a49647 100644 --- a/roms/ipxe/src/arch/x86/prefix/pciromprefix.S +++ b/roms/ipxe/src/arch/i386/prefix/pciromprefix.S diff --git a/roms/ipxe/src/arch/x86/prefix/pxeprefix.S b/roms/ipxe/src/arch/i386/prefix/pxeprefix.S index 52ea18039..465ce4345 100644 --- a/roms/ipxe/src/arch/x86/prefix/pxeprefix.S +++ b/roms/ipxe/src/arch/i386/prefix/pxeprefix.S @@ -16,7 +16,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) .org 0 .code16 -#include <librm.h> #include <undi.h> #define STACK_MAGIC ( 'L' + ( 'R' << 8 ) + ( 'E' << 16 ) + ( 'T' << 24 ) ) @@ -821,7 +820,10 @@ run_ipxe: movl %ecx, cached_dhcpack_phys /* Run main program */ - virtcall main + pushl $main + pushw %cs + call prot_call + popl %ecx /* discard */ /* Uninstall iPXE */ call uninstall diff --git a/roms/ipxe/src/arch/x86/prefix/romprefix.S b/roms/ipxe/src/arch/i386/prefix/romprefix.S index f4ca20677..18dda2b37 100644 --- a/roms/ipxe/src/arch/x86/prefix/romprefix.S +++ b/roms/ipxe/src/arch/i386/prefix/romprefix.S @@ -8,7 +8,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) -#include <librm.h> #include <config/general.h> #include <config/branding.h> @@ -124,7 +123,7 @@ pci_devlist_end: .long pciheader_image_length .long 512 .long 0 - .ascii "ADHW" + .ascii ZINFO_TYPE_ADxW .long pciheader_runtime_length .long 512 .long 0 @@ -403,22 +402,19 @@ pmm_scan: /* Shrink ROM */ movb shrunk_rom_size, %al movb %al, romheader_size -1: /* Allocate decompression PMM block. Allow 4kB for page - * alignment and round up the size to the nearest 128kB, then - * use the size within the PMM handle; this allows the same - * decompression area to be shared between multiple iPXE ROMs - * even with differing build IDs +1: /* Allocate decompression PMM block. Round up the size to the + * nearest 128kB and use the size within the PMM handle; this + * allows the same decompression area to be shared between + * multiple iPXE ROMs even with differing build IDs */ movl $_textdata_memsz_pgh, %ecx - addl $( 0x00000100 /* 4kB */ + 0x00001fff /* 128kB - 1 */ ), %ecx - andl $( 0xffffe000 /* ~( 128kB - 1 ) */ ), %ecx + addl $0x00001fff, %ecx + andl $0xffffe000, %ecx movl %ecx, %ebx shrw $12, %bx orl $PMM_HANDLE_BASE_DECOMPRESS_TO, %ebx movw $get_pmm_decompress_to, %bp call get_pmm - addl $( 0x00000fff /* 4kB - 1 */ ), %esi - andl $( 0xfffff000 /* ~( 4kB - 1 ) */ ), %esi movl %esi, decompress_to /* Restore registers */ popal @@ -439,25 +435,13 @@ no_pmm: * memory. Will be a no-op for lower PCI versions. */ .ifeqs BUSTYPE, "PCIR" - /* Get runtime segment address and length */ - movw %gs, %ax - movw %ax, %es - movzbw romheader_size, %cx - /* Print runtime segment address */ xorw %di, %di call print_space + movw %gs, %ax call print_hex_word - /* Fail if we have insufficient space in final location */ - movw %cs, %si - cmpw %si, %ax - je 1f - cmpw pciheader_runtime_length, %cx - jbe 1f - movb $( '!' ), %al - call print_character - xorw %cx, %cx -1: /* Copy to final location */ + movzbw romheader_size, %cx shlw $9, %cx + movw %ax, %es xorw %si, %si xorw %di, %di cs rep movsb @@ -807,8 +791,11 @@ exec: /* Set %ds = %cs */ #endif /* AUTOBOOT_ROM_FILTER */ .endif - /* Run iPXE */ - virtcall main + /* Call main() */ + pushl $main + pushw %cs + call prot_call + popl %eax /* discard */ /* Set up flat real mode for return to BIOS */ call flatten_real_mode diff --git a/roms/ipxe/src/arch/x86/prefix/undiloader.S b/roms/ipxe/src/arch/i386/prefix/undiloader.S index 530b48e8a..5cace44b7 100644 --- a/roms/ipxe/src/arch/x86/prefix/undiloader.S +++ b/roms/ipxe/src/arch/i386/prefix/undiloader.S @@ -1,7 +1,5 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) -#include <librm.h> - .text .code16 .arch i386 @@ -20,16 +18,13 @@ undiloader: pushw %ds pushw %es pushw %bx - /* ROM segment address to %ds */ pushw %cs popw %ds - /* UNDI loader parameter structure address into %es:%di */ movw %sp, %bx movw %ss:22(%bx), %di movw %ss:24(%bx), %es - /* Install to specified real-mode addresses */ pushw %di movw %es:12(%di), %bx @@ -39,17 +34,16 @@ undiloader: orl $0xffffffff, %ebp /* Allow arbitrary relocation */ call install_prealloc popw %di - - /* Jump to .text16 segment */ - pushw %ax + /* Call UNDI loader C code */ + pushl $pxe_loader_call + pushw %cs pushw $1f + pushw %ax + pushw $prot_call lret - .section ".text16", "ax", @progbits -1: - /* Call UNDI loader C code */ - virtcall pxe_loader_call - -1: /* Restore registers and return */ +1: popw %bx /* discard */ + popw %bx /* discard */ + /* Restore registers and return */ popw %bx popw %es popw %ds @@ -57,3 +51,4 @@ undiloader: popl %edi popl %esi lret + .size undiloader, . - undiloader diff --git a/roms/ipxe/src/arch/x86/prefix/unlzma.S b/roms/ipxe/src/arch/i386/prefix/unlzma.S index ce18c756f..8d4b3c1a8 100644 --- a/roms/ipxe/src/arch/x86/prefix/unlzma.S +++ b/roms/ipxe/src/arch/i386/prefix/unlzma.S @@ -58,9 +58,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); .code32 #endif /* CODE16 */ -#define CRCPOLY 0xedb88320 -#define CRCSEED 0xffffffff - /**************************************************************************** * Debugging **************************************************************************** @@ -866,44 +863,6 @@ bcj_filter: .size bcj_filter, . - bcj_filter /**************************************************************************** - * Verify CRC32 - * - * Parameters: - * %ds:%esi : Start of compressed input data - * %edx : Length of compressed input data (including CRC) - * Returns: - * CF clear if CRC32 is zero - * All other registers are preserved - * Corrupts: - * %eax - * %ebx - * %ecx - * %edx - * %esi - **************************************************************************** - */ -verify_crc32: - /* Calculate CRC */ - addl %esi, %edx - movl $CRCSEED, %ebx -1: ADDR32 lodsb - xorb %al, %bl - movw $8, %cx -2: rcrl %ebx - jnc 3f - xorl $CRCPOLY, %ebx -3: ADDR16 loop 2b - cmpl %esi, %edx - jne 1b - /* Set CF if result is nonzero */ - testl %ebx, %ebx - jz 1f - stc -1: /* Return */ - ret - .size verify_crc32, . - verify_crc32 - -/**************************************************************************** * decompress (real-mode or 16/32-bit protected-mode near call) * * Decompress data @@ -914,7 +873,6 @@ verify_crc32: * Returns: * %ds:%esi - End of compressed input data * %es:%edi - End of decompressed output data - * CF set if CRC32 was incorrect * All other registers are preserved * * NOTE: It would be possible to build a smaller version of the @@ -930,13 +888,6 @@ decompress: pushl %ecx pushl %edx pushl %ebp - /* Verify CRC32 */ - ADDR32 lodsl - movl %eax, %edx - pushl %esi - call verify_crc32 - popl %esi - jc 99f /* Allocate parameter block */ subl $sizeof__lzma_dec, %esp movl %esp, %ebp @@ -977,11 +928,8 @@ decompress: movl out_start(%ebp), %esi call bcj_filter popl %esi - /* Skip CRC */ - ADDR32 lodsl - /* Free parameter block (and clear CF) */ + /* Restore registers and return */ addl $sizeof__lzma_dec, %esp -99: /* Restore registers and return */ popl %ebp popl %edx popl %ecx diff --git a/roms/ipxe/src/arch/x86/prefix/unlzma16.S b/roms/ipxe/src/arch/i386/prefix/unlzma16.S index 32b43f0dc..32b43f0dc 100644 --- a/roms/ipxe/src/arch/x86/prefix/unlzma16.S +++ b/roms/ipxe/src/arch/i386/prefix/unlzma16.S diff --git a/roms/ipxe/src/arch/x86/prefix/usbdisk.S b/roms/ipxe/src/arch/i386/prefix/usbdisk.S index 9676406e2..9676406e2 100644 --- a/roms/ipxe/src/arch/x86/prefix/usbdisk.S +++ b/roms/ipxe/src/arch/i386/prefix/usbdisk.S diff --git a/roms/ipxe/src/arch/x86/scripts/pcbios.lds b/roms/ipxe/src/arch/i386/scripts/i386.lds index c9a91c02b..38c89e14b 100644 --- a/roms/ipxe/src/arch/x86/scripts/pcbios.lds +++ b/roms/ipxe/src/arch/i386/scripts/i386.lds @@ -27,20 +27,6 @@ SECTIONS { PROVIDE ( _max_align = 16 ); /* - * Values used in page table calculations - * - * On older versions of ld (without the SANE_EXPR feature), - * numeric literals within a section description tend to be - * interpreted as section-relative symbols. - * - */ - _page_size = 4096; - _page_size_1 = ( _page_size - 1 ); - _pte_size = 8; - _pte_count = ( _page_size / _pte_size ); - _pte_count_1 = ( _pte_count - 1 ); - - /* * Allow decompressor to require a minimum amount of temporary stack * space. * @@ -141,18 +127,6 @@ SECTIONS { *(COMMON) *(.stack) *(.stack.*) - _pages = .; - *(.pages) - *(.pages.*) - _use_page_tables = ABSOLUTE ( . ) - ABSOLUTE ( _pages ); - _textdata_paged_len = - ABSOLUTE ( ABSOLUTE ( . ) - ABSOLUTE ( _textdata ) ); - _textdata_ptes = - ABSOLUTE ( ( _textdata_paged_len + _page_size_1 ) / _page_size ); - _textdata_pdes = - ABSOLUTE ( ( _textdata_ptes + _pte_count_1 ) / _pte_count ); - . += ( _use_page_tables ? ( _textdata_pdes * _page_size ) : 0 ); - _epages = .; _etextdata = .; } _textdata_filesz = ABSOLUTE ( _mtextdata ) - ABSOLUTE ( _textdata ); @@ -273,8 +247,8 @@ SECTIONS { * Values calculated to save code from doing it * */ - _text16_memsz_ppgh = ( ( ( _text16_memsz + 63 ) / 64 ) * 4 ); - _data16_memsz_ppgh = ( ( ( _data16_memsz + 63 ) / 64 ) * 4 ); + _text16_memsz_pgh = ( ( _text16_memsz + 15 ) / 16 ); + _data16_memsz_pgh = ( ( _data16_memsz + 15 ) / 16 ); _textdata_memsz_pgh = ( ( _textdata_memsz + 15 ) / 16 ); _textdata_memsz_kb = ( ( _textdata_memsz + 1023 ) / 1024 ); } diff --git a/roms/ipxe/src/arch/x86/transitions/liba20.S b/roms/ipxe/src/arch/i386/transitions/liba20.S index 6c1e1f62f..6c1e1f62f 100644 --- a/roms/ipxe/src/arch/x86/transitions/liba20.S +++ b/roms/ipxe/src/arch/i386/transitions/liba20.S diff --git a/roms/ipxe/src/arch/x86/transitions/libkir.S b/roms/ipxe/src/arch/i386/transitions/libkir.S index fa9459d52..fa9459d52 100644 --- a/roms/ipxe/src/arch/x86/transitions/libkir.S +++ b/roms/ipxe/src/arch/i386/transitions/libkir.S diff --git a/roms/ipxe/src/arch/x86/transitions/libpm.S b/roms/ipxe/src/arch/i386/transitions/libpm.S index e69de29bb..e69de29bb 100644 --- a/roms/ipxe/src/arch/x86/transitions/libpm.S +++ b/roms/ipxe/src/arch/i386/transitions/libpm.S diff --git a/roms/ipxe/src/arch/i386/transitions/librm.S b/roms/ipxe/src/arch/i386/transitions/librm.S new file mode 100644 index 000000000..863e22415 --- /dev/null +++ b/roms/ipxe/src/arch/i386/transitions/librm.S @@ -0,0 +1,671 @@ +/* + * librm: a library for interfacing to real-mode code + * + * Michael Brown <mbrown@fensystems.co.uk> + * + */ + +FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) + +/* Drag in local definitions */ +#include "librm.h" + +/* For switches to/from protected mode */ +#define CR0_PE 1 + +/* Size of various C data structures */ +#define SIZEOF_I386_SEG_REGS 12 +#define SIZEOF_I386_REGS 32 +#define SIZEOF_REAL_MODE_REGS ( SIZEOF_I386_SEG_REGS + SIZEOF_I386_REGS ) +#define SIZEOF_I386_FLAGS 4 +#define SIZEOF_I386_ALL_REGS ( SIZEOF_REAL_MODE_REGS + SIZEOF_I386_FLAGS ) + + .arch i386 + +/**************************************************************************** + * Global descriptor table + * + * Call init_librm to set up the GDT before attempting to use any + * protected-mode code. + * + * NOTE: This must be located before prot_to_real, otherwise gas + * throws a "can't handle non absolute segment in `ljmp'" error due to + * not knowing the value of REAL_CS when the ljmp is encountered. + * + * Note also that putting ".word gdt_end - gdt - 1" directly into + * gdt_limit, rather than going via gdt_length, will also produce the + * "non absolute segment" error. This is most probably a bug in gas. + **************************************************************************** + */ + .section ".data16", "aw", @progbits + .align 16 +gdt: +gdtr: /* The first GDT entry is unused, the GDTR can fit here. */ +gdt_limit: .word gdt_length - 1 +gdt_base: .long 0 + .word 0 /* padding */ + + .org gdt + VIRTUAL_CS, 0 +virtual_cs: /* 32 bit protected mode code segment, virtual addresses */ + .word 0xffff, 0 + .byte 0, 0x9f, 0xcf, 0 + + .org gdt + VIRTUAL_DS, 0 +virtual_ds: /* 32 bit protected mode data segment, virtual addresses */ + .word 0xffff, 0 + .byte 0, 0x93, 0xcf, 0 + + .org gdt + PHYSICAL_CS, 0 +physical_cs: /* 32 bit protected mode code segment, physical addresses */ + .word 0xffff, 0 + .byte 0, 0x9f, 0xcf, 0 + + .org gdt + PHYSICAL_DS, 0 +physical_ds: /* 32 bit protected mode data segment, physical addresses */ + .word 0xffff, 0 + .byte 0, 0x93, 0xcf, 0 + + .org gdt + REAL_CS, 0 +real_cs: /* 16 bit real mode code segment */ + .word 0xffff, 0 + .byte 0, 0x9b, 0x00, 0 + + .org gdt + REAL_DS +real_ds: /* 16 bit real mode data segment */ + .word 0xffff, ( REAL_DS << 4 ) + .byte 0, 0x93, 0x00, 0 + +gdt_end: + .equ gdt_length, gdt_end - gdt + +/**************************************************************************** + * init_librm (real-mode far call, 16-bit real-mode far return address) + * + * Initialise the GDT ready for transitions to protected mode. + * + * Parameters: + * %cs : .text16 segment + * %ds : .data16 segment + * %edi : Physical base of protected-mode code (virt_offset) + **************************************************************************** + */ + .section ".text16", "ax", @progbits + .code16 + .globl init_librm +init_librm: + /* Preserve registers */ + pushl %eax + pushl %ebx + + /* Store virt_offset and set up virtual_cs and virtual_ds segments */ + movl %edi, %eax + movw $virtual_cs, %bx + call set_seg_base + movw $virtual_ds, %bx + call set_seg_base + movl %edi, rm_virt_offset + + /* Negate virt_offset */ + negl %edi + + /* Store rm_cs and text16, set up real_cs segment */ + xorl %eax, %eax + movw %cs, %ax + movw %ax, %cs:rm_cs + shll $4, %eax + movw $real_cs, %bx + call set_seg_base + addr32 leal (%eax, %edi), %ebx + movl %ebx, rm_text16 + + /* Store rm_ds and data16 */ + xorl %eax, %eax + movw %ds, %ax + movw %ax, %cs:rm_ds + shll $4, %eax + addr32 leal (%eax, %edi), %ebx + movl %ebx, rm_data16 + + /* Set GDT base */ + movl %eax, gdt_base + addl $gdt, gdt_base + + /* Initialise IDT */ + pushl $init_idt + pushw %cs + call prot_call + popl %eax /* discard */ + + /* Restore registers */ + negl %edi + popl %ebx + popl %eax + lret + + .section ".text16", "ax", @progbits + .code16 +set_seg_base: +1: movw %ax, 2(%bx) + rorl $16, %eax + movb %al, 4(%bx) + movb %ah, 7(%bx) + roll $16, %eax + ret + +/**************************************************************************** + * real_to_prot (real-mode near call, 32-bit virtual return address) + * + * Switch from 16-bit real-mode to 32-bit protected mode with virtual + * addresses. The real-mode %ss:sp is stored in rm_ss and rm_sp, and + * the protected-mode %esp is restored from the saved pm_esp. + * Interrupts are disabled. All other registers may be destroyed. + * + * The return address for this function should be a 32-bit virtual + * address. + * + * Parameters: + * %ecx : number of bytes to move from RM stack to PM stack + * + **************************************************************************** + */ + .section ".text16", "ax", @progbits + .code16 +real_to_prot: + /* Enable A20 line */ + call enable_a20 + /* A failure at this point is fatal, and there's nothing we + * can do about it other than lock the machine to make the + * problem immediately visible. + */ +1: jc 1b + + /* Make sure we have our data segment available */ + movw %cs:rm_ds, %ax + movw %ax, %ds + + /* Add virt_offset, text16 and data16 to stack to be + * copied, and also copy the return address. + */ + pushl rm_virt_offset + pushl rm_text16 + pushl rm_data16 + addw $16, %cx /* %ecx must be less than 64kB anyway */ + + /* Real-mode %ss:%sp => %ebp:%edx and virtual address => %esi */ + xorl %ebp, %ebp + movw %ss, %bp + movzwl %sp, %edx + movl %ebp, %eax + shll $4, %eax + addr32 leal (%eax,%edx), %esi + subl rm_virt_offset, %esi + + /* Load protected-mode global descriptor table */ + data32 lgdt gdtr + + /* Zero segment registers. This wastes around 12 cycles on + * real hardware, but saves a substantial number of emulated + * instructions under KVM. + */ + xorw %ax, %ax + movw %ax, %ds + movw %ax, %es + movw %ax, %fs + movw %ax, %gs + movw %ax, %ss + + /* Switch to protected mode */ + cli + movl %cr0, %eax + orb $CR0_PE, %al + movl %eax, %cr0 + data32 ljmp $VIRTUAL_CS, $r2p_pmode + .section ".text", "ax", @progbits + .code32 +r2p_pmode: + /* Set up protected-mode data segments and stack pointer */ + movw $VIRTUAL_DS, %ax + movw %ax, %ds + movw %ax, %es + movw %ax, %fs + movw %ax, %gs + movw %ax, %ss + movl pm_esp, %esp + + /* Load protected-mode interrupt descriptor table */ + lidt idtr + + /* Record real-mode %ss:sp (after removal of data) */ + movw %bp, rm_ss + addl %ecx, %edx + movw %dx, rm_sp + + /* Move data from RM stack to PM stack */ + subl %ecx, %esp + movl %esp, %edi + rep movsb + + /* Publish virt_offset, text16 and data16 for PM code to use */ + popl data16 + popl text16 + popl virt_offset + + /* Return to virtual address */ + ret + +/**************************************************************************** + * prot_to_real (protected-mode near call, 32-bit real-mode return address) + * + * Switch from 32-bit protected mode with virtual addresses to 16-bit + * real mode. The protected-mode %esp is stored in pm_esp and the + * real-mode %ss:sp is restored from the saved rm_ss and rm_sp. The + * high word of the real-mode %esp is set to zero. All real-mode data + * segment registers are loaded from the saved rm_ds. Interrupts are + * *not* enabled, since we want to be able to use prot_to_real in an + * ISR. All other registers may be destroyed. + * + * The return address for this function should be a 32-bit (sic) + * real-mode offset within .code16. + * + * Parameters: + * %ecx : number of bytes to move from PM stack to RM stack + * %esi : real-mode global and interrupt descriptor table registers + * + **************************************************************************** + */ + .section ".text", "ax", @progbits + .code32 +prot_to_real: + /* Copy real-mode global descriptor table register to RM code segment */ + movl text16, %edi + leal rm_gdtr(%edi), %edi + movsw + movsl + + /* Load real-mode interrupt descriptor table register */ + lidt (%esi) + + /* Add return address to data to be moved to RM stack */ + addl $4, %ecx + + /* Real-mode %ss:sp => %ebp:edx and virtual address => %edi */ + movzwl rm_ss, %ebp + movzwl rm_sp, %edx + subl %ecx, %edx + movl %ebp, %eax + shll $4, %eax + leal (%eax,%edx), %edi + subl virt_offset, %edi + + /* Move data from PM stack to RM stack */ + movl %esp, %esi + rep movsb + + /* Record protected-mode %esp (after removal of data) */ + movl %esi, pm_esp + + /* Load real-mode segment limits */ + movw $REAL_DS, %ax + movw %ax, %ds + movw %ax, %es + movw %ax, %fs + movw %ax, %gs + movw %ax, %ss + ljmp $REAL_CS, $p2r_rmode + .section ".text16", "ax", @progbits + .code16 +p2r_rmode: + /* Load real-mode GDT */ + data32 lgdt %cs:rm_gdtr + /* Switch to real mode */ + movl %cr0, %eax + andb $0!CR0_PE, %al + movl %eax, %cr0 +p2r_ljmp_rm_cs: + ljmp $0, $1f +1: + /* Set up real-mode data segments and stack pointer */ + movw %cs:rm_ds, %ax + movw %ax, %ds + movw %ax, %es + movw %ax, %fs + movw %ax, %gs + movw %bp, %ss + movl %edx, %esp + + /* Return to real-mode address */ + data32 ret + + + /* Real-mode code and data segments. Assigned by the call to + * init_librm. rm_cs doubles as the segment part of the jump + * instruction used by prot_to_real. Both are located in + * .text16 rather than .data16: rm_cs since it forms part of + * the jump instruction within the code segment, and rm_ds + * since real-mode code needs to be able to locate the data + * segment with no other reference available. + */ + .globl rm_cs + .equ rm_cs, ( p2r_ljmp_rm_cs + 3 ) + + .section ".text16.data", "aw", @progbits + .globl rm_ds +rm_ds: .word 0 + + /* Real-mode global and interrupt descriptor table registers */ + .section ".text16.data", "aw", @progbits +rm_gdtr: + .word 0 /* Limit */ + .long 0 /* Base */ + +/**************************************************************************** + * prot_call (real-mode far call, 16-bit real-mode far return address) + * + * Call a specific C function in the protected-mode code. The + * prototype of the C function must be + * void function ( struct i386_all_regs *ix86 ); + * ix86 will point to a struct containing the real-mode registers + * at entry to prot_call. + * + * All registers will be preserved across prot_call(), unless the C + * function explicitly overwrites values in ix86. Interrupt status + * and GDT will also be preserved. Gate A20 will be enabled. + * + * Note that prot_call() does not rely on the real-mode stack + * remaining intact in order to return, since everything relevant is + * copied to the protected-mode stack for the duration of the call. + * In particular, this means that a real-mode prefix can make a call + * to main() which will return correctly even if the prefix's stack + * gets vapourised during the Etherboot run. (The prefix cannot rely + * on anything else on the stack being preserved, so should move any + * critical data to registers before calling main()). + * + * Parameters: + * function : virtual address of protected-mode function to call + * + * Example usage: + * pushl $pxe_api_call + * call prot_call + * addw $4, %sp + * to call in to the C function + * void pxe_api_call ( struct i386_all_regs *ix86 ); + **************************************************************************** + */ + +#define PC_OFFSET_GDT ( 0 ) +#define PC_OFFSET_IDT ( PC_OFFSET_GDT + 6 ) +#define PC_OFFSET_IX86 ( PC_OFFSET_IDT + 6 ) +#define PC_OFFSET_RETADDR ( PC_OFFSET_IX86 + SIZEOF_I386_ALL_REGS ) +#define PC_OFFSET_FUNCTION ( PC_OFFSET_RETADDR + 4 ) +#define PC_OFFSET_END ( PC_OFFSET_FUNCTION + 4 ) + + .section ".text16", "ax", @progbits + .code16 + .globl prot_call +prot_call: + /* Preserve registers, flags and GDT on external RM stack */ + pushfl + pushal + pushw %gs + pushw %fs + pushw %es + pushw %ds + pushw %ss + pushw %cs + subw $PC_OFFSET_IX86, %sp + movw %sp, %bp + sidt PC_OFFSET_IDT(%bp) + sgdt PC_OFFSET_GDT(%bp) + + /* For sanity's sake, clear the direction flag as soon as possible */ + cld + + /* Switch to protected mode and move register dump to PM stack */ + movl $PC_OFFSET_END, %ecx + pushl $pc_pmode + jmp real_to_prot + .section ".text", "ax", @progbits + .code32 +pc_pmode: + /* Call function */ + leal PC_OFFSET_IX86(%esp), %eax + pushl %eax + call *(PC_OFFSET_FUNCTION+4)(%esp) + popl %eax /* discard */ + + /* Switch to real mode and move register dump back to RM stack */ + movl $PC_OFFSET_END, %ecx + movl %esp, %esi + pushl $pc_rmode + jmp prot_to_real + .section ".text16", "ax", @progbits + .code16 +pc_rmode: + /* Restore registers and flags and return */ + addw $( PC_OFFSET_IX86 + 4 /* also skip %cs and %ss */ ), %sp + popw %ds + popw %es + popw %fs + popw %gs + popal + /* popal skips %esp. We therefore want to do "movl -20(%sp), + * %esp", but -20(%sp) is not a valid 80386 expression. + * Fortunately, prot_to_real() zeroes the high word of %esp, so + * we can just use -20(%esp) instead. + */ + addr32 movl -20(%esp), %esp + popfl + lret + +/**************************************************************************** + * real_call (protected-mode near call, 32-bit virtual return address) + * + * Call a real-mode function from protected-mode code. + * + * The non-segment register values will be passed directly to the + * real-mode code. The segment registers will be set as per + * prot_to_real. The non-segment register values set by the real-mode + * function will be passed back to the protected-mode caller. A + * result of this is that this routine cannot be called directly from + * C code, since it clobbers registers that the C ABI expects the + * callee to preserve. + * + * librm.h defines a convenient macro REAL_CODE() for using real_call. + * See librm.h and realmode.h for details and examples. + * + * Parameters: + * (32-bit) near pointer to real-mode function to call + * + * Returns: none + **************************************************************************** + */ + +#define RC_OFFSET_PRESERVE_REGS ( 0 ) +#define RC_OFFSET_RETADDR ( RC_OFFSET_PRESERVE_REGS + SIZEOF_I386_REGS ) +#define RC_OFFSET_FUNCTION ( RC_OFFSET_RETADDR + 4 ) +#define RC_OFFSET_END ( RC_OFFSET_FUNCTION + 4 ) + + .section ".text", "ax", @progbits + .code32 + .globl real_call +real_call: + /* Create register dump and function pointer copy on PM stack */ + pushal + pushl RC_OFFSET_FUNCTION(%esp) + + /* Switch to real mode and move register dump to RM stack */ + movl $( RC_OFFSET_RETADDR + 4 /* function pointer copy */ ), %ecx + pushl $rc_rmode + movl $rm_default_gdtr_idtr, %esi + jmp prot_to_real + .section ".text16", "ax", @progbits + .code16 +rc_rmode: + /* Call real-mode function */ + popl rc_function + popal + call *rc_function + pushal + + /* For sanity's sake, clear the direction flag as soon as possible */ + cld + + /* Switch to protected mode and move register dump back to PM stack */ + movl $RC_OFFSET_RETADDR, %ecx + pushl $rc_pmode + jmp real_to_prot + .section ".text", "ax", @progbits + .code32 +rc_pmode: + /* Restore registers and return */ + popal + ret + + + /* Function vector, used because "call xx(%sp)" is not a valid + * 16-bit expression. + */ + .section ".data16", "aw", @progbits +rc_function: .word 0, 0 + + /* Default real-mode global and interrupt descriptor table registers */ + .section ".data", "aw", @progbits +rm_default_gdtr_idtr: + .word 0 /* Global descriptor table limit */ + .long 0 /* Global descriptor table base */ + .word 0x03ff /* Interrupt descriptor table limit */ + .long 0 /* Interrupt descriptor table base */ + +/**************************************************************************** + * flatten_real_mode (real-mode near call) + * + * Switch to flat real mode + * + **************************************************************************** + */ + .section ".text16", "ax", @progbits + .code16 + .globl flatten_real_mode +flatten_real_mode: + /* Modify GDT to use flat real mode */ + movb $0x8f, real_cs + 6 + movb $0x8f, real_ds + 6 + /* Call dummy protected-mode function */ + pushl $flatten_dummy + pushw %cs + call prot_call + addw $4, %sp + /* Restore GDT */ + movb $0x00, real_cs + 6 + movb $0x00, real_ds + 6 + /* Return */ + ret + + .section ".text", "ax", @progbits + .code32 +flatten_dummy: + ret + +/**************************************************************************** + * Interrupt wrapper + * + * Used by the protected-mode interrupt vectors to call the + * interrupt() function. + * + * May be entered with either physical or virtual stack segment. + **************************************************************************** + */ + .globl interrupt_wrapper +interrupt_wrapper: + /* Preserve segment registers and original %esp */ + pushl %ds + pushl %es + pushl %fs + pushl %gs + pushl %ss + pushl %esp + + /* Switch to virtual addressing */ + call _intr_to_virt + + /* Expand IRQ number to whole %eax register */ + movzbl %al, %eax + + /* Call interrupt handler */ + call interrupt + + /* Restore original stack and segment registers */ + lss (%esp), %esp + popl %ss + popl %gs + popl %fs + popl %es + popl %ds + + /* Restore registers and return */ + popal + iret + +/**************************************************************************** + * Stored real-mode and protected-mode stack pointers + * + * The real-mode stack pointer is stored here whenever real_to_prot + * is called and restored whenever prot_to_real is called. The + * converse happens for the protected-mode stack pointer. + * + * Despite initial appearances this scheme is, in fact re-entrant, + * because program flow dictates that we always return via the point + * we left by. For example: + * PXE API call entry + * 1 real => prot + * ... + * Print a text string + * ... + * 2 prot => real + * INT 10 + * 3 real => prot + * ... + * ... + * 4 prot => real + * PXE API call exit + * + * At point 1, the RM mode stack value, say RPXE, is stored in + * rm_ss,sp. We want this value to still be present in rm_ss,sp when + * we reach point 4. + * + * At point 2, the RM stack value is restored from RPXE. At point 3, + * the RM stack value is again stored in rm_ss,sp. This *does* + * overwrite the RPXE that we have stored there, but it's the same + * value, since the code between points 2 and 3 has managed to return + * to us. + **************************************************************************** + */ + .section ".data", "aw", @progbits + .globl rm_sp +rm_sp: .word 0 + .globl rm_ss +rm_ss: .word 0 +pm_esp: .long _estack + +/**************************************************************************** + * Virtual address offsets + * + * These are used by the protected-mode code to map between virtual + * and physical addresses, and to access variables in the .text16 or + * .data16 segments. + **************************************************************************** + */ + /* Internal copies, created by init_librm (which runs in real mode) */ + .section ".data16", "aw", @progbits +rm_virt_offset: .long 0 +rm_text16: .long 0 +rm_data16: .long 0 + + /* Externally-visible copies, created by real_to_prot */ + .section ".data", "aw", @progbits + .globl virt_offset +virt_offset: .long 0 + .globl text16 +text16: .long 0 + .globl data16 +data16: .long 0 diff --git a/roms/ipxe/src/arch/i386/transitions/librm_mgmt.c b/roms/ipxe/src/arch/i386/transitions/librm_mgmt.c new file mode 100644 index 000000000..becb02677 --- /dev/null +++ b/roms/ipxe/src/arch/i386/transitions/librm_mgmt.c @@ -0,0 +1,158 @@ +/* + * librm: a library for interfacing to real-mode code + * + * Michael Brown <mbrown@fensystems.co.uk> + * + */ + +FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); + +#include <stdint.h> +#include <ipxe/profile.h> +#include <realmode.h> +#include <pic8259.h> + +/* + * This file provides functions for managing librm. + * + */ + +/** The interrupt wrapper */ +extern char interrupt_wrapper[]; + +/** The interrupt vectors */ +static struct interrupt_vector intr_vec[NUM_INT]; + +/** The interrupt descriptor table */ +struct interrupt_descriptor idt[NUM_INT] __attribute__ (( aligned ( 16 ) )); + +/** The interrupt descriptor table register */ +struct idtr idtr = { + .limit = ( sizeof ( idt ) - 1 ), +}; + +/** Timer interrupt profiler */ +static struct profiler timer_irq_profiler __profiler = { .name = "irq.timer" }; + +/** Other interrupt profiler */ +static struct profiler other_irq_profiler __profiler = { .name = "irq.other" }; + +/** + * Allocate space on the real-mode stack and copy data there from a + * user buffer + * + * @v data User buffer + * @v size Size of stack data + * @ret sp New value of real-mode stack pointer + */ +uint16_t copy_user_to_rm_stack ( userptr_t data, size_t size ) { + userptr_t rm_stack; + rm_sp -= size; + rm_stack = real_to_user ( rm_ss, rm_sp ); + memcpy_user ( rm_stack, 0, data, 0, size ); + return rm_sp; +}; + +/** + * Deallocate space on the real-mode stack, optionally copying back + * data to a user buffer. + * + * @v data User buffer + * @v size Size of stack data + */ +void remove_user_from_rm_stack ( userptr_t data, size_t size ) { + if ( data ) { + userptr_t rm_stack = real_to_user ( rm_ss, rm_sp ); + memcpy_user ( rm_stack, 0, data, 0, size ); + } + rm_sp += size; +}; + +/** + * Set interrupt vector + * + * @v intr Interrupt number + * @v vector Interrupt vector, or NULL to disable + */ +void set_interrupt_vector ( unsigned int intr, void *vector ) { + struct interrupt_descriptor *idte; + + idte = &idt[intr]; + idte->segment = VIRTUAL_CS; + idte->attr = ( vector ? ( IDTE_PRESENT | IDTE_TYPE_IRQ32 ) : 0 ); + idte->low = ( ( ( uint32_t ) vector ) & 0xffff ); + idte->high = ( ( ( uint32_t ) vector ) >> 16 ); +} + +/** + * Initialise interrupt descriptor table + * + */ +void init_idt ( void ) { + struct interrupt_vector *vec; + unsigned int intr; + + /* Initialise the interrupt descriptor table and interrupt vectors */ + for ( intr = 0 ; intr < NUM_INT ; intr++ ) { + vec = &intr_vec[intr]; + vec->pushal = PUSHAL_INSN; + vec->movb = MOVB_INSN; + vec->intr = intr; + vec->jmp = JMP_INSN; + vec->offset = ( ( uint32_t ) interrupt_wrapper - + ( uint32_t ) vec->next ); + set_interrupt_vector ( intr, vec ); + } + DBGC ( &intr_vec[0], "INTn vector at %p+%zxn (phys %#lx+%zxn)\n", + intr_vec, sizeof ( intr_vec[0] ), + virt_to_phys ( intr_vec ), sizeof ( intr_vec[0] ) ); + + /* Initialise the interrupt descriptor table register */ + idtr.base = virt_to_phys ( idt ); +} + +/** + * Determine interrupt profiler (for debugging) + * + * @v intr Interrupt number + * @ret profiler Profiler + */ +static struct profiler * interrupt_profiler ( int intr ) { + + switch ( intr ) { + case IRQ_INT ( 0 ) : + return &timer_irq_profiler; + default: + return &other_irq_profiler; + } +} + +/** + * Interrupt handler + * + * @v intr Interrupt number + */ +void __attribute__ (( cdecl, regparm ( 1 ) )) interrupt ( int intr ) { + struct profiler *profiler = interrupt_profiler ( intr ); + uint32_t discard_eax; + + /* Reissue interrupt in real mode */ + profile_start ( profiler ); + __asm__ __volatile__ ( REAL_CODE ( "movb %%al, %%cs:(1f + 1)\n\t" + "\n1:\n\t" + "int $0x00\n\t" ) + : "=a" ( discard_eax ) : "0" ( intr ) ); + profile_stop ( profiler ); + profile_exclude ( profiler ); +} + +PROVIDE_UACCESS_INLINE ( librm, phys_to_user ); +PROVIDE_UACCESS_INLINE ( librm, user_to_phys ); +PROVIDE_UACCESS_INLINE ( librm, virt_to_user ); +PROVIDE_UACCESS_INLINE ( librm, user_to_virt ); +PROVIDE_UACCESS_INLINE ( librm, userptr_add ); +PROVIDE_UACCESS_INLINE ( librm, memcpy_user ); +PROVIDE_UACCESS_INLINE ( librm, memmove_user ); +PROVIDE_UACCESS_INLINE ( librm, memset_user ); +PROVIDE_UACCESS_INLINE ( librm, strlen_user ); +PROVIDE_UACCESS_INLINE ( librm, memchr_user ); diff --git a/roms/ipxe/src/arch/x86/transitions/librm_test.c b/roms/ipxe/src/arch/i386/transitions/librm_test.c index ba4254fe4..f1a517eda 100644 --- a/roms/ipxe/src/arch/x86/transitions/librm_test.c +++ b/roms/ipxe/src/arch/i386/transitions/librm_test.c @@ -52,13 +52,13 @@ static struct profiler r2p_profiler __profiler = { .name = "r2p" }; /** Real-mode call profiler */ static struct profiler real_call_profiler __profiler = { .name = "real_call" }; -/** Virtual call profiler */ -static struct profiler virt_call_profiler __profiler = { .name = "virt_call" }; +/** Protected-mode call profiler */ +static struct profiler prot_call_profiler __profiler = { .name = "prot_call" }; /** - * Dummy function for profiling tests + * Dummy protected-mode function */ -static __asmcall void librm_test_call ( struct i386_all_regs *ix86 __unused ) { +static void librm_test_prot_call ( void ) { /* Do nothing */ } @@ -69,11 +69,9 @@ static __asmcall void librm_test_call ( struct i386_all_regs *ix86 __unused ) { static void librm_test_exec ( void ) { unsigned int i; unsigned long timestamp; - uint32_t timestamp_lo; - uint32_t timestamp_hi; - uint32_t started; - uint32_t stopped; - uint32_t discard_d; + unsigned long started; + unsigned long stopped; + unsigned int discard_d; /* Profile mode transitions. We want to profile each * direction of the transition separately, so perform an RDTSC @@ -83,12 +81,8 @@ static void librm_test_exec ( void ) { for ( i = 0 ; i < PROFILE_COUNT ; i++ ) { profile_start ( &p2r_profiler ); __asm__ __volatile__ ( REAL_CODE ( "rdtsc\n\t" ) - : "=a" ( timestamp_lo ), - "=d" ( timestamp_hi ) + : "=a" ( timestamp ), "=d" ( discard_d ) : ); - timestamp = timestamp_lo; - if ( sizeof ( timestamp ) > sizeof ( timestamp_lo ) ) - timestamp |= ( ( ( uint64_t ) timestamp_hi ) << 32 ); profile_start_at ( &r2p_profiler, timestamp ); profile_stop ( &r2p_profiler ); profile_stop_at ( &p2r_profiler, timestamp ); @@ -97,20 +91,24 @@ static void librm_test_exec ( void ) { /* Profile complete real-mode call cycle */ for ( i = 0 ; i < PROFILE_COUNT ; i++ ) { profile_start ( &real_call_profiler ); - __asm__ __volatile__ ( REAL_CODE ( "" ) ); + __asm__ __volatile__ ( REAL_CODE ( "" ) : : ); profile_stop ( &real_call_profiler ); } - /* Profile complete virtual call cycle */ + /* Profile complete protected-mode call cycle */ for ( i = 0 ; i < PROFILE_COUNT ; i++ ) { __asm__ __volatile__ ( REAL_CODE ( "rdtsc\n\t" - "movl %k0, %k2\n\t" - VIRT_CALL ( librm_test_call ) + "movl %0, %2\n\t" + "pushl %3\n\t" + "pushw %%cs\n\t" + "call prot_call\n\t" + "addw $4, %%sp\n\t" "rdtsc\n\t" ) : "=a" ( stopped ), "=d" ( discard_d ), - "=R" ( started ) : ); - profile_start_at ( &virt_call_profiler, started ); - profile_stop_at ( &virt_call_profiler, stopped ); + "=r" ( started ) + : "i" ( librm_test_prot_call ) ); + profile_start_at ( &prot_call_profiler, started ); + profile_stop_at ( &prot_call_profiler, stopped ); } } diff --git a/roms/ipxe/src/arch/x86/Makefile b/roms/ipxe/src/arch/x86/Makefile index 368c29f6d..98c49b98d 100644 --- a/roms/ipxe/src/arch/x86/Makefile +++ b/roms/ipxe/src/arch/x86/Makefile @@ -1,8 +1,3 @@ -# Assembler section type character -# -ASM_TCHAR := @ -ASM_TCHAR_OPS := @ - # Include common x86 headers # INCDIRS += arch/x86/include @@ -10,18 +5,11 @@ INCDIRS += arch/x86/include # x86-specific directories containing source files # SRCDIRS += arch/x86/core -SRCDIRS += arch/x86/image -SRCDIRS += arch/x86/interface/pcbios -SRCDIRS += arch/x86/interface/pxe -SRCDIRS += arch/x86/interface/pxeparent SRCDIRS += arch/x86/interface/efi -SRCDIRS += arch/x86/interface/vmware -SRCDIRS += arch/x86/interface/syslinux SRCDIRS += arch/x86/prefix SRCDIRS += arch/x86/hci/commands SRCDIRS += arch/x86/drivers/xen SRCDIRS += arch/x86/drivers/hyperv -SRCDIRS += arch/x86/transitions # breaks building some of the linux-related objects CFLAGS += -Ulinux @@ -29,10 +17,6 @@ CFLAGS += -Ulinux # disable valgrind CFLAGS += -DNVALGRIND -# Define version string for lkrnprefix.S -# -CFLAGS_lkrnprefix += -DVERSION="\"$(VERSION)\"" - # Include Hyper-V driver in the all-drivers build # DRIVERS_hyperv += hyperv diff --git a/roms/ipxe/src/arch/x86/Makefile.efi b/roms/ipxe/src/arch/x86/Makefile.efi index f04be425b..f73bc7d5d 100644 --- a/roms/ipxe/src/arch/x86/Makefile.efi +++ b/roms/ipxe/src/arch/x86/Makefile.efi @@ -1,6 +1,42 @@ # -*- makefile -*- : Force emacs to use Makefile mode -# Include generic EFI Makefile +# The EFI linker script # -MAKEDEPS += Makefile.efi -include Makefile.efi +LDSCRIPT = arch/x86/scripts/efi.lds + +# Retain relocation information for elf2efi +# +LDFLAGS += -q -S + +# Media types. +# +NON_AUTO_MEDIA += efi +NON_AUTO_MEDIA += efidrv +NON_AUTO_MEDIA += drv.efi +NON_AUTO_MEDIA += efirom + +# Include SNP driver in the all-drivers build +# +DRIVERS_net += snp + +# Rules for building EFI files +# +$(BIN)/%.efi : $(BIN)/%.efi.tmp $(ELF2EFI) + $(QM)$(ECHO) " [FINISH] $@" + $(Q)$(ELF2EFI) --subsystem=10 $< $@ + +$(BIN)/%.efidrv : $(BIN)/%.efidrv.tmp $(ELF2EFI) + $(QM)$(ECHO) " [FINISH] $@" + $(Q)$(ELF2EFI) --subsystem=11 $< $@ + +$(BIN)/%.drv.efi : $(BIN)/%.efidrv + $(QM)$(ECHO) " [FINISH] $@" + $(Q)$(CP) $< $@ + +$(BIN)/%.efirom : $(BIN)/%.efidrv $(EFIROM) + $(QM)$(ECHO) " [FINISH] $@" + $(Q)$(EFIROM) -v $(TGT_PCI_VENDOR) -d $(TGT_PCI_DEVICE) $< $@ + +$(BIN)/efidrv.cab : $(BIN)/alldrv.efis # $(ALL_drv.efi) is not yet defined + $(QM)$(ECHO) " [CAB] $@" + $(Q)$(LCAB) -n -q $(ALL_drv.efi) $@ diff --git a/roms/ipxe/src/arch/x86/Makefile.pcbios b/roms/ipxe/src/arch/x86/Makefile.pcbios deleted file mode 100644 index f8c225352..000000000 --- a/roms/ipxe/src/arch/x86/Makefile.pcbios +++ /dev/null @@ -1,127 +0,0 @@ -# -*- makefile -*- : Force emacs to use Makefile mode - -# BIOS-specific directories containing source files -# -SRCDIRS += arch/x86/drivers/net - -# The i386 linker script -# -LDSCRIPT = arch/x86/scripts/pcbios.lds - -# Stop ld from complaining about our customised linker script -# -LDFLAGS += -N --no-check-sections - -# Prefix always starts at address zero -# -LDFLAGS += --section-start=.prefix=0 - -# Media types. -# -MEDIA += rom -MEDIA += mrom -MEDIA += pcirom -MEDIA += isarom -MEDIA += pxe -MEDIA += kpxe -MEDIA += kkpxe -MEDIA += kkkpxe -MEDIA += lkrn -MEDIA += dsk -MEDIA += nbi -MEDIA += hd -MEDIA += raw -MEDIA += exe - -# Padding rules -# -PAD_rom = $(PERL) $(PADIMG) --blksize=512 --byte=0xff -PAD_mrom = $(PAD_rom) -PAD_pcirom = $(PAD_rom) -PAD_isarom = $(PAD_rom) -PAD_dsk = $(PERL) $(PADIMG) --blksize=512 -PAD_hd = $(PERL) $(PADIMG) --blksize=32768 -PAD_exe = $(PERL) $(PADIMG) --blksize=512 - -# Finalisation rules -# -FINALISE_rom = $(PERL) $(FIXROM) -FINALISE_mrom = $(FINALISE_rom) -FINALISE_pcirom = $(FINALISE_rom) -FINALISE_isarom = $(FINALISE_rom) - -# Use $(ROMS) rather than $(DRIVERS) for "allroms", "allmroms", etc. -# -LIST_NAME_rom := ROMS -LIST_NAME_mrom := ROMS -LIST_NAME_pcirom := ROMS -LIST_NAME_isarom := ROMS - -# Locations of isolinux files -# -SYSLINUX_DIR_LIST := \ - /usr/lib/syslinux \ - /usr/lib/syslinux/bios \ - /usr/lib/syslinux/modules/bios \ - /usr/share/syslinux \ - /usr/share/syslinux/bios \ - /usr/share/syslinux/modules/bios \ - /usr/local/share/syslinux \ - /usr/local/share/syslinux/bios \ - /usr/local/share/syslinux/modules/bios \ - /usr/lib/ISOLINUX -ISOLINUX_BIN_LIST := \ - $(ISOLINUX_BIN) \ - $(patsubst %,%/isolinux.bin,$(SYSLINUX_DIR_LIST)) -LDLINUX_C32_LIST := \ - $(LDLINUX_C32) \ - $(patsubst %,%/ldlinux.c32,$(SYSLINUX_DIR_LIST)) -ISOLINUX_BIN = $(firstword $(wildcard $(ISOLINUX_BIN_LIST))) -LDLINUX_C32 = $(firstword $(wildcard $(LDLINUX_C32_LIST))) - -# rule to make a non-emulation ISO boot image -NON_AUTO_MEDIA += iso -%iso: %lkrn util/geniso - $(QM)$(ECHO) " [GENISO] $@" - $(Q)ISOLINUX_BIN=$(ISOLINUX_BIN) LDLINUX_C32=$(LDLINUX_C32) \ - VERSION="$(VERSION)" bash util/geniso -o $@ $< - -# rule to make a floppy emulation ISO boot image -NON_AUTO_MEDIA += liso -%liso: %lkrn util/geniso - $(QM)$(ECHO) " [GENISO] $@" - $(Q)VERSION="$(VERSION)" bash util/geniso -l -o $@ $< - -# rule to make a syslinux floppy image (mountable, bootable) -NON_AUTO_MEDIA += sdsk -%sdsk: %lkrn util/gensdsk - $(QM)$(ECHO) " [GENSDSK] $@" - $(Q)bash util/gensdsk $@ $< - -# rule to write disk images to /dev/fd0 -NON_AUTO_MEDIA += fd0 -%fd0 : %dsk - $(QM)$(ECHO) " [DD] $@" - $(Q)dd if=$< bs=512 conv=sync of=/dev/fd0 - $(Q)sync - -# Special target for building Master Boot Record binary -$(BIN)/mbr.bin : $(BIN)/mbr.o - $(QM)$(ECHO) " [LD] $@" - $(Q)$(LD) $(LDFLAGS) -o $@ --oformat binary -e 0 $< - -# rule to make a USB disk image -$(BIN)/usbdisk.bin : $(BIN)/usbdisk.o - $(QM)$(ECHO) " [LD] $@" - $(Q)$(LD) $(LDFLAGS) -o $@ --oformat binary -e 0 $< - -NON_AUTO_MEDIA += usb -%usb: $(BIN)/usbdisk.bin %hd - $(QM)$(ECHO) " [FINISH] $@" - $(Q)cat $^ > $@ - -# Padded floppy image (e.g. for iLO) -NON_AUTO_MEDIA += pdsk -%pdsk : %dsk - $(Q)cp $< $@ - $(Q)$(PADIMG) --blksize=1474560 $@ diff --git a/roms/ipxe/src/arch/x86/core/gdbmach.c b/roms/ipxe/src/arch/x86/core/gdbmach.c deleted file mode 100644 index af6abfedd..000000000 --- a/roms/ipxe/src/arch/x86/core/gdbmach.c +++ /dev/null @@ -1,251 +0,0 @@ -/* - * Copyright (C) 2008 Stefan Hajnoczi <stefanha@gmail.com>. - * Copyright (C) 2016 Michael Brown <mbrown@fensystems.co.uk>. - * - * 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 <stddef.h> -#include <stdio.h> -#include <errno.h> -#include <assert.h> -#include <ipxe/uaccess.h> -#include <ipxe/gdbstub.h> -#include <librm.h> -#include <gdbmach.h> - -/** @file - * - * GDB architecture-specific bits for x86 - * - */ - -/** Number of hardware breakpoints */ -#define NUM_HWBP 4 - -/** Debug register 7: Global breakpoint enable */ -#define DR7_G( bp ) ( 2 << ( 2 * (bp) ) ) - -/** Debug register 7: Global exact breakpoint enable */ -#define DR7_GE ( 1 << 9 ) - -/** Debug register 7: Break on data writes */ -#define DR7_RWLEN_WRITE 0x11110000 - -/** Debug register 7: Break on data access */ -#define DR7_RWLEN_ACCESS 0x33330000 - -/** Debug register 7: One-byte length */ -#define DR7_RWLEN_1 0x00000000 - -/** Debug register 7: Two-byte length */ -#define DR7_RWLEN_2 0x44440000 - -/** Debug register 7: Four-byte length */ -#define DR7_RWLEN_4 0xcccc0000 - -/** Debug register 7: Eight-byte length */ -#define DR7_RWLEN_8 0x88880000 - -/** Debug register 7: Breakpoint R/W and length mask */ -#define DR7_RWLEN_MASK( bp ) ( 0xf0000 << ( 4 * (bp) ) ) - -/** Hardware breakpoint addresses (debug registers 0-3) */ -static unsigned long dr[NUM_HWBP]; - -/** Active value of debug register 7 */ -static unsigned long dr7 = DR7_GE; - -/** - * Update debug registers - * - */ -static void gdbmach_update ( void ) { - - /* Set debug registers */ - __asm__ __volatile__ ( "mov %0, %%dr0" : : "r" ( dr[0] ) ); - __asm__ __volatile__ ( "mov %0, %%dr1" : : "r" ( dr[1] ) ); - __asm__ __volatile__ ( "mov %0, %%dr2" : : "r" ( dr[2] ) ); - __asm__ __volatile__ ( "mov %0, %%dr3" : : "r" ( dr[3] ) ); - __asm__ __volatile__ ( "mov %0, %%dr7" : : "r" ( dr7 ) ); -} - -/** - * Find reusable or available hardware breakpoint - * - * @v addr Linear address - * @v rwlen Control bits - * @ret bp Hardware breakpoint, or negative error - */ -static int gdbmach_find ( unsigned long addr, unsigned int rwlen ) { - unsigned int i; - int bp = -ENOENT; - - /* Look for a reusable or available breakpoint */ - for ( i = 0 ; i < NUM_HWBP ; i++ ) { - - /* If breakpoint is not enabled, then it is available */ - if ( ! ( dr7 & DR7_G ( i ) ) ) { - bp = i; - continue; - } - - /* If breakpoint is enabled and has the same address - * and control bits, then reuse it. - */ - if ( ( dr[i] == addr ) && - ( ( ( dr7 ^ rwlen ) & DR7_RWLEN_MASK ( i ) ) == 0 ) ) { - bp = i; - break; - } - } - - return bp; -} - -/** - * Set hardware breakpoint - * - * @v type GDB breakpoint type - * @v addr Virtual address - * @v len Length - * @v enable Enable (not disable) breakpoint - * @ret rc Return status code - */ -int gdbmach_set_breakpoint ( int type, unsigned long addr, size_t len, - int enable ) { - unsigned int rwlen; - unsigned long mask; - int bp; - - /* Parse breakpoint type */ - switch ( type ) { - case GDBMACH_WATCH: - rwlen = DR7_RWLEN_WRITE; - break; - case GDBMACH_AWATCH: - rwlen = DR7_RWLEN_ACCESS; - break; - default: - return -ENOTSUP; - } - - /* Parse breakpoint length */ - switch ( len ) { - case 1: - rwlen |= DR7_RWLEN_1; - break; - case 2: - rwlen |= DR7_RWLEN_2; - break; - case 4: - rwlen |= DR7_RWLEN_4; - break; - case 8: - rwlen |= DR7_RWLEN_8; - break; - default: - return -ENOTSUP; - } - - /* Convert to linear address */ - if ( sizeof ( physaddr_t ) <= sizeof ( uint32_t ) ) - addr = virt_to_phys ( ( void * ) addr ); - - /* Find reusable or available hardware breakpoint */ - bp = gdbmach_find ( addr, rwlen ); - if ( bp < 0 ) - return ( enable ? -ENOBUFS : 0 ); - - /* Configure this breakpoint */ - DBGC ( &dr[0], "GDB bp %d at %p+%zx type %d (%sabled)\n", - bp, ( ( void * ) addr ), len, type, ( enable ? "en" : "dis" ) ); - dr[bp] = addr; - mask = DR7_RWLEN_MASK ( bp ); - dr7 = ( ( dr7 & ~mask ) | ( rwlen & mask ) ); - mask = DR7_G ( bp ); - dr7 &= ~mask; - if ( enable ) - dr7 |= mask; - - /* Update debug registers */ - gdbmach_update(); - - return 0; -} - -/** - * Handle exception - * - * @v signo GDB signal number - * @v regs Register dump - */ -__asmcall void gdbmach_handler ( int signo, gdbreg_t *regs ) { - unsigned long dr7_disabled = DR7_GE; - unsigned long dr6_clear = 0; - - /* Temporarily disable breakpoints */ - __asm__ __volatile__ ( "mov %0, %%dr7\n" : : "r" ( dr7_disabled ) ); - - /* Handle exception */ - DBGC ( &dr[0], "GDB signal %d\n", signo ); - DBGC2_HDA ( &dr[0], 0, regs, ( GDBMACH_NREGS * sizeof ( *regs ) ) ); - gdbstub_handler ( signo, regs ); - DBGC ( &dr[0], "GDB signal %d returning\n", signo ); - DBGC2_HDA ( &dr[0], 0, regs, ( GDBMACH_NREGS * sizeof ( *regs ) ) ); - - /* Clear breakpoint status register */ - __asm__ __volatile__ ( "mov %0, %%dr6\n" : : "r" ( dr6_clear ) ); - - /* Re-enable breakpoints */ - __asm__ __volatile__ ( "mov %0, %%dr7\n" : : "r" ( dr7 ) ); -} - -/** - * CPU exception vectors - * - * Note that we cannot intercept anything from INT8 (double fault) - * upwards, since these overlap by default with IRQ0-7. - */ -static void * gdbmach_vectors[] = { - gdbmach_sigfpe, /* Divide by zero */ - gdbmach_sigtrap, /* Debug trap */ - NULL, /* Non-maskable interrupt */ - gdbmach_sigtrap, /* Breakpoint */ - gdbmach_sigstkflt, /* Overflow */ - gdbmach_sigstkflt, /* Bound range exceeded */ - gdbmach_sigill, /* Invalid opcode */ -}; - -/** - * Initialise GDB - */ -void gdbmach_init ( void ) { - unsigned int i; - - /* Hook CPU exception vectors */ - for ( i = 0 ; i < ( sizeof ( gdbmach_vectors ) / - sizeof ( gdbmach_vectors[0] ) ) ; i++ ) { - if ( gdbmach_vectors[i] ) - set_interrupt_vector ( i, gdbmach_vectors[i] ); - } -} diff --git a/roms/ipxe/src/arch/x86/core/pcidirect.c b/roms/ipxe/src/arch/x86/core/pcidirect.c index 0d09be84b..9b8e6b1d9 100644 --- a/roms/ipxe/src/arch/x86/core/pcidirect.c +++ b/roms/ipxe/src/arch/x86/core/pcidirect.c @@ -36,12 +36,10 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); * Prepare for Type 1 PCI configuration space access * * @v pci PCI device - * @v where Location within PCI configuration space + * @v where Location within PCI configuration space */ void pcidirect_prepare ( struct pci_device *pci, int where ) { - uint16_t busdevfn = ( pci->busdevfn & 0xffff ); - - outl ( ( 0x80000000 | ( busdevfn << 8 ) | ( where & ~3 ) ), + outl ( ( 0x80000000 | ( pci->busdevfn << 8 ) | ( where & ~3 ) ), PCIDIRECT_CONFIG_ADDRESS ); } diff --git a/roms/ipxe/src/arch/x86/core/x86_io.c b/roms/ipxe/src/arch/x86/core/x86_io.c index 6c6b6e1e7..3081fa8b9 100644 --- a/roms/ipxe/src/arch/x86/core/x86_io.c +++ b/roms/ipxe/src/arch/x86/core/x86_io.c @@ -74,6 +74,9 @@ static __unused void i386_writeq ( uint64_t data, volatile uint64_t *io_addr ) { PROVIDE_IOAPI_INLINE ( x86, phys_to_bus ); PROVIDE_IOAPI_INLINE ( x86, bus_to_phys ); +PROVIDE_IOAPI_INLINE ( x86, ioremap ); +PROVIDE_IOAPI_INLINE ( x86, iounmap ); +PROVIDE_IOAPI_INLINE ( x86, io_to_bus ); PROVIDE_IOAPI_INLINE ( x86, readb ); PROVIDE_IOAPI_INLINE ( x86, readw ); PROVIDE_IOAPI_INLINE ( x86, readl ); diff --git a/roms/ipxe/src/arch/x86/core/x86_tcpip.c b/roms/ipxe/src/arch/x86/core/x86_tcpip.c index ed323d5d0..88042f5f7 100644 --- a/roms/ipxe/src/arch/x86/core/x86_tcpip.c +++ b/roms/ipxe/src/arch/x86/core/x86_tcpip.c @@ -42,8 +42,8 @@ extern char x86_tcpip_loop_end[]; * @v len Length of data buffer * @ret cksum Updated checksum, in network byte order */ -uint16_t tcpip_continue_chksum ( uint16_t partial, const void *data, - size_t len ) { +uint16_t x86_tcpip_continue_chksum ( uint16_t partial, + const void *data, size_t len ) { unsigned long sum = ( ( ~partial ) & 0xffff ); unsigned long initial_word_count; unsigned long loop_count; diff --git a/roms/ipxe/src/arch/x86/include/bits/bitops.h b/roms/ipxe/src/arch/x86/include/bits/bitops.h deleted file mode 100644 index 17dcf1024..000000000 --- a/roms/ipxe/src/arch/x86/include/bits/bitops.h +++ /dev/null @@ -1,94 +0,0 @@ -#ifndef _BITS_BITOPS_H -#define _BITS_BITOPS_H - -/** @file - * - * x86 bit operations - * - * We perform atomic bit set and bit clear operations using "lock bts" - * and "lock btr". We use the output constraint to inform the - * compiler that any memory from the start of the bit field up to and - * including the byte containing the bit may be modified. (This is - * overkill but shouldn't matter in practice since we're unlikely to - * subsequently read other bits from the same bit field.) - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#include <stdint.h> - -/** - * Set bit atomically - * - * @v bit Bit to set - * @v bits Bit field - */ -static inline __attribute__ (( always_inline )) void -set_bit ( unsigned int bit, volatile void *bits ) { - volatile struct { - uint8_t byte[ ( bit / 8 ) + 1 ]; - } *bytes = bits; - - __asm__ __volatile__ ( "lock bts %1, %0" - : "+m" ( *bytes ) : "Ir" ( bit ) ); -} - -/** - * Clear bit atomically - * - * @v bit Bit to set - * @v bits Bit field - */ -static inline __attribute__ (( always_inline )) void -clear_bit ( unsigned int bit, volatile void *bits ) { - volatile struct { - uint8_t byte[ ( bit / 8 ) + 1 ]; - } *bytes = bits; - - __asm__ __volatile__ ( "lock btr %1, %0" - : "+m" ( *bytes ) : "Ir" ( bit ) ); -} - -/** - * Test and set bit atomically - * - * @v bit Bit to set - * @v bits Bit field - * @ret old Old value of bit (zero or non-zero) - */ -static inline __attribute__ (( always_inline )) int -test_and_set_bit ( unsigned int bit, volatile void *bits ) { - volatile struct { - uint8_t byte[ ( bit / 8 ) + 1 ]; - } *bytes = bits; - int old; - - __asm__ __volatile__ ( "lock bts %2, %0\n\t" - "sbb %1, %1\n\t" - : "+m" ( *bytes ), "=r" ( old ) - : "Ir" ( bit ) ); - return old; -} - -/** - * Test and clear bit atomically - * - * @v bit Bit to set - * @v bits Bit field - * @ret old Old value of bit (zero or non-zero) - */ -static inline __attribute__ (( always_inline )) int -test_and_clear_bit ( unsigned int bit, volatile void *bits ) { - volatile struct { - uint8_t byte[ ( bit / 8 ) + 1 ]; - } *bytes = bits; - int old; - - __asm__ __volatile__ ( "lock btr %2, %0\n\t" - "sbb %1, %1\n\t" - : "+m" ( *bytes ), "=r" ( old ) - : "Ir" ( bit ) ); - return old; -} - -#endif /* _BITS_BITOPS_H */ diff --git a/roms/ipxe/src/arch/x86/include/bits/errfile.h b/roms/ipxe/src/arch/x86/include/bits/errfile.h index 42792242d..0d1617d20 100644 --- a/roms/ipxe/src/arch/x86/include/bits/errfile.h +++ b/roms/ipxe/src/arch/x86/include/bits/errfile.h @@ -22,7 +22,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #define ERRFILE_apm ( ERRFILE_ARCH | ERRFILE_CORE | 0x000b0000 ) #define ERRFILE_vesafb ( ERRFILE_ARCH | ERRFILE_CORE | 0x000c0000 ) #define ERRFILE_int13con ( ERRFILE_ARCH | ERRFILE_CORE | 0x000d0000 ) -#define ERRFILE_gdbmach ( ERRFILE_ARCH | ERRFILE_CORE | 0x000e0000 ) #define ERRFILE_bootsector ( ERRFILE_ARCH | ERRFILE_IMAGE | 0x00000000 ) #define ERRFILE_bzimage ( ERRFILE_ARCH | ERRFILE_IMAGE | 0x00010000 ) @@ -53,6 +52,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #define ERRFILE_cpuid_cmd ( ERRFILE_ARCH | ERRFILE_OTHER | 0x00000000 ) #define ERRFILE_cpuid_settings ( ERRFILE_ARCH | ERRFILE_OTHER | 0x00010000 ) +#define ERRFILE_efi_entropy ( ERRFILE_ARCH | ERRFILE_OTHER | 0x00020000 ) /** @} */ diff --git a/roms/ipxe/src/arch/x86/include/bits/iomap.h b/roms/ipxe/src/arch/x86/include/bits/iomap.h deleted file mode 100644 index d6fff257e..000000000 --- a/roms/ipxe/src/arch/x86/include/bits/iomap.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef _BITS_IOMAP_H -#define _BITS_IOMAP_H - -/** @file - * - * x86-specific I/O mapping API implementations - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#include <ipxe/iomap_pages.h> - -#endif /* _BITS_IOMAP_H */ diff --git a/roms/ipxe/src/arch/x86/include/bits/tcpip.h b/roms/ipxe/src/arch/x86/include/bits/tcpip.h index 0ac55b1a0..5c2baffcf 100644 --- a/roms/ipxe/src/arch/x86/include/bits/tcpip.h +++ b/roms/ipxe/src/arch/x86/include/bits/tcpip.h @@ -9,7 +9,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); -extern uint16_t tcpip_continue_chksum ( uint16_t partial, const void *data, - size_t len ); +extern uint16_t x86_tcpip_continue_chksum ( uint16_t partial, + const void *data, size_t len ); + +#define tcpip_continue_chksum x86_tcpip_continue_chksum #endif /* _BITS_TCPIP_H */ diff --git a/roms/ipxe/src/arch/x86/include/bits/xen.h b/roms/ipxe/src/arch/x86/include/bits/xen.h index 3433cea1f..fc065ea38 100644 --- a/roms/ipxe/src/arch/x86/include/bits/xen.h +++ b/roms/ipxe/src/arch/x86/include/bits/xen.h @@ -161,4 +161,23 @@ xen_hypercall_5 ( struct xen_hypervisor *xen, unsigned int hypercall, return retval; } +/** + * Test and clear pending event + * + * @v xen Xen hypervisor + * @v port Event channel port + * @ret pending Event was pending + */ +static inline __attribute__ (( always_inline )) uint8_t +xenevent_pending ( struct xen_hypervisor *xen, evtchn_port_t port ) { + uint8_t pending; + + __asm__ __volatile__ ( "lock btr %2, %0\n\t" + "setc %1\n\t" + : "+m" ( xen->shared->evtchn_pending ), + "=a" ( pending ) + : "Ir" ( port ) ); + return pending; +} + #endif /* _BITS_XEN_H */ diff --git a/roms/ipxe/src/arch/x86/include/ipxe/iomap_pages.h b/roms/ipxe/src/arch/x86/include/ipxe/iomap_pages.h deleted file mode 100644 index 18e0a3002..000000000 --- a/roms/ipxe/src/arch/x86/include/ipxe/iomap_pages.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef _IPXE_IOMAP_PAGES_H -#define _IPXE_IOMAP_PAGES_H - -/** @file - * - * I/O mapping API using page tables - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#ifdef IOMAP_PAGES -#define IOMAP_PREFIX_pages -#else -#define IOMAP_PREFIX_pages __pages_ -#endif - -static inline __always_inline unsigned long -IOMAP_INLINE ( pages, io_to_bus ) ( volatile const void *io_addr ) { - /* Not easy to do; just return the CPU address for debugging purposes */ - return ( ( intptr_t ) io_addr ); -} - -#endif /* _IPXE_IOMAP_PAGES_H */ diff --git a/roms/ipxe/src/arch/x86/include/ipxe/x86_io.h b/roms/ipxe/src/arch/x86/include/ipxe/x86_io.h index a6ebe1f4c..5214e9fbb 100644 --- a/roms/ipxe/src/arch/x86/include/ipxe/x86_io.h +++ b/roms/ipxe/src/arch/x86/include/ipxe/x86_io.h @@ -32,7 +32,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #define PAGE_SHIFT 12 /* - * Physical<->Bus address mappings + * Physical<->Bus and Bus<->I/O address mappings * */ @@ -46,6 +46,21 @@ IOAPI_INLINE ( x86, bus_to_phys ) ( unsigned long bus_addr ) { return bus_addr; } +static inline __always_inline void * +IOAPI_INLINE ( x86, ioremap ) ( unsigned long bus_addr, size_t len __unused ) { + return ( bus_addr ? phys_to_virt ( bus_addr ) : NULL ); +} + +static inline __always_inline void +IOAPI_INLINE ( x86, iounmap ) ( volatile const void *io_addr __unused ) { + /* Nothing to do */ +} + +static inline __always_inline unsigned long +IOAPI_INLINE ( x86, io_to_bus ) ( volatile const void *io_addr ) { + return virt_to_phys ( io_addr ); +} + /* * MMIO reads and writes up to native word size * diff --git a/roms/ipxe/src/arch/x86/include/rmsetjmp.h b/roms/ipxe/src/arch/x86/include/rmsetjmp.h deleted file mode 100644 index 3470be477..000000000 --- a/roms/ipxe/src/arch/x86/include/rmsetjmp.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef _RMSETJMP_H -#define _RMSETJMP_H - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#include <setjmp.h> -#include <realmode.h> - -/** A real-mode-extended jump buffer */ -typedef struct { - /** Jump buffer */ - jmp_buf env; - /** Real-mode stack pointer */ - segoff_t rm_stack; -} rmjmp_buf[1]; - -#define rmsetjmp( _env ) ( { \ - (_env)->rm_stack.segment = rm_ss; \ - (_env)->rm_stack.offset = rm_sp; \ - setjmp ( (_env)->env ); } ) \ - -#define rmlongjmp( _env, _val ) do { \ - rm_ss = (_env)->rm_stack.segment; \ - rm_sp = (_env)->rm_stack.offset; \ - longjmp ( (_env)->env, (_val) ); \ - } while ( 0 ) - -#endif /* _RMSETJMP_H */ diff --git a/roms/ipxe/src/interface/efi/efi_entropy.c b/roms/ipxe/src/arch/x86/interface/efi/efi_entropy.c index 881c4c9a2..a54bd12e6 100644 --- a/roms/ipxe/src/interface/efi/efi_entropy.c +++ b/roms/ipxe/src/arch/x86/interface/efi/efi_entropy.c @@ -26,7 +26,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <errno.h> #include <ipxe/entropy.h> #include <ipxe/crc32.h> -#include <ipxe/profile.h> #include <ipxe/efi/efi.h> #include <ipxe/efi/Protocol/Rng.h> @@ -105,12 +104,13 @@ static void efi_entropy_disable ( void ) { /** * Wait for a timer tick * - * @ret low CPU profiling low-order bits, or negative error + * @ret low TSC low-order bits, or negative error */ static int efi_entropy_tick ( void ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; UINTN index; uint16_t low; + uint32_t discard_d; EFI_STATUS efirc; int rc; @@ -129,8 +129,8 @@ static int efi_entropy_tick ( void ) { return rc; } - /* Get current CPU profiling timestamp low-order bits */ - low = profile_timestamp(); + /* Get current TSC low-order bits */ + __asm__ __volatile__ ( "rdtsc" : "=a" ( low ), "=d" ( discard_d ) ); return low; } diff --git a/roms/ipxe/src/interface/efi/efidrvprefix.c b/roms/ipxe/src/arch/x86/prefix/efidrvprefix.c index 4fbb19ff7..4fbb19ff7 100644 --- a/roms/ipxe/src/interface/efi/efidrvprefix.c +++ b/roms/ipxe/src/arch/x86/prefix/efidrvprefix.c diff --git a/roms/ipxe/src/interface/efi/efiprefix.c b/roms/ipxe/src/arch/x86/prefix/efiprefix.c index 18b931e68..18b931e68 100644 --- a/roms/ipxe/src/interface/efi/efiprefix.c +++ b/roms/ipxe/src/arch/x86/prefix/efiprefix.c diff --git a/roms/ipxe/src/scripts/efi.lds b/roms/ipxe/src/arch/x86/scripts/efi.lds index f1049f24b..f1049f24b 100644 --- a/roms/ipxe/src/scripts/efi.lds +++ b/roms/ipxe/src/arch/x86/scripts/efi.lds diff --git a/roms/ipxe/src/arch/x86/transitions/librm.S b/roms/ipxe/src/arch/x86/transitions/librm.S deleted file mode 100644 index e91ede372..000000000 --- a/roms/ipxe/src/arch/x86/transitions/librm.S +++ /dev/null @@ -1,1592 +0,0 @@ -/* - * librm: a library for interfacing to real-mode code - * - * Michael Brown <mbrown@fensystems.co.uk> - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) - -/* Drag in local definitions */ -#include "librm.h" - -/* CR0: protection enabled */ -#define CR0_PE ( 1 << 0 ) - -/* CR0: paging */ -#define CR0_PG ( 1 << 31 ) - -/* CR4: physical address extensions */ -#define CR4_PAE ( 1 << 5 ) - -/* Extended feature enable MSR (EFER) */ -#define MSR_EFER 0xc0000080 - -/* EFER: long mode enable */ -#define EFER_LME ( 1 << 8 ) - -/* Page: present */ -#define PG_P 0x01 - -/* Page: read/write */ -#define PG_RW 0x02 - -/* Page: user/supervisor */ -#define PG_US 0x04 - -/* Page: page size */ -#define PG_PS 0x80 - -/* Size of various paging-related data structures */ -#define SIZEOF_PTE_LOG2 3 -#define SIZEOF_PTE ( 1 << SIZEOF_PTE_LOG2 ) -#define SIZEOF_PT_LOG2 12 -#define SIZEOF_PT ( 1 << SIZEOF_PT_LOG2 ) -#define SIZEOF_4KB_PAGE_LOG2 12 -#define SIZEOF_4KB_PAGE ( 1 << SIZEOF_4KB_PAGE_LOG2 ) -#define SIZEOF_2MB_PAGE_LOG2 21 -#define SIZEOF_2MB_PAGE ( 1 << SIZEOF_2MB_PAGE_LOG2 ) -#define SIZEOF_LOW_4GB_LOG2 32 -#define SIZEOF_LOW_4GB ( 1 << SIZEOF_LOW_4GB_LOG2 ) - -/* Size of various C data structures */ -#define SIZEOF_I386_SEG_REGS 12 -#define SIZEOF_I386_REGS 32 -#define SIZEOF_REAL_MODE_REGS ( SIZEOF_I386_SEG_REGS + SIZEOF_I386_REGS ) -#define SIZEOF_I386_FLAGS 4 -#define SIZEOF_I386_ALL_REGS ( SIZEOF_REAL_MODE_REGS + SIZEOF_I386_FLAGS ) -#define SIZEOF_X86_64_REGS 128 - -/* Size of an address */ -#ifdef __x86_64__ -#define SIZEOF_ADDR 8 -#else -#define SIZEOF_ADDR 4 -#endif - -/* Default code size */ -#ifdef __x86_64__ -#define CODE_DEFAULT code64 -#else -#define CODE_DEFAULT code32 -#endif - -/* Selectively assemble code for 32-bit/64-bit builds */ -#ifdef __x86_64__ -#define if32 if 0 -#define if64 if 1 -#else -#define if32 if 1 -#define if64 if 0 -#endif - -/**************************************************************************** - * Global descriptor table - * - * Call init_librm to set up the GDT before attempting to use any - * protected-mode code. - * - * NOTE: This must be located before prot_to_real, otherwise gas - * throws a "can't handle non absolute segment in `ljmp'" error due to - * not knowing the value of REAL_CS when the ljmp is encountered. - * - * Note also that putting ".word gdt_end - gdt - 1" directly into - * gdt_limit, rather than going via gdt_length, will also produce the - * "non absolute segment" error. This is most probably a bug in gas. - **************************************************************************** - */ - .section ".data16.gdt", "aw", @progbits - .align 16 -gdt: -gdtr: /* The first GDT entry is unused, the GDTR can fit here. */ -gdt_limit: .word gdt_length - 1 -gdt_base: .long 0 - .word 0 /* padding */ - - .org gdt + VIRTUAL_CS, 0 -virtual_cs: /* 32 bit protected mode code segment, virtual addresses */ - .word 0xffff, 0 - .byte 0, 0x9f, 0xcf, 0 - - .org gdt + VIRTUAL_DS, 0 -virtual_ds: /* 32 bit protected mode data segment, virtual addresses */ - .word 0xffff, 0 - .byte 0, 0x93, 0xcf, 0 - - .org gdt + PHYSICAL_CS, 0 -physical_cs: /* 32 bit protected mode code segment, physical addresses */ - .word 0xffff, 0 - .byte 0, 0x9f, 0xcf, 0 - - .org gdt + PHYSICAL_DS, 0 -physical_ds: /* 32 bit protected mode data segment, physical addresses */ - .word 0xffff, 0 - .byte 0, 0x93, 0xcf, 0 - - .org gdt + REAL_CS, 0 -real_cs: /* 16 bit real mode code segment */ - .word 0xffff, 0 - .byte 0, 0x9b, 0x00, 0 - - .org gdt + REAL_DS, 0 -real_ds: /* 16 bit real mode data segment */ - .word 0xffff, 0 - .byte 0, 0x93, 0x00, 0 - - .org gdt + P2R_DS, 0 -p2r_ds: /* 16 bit real mode data segment for prot_to_real transition */ - .word 0xffff, ( P2R_DS << 4 ) - .byte 0, 0x93, 0x00, 0 - - .org gdt + LONG_CS, 0 -long_cs: /* 64 bit long mode code segment */ - .word 0, 0 - .byte 0, 0x9a, 0x20, 0 - -gdt_end: - .equ gdt_length, gdt_end - gdt - -/**************************************************************************** - * Stored real-mode and protected-mode stack pointers - * - * The real-mode stack pointer is stored here whenever real_to_prot - * is called and restored whenever prot_to_real is called. The - * converse happens for the protected-mode stack pointer. - * - * Despite initial appearances this scheme is, in fact re-entrant, - * because program flow dictates that we always return via the point - * we left by. For example: - * PXE API call entry - * 1 real => prot - * ... - * Print a text string - * ... - * 2 prot => real - * INT 10 - * 3 real => prot - * ... - * ... - * 4 prot => real - * PXE API call exit - * - * At point 1, the RM mode stack value, say RPXE, is stored in - * rm_ss,sp. We want this value to still be present in rm_ss,sp when - * we reach point 4. - * - * At point 2, the RM stack value is restored from RPXE. At point 3, - * the RM stack value is again stored in rm_ss,sp. This *does* - * overwrite the RPXE that we have stored there, but it's the same - * value, since the code between points 2 and 3 has managed to return - * to us. - **************************************************************************** - */ - .section ".bss.rm_ss_sp", "aw", @nobits - .globl rm_sp -rm_sp: .word 0 - .globl rm_ss -rm_ss: .word 0 - - .section ".data.pm_esp", "aw", @progbits -pm_esp: .long VIRTUAL(_estack) - -/**************************************************************************** - * Temporary static data buffer - * - * This is used to reduce the amount of real-mode stack space consumed - * during mode transitions, since we are sometimes called with very - * little real-mode stack space available. - **************************************************************************** - */ - /* Temporary static buffer usage by virt_call */ - .struct 0 -VC_TMP_GDT: .space 6 -VC_TMP_IDT: .space 6 -VC_TMP_PAD: .space 4 /* for alignment */ -.if64 -VC_TMP_CR3: .space 4 -VC_TMP_CR4: .space 4 -VC_TMP_EMER: .space 8 -.endif -VC_TMP_FXSAVE: .space 512 -VC_TMP_END: - .previous - - /* Temporary static buffer usage by real_call */ - .struct 0 -RC_TMP_FUNCTION: .space 4 -RC_TMP_END: - .previous - - /* Shared temporary static buffer */ - .section ".bss16.rm_tmpbuf", "aw", @nobits - .align 16 -rm_tmpbuf: - .space VC_TMP_END - .size rm_tmpbuf, . - rm_tmpbuf - -/**************************************************************************** - * Virtual address offsets - * - * These are used by the protected-mode code to map between virtual - * and physical addresses, and to access variables in the .text16 or - * .data16 segments. - **************************************************************************** - */ - .struct 0 -VA_VIRT_OFFSET: .space SIZEOF_ADDR -VA_TEXT16: .space SIZEOF_ADDR -VA_DATA16: .space SIZEOF_ADDR -VA_SIZE: - .previous - - /* Internal copies, used only by librm itself */ - .section ".bss16.rm_virt_addrs", "aw", @nobits -rm_virt_addrs: .space VA_SIZE - .equ rm_virt_offset, ( rm_virt_addrs + VA_VIRT_OFFSET ) - .equ rm_text16, ( rm_virt_addrs + VA_TEXT16 ) - .equ rm_data16, ( rm_virt_addrs + VA_DATA16 ) - - /* Externally visible variables, used by C code */ - .section ".bss.virt_addrs", "aw", @nobits -virt_addrs: .space VA_SIZE - .globl virt_offset - .equ virt_offset, ( virt_addrs + VA_VIRT_OFFSET ) - .globl text16 - .equ text16, ( virt_addrs + VA_TEXT16 ) - .globl data16 - .equ data16, ( virt_addrs + VA_DATA16 ) - -/**************************************************************************** - * init_librm (real-mode far call, 16-bit real-mode far return address) - * - * Initialise the GDT ready for transitions to protected mode. - * - * Parameters: - * %cs : .text16 segment - * %ds : .data16 segment - * %edi : Physical base of protected-mode code - **************************************************************************** - */ - .section ".text16.init_librm", "ax", @progbits - .code16 - .globl init_librm -init_librm: - /* Preserve registers */ - pushl %eax - pushl %ebx - pushl %edi - - /* Store rm_virt_offset and set up virtual_cs and virtual_ds segments */ - subl $VIRTUAL(_textdata), %edi - movl %edi, rm_virt_offset -.if64 ; setae (rm_virt_offset+4) ; .endif - movl %edi, %eax - movw $virtual_cs, %bx - call set_seg_base - movw $virtual_ds, %bx - call set_seg_base - - /* Store rm_cs and rm_text16, set up real_cs segment */ - xorl %eax, %eax - movw %cs, %ax - movw %ax, %cs:rm_cs - shll $4, %eax - movw $real_cs, %bx - call set_seg_base -.if32 ; subl %edi, %eax ; .endif - movl %eax, rm_text16 - - /* Store rm_ds and rm_data16, set up real_ds segment and GDT base */ - xorl %eax, %eax - movw %ds, %ax - movw %ax, %cs:rm_ds - shll $4, %eax - movw $real_ds, %bx - call set_seg_base - movl %eax, gdt_base - addl $gdt, gdt_base -.if32 ; subl %edi, %eax ; .endif - movl %eax, rm_data16 - - /* Configure virt_call for protected mode, if applicable */ -.if64 ; movl $VIRTUAL(vc_pmode), %cs:vc_jmp_offset ; .endif - - /* Switch to protected mode */ - virtcall init_librm_pmode - .section ".text.init_librm", "ax", @progbits - .code32 -init_librm_pmode: - - /* Store virt_offset, text16, and data16 */ - pushw %ds - movw $REAL_DS, %ax - movw %ax, %ds - movl $rm_virt_addrs, %esi - movl $VIRTUAL(virt_addrs), %edi - movl $( VA_SIZE / 4 ), %ecx - rep movsl - popw %ds - -.if64 ; /* Initialise long mode, if applicable */ - movl VIRTUAL(virt_offset), %edi - leal VIRTUAL(p2l_ljmp_target)(%edi), %eax - movl %eax, VIRTUAL(p2l_ljmp_offset) - call init_pages -.endif - /* Return to real mode */ - ret - .section ".text16.init_librm", "ax", @progbits - .code16 -init_librm_rmode: - - /* Configure virt_call for long mode, if applicable */ -.if64 ; movl $VIRTUAL(vc_lmode), %cs:vc_jmp_offset ; .endif - - /* Initialise IDT */ - virtcall init_idt - - /* Restore registers */ - popl %edi - popl %ebx - popl %eax - lret - - .section ".text16.set_seg_base", "ax", @progbits - .code16 -set_seg_base: -1: movw %ax, 2(%bx) - rorl $16, %eax - movb %al, 4(%bx) - movb %ah, 7(%bx) - roll $16, %eax - ret - -/**************************************************************************** - * real_to_prot (real-mode near call, 32-bit virtual return address) - * - * Switch from 16-bit real-mode to 32-bit protected mode with virtual - * addresses. The real-mode %ss:sp is stored in rm_ss and rm_sp, and - * the protected-mode %esp is restored from the saved pm_esp. - * Interrupts are disabled. All other registers may be destroyed. - * - * The return address for this function should be a 32-bit virtual - * address. - * - * Parameters: - * %ecx : number of bytes to move from RM stack to PM stack - * %edx : number of bytes to copy from RM temporary buffer to PM stack - * - **************************************************************************** - */ - .section ".text16.real_to_prot", "ax", @progbits - .code16 -real_to_prot: - /* Enable A20 line */ - call enable_a20 - /* A failure at this point is fatal, and there's nothing we - * can do about it other than lock the machine to make the - * problem immediately visible. - */ -1: jc 1b - - /* Make sure we have our data segment available */ - movw %cs:rm_ds, %ds - - /* Add protected-mode return address to length of data to be copied */ - addw $4, %cx /* %ecx must be less than 64kB anyway */ - - /* Real-mode %ss:%sp => %ebp and virtual address => %esi */ - xorl %eax, %eax - movw %ss, %ax - shll $4, %eax - movzwl %sp, %ebp - addr32 leal (%eax,%ebp), %esi - subl rm_virt_offset, %esi - shll $12, %eax - orl %eax, %ebp - - /* Real-mode data segment virtual address => %ebx */ - movl rm_data16, %ebx -.if64 ; subl rm_virt_offset, %ebx ; .endif - - /* Load protected-mode global descriptor table */ - data32 lgdt gdtr - - /* Zero segment registers. This wastes around 12 cycles on - * real hardware, but saves a substantial number of emulated - * instructions under KVM. - */ - xorw %ax, %ax - movw %ax, %ds - movw %ax, %es - movw %ax, %fs - movw %ax, %gs - movw %ax, %ss - - /* Switch to protected mode (with paging disabled if applicable) */ - cli - movl %cr0, %eax -.if64 ; andl $~CR0_PG, %eax ; .endif - orb $CR0_PE, %al - movl %eax, %cr0 - data32 ljmp $VIRTUAL_CS, $VIRTUAL(r2p_pmode) - .section ".text.real_to_prot", "ax", @progbits - .code32 -r2p_pmode: - /* Set up protected-mode data segments and stack pointer */ - movw $VIRTUAL_DS, %ax - movw %ax, %ds - movw %ax, %es - movw %ax, %fs - movw %ax, %gs - movw %ax, %ss - movl VIRTUAL(pm_esp), %esp - - /* Load protected-mode interrupt descriptor table */ - lidt VIRTUAL(idtr32) - - /* Record real-mode %ss:sp (after removal of data) */ - addl %ecx, %ebp - movl %ebp, VIRTUAL(rm_sp) - - /* Move data from RM stack to PM stack */ - subl %edx, %esp - subl %ecx, %esp - movl %esp, %edi - rep movsb - - /* Copy data from RM temporary buffer to PM stack */ - leal rm_tmpbuf(%ebx), %esi - movl %edx, %ecx - rep movsb - - /* Return to virtual address */ - ret - -/**************************************************************************** - * prot_to_real (protected-mode near call, 32-bit real-mode return address) - * - * Switch from 32-bit protected mode with virtual addresses to 16-bit - * real mode. The protected-mode %esp is stored in pm_esp and the - * real-mode %ss:sp is restored from the saved rm_ss and rm_sp. The - * high word of the real-mode %esp is set to zero. All real-mode data - * segment registers are loaded from the saved rm_ds. Interrupts are - * *not* enabled, since we want to be able to use prot_to_real in an - * ISR. All other registers may be destroyed. - * - * The return address for this function should be a 32-bit (sic) - * real-mode offset within .code16. - * - * Parameters: - * %ecx : number of bytes to move from PM stack to RM stack - * %edx : number of bytes to move from PM stack to RM temporary buffer - * %esi : real-mode global and interrupt descriptor table registers - * - **************************************************************************** - */ - .section ".text.prot_to_real", "ax", @progbits - .code32 -prot_to_real: - /* Copy real-mode global descriptor table register to RM code segment */ - movl VIRTUAL(text16), %edi -.if64 ; subl VIRTUAL(virt_offset), %edi ; .endif - leal rm_gdtr(%edi), %edi - movsw - movsl - - /* Load real-mode interrupt descriptor table register */ - lidt (%esi) - - /* Add return address to data to be moved to RM stack */ - addl $4, %ecx - - /* Real-mode %ss:sp => %ebp and virtual address => %edi */ - movl VIRTUAL(rm_sp), %ebp - subl %ecx, %ebp - movzwl VIRTUAL(rm_ss), %eax - shll $4, %eax - movzwl %bp, %edi - addl %eax, %edi - subl VIRTUAL(virt_offset), %edi - - /* Move data from PM stack to RM stack */ - movl %esp, %esi - rep movsb - - /* Move data from PM stack to RM temporary buffer */ - movl VIRTUAL(data16), %edi -.if64 ; subl VIRTUAL(virt_offset), %edi ; .endif - addl $rm_tmpbuf, %edi - movl %edx, %ecx - rep movsb - - /* Record protected-mode %esp (after removal of data) */ - movl %esi, VIRTUAL(pm_esp) - - /* Load real-mode segment limits */ - movw $P2R_DS, %ax - movw %ax, %ds - movw %ax, %es - movw %ax, %fs - movw %ax, %gs - movw %ax, %ss - ljmp $REAL_CS, $p2r_rmode - .section ".text16.prot_to_real", "ax", @progbits - .code16 -p2r_rmode: - /* Load real-mode GDT */ - data32 lgdt %cs:rm_gdtr - /* Switch to real mode */ - movl %cr0, %eax - andb $0!CR0_PE, %al - movl %eax, %cr0 -p2r_ljmp_rm_cs: - ljmp $0, $1f -1: - /* Set up real-mode data segments and stack pointer */ - movw %cs:rm_ds, %ax - movw %ax, %ds - movw %ax, %es - movw %ax, %fs - movw %ax, %gs - movl %ebp, %eax - shrl $16, %eax - movw %ax, %ss - movzwl %bp, %esp - - /* Return to real-mode address */ - data32 ret - - - /* Real-mode code and data segments. Assigned by the call to - * init_librm. rm_cs doubles as the segment part of the jump - * instruction used by prot_to_real. Both are located in - * .text16 rather than .data16: rm_cs since it forms part of - * the jump instruction within the code segment, and rm_ds - * since real-mode code needs to be able to locate the data - * segment with no other reference available. - */ - .globl rm_cs - .equ rm_cs, ( p2r_ljmp_rm_cs + 3 ) - - .section ".text16.data.rm_ds", "aw", @progbits - .globl rm_ds -rm_ds: .word 0 - - /* Real-mode global and interrupt descriptor table registers */ - .section ".text16.data.rm_gdtr", "aw", @progbits -rm_gdtr: - .word 0 /* Limit */ - .long 0 /* Base */ - -/**************************************************************************** - * phys_to_prot (protected-mode near call, 32-bit physical return address) - * - * Switch from 32-bit protected mode with physical addresses to 32-bit - * protected mode with virtual addresses. %esp is adjusted to a - * virtual address. All other registers are preserved. - * - * The return address for this function should be a 32-bit physical - * (sic) address. - * - **************************************************************************** - */ - .section ".text.phys_to_prot", "ax", @progbits - .code32 - .globl phys_to_prot -phys_to_prot: - /* Preserve registers */ - pushl %eax - pushl %ebp - - /* Switch to virtual code segment */ - cli - ljmp $VIRTUAL_CS, $VIRTUAL(1f) -1: - /* Switch to virtual data segment and adjust %esp */ - movw $VIRTUAL_DS, %ax - movw %ax, %ds - movw %ax, %es - movw %ax, %fs - movw %ax, %gs - movw %ax, %ss - movl VIRTUAL(virt_offset), %ebp - subl %ebp, %esp - - /* Adjust return address to a virtual address */ - subl %ebp, 8(%esp) - - /* Restore registers and return */ - popl %ebp - popl %eax - ret - -.if32 /* Expose as _phys_to_virt for use by COMBOOT, if applicable */ - .globl _phys_to_virt - .equ _phys_to_virt, phys_to_prot -.endif - -/**************************************************************************** - * prot_to_phys (protected-mode near call, 32-bit virtual return address) - * - * Switch from 32-bit protected mode with virtual addresses to 32-bit - * protected mode with physical addresses. %esp is adjusted to a - * physical address. All other registers are preserved. - * - * The return address for this function should be a 32-bit virtual - * (sic) address. - * - **************************************************************************** - */ - .section ".text.prot_to_phys", "ax", @progbits - .code32 -prot_to_phys: - /* Preserve registers */ - pushl %eax - pushl %ebp - - /* Adjust return address to a physical address */ - movl VIRTUAL(virt_offset), %ebp - addl %ebp, 8(%esp) - - /* Switch to physical code segment */ - cli - pushl $PHYSICAL_CS - leal VIRTUAL(1f)(%ebp), %eax - pushl %eax - lret -1: - /* Switch to physical data segment and adjust %esp */ - movw $PHYSICAL_DS, %ax - movw %ax, %ds - movw %ax, %es - movw %ax, %fs - movw %ax, %gs - movw %ax, %ss - addl %ebp, %esp - - /* Restore registers and return */ - popl %ebp - popl %eax - ret - -.if32 /* Expose as _virt_to_phys for use by COMBOOT, if applicable */ - .globl _virt_to_phys - .equ _virt_to_phys, prot_to_phys -.endif - -/**************************************************************************** - * intr_to_prot (protected-mode near call, 32-bit virtual return address) - * - * Switch from 32-bit protected mode with a virtual code segment and - * either a physical or virtual stack segment to 32-bit protected mode - * with normal virtual addresses. %esp is adjusted if necessary to a - * virtual address. All other registers are preserved. - * - * The return address for this function should be a 32-bit virtual - * address. - * - **************************************************************************** - */ - .section ".text.intr_to_prot", "ax", @progbits - .code32 - .globl intr_to_prot -intr_to_prot: - /* Preserve registers */ - pushl %eax - - /* Check whether stack segment is physical or virtual */ - movw %ss, %ax - cmpw $VIRTUAL_DS, %ax - movw $VIRTUAL_DS, %ax - - /* Reload data segment registers */ - movw %ax, %ds - movw %ax, %es - movw %ax, %fs - movw %ax, %gs - - /* Reload stack segment and adjust %esp if necessary */ - je 1f - movw %ax, %ss - subl VIRTUAL(virt_offset), %esp -1: - /* Restore registers and return */ - popl %eax - ret - - /* Expose as _intr_to_virt for use by GDB */ - .globl _intr_to_virt - .equ _intr_to_virt, intr_to_prot - -/**************************************************************************** - * prot_to_long (protected-mode near call, 32-bit virtual return address) - * - * Switch from 32-bit protected mode with virtual addresses to 64-bit - * long mode. The protected-mode %esp is adjusted to a physical - * address. All other registers are preserved. - * - * The return address for this function should be a 32-bit (sic) - * virtual address. - * - **************************************************************************** - */ - .if64 - - .section ".text.prot_to_long", "ax", @progbits - .code32 -prot_to_long: - /* Preserve registers */ - pushl %eax - pushl %ecx - pushl %edx - - /* Set up PML4 */ - movl VIRTUAL(pml4), %eax - movl %eax, %cr3 - - /* Enable PAE */ - movl %cr4, %eax - orb $CR4_PAE, %al - movl %eax, %cr4 - - /* Enable long mode */ - movl $MSR_EFER, %ecx - rdmsr - orw $EFER_LME, %ax - wrmsr - - /* Enable paging */ - movl %cr0, %eax - orl $CR0_PG, %eax - movl %eax, %cr0 - - /* Restore registers */ - popl %edx - popl %ecx - popl %eax - - /* Construct 64-bit return address */ - pushl (%esp) - movl $0xffffffff, 4(%esp) -p2l_ljmp: - /* Switch to long mode (using a physical %rip) */ - ljmp $LONG_CS, $0 - .code64 -p2l_lmode: - /* Adjust and zero-extend %esp to a physical address */ - addl virt_offset, %esp - - /* Use long-mode IDT */ - lidt idtr64 - - /* Return to virtual address */ - ret - - /* Long mode jump offset and target. Required since an ljmp - * in protected mode will zero-extend the offset, and so - * cannot reach an address within the negative 2GB as used by - * -mcmodel=kernel. Assigned by the call to init_librm. - */ - .equ p2l_ljmp_offset, ( p2l_ljmp + 1 ) - .equ p2l_ljmp_target, p2l_lmode - - .endif - -/**************************************************************************** - * long_to_prot (long-mode near call, 64-bit virtual return address) - * - * Switch from 64-bit long mode to 32-bit protected mode with virtual - * addresses. The long-mode %rsp is adjusted to a virtual address. - * All other registers are preserved. - * - * The return address for this function should be a 64-bit (sic) - * virtual address. - * - **************************************************************************** - */ - .if64 - - .section ".text.long_to_prot", "ax", @progbits - .code64 -long_to_prot: - /* Switch to protected mode */ - ljmp *l2p_vector - .code32 -l2p_pmode: - /* Adjust %esp to a virtual address */ - subl VIRTUAL(virt_offset), %esp - - /* Preserve registers */ - pushl %eax - pushl %ecx - pushl %edx - - /* Disable paging */ - movl %cr0, %eax - andl $~CR0_PG, %eax - movl %eax, %cr0 - - /* Disable PAE (in case external non-PAE-aware code enables paging) */ - movl %cr4, %eax - andb $~CR4_PAE, %al - movl %eax, %cr4 - - /* Disable long mode */ - movl $MSR_EFER, %ecx - rdmsr - andw $~EFER_LME, %ax - wrmsr - - /* Restore registers */ - popl %edx - popl %ecx - popl %eax - - /* Use protected-mode IDT */ - lidt VIRTUAL(idtr32) - - /* Return */ - ret $4 - - /* Long mode jump vector. Required since there is no "ljmp - * immediate" instruction in long mode. - */ - .section ".data.l2p_vector", "aw", @progbits -l2p_vector: - .long VIRTUAL(l2p_pmode), VIRTUAL_CS - - .endif - -/**************************************************************************** - * long_save_regs (long-mode near call, 64-bit virtual return address) - * - * Preserve registers that are accessible only in long mode. This - * includes %r8-%r15 and the upper halves of %rax, %rbx, %rcx, %rdx, - * %rsi, %rdi, and %rbp. - * - **************************************************************************** - */ - .if64 - - .section ".text.long_preserve_regs", "ax", @progbits - .code64 -long_preserve_regs: - /* Preserve registers */ - pushq %rax - pushq %rcx - pushq %rdx - pushq %rbx - pushq %rsp - pushq %rbp - pushq %rsi - pushq %rdi - pushq %r8 - pushq %r9 - pushq %r10 - pushq %r11 - pushq %r12 - pushq %r13 - pushq %r14 - pushq %r15 - - /* Return */ - jmp *SIZEOF_X86_64_REGS(%rsp) - - .endif - -/**************************************************************************** - * long_restore_regs (long-mode near call, 64-bit virtual return address) - * - * Restore registers that are accessible only in long mode. This - * includes %r8-%r15 and the upper halves of %rax, %rbx, %rcx, %rdx, - * %rsi, %rdi, and %rbp. - * - **************************************************************************** - */ - .if64 - - .section ".text.long_restore_regs", "ax", @progbits - .code64 -long_restore_regs: - /* Move return address above register dump */ - popq SIZEOF_X86_64_REGS(%rsp) - - /* Restore registers */ - popq %r15 - popq %r14 - popq %r13 - popq %r12 - popq %r11 - popq %r10 - popq %r9 - popq %r8 - movl %edi, (%rsp) - popq %rdi - movl %esi, (%rsp) - popq %rsi - movl %ebp, (%rsp) - popq %rbp - leaq 8(%rsp), %rsp /* discard */ - movl %ebx, (%rsp) - popq %rbx - movl %edx, (%rsp) - popq %rdx - movl %ecx, (%rsp) - popq %rcx - movl %eax, (%rsp) - popq %rax - - /* Return */ - ret - - .endif - -/**************************************************************************** - * virt_call (real-mode near call, 16-bit real-mode near return address) - * - * Call a specific C function in 32-bit protected mode or 64-bit long - * mode (as applicable). The prototype of the C function must be - * void function ( struct i386_all_regs *ix86 ); - * ix86 will point to a struct containing the real-mode registers - * at entry to virt_call(). - * - * All registers will be preserved across virt_call(), unless the C - * function explicitly overwrites values in ix86. Interrupt status - * and GDT will also be preserved. Gate A20 will be enabled. - * - * Note that virt_call() does not rely on the real-mode stack - * remaining intact in order to return, since everything relevant is - * copied to the protected-mode stack for the duration of the call. - * In particular, this means that a real-mode prefix can make a call - * to main() which will return correctly even if the prefix's stack - * gets vapourised during the Etherboot run. (The prefix cannot rely - * on anything else on the stack being preserved, so should move any - * critical data to registers before calling main()). - * - * Parameters: - * function : 32-bit virtual address of function to call - * - * Example usage: - * pushl $pxe_api_call - * call virt_call - * to call in to the C function - * void pxe_api_call ( struct i386_all_regs *ix86 ); - **************************************************************************** - */ - .struct 0 -VC_OFFSET_IX86: .space SIZEOF_I386_ALL_REGS -VC_OFFSET_PADDING: .space 2 /* for alignment */ -VC_OFFSET_RETADDR: .space 2 -VC_OFFSET_PARAMS: -VC_OFFSET_FUNCTION: .space 4 -VC_OFFSET_END: - .previous - - .section ".text16.virt_call", "ax", @progbits - .code16 - .globl virt_call -virt_call: - /* Preserve registers and flags on external RM stack */ - pushw %ss /* padding */ - pushfl - pushal - pushw %gs - pushw %fs - pushw %es - pushw %ds - pushw %ss - pushw %cs - - /* Claim ownership of temporary static buffer */ - cli - - /* Preserve FPU, MMX and SSE state in temporary static buffer */ - movw %cs:rm_ds, %ds - fxsave ( rm_tmpbuf + VC_TMP_FXSAVE ) - - /* Preserve GDT and IDT in temporary static buffer */ - sidt ( rm_tmpbuf + VC_TMP_IDT ) - sgdt ( rm_tmpbuf + VC_TMP_GDT ) - -.if64 ; /* Preserve control registers, if applicable */ - movl $MSR_EFER, %ecx - rdmsr - movl %eax, ( rm_tmpbuf + VC_TMP_EMER + 0 ) - movl %edx, ( rm_tmpbuf + VC_TMP_EMER + 4 ) - movl %cr4, %eax - movl %eax, ( rm_tmpbuf + VC_TMP_CR4 ) - movl %cr3, %eax - movl %eax, ( rm_tmpbuf + VC_TMP_CR3 ) -.endif - /* For sanity's sake, clear the direction flag as soon as possible */ - cld - - /* Switch to protected mode and move register dump to PM stack */ - movl $VC_OFFSET_END, %ecx - movl $VC_TMP_END, %edx - pushl $VIRTUAL(vc_pmode) -vc_jmp: jmp real_to_prot - .section ".text.virt_call", "ax", @progbits - .code32 -vc_pmode: - /* Call function (in protected mode) */ - pushl %esp - call *(VC_OFFSET_FUNCTION+4)(%esp) - popl %eax /* discard */ - -.if64 ; /* Switch to long mode */ - jmp 1f -vc_lmode: - call prot_to_long - .code64 - - /* Call function (in long mode) */ - movq %rsp, %rdi - movslq VC_OFFSET_FUNCTION(%rsp), %rax - callq *%rax - - /* Switch to protected mode */ - call long_to_prot -1: .code32 -.endif - /* Switch to real mode and move register dump back to RM stack */ - movl $VC_OFFSET_END, %ecx - movl $VC_TMP_END, %edx - leal VC_TMP_GDT(%esp, %ecx), %esi - pushl $vc_rmode - jmp prot_to_real - .section ".text16.virt_call", "ax", @progbits - .code16 -vc_rmode: -.if64 ; /* Restore control registers, if applicable */ - movw %sp, %bp - movl ( rm_tmpbuf + VC_TMP_CR3 ), %eax - movl %eax, %cr3 - movl ( rm_tmpbuf + VC_TMP_CR4 ), %eax - movl %eax, %cr4 - movl ( rm_tmpbuf + VC_TMP_EMER + 0 ), %eax - movl ( rm_tmpbuf + VC_TMP_EMER + 4 ), %edx - movl $MSR_EFER, %ecx - wrmsr -.endif - /* Restore FPU, MMX and SSE state from temporary static buffer */ - fxrstor ( rm_tmpbuf + VC_TMP_FXSAVE ) - - /* Restore registers and flags and return */ - popl %eax /* skip %cs and %ss */ - popw %ds - popw %es - popw %fs - popw %gs - popal - /* popal skips %esp. We therefore want to do "movl -20(%sp), - * %esp", but -20(%sp) is not a valid 80386 expression. - * Fortunately, prot_to_real() zeroes the high word of %esp, so - * we can just use -20(%esp) instead. - */ - addr32 movl -20(%esp), %esp - popfl - popw %ss /* padding */ - - /* Return and discard function parameters */ - ret $( VC_OFFSET_END - VC_OFFSET_PARAMS ) - - - /* Protected-mode jump target */ - .equ vc_jmp_offset, ( vc_jmp - 4 ) - -/**************************************************************************** - * real_call (protected-mode near call, 32-bit virtual return address) - * real_call (long-mode near call, 64-bit virtual return address) - * - * Call a real-mode function from protected-mode or long-mode code. - * - * The non-segment register values will be passed directly to the - * real-mode code. The segment registers will be set as per - * prot_to_real. The non-segment register values set by the real-mode - * function will be passed back to the protected-mode or long-mode - * caller. A result of this is that this routine cannot be called - * directly from C code, since it clobbers registers that the C ABI - * expects the callee to preserve. - * - * librm.h defines a convenient macro REAL_CODE() for using real_call. - * See librm.h and realmode.h for details and examples. - * - * Parameters: - * function : offset within .text16 of real-mode function to call - * - * Returns: none - **************************************************************************** - */ - .struct 0 -RC_OFFSET_REGS: .space SIZEOF_I386_REGS -RC_OFFSET_REGS_END: -RC_OFFSET_FUNCTION_COPY:.space 4 -.if64 -RC_OFFSET_LREGS: .space SIZEOF_X86_64_REGS -RC_OFFSET_LREG_RETADDR: .space SIZEOF_ADDR -.endif -RC_OFFSET_RETADDR: .space SIZEOF_ADDR -RC_OFFSET_PARAMS: -RC_OFFSET_FUNCTION: .space SIZEOF_ADDR -RC_OFFSET_END: - .previous - - .section ".text.real_call", "ax", @progbits - .CODE_DEFAULT - .globl real_call -real_call: -.if64 ; /* Preserve registers and switch to protected mode, if applicable */ - call long_preserve_regs - call long_to_prot - .code32 -.endif - /* Create register dump and function pointer copy on PM stack */ - pushl ( RC_OFFSET_FUNCTION - RC_OFFSET_FUNCTION_COPY - 4 )(%esp) - pushal - - /* Switch to real mode and move register dump to RM stack */ - movl $RC_OFFSET_REGS_END, %ecx - movl $RC_TMP_END, %edx - pushl $rc_rmode - movl $VIRTUAL(rm_default_gdtr_idtr), %esi - jmp prot_to_real - .section ".text16.real_call", "ax", @progbits - .code16 -rc_rmode: - /* Call real-mode function */ - popal - call *( rm_tmpbuf + RC_TMP_FUNCTION ) - pushal - - /* For sanity's sake, clear the direction flag as soon as possible */ - cld - - /* Switch to protected mode and move register dump back to PM stack */ - movl $RC_OFFSET_REGS_END, %ecx - xorl %edx, %edx - pushl $VIRTUAL(rc_pmode) - jmp real_to_prot - .section ".text.real_call", "ax", @progbits - .code32 -rc_pmode: - /* Restore registers */ - popal - -.if64 ; /* Switch to long mode and restore registers, if applicable */ - call prot_to_long - .code64 - call long_restore_regs -.endif - /* Return and discard function parameters */ - ret $( RC_OFFSET_END - RC_OFFSET_PARAMS ) - - - /* Default real-mode global and interrupt descriptor table registers */ - .section ".data.rm_default_gdtr_idtr", "aw", @progbits -rm_default_gdtr_idtr: - .word 0 /* Global descriptor table limit */ - .long 0 /* Global descriptor table base */ - .word 0x03ff /* Interrupt descriptor table limit */ - .long 0 /* Interrupt descriptor table base */ - -/**************************************************************************** - * phys_call (protected-mode near call, 32-bit virtual return address) - * phys_call (long-mode near call, 64-bit virtual return address) - * - * Call a function with flat 32-bit physical addressing - * - * The non-segment register values will be passed directly to the - * function. The segment registers will be set for flat 32-bit - * physical addressing. The non-segment register values set by the - * function will be passed back to the caller. - * - * librm.h defines a convenient macro PHYS_CODE() for using phys_call. - * - * Parameters: - * function : virtual (sic) address of function to call - * - **************************************************************************** - */ - .struct 0 -.if64 -PHC_OFFSET_LREGS: .space SIZEOF_X86_64_REGS -PHC_OFFSET_LREG_RETADDR:.space SIZEOF_ADDR -.endif -PHC_OFFSET_RETADDR: .space SIZEOF_ADDR -PHC_OFFSET_PARAMS: -PHC_OFFSET_FUNCTION: .space SIZEOF_ADDR -PHC_OFFSET_END: - .previous - - .section ".text.phys_call", "ax", @progbits - .CODE_DEFAULT - .globl phys_call -phys_call: -.if64 ; /* Preserve registers and switch to protected mode, if applicable */ - call long_preserve_regs - call long_to_prot - .code32 -.endif - /* Adjust function pointer to a physical address */ - pushl %ebp - movl VIRTUAL(virt_offset), %ebp - addl %ebp, ( PHC_OFFSET_FUNCTION + 4 /* saved %ebp */ )(%esp) - popl %ebp - - /* Switch to physical addresses */ - call prot_to_phys - - /* Call function */ - call *PHC_OFFSET_FUNCTION(%esp) - - /* For sanity's sake, clear the direction flag as soon as possible */ - cld - - /* Switch to virtual addresses */ - call phys_to_prot - -.if64 ; /* Switch to long mode and restore registers, if applicable */ - call prot_to_long - .code64 - call long_restore_regs -.endif - /* Return and discard function parameters */ - ret $( PHC_OFFSET_END - PHC_OFFSET_PARAMS ) - -/**************************************************************************** - * phys_to_long (protected-mode near call, 32-bit physical return address) - * - * Used by COMBOOT. - * - **************************************************************************** - */ - .if64 - - .section ".text.phys_to_long", "ax", @progbits - .code32 -phys_to_long: - - /* Switch to virtual addresses */ - call phys_to_prot - - /* Convert to 32-bit virtual return address */ - pushl %eax - movl VIRTUAL(virt_offset), %eax - subl %eax, 4(%esp) - popl %eax - - /* Switch to long mode and return */ - jmp prot_to_long - - /* Expose as _phys_to_virt for use by COMBOOT */ - .globl _phys_to_virt - .equ _phys_to_virt, phys_to_long - - .endif - -/**************************************************************************** - * long_to_phys (long-mode near call, 64-bit virtual return address) - * - * Used by COMBOOT. - * - **************************************************************************** - */ - .if64 - - .section ".text.long_to_phys", "ax", @progbits - .code64 -long_to_phys: - - /* Switch to protected mode */ - call long_to_prot - .code32 - - /* Convert to 32-bit virtual return address */ - popl (%esp) - - /* Switch to physical addresses and return */ - jmp prot_to_phys - - /* Expose as _virt_to_phys for use by COMBOOT */ - .globl _virt_to_phys - .equ _virt_to_phys, long_to_phys - - .endif - -/**************************************************************************** - * flatten_real_mode (real-mode near call) - * - * Switch to flat real mode - * - **************************************************************************** - */ - .section ".text16.flatten_real_mode", "ax", @progbits - .code16 - .globl flatten_real_mode -flatten_real_mode: - /* Modify GDT to use flat real mode */ - movb $0x8f, real_cs + 6 - movb $0x8f, real_ds + 6 - /* Call dummy protected-mode function */ - virtcall flatten_dummy - /* Restore GDT */ - movb $0x00, real_cs + 6 - movb $0x00, real_ds + 6 - /* Return */ - ret - - .section ".text.flatten_dummy", "ax", @progbits - .CODE_DEFAULT -flatten_dummy: - ret - -/**************************************************************************** - * Interrupt wrapper - * - * Used by the protected-mode and long-mode interrupt vectors to call - * the interrupt() function. - * - * May be entered with either physical or virtual stack segment. - **************************************************************************** - */ - .section ".text.interrupt_wrapper", "ax", @progbits - .code32 - .globl interrupt_wrapper -interrupt_wrapper: - /* Preserve registers (excluding already-saved %eax and - * otherwise unused registers which are callee-save for both - * 32-bit and 64-bit ABIs). - */ - pushl %ebx - pushl %ecx - pushl %edx - pushl %esi - pushl %edi - - /* Expand IRQ number to whole %eax register */ - movzbl %al, %eax - -.if64 ; /* Skip transition to long mode, if applicable */ - movw %cs, %bx - cmpw $LONG_CS, %bx - je 1f -.endif - /* Preserve segment registers and original %esp */ - pushl %ds - pushl %es - pushl %fs - pushl %gs - pushl %ss - pushl %esp - - /* Switch to virtual addressing */ - call intr_to_prot -.if64 - /* Switch to long mode */ - call prot_to_long - .code64 - -1: /* Preserve long-mode caller-save registers */ - pushq %r8 - pushq %r9 - pushq %r10 - pushq %r11 - - /* Expand IRQ number to whole %rdi register */ - movl %eax, %edi -.endif - /* Call interrupt handler */ - call interrupt -.if64 - /* Restore long-mode caller-save registers */ - popq %r11 - popq %r10 - popq %r9 - popq %r8 - - /* Skip transition back to protected mode, if applicable */ - cmpw $LONG_CS, %bx - je 1f - - /* Switch to protected mode */ - call long_to_prot - .code32 - cmpw $LONG_CS, %bx -.endif - /* Restore segment registers and original %esp */ - lss (%esp), %esp - popl %ss - popl %gs - popl %fs - popl %es - popl %ds - -1: /* Restore registers */ - popl %edi - popl %esi - popl %edx - popl %ecx - popl %ebx - popl %eax - - /* Return from interrupt (with REX prefix if required) */ -.if64 ; jne 1f ; .byte 0x48 ; .endif -1: iret - -/**************************************************************************** - * Page tables - * - **************************************************************************** - */ - .section ".pages", "aw", @nobits - .align SIZEOF_PT - - /* Page map level 4 entries (PML4Es) - * - * This comprises - * - * - PML4E[0x000] covering [0x0000000000000000-0x0000007fffffffff] - * - PML4E[0x1ff] covering [0xffffff8000000000-0xffffffffffffffff] - * - * These point to the PDPT. This creates some aliased - * addresses within unused portions of the 64-bit address - * space, but allows us to use just a single PDPT. - * - * - PDE[...] covering arbitrary 2MB portions of I/O space - * - * These are 2MB pages created by ioremap() to cover I/O - * device addresses. - */ -pml4e: - .space SIZEOF_PT - .size pml4e, . - pml4e - - .globl io_pages - .equ io_pages, pml4e - - /* Page directory pointer table entries (PDPTEs) - * - * This comprises: - * - * - PDPTE[0x000] covering [0x0000000000000000-0x000000003fffffff] - * - PDPTE[0x001] covering [0x0000000040000000-0x000000007fffffff] - * - PDPTE[0x002] covering [0x0000000080000000-0x00000000bfffffff] - * - PDPTE[0x003] covering [0x00000000c0000000-0x00000000ffffffff] - * - * These point to the appropriate page directories (in pde_low) - * used to identity-map the whole of the 32-bit address space. - * - * - PDPTE[0x004] covering [0x0000000100000000-0x000000013fffffff] - * - * This points back to the PML4, allowing the PML4 to be - * (ab)used to hold 2MB pages used for I/O device addresses. - * - * - PDPTE[0x1ff] covering [0xffffffffc0000000-0xffffffffffffffff] - * - * This points back to the PDPT itself, allowing the PDPT to be - * (ab)used to hold PDEs covering .textdata. - * - * - PDE[N-M] covering [_textdata,_end) - * - * These are used to point to the page tables (in pte_textdata) - * used to map our .textdata section. Note that each PDE - * covers 2MB, so we are likely to use only a single PDE in - * practice. - */ -pdpte: - .space SIZEOF_PT - .size pdpte, . - pdpte - .equ pde_textdata, pdpte /* (ab)use */ - - /* Page directory entries (PDEs) for the low 4GB - * - * This comprises 2048 2MB pages to identity-map the whole of - * the 32-bit address space. - */ -pde_low: - .equ PDE_LOW_PTES, ( SIZEOF_LOW_4GB / SIZEOF_2MB_PAGE ) - .equ PDE_LOW_PTS, ( ( PDE_LOW_PTES * SIZEOF_PTE ) / SIZEOF_PT ) - .space ( PDE_LOW_PTS * SIZEOF_PT ) - .size pde_low, . - pde_low - - /* Page table entries (PTEs) for .textdata - * - * This comprises enough 4kB pages to map the whole of - * .textdata. The required number of PTEs is calculated by - * the linker script. - * - * Note that these mappings do not cover the PTEs themselves. - * This does not matter, since code running with paging - * enabled never needs to access these PTEs. - */ -pte_textdata: - /* Allocated by linker script; must be at the end of .textdata */ - - .section ".bss.pml4", "aw", @nobits -pml4: .long 0 - -/**************************************************************************** - * init_pages (protected-mode near call) - * - * Initialise the page tables ready for long mode. - * - * Parameters: - * %edi : virt_offset - **************************************************************************** - */ - .section ".text.init_pages", "ax", @progbits - .code32 -init_pages: - /* Initialise PML4Es for low 4GB and negative 2GB */ - leal ( VIRTUAL(pdpte) + ( PG_P | PG_RW | PG_US ) )(%edi), %eax - movl %eax, VIRTUAL(pml4e) - movl %eax, ( VIRTUAL(pml4e) + SIZEOF_PT - SIZEOF_PTE ) - - /* Initialise PDPTE for negative 1GB */ - movl %eax, ( VIRTUAL(pdpte) + SIZEOF_PT - SIZEOF_PTE ) - - /* Initialise PDPTE for I/O space */ - leal ( VIRTUAL(pml4e) + ( PG_P | PG_RW | PG_US ) )(%edi), %eax - movl %eax, ( VIRTUAL(pdpte) + ( PDE_LOW_PTS * SIZEOF_PTE ) ) - - /* Initialise PDPTEs for low 4GB */ - movl $PDE_LOW_PTS, %ecx - leal ( VIRTUAL(pde_low) + ( PDE_LOW_PTS * SIZEOF_PT ) + \ - ( PG_P | PG_RW | PG_US ) )(%edi), %eax -1: subl $SIZEOF_PT, %eax - movl %eax, ( VIRTUAL(pdpte) - SIZEOF_PTE )(,%ecx,SIZEOF_PTE) - loop 1b - - /* Initialise PDEs for low 4GB */ - movl $PDE_LOW_PTES, %ecx - leal ( 0 + ( PG_P | PG_RW | PG_US | PG_PS ) ), %eax -1: subl $SIZEOF_2MB_PAGE, %eax - movl %eax, ( VIRTUAL(pde_low) - SIZEOF_PTE )(,%ecx,SIZEOF_PTE) - loop 1b - - /* Initialise PDEs for .textdata */ - movl $_textdata_pdes, %ecx - leal ( VIRTUAL(_etextdata) + ( PG_P | PG_RW | PG_US ) )(%edi), %eax - movl $VIRTUAL(_textdata), %ebx - shrl $( SIZEOF_2MB_PAGE_LOG2 - SIZEOF_PTE_LOG2 ), %ebx - andl $( SIZEOF_PT - 1 ), %ebx -1: subl $SIZEOF_PT, %eax - movl %eax, (VIRTUAL(pde_textdata) - SIZEOF_PTE)(%ebx,%ecx,SIZEOF_PTE) - loop 1b - - /* Initialise PTEs for .textdata */ - movl $_textdata_ptes, %ecx - leal ( VIRTUAL(_textdata) + ( PG_P | PG_RW | PG_US ) )(%edi), %eax - addl $_textdata_paged_len, %eax -1: subl $SIZEOF_4KB_PAGE, %eax - movl %eax, ( VIRTUAL(pte_textdata) - SIZEOF_PTE )(,%ecx,SIZEOF_PTE) - loop 1b - - /* Record PML4 physical address */ - leal VIRTUAL(pml4e)(%edi), %eax - movl %eax, VIRTUAL(pml4) - - /* Return */ - ret diff --git a/roms/ipxe/src/arch/x86/transitions/librm_mgmt.c b/roms/ipxe/src/arch/x86/transitions/librm_mgmt.c deleted file mode 100644 index 8776f2854..000000000 --- a/roms/ipxe/src/arch/x86/transitions/librm_mgmt.c +++ /dev/null @@ -1,310 +0,0 @@ -/* - * librm: a library for interfacing to real-mode code - * - * Michael Brown <mbrown@fensystems.co.uk> - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#include <stdint.h> -#include <strings.h> -#include <assert.h> -#include <ipxe/profile.h> -#include <realmode.h> -#include <pic8259.h> - -/* - * This file provides functions for managing librm. - * - */ - -/** The interrupt wrapper */ -extern char interrupt_wrapper[]; - -/** The interrupt vectors */ -static struct interrupt_vector intr_vec[NUM_INT]; - -/** The 32-bit interrupt descriptor table */ -static struct interrupt32_descriptor -idt32[NUM_INT] __attribute__ (( aligned ( 16 ) )); - -/** The 32-bit interrupt descriptor table register */ -struct idtr32 idtr32 = { - .limit = ( sizeof ( idt32 ) - 1 ), -}; - -/** The 64-bit interrupt descriptor table */ -static struct interrupt64_descriptor -idt64[NUM_INT] __attribute__ (( aligned ( 16 ) )); - -/** The interrupt descriptor table register */ -struct idtr64 idtr64 = { - .limit = ( sizeof ( idt64 ) - 1 ), -}; - -/** Timer interrupt profiler */ -static struct profiler timer_irq_profiler __profiler = { .name = "irq.timer" }; - -/** Other interrupt profiler */ -static struct profiler other_irq_profiler __profiler = { .name = "irq.other" }; - -/** - * Allocate space on the real-mode stack and copy data there from a - * user buffer - * - * @v data User buffer - * @v size Size of stack data - * @ret sp New value of real-mode stack pointer - */ -uint16_t copy_user_to_rm_stack ( userptr_t data, size_t size ) { - userptr_t rm_stack; - rm_sp -= size; - rm_stack = real_to_user ( rm_ss, rm_sp ); - memcpy_user ( rm_stack, 0, data, 0, size ); - return rm_sp; -}; - -/** - * Deallocate space on the real-mode stack, optionally copying back - * data to a user buffer. - * - * @v data User buffer - * @v size Size of stack data - */ -void remove_user_from_rm_stack ( userptr_t data, size_t size ) { - if ( data ) { - userptr_t rm_stack = real_to_user ( rm_ss, rm_sp ); - memcpy_user ( rm_stack, 0, data, 0, size ); - } - rm_sp += size; -}; - -/** - * Set interrupt vector - * - * @v intr Interrupt number - * @v vector Interrupt vector, or NULL to disable - */ -void set_interrupt_vector ( unsigned int intr, void *vector ) { - struct interrupt32_descriptor *idte32; - struct interrupt64_descriptor *idte64; - intptr_t addr = ( ( intptr_t ) vector ); - - /* Populate 32-bit interrupt descriptor */ - idte32 = &idt32[intr]; - idte32->segment = VIRTUAL_CS; - idte32->attr = ( vector ? ( IDTE_PRESENT | IDTE_TYPE_IRQ32 ) : 0 ); - idte32->low = ( addr >> 0 ); - idte32->high = ( addr >> 16 ); - - /* Populate 64-bit interrupt descriptor, if applicable */ - if ( sizeof ( physaddr_t ) > sizeof ( uint32_t ) ) { - idte64 = &idt64[intr]; - idte64->segment = LONG_CS; - idte64->attr = ( vector ? - ( IDTE_PRESENT | IDTE_TYPE_IRQ64 ) : 0 ); - idte64->low = ( addr >> 0 ); - idte64->mid = ( addr >> 16 ); - idte64->high = ( ( ( uint64_t ) addr ) >> 32 ); - } -} - -/** - * Initialise interrupt descriptor table - * - */ -void init_idt ( void ) { - struct interrupt_vector *vec; - unsigned int intr; - - /* Initialise the interrupt descriptor table and interrupt vectors */ - for ( intr = 0 ; intr < NUM_INT ; intr++ ) { - vec = &intr_vec[intr]; - vec->push = PUSH_INSN; - vec->movb = MOVB_INSN; - vec->intr = intr; - vec->jmp = JMP_INSN; - vec->offset = ( ( intptr_t ) interrupt_wrapper - - ( intptr_t ) vec->next ); - set_interrupt_vector ( intr, vec ); - } - DBGC ( &intr_vec[0], "INTn vector at %p+%zxn (phys %#lx+%zxn)\n", - intr_vec, sizeof ( intr_vec[0] ), - virt_to_phys ( intr_vec ), sizeof ( intr_vec[0] ) ); - - /* Initialise the 32-bit interrupt descriptor table register */ - idtr32.base = virt_to_phys ( idt32 ); - - /* Initialise the 64-bit interrupt descriptor table register, - * if applicable. - */ - if ( sizeof ( physaddr_t ) > sizeof ( uint32_t ) ) - idtr64.base = virt_to_phys ( idt64 ); -} - -/** - * Determine interrupt profiler (for debugging) - * - * @v intr Interrupt number - * @ret profiler Profiler - */ -static struct profiler * interrupt_profiler ( int intr ) { - - switch ( intr ) { - case IRQ_INT ( 0 ) : - return &timer_irq_profiler; - default: - return &other_irq_profiler; - } -} - -/** - * Interrupt handler - * - * @v intr Interrupt number - */ -void __attribute__ (( regparm ( 1 ) )) interrupt ( int intr ) { - struct profiler *profiler = interrupt_profiler ( intr ); - uint32_t discard_eax; - - /* Reissue interrupt in real mode */ - profile_start ( profiler ); - __asm__ __volatile__ ( REAL_CODE ( "movb %%al, %%cs:(1f + 1)\n\t" - "\n1:\n\t" - "int $0x00\n\t" ) - : "=a" ( discard_eax ) : "0" ( intr ) ); - profile_stop ( profiler ); - profile_exclude ( profiler ); -} - -/** - * Map pages for I/O - * - * @v bus_addr Bus address - * @v len Length of region - * @ret io_addr I/O address - */ -static void * ioremap_pages ( unsigned long bus_addr, size_t len ) { - unsigned long start; - unsigned int count; - unsigned int stride; - unsigned int first; - unsigned int i; - size_t offset; - void *io_addr; - - DBGC ( &io_pages, "IO mapping %08lx+%zx\n", bus_addr, len ); - - /* Sanity check */ - assert ( len != 0 ); - - /* Round down start address to a page boundary */ - start = ( bus_addr & ~( IO_PAGE_SIZE - 1 ) ); - offset = ( bus_addr - start ); - assert ( offset < IO_PAGE_SIZE ); - - /* Calculate number of pages required */ - count = ( ( offset + len + IO_PAGE_SIZE - 1 ) / IO_PAGE_SIZE ); - assert ( count != 0 ); - assert ( count < ( sizeof ( io_pages.page ) / - sizeof ( io_pages.page[0] ) ) ); - - /* Round up number of pages to a power of two */ - stride = ( 1 << ( fls ( count ) - 1 ) ); - assert ( count <= stride ); - - /* Allocate pages */ - for ( first = 0 ; first < ( sizeof ( io_pages.page ) / - sizeof ( io_pages.page[0] ) ) ; - first += stride ) { - - /* Calculate I/O address */ - io_addr = ( IO_BASE + ( first * IO_PAGE_SIZE ) + offset ); - - /* Check that page table entries are available */ - for ( i = first ; i < ( first + count ) ; i++ ) { - if ( io_pages.page[i] & PAGE_P ) { - io_addr = NULL; - break; - } - } - if ( ! io_addr ) - continue; - - /* Create page table entries */ - for ( i = first ; i < ( first + count ) ; i++ ) { - io_pages.page[i] = ( start | PAGE_P | PAGE_RW | - PAGE_US | PAGE_PWT | PAGE_PCD | - PAGE_PS ); - start += IO_PAGE_SIZE; - } - - /* Mark last page as being the last in this allocation */ - io_pages.page[ i - 1 ] |= PAGE_LAST; - - /* Return I/O address */ - DBGC ( &io_pages, "IO mapped %08lx+%zx to %p using PTEs " - "[%d-%d]\n", bus_addr, len, io_addr, first, - ( first + count - 1 ) ); - return io_addr; - } - - DBGC ( &io_pages, "IO could not map %08lx+%zx\n", bus_addr, len ); - return NULL; -} - -/** - * Unmap pages for I/O - * - * @v io_addr I/O address - */ -static void iounmap_pages ( volatile const void *io_addr ) { - volatile const void *invalidate = io_addr; - unsigned int first; - unsigned int i; - int is_last; - - DBGC ( &io_pages, "IO unmapping %p\n", io_addr ); - - /* Calculate first page table entry */ - first = ( ( io_addr - IO_BASE ) / IO_PAGE_SIZE ); - - /* Clear page table entries */ - for ( i = first ; ; i++ ) { - - /* Sanity check */ - assert ( io_pages.page[i] & PAGE_P ); - - /* Check if this is the last page in this allocation */ - is_last = ( io_pages.page[i] & PAGE_LAST ); - - /* Clear page table entry */ - io_pages.page[i] = 0; - - /* Invalidate TLB for this page */ - __asm__ __volatile__ ( "invlpg (%0)" : : "r" ( invalidate ) ); - invalidate += IO_PAGE_SIZE; - - /* Terminate if this was the last page */ - if ( is_last ) - break; - } - - DBGC ( &io_pages, "IO unmapped %p using PTEs [%d-%d]\n", - io_addr, first, i ); -} - -PROVIDE_UACCESS_INLINE ( librm, phys_to_user ); -PROVIDE_UACCESS_INLINE ( librm, user_to_phys ); -PROVIDE_UACCESS_INLINE ( librm, virt_to_user ); -PROVIDE_UACCESS_INLINE ( librm, user_to_virt ); -PROVIDE_UACCESS_INLINE ( librm, userptr_add ); -PROVIDE_UACCESS_INLINE ( librm, memcpy_user ); -PROVIDE_UACCESS_INLINE ( librm, memmove_user ); -PROVIDE_UACCESS_INLINE ( librm, memset_user ); -PROVIDE_UACCESS_INLINE ( librm, strlen_user ); -PROVIDE_UACCESS_INLINE ( librm, memchr_user ); -PROVIDE_IOMAP_INLINE ( pages, io_to_bus ); -PROVIDE_IOMAP ( pages, ioremap, ioremap_pages ); -PROVIDE_IOMAP ( pages, iounmap, iounmap_pages ); diff --git a/roms/ipxe/src/arch/x86_64/Makefile b/roms/ipxe/src/arch/x86_64/Makefile index 246905cdb..48c0aa1af 100644 --- a/roms/ipxe/src/arch/x86_64/Makefile +++ b/roms/ipxe/src/arch/x86_64/Makefile @@ -7,6 +7,10 @@ CFLAGS += -fstrength-reduce -fomit-frame-pointer # CFLAGS += -falign-jumps=1 -falign-loops=1 -falign-functions=1 +# Use %rip-relative addressing wherever possible. +# +CFLAGS += -fpie + # Force 64-bit code # CFLAGS += -m64 diff --git a/roms/ipxe/src/arch/x86_64/Makefile.efi b/roms/ipxe/src/arch/x86_64/Makefile.efi index 0041bb8f0..26b712780 100644 --- a/roms/ipxe/src/arch/x86_64/Makefile.efi +++ b/roms/ipxe/src/arch/x86_64/Makefile.efi @@ -1,9 +1,5 @@ # -*- makefile -*- : Force emacs to use Makefile mode -# Use %rip-relative addressing wherever possible. -# -CFLAGS += -fpie - # EFI probably doesn't guarantee us a red zone, so let's not rely on it. # CFLAGS += -mno-red-zone @@ -12,10 +8,6 @@ CFLAGS += -mno-red-zone # ELF2EFI = $(ELF2EFI64) -# Specify EFI boot file -# -EFI_BOOT_FILE = bootx64.efi - # Include generic EFI Makefile # MAKEDEPS += arch/x86/Makefile.efi diff --git a/roms/ipxe/src/arch/x86_64/Makefile.pcbios b/roms/ipxe/src/arch/x86_64/Makefile.pcbios deleted file mode 100644 index ba4c8d8dc..000000000 --- a/roms/ipxe/src/arch/x86_64/Makefile.pcbios +++ /dev/null @@ -1,15 +0,0 @@ -# -*- makefile -*- : Force emacs to use Makefile mode - -# Place .textdata in negative 2GB of address space -# -CFLAGS += -mcmodel=kernel -LDFLAGS += --section-start=.textdata=0xffffffffeb000000 - -# Assembly code does not respect a red zone. -# -CFLAGS += -mno-red-zone - -# Include generic BIOS Makefile -# -MAKEDEPS += arch/x86/Makefile.pcbios -include arch/x86/Makefile.pcbios diff --git a/roms/ipxe/src/arch/x86_64/core/gdbidt.S b/roms/ipxe/src/arch/x86_64/core/gdbidt.S deleted file mode 100644 index 89280bf89..000000000 --- a/roms/ipxe/src/arch/x86_64/core/gdbidt.S +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (C) 2016 Michael Brown <mbrown@fensystems.co.uk>. - * - * 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 ); - -/** @file - * - * GDB exception handlers - * - */ - -/* Size of a register */ -#define SIZEOF_REG 8 - -/* POSIX signal numbers for reporting traps to GDB */ -#define SIGILL 4 -#define SIGTRAP 5 -#define SIGFPE 8 -#define SIGSTKFLT 16 - - .section ".text.gdbmach_interrupt", "ax", @progbits - .code64 - - .struct 0 -/* Register dump created for GDB stub */ -regs: -regs_rax: .space SIZEOF_REG -regs_rbx: .space SIZEOF_REG -regs_rcx: .space SIZEOF_REG -regs_rdx: .space SIZEOF_REG -regs_rsi: .space SIZEOF_REG -regs_rdi: .space SIZEOF_REG -regs_rbp: .space SIZEOF_REG -regs_rsp: .space SIZEOF_REG -regs_r8: .space SIZEOF_REG -regs_r9: .space SIZEOF_REG -regs_r10: .space SIZEOF_REG -regs_r11: .space SIZEOF_REG -regs_r12: .space SIZEOF_REG -regs_r13: .space SIZEOF_REG -regs_r14: .space SIZEOF_REG -regs_r15: .space SIZEOF_REG -regs_rip: .space SIZEOF_REG -regs_rflags: .space SIZEOF_REG -regs_cs: .space SIZEOF_REG -regs_ss: .space SIZEOF_REG -regs_ds: .space SIZEOF_REG -regs_es: .space SIZEOF_REG -regs_fs: .space SIZEOF_REG -regs_gs: .space SIZEOF_REG -regs_end: -/* GDB signal code */ -gdb: -gdb_code: .space SIZEOF_REG -gdb_end: -/* Long-mode exception frame */ -frame: -frame_rip: .space SIZEOF_REG -frame_cs: .space SIZEOF_REG -frame_rflags: .space SIZEOF_REG -frame_rsp: .space SIZEOF_REG -frame_ss: .space SIZEOF_REG -frame_end: - .previous - - .globl gdbmach_sigfpe -gdbmach_sigfpe: - push $SIGFPE - jmp gdbmach_interrupt - - .globl gdbmach_sigtrap -gdbmach_sigtrap: - push $SIGTRAP - jmp gdbmach_interrupt - - .globl gdbmach_sigstkflt -gdbmach_sigstkflt: - push $SIGSTKFLT - jmp gdbmach_interrupt - - .globl gdbmach_sigill -gdbmach_sigill: - push $SIGILL - jmp gdbmach_interrupt - -gdbmach_interrupt: - - /* Create register dump */ - pushq %gs - pushq %fs - pushq $0 /* %es unused in long mode */ - pushq $0 /* %ds unused in long mode */ - pushq ( frame_ss - regs_ss - SIZEOF_REG )(%rsp) - pushq ( frame_cs - regs_cs - SIZEOF_REG )(%rsp) - pushq ( frame_rflags - regs_rflags - SIZEOF_REG )(%rsp) - pushq ( frame_rip - regs_rip - SIZEOF_REG )(%rsp) - pushq %r15 - pushq %r14 - pushq %r13 - pushq %r12 - pushq %r11 - pushq %r10 - pushq %r9 - pushq %r8 - pushq ( frame_rsp - regs_rsp - SIZEOF_REG )(%rsp) - pushq %rbp - pushq %rdi - pushq %rsi - pushq %rdx - pushq %rcx - pushq %rbx - pushq %rax - - /* Call GDB stub exception handler */ - movq gdb_code(%rsp), %rdi - movq %rsp, %rsi - call gdbmach_handler - - /* Restore from register dump */ - popq %rax - popq %rbx - popq %rcx - popq %rdx - popq %rsi - popq %rdi - popq %rbp - popq ( frame_rsp - regs_rsp - SIZEOF_REG )(%rsp) - popq %r8 - popq %r9 - popq %r10 - popq %r11 - popq %r12 - popq %r13 - popq %r14 - popq %r15 - popq ( frame_rip - regs_rip - SIZEOF_REG )(%rsp) - popq ( frame_rflags - regs_rflags - SIZEOF_REG )(%rsp) - popq ( frame_cs - regs_cs - SIZEOF_REG )(%rsp) - popq ( frame_ss - regs_ss - SIZEOF_REG )(%rsp) - addq $( regs_fs - regs_ds ), %rsp /* skip %ds, %es */ - popq %fs - popq %gs - - /* Skip code */ - addq $( gdb_end - gdb_code ), %rsp /* skip code */ - - /* Return */ - iretq diff --git a/roms/ipxe/src/arch/x86_64/include/bits/compiler.h b/roms/ipxe/src/arch/x86_64/include/bits/compiler.h index 98c560e7d..f70b2e517 100644 --- a/roms/ipxe/src/arch/x86_64/include/bits/compiler.h +++ b/roms/ipxe/src/arch/x86_64/include/bits/compiler.h @@ -7,7 +7,7 @@ #ifndef ASSEMBLY /** Declare a function with standard calling conventions */ -#define __asmcall __attribute__ (( used, regparm(0) )) +#define __asmcall __attribute__ (( regparm(0) )) /** Declare a function with libgcc implicit linkage */ #define __libgcc diff --git a/roms/ipxe/src/arch/arm/include/bits/entropy.h b/roms/ipxe/src/arch/x86_64/include/bits/entropy.h index 75fdc90ea..a9b3bc10e 100644 --- a/roms/ipxe/src/arch/arm/include/bits/entropy.h +++ b/roms/ipxe/src/arch/x86_64/include/bits/entropy.h @@ -3,7 +3,7 @@ /** @file * - * ARM-specific entropy API implementations + * x86_64-specific entropy API implementations * */ diff --git a/roms/ipxe/src/arch/x86_64/include/bits/hyperv.h b/roms/ipxe/src/arch/x86_64/include/bits/hyperv.h index 975b1eee0..845c182f7 100644 --- a/roms/ipxe/src/arch/x86_64/include/bits/hyperv.h +++ b/roms/ipxe/src/arch/x86_64/include/bits/hyperv.h @@ -49,4 +49,27 @@ hv_call ( struct hv_hypervisor *hv, unsigned int code, const void *in, return result; } +/** + * Set bit atomically + * + * @v bits Bit field + * @v bit Bit to set + */ +static inline __attribute__ (( always_inline )) void +hv_set_bit ( void *bits, unsigned int bit ) { + struct { + uint64_t qword[ ( bit / 64 ) + 1 ]; + } *qwords = bits; + + /* Set bit using "lock bts". Inform compiler that any memory + * from the start of the bit field up to and including the + * qword containing this bit may be modified. (This is + * overkill but shouldn't matter in practice since we're + * unlikely to subsequently read other bits from the same bit + * field.) + */ + __asm__ __volatile__ ( "lock bts %1, %0" + : "+m" ( *qwords ) : "Ir" ( bit ) ); +} + #endif /* _BITS_HYPERV_H */ diff --git a/roms/ipxe/src/arch/x86_64/include/bits/nap.h b/roms/ipxe/src/arch/x86_64/include/bits/nap.h new file mode 100644 index 000000000..8b42c0a4a --- /dev/null +++ b/roms/ipxe/src/arch/x86_64/include/bits/nap.h @@ -0,0 +1,12 @@ +#ifndef _BITS_NAP_H +#define _BITS_NAP_H + +/** @file + * + * x86_64-specific CPU sleeping API implementations + * + */ + +#include <ipxe/efi/efix86_nap.h> + +#endif /* _BITS_MAP_H */ diff --git a/roms/ipxe/src/arch/arm/include/bits/reboot.h b/roms/ipxe/src/arch/x86_64/include/bits/reboot.h index 88c50250c..f9bcd6a7b 100644 --- a/roms/ipxe/src/arch/arm/include/bits/reboot.h +++ b/roms/ipxe/src/arch/x86_64/include/bits/reboot.h @@ -3,7 +3,7 @@ /** @file * - * ARM-specific reboot API implementations + * x86_64-specific reboot API implementations * */ diff --git a/roms/ipxe/src/arch/arm/include/bits/sanboot.h b/roms/ipxe/src/arch/x86_64/include/bits/sanboot.h index abd4c79a5..dcab830f6 100644 --- a/roms/ipxe/src/arch/arm/include/bits/sanboot.h +++ b/roms/ipxe/src/arch/x86_64/include/bits/sanboot.h @@ -3,7 +3,7 @@ /** @file * - * ARM-specific sanboot API implementations + * x86_64-specific sanboot API implementations * */ diff --git a/roms/ipxe/src/arch/arm/include/bits/smbios.h b/roms/ipxe/src/arch/x86_64/include/bits/smbios.h index d94218116..2f0118d02 100644 --- a/roms/ipxe/src/arch/arm/include/bits/smbios.h +++ b/roms/ipxe/src/arch/x86_64/include/bits/smbios.h @@ -3,10 +3,8 @@ /** @file * - * ARM-specific SMBIOS API implementations + * i386-specific SMBIOS API implementations * */ -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - #endif /* _BITS_SMBIOS_H */ diff --git a/roms/ipxe/src/arch/arm/include/bits/time.h b/roms/ipxe/src/arch/x86_64/include/bits/time.h index 724d8b932..aa74fac8c 100644 --- a/roms/ipxe/src/arch/arm/include/bits/time.h +++ b/roms/ipxe/src/arch/x86_64/include/bits/time.h @@ -3,7 +3,7 @@ /** @file * - * ARM-specific time API implementations + * x86_64-specific time API implementations * */ diff --git a/roms/ipxe/src/arch/arm/include/bits/timer.h b/roms/ipxe/src/arch/x86_64/include/bits/timer.h index 64e7d31df..dfa6c270c 100644 --- a/roms/ipxe/src/arch/arm/include/bits/timer.h +++ b/roms/ipxe/src/arch/x86_64/include/bits/timer.h @@ -3,10 +3,8 @@ /** @file * - * ARM-specific timer API implementations + * x86_64-specific timer API implementations * */ -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - #endif /* _BITS_TIMER_H */ diff --git a/roms/ipxe/src/arch/arm/include/bits/uaccess.h b/roms/ipxe/src/arch/x86_64/include/bits/uaccess.h index 87f11509c..455829242 100644 --- a/roms/ipxe/src/arch/arm/include/bits/uaccess.h +++ b/roms/ipxe/src/arch/x86_64/include/bits/uaccess.h @@ -3,10 +3,8 @@ /** @file * - * ARM-specific user access API implementations + * x86_64-specific user access API implementations * */ -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - #endif /* _BITS_UACCESS_H */ diff --git a/roms/ipxe/src/arch/x86_64/include/bits/umalloc.h b/roms/ipxe/src/arch/x86_64/include/bits/umalloc.h new file mode 100644 index 000000000..12bf949d1 --- /dev/null +++ b/roms/ipxe/src/arch/x86_64/include/bits/umalloc.h @@ -0,0 +1,10 @@ +#ifndef _BITS_UMALLOC_H +#define _BITS_UMALLOC_H + +/** @file + * + * x86_64-specific user memory allocation API implementations + * + */ + +#endif /* _BITS_UMALLOC_H */ diff --git a/roms/ipxe/src/arch/x86_64/include/gdbmach.h b/roms/ipxe/src/arch/x86_64/include/gdbmach.h index 367405fd6..6dadbbdd3 100644 --- a/roms/ipxe/src/arch/x86_64/include/gdbmach.h +++ b/roms/ipxe/src/arch/x86_64/include/gdbmach.h @@ -14,37 +14,16 @@ typedef unsigned long gdbreg_t; -/* Register snapshot */ +/* The register snapshot, this must be in sync with interrupt handler and the + * GDB protocol. */ enum { - GDBMACH_RAX, - GDBMACH_RBX, - GDBMACH_RCX, - GDBMACH_RDX, - GDBMACH_RSI, - GDBMACH_RDI, - GDBMACH_RBP, - GDBMACH_RSP, - GDBMACH_R8, - GDBMACH_R9, - GDBMACH_R10, - GDBMACH_R11, - GDBMACH_R12, - GDBMACH_R13, - GDBMACH_R14, - GDBMACH_R15, - GDBMACH_RIP, - GDBMACH_RFLAGS, - GDBMACH_CS, - GDBMACH_SS, - GDBMACH_DS, - GDBMACH_ES, - GDBMACH_FS, - GDBMACH_GS, + // STUB: don't expect this to work! + GDBMACH_EIP, + GDBMACH_EFLAGS, GDBMACH_NREGS, + GDBMACH_SIZEOF_REGS = GDBMACH_NREGS * sizeof ( gdbreg_t ) }; -#define GDBMACH_SIZEOF_REGS ( GDBMACH_NREGS * sizeof ( gdbreg_t ) ) - /* Breakpoint types */ enum { GDBMACH_BPMEM, @@ -54,27 +33,21 @@ enum { GDBMACH_AWATCH, }; -/* Exception vectors */ -extern void gdbmach_sigfpe ( void ); -extern void gdbmach_sigtrap ( void ); -extern void gdbmach_sigstkflt ( void ); -extern void gdbmach_sigill ( void ); - static inline void gdbmach_set_pc ( gdbreg_t *regs, gdbreg_t pc ) { - regs[GDBMACH_RIP] = pc; + regs [ GDBMACH_EIP ] = pc; } static inline void gdbmach_set_single_step ( gdbreg_t *regs, int step ) { - regs[GDBMACH_RFLAGS] &= ~( 1 << 8 ); /* Trace Flag (TF) */ - regs[GDBMACH_RFLAGS] |= ( step << 8 ); + regs [ GDBMACH_EFLAGS ] &= ~( 1 << 8 ); /* Trace Flag (TF) */ + regs [ GDBMACH_EFLAGS ] |= ( step << 8 ); } static inline void gdbmach_breakpoint ( void ) { __asm__ __volatile__ ( "int $3\n" ); } -extern int gdbmach_set_breakpoint ( int type, unsigned long addr, size_t len, - int enable ); +extern int gdbmach_set_breakpoint ( int type, unsigned long addr, size_t len, int enable ); + extern void gdbmach_init ( void ); #endif /* GDBMACH_H */ diff --git a/roms/ipxe/src/arch/x86_64/include/pcbios/ipxe/dhcp_arch.h b/roms/ipxe/src/arch/x86_64/include/pcbios/ipxe/dhcp_arch.h deleted file mode 100644 index e07e4c192..000000000 --- a/roms/ipxe/src/arch/x86_64/include/pcbios/ipxe/dhcp_arch.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2010 VMware, Inc. All Rights Reserved. - * - * 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 (at your option) 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. - */ - -#ifndef _DHCP_ARCH_H -#define _DHCP_ARCH_H - -/** @file - * - * Architecture-specific DHCP options - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#include <ipxe/dhcp.h> - -#define DHCP_ARCH_VENDOR_CLASS_ID \ - DHCP_STRING ( 'P', 'X', 'E', 'C', 'l', 'i', 'e', 'n', 't', ':', \ - 'A', 'r', 'c', 'h', ':', '0', '0', '0', '0', '0', ':', \ - 'U', 'N', 'D', 'I', ':', '0', '0', '2', '0', '0', '1' ) - -#define DHCP_ARCH_CLIENT_ARCHITECTURE \ - DHCP_WORD ( DHCP_CLIENT_ARCHITECTURE_X86 ) - -#define DHCP_ARCH_CLIENT_NDI DHCP_OPTION ( 1 /* UNDI */ , 2, 1 /* v2.1 */ ) - -#endif diff --git a/roms/ipxe/src/config/cloud/aws.ipxe b/roms/ipxe/src/config/cloud/aws.ipxe deleted file mode 100644 index d857d71df..000000000 --- a/roms/ipxe/src/config/cloud/aws.ipxe +++ /dev/null @@ -1,7 +0,0 @@ -#!ipxe - -echo Amazon EC2 - iPXE boot via user-data -ifstat || -dhcp || -route || -chain -ar http://169.254.169.254/latest/user-data diff --git a/roms/ipxe/src/config/cloud/colour.h b/roms/ipxe/src/config/cloud/colour.h deleted file mode 100644 index e69de29bb..000000000 --- a/roms/ipxe/src/config/cloud/colour.h +++ /dev/null diff --git a/roms/ipxe/src/config/cloud/console.h b/roms/ipxe/src/config/cloud/console.h deleted file mode 100644 index dae18e556..000000000 --- a/roms/ipxe/src/config/cloud/console.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Console configuration suitable for use in public cloud - * environments, or any environment where direct console access is not - * available. - * - */ - -/* Log to syslog(s) server - * - * The syslog server to be used must be specified via e.g. - * "set syslog 192.168.0.1". - */ -#define CONSOLE_SYSLOG -#define CONSOLE_SYSLOGS - -/* Log to serial port - * - * Note that the serial port output from an AWS EC2 virtual machine is - * generally available (as the "System Log") only after the instance - * has been stopped. - */ -#define CONSOLE_SERIAL - -/* Log to partition on local disk - * - * If all other log mechanisms fail then the VM boot disk containing - * the iPXE image can be detached and attached to another machine in - * the same cloud, allowing the log to be retrieved from the log - * partition. - */ -#define CONSOLE_INT13 diff --git a/roms/ipxe/src/config/cloud/crypto.h b/roms/ipxe/src/config/cloud/crypto.h deleted file mode 100644 index e69de29bb..000000000 --- a/roms/ipxe/src/config/cloud/crypto.h +++ /dev/null diff --git a/roms/ipxe/src/config/cloud/general.h b/roms/ipxe/src/config/cloud/general.h deleted file mode 100644 index e69de29bb..000000000 --- a/roms/ipxe/src/config/cloud/general.h +++ /dev/null diff --git a/roms/ipxe/src/config/cloud/serial.h b/roms/ipxe/src/config/cloud/serial.h deleted file mode 100644 index e69de29bb..000000000 --- a/roms/ipxe/src/config/cloud/serial.h +++ /dev/null diff --git a/roms/ipxe/src/config/cloud/settings.h b/roms/ipxe/src/config/cloud/settings.h deleted file mode 100644 index e69de29bb..000000000 --- a/roms/ipxe/src/config/cloud/settings.h +++ /dev/null diff --git a/roms/ipxe/src/config/cloud/sideband.h b/roms/ipxe/src/config/cloud/sideband.h deleted file mode 100644 index e69de29bb..000000000 --- a/roms/ipxe/src/config/cloud/sideband.h +++ /dev/null diff --git a/roms/ipxe/src/config/cloud/usb.h b/roms/ipxe/src/config/cloud/usb.h deleted file mode 100644 index e69de29bb..000000000 --- a/roms/ipxe/src/config/cloud/usb.h +++ /dev/null diff --git a/roms/ipxe/src/config/config.c b/roms/ipxe/src/config/config.c index e24cfe0d0..1dd912c1d 100644 --- a/roms/ipxe/src/config/config.c +++ b/roms/ipxe/src/config/config.c @@ -51,6 +51,9 @@ PROVIDE_REQUIRING_SYMBOL(); * */ +#ifdef CONSOLE_PCBIOS +REQUIRE_OBJECT ( bios_console ); +#endif #ifdef CONSOLE_SERIAL REQUIRE_OBJECT ( serial ); #endif @@ -78,6 +81,12 @@ REQUIRE_OBJECT ( vmconsole ); #ifdef CONSOLE_DEBUGCON REQUIRE_OBJECT ( debugcon ); #endif +#ifdef CONSOLE_VESAFB +REQUIRE_OBJECT ( vesafb ); +#endif +#ifdef CONSOLE_INT13 +REQUIRE_OBJECT ( int13con ); +#endif /* * Drag in all requested network protocols @@ -278,9 +287,6 @@ REQUIRE_OBJECT ( ipstat_cmd ); #ifdef PROFSTAT_CMD REQUIRE_OBJECT ( profstat_cmd ); #endif -#ifdef NTP_CMD -REQUIRE_OBJECT ( ntp_cmd ); -#endif /* * Drag in miscellaneous objects diff --git a/roms/ipxe/src/config/config_efi.c b/roms/ipxe/src/config/config_efi.c deleted file mode 100644 index 92678d12d..000000000 --- a/roms/ipxe/src/config/config_efi.c +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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 (at your option) 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 <config/general.h> -#include <config/console.h> - -/** @file - * - * EFI-specific configuration options - * - */ - -PROVIDE_REQUIRING_SYMBOL(); - -/* - * Drag in all requested console types - * - */ - -#ifdef CONSOLE_EFI -REQUIRE_OBJECT ( efi_console ); -#endif -#ifdef CONSOLE_EFIFB -REQUIRE_OBJECT ( efi_fbcon ); -#endif -#ifdef CONSOLE_FRAMEBUFFER -REQUIRE_OBJECT ( efi_fbcon ); -#endif -#ifdef DOWNLOAD_PROTO_FILE -REQUIRE_OBJECT ( efi_local ); -#endif diff --git a/roms/ipxe/src/config/config_ethernet.c b/roms/ipxe/src/config/config_ethernet.c index b5f7ddc9d..de7a07c57 100644 --- a/roms/ipxe/src/config/config_ethernet.c +++ b/roms/ipxe/src/config/config_ethernet.c @@ -43,6 +43,3 @@ REQUIRE_OBJECT ( fcoe ); #ifdef NET_PROTO_STP REQUIRE_OBJECT ( stp ); #endif -#ifdef NET_PROTO_LACP -REQUIRE_OBJECT ( eth_slow ); -#endif diff --git a/roms/ipxe/src/config/config_infiniband.c b/roms/ipxe/src/config/config_infiniband.c index 4da8fe219..a742e7559 100644 --- a/roms/ipxe/src/config/config_infiniband.c +++ b/roms/ipxe/src/config/config_infiniband.c @@ -37,20 +37,3 @@ PROVIDE_REQUIRING_SYMBOL(); #ifdef SANBOOT_PROTO_IB_SRP REQUIRE_OBJECT ( ib_srp ); #endif - -/* - * Drag in Infiniband-specific virtual network devices - */ -#ifdef VNIC_IPOIB -REQUIRE_OBJECT ( ipoib ); -#endif -#ifdef VNIC_XSIGO -REQUIRE_OBJECT ( xsigo ); -#endif - -/* - * Drag in Infiniband-specific commands - */ -#ifdef IBMGMT_CMD -REQUIRE_OBJECT ( ibmgmt_cmd ); -#endif diff --git a/roms/ipxe/src/config/config_linux.c b/roms/ipxe/src/config/config_linux.c deleted file mode 100644 index 71eeff9e7..000000000 --- a/roms/ipxe/src/config/config_linux.c +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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 (at your option) 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 <config/console.h> - -/** @file - * - * Linux-specific configuration options - * - */ - -PROVIDE_REQUIRING_SYMBOL(); - -/* - * Drag in all requested console types - * - */ - -#ifdef CONSOLE_LINUX -REQUIRE_OBJECT ( linux_console ); -#endif diff --git a/roms/ipxe/src/config/config_pcbios.c b/roms/ipxe/src/config/config_pcbios.c deleted file mode 100644 index 698c68a8d..000000000 --- a/roms/ipxe/src/config/config_pcbios.c +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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 (at your option) 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 <config/console.h> - -/** @file - * - * BIOS-specific configuration options - * - */ - -PROVIDE_REQUIRING_SYMBOL(); - -/* - * Drag in all requested console types - * - */ - -#ifdef CONSOLE_PCBIOS -REQUIRE_OBJECT ( bios_console ); -#endif -#ifdef CONSOLE_VESAFB -REQUIRE_OBJECT ( vesafb ); -#endif -#ifdef CONSOLE_FRAMEBUFFER -REQUIRE_OBJECT ( vesafb ); -#endif -#ifdef CONSOLE_INT13 -REQUIRE_OBJECT ( int13con ); -#endif diff --git a/roms/ipxe/src/config/config_usb.c b/roms/ipxe/src/config/config_usb.c index 17296d277..dc0e6e6af 100644 --- a/roms/ipxe/src/config/config_usb.c +++ b/roms/ipxe/src/config/config_usb.c @@ -43,9 +43,6 @@ REQUIRE_OBJECT ( ehci ); #ifdef USB_HCD_UHCI REQUIRE_OBJECT ( uhci ); #endif -#ifdef USB_HCD_USBIO -REQUIRE_OBJECT ( usbio ); -#endif /* * Drag in USB peripherals @@ -53,10 +50,3 @@ REQUIRE_OBJECT ( usbio ); #ifdef USB_KEYBOARD REQUIRE_OBJECT ( usbkbd ); #endif - -/* - * Drag in USB external interfaces - */ -#ifdef USB_EFI -REQUIRE_OBJECT ( efi_usb ); -#endif diff --git a/roms/ipxe/src/config/console.h b/roms/ipxe/src/config/console.h index 9f770d094..ffa5cf50d 100644 --- a/roms/ipxe/src/config/console.h +++ b/roms/ipxe/src/config/console.h @@ -5,7 +5,7 @@ * * Console configuration * - * These options specify the console types that iPXE will use for + * These options specify the console types that Etherboot will use for * interaction with the user. * */ @@ -14,51 +14,19 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <config/defaults.h> -/* - * Default console types - * - * These are all enabled by default for the appropriate platforms. - * You may disable them if needed. - * - */ - -//#undef CONSOLE_PCBIOS /* Default BIOS console */ -//#undef CONSOLE_EFI /* Default EFI console */ -//#undef CONSOLE_LINUX /* Default Linux console */ - -/* - * Additional console types - * - * These are not enabled by default, but may be useful in your - * environment. - * - */ - -//#define CONSOLE_SERIAL /* Serial port console */ -//#define CONSOLE_FRAMEBUFFER /* Graphical framebuffer console */ +//#define CONSOLE_PCBIOS /* Default BIOS console */ +//#define CONSOLE_SERIAL /* Serial port */ +//#define CONSOLE_DIRECT_VGA /* Direct access to VGA card */ +//#define CONSOLE_PC_KBD /* Direct access to PC keyboard */ //#define CONSOLE_SYSLOG /* Syslog console */ //#define CONSOLE_SYSLOGS /* Encrypted syslog console */ //#define CONSOLE_VMWARE /* VMware logfile console */ -//#define CONSOLE_DEBUGCON /* Bochs/QEMU/KVM debug port console */ +//#define CONSOLE_DEBUGCON /* Debug port console */ +//#define CONSOLE_VESAFB /* VESA framebuffer console */ //#define CONSOLE_INT13 /* INT13 disk log console */ -/* - * Very obscure console types - * - * You almost certainly do not need to enable these. - * - */ - -//#define CONSOLE_DIRECT_VGA /* Direct access to VGA card */ -//#define CONSOLE_PC_KBD /* Direct access to PC keyboard */ - -/* Keyboard map (available maps in hci/keymap/) */ #define KEYBOARD_MAP us -/* Control which syslog() messages are generated. - * - * Note that this is not related in any way to CONSOLE_SYSLOG. - */ #define LOG_LEVEL LOG_NONE #include <config/named.h> diff --git a/roms/ipxe/src/config/crypto.h b/roms/ipxe/src/config/crypto.h index 8f885c554..bccfc04b8 100644 --- a/roms/ipxe/src/config/crypto.h +++ b/roms/ipxe/src/config/crypto.h @@ -50,14 +50,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); */ #define TIMESTAMP_ERROR_MARGIN ( ( 12 * 60 + 30 ) * 60 ) -/** Default cross-signed certificate source - * - * This is the default location from which iPXE will attempt to - * download cross-signed certificates in order to complete a - * certificate chain. - */ -#define CROSSCERT "http://ca.ipxe.org/auto" - #include <config/named.h> #include NAMED_CONFIG(crypto.h) #include <config/local/crypto.h> diff --git a/roms/ipxe/src/config/defaults/efi.h b/roms/ipxe/src/config/defaults/efi.h index ba4eed936..cdf41c54d 100644 --- a/roms/ipxe/src/config/defaults/efi.h +++ b/roms/ipxe/src/config/defaults/efi.h @@ -10,10 +10,11 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #define UACCESS_EFI -#define IOMAP_VIRT +#define IOAPI_X86 #define PCIAPI_EFI #define CONSOLE_EFI #define TIMER_EFI +#define NAP_EFIX86 #define UMALLOC_EFI #define SMBIOS_EFI #define SANBOOT_NULL @@ -22,27 +23,10 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #define TIME_EFI #define REBOOT_EFI -#define DOWNLOAD_PROTO_FILE /* Local filesystem access */ - #define IMAGE_EFI /* EFI image support */ #define IMAGE_SCRIPT /* iPXE script image support */ -#define USB_HCD_XHCI /* xHCI USB host controller */ -#define USB_HCD_EHCI /* EHCI USB host controller */ -#define USB_HCD_UHCI /* UHCI USB host controller */ -#define USB_EFI /* Provide EFI_USB_IO_PROTOCOL interface */ - #define REBOOT_CMD /* Reboot command */ - -#if defined ( __i386__ ) || defined ( __x86_64__ ) -#define IOAPI_X86 -#define NAP_EFIX86 #define CPUID_CMD /* x86 CPU feature detection command */ -#endif - -#if defined ( __arm__ ) || defined ( __aarch64__ ) -#define IOAPI_ARM -#define NAP_EFIARM -#endif #endif /* CONFIG_DEFAULTS_EFI_H */ diff --git a/roms/ipxe/src/config/defaults/pcbios.h b/roms/ipxe/src/config/defaults/pcbios.h index e1915054c..3ed8343ce 100644 --- a/roms/ipxe/src/config/defaults/pcbios.h +++ b/roms/ipxe/src/config/defaults/pcbios.h @@ -22,12 +22,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #define TIME_RTC #define REBOOT_PCBIOS -#ifdef __x86_64__ -#define IOMAP_PAGES -#else -#define IOMAP_VIRT -#endif - #define IMAGE_ELF /* ELF image support */ #define IMAGE_MULTIBOOT /* MultiBoot image support */ #define IMAGE_PXE /* PXE image support */ diff --git a/roms/ipxe/src/config/dhcp.h b/roms/ipxe/src/config/dhcp.h index bff5b56d6..49fe16b92 100644 --- a/roms/ipxe/src/config/dhcp.h +++ b/roms/ipxe/src/config/dhcp.h @@ -25,12 +25,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); //#define DHCP_DISC_END_TIMEOUT_SEC 32 /* as per PXE spec */ /* - * Maximum number of discovery deferrals due to blocked links - * (e.g. from non-forwarding STP ports) - */ -#define DHCP_DISC_MAX_DEFERRALS 60 - -/* * ProxyDHCP offers are given precedence by continue to wait for them * after a valid DHCPOFFER is received. We'll wait through this * timeout for it. The PXE spec indicates waiting through the 4 & 8 diff --git a/roms/ipxe/src/config/general.h b/roms/ipxe/src/config/general.h index a71ba726f..ee15f6bf1 100644 --- a/roms/ipxe/src/config/general.h +++ b/roms/ipxe/src/config/general.h @@ -38,7 +38,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #undef NET_PROTO_IPV6 /* IPv6 protocol */ #undef NET_PROTO_FCOE /* Fibre Channel over Ethernet protocol */ #define NET_PROTO_STP /* Spanning Tree protocol */ -#define NET_PROTO_LACP /* Link Aggregation control protocol */ /* * PXE support @@ -58,7 +57,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #undef DOWNLOAD_PROTO_FTP /* File Transfer Protocol */ #undef DOWNLOAD_PROTO_SLAM /* Scalable Local Area Multicast */ #undef DOWNLOAD_PROTO_NFS /* Network File System Protocol */ -//#undef DOWNLOAD_PROTO_FILE /* Local filesystem access */ /* * SAN boot protocols @@ -122,7 +120,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #define CONFIG_CMD /* Option configuration console */ #define IFMGMT_CMD /* Interface management commands */ #define IWMGMT_CMD /* Wireless interface management commands */ -#define IBMGMT_CMD /* Infiniband management commands */ #define FCMGMT_CMD /* Fibre Channel management commands */ #define ROUTE_CMD /* Routing table management commands */ #define IMAGE_CMD /* Image management commands */ @@ -147,7 +144,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); //#define CONSOLE_CMD /* Console command */ //#define IPSTAT_CMD /* IP statistics commands */ //#define PROFSTAT_CMD /* Profiling commands */ -//#define NTP_CMD /* NTP commands */ /* * ROM-specific options @@ -157,13 +153,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #define AUTOBOOT_ROM_FILTER /* Autoboot only devices matching our ROM */ /* - * Virtual network devices - * - */ -#define VNIC_IPOIB /* Infiniband IPoIB virtual NICs */ -//#define VNIC_XSIGO /* Infiniband Xsigo virtual NICs */ - -/* * Error message tables to include * */ diff --git a/roms/ipxe/src/config/usb.h b/roms/ipxe/src/config/usb.h index d2519d877..52e82eaad 100644 --- a/roms/ipxe/src/config/usb.h +++ b/roms/ipxe/src/config/usb.h @@ -15,22 +15,15 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); * USB host controllers (all enabled by default) * */ -//#undef USB_HCD_XHCI /* xHCI USB host controller */ -//#undef USB_HCD_EHCI /* EHCI USB host controller */ -//#undef USB_HCD_UHCI /* UHCI USB host controller */ -//#define USB_HCD_USBIO /* Very slow EFI USB host controller */ +//#undef USB_HCD_XHCI /* xHCI USB host controller */ +//#undef USB_HCD_EHCI /* EHCI USB host controller */ +//#undef USB_HCD_UHCI /* UHCI USB host controller */ /* * USB peripherals * */ -//#undef USB_KEYBOARD /* USB keyboards */ - -/* - * USB external interfaces - * - */ -//#undef USB_EFI /* Provide EFI_USB_IO_PROTOCOL interface */ +//#undef USB_KEYBOARD /* USB keyboards */ #include <config/named.h> #include NAMED_CONFIG(usb.h) diff --git a/roms/ipxe/src/core/debug.c b/roms/ipxe/src/core/debug.c index 9b2a823f5..def5d8b09 100644 --- a/roms/ipxe/src/core/debug.c +++ b/roms/ipxe/src/core/debug.c @@ -194,12 +194,8 @@ static int dbg_autocolour ( unsigned long stream ) { * @v stream Message stream ID */ void dbg_autocolourise ( unsigned long stream ) { - - if ( DBGCOL_MIN ) { - dbg_printf ( "\033[%dm", - ( stream ? - ( DBGCOL_MIN + dbg_autocolour ( stream ) ) : 0)); - } + dbg_printf ( "\033[%dm", + ( stream ? ( DBGCOL_MIN + dbg_autocolour ( stream ) ) :0)); } /** @@ -207,7 +203,5 @@ void dbg_autocolourise ( unsigned long stream ) { * */ void dbg_decolourise ( void ) { - - if ( DBGCOL_MIN ) - dbg_printf ( "\033[0m" ); + dbg_printf ( "\033[0m" ); } diff --git a/roms/ipxe/src/core/downloader.c b/roms/ipxe/src/core/downloader.c index ba678f868..d745f3617 100644 --- a/roms/ipxe/src/core/downloader.c +++ b/roms/ipxe/src/core/downloader.c @@ -136,9 +136,9 @@ static int downloader_progress ( struct downloader *downloader, * @v meta Data transfer metadata * @ret rc Return status code */ -static int downloader_deliver ( struct downloader *downloader, - struct io_buffer *iobuf, - struct xfer_metadata *meta ) { +static int downloader_xfer_deliver ( struct downloader *downloader, + struct io_buffer *iobuf, + struct xfer_metadata *meta ) { int rc; /* Add data to buffer */ @@ -160,51 +160,16 @@ static int downloader_deliver ( struct downloader *downloader, * @ret xferbuf Data transfer buffer, or NULL on error */ static struct xfer_buffer * -downloader_buffer ( struct downloader *downloader ) { +downloader_xfer_buffer ( struct downloader *downloader ) { /* Provide direct access to underlying data transfer buffer */ return &downloader->buffer; } -/** - * Redirect data transfer interface - * - * @v downloader Downloader - * @v type New location type - * @v args Remaining arguments depend upon location type - * @ret rc Return status code - */ -static int downloader_vredirect ( struct downloader *downloader, int type, - va_list args ) { - va_list tmp; - struct uri *uri; - int rc; - - /* Intercept redirects to a LOCATION_URI and update the image URI */ - if ( type == LOCATION_URI ) { - - /* Extract URI argument */ - va_copy ( tmp, args ); - uri = va_arg ( tmp, struct uri * ); - va_end ( tmp ); - - /* Set image URI */ - if ( ( rc = image_set_uri ( downloader->image, uri ) ) != 0 ) - return rc; - } - - /* Redirect to new location */ - if ( ( rc = xfer_vreopen ( &downloader->xfer, type, args ) ) != 0 ) - return rc; - - return 0; -} - /** Downloader data transfer interface operations */ static struct interface_operation downloader_xfer_operations[] = { - INTF_OP ( xfer_deliver, struct downloader *, downloader_deliver ), - INTF_OP ( xfer_buffer, struct downloader *, downloader_buffer ), - INTF_OP ( xfer_vredirect, struct downloader *, downloader_vredirect ), + INTF_OP ( xfer_deliver, struct downloader *, downloader_xfer_deliver ), + INTF_OP ( xfer_buffer, struct downloader *, downloader_xfer_buffer ), INTF_OP ( intf_close, struct downloader *, downloader_finished ), }; diff --git a/roms/ipxe/src/core/exec.c b/roms/ipxe/src/core/exec.c index a13884b68..2c2ade0a5 100644 --- a/roms/ipxe/src/core/exec.c +++ b/roms/ipxe/src/core/exec.c @@ -36,6 +36,10 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <ipxe/command.h> #include <ipxe/parseopt.h> #include <ipxe/settings.h> +#include <ipxe/console.h> +#include <ipxe/keys.h> +#include <ipxe/process.h> +#include <ipxe/nap.h> #include <ipxe/shell.h> /** @file @@ -569,6 +573,8 @@ static struct command_descriptor sleep_cmd = static int sleep_exec ( int argc, char **argv ) { struct sleep_options opts; unsigned int seconds; + unsigned long start; + unsigned long delay; int rc; /* Parse options */ @@ -580,8 +586,14 @@ static int sleep_exec ( int argc, char **argv ) { return rc; /* Delay for specified number of seconds */ - if ( sleep ( seconds ) != 0 ) - return -ECANCELED; + start = currticks(); + delay = ( seconds * TICKS_PER_SEC ); + while ( ( currticks() - start ) <= delay ) { + step(); + if ( iskey() && ( getchar() == CTRL_C ) ) + return -ECANCELED; + cpu_nap(); + } return 0; } diff --git a/roms/ipxe/src/core/fbcon.c b/roms/ipxe/src/core/fbcon.c index 44a56e105..6d8b0086d 100644 --- a/roms/ipxe/src/core/fbcon.c +++ b/roms/ipxe/src/core/fbcon.c @@ -156,7 +156,7 @@ static void fbcon_store ( struct fbcon *fbcon, struct fbcon_text_cell *cell, */ static void fbcon_draw ( struct fbcon *fbcon, struct fbcon_text_cell *cell, unsigned int xpos, unsigned int ypos ) { - uint8_t glyph[fbcon->font->height]; + struct fbcon_font_glyph glyph; size_t offset; size_t pixel_len; size_t skip_len; @@ -167,7 +167,9 @@ static void fbcon_draw ( struct fbcon *fbcon, struct fbcon_text_cell *cell, void *src; /* Get font character */ - fbcon->font->glyph ( cell->character, glyph ); + copy_from_user ( &glyph, fbcon->font->start, + ( cell->character * sizeof ( glyph ) ), + sizeof ( glyph ) ); /* Calculate pixel geometry */ offset = ( fbcon->indent + @@ -180,7 +182,7 @@ static void fbcon_draw ( struct fbcon *fbcon, struct fbcon_text_cell *cell, transparent = ( cell->background == FBCON_TRANSPARENT ); /* Draw character rows */ - for ( row = 0 ; row < fbcon->font->height ; row++ ) { + for ( row = 0 ; row < FBCON_CHAR_HEIGHT ; row++ ) { /* Draw background picture, if applicable */ if ( transparent ) { @@ -195,7 +197,7 @@ static void fbcon_draw ( struct fbcon *fbcon, struct fbcon_text_cell *cell, } /* Draw character row */ - for ( column = FBCON_CHAR_WIDTH, bitmask = glyph[row] ; + for ( column = FBCON_CHAR_WIDTH, bitmask = glyph.bitmask[row] ; column ; column--, bitmask <<= 1, offset += pixel_len ) { if ( bitmask & 0x80 ) { src = &cell->foreground; @@ -575,24 +577,22 @@ static int fbcon_picture_init ( struct fbcon *fbcon, * @v fbcon Frame buffer console * @v start Start address * @v pixel Pixel geometry + * @v margin Minimum margin * @v map Colour mapping * @v font Font definition - * @v config Console configuration + * @v pixbuf Background picture (if any) * @ret rc Return status code */ int fbcon_init ( struct fbcon *fbcon, userptr_t start, struct fbcon_geometry *pixel, + struct fbcon_margin *margin, struct fbcon_colour_map *map, struct fbcon_font *font, - struct console_configuration *config ) { + struct pixel_buffer *pixbuf ) { int width; int height; unsigned int xgap; unsigned int ygap; - unsigned int left; - unsigned int right; - unsigned int top; - unsigned int bottom; int rc; /* Initialise data structure */ @@ -611,51 +611,31 @@ int fbcon_init ( struct fbcon *fbcon, userptr_t start, user_to_phys ( fbcon->start, 0 ), user_to_phys ( fbcon->start, fbcon->len ) ); - /* Calculate margin. If the actual screen size is larger than - * the requested screen size, then update the margins so that - * the margin remains relative to the requested screen size. - * (As an exception, if a zero margin was specified then treat - * this as meaning "expand to edge of actual screen".) - */ - xgap = ( pixel->width - config->width ); - ygap = ( pixel->height - config->height ); - left = ( xgap / 2 ); - right = ( xgap - left ); - top = ( ygap / 2 ); - bottom = ( ygap - top ); - fbcon->margin.left = ( config->left + ( config->left ? left : 0 ) ); - fbcon->margin.right = ( config->right + ( config->right ? right : 0 ) ); - fbcon->margin.top = ( config->top + ( config->top ? top : 0 ) ); - fbcon->margin.bottom = - ( config->bottom + ( config->bottom ? bottom : 0 ) ); - /* Expand margin to accommodate whole characters */ - width = ( pixel->width - fbcon->margin.left - fbcon->margin.right ); - height = ( pixel->height - fbcon->margin.top - fbcon->margin.bottom ); - if ( ( width < FBCON_CHAR_WIDTH ) || - ( height < ( ( int ) font->height ) ) ) { + width = ( pixel->width - margin->left - margin->right ); + height = ( pixel->height - margin->top - margin->bottom ); + if ( ( width < FBCON_CHAR_WIDTH ) || ( height < FBCON_CHAR_HEIGHT ) ) { DBGC ( fbcon, "FBCON %p has unusable character area " - "[%d-%d),[%d-%d)\n", fbcon, fbcon->margin.left, - ( pixel->width - fbcon->margin.right ), - fbcon->margin.top, - ( pixel->height - fbcon->margin.bottom ) ); + "[%d-%d),[%d-%d)\n", fbcon, + margin->left, ( pixel->width - margin->right ), + margin->top, ( pixel->height - margin->bottom ) ); rc = -EINVAL; goto err_margin; } xgap = ( width % FBCON_CHAR_WIDTH ); - ygap = ( height % font->height ); - fbcon->margin.left += ( xgap / 2 ); - fbcon->margin.top += ( ygap / 2 ); - fbcon->margin.right += ( xgap - ( xgap / 2 ) ); - fbcon->margin.bottom += ( ygap - ( ygap / 2 ) ); + ygap = ( height % FBCON_CHAR_HEIGHT ); + fbcon->margin.left = ( margin->left + ( xgap / 2 ) ); + fbcon->margin.top = ( margin->top + ( ygap / 2 ) ); + fbcon->margin.right = ( margin->right + ( xgap - ( xgap / 2 ) ) ); + fbcon->margin.bottom = ( margin->bottom + ( ygap - ( ygap / 2 ) ) ); fbcon->indent = ( ( fbcon->margin.top * pixel->stride ) + ( fbcon->margin.left * pixel->len ) ); /* Derive character geometry from pixel geometry */ fbcon->character.width = ( width / FBCON_CHAR_WIDTH ); - fbcon->character.height = ( height / font->height ); + fbcon->character.height = ( height / FBCON_CHAR_HEIGHT ); fbcon->character.len = ( pixel->len * FBCON_CHAR_WIDTH ); - fbcon->character.stride = ( pixel->stride * font->height ); + fbcon->character.stride = ( pixel->stride * FBCON_CHAR_HEIGHT ); DBGC ( fbcon, "FBCON %p is pixel %dx%d, char %dx%d at " "[%d-%d),[%d-%d)\n", fbcon, fbcon->pixel->width, fbcon->pixel->height, fbcon->character.width, @@ -682,8 +662,7 @@ int fbcon_init ( struct fbcon *fbcon, userptr_t start, memset_user ( fbcon->start, 0, 0, fbcon->len ); /* Generate pixel buffer from background image, if applicable */ - if ( config->pixbuf && - ( ( rc = fbcon_picture_init ( fbcon, config->pixbuf ) ) != 0 ) ) + if ( pixbuf && ( ( rc = fbcon_picture_init ( fbcon, pixbuf ) ) != 0 ) ) goto err_picture; /* Draw background picture (including margins), if applicable */ diff --git a/roms/ipxe/src/core/gdbstub.c b/roms/ipxe/src/core/gdbstub.c index 8b57ddf56..6ad52d1a6 100644 --- a/roms/ipxe/src/core/gdbstub.c +++ b/roms/ipxe/src/core/gdbstub.c @@ -40,7 +40,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); enum { POSIX_EINVAL = 0x1c, /* used to report bad arguments to GDB */ - SIZEOF_PAYLOAD = 512, /* buffer size of GDB payload data */ + SIZEOF_PAYLOAD = 256, /* buffer size of GDB payload data */ }; struct gdbstub { @@ -255,20 +255,17 @@ static void gdbstub_continue ( struct gdbstub *stub, int single_step ) { static void gdbstub_breakpoint ( struct gdbstub *stub ) { unsigned long args [ 3 ]; int enable = stub->payload [ 0 ] == 'Z' ? 1 : 0; - int rc; - if ( !gdbstub_get_packet_args ( stub, args, sizeof args / sizeof args [ 0 ], NULL ) ) { gdbstub_send_errno ( stub, POSIX_EINVAL ); return; } - if ( ( rc = gdbmach_set_breakpoint ( args [ 0 ], args [ 1 ], - args [ 2 ], enable ) ) != 0 ) { + if ( gdbmach_set_breakpoint ( args [ 0 ], args [ 1 ], args [ 2 ], enable ) ) { + gdbstub_send_ok ( stub ); + } else { /* Not supported */ stub->len = 0; gdbstub_tx_packet ( stub ); - return; } - gdbstub_send_ok ( stub ); } static void gdbstub_rx_packet ( struct gdbstub *stub ) { diff --git a/roms/ipxe/src/core/getkey.c b/roms/ipxe/src/core/getkey.c index 0c280d23b..0f0f8b7c3 100644 --- a/roms/ipxe/src/core/getkey.c +++ b/roms/ipxe/src/core/getkey.c @@ -76,14 +76,9 @@ int getkey ( unsigned long timeout ) { if ( character != ESC ) return character; - character = getchar_timeout ( GETKEY_TIMEOUT ); - if ( character < 0 ) - return ESC; - - if ( isalpha ( character ) ) - return ( toupper ( character ) - 'A' + 1 ); - while ( ( character = getchar_timeout ( GETKEY_TIMEOUT ) ) >= 0 ) { + if ( character == '[' ) + continue; if ( isdigit ( character ) ) { n = ( ( n * 10 ) + ( character - '0' ) ); continue; diff --git a/roms/ipxe/src/core/image.c b/roms/ipxe/src/core/image.c index a185b82f4..529e3d72c 100644 --- a/roms/ipxe/src/core/image.c +++ b/roms/ipxe/src/core/image.c @@ -88,6 +88,7 @@ static void free_image ( struct refcnt *refcnt ) { * @ret image Executable image */ struct image * alloc_image ( struct uri *uri ) { + const char *name; struct image *image; int rc; @@ -98,43 +99,24 @@ struct image * alloc_image ( struct uri *uri ) { /* Initialise image */ ref_init ( &image->refcnt, free_image ); - if ( uri && ( ( rc = image_set_uri ( image, uri ) ) != 0 ) ) - goto err_set_uri; + if ( uri ) { + image->uri = uri_get ( uri ); + if ( uri->path ) { + name = basename ( ( char * ) uri->path ); + if ( ( rc = image_set_name ( image, name ) ) != 0 ) + goto err_set_name; + } + } return image; - err_set_uri: + err_set_name: image_put ( image ); err_alloc: return NULL; } /** - * Set image URI - * - * @v image Image - * @v uri New image URI - * @ret rc Return status code - */ -int image_set_uri ( struct image *image, struct uri *uri ) { - const char *name; - int rc; - - /* Set name, if image does not already have one */ - if ( uri->path && ( ! ( image->name && image->name[0] ) ) ) { - name = basename ( ( char * ) uri->path ); - if ( ( rc = image_set_name ( image, name ) ) != 0 ) - return rc; - } - - /* Update image URI */ - uri_put ( image->uri ); - image->uri = uri_get ( uri ); - - return 0; -} - -/** * Set image name * * @v image Image @@ -191,7 +173,7 @@ static int image_probe ( struct image *image ) { image->type = type; DBGC ( image, "IMAGE %s is %s\n", image->name, type->name ); - return 0; + break; } DBGC ( image, "IMAGE %s is not %s: %s\n", image->name, type->name, strerror ( rc ) ); diff --git a/roms/ipxe/src/core/iobuf.c b/roms/ipxe/src/core/iobuf.c index 0ee53e038..3e52ada4f 100644 --- a/roms/ipxe/src/core/iobuf.c +++ b/roms/ipxe/src/core/iobuf.c @@ -47,45 +47,20 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); */ struct io_buffer * alloc_iob_raw ( size_t len, size_t align, size_t offset ) { struct io_buffer *iobuf; - size_t padding; - size_t threshold; - unsigned int align_log2; void *data; - /* Calculate padding required below alignment boundary to - * ensure that a correctly aligned inline struct io_buffer - * could fit (regardless of the requested offset). - */ - padding = ( sizeof ( *iobuf ) + __alignof__ ( *iobuf ) - 1 ); + /* Align buffer length to ensure that struct io_buffer is aligned */ + len = ( len + __alignof__ ( *iobuf ) - 1 ) & + ~( __alignof__ ( *iobuf ) - 1 ); - /* Round up requested alignment to at least the size of the - * padding, to simplify subsequent calculations. - */ - if ( align < padding ) - align = padding; + /* Round up alignment to the nearest power of two */ + align = ( 1 << fls ( align - 1 ) ); - /* Round up alignment to the nearest power of two, avoiding - * a potentially undefined shift operation. + /* Allocate buffer plus descriptor as a single unit, unless + * doing so will push the total size over the alignment + * boundary. */ - align_log2 = fls ( align - 1 ); - if ( align_log2 >= ( 8 * sizeof ( align ) ) ) - return NULL; - align = ( 1UL << align_log2 ); - - /* Calculate length threshold */ - assert ( align >= padding ); - threshold = ( align - padding ); - - /* Allocate buffer plus an inline descriptor as a single unit, - * unless doing so would push the total size over the - * alignment boundary. - */ - if ( len <= threshold ) { - - /* Round up buffer length to ensure that struct - * io_buffer is aligned. - */ - len += ( ( - len - offset ) & ( __alignof__ ( *iobuf ) - 1 ) ); + if ( ( len + sizeof ( *iobuf ) ) <= align ) { /* Allocate memory for buffer plus descriptor */ data = malloc_dma_offset ( len + sizeof ( *iobuf ), align, diff --git a/roms/ipxe/src/core/iomap_virt.c b/roms/ipxe/src/core/iomap_virt.c deleted file mode 100644 index c7f487274..000000000 --- a/roms/ipxe/src/core/iomap_virt.c +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2016 Michael Brown <mbrown@fensystems.co.uk>. - * - * 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 (at your option) 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 ); - -/** @file - * - * iPXE I/O mapping API using phys_to_virt() - * - */ - -#include <ipxe/iomap.h> - -PROVIDE_IOMAP_INLINE ( virt, ioremap ); -PROVIDE_IOMAP_INLINE ( virt, iounmap ); -PROVIDE_IOMAP_INLINE ( virt, io_to_bus ); diff --git a/roms/ipxe/src/core/malloc.c b/roms/ipxe/src/core/malloc.c index 32c203532..b120c0325 100644 --- a/roms/ipxe/src/core/malloc.c +++ b/roms/ipxe/src/core/malloc.c @@ -275,7 +275,7 @@ void * alloc_memblock ( size_t size, size_t align, size_t offset ) { size_t align_mask; size_t actual_size; size_t pre_size; - size_t post_size; + ssize_t post_size; struct memory_block *pre; struct memory_block *post; void *ptr; @@ -291,16 +291,6 @@ void * alloc_memblock ( size_t size, size_t align, size_t offset ) { */ actual_size = ( ( size + MIN_MEMBLOCK_SIZE - 1 ) & ~( MIN_MEMBLOCK_SIZE - 1 ) ); - if ( ! actual_size ) { - /* The requested size is not permitted to be zero. A - * zero result at this point indicates that either the - * original requested size was zero, or that unsigned - * integer overflow has occurred. - */ - ptr = NULL; - goto done; - } - assert ( actual_size >= size ); align_mask = ( ( align - 1 ) | ( MIN_MEMBLOCK_SIZE - 1 ) ); DBGC2 ( &heap, "Allocating %#zx (aligned %#zx+%zx)\n", @@ -310,55 +300,55 @@ void * alloc_memblock ( size_t size, size_t align, size_t offset ) { list_for_each_entry ( block, &free_blocks, list ) { pre_size = ( ( offset - virt_to_phys ( block ) ) & align_mask ); - if ( ( block->size < pre_size ) || - ( ( block->size - pre_size ) < actual_size ) ) - continue; post_size = ( block->size - pre_size - actual_size ); - /* Split block into pre-block, block, and - * post-block. After this split, the "pre" - * block is the one currently linked into the - * free list. - */ - pre = block; - block = ( ( ( void * ) pre ) + pre_size ); - post = ( ( ( void * ) block ) + actual_size ); - DBGC2 ( &heap, "[%p,%p) -> [%p,%p) + [%p,%p)\n", pre, - ( ( ( void * ) pre ) + pre->size ), pre, block, - post, ( ( ( void * ) pre ) + pre->size ) ); - /* If there is a "post" block, add it in to - * the free list. Leak it if it is too small - * (which can happen only at the very end of - * the heap). - */ - if ( post_size >= MIN_MEMBLOCK_SIZE ) { - VALGRIND_MAKE_MEM_UNDEFINED ( post, - sizeof ( *post )); - post->size = post_size; - list_add ( &post->list, &pre->list ); - } - /* Shrink "pre" block, leaving the main block - * isolated and no longer part of the free - * list. - */ - pre->size = pre_size; - /* If there is no "pre" block, remove it from - * the list. Also remove it (i.e. leak it) if - * it is too small, which can happen only at - * the very start of the heap. - */ - if ( pre_size < MIN_MEMBLOCK_SIZE ) { - list_del ( &pre->list ); - VALGRIND_MAKE_MEM_NOACCESS ( pre, - sizeof ( *pre ) ); + if ( post_size >= 0 ) { + /* Split block into pre-block, block, and + * post-block. After this split, the "pre" + * block is the one currently linked into the + * free list. + */ + pre = block; + block = ( ( ( void * ) pre ) + pre_size ); + post = ( ( ( void * ) block ) + actual_size ); + DBGC2 ( &heap, "[%p,%p) -> [%p,%p) + [%p,%p)\n", + pre, ( ( ( void * ) pre ) + pre->size ), + pre, block, post, + ( ( ( void * ) pre ) + pre->size ) ); + /* If there is a "post" block, add it in to + * the free list. Leak it if it is too small + * (which can happen only at the very end of + * the heap). + */ + if ( (size_t) post_size >= MIN_MEMBLOCK_SIZE ) { + VALGRIND_MAKE_MEM_UNDEFINED + ( post, sizeof ( *post ) ); + post->size = post_size; + list_add ( &post->list, &pre->list ); + } + /* Shrink "pre" block, leaving the main block + * isolated and no longer part of the free + * list. + */ + pre->size = pre_size; + /* If there is no "pre" block, remove it from + * the list. Also remove it (i.e. leak it) if + * it is too small, which can happen only at + * the very start of the heap. + */ + if ( pre_size < MIN_MEMBLOCK_SIZE ) { + list_del ( &pre->list ); + VALGRIND_MAKE_MEM_NOACCESS + ( pre, sizeof ( *pre ) ); + } + /* Update total free memory */ + freemem -= actual_size; + /* Return allocated block */ + DBGC2 ( &heap, "Allocated [%p,%p)\n", block, + ( ( ( void * ) block ) + size ) ); + ptr = block; + VALGRIND_MAKE_MEM_UNDEFINED ( ptr, size ); + goto done; } - /* Update total free memory */ - freemem -= actual_size; - /* Return allocated block */ - DBGC2 ( &heap, "Allocated [%p,%p)\n", block, - ( ( ( void * ) block ) + size ) ); - ptr = block; - VALGRIND_MAKE_MEM_UNDEFINED ( ptr, size ); - goto done; } /* Try discarding some cached data to free up memory */ @@ -515,8 +505,6 @@ void * realloc ( void *old_ptr, size_t new_size ) { if ( new_size ) { new_total_size = ( new_size + offsetof ( struct autosized_block, data ) ); - if ( new_total_size < new_size ) - return NULL; new_block = alloc_memblock ( new_total_size, 1, 0 ); if ( ! new_block ) return NULL; diff --git a/roms/ipxe/src/core/memblock.c b/roms/ipxe/src/core/memblock.c new file mode 100644 index 000000000..aecddc22c --- /dev/null +++ b/roms/ipxe/src/core/memblock.c @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>. + * + * 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 (at your option) 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 ); + +/** @file + * + * Largest memory block + * + */ + +#include <stdint.h> +#include <ipxe/uaccess.h> +#include <ipxe/io.h> +#include <ipxe/memblock.h> + +/** + * Find largest usable memory region + * + * @ret start Start of region + * @ret len Length of region + */ +size_t largest_memblock ( userptr_t *start ) { + struct memory_map memmap; + struct memory_region *region; + physaddr_t max = ~( ( physaddr_t ) 0 ); + physaddr_t region_start; + physaddr_t region_end; + size_t region_len; + unsigned int i; + size_t len = 0; + + /* Avoid returning uninitialised data on error */ + *start = UNULL; + + /* Scan through all memory regions */ + get_memmap ( &memmap ); + for ( i = 0 ; i < memmap.count ; i++ ) { + region = &memmap.regions[i]; + DBG ( "Considering [%llx,%llx)\n", region->start, region->end ); + + /* Truncate block to maximum physical address */ + if ( region->start > max ) { + DBG ( "...starts after maximum address %lx\n", max ); + continue; + } + region_start = region->start; + if ( region->end > max ) { + DBG ( "...end truncated to maximum address %lx\n", max); + region_end = 0; /* =max, given the wraparound */ + } else { + region_end = region->end; + } + region_len = ( region_end - region_start ); + + /* Use largest block */ + if ( region_len > len ) { + DBG ( "...new best block found\n" ); + *start = phys_to_user ( region_start ); + len = region_len; + } + } + + return len; +} diff --git a/roms/ipxe/src/core/memmap_settings.c b/roms/ipxe/src/core/memmap_settings.c index 1098bd756..fab3e5f3a 100644 --- a/roms/ipxe/src/core/memmap_settings.c +++ b/roms/ipxe/src/core/memmap_settings.c @@ -145,7 +145,7 @@ static int memmap_settings_fetch ( struct settings *settings, unsigned int i; unsigned int count; - DBGC ( settings, "MEMMAP start %ld count %ld %s%s%s%s scale %ld\n", + DBGC ( settings, "MEMMAP start %d count %d %s%s%s%s scale %d\n", MEMMAP_START ( setting->tag ), MEMMAP_COUNT ( setting->tag ), ( MEMMAP_INCLUDE_START ( setting->tag ) ? "start" : "" ), ( ( MEMMAP_INCLUDE_START ( setting->tag ) && diff --git a/roms/ipxe/src/core/pixbuf.c b/roms/ipxe/src/core/pixbuf.c index c12bd3c06..41e18f8dc 100644 --- a/roms/ipxe/src/core/pixbuf.c +++ b/roms/ipxe/src/core/pixbuf.c @@ -65,10 +65,6 @@ struct pixel_buffer * alloc_pixbuf ( unsigned int width, unsigned int height ) { pixbuf->height = height; pixbuf->len = ( width * height * sizeof ( uint32_t ) ); - /* Check for multiplication overflow */ - if ( ( ( pixbuf->len / sizeof ( uint32_t ) ) / width ) != height ) - goto err_overflow; - /* Allocate pixel data buffer */ pixbuf->data = umalloc ( pixbuf->len ); if ( ! pixbuf->data ) @@ -77,7 +73,6 @@ struct pixel_buffer * alloc_pixbuf ( unsigned int width, unsigned int height ) { return pixbuf; err_alloc_data: - err_overflow: pixbuf_put ( pixbuf ); err_alloc_pixbuf: return NULL; diff --git a/roms/ipxe/src/core/random.c b/roms/ipxe/src/core/random.c index 975a03cf5..a74175a79 100644 --- a/roms/ipxe/src/core/random.c +++ b/roms/ipxe/src/core/random.c @@ -18,8 +18,6 @@ static int32_t rnd_seed = 0; */ void srandom ( unsigned int seed ) { rnd_seed = seed; - if ( ! rnd_seed ) - rnd_seed = 4; /* Chosen by fair dice roll */ } /** diff --git a/roms/ipxe/src/core/serial.c b/roms/ipxe/src/core/serial.c index dd22f6731..4ce025519 100644 --- a/roms/ipxe/src/core/serial.c +++ b/roms/ipxe/src/core/serial.c @@ -30,7 +30,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); */ #include <stddef.h> -#include <string.h> #include <ipxe/init.h> #include <ipxe/uart.h> #include <ipxe/console.h> diff --git a/roms/ipxe/src/core/settings.c b/roms/ipxe/src/core/settings.c index 9cae0cae3..12e6c7d61 100644 --- a/roms/ipxe/src/core/settings.c +++ b/roms/ipxe/src/core/settings.c @@ -1474,9 +1474,9 @@ struct setting * find_setting ( const char *name ) { * @v name Name * @ret tag Tag number, or 0 if not a valid number */ -static unsigned long parse_setting_tag ( const char *name ) { +static unsigned int parse_setting_tag ( const char *name ) { char *tmp = ( ( char * ) name ); - unsigned long tag = 0; + unsigned int tag = 0; while ( 1 ) { tag = ( ( tag << 8 ) | strtoul ( tmp, &tmp, 0 ) ); @@ -1666,43 +1666,15 @@ const struct setting_type setting_type_string __setting_type = { .format = format_string_setting, }; -/** - * Parse URI-encoded string setting value +/** A URI-encoded string setting type * - * @v type Setting type - * @v value Formatted setting value - * @v buf Buffer to contain raw value - * @v len Length of buffer - * @ret len Length of raw value, or negative error - */ -static int parse_uristring_setting ( const struct setting_type *type __unused, - const char *value, void *buf, size_t len ){ - - return uri_decode ( value, buf, len ); -} - -/** - * Format URI-encoded string setting value - * - * @v type Setting type - * @v raw Raw setting value - * @v raw_len Length of raw setting value - * @v buf Buffer to contain formatted value - * @v len Length of buffer - * @ret len Length of formatted value, or negative error + * This setting type is obsolete; the name ":uristring" is retained to + * avoid breaking existing scripts. */ -static int format_uristring_setting ( const struct setting_type *type __unused, - const void *raw, size_t raw_len, - char *buf, size_t len ) { - - return uri_encode ( 0, raw, raw_len, buf, len ); -} - -/** A URI-encoded string setting type */ const struct setting_type setting_type_uristring __setting_type = { .name = "uristring", - .parse = parse_uristring_setting, - .format = format_uristring_setting, + .parse = parse_string_setting, + .format = format_string_setting, }; /** @@ -2232,10 +2204,6 @@ static int format_busdevfn_setting ( const struct setting_type *type __unused, const void *raw, size_t raw_len, char *buf, size_t len ) { unsigned long busdevfn; - unsigned int seg; - unsigned int bus; - unsigned int slot; - unsigned int func; int check_len; /* Extract numeric value */ @@ -2244,14 +2212,9 @@ static int format_busdevfn_setting ( const struct setting_type *type __unused, return check_len; assert ( check_len == ( int ) raw_len ); - /* Extract PCI address components */ - seg = PCI_SEG ( busdevfn ); - bus = PCI_BUS ( busdevfn ); - slot = PCI_SLOT ( busdevfn ); - func = PCI_FUNC ( busdevfn ); - /* Format value */ - return snprintf ( buf, len, "%04x:%02x:%02x.%x", seg, bus, slot, func ); + return snprintf ( buf, len, "%02lx:%02lx.%lx", PCI_BUS ( busdevfn ), + PCI_SLOT ( busdevfn ), PCI_FUNC ( busdevfn ) ); } /** PCI bus:dev.fn setting type */ diff --git a/roms/ipxe/src/core/string.c b/roms/ipxe/src/core/string.c index 5a185e635..3e658e54e 100644 --- a/roms/ipxe/src/core/string.c +++ b/roms/ipxe/src/core/string.c @@ -81,7 +81,7 @@ void * generic_memmove ( void *dest, const void *src, size_t len ) { uint8_t *dest_bytes = ( dest + len ); if ( dest < src ) - return generic_memcpy ( dest, src, len ); + return memcpy ( dest, src, len ); while ( len-- ) *(--dest_bytes) = *(--src_bytes); return dest; diff --git a/roms/ipxe/src/core/time.c b/roms/ipxe/src/core/time.c index c353ac5bd..29a924ebe 100644 --- a/roms/ipxe/src/core/time.c +++ b/roms/ipxe/src/core/time.c @@ -43,9 +43,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); * 400. */ -/** Current system clock offset */ -signed long time_offset; - /** Days of week (for debugging) */ static const char *weekdays[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" diff --git a/roms/ipxe/src/core/timer.c b/roms/ipxe/src/core/timer.c index ca945cfba..dbd89f12b 100644 --- a/roms/ipxe/src/core/timer.c +++ b/roms/ipxe/src/core/timer.c @@ -24,10 +24,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <unistd.h> -#include <ipxe/process.h> -#include <ipxe/console.h> -#include <ipxe/keys.h> -#include <ipxe/nap.h> /** * Delay for a fixed number of milliseconds @@ -40,24 +36,12 @@ void mdelay ( unsigned long msecs ) { } /** - * Sleep (interruptibly) for a fixed number of seconds + * Delay for a fixed number of seconds * * @v secs Number of seconds for which to delay - * @ret secs Number of seconds remaining, if interrupted */ unsigned int sleep ( unsigned int secs ) { - unsigned long start = currticks(); - unsigned long now; - - for ( ; secs ; secs-- ) { - while ( ( ( now = currticks() ) - start ) < TICKS_PER_SEC ) { - step(); - if ( iskey() && ( getchar() == CTRL_C ) ) - return secs; - cpu_nap(); - } - start = now; - } - + while ( secs-- ) + mdelay ( 1000 ); return 0; } diff --git a/roms/ipxe/src/core/uri.c b/roms/ipxe/src/core/uri.c index 73ad2b227..3b5f270fe 100644 --- a/roms/ipxe/src/core/uri.c +++ b/roms/ipxe/src/core/uri.c @@ -36,23 +36,18 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <ctype.h> #include <ipxe/vsprintf.h> #include <ipxe/params.h> -#include <ipxe/tcpip.h> #include <ipxe/uri.h> /** - * Decode URI field + * Decode URI field (in place) * - * @v encoded Encoded field - * @v buf Data buffer - * @v len Length - * @ret len Length of data + * @v string String * * URI decoding can never increase the length of a string; we can * therefore safely decode in place. */ -size_t uri_decode ( const char *encoded, void *buf, size_t len ) { - uint8_t *out = buf; - unsigned int count = 0; +static void uri_decode ( char *string ) { + char *dest = string; char hexbuf[3]; char *hexbuf_end; char c; @@ -60,42 +55,18 @@ size_t uri_decode ( const char *encoded, void *buf, size_t len ) { unsigned int skip; /* Copy string, decoding escaped characters as necessary */ - while ( ( c = *(encoded++) ) ) { + do { + c = *(string++); if ( c == '%' ) { - snprintf ( hexbuf, sizeof ( hexbuf ), "%s", encoded ); + snprintf ( hexbuf, sizeof ( hexbuf ), "%s", string ); decoded = strtoul ( hexbuf, &hexbuf_end, 16 ); skip = ( hexbuf_end - hexbuf ); - encoded += skip; + string += skip; if ( skip ) c = decoded; } - if ( count < len ) - out[count] = c; - count++; - } - return count; -} - -/** - * Decode URI field in-place - * - * @v uri URI - * @v field URI field index - */ -static void uri_decode_inplace ( struct uri *uri, unsigned int field ) { - const char *encoded = uri_field ( uri, field ); - char *decoded = ( ( char * ) encoded ); - size_t len; - - /* Do nothing if field is not present */ - if ( ! encoded ) - return; - - /* Decode field in place */ - len = uri_decode ( encoded, decoded, strlen ( encoded ) ); - - /* Terminate decoded string */ - decoded[len] = '\0'; + *(dest++) = c; + } while ( c ); } /** @@ -144,20 +115,15 @@ static int uri_character_escaped ( char c, unsigned int field ) { * '%', the full set of characters with significance to the * URL parser is "/#:@?". We choose for each URI field which * of these require escaping in our use cases. - * - * For the scheme field (equivalently, if field is zero), we - * escape anything that has significance not just for our URI - * parser but for any other URI parsers (e.g. HTTP query - * string parsers, which care about '=' and '&'). */ static const char *escaped[URI_FIELDS] = { - /* Scheme or default: escape everything */ - [URI_SCHEME] = "/#:@?=&", + /* Scheme: escape everything */ + [URI_SCHEME] = "/#:@?", /* Opaque part: escape characters which would affect * the reparsing of the URI, allowing everything else * (e.g. ':', which will appear in iSCSI URIs). */ - [URI_OPAQUE] = "#", + [URI_OPAQUE] = "/#", /* User name: escape everything */ [URI_USER] = "/#:@?", /* Password: escape everything */ @@ -191,16 +157,14 @@ static int uri_character_escaped ( char c, unsigned int field ) { /** * Encode URI field * + * @v uri URI * @v field URI field index - * @v raw Raw data - * @v raw_len Length of raw data - * @v buf Buffer + * @v buf Buffer to contain encoded string * @v len Length of buffer * @ret len Length of encoded string (excluding NUL) */ -size_t uri_encode ( unsigned int field, const void *raw, size_t raw_len, +size_t uri_encode ( const char *string, unsigned int field, char *buf, ssize_t len ) { - const uint8_t *raw_bytes = ( ( const uint8_t * ) raw ); ssize_t remaining = len; size_t used; char c; @@ -210,8 +174,7 @@ size_t uri_encode ( unsigned int field, const void *raw, size_t raw_len, buf[0] = '\0'; /* Copy string, escaping as necessary */ - while ( raw_len-- ) { - c = *(raw_bytes++); + while ( ( c = *(string++) ) ) { if ( uri_character_escaped ( c, field ) ) { used = ssnprintf ( buf, remaining, "%%%02X", c ); } else { @@ -225,21 +188,6 @@ size_t uri_encode ( unsigned int field, const void *raw, size_t raw_len, } /** - * Encode URI field string - * - * @v field URI field index - * @v string String - * @v buf Buffer - * @v len Length of buffer - * @ret len Length of encoded string (excluding NUL) - */ -size_t uri_encode_string ( unsigned int field, const char *string, - char *buf, ssize_t len ) { - - return uri_encode ( field, string, strlen ( string ), buf, len ); -} - -/** * Dump URI for debugging * * @v uri URI @@ -368,7 +316,7 @@ struct uri * parse_uri ( const char *uri_string ) { goto done; /* Identify net/absolute/relative path */ - if ( uri->scheme && ( strncmp ( path, "//", 2 ) == 0 ) ) { + if ( strncmp ( path, "//", 2 ) == 0 ) { /* Net path. If this is terminated by the first '/' * of an absolute path, then we have no space for a * terminator after the authority field, so shuffle @@ -419,11 +367,13 @@ struct uri * parse_uri ( const char *uri_string ) { uri->port = tmp; } - done: /* Decode fields in-place */ - for ( field = 0 ; field < URI_FIELDS ; field++ ) - uri_decode_inplace ( uri, field ); + for ( field = 0 ; field < URI_FIELDS ; field++ ) { + if ( uri_field ( uri, field ) ) + uri_decode ( ( char * ) uri_field ( uri, field ) ); + } + done: DBGC ( uri, "URI parsed \"%s\" to", uri_string ); uri_dump ( uri ); DBGC ( uri, "\n" ); @@ -456,8 +406,10 @@ unsigned int uri_port ( const struct uri *uri, unsigned int default_port ) { */ size_t format_uri ( const struct uri *uri, char *buf, size_t len ) { static const char prefixes[URI_FIELDS] = { + [URI_OPAQUE] = ':', [URI_PASSWORD] = ':', [URI_PORT] = ':', + [URI_PATH] = '/', [URI_QUERY] = '?', [URI_FRAGMENT] = '#', }; @@ -484,19 +436,21 @@ size_t format_uri ( const struct uri *uri, char *buf, size_t len ) { prefix = prefixes[field]; if ( ( field == URI_HOST ) && ( uri->user != NULL ) ) prefix = '@'; + if ( ( field == URI_PATH ) && ( uri->path[0] == '/' ) ) + prefix = '\0'; if ( prefix ) { used += ssnprintf ( ( buf + used ), ( len - used ), "%c", prefix ); } /* Encode this field */ - used += uri_encode_string ( field, uri_field ( uri, field ), - ( buf + used ), ( len - used ) ); + used += uri_encode ( uri_field ( uri, field ), field, + ( buf + used ), ( len - used ) ); /* Suffix this field, if applicable */ - if ( field == URI_SCHEME ) { + if ( ( field == URI_SCHEME ) && ( ! uri->opaque ) ) { used += ssnprintf ( ( buf + used ), ( len - used ), - ":%s", ( uri->host ? "//" : "" ) ); + "://" ); } } @@ -602,7 +556,7 @@ struct uri * uri_dup ( const struct uri *uri ) { * * @v base_uri Base path * @v relative_uri Relative path - * @ret resolved_uri Resolved path, or NULL on failure + * @ret resolved_uri Resolved path * * Takes a base path (e.g. "/var/lib/tftpboot/vmlinuz" and a relative * path (e.g. "initrd.gz") and produces a new path @@ -613,8 +567,9 @@ struct uri * uri_dup ( const struct uri *uri ) { */ char * resolve_path ( const char *base_path, const char *relative_path ) { - char *base_copy; - char *base_tmp; + size_t base_len = ( strlen ( base_path ) + 1 ); + char base_path_copy[base_len]; + char *base_tmp = base_path_copy; char *resolved; /* If relative path is absolute, just re-use it */ @@ -622,12 +577,8 @@ char * resolve_path ( const char *base_path, return strdup ( relative_path ); /* Create modifiable copy of path for dirname() */ - base_copy = strdup ( base_path ); - if ( ! base_copy ) - return NULL; - - /* Strip filename portion of base path */ - base_tmp = dirname ( base_copy ); + memcpy ( base_tmp, base_path, base_len ); + base_tmp = dirname ( base_tmp ); /* Process "./" and "../" elements */ while ( *relative_path == '.' ) { @@ -657,8 +608,8 @@ char * resolve_path ( const char *base_path, if ( asprintf ( &resolved, "%s%s%s", base_tmp, ( ( base_tmp[ strlen ( base_tmp ) - 1 ] == '/' ) ? "" : "/" ), relative_path ) < 0 ) - resolved = NULL; - free ( base_copy ); + return NULL; + return resolved; } @@ -667,7 +618,7 @@ char * resolve_path ( const char *base_path, * * @v base_uri Base URI, or NULL * @v relative_uri Relative URI - * @ret resolved_uri Resolved URI, or NULL on failure + * @ret resolved_uri Resolved URI * * Takes a base URI (e.g. "http://ipxe.org/kernels/vmlinuz" and a * relative URI (e.g. "../initrds/initrd.gz") and produces a new URI @@ -711,83 +662,30 @@ struct uri * resolve_uri ( const struct uri *base_uri, } /** - * Construct TFTP URI from server address and filename - * - * @v sa_server Server address - * @v filename Filename - * @ret uri URI, or NULL on failure - */ -static struct uri * tftp_uri ( struct sockaddr *sa_server, - const char *filename ) { - struct sockaddr_tcpip *st_server = - ( ( struct sockaddr_tcpip * ) sa_server ); - char buf[ 6 /* "65535" + NUL */ ]; - char *path; - struct uri tmp; - struct uri *uri = NULL; - - /* Initialise TFTP URI */ - memset ( &tmp, 0, sizeof ( tmp ) ); - tmp.scheme = "tftp"; - - /* Construct TFTP server address */ - tmp.host = sock_ntoa ( sa_server ); - if ( ! tmp.host ) - goto err_host; - - /* Construct TFTP server port, if applicable */ - if ( st_server->st_port ) { - snprintf ( buf, sizeof ( buf ), "%d", - ntohs ( st_server->st_port ) ); - tmp.port = buf; - } - - /* Construct TFTP path */ - if ( asprintf ( &path, "/%s", filename ) < 0 ) - goto err_path; - tmp.path = path; - - /* Demangle URI */ - uri = uri_dup ( &tmp ); - if ( ! uri ) - goto err_uri; - - err_uri: - free ( path ); - err_path: - err_host: - return uri; -} - -/** - * Construct URI from server address and filename + * Construct TFTP URI from next-server and filename * - * @v sa_server Server address + * @v next_server Next-server address + * @v port Port number, or zero to use the default port * @v filename Filename * @ret uri URI, or NULL on failure * - * PXE TFTP filenames specified via the DHCP next-server field often + * TFTP filenames specified via the DHCP next-server field often * contain characters such as ':' or '#' which would confuse the * generic URI parser. We provide a mechanism for directly * constructing a TFTP URI from the next-server and filename. */ -struct uri * pxe_uri ( struct sockaddr *sa_server, const char *filename ) { - struct uri *uri; - - /* Fail if filename is empty */ - if ( ! ( filename && filename[0] ) ) - return NULL; - - /* If filename is a hierarchical absolute URI, then use that - * URI. (We accept only hierarchical absolute URIs, since PXE - * filenames sometimes start with DOS drive letters such as - * "C:\", which get misinterpreted as opaque absolute URIs.) - */ - uri = parse_uri ( filename ); - if ( uri && uri_is_absolute ( uri ) && ( ! uri->opaque ) ) - return uri; - uri_put ( uri ); - - /* Otherwise, construct a TFTP URI directly */ - return tftp_uri ( sa_server, filename ); +struct uri * tftp_uri ( struct in_addr next_server, unsigned int port, + const char *filename ) { + char buf[ 6 /* "65535" + NUL */ ]; + struct uri uri; + + memset ( &uri, 0, sizeof ( uri ) ); + uri.scheme = "tftp"; + uri.host = inet_ntoa ( next_server ); + if ( port ) { + snprintf ( buf, sizeof ( buf ), "%d", port ); + uri.port = buf; + } + uri.path = filename; + return uri_dup ( &uri ); } diff --git a/roms/ipxe/src/core/vsprintf.c b/roms/ipxe/src/core/vsprintf.c index 9d3a97c2d..cb3bec5dd 100644 --- a/roms/ipxe/src/core/vsprintf.c +++ b/roms/ipxe/src/core/vsprintf.c @@ -257,13 +257,11 @@ size_t vcprintf ( struct printf_context *ctx, const char *fmt, va_list args ) { } else if ( *fmt == 's' ) { if ( length < &type_sizes[LONG_LEN] ) { ptr = va_arg ( args, char * ); - if ( ! ptr ) - ptr = "<NULL>"; } else { wptr = va_arg ( args, wchar_t * ); - if ( ! wptr ) - ptr = "<NULL>"; } + if ( ( ptr == NULL ) && ( wptr == NULL ) ) + ptr = "<NULL>"; } else if ( *fmt == 'p' ) { intptr_t ptrval; diff --git a/roms/ipxe/src/crypto/asn1.c b/roms/ipxe/src/crypto/asn1.c index 9c71ffe10..aca12bf30 100644 --- a/roms/ipxe/src/crypto/asn1.c +++ b/roms/ipxe/src/crypto/asn1.c @@ -82,6 +82,18 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); __einfo_uniqify ( EINFO_ENOTTY, 0x01, "Inappropriate algorithm" ) /** + * Invalidate ASN.1 object cursor + * + * @v cursor ASN.1 object cursor + */ +void asn1_invalidate_cursor ( struct asn1_cursor *cursor ) { + static uint8_t asn1_invalid_object[] = { ASN1_END, 0 }; + + cursor->data = asn1_invalid_object; + cursor->len = 0; +} + +/** * Start parsing ASN.1 object * * @v cursor ASN.1 object cursor diff --git a/roms/ipxe/src/crypto/certstore.c b/roms/ipxe/src/crypto/certstore.c index e62d8330b..503ce499e 100644 --- a/roms/ipxe/src/crypto/certstore.c +++ b/roms/ipxe/src/crypto/certstore.c @@ -45,7 +45,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #define CERT( _index, _path ) \ extern char stored_cert_ ## _index ## _data[]; \ extern char stored_cert_ ## _index ## _len[]; \ - __asm__ ( ".section \".rodata\", \"a\", " PROGBITS "\n\t" \ + __asm__ ( ".section \".rodata\", \"a\", @progbits\n\t" \ "\nstored_cert_" #_index "_data:\n\t" \ ".incbin \"" _path "\"\n\t" \ "\nstored_cert_" #_index "_end:\n\t" \ diff --git a/roms/ipxe/src/crypto/drbg.c b/roms/ipxe/src/crypto/drbg.c index a3366e806..5c8b5e612 100644 --- a/roms/ipxe/src/crypto/drbg.c +++ b/roms/ipxe/src/crypto/drbg.c @@ -19,18 +19,6 @@ * 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. - * - * Alternatively, you may distribute this code in source or binary - * form, with or without modification, provided that the following - * conditions are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the above disclaimer. - * - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the above - * disclaimer in the documentation and/or other materials provided - * with the distribution. */ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); diff --git a/roms/ipxe/src/crypto/hash_df.c b/roms/ipxe/src/crypto/hash_df.c index dc0dc0ce8..c1417e683 100644 --- a/roms/ipxe/src/crypto/hash_df.c +++ b/roms/ipxe/src/crypto/hash_df.c @@ -19,18 +19,6 @@ * 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. - * - * Alternatively, you may distribute this code in source or binary - * form, with or without modification, provided that the following - * conditions are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the above disclaimer. - * - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the above - * disclaimer in the documentation and/or other materials provided - * with the distribution. */ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); diff --git a/roms/ipxe/src/crypto/hmac.c b/roms/ipxe/src/crypto/hmac.c index f898619c8..95a46195c 100644 --- a/roms/ipxe/src/crypto/hmac.c +++ b/roms/ipxe/src/crypto/hmac.c @@ -19,18 +19,6 @@ * 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. - * - * Alternatively, you may distribute this code in source or binary - * form, with or without modification, provided that the following - * conditions are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the above disclaimer. - * - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the above - * disclaimer in the documentation and/or other materials provided - * with the distribution. */ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); diff --git a/roms/ipxe/src/crypto/hmac_drbg.c b/roms/ipxe/src/crypto/hmac_drbg.c index 098297716..6c1d5deb2 100644 --- a/roms/ipxe/src/crypto/hmac_drbg.c +++ b/roms/ipxe/src/crypto/hmac_drbg.c @@ -19,18 +19,6 @@ * 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. - * - * Alternatively, you may distribute this code in source or binary - * form, with or without modification, provided that the following - * conditions are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the above disclaimer. - * - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the above - * disclaimer in the documentation and/or other materials provided - * with the distribution. */ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); diff --git a/roms/ipxe/src/crypto/ocsp.c b/roms/ipxe/src/crypto/ocsp.c index e7adcdba9..5df55bc96 100644 --- a/roms/ipxe/src/crypto/ocsp.c +++ b/roms/ipxe/src/crypto/ocsp.c @@ -209,10 +209,10 @@ static int ocsp_request ( struct ocsp_check *ocsp ) { static int ocsp_uri_string ( struct ocsp_check *ocsp ) { struct x509_ocsp_responder *responder = &ocsp->cert->extensions.auth_info.ocsp; - char *base64; - char *sep; - size_t base64_len; - size_t uri_len; + struct uri path_uri; + char *path_base64_string; + char *path_uri_string; + size_t path_len; size_t len; int rc; @@ -224,44 +224,46 @@ static int ocsp_uri_string ( struct ocsp_check *ocsp ) { goto err_no_uri; } - /* Calculate base64-encoded request length */ - base64_len = ( base64_encoded_len ( ocsp->request.builder.len ) - + 1 /* NUL */ ); - - /* Allocate and construct the base64-encoded request */ - base64 = malloc ( base64_len ); - if ( ! base64 ) { + /* Base64-encode the request as the URI path */ + path_len = ( base64_encoded_len ( ocsp->request.builder.len ) + + 1 /* NUL */ ); + path_base64_string = malloc ( path_len ); + if ( ! path_base64_string ) { rc = -ENOMEM; - goto err_alloc_base64; + goto err_path_base64; } base64_encode ( ocsp->request.builder.data, ocsp->request.builder.len, - base64, base64_len ); + path_base64_string, path_len ); - /* Calculate URI-encoded base64-encoded request length */ - uri_len = ( uri_encode ( URI_PATH, base64, ( base64_len - 1 /* NUL */ ), - NULL, 0 ) + 1 /* NUL */ ); + /* URI-encode the Base64-encoded request */ + memset ( &path_uri, 0, sizeof ( path_uri ) ); + path_uri.path = path_base64_string; + path_uri_string = format_uri_alloc ( &path_uri ); + if ( ! path_uri_string ) { + rc = -ENOMEM; + goto err_path_uri; + } - /* Allocate and construct the URI string */ - len = ( responder->uri.len + 1 /* possible "/" */ + uri_len ); + /* Construct URI string */ + len = ( responder->uri.len + strlen ( path_uri_string ) + 1 /* NUL */ ); ocsp->uri_string = zalloc ( len ); if ( ! ocsp->uri_string ) { rc = -ENOMEM; - goto err_alloc_uri; + goto err_ocsp_uri; } memcpy ( ocsp->uri_string, responder->uri.data, responder->uri.len ); - sep = &ocsp->uri_string[ responder->uri.len - 1 ]; - if ( *sep != '/' ) - *(++sep) = '/'; - uri_encode ( URI_PATH, base64, base64_len, ( sep + 1 ), uri_len ); + strcpy ( &ocsp->uri_string[responder->uri.len], path_uri_string ); DBGC2 ( ocsp, "OCSP %p \"%s\" URI is %s\n", ocsp, x509_name ( ocsp->cert ), ocsp->uri_string ); /* Success */ rc = 0; - err_alloc_uri: - free ( base64 ); - err_alloc_base64: + err_ocsp_uri: + free ( path_uri_string ); + err_path_uri: + free ( path_base64_string ); + err_path_base64: err_no_uri: return rc; } diff --git a/roms/ipxe/src/crypto/privkey.c b/roms/ipxe/src/crypto/privkey.c index 7ef04880f..a6043bd1e 100644 --- a/roms/ipxe/src/crypto/privkey.c +++ b/roms/ipxe/src/crypto/privkey.c @@ -54,7 +54,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); /* Raw private key data */ extern char private_key_data[]; extern char private_key_len[]; -__asm__ ( ".section \".rodata\", \"a\", " PROGBITS "\n\t" +__asm__ ( ".section \".rodata\", \"a\", @progbits\n\t" "\nprivate_key_data:\n\t" #ifdef PRIVATE_KEY ".incbin \"" PRIVATE_KEY "\"\n\t" @@ -69,12 +69,6 @@ struct asn1_cursor private_key = { .len = ( ( size_t ) private_key_len ), }; -/** Default private key */ -static struct asn1_cursor default_private_key = { - .data = private_key_data, - .len = ( ( size_t ) private_key_len ), -}; - /** Private key setting */ static struct setting privkey_setting __setting ( SETTING_CRYPTO, privkey ) = { .name = "privkey", @@ -98,8 +92,8 @@ static int privkey_apply_settings ( void ) { if ( ALLOW_KEY_OVERRIDE ) { /* Restore default private key */ - memcpy ( &private_key, &default_private_key, - sizeof ( private_key ) ); + private_key.data = private_key_data; + private_key.len = ( ( size_t ) private_key_len ); /* Fetch new private key, if any */ free ( key_data ); diff --git a/roms/ipxe/src/crypto/rbg.c b/roms/ipxe/src/crypto/rbg.c index a5a77e3cd..943b288c3 100644 --- a/roms/ipxe/src/crypto/rbg.c +++ b/roms/ipxe/src/crypto/rbg.c @@ -19,18 +19,6 @@ * 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. - * - * Alternatively, you may distribute this code in source or binary - * form, with or without modification, provided that the following - * conditions are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the above disclaimer. - * - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the above - * disclaimer in the documentation and/or other materials provided - * with the distribution. */ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); diff --git a/roms/ipxe/src/crypto/rootcert.c b/roms/ipxe/src/crypto/rootcert.c index f7b9dcfb7..00ea1647e 100644 --- a/roms/ipxe/src/crypto/rootcert.c +++ b/roms/ipxe/src/crypto/rootcert.c @@ -93,14 +93,13 @@ struct x509_root root_certificates = { * a rebuild. */ static void rootcert_init ( void ) { - static int initialised; void *external = NULL; int len; /* Allow trusted root certificates to be overridden only if * not explicitly specified at build time. */ - if ( ALLOW_TRUST_OVERRIDE && ( ! initialised ) ) { + if ( ALLOW_TRUST_OVERRIDE ) { /* Fetch copy of "trust" setting, if it exists. This * memory will never be freed. @@ -110,9 +109,6 @@ static void rootcert_init ( void ) { root_certificates.fingerprints = external; root_certificates.count = ( len / FINGERPRINT_LEN ); } - - /* Prevent subsequent modifications */ - initialised = 1; } DBGC ( &root_certificates, "ROOTCERT using %d %s certificate(s):\n", @@ -122,6 +118,6 @@ static void rootcert_init ( void ) { } /** Root certificate initialiser */ -struct startup_fn rootcert_startup_fn __startup_fn ( STARTUP_LATE ) = { - .startup = rootcert_init, +struct init_fn rootcert_init_fn __init_fn ( INIT_LATE ) = { + .initialise = rootcert_init, }; diff --git a/roms/ipxe/src/drivers/block/ibft.c b/roms/ipxe/src/drivers/block/ibft.c index 91a808d85..6aabd766a 100644 --- a/roms/ipxe/src/drivers/block/ibft.c +++ b/roms/ipxe/src/drivers/block/ibft.c @@ -260,7 +260,6 @@ static int ibft_fill_nic ( struct ibft_nic *nic, ibft_set_ipaddr_setting ( NULL, &nic->dns[0], &dns_setting, ( sizeof ( nic->dns ) / sizeof ( nic->dns[0] ) ) ); - ibft_set_ipaddr_setting ( parent, &nic->dhcp, &dhcp_server_setting, 1 ); DBG ( "iBFT NIC DNS = %s", ibft_ipaddr ( &nic->dns[0] ) ); DBG ( ", %s\n", ibft_ipaddr ( &nic->dns[1] ) ); if ( ( rc = ibft_set_string_setting ( NULL, strings, &nic->hostname, diff --git a/roms/ipxe/src/drivers/bus/pci.c b/roms/ipxe/src/drivers/bus/pci.c index 06b36a770..6fbedd940 100644 --- a/roms/ipxe/src/drivers/bus/pci.c +++ b/roms/ipxe/src/drivers/bus/pci.c @@ -175,7 +175,7 @@ void adjust_pci_device ( struct pci_device *pci ) { * @ret rc Return status code */ int pci_read_config ( struct pci_device *pci ) { - uint32_t busdevfn; + uint16_t busdevfn; uint8_t hdrtype; uint32_t tmp; @@ -203,8 +203,8 @@ int pci_read_config ( struct pci_device *pci ) { pci_read_bases ( pci ); /* Initialise generic device component */ - snprintf ( pci->dev.name, sizeof ( pci->dev.name ), "%04x:%02x:%02x.%x", - PCI_SEG ( pci->busdevfn ), PCI_BUS ( pci->busdevfn ), + snprintf ( pci->dev.name, sizeof ( pci->dev.name ), + "PCI%02x:%02x.%x", PCI_BUS ( pci->busdevfn ), PCI_SLOT ( pci->busdevfn ), PCI_FUNC ( pci->busdevfn ) ); pci->dev.desc.bus_type = BUS_TYPE_PCI; pci->dev.desc.location = pci->busdevfn; @@ -232,7 +232,7 @@ int pci_find_next ( struct pci_device *pci, unsigned int busdevfn ) { /* Determine number of PCI buses */ if ( ! end ) - end = PCI_BUSDEVFN ( 0, pci_num_bus(), 0, 0 ); + end = PCI_BUSDEVFN ( pci_num_bus(), 0, 0 ); /* Find next PCI device, if any */ for ( ; busdevfn < end ; busdevfn++ ) { diff --git a/roms/ipxe/src/drivers/bus/pci_settings.c b/roms/ipxe/src/drivers/bus/pci_settings.c index 98005559d..1cb9fa5a3 100644 --- a/roms/ipxe/src/drivers/bus/pci_settings.c +++ b/roms/ipxe/src/drivers/bus/pci_settings.c @@ -70,7 +70,7 @@ static int pci_settings_fetch ( struct settings *settings __unused, unsigned int i; /* Extract busdevfn, offset, and length from tag */ - tag_busdevfn = ( setting->tag >> 16 ); + tag_busdevfn = ( ( setting->tag >> 16 ) & 0xffff ); tag_offset = ( ( setting->tag >> 8 ) & 0xff ); tag_len = ( ( setting->tag >> 0 ) & 0xff ); diff --git a/roms/ipxe/src/drivers/bus/pciea.c b/roms/ipxe/src/drivers/bus/pciea.c deleted file mode 100644 index aaa69cf4c..000000000 --- a/roms/ipxe/src/drivers/bus/pciea.c +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (C) 2016 Michael Brown <mbrown@fensystems.co.uk>. - * - * 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 (at your option) 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 <stdint.h> -#include <errno.h> -#include <ipxe/pci.h> -#include <ipxe/pciea.h> - -/** @file - * - * PCI Enhanced Allocation - * - */ - -/** - * Locate PCI Enhanced Allocation BAR equivalent entry - * - * @v pci PCI device - * @v bei BAR equivalent indicator - * @ret offset PCI Enhanced Allocation entry offset, or negative error - */ -static int pciea_offset ( struct pci_device *pci, unsigned int bei ) { - uint8_t entries; - uint32_t desc; - unsigned int i; - int offset; - - /* Locate Enhanced Allocation capability */ - offset = pci_find_capability ( pci, PCI_CAP_ID_EA ); - if ( offset < 0 ) - return offset; - - /* Get number of entries */ - pci_read_config_byte ( pci, ( offset + PCIEA_ENTRIES ), &entries ); - entries &= PCIEA_ENTRIES_MASK; - - /* Locate first entry */ - offset += PCIEA_FIRST; - - /* Search for a matching entry */ - for ( i = 0 ; i < entries ; i++ ) { - - /* Read entry descriptor */ - pci_read_config_dword ( pci, offset, &desc ); - - /* Check for a matching entry */ - if ( ( desc & PCIEA_DESC_ENABLED ) && - ( bei == PCIEA_DESC_BEI ( desc ) ) ) - return offset; - - /* Move to next entry */ - offset += ( ( PCIEA_DESC_SIZE ( desc ) + 1 ) << 2 ); - } - - return -ENOENT; -} - -/** - * Read PCI Enhanced Allocation BAR equivalent value - * - * @v pci PCI device - * @v bei BAR equivalent indicator - * @v low_offset Offset to low dword of value - * @ret value BAR equivalent value - */ -static unsigned long pciea_bar_value ( struct pci_device *pci, unsigned int bei, - unsigned int low_offset ) { - uint32_t low; - uint32_t high; - int offset; - - /* Locate Enhanced Allocation offset for this BEI */ - offset = pciea_offset ( pci, bei ); - if ( offset < 0 ) - return 0; - - /* Read BAR equivalent */ - offset += low_offset; - pci_read_config_dword ( pci, offset, &low ); - if ( low & PCIEA_LOW_ATTR_64BIT ) { - offset += PCIEA_LOW_HIGH; - pci_read_config_dword ( pci, offset, &high ); - if ( high ) { - if ( sizeof ( unsigned long ) > sizeof ( uint32_t ) ) { - return ( ( ( uint64_t ) high << 32 ) | low ); - } else { - DBGC ( pci, PCI_FMT " unhandled 64-bit EA BAR " - "%08x%08x\n", - PCI_ARGS ( pci ), high, low ); - return 0; - } - } - } - return low; -} - -/** - * Find the start of a PCI Enhanced Allocation BAR equivalent - * - * @v pci PCI device - * @v bei BAR equivalent indicator - * @ret start BAR start address - * - * If the address exceeds the size of an unsigned long (i.e. if a - * 64-bit BAR has a non-zero high dword on a 32-bit machine), the - * return value will be zero. - */ -unsigned long pciea_bar_start ( struct pci_device *pci, unsigned int bei ) { - unsigned long base; - - base = pciea_bar_value ( pci, bei, PCIEA_LOW_BASE ); - return ( base & ~PCIEA_LOW_ATTR_MASK ); -} - -/** - * Find the size of a PCI Enhanced Allocation BAR equivalent - * - * @v pci PCI device - * @v bei BAR equivalent indicator - * @ret size BAR size - */ -unsigned long pciea_bar_size ( struct pci_device *pci, unsigned int bei ) { - unsigned long limit; - - limit = pciea_bar_value ( pci, bei, PCIEA_LOW_LIMIT ); - return ( limit ? ( ( limit | PCIEA_LOW_ATTR_MASK ) + 1 ) : 0 ); -} diff --git a/roms/ipxe/src/drivers/bus/pciextra.c b/roms/ipxe/src/drivers/bus/pciextra.c index 3082d8a3d..82287fb86 100644 --- a/roms/ipxe/src/drivers/bus/pciextra.c +++ b/roms/ipxe/src/drivers/bus/pciextra.c @@ -3,24 +3,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <stdint.h> #include <ipxe/pci.h> -static int pci_find_capability_common ( struct pci_device *pci, - uint8_t pos, int cap ) { - uint8_t id; - int ttl = 48; - - while ( ttl-- && pos >= 0x40 ) { - pos &= ~3; - pci_read_config_byte ( pci, pos + PCI_CAP_ID, &id ); - DBG ( "PCI Capability: %d\n", id ); - if ( id == 0xff ) - break; - if ( id == cap ) - return pos; - pci_read_config_byte ( pci, pos + PCI_CAP_NEXT, &pos ); - } - return 0; -} - /** * Look for a PCI capability * @@ -35,8 +17,9 @@ static int pci_find_capability_common ( struct pci_device *pci, */ int pci_find_capability ( struct pci_device *pci, int cap ) { uint16_t status; - uint8_t pos; + uint8_t pos, id; uint8_t hdr_type; + int ttl = 48; pci_read_config_word ( pci, PCI_STATUS, &status ); if ( ! ( status & PCI_STATUS_CAP_LIST ) ) @@ -53,28 +36,17 @@ int pci_find_capability ( struct pci_device *pci, int cap ) { pci_read_config_byte ( pci, PCI_CB_CAPABILITY_LIST, &pos ); break; } - return pci_find_capability_common ( pci, pos, cap ); -} - -/** - * Look for another PCI capability - * - * @v pci PCI device to query - * @v pos Address of the current capability - * @v cap Capability code - * @ret address Address of capability, or 0 if not found - * - * Determine whether or not a device supports a given PCI capability - * starting the search at a given address within the device's PCI - * configuration space. Returns the address of the next capability - * structure within the device's PCI configuration space, or 0 if the - * device does not support another such capability. - */ -int pci_find_next_capability ( struct pci_device *pci, int pos, int cap ) { - uint8_t new_pos; - - pci_read_config_byte ( pci, pos + PCI_CAP_NEXT, &new_pos ); - return pci_find_capability_common ( pci, new_pos, cap ); + while ( ttl-- && pos >= 0x40 ) { + pos &= ~3; + pci_read_config_byte ( pci, pos + PCI_CAP_ID, &id ); + DBG ( "PCI Capability: %d\n", id ); + if ( id == 0xff ) + break; + if ( id == cap ) + return pos; + pci_read_config_byte ( pci, pos + PCI_CAP_NEXT, &pos ); + } + return 0; } /** diff --git a/roms/ipxe/src/drivers/bus/usb.c b/roms/ipxe/src/drivers/bus/usb.c index 880e3f08c..2019e3341 100644 --- a/roms/ipxe/src/drivers/bus/usb.c +++ b/roms/ipxe/src/drivers/bus/usb.c @@ -243,6 +243,7 @@ int usb_endpoint_described ( struct usb_endpoint *ep, struct usb_interface_descriptor *interface, unsigned int type, unsigned int index ) { struct usb_device *usb = ep->usb; + struct usb_port *port = usb->port; struct usb_endpoint_descriptor *desc; struct usb_endpoint_companion_descriptor *descx; unsigned int sizes; @@ -266,7 +267,7 @@ int usb_endpoint_described ( struct usb_endpoint *ep, /* Calculate interval */ if ( ( type & USB_ENDPOINT_ATTR_TYPE_MASK ) == USB_ENDPOINT_ATTR_INTERRUPT ) { - if ( usb->speed >= USB_SPEED_HIGH ) { + if ( port->speed >= USB_SPEED_HIGH ) { /* 2^(desc->interval-1) is a microframe count */ interval = ( 1 << ( desc->interval - 1 ) ); } else { @@ -484,7 +485,7 @@ int usb_message ( struct usb_endpoint *ep, unsigned int request, assert ( iob_headroom ( iobuf ) >= sizeof ( *packet ) ); /* Fail immediately if device has been unplugged */ - if ( port->disconnected ) + if ( port->speed == USB_SPEED_NONE ) return -ENODEV; /* Reset endpoint if required */ @@ -529,11 +530,10 @@ int usb_stream ( struct usb_endpoint *ep, struct io_buffer *iobuf, int terminate ) { struct usb_device *usb = ep->usb; struct usb_port *port = usb->port; - int zlp; int rc; /* Fail immediately if device has been unplugged */ - if ( port->disconnected ) + if ( port->speed == USB_SPEED_NONE ) return -ENODEV; /* Reset endpoint if required */ @@ -541,13 +541,8 @@ int usb_stream ( struct usb_endpoint *ep, struct io_buffer *iobuf, ( ( rc = usb_endpoint_reset ( ep ) ) != 0 ) ) return rc; - /* Append a zero-length packet if necessary */ - zlp = terminate; - if ( iob_len ( iobuf ) & ( ep->mtu - 1 ) ) - zlp = 0; - /* Enqueue stream transfer */ - if ( ( rc = ep->host->stream ( ep, iobuf, zlp ) ) != 0 ) { + if ( ( rc = ep->host->stream ( ep, iobuf, terminate ) ) != 0 ) { DBGC ( usb, "USB %s %s could not enqueue stream transfer: %s\n", usb->name, usb_endpoint_name ( ep ), strerror ( rc ) ); return rc; @@ -601,7 +596,6 @@ void usb_complete_err ( struct usb_endpoint *ep, struct io_buffer *iobuf, */ int usb_prefill ( struct usb_endpoint *ep ) { struct io_buffer *iobuf; - size_t reserve = ep->reserve; size_t len = ( ep->len ? ep->len : ep->mtu ); unsigned int fill; int rc; @@ -615,12 +609,11 @@ int usb_prefill ( struct usb_endpoint *ep ) { for ( fill = 0 ; fill < ep->max ; fill++ ) { /* Allocate I/O buffer */ - iobuf = alloc_iob ( reserve + len ); + iobuf = alloc_iob ( len ); if ( ! iobuf ) { rc = -ENOMEM; goto err_alloc; } - iob_reserve ( iobuf, reserve ); /* Add to recycled buffer list */ list_add_tail ( &iobuf->list, &ep->recycled ); @@ -641,7 +634,6 @@ int usb_prefill ( struct usb_endpoint *ep ) { */ int usb_refill ( struct usb_endpoint *ep ) { struct io_buffer *iobuf; - size_t reserve = ep->reserve; size_t len = ( ep->len ? ep->len : ep->mtu ); int rc; @@ -655,10 +647,9 @@ int usb_refill ( struct usb_endpoint *ep ) { /* Get or allocate buffer */ if ( list_empty ( &ep->recycled ) ) { /* Recycled buffer list is empty; allocate new buffer */ - iobuf = alloc_iob ( reserve + len ); + iobuf = alloc_iob ( len ); if ( ! iobuf ) return -ENOMEM; - iob_reserve ( iobuf, reserve ); } else { /* Get buffer from recycled buffer list */ iobuf = list_first_entry ( &ep->recycled, @@ -904,155 +895,75 @@ int usb_get_string_descriptor ( struct usb_device *usb, unsigned int index, */ /** - * Get USB configuration descriptor - * - * @v usb USB device - * @v index Configuration index - * @ret config Configuration descriptor - * @ret rc Return status code - * - * The configuration descriptor is dynamically allocated and must - * eventually be freed by the caller. - */ -static int -usb_config_descriptor ( struct usb_device *usb, unsigned int index, - struct usb_configuration_descriptor **config ) { - struct usb_configuration_descriptor partial; - size_t len; - int rc; - - /* Read first part of configuration descriptor to get size */ - if ( ( rc = usb_get_config_descriptor ( usb, index, &partial, - sizeof ( partial ) ) ) != 0 ) { - DBGC ( usb, "USB %s could not get configuration descriptor %d: " - "%s\n", usb->name, index, strerror ( rc ) ); - goto err_get_partial; - } - len = le16_to_cpu ( partial.len ); - if ( len < sizeof ( partial ) ) { - DBGC ( usb, "USB %s underlength configuraton descriptor %d\n", - usb->name, index ); - rc = -EINVAL; - goto err_partial_len; - } - - /* Allocate buffer for whole configuration descriptor */ - *config = malloc ( len ); - if ( ! *config ) { - rc = -ENOMEM; - goto err_alloc_config; - } - - /* Read whole configuration descriptor */ - if ( ( rc = usb_get_config_descriptor ( usb, index, *config, - len ) ) != 0 ) { - DBGC ( usb, "USB %s could not get configuration descriptor %d: " - "%s\n", usb->name, index, strerror ( rc ) ); - goto err_get_config_descriptor; - } - if ( (*config)->len != partial.len ) { - DBGC ( usb, "USB %s bad configuration descriptor %d length\n", - usb->name, index ); - rc = -EINVAL; - goto err_config_len; - } - - return 0; - - err_config_len: - err_get_config_descriptor: - free ( *config ); - err_alloc_config: - err_partial_len: - err_get_partial: - return rc; -} - -/** * Describe USB function * - * @v usb USB device + * @v func USB function * @v config Configuration descriptor * @v first First interface number - * @v interfaces Interface list to fill in - * @v desc Function descriptor to fill in * @ret rc Return status code */ -static int usb_describe ( struct usb_device *usb, +static int usb_function ( struct usb_function *func, struct usb_configuration_descriptor *config, - unsigned int first, uint8_t *interfaces, - struct usb_function_descriptor *desc ) { + unsigned int first ) { + struct usb_device *usb = func->usb; struct usb_interface_association_descriptor *association; struct usb_interface_descriptor *interface; struct cdc_union_descriptor *cdc_union; unsigned int i; - /* Fill in vendor and product ID */ - memset ( desc, 0, sizeof ( *desc ) ); - desc->vendor = le16_to_cpu ( usb->device.vendor ); - desc->product = le16_to_cpu ( usb->device.product ); - /* First, look for an interface association descriptor */ association = usb_interface_association_descriptor ( config, first ); if ( association ) { /* Sanity check */ - assert ( association->first == first ); - if ( ( first + association->count ) > config->interfaces ) { + if ( association->count > config->interfaces ) { DBGC ( usb, "USB %s has invalid association [%d-%d)\n", - usb->name, first, ( first + association->count)); + func->name, association->first, + ( association->first + association->count ) ); return -ERANGE; } /* Describe function */ - memcpy ( &desc->class, &association->class, - sizeof ( desc->class ) ); - desc->count = association->count; + memcpy ( &func->class, &association->class, + sizeof ( func->class ) ); + func->count = association->count; for ( i = 0 ; i < association->count ; i++ ) - interfaces[i] = ( first + i ); + func->interface[i] = ( association->first + i ); return 0; } /* Next, look for an interface descriptor */ interface = usb_interface_descriptor ( config, first, 0 ); if ( ! interface ) { - DBGC ( usb, "USB %s has no descriptor for interface %d\n", - usb->name, first ); + DBGC ( usb, "USB %s has no interface descriptor\n", + func->name ); return -ENOENT; } /* Describe function */ - memcpy ( &desc->class, &interface->class, sizeof ( desc->class ) ); - desc->count = 1; - interfaces[0] = first; + memcpy ( &func->class, &interface->class, sizeof ( func->class ) ); + func->count = 1; + func->interface[0] = first; /* Look for a CDC union descriptor, if applicable */ - if ( ( desc->class.class.class == USB_CLASS_CDC ) && + if ( ( func->class.class == USB_CLASS_CDC ) && ( cdc_union = cdc_union_descriptor ( config, interface ) ) ) { /* Determine interface count */ - desc->count = ( ( cdc_union->header.len - + func->count = ( ( cdc_union->header.len - offsetof ( typeof ( *cdc_union ), interface[0] ) ) / sizeof ( cdc_union->interface[0] ) ); - if ( desc->count > config->interfaces ) { + if ( func->count > config->interfaces ) { DBGC ( usb, "USB %s has invalid union functional " "descriptor with %d interfaces\n", - usb->name, desc->count ); + func->name, func->count ); return -ERANGE; } /* Describe function */ - for ( i = 0 ; i < desc->count ; i++ ) { - if ( cdc_union->interface[i] >= config->interfaces ) { - DBGC ( usb, "USB %s has invalid union " - "functional descriptor covering " - "interface %d\n", usb->name, - cdc_union->interface[i] ); - return -ERANGE; - } - interfaces[i] = cdc_union->interface[i]; - } + for ( i = 0 ; i < func->count ; i++ ) + func->interface[i] = cdc_union->interface[i]; return 0; } @@ -1061,108 +972,22 @@ static int usb_describe ( struct usb_device *usb, } /** - * Update list of used interface + * Check for a USB device ID match * - * @v usb USB device - * @v count Number of interfaces - * @v interface List of interfaces - * @v used List of already-used interfaces - * @ret rc Return status code - */ -static int usb_used ( struct usb_device *usb, unsigned int count, - uint8_t *interface, uint8_t *used ) { - unsigned int i; - - for ( i = 0 ; i < count ; i++ ) { - if ( used[interface[i]] ) { - DBGC ( usb, "USB %s interface %d already in use\n", - usb->name, interface[i] ); - return -EINVAL; - } - used[interface[i]] = 1; - } - return 0; -} - -/** - * Find USB device driver - * - * @v desc Function descriptor - * @ret id USB device ID, or NULL - * @ret driver USB device driver, or NULL - */ -struct usb_driver * usb_find_driver ( struct usb_function_descriptor *desc, - struct usb_device_id **id ) { - struct usb_driver *driver; - unsigned int i; - - /* Look for a matching driver */ - for_each_table_entry ( driver, USB_DRIVERS ) { - for ( i = 0 ; i < driver->id_count ; i++ ) { - - /* Ignore non-matching driver class */ - if ( ( driver->class.class.scalar ^ desc->class.scalar ) - & driver->class.mask.scalar ) - continue; - - /* Look for a matching ID */ - *id = &driver->ids[i]; - if ( ( ( (*id)->vendor == desc->vendor ) || - ( (*id)->vendor == USB_ANY_ID ) ) && - ( ( (*id)->product == desc->product ) || - ( (*id)->product == USB_ANY_ID ) ) ) - return driver; - } - } - - /* Not found */ - *id = NULL; - return NULL; -} - -/** - * Get USB device configuration score - * - * @v usb USB device - * @v config Configuration descriptor - * @ret score Device configuration score, or negative error + * @v func USB function + * @v id Device ID + * @ret matches Device ID matches */ -static int usb_score ( struct usb_device *usb, - struct usb_configuration_descriptor *config ) { - uint8_t used[config->interfaces]; - uint8_t interface[config->interfaces]; - struct usb_function_descriptor desc; - struct usb_driver *driver; - struct usb_device_id *id; - unsigned int first; - unsigned int score = 0; - int rc; - - /* Identify each function in turn */ - memset ( used, 0, sizeof ( used ) ); - for ( first = 0 ; first < config->interfaces ; first++ ) { - - /* Skip interfaces already used */ - if ( used[first] ) - continue; - - /* Describe function */ - if ( ( rc = usb_describe ( usb, config, first, interface, - &desc ) ) != 0 ) - return rc; - - /* Update used interfaces */ - if ( ( rc = usb_used ( usb, desc.count, interface, - used ) ) != 0 ) - return rc; - - /* Look for a driver for this function */ - driver = usb_find_driver ( &desc, &id ); - if ( driver ) - score += driver->score; - } - - return score; +static int +usb_device_id_matches ( struct usb_function *func, struct usb_device_id *id ) { + + return ( ( ( id->vendor == func->dev.desc.vendor ) || + ( id->vendor == USB_ANY_ID ) ) && + ( ( id->product == func->dev.desc.device ) || + ( id->product == USB_ANY_ID ) ) && + ( id->class.class == func->class.class ) && + ( id->class.subclass == func->class.subclass ) && + ( id->class.protocol == func->class.protocol ) ); } /** @@ -1177,32 +1002,39 @@ static int usb_probe ( struct usb_function *func, struct usb_device *usb = func->usb; struct usb_driver *driver; struct usb_device_id *id; + unsigned int i; int rc; - /* Identify driver */ - driver = usb_find_driver ( &func->desc, &id ); - if ( ! driver ) { - DBGC ( usb, "USB %s %04x:%04x class %d:%d:%d has no driver\n", - func->name, func->desc.vendor, func->desc.product, - func->desc.class.class.class, - func->desc.class.class.subclass, - func->desc.class.class.protocol ); - return -ENOENT; - } + /* Look for a matching driver */ + for_each_table_entry ( driver, USB_DRIVERS ) { + for ( i = 0 ; i < driver->id_count ; i++ ) { - /* Record driver */ - func->driver = driver; - func->id = id; - func->dev.driver_name = id->name; + /* Check for a matching ID */ + id = &driver->ids[i]; + if ( ! usb_device_id_matches ( func, id ) ) + continue; - /* Probe driver */ - if ( ( rc = driver->probe ( func, config ) ) != 0 ) { - DBGC ( usb, "USB %s failed to probe driver %s: %s\n", - func->name, id->name, strerror ( rc ) ); - return rc; + /* Probe driver */ + if ( ( rc = driver->probe ( func, config ) ) != 0 ) { + DBGC ( usb, "USB %s failed to probe driver %s: " + "%s\n", func->name, id->name, + strerror ( rc ) ); + /* Continue trying other drivers */ + continue; + } + + /* Record driver */ + func->driver = driver; + func->dev.driver_name = id->name; + return 0; + } } - return 0; + /* No driver found */ + DBGC ( usb, "USB %s %04x:%04x class %d:%d:%d has no driver\n", + func->name, func->dev.desc.vendor, func->dev.desc.device, + func->class.class, func->class.subclass, func->class.protocol ); + return -ENOENT; } /** @@ -1256,45 +1088,50 @@ usb_probe_all ( struct usb_device *usb, "%s-%d.%d", usb->name, config->config, first ); INIT_LIST_HEAD ( &func->dev.children ); func->dev.parent = bus->dev; - list_add_tail ( &func->list, &usb->functions ); /* Identify function */ - if ( ( rc = usb_describe ( usb, config, first, func->interface, - &func->desc ) ) != 0 ) - goto err_describe; - assert ( func->desc.count <= config->interfaces ); + if ( ( rc = usb_function ( func, config, first ) ) != 0 ) + goto err_function; + assert ( func->count <= config->interfaces ); /* Mark interfaces as used */ - if ( ( rc = usb_used ( usb, func->desc.count, func->interface, - used ) ) != 0 ) - goto err_used; + for ( i = 0 ; i < func->count ; i++ ) { + if ( func->interface[i] >= config->interfaces ) { + DBGC ( usb, "USB %s has invalid interface %d\n", + func->name, func->interface[i] ); + goto err_interface; + } + used[ func->interface[i] ] = 1; + } /* Probe device driver */ if ( ( rc = usb_probe ( func, config ) ) != 0 ) goto err_probe; DBGC ( usb, "USB %s %04x:%04x class %d:%d:%d interfaces ", - func->name, func->desc.vendor, func->desc.product, - func->desc.class.class.class, - func->desc.class.class.subclass, - func->desc.class.class.protocol ); - for ( i = 0 ; i < func->desc.count ; i++ ) + func->name, func->dev.desc.vendor, func->dev.desc.device, + func->class.class, func->class.subclass, + func->class.protocol ); + for ( i = 0 ; i < func->count ; i++ ) DBGC ( usb, "%s%d", ( i ? "," : "" ), func->interface[i] ); DBGC ( usb, " using driver %s\n", func->dev.driver_name ); + /* Add to list of functions */ + list_add ( &func->list, &usb->functions ); + /* Add to device hierarchy */ list_add_tail ( &func->dev.siblings, &bus->dev->children ); continue; list_del ( &func->dev.siblings ); + list_del ( &func->list ); usb_remove ( func ); err_probe: - err_used: - err_describe: - list_del ( &func->list ); free ( func ); err_alloc: + err_interface: + err_function: /* Continue registering other functions */ continue; } @@ -1328,6 +1165,82 @@ static void usb_remove_all ( struct usb_device *usb ) { } /** + * Select USB device configuration + * + * @v usb USB device + * @v index Configuration index + * @ret rc Return status code + */ +static int usb_configure ( struct usb_device *usb, unsigned int index ) { + struct usb_configuration_descriptor partial; + struct usb_configuration_descriptor *config; + size_t len; + int rc; + + /* Read first part of configuration descriptor to get size */ + if ( ( rc = usb_get_config_descriptor ( usb, index, &partial, + sizeof ( partial ) ) ) != 0 ) { + DBGC ( usb, "USB %s could not get configuration descriptor %d: " + "%s\n", usb->name, index, strerror ( rc ) ); + goto err_get_partial; + } + len = le16_to_cpu ( partial.len ); + if ( len < sizeof ( partial ) ) { + DBGC ( usb, "USB %s underlength configuraton descriptor %d\n", + usb->name, index ); + rc = -EINVAL; + goto err_partial_len; + } + + /* Allocate buffer for whole configuration descriptor */ + config = malloc ( len ); + if ( ! config ) { + rc = -ENOMEM; + goto err_alloc_config; + } + + /* Read whole configuration descriptor */ + if ( ( rc = usb_get_config_descriptor ( usb, index, config, + len ) ) != 0 ) { + DBGC ( usb, "USB %s could not get configuration descriptor %d: " + "%s\n", usb->name, index, strerror ( rc ) ); + goto err_get_config_descriptor; + } + if ( config->len != partial.len ) { + DBGC ( usb, "USB %s bad configuration descriptor %d length\n", + usb->name, index ); + rc = -EINVAL; + goto err_config_len; + } + + /* Set configuration */ + if ( ( rc = usb_set_configuration ( usb, config->config ) ) != 0){ + DBGC ( usb, "USB %s could not set configuration %d: %s\n", + usb->name, config->config, strerror ( rc ) ); + goto err_set_configuration; + } + + /* Probe USB device drivers */ + usb_probe_all ( usb, config ); + + /* Free configuration descriptor */ + free ( config ); + + return 0; + + usb_remove_all ( usb ); + usb_set_configuration ( usb, 0 ); + err_set_configuration: + err_config_len: + err_get_config_descriptor: + free ( config ); + err_alloc_config: + err_partial_len: + err_get_partial: + return rc; +} + +/** * Clear USB device configuration * * @v usb USB device @@ -1349,76 +1262,32 @@ static void usb_deconfigure ( struct usb_device *usb ) { } /** - * Choose our preferred USB device configuration + * Find and select a supported USB device configuration * * @v usb USB device * @ret rc Return status code */ -static int usb_autoconfigure ( struct usb_device *usb ) { - struct usb_configuration_descriptor *config; - unsigned int preferred = 0; +static int usb_configure_any ( struct usb_device *usb ) { unsigned int index; - int score; - int best = 0; - int rc; + int rc = -ENOENT; - /* Calculate driver score for each configuration index */ + /* Attempt all configuration indexes */ for ( index = 0 ; index < usb->device.configurations ; index++ ) { - /* Read configuration descriptor */ - if ( ( rc = usb_config_descriptor ( usb, index, - &config ) ) != 0 ) - goto err_config; - - /* Get score for this configuration */ - score = usb_score ( usb, config ); - if ( score < 0 ) { - rc = score; - goto err_score; - } - DBGC2 ( usb, "USB %s configuration %d score %d\n", - usb->name, config->config, score ); + /* Attempt this configuration index */ + if ( ( rc = usb_configure ( usb, index ) ) != 0 ) + continue; - /* Record as preferred configuration, if applicable */ - if ( score > best ) { - best = score; - preferred = index; + /* If we have no drivers, then try the next configuration */ + if ( list_empty ( &usb->functions ) ) { + rc = -ENOTSUP; + usb_deconfigure ( usb ); + continue; } - /* Free configuration descriptor */ - free ( config ); - config = NULL; - } - - /* Read preferred configuration descriptor */ - if ( ( rc = usb_config_descriptor ( usb, preferred, &config ) ) != 0 ) - goto err_preferred; - - /* Set configuration */ - if ( ( rc = usb_set_configuration ( usb, config->config ) ) != 0){ - DBGC ( usb, "USB %s could not set configuration %d: %s\n", - usb->name, config->config, strerror ( rc ) ); - goto err_set_configuration; + return 0; } - /* Probe USB device drivers */ - usb_probe_all ( usb, config ); - - /* Free configuration descriptor */ - free ( config ); - - return 0; - - usb_remove_all ( usb ); - usb_set_configuration ( usb, 0 ); - err_set_configuration: - free ( config ); - err_preferred: - return rc; - - err_score: - free ( config ); - err_config: return rc; } @@ -1497,9 +1366,8 @@ static int register_usb ( struct usb_device *usb ) { hub->name, port->address, strerror ( rc ) ); goto err_speed; } - usb->speed = port->speed; DBGC2 ( usb, "USB %s attached as %s-speed device\n", - usb->name, usb_speed_name ( usb->speed ) ); + usb->name, usb_speed_name ( port->speed ) ); /* Open device */ if ( ( rc = usb->host->open ( usb ) ) != 0 ) { @@ -1509,7 +1377,7 @@ static int register_usb ( struct usb_device *usb ) { } /* Describe control endpoint */ - mtu = USB_EP0_DEFAULT_MTU ( usb->speed ); + mtu = USB_EP0_DEFAULT_MTU ( port->speed ); usb_endpoint_describe ( &usb->control, USB_EP0_ADDRESS, USB_EP0_ATTRIBUTES, mtu, USB_EP0_BURST, USB_EP0_INTERVAL ); @@ -1560,16 +1428,16 @@ static int register_usb ( struct usb_device *usb ) { le16_to_cpu ( usb->device.product ), usb->device.class.class, usb->device.class.subclass, usb->device.class.protocol, usb_bcd ( le16_to_cpu ( usb->device.protocol ) ), - usb_speed_name ( usb->speed ), usb->control.mtu ); + usb_speed_name ( port->speed ), usb->control.mtu ); /* Configure device */ - if ( ( rc = usb_autoconfigure ( usb ) ) != 0 ) - goto err_autoconfigure; + if ( ( rc = usb_configure_any ( usb ) ) != 0 ) + goto err_configure_any; return 0; usb_deconfigure ( usb ); - err_autoconfigure: + err_configure_any: err_get_device_descriptor: err_mtu: err_get_mtu: @@ -1723,24 +1591,23 @@ static int usb_hotplugged ( struct usb_port *port ) { if ( ( rc = hub->driver->speed ( hub, port ) ) != 0 ) { DBGC ( hub, "USB hub %s port %d could not get speed: %s\n", hub->name, port->address, strerror ( rc ) ); - /* Treat as a disconnection */ - port->disconnected = 1; - port->speed = USB_SPEED_NONE; + goto err_speed; } /* Detach device, if applicable */ if ( port->attached && ( port->disconnected || ! port->speed ) ) usb_detached ( port ); - /* Clear any recorded disconnections */ - port->disconnected = 0; - /* Attach device, if applicable */ if ( port->speed && ( ! port->attached ) && ( ( rc = usb_attached ( port ) ) != 0 ) ) - return rc; + goto err_attached; - return 0; + err_attached: + err_speed: + /* Clear any recorded disconnections */ + port->disconnected = 0; + return rc; } /****************************************************************************** @@ -2239,12 +2106,12 @@ struct usb_port * usb_transaction_translator ( struct usb_device *usb ) { struct usb_device *parent; /* Navigate up to root hub. If we find a low-speed or - * full-speed device with a higher-speed parent hub, then that - * device's port is the transaction translator. + * full-speed port with a higher-speed parent device, then + * that port is the transaction translator. */ for ( ; ( parent = usb->port->hub->usb ) ; usb = parent ) { - if ( ( usb->speed <= USB_SPEED_FULL ) && - ( parent->speed > USB_SPEED_FULL ) ) + if ( ( usb->port->speed <= USB_SPEED_FULL ) && + ( parent->port->speed > USB_SPEED_FULL ) ) return usb->port; } diff --git a/roms/ipxe/src/drivers/bus/virtio-pci.c b/roms/ipxe/src/drivers/bus/virtio-pci.c index 3311595fb..fbef067bc 100644 --- a/roms/ipxe/src/drivers/bus/virtio-pci.c +++ b/roms/ipxe/src/drivers/bus/virtio-pci.c @@ -11,15 +11,10 @@ * */ -#include "errno.h" -#include "byteswap.h" #include "etherboot.h" #include "ipxe/io.h" -#include "ipxe/iomap.h" -#include "ipxe/pci.h" -#include "ipxe/reboot.h" -#include "ipxe/virtio-pci.h" #include "ipxe/virtio-ring.h" +#include "ipxe/virtio-pci.h" int vp_find_vq(unsigned int ioaddr, int queue_index, struct vring_virtqueue *vq) @@ -35,19 +30,19 @@ int vp_find_vq(unsigned int ioaddr, int queue_index, num = inw(ioaddr + VIRTIO_PCI_QUEUE_NUM); if (!num) { - DBG("VIRTIO-PCI ERROR: queue size is 0\n"); + printf("ERROR: queue size is 0\n"); return -1; } if (num > MAX_QUEUE_NUM) { - DBG("VIRTIO-PCI ERROR: queue size %d > %d\n", num, MAX_QUEUE_NUM); + printf("ERROR: queue size %d > %d\n", num, MAX_QUEUE_NUM); return -1; } /* check if the queue is already active */ if (inl(ioaddr + VIRTIO_PCI_QUEUE_PFN)) { - DBG("VIRTIO-PCI ERROR: queue already active\n"); + printf("ERROR: queue already active\n"); return -1; } @@ -67,343 +62,3 @@ int vp_find_vq(unsigned int ioaddr, int queue_index, return num; } - -#define CFG_POS(vdev, field) \ - (vdev->cfg_cap_pos + offsetof(struct virtio_pci_cfg_cap, field)) - -static void prep_pci_cfg_cap(struct virtio_pci_modern_device *vdev, - struct virtio_pci_region *region, - size_t offset, u32 length) -{ - pci_write_config_byte(vdev->pci, CFG_POS(vdev, cap.bar), region->bar); - pci_write_config_dword(vdev->pci, CFG_POS(vdev, cap.length), length); - pci_write_config_dword(vdev->pci, CFG_POS(vdev, cap.offset), - (intptr_t)(region->base + offset)); -} - -void vpm_iowrite8(struct virtio_pci_modern_device *vdev, - struct virtio_pci_region *region, u8 data, size_t offset) -{ - switch (region->flags & VIRTIO_PCI_REGION_TYPE_MASK) { - case VIRTIO_PCI_REGION_MEMORY: - writeb(data, region->base + offset); - break; - case VIRTIO_PCI_REGION_PORT: - outb(data, region->base + offset); - break; - case VIRTIO_PCI_REGION_PCI_CONFIG: - prep_pci_cfg_cap(vdev, region, offset, 1); - pci_write_config_byte(vdev->pci, CFG_POS(vdev, pci_cfg_data), data); - break; - default: - assert(0); - break; - } -} - -void vpm_iowrite16(struct virtio_pci_modern_device *vdev, - struct virtio_pci_region *region, u16 data, size_t offset) -{ - data = cpu_to_le16(data); - switch (region->flags & VIRTIO_PCI_REGION_TYPE_MASK) { - case VIRTIO_PCI_REGION_MEMORY: - writew(data, region->base + offset); - break; - case VIRTIO_PCI_REGION_PORT: - outw(data, region->base + offset); - break; - case VIRTIO_PCI_REGION_PCI_CONFIG: - prep_pci_cfg_cap(vdev, region, offset, 2); - pci_write_config_word(vdev->pci, CFG_POS(vdev, pci_cfg_data), data); - break; - default: - assert(0); - break; - } -} - -void vpm_iowrite32(struct virtio_pci_modern_device *vdev, - struct virtio_pci_region *region, u32 data, size_t offset) -{ - data = cpu_to_le32(data); - switch (region->flags & VIRTIO_PCI_REGION_TYPE_MASK) { - case VIRTIO_PCI_REGION_MEMORY: - writel(data, region->base + offset); - break; - case VIRTIO_PCI_REGION_PORT: - outl(data, region->base + offset); - break; - case VIRTIO_PCI_REGION_PCI_CONFIG: - prep_pci_cfg_cap(vdev, region, offset, 4); - pci_write_config_dword(vdev->pci, CFG_POS(vdev, pci_cfg_data), data); - break; - default: - assert(0); - break; - } -} - -u8 vpm_ioread8(struct virtio_pci_modern_device *vdev, - struct virtio_pci_region *region, size_t offset) -{ - uint8_t data; - switch (region->flags & VIRTIO_PCI_REGION_TYPE_MASK) { - case VIRTIO_PCI_REGION_MEMORY: - data = readb(region->base + offset); - break; - case VIRTIO_PCI_REGION_PORT: - data = inb(region->base + offset); - break; - case VIRTIO_PCI_REGION_PCI_CONFIG: - prep_pci_cfg_cap(vdev, region, offset, 1); - pci_read_config_byte(vdev->pci, CFG_POS(vdev, pci_cfg_data), &data); - break; - default: - assert(0); - data = 0; - break; - } - return data; -} - -u16 vpm_ioread16(struct virtio_pci_modern_device *vdev, - struct virtio_pci_region *region, size_t offset) -{ - uint16_t data; - switch (region->flags & VIRTIO_PCI_REGION_TYPE_MASK) { - case VIRTIO_PCI_REGION_MEMORY: - data = readw(region->base + offset); - break; - case VIRTIO_PCI_REGION_PORT: - data = inw(region->base + offset); - break; - case VIRTIO_PCI_REGION_PCI_CONFIG: - prep_pci_cfg_cap(vdev, region, offset, 2); - pci_read_config_word(vdev->pci, CFG_POS(vdev, pci_cfg_data), &data); - break; - default: - assert(0); - data = 0; - break; - } - return le16_to_cpu(data); -} - -u32 vpm_ioread32(struct virtio_pci_modern_device *vdev, - struct virtio_pci_region *region, size_t offset) -{ - uint32_t data; - switch (region->flags & VIRTIO_PCI_REGION_TYPE_MASK) { - case VIRTIO_PCI_REGION_MEMORY: - data = readw(region->base + offset); - break; - case VIRTIO_PCI_REGION_PORT: - data = inw(region->base + offset); - break; - case VIRTIO_PCI_REGION_PCI_CONFIG: - prep_pci_cfg_cap(vdev, region, offset, 4); - pci_read_config_dword(vdev->pci, CFG_POS(vdev, pci_cfg_data), &data); - break; - default: - assert(0); - data = 0; - break; - } - return le32_to_cpu(data); -} - -int virtio_pci_find_capability(struct pci_device *pci, uint8_t cfg_type) -{ - int pos; - uint8_t type, bar; - - for (pos = pci_find_capability(pci, PCI_CAP_ID_VNDR); - pos > 0; - pos = pci_find_next_capability(pci, pos, PCI_CAP_ID_VNDR)) { - - pci_read_config_byte(pci, pos + offsetof(struct virtio_pci_cap, - cfg_type), &type); - pci_read_config_byte(pci, pos + offsetof(struct virtio_pci_cap, - bar), &bar); - - /* Ignore structures with reserved BAR values */ - if (bar > 0x5) { - continue; - } - - if (type == cfg_type) { - return pos; - } - } - return 0; -} - -int virtio_pci_map_capability(struct pci_device *pci, int cap, size_t minlen, - u32 align, u32 start, u32 size, - struct virtio_pci_region *region) -{ - u8 bar; - u32 offset, length, base_raw; - unsigned long base; - - pci_read_config_byte(pci, cap + offsetof(struct virtio_pci_cap, bar), &bar); - pci_read_config_dword(pci, cap + offsetof(struct virtio_pci_cap, offset), - &offset); - pci_read_config_dword(pci, cap + offsetof(struct virtio_pci_cap, length), - &length); - - if (length <= start) { - DBG("VIRTIO-PCI bad capability len %d (>%d expected)\n", length, start); - return -EINVAL; - } - if (length - start < minlen) { - DBG("VIRTIO-PCI bad capability len %d (>=%zd expected)\n", length, minlen); - return -EINVAL; - } - length -= start; - if (start + offset < offset) { - DBG("VIRTIO-PCI map wrap-around %d+%d\n", start, offset); - return -EINVAL; - } - offset += start; - if (offset & (align - 1)) { - DBG("VIRTIO-PCI offset %d not aligned to %d\n", offset, align); - return -EINVAL; - } - if (length > size) { - length = size; - } - - if (minlen + offset < minlen || - minlen + offset > pci_bar_size(pci, PCI_BASE_ADDRESS(bar))) { - DBG("VIRTIO-PCI map virtio %zd@%d out of range on bar %i length %ld\n", - minlen, offset, - bar, pci_bar_size(pci, PCI_BASE_ADDRESS(bar))); - return -EINVAL; - } - - region->base = NULL; - region->length = length; - region->bar = bar; - - base = pci_bar_start(pci, PCI_BASE_ADDRESS(bar)); - if (base) { - pci_read_config_dword(pci, PCI_BASE_ADDRESS(bar), &base_raw); - - if (base_raw & PCI_BASE_ADDRESS_SPACE_IO) { - /* Region accessed using port I/O */ - region->base = (void *)(base + offset); - region->flags = VIRTIO_PCI_REGION_PORT; - } else { - /* Region mapped into memory space */ - region->base = ioremap(base + offset, length); - region->flags = VIRTIO_PCI_REGION_MEMORY; - } - } - if (!region->base) { - /* Region accessed via PCI config space window */ - region->base = (void *)(intptr_t)offset; - region->flags = VIRTIO_PCI_REGION_PCI_CONFIG; - } - return 0; -} - -void virtio_pci_unmap_capability(struct virtio_pci_region *region) -{ - unsigned region_type = region->flags & VIRTIO_PCI_REGION_TYPE_MASK; - if (region_type == VIRTIO_PCI_REGION_MEMORY) { - iounmap(region->base); - } -} - -void vpm_notify(struct virtio_pci_modern_device *vdev, - struct vring_virtqueue *vq) -{ - vpm_iowrite16(vdev, &vq->notification, (u16)vq->queue_index, 0); -} - -int vpm_find_vqs(struct virtio_pci_modern_device *vdev, - unsigned nvqs, struct vring_virtqueue *vqs) -{ - unsigned i; - struct vring_virtqueue *vq; - u16 size, off; - u32 notify_offset_multiplier; - int err; - - if (nvqs > vpm_ioread16(vdev, &vdev->common, COMMON_OFFSET(num_queues))) { - return -ENOENT; - } - - /* Read notify_off_multiplier from config space. */ - pci_read_config_dword(vdev->pci, - vdev->notify_cap_pos + offsetof(struct virtio_pci_notify_cap, - notify_off_multiplier), - ¬ify_offset_multiplier); - - for (i = 0; i < nvqs; i++) { - /* Select the queue we're interested in */ - vpm_iowrite16(vdev, &vdev->common, (u16)i, COMMON_OFFSET(queue_select)); - - /* Check if queue is either not available or already active. */ - size = vpm_ioread16(vdev, &vdev->common, COMMON_OFFSET(queue_size)); - /* QEMU has a bug where queues don't revert to inactive on device - * reset. Skip checking the queue_enable field until it is fixed. - */ - if (!size /*|| vpm_ioread16(vdev, &vdev->common.queue_enable)*/) - return -ENOENT; - - if (size & (size - 1)) { - DBG("VIRTIO-PCI %p: bad queue size %d", vdev, size); - return -EINVAL; - } - - vq = &vqs[i]; - vq->queue_index = i; - - /* get offset of notification word for this vq */ - off = vpm_ioread16(vdev, &vdev->common, COMMON_OFFSET(queue_notify_off)); - vq->vring.num = size; - - vring_init(&vq->vring, size, (unsigned char *)vq->queue); - - /* activate the queue */ - vpm_iowrite16(vdev, &vdev->common, size, COMMON_OFFSET(queue_size)); - - vpm_iowrite64(vdev, &vdev->common, virt_to_phys(vq->vring.desc), - COMMON_OFFSET(queue_desc_lo), - COMMON_OFFSET(queue_desc_hi)); - vpm_iowrite64(vdev, &vdev->common, virt_to_phys(vq->vring.avail), - COMMON_OFFSET(queue_avail_lo), - COMMON_OFFSET(queue_avail_hi)); - vpm_iowrite64(vdev, &vdev->common, virt_to_phys(vq->vring.used), - COMMON_OFFSET(queue_used_lo), - COMMON_OFFSET(queue_used_hi)); - - err = virtio_pci_map_capability(vdev->pci, - vdev->notify_cap_pos, 2, 2, - off * notify_offset_multiplier, 2, - &vq->notification); - if (err) { - goto err_map_notify; - } - } - - /* Select and activate all queues. Has to be done last: once we do - * this, there's no way to go back except reset. - */ - for (i = 0; i < nvqs; i++) { - vq = &vqs[i]; - vpm_iowrite16(vdev, &vdev->common, (u16)vq->queue_index, - COMMON_OFFSET(queue_select)); - vpm_iowrite16(vdev, &vdev->common, 1, COMMON_OFFSET(queue_enable)); - } - return 0; - -err_map_notify: - /* Undo the virtio_pci_map_capability calls. */ - while (i-- > 0) { - virtio_pci_unmap_capability(&vqs[i].notification); - } - return err; -} diff --git a/roms/ipxe/src/drivers/bus/virtio-ring.c b/roms/ipxe/src/drivers/bus/virtio-ring.c index 98e787e16..e55b6d0ed 100644 --- a/roms/ipxe/src/drivers/bus/virtio-ring.c +++ b/roms/ipxe/src/drivers/bus/virtio-ring.c @@ -18,8 +18,8 @@ FILE_LICENCE ( GPL2_OR_LATER ); #include "etherboot.h" #include "ipxe/io.h" -#include "ipxe/virtio-pci.h" #include "ipxe/virtio-ring.h" +#include "ipxe/virtio-pci.h" #define BUG() do { \ printf("BUG: failure at %s:%d/%s()!\n", \ @@ -122,8 +122,7 @@ void vring_add_buf(struct vring_virtqueue *vq, wmb(); } -void vring_kick(struct virtio_pci_modern_device *vdev, unsigned int ioaddr, - struct vring_virtqueue *vq, int num_added) +void vring_kick(unsigned int ioaddr, struct vring_virtqueue *vq, int num_added) { struct vring *vr = &vq->vring; @@ -131,13 +130,7 @@ void vring_kick(struct virtio_pci_modern_device *vdev, unsigned int ioaddr, vr->avail->idx += num_added; mb(); - if (!(vr->used->flags & VRING_USED_F_NO_NOTIFY)) { - if (vdev) { - /* virtio 1.0 */ - vpm_notify(vdev, vq); - } else { - /* legacy virtio */ - vp_notify(ioaddr, vq->queue_index); - } - } + if (!(vr->used->flags & VRING_USED_F_NO_NOTIFY)) + vp_notify(ioaddr, vq->queue_index); } + diff --git a/roms/ipxe/src/drivers/infiniband/CIB_PRM.h b/roms/ipxe/src/drivers/infiniband/CIB_PRM.h deleted file mode 100755 index 6d07c0151..000000000 --- a/roms/ipxe/src/drivers/infiniband/CIB_PRM.h +++ /dev/null @@ -1,1168 +0,0 @@ -/* - * Copyright (C) 2013-2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#ifndef __CIB_PRM__ -#define __CIB_PRM__ - -typedef unsigned long long __be64; -typedef uint32_t __be32; -typedef uint16_t __be16; - -#define GOLAN_CMD_DATA_BLOCK_SIZE (1 << 9) -#define GOLAN_CMD_PAS_CNT (GOLAN_CMD_DATA_BLOCK_SIZE / sizeof(__be64)) -#define MAILBOX_STRIDE (1 << 10) -#define MAILBOX_MASK (MAILBOX_STRIDE - 1) - -#define GOLAN_PCI_CMD_XPORT 7 -#define CMD_OWNER_HW 0x1 - -#define IB_NUM_PKEYS 0x20 - -struct health_buffer { - __be32 assert_var[5]; - __be32 rsvd0[3]; - __be32 assert_exit_ptr; - __be32 assert_callra; - __be32 rsvd1[2]; - __be32 fw_ver; - __be32 hw_id; - __be32 rsvd2; - u8 irisc_index; - u8 synd; - __be16 ext_sync; -} __attribute ( ( packed ) ); - -struct golan_hca_init_seg { - __be32 fw_rev; - __be32 cmdif_rev_fw_sub; - __be32 rsvd0[2]; - __be32 cmdq_addr_h; - __be32 cmdq_addr_l_sz; - __be32 cmd_dbell; - __be32 rsvd1[121]; - struct health_buffer health; - __be32 rsvd2[884]; - __be32 health_counter; - __be32 rsvd3[1023]; - __be64 ieee1588_clk; - __be32 ieee1588_clk_type; - __be32 clr_intx; -} __attribute ( ( packed ) ); - -enum golan_manage_pages_mode { - GOLAN_PAGES_CANT_GIVE = 0, - GOLAN_PAGES_GIVE = 1, - GOLAN_PAGES_TAKE = 2 -}; - -enum golan_qry_pages_mode { - GOLAN_BOOT_PAGES = 0x1, - GOLAN_INIT_PAGES = 0x2, - GOLAN_REG_PAGES = 0x3, -}; - -enum { - GOLAN_REG_PCAP = 0x5001, - GOLAN_REG_PMTU = 0x5003, - GOLAN_REG_PTYS = 0x5004, - GOLAN_REG_PAOS = 0x5006, - GOLAN_REG_PMAOS = 0x5012, - GOLAN_REG_PUDE = 0x5009, - GOLAN_REG_PMPE = 0x5010, - GOLAN_REG_PELC = 0x500e, - GOLAN_REG_PMLP = 0, /* TBD */ - GOLAN_REG_NODE_DESC = 0x6001, - GOLAN_REG_HOST_ENDIANESS = 0x7004, -}; - -enum { - GOLAN_CMD_OP_QUERY_HCA_CAP = 0x100, - GOLAN_CMD_OP_QUERY_ADAPTER = 0x101, - GOLAN_CMD_OP_INIT_HCA = 0x102, - GOLAN_CMD_OP_TEARDOWN_HCA = 0x103, - GOLAN_CMD_OP_ENABLE_HCA = 0x104, - GOLAN_CMD_OP_DISABLE_HCA = 0x105, - - GOLAN_CMD_OP_QUERY_PAGES = 0x107, - GOLAN_CMD_OP_MANAGE_PAGES = 0x108, - GOLAN_CMD_OP_SET_HCA_CAP = 0x109, - - GOLAN_CMD_OP_CREATE_MKEY = 0x200, - GOLAN_CMD_OP_QUERY_MKEY = 0x201, - GOLAN_CMD_OP_DESTROY_MKEY = 0x202, - GOLAN_CMD_OP_QUERY_SPECIAL_CONTEXTS = 0x203, - - GOLAN_CMD_OP_CREATE_EQ = 0x301, - GOLAN_CMD_OP_DESTROY_EQ = 0x302, - GOLAN_CMD_OP_QUERY_EQ = 0x303, - - GOLAN_CMD_OP_CREATE_CQ = 0x400, - GOLAN_CMD_OP_DESTROY_CQ = 0x401, - GOLAN_CMD_OP_QUERY_CQ = 0x402, - GOLAN_CMD_OP_MODIFY_CQ = 0x403, - - GOLAN_CMD_OP_CREATE_QP = 0x500, - GOLAN_CMD_OP_DESTROY_QP = 0x501, - GOLAN_CMD_OP_RST2INIT_QP = 0x502, - GOLAN_CMD_OP_INIT2RTR_QP = 0x503, - GOLAN_CMD_OP_RTR2RTS_QP = 0x504, - GOLAN_CMD_OP_RTS2RTS_QP = 0x505, - GOLAN_CMD_OP_SQERR2RTS_QP = 0x506, - GOLAN_CMD_OP_2ERR_QP = 0x507, - GOLAN_CMD_OP_RTS2SQD_QP = 0x508, - GOLAN_CMD_OP_SQD2RTS_QP = 0x509, - GOLAN_CMD_OP_2RST_QP = 0x50a, - GOLAN_CMD_OP_QUERY_QP = 0x50b, - GOLAN_CMD_OP_CONF_SQP = 0x50c, - GOLAN_CMD_OP_MAD_IFC = 0x50d, - GOLAN_CMD_OP_INIT2INIT_QP = 0x50e, - GOLAN_CMD_OP_SUSPEND_QP = 0x50f, - GOLAN_CMD_OP_UNSUSPEND_QP = 0x510, - GOLAN_CMD_OP_SQD2SQD_QP = 0x511, - GOLAN_CMD_OP_ALLOC_QP_COUNTER_SET = 0x512, - GOLAN_CMD_OP_DEALLOC_QP_COUNTER_SET = 0x513, - GOLAN_CMD_OP_QUERY_QP_COUNTER_SET = 0x514, - - GOLAN_CMD_OP_CREATE_PSV = 0x600, - GOLAN_CMD_OP_DESTROY_PSV = 0x601, - GOLAN_CMD_OP_QUERY_PSV = 0x602, - GOLAN_CMD_OP_QUERY_SIG_RULE_TABLE = 0x603, - GOLAN_CMD_OP_QUERY_BLOCK_SIZE_TABLE = 0x604, - - GOLAN_CMD_OP_CREATE_SRQ = 0x700, - GOLAN_CMD_OP_DESTROY_SRQ = 0x701, - GOLAN_CMD_OP_QUERY_SRQ = 0x702, - GOLAN_CMD_OP_ARM_RQ = 0x703, - GOLAN_CMD_OP_RESIZE_SRQ = 0x704, - - GOLAN_CMD_OP_QUERY_HCA_VPORT_CONTEXT = 0x762, - GOLAN_CMD_OP_QUERY_HCA_VPORT_GID = 0x764, - GOLAN_CMD_OP_QUERY_HCA_VPORT_PKEY = 0x765, - - GOLAN_CMD_OP_ALLOC_PD = 0x800, - GOLAN_CMD_OP_DEALLOC_PD = 0x801, - GOLAN_CMD_OP_ALLOC_UAR = 0x802, - GOLAN_CMD_OP_DEALLOC_UAR = 0x803, - - GOLAN_CMD_OP_ATTACH_TO_MCG = 0x806, - GOLAN_CMD_OP_DETACH_FROM_MCG = 0x807, - - - GOLAN_CMD_OP_ALLOC_XRCD = 0x80e, - GOLAN_CMD_OP_DEALLOC_XRCD = 0x80f, - - GOLAN_CMD_OP_ACCESS_REG = 0x805, -}; - -struct golan_inbox_hdr { - __be16 opcode; - u8 rsvd[4]; - __be16 opmod; -} __attribute ( ( packed ) ); - -struct golan_cmd_layout { - u8 type; - u8 rsvd0[3]; - __be32 inlen; - union { - __be64 in_ptr; - __be32 in_ptr32[2]; - }; - __be32 in[4]; - __be32 out[4]; - union { - __be64 out_ptr; - __be32 out_ptr32[2]; - }; - __be32 outlen; - u8 token; - u8 sig; - u8 rsvd1; - volatile u8 status_own; -} __attribute ( ( packed ) ); - -struct golan_outbox_hdr { - u8 status; - u8 rsvd[3]; - __be32 syndrome; -} __attribute ( ( packed ) ); - -enum { - GOLAN_DEV_CAP_FLAG_RC = 1LL << 0, - GOLAN_DEV_CAP_FLAG_UC = 1LL << 1, - GOLAN_DEV_CAP_FLAG_UD = 1LL << 2, - GOLAN_DEV_CAP_FLAG_XRC = 1LL << 3, - GOLAN_DEV_CAP_FLAG_SRQ = 1LL << 6, - GOLAN_DEV_CAP_FLAG_BAD_PKEY_CNTR = 1LL << 8, - GOLAN_DEV_CAP_FLAG_BAD_QKEY_CNTR = 1LL << 9, - GOLAN_DEV_CAP_FLAG_APM = 1LL << 17, - GOLAN_DEV_CAP_FLAG_ATOMIC = 1LL << 18, - GOLAN_DEV_CAP_FLAG_ON_DMND_PG = 1LL << 24, - GOLAN_DEV_CAP_FLAG_RESIZE_SRQ = 1LL << 32, - GOLAN_DEV_CAP_FLAG_REMOTE_FENCE = 1LL << 38, - GOLAN_DEV_CAP_FLAG_TLP_HINTS = 1LL << 39, - GOLAN_DEV_CAP_FLAG_SIG_HAND_OVER = 1LL << 40, - GOLAN_DEV_CAP_FLAG_DCT = 1LL << 41, - GOLAN_DEV_CAP_FLAG_CMDIF_CSUM = 1LL << 46, -}; - - -struct golan_hca_cap { - u8 rsvd1[16]; - u8 log_max_srq_sz; - u8 log_max_qp_sz; - u8 rsvd2; - u8 log_max_qp; - u8 log_max_strq_sz; - u8 log_max_srqs; - u8 rsvd4[2]; - u8 rsvd5; - u8 log_max_cq_sz; - u8 rsvd6; - u8 log_max_cq; - u8 log_max_eq_sz; - u8 log_max_mkey; - u8 rsvd7; - u8 log_max_eq; - u8 max_indirection; - u8 log_max_mrw_sz; - u8 log_max_bsf_list_sz; - u8 log_max_klm_list_sz; - u8 rsvd_8_0; - u8 log_max_ra_req_dc; - u8 rsvd_8_1; - u8 log_max_ra_res_dc; - u8 rsvd9; - u8 log_max_ra_req_qp; - u8 rsvd10; - u8 log_max_ra_res_qp; - u8 rsvd11[4]; - __be16 max_qp_count; - __be16 pkey_table_size; - u8 rsvd13; - u8 local_ca_ack_delay; - u8 rsvd14; - u8 num_ports; - u8 log_max_msg; - u8 rsvd15[3]; - __be16 stat_rate_support; - u8 rsvd16[2]; - __be64 flags; - u8 rsvd17; - u8 uar_sz; - u8 rsvd18; - u8 log_pg_sz; - __be16 bf_log_bf_reg_size; - u8 rsvd19[4]; - __be16 max_wqe_sz_sq; - u8 rsvd20[2]; - __be16 max_wqe_sz_rq; - u8 rsvd21[2]; - __be16 max_wqe_sz_sq_dc; - u8 rsvd22[4]; - __be16 max_qp_mcg; - u8 rsvd23; - u8 log_max_mcg; - u8 rsvd24; - u8 log_max_pd; - u8 rsvd25; - u8 log_max_xrcd; - u8 rsvd26[40]; - __be32 uar_page_sz; - u8 rsvd27[28]; - u8 log_msx_atomic_size_qp; - u8 rsvd28[2]; - u8 log_msx_atomic_size_dc; - u8 rsvd29[76]; -} __attribute ( ( packed ) ); - -struct golan_query_pages_inbox { - struct golan_inbox_hdr hdr; - u8 rsvd[8]; -} __attribute ( ( packed ) ); - -struct golan_query_pages_outbox { - struct golan_outbox_hdr hdr; - u8 rsvd[2]; - __be16 func_id; - __be32 num_pages; -} __attribute ( ( packed ) ); - -struct golan_cmd_query_hca_cap_mbox_in { - struct golan_inbox_hdr hdr; - u8 rsvd[8]; -} __attribute ( ( packed ) ); - -struct golan_cmd_query_hca_cap_mbox_out { - struct golan_outbox_hdr hdr; - u8 rsvd0[8]; - struct golan_hca_cap hca_cap; -} __attribute ( ( packed ) ); - -struct golan_cmd_set_hca_cap_mbox_in { - struct golan_inbox_hdr hdr; - u8 rsvd[8]; - struct golan_hca_cap hca_cap; -} __attribute ( ( packed ) ); - -struct golan_cmd_set_hca_cap_mbox_out { - struct golan_outbox_hdr hdr; - u8 rsvd0[8]; -} __attribute ( ( packed ) ); - -struct golan_cmd_init_hca_mbox_in { - struct golan_inbox_hdr hdr; - u8 rsvd0[2]; - __be16 profile; - u8 rsvd1[4]; -} __attribute ( ( packed ) ); - -struct golan_cmd_init_hca_mbox_out { - struct golan_outbox_hdr hdr; - u8 rsvd[8]; -} __attribute ( ( packed ) ); - -enum golan_teardown { - GOLAN_TEARDOWN_GRACEFUL = 0x0, - GOLAN_TEARDOWN_PANIC = 0x1 -}; - -struct golan_cmd_teardown_hca_mbox_in { - struct golan_inbox_hdr hdr; - u8 rsvd0[2]; - __be16 profile; - u8 rsvd1[4]; -} __attribute ( ( packed ) ); - -struct golan_cmd_teardown_hca_mbox_out { - struct golan_outbox_hdr hdr; - u8 rsvd[8]; -} __attribute ( ( packed ) ); - -struct golan_enable_hca_mbox_in { - struct golan_inbox_hdr hdr; - u8 rsvd[8]; -} __attribute ( ( packed ) ); - -struct golan_enable_hca_mbox_out { - struct golan_outbox_hdr hdr; - u8 rsvd[8]; -} __attribute ( ( packed ) ); - -struct golan_disable_hca_mbox_in { - struct golan_inbox_hdr hdr; - u8 rsvd[8]; -} __attribute ( ( packed ) ); - -struct golan_disable_hca_mbox_out { - struct golan_outbox_hdr hdr; - u8 rsvd[8]; -} __attribute ( ( packed ) ); - -struct golan_manage_pages_inbox_data { - u8 rsvd2[16]; - __be64 pas[0]; -} __attribute ( ( packed ) ); - -struct golan_manage_pages_inbox { - struct golan_inbox_hdr hdr; - __be16 rsvd0; - __be16 func_id; - __be32 num_entries; - struct golan_manage_pages_inbox_data data; -} __attribute ( ( packed ) ); - -struct golan_manage_pages_outbox_data { - __be64 pas[0]; -} __attribute ( ( packed ) ); - -struct golan_manage_pages_outbox { - struct golan_outbox_hdr hdr; - __be32 num_entries; - __be32 rsrvd; - struct golan_manage_pages_outbox_data data; -} __attribute ( ( packed ) ); - -struct golan_reg_host_endianess { - u8 he; - u8 rsvd[15]; -} __attribute ( ( packed ) ); - -struct golan_cmd_prot_block { - union { - __be64 data[GOLAN_CMD_PAS_CNT]; - u8 bdata[GOLAN_CMD_DATA_BLOCK_SIZE]; - }; - u8 rsvd0[48]; - __be64 next; - __be32 block_num; - u8 rsvd1; - u8 token; - u8 ctrl_sig; - u8 sig; -} __attribute ( ( packed ) ); - -/* MAD IFC structures */ -#define GOLAN_MAD_SIZE 256 -#define GOLAN_MAD_IFC_NO_VALIDATION 0x3 -#define GOLAN_MAD_IFC_RLID_BIT 16 - -struct golan_mad_ifc_mbox_in { - struct golan_inbox_hdr hdr; - __be16 remote_lid; - u8 rsvd0; - u8 port; - u8 rsvd1[4]; - u8 mad[GOLAN_MAD_SIZE]; -} __attribute ( ( packed ) ); - -struct golan_mad_ifc_mbox_out { - struct golan_outbox_hdr hdr; - u8 rsvd[8]; - u8 mad[GOLAN_MAD_SIZE]; -} __attribute ( ( packed ) ); - -/* UAR Structures */ -struct golan_alloc_uar_mbox_in { - struct golan_inbox_hdr hdr; - u8 rsvd[8]; -} __attribute ( ( packed ) ); - -struct golan_alloc_uar_mbox_out { - struct golan_outbox_hdr hdr; - __be32 uarn; - u8 rsvd[4]; -} __attribute ( ( packed ) ); - -struct golan_free_uar_mbox_in { - struct golan_inbox_hdr hdr; - __be32 uarn; - u8 rsvd[4]; -} __attribute ( ( packed ) ); - -struct golan_free_uar_mbox_out { - struct golan_outbox_hdr hdr; - u8 rsvd[8]; -} __attribute ( ( packed ) ); - -/* Event Queue Structures */ -enum { - GOLAN_EQ_STATE_ARMED = 0x9, - GOLAN_EQ_STATE_FIRED = 0xa, - GOLAN_EQ_STATE_ALWAYS_ARMED = 0xb, -}; - - -struct golan_eq_context { - u8 status; - u8 ec_oi; - u8 st; - u8 rsvd2[7]; - __be16 page_pffset; - __be32 log_sz_usr_page; - u8 rsvd3[7]; - u8 intr; - u8 log_page_size; - u8 rsvd4[15]; - __be32 consumer_counter; - __be32 produser_counter; - u8 rsvd5[16]; -} __attribute ( ( packed ) ); - -struct golan_create_eq_mbox_in_data { - struct golan_eq_context ctx; - u8 rsvd2[8]; - __be64 events_mask; - u8 rsvd3[176]; - __be64 pas[0]; -} __attribute ( ( packed ) ); - -struct golan_create_eq_mbox_in { - struct golan_inbox_hdr hdr; - u8 rsvd0[3]; - u8 input_eqn; - u8 rsvd1[4]; - struct golan_create_eq_mbox_in_data data; -} __attribute ( ( packed ) ); - -struct golan_create_eq_mbox_out { - struct golan_outbox_hdr hdr; - u8 rsvd0[3]; - u8 eq_number; - u8 rsvd1[4]; -} __attribute ( ( packed ) ); - -struct golan_destroy_eq_mbox_in { - struct golan_inbox_hdr hdr; - u8 rsvd0[3]; - u8 eqn; - u8 rsvd1[4]; -} __attribute ( ( packed ) ); - -struct golan_destroy_eq_mbox_out { - struct golan_outbox_hdr hdr; - u8 rsvd[8]; -} __attribute ( ( packed ) ); - -/***********************************************/ -/************** Query Vport ****************/ -struct golan_query_hca_vport_context_inbox { - struct golan_inbox_hdr hdr; - __be16 other_vport : 1; - __be16 rsvd1 : 7; - __be16 port_num : 4; - __be16 rsvd2 : 4; - __be16 vport_number; - u8 rsvd[4]; -} __attribute ( ( packed ) ); - -struct golan_query_hca_vport_context_data { - __be32 field_select; - __be32 rsvd1[7]; - //**** - __be16 sm_virt_aware : 1; - __be16 has_smi : 1; - __be16 has_raw : 1; - __be16 grh_required : 1; - __be16 rsvd2 : 12; - u8 port_physical_state : 4; - u8 vport_state_policy : 4; - u8 port_state : 4; - u8 vport_state : 4; - //**** - u8 rsvd3[4]; - //**** - __be32 system_image_guid[2]; - //**** - __be32 port_guid[2]; - //**** - __be32 node_guid[2]; - //**** - __be32 cap_mask1; - __be32 cap_mask1_field_select; - __be32 cap_mask2; - __be32 cap_mask2_field_select; - u8 rsvd4[16]; - __be16 lid; - u8 rsvd5 : 4; - u8 init_type_reply : 4; - u8 lmc : 3; - u8 subnet_timeout : 5; - __be16 sm_lid; - u8 sm_sl : 4; - u8 rsvd6 : 4; - u8 rsvd7; - __be16 qkey_violation_counter; - __be16 pkey_violation_counter; - u8 rsvd8[100]; -} __attribute ( ( packed ) ); - -struct golan_query_hca_vport_context_outbox { - struct golan_outbox_hdr hdr; - u8 rsvd[8]; - struct golan_query_hca_vport_context_data context_data; -} __attribute ( ( packed ) ); - -struct golan_query_hca_vport_gid_inbox { - struct golan_inbox_hdr hdr; - u8 other_vport : 1; - u8 rsvd1 : 7; - u8 port_num : 4; - u8 rsvd2 : 4; - __be16 vport_number; - __be16 rsvd3; - __be16 gid_index; -} __attribute ( ( packed ) ); - -struct golan_query_hca_vport_gid_outbox { - struct golan_outbox_hdr hdr; - u8 rsvd0[4]; - __be16 gids_num; - u8 rsvd1[2]; - __be32 gid0[4]; -} __attribute ( ( packed ) ); - -struct golan_query_hca_vport_pkey_inbox { - struct golan_inbox_hdr hdr; - u8 other_vport : 1; - u8 rsvd1 : 7; - u8 port_num : 4; - u8 rsvd2 : 4; - __be16 vport_number; - __be16 rsvd3; - __be16 pkey_index; -} __attribute ( ( packed ) ); - -struct golan_query_hca_vport_pkey_data { - __be16 rsvd1; - __be16 pkey0; -} __attribute ( ( packed ) ); - -struct golan_query_hca_vport_pkey_outbox { - struct golan_outbox_hdr hdr; - u8 rsvd[8]; - struct golan_query_hca_vport_pkey_data *pkey_data; -} __attribute ( ( packed ) ); - -struct golan_eqe_comp { - __be32 reserved[6]; - __be32 cqn; -} __attribute ( ( packed ) ); - -struct golan_eqe_qp_srq { - __be32 reserved[6]; - __be32 qp_srq_n; -} __attribute ( ( packed ) ); - -struct golan_eqe_cq_err { - __be32 cqn; - u8 reserved1[7]; - u8 syndrome; -} __attribute ( ( packed ) ); - -struct golan_eqe_dropped_packet { -}; - -struct golan_eqe_port_state { - u8 reserved0[8]; - u8 port; -} __attribute ( ( packed ) ); - -struct golan_eqe_gpio { - __be32 reserved0[2]; - __be64 gpio_event; -} __attribute ( ( packed ) ); - -struct golan_eqe_congestion { - u8 type; - u8 rsvd0; - u8 congestion_level; -} __attribute ( ( packed ) ); - -struct golan_eqe_stall_vl { - u8 rsvd0[3]; - u8 port_vl; -} __attribute ( ( packed ) ); - -struct golan_eqe_cmd { - __be32 vector; - __be32 rsvd[6]; -} __attribute ( ( packed ) ); - -struct golan_eqe_page_req { - u8 rsvd0[2]; - __be16 func_id; - u8 rsvd1[2]; - __be16 num_pages; - __be32 rsvd2[5]; -} __attribute ( ( packed ) ); - -union ev_data { - __be32 raw[7]; - struct golan_eqe_cmd cmd; - struct golan_eqe_comp comp; - struct golan_eqe_qp_srq qp_srq; - struct golan_eqe_cq_err cq_err; - struct golan_eqe_dropped_packet dp; - struct golan_eqe_port_state port; - struct golan_eqe_gpio gpio; - struct golan_eqe_congestion cong; - struct golan_eqe_stall_vl stall_vl; - struct golan_eqe_page_req req_pages; -} __attribute__ ((packed)); - -struct golan_eqe { - u8 rsvd0; - u8 type; - u8 rsvd1; - u8 sub_type; - __be32 rsvd2[7]; - union ev_data data; - __be16 rsvd3; - u8 signature; - u8 owner; -} __attribute__ ((packed)); - -/* Protection Domain Structures */ -struct golan_alloc_pd_mbox_in { - struct golan_inbox_hdr hdr; - u8 rsvd[8]; -} __attribute ( ( packed ) ); - -struct golan_alloc_pd_mbox_out { - struct golan_outbox_hdr hdr; - __be32 pdn; - u8 rsvd[4]; -} __attribute ( ( packed ) ); - -struct golan_dealloc_pd_mbox_in { - struct golan_inbox_hdr hdr; - __be32 pdn; - u8 rsvd[4]; -} __attribute ( ( packed ) ); - -struct golan_dealloc_pd_mbox_out { - struct golan_outbox_hdr hdr; - u8 rsvd[8]; -} __attribute ( ( packed ) ); - -/* Memory key structures */ -#define GOLAN_IB_ACCESS_LOCAL_READ (1 << 2) -#define GOLAN_IB_ACCESS_LOCAL_WRITE (1 << 3) -#define GOLAN_MKEY_LEN64 (1 << 31) -#define GOLAN_CREATE_MKEY_SEG_QPN_BIT 8 - -struct golan_mkey_seg { - /* - * This is a two bit field occupying bits 31-30. - * bit 31 is always 0, - * bit 30 is zero for regular MRs and 1 (e.g free) for UMRs that do not have tanslation - */ - u8 status; - u8 pcie_control; - u8 flags; - u8 version; - __be32 qpn_mkey7_0; - u8 rsvd1[4]; - __be32 flags_pd; - __be64 start_addr; - __be64 len; - __be32 bsfs_octo_size; - u8 rsvd2[16]; - __be32 xlt_oct_size; - u8 rsvd3[3]; - u8 log2_page_size; - u8 rsvd4[4]; -} __attribute ( ( packed ) ); - -struct golan_create_mkey_mbox_in_data { - struct golan_mkey_seg seg; - u8 rsvd1[16]; - __be32 xlat_oct_act_size; - __be32 bsf_coto_act_size; - u8 rsvd2[168]; - __be64 pas[0]; -} __attribute ( ( packed ) ); - -struct golan_create_mkey_mbox_in { - struct golan_inbox_hdr hdr; - __be32 input_mkey_index; - u8 rsvd0[4]; - struct golan_create_mkey_mbox_in_data data; -} __attribute ( ( packed ) ); - -struct golan_create_mkey_mbox_out { - struct golan_outbox_hdr hdr; - __be32 mkey; - u8 rsvd[4]; -} __attribute ( ( packed ) ); - -struct golan_destroy_mkey_mbox_in { - struct golan_inbox_hdr hdr; - __be32 mkey; - u8 rsvd[4]; -} __attribute ( ( packed ) ); - -struct golan_destroy_mkey_mbox_out { - struct golan_outbox_hdr hdr; - u8 rsvd[8]; -} __attribute ( ( packed ) ); - -/* Completion Queue Structures */ -enum { - GOLAN_CQ_STATE_ARMED = 9, - GOLAN_CQ_STATE_ALWAYS_ARMED = 0xb, - GOLAN_CQ_STATE_FIRED = 0xa -}; - -enum { - GOLAN_CQE_REQ = 0, - GOLAN_CQE_RESP_WR_IMM = 1, - GOLAN_CQE_RESP_SEND = 2, - GOLAN_CQE_RESP_SEND_IMM = 3, - GOLAN_CQE_RESP_SEND_INV = 4, - GOLAN_CQE_RESIZE_CQ = 0xff, /* TBD */ - GOLAN_CQE_REQ_ERR = 13, - GOLAN_CQE_RESP_ERR = 14 -}; - -struct golan_cq_context { - u8 status; - u8 cqe_sz_flags; - u8 st; - u8 rsvd3; - u8 rsvd4[6]; - __be16 page_offset; - __be32 log_sz_usr_page; - __be16 cq_period; - __be16 cq_max_count; - __be16 rsvd20; - __be16 c_eqn; - u8 log_pg_sz; - u8 rsvd25[7]; - __be32 last_notified_index; - __be32 solicit_producer_index; - __be32 consumer_counter; - __be32 producer_counter; - u8 rsvd48[8]; - __be64 db_record_addr; -} __attribute ( ( packed ) ); - - -struct golan_create_cq_mbox_in_data { - struct golan_cq_context ctx; - u8 rsvd6[192]; - __be64 pas[0]; -} __attribute ( ( packed ) ); - -struct golan_create_cq_mbox_in { - struct golan_inbox_hdr hdr; - __be32 input_cqn; - u8 rsvdx[4]; - struct golan_create_cq_mbox_in_data data; -} __attribute ( ( packed ) ); - -struct golan_create_cq_mbox_out { - struct golan_outbox_hdr hdr; - __be32 cqn; - u8 rsvd0[4]; -} __attribute ( ( packed ) ); - -struct golan_destroy_cq_mbox_in { - struct golan_inbox_hdr hdr; - __be32 cqn; - u8 rsvd0[4]; -} __attribute ( ( packed ) ); - -struct golan_destroy_cq_mbox_out { - struct golan_outbox_hdr hdr; - u8 rsvd0[8]; -} __attribute ( ( packed ) ); - -struct golan_err_cqe { - u8 rsvd0[32]; - __be32 srqn; - u8 rsvd1[16]; - u8 hw_syndrom; - u8 rsvd2; - u8 vendor_err_synd; - u8 syndrome; - __be32 s_wqe_opcode_qpn; - __be16 wqe_counter; - u8 signature; - u8 op_own; -} __attribute ( ( packed ) ); - -struct golan_cqe64 { - u8 rsvd0[17]; - u8 ml_path; - u8 rsvd20[4]; - __be16 slid; - __be32 flags_rqpn; - u8 rsvd28[4]; - __be32 srqn; - __be32 imm_inval_pkey; - u8 rsvd40[4]; - __be32 byte_cnt; - __be64 timestamp; - __be32 sop_drop_qpn; - __be16 wqe_counter; - u8 signature; - u8 op_own; -} __attribute ( ( packed ) ); - -/* Queue Pair Structures */ -#define GOLAN_QP_CTX_ST_BIT 16 -#define GOLAN_QP_CTX_PM_STATE_BIT 11 -#define GOLAN_QP_CTX_FRE_BIT 11 -#define GOLAN_QP_CTX_RLKY_BIT 4 -#define GOLAN_QP_CTX_RQ_SIZE_BIT 3 -#define GOLAN_QP_CTX_SQ_SIZE_BIT 11 -#define GOLAN_QP_CTX_MTU_BIT 5 -#define GOLAN_QP_CTX_ACK_REQ_FREQ_BIT 28 - -enum { - GOLAN_QP_CTX_DONT_USE_RSRVD_LKEY = 0, - GOLAN_QP_CTX_USE_RSRVD_LKEY = 1 -}; - -enum { - GOLAN_IB_ACK_REQ_FREQ = 8, -}; - -enum golan_qp_optpar { - GOLAN_QP_PARAM_ALT_ADDR_PATH = 1 << 0, - GOLAN_QP_PARAM_RRE = 1 << 1, - GOLAN_QP_PARAM_RAE = 1 << 2, - GOLAN_QP_PARAM_RWE = 1 << 3, - GOLAN_QP_PARAM_PKEY_INDEX = 1 << 4, - GOLAN_QP_PARAM_Q_KEY = 1 << 5, - GOLAN_QP_PARAM_RNR_TIMEOUT = 1 << 6, - GOLAN_QP_PARAM_PRIMARY_ADDR_PATH = 1 << 7, - GOLAN_QP_PARAM_SRA_MAX = 1 << 8, - GOLAN_QP_PARAM_RRA_MAX = 1 << 9, - GOLAN_QP_PARAM_PM_STATE = 1 << 10, - GOLAN_QP_PARAM_RETRY_COUNT = 1 << 12, - GOLAN_QP_PARAM_RNR_RETRY = 1 << 13, - GOLAN_QP_PARAM_ACK_TIMEOUT = 1 << 14, - GOLAN_QP_PARAM_PRI_PORT = 1 << 16, - GOLAN_QP_PARAM_SRQN = 1 << 18, - GOLAN_QP_PARAM_CQN_RCV = 1 << 19, - GOLAN_QP_PARAM_DC_HS = 1 << 20, - GOLAN_QP_PARAM_DC_KEY = 1 << 21 -}; - -#define GOLAN_QP_PARAMS_INIT2RTR_MASK (GOLAN_QP_PARAM_PKEY_INDEX |\ - GOLAN_QP_PARAM_Q_KEY |\ - GOLAN_QP_PARAM_RWE |\ - GOLAN_QP_PARAM_RRE) - -#define GOLAN_QP_PARAMS_RTR2RTS_MASK (GOLAN_QP_PARAM_PM_STATE |\ - GOLAN_QP_PARAM_RNR_TIMEOUT |\ - GOLAN_QP_PARAM_Q_KEY |\ - GOLAN_QP_PARAM_RWE |\ - GOLAN_QP_PARAM_RRE) - - -enum { - GOLAN_QP_ST_RC = 0x0, - GOLAN_QP_ST_UC = 0x1, - GOLAN_QP_ST_UD = 0x2, - GOLAN_QP_ST_XRC = 0x3, - GOLAN_QP_ST_MLX = 0x4, - GOLAN_QP_ST_DC = 0x5, - GOLAN_QP_ST_QP0 = 0x7, - GOLAN_QP_ST_QP1 = 0x8, - GOLAN_QP_ST_RAW_ETHERTYPE = 0x9, - GOLAN_QP_ST_RAW_IPV6 = 0xa, - GOLAN_QP_ST_SNIFFER = 0xb, - GOLAN_QP_ST_SYNC_UMR = 0xe, - GOLAN_QP_ST_PTP_1588 = 0xd, - GOLAN_QP_ST_REG_UMR = 0xc, - GOLAN_QP_ST_MAX -}; - -enum { - GOLAN_QP_PM_MIGRATED = 0x3, - GOLAN_QP_PM_ARMED = 0x0, - GOLAN_QP_PM_REARM = 0x1 -}; - -enum { - GOLAN_QP_LAT_SENSITIVE = 1 << 28, - GOLAN_QP_ENABLE_SIG = 1 << 31 -}; - - -struct golan_qp_db { - u8 rsvd0[2]; - __be16 recv_db; - u8 rsvd1[2]; - __be16 send_db; -} __attribute ( ( packed ) ); - -enum { - GOLAN_WQE_CTRL_CQ_UPDATE = 2 << 2, /*Wissam, wtf?*/ - GOLAN_WQE_CTRL_SOLICITED = 1 << 1 -}; - -struct golan_wqe_ctrl_seg { - __be32 opmod_idx_opcode; - __be32 qpn_ds; - u8 signature; - u8 rsvd[2]; - u8 fm_ce_se; - __be32 imm; -} __attribute ( ( packed ) ); - -struct golan_av { - union { - struct { - __be32 qkey; - __be32 reserved; - } qkey; - __be64 dc_key; - } key; - __be32 dqp_dct; - u8 stat_rate_sl; - u8 fl_mlid; - __be16 rlid; - u8 reserved0[10]; - u8 tclass; - u8 hop_limit; - __be32 grh_gid_fl; - u8 rgid[16]; -} __attribute ( ( packed ) ); - -struct golan_wqe_data_seg { - __be32 byte_count; - __be32 lkey; - __be64 addr; -} __attribute ( ( packed ) ); - -struct golan_wqe_signature_seg { - u8 rsvd0[4]; - u8 signature; - u8 rsvd1[11]; -} __attribute ( ( packed ) ); - -struct golan_wqe_inline_seg { - __be32 byte_count; -} __attribute ( ( packed ) ); - -struct golan_qp_path { - u8 fl; - u8 rsvd3; - u8 free_ar; - u8 pkey_index; - u8 rsvd0; - u8 grh_mlid; - __be16 rlid; - u8 ackto_lt; - u8 mgid_index; - u8 static_rate; - u8 hop_limit; - __be32 tclass_flowlabel; - u8 rgid[16]; - u8 rsvd1[4]; - u8 sl; - u8 port; - u8 rsvd2[6]; -} __attribute ( ( packed ) ); - -struct golan_qp_context { - __be32 flags; - __be32 flags_pd; - u8 mtu_msgmax; - u8 rq_size_stride; - __be16 sq_crq_size; - __be32 qp_counter_set_usr_page; - __be32 wire_qpn; - __be32 log_pg_sz_remote_qpn; - struct golan_qp_path pri_path; - struct golan_qp_path alt_path; - __be32 params1; - u8 reserved2[4]; - __be32 next_send_psn; - __be32 cqn_send; - u8 reserved3[8]; - __be32 last_acked_psn; - __be32 ssn; - __be32 params2; - __be32 rnr_nextrecvpsn; - __be32 xrcd; - __be32 cqn_recv; - __be64 db_rec_addr; - __be32 qkey; - __be32 rq_type_srqn; - __be32 rmsn; - __be16 hw_sq_wqe_counter; - __be16 sw_sq_wqe_counter; - __be16 hw_rcyclic_byte_counter; - __be16 hw_rq_counter; - __be16 sw_rcyclic_byte_counter; - __be16 sw_rq_counter; - u8 rsvd0[5]; - u8 cgs; - u8 cs_req; - u8 cs_res; - __be64 dc_access_key; - u8 rsvd1[24]; -} __attribute ( ( packed ) ); - -struct golan_create_qp_mbox_in_data { - __be32 opt_param_mask; - u8 rsvd1[4]; - struct golan_qp_context ctx; - u8 rsvd3[16]; - __be64 pas[0]; -} __attribute ( ( packed ) ); - -struct golan_create_qp_mbox_in { - struct golan_inbox_hdr hdr; - __be32 input_qpn; - u8 rsvd0[4]; - struct golan_create_qp_mbox_in_data data; -} __attribute ( ( packed ) ); - -struct golan_create_qp_mbox_out { - struct golan_outbox_hdr hdr; - __be32 qpn; - u8 rsvd0[4]; -} __attribute ( ( packed ) ); - -struct golan_destroy_qp_mbox_in { - struct golan_inbox_hdr hdr; - __be32 qpn; - u8 rsvd0[4]; -} __attribute ( ( packed ) ); - -struct golan_destroy_qp_mbox_out { - struct golan_outbox_hdr hdr; - u8 rsvd0[8]; -} __attribute ( ( packed ) ); - -struct golan_modify_qp_mbox_in_data { - __be32 optparam; - u8 rsvd0[4]; - struct golan_qp_context ctx; -} __attribute ( ( packed ) ); - -struct golan_modify_qp_mbox_in { - struct golan_inbox_hdr hdr; - __be32 qpn; - u8 rsvd1[4]; - struct golan_modify_qp_mbox_in_data data; -} __attribute ( ( packed ) ); - -struct golan_modify_qp_mbox_out { - struct golan_outbox_hdr hdr; - u8 rsvd0[8]; -} __attribute ( ( packed ) ); - -struct golan_attach_mcg_mbox_in { - struct golan_inbox_hdr hdr; - __be32 qpn; - __be32 rsvd; - u8 gid[16]; -} __attribute ( ( packed ) ); - -struct golan_attach_mcg_mbox_out { - struct golan_outbox_hdr hdr; - u8 rsvf[8]; -} __attribute ( ( packed ) ); - -struct golan_detach_mcg_mbox_in { - struct golan_inbox_hdr hdr; - __be32 qpn; - __be32 rsvd; - u8 gid[16]; -} __attribute ( ( packed ) ); - -struct golan_detach_mcg_mbox_out { - struct golan_outbox_hdr hdr; - u8 rsvf[8]; -} __attribute ( ( packed ) ); - - -#define MAILBOX_SIZE sizeof(struct golan_cmd_prot_block) - -#endif /* __CIB_PRM__ */ diff --git a/roms/ipxe/src/drivers/infiniband/arbel.c b/roms/ipxe/src/drivers/infiniband/arbel.c index 9671174c3..2a6c32dec 100644 --- a/roms/ipxe/src/drivers/infiniband/arbel.c +++ b/roms/ipxe/src/drivers/infiniband/arbel.c @@ -897,44 +897,26 @@ static int arbel_create_send_wq ( struct arbel_send_work_queue *arbel_send_wq, * * @v arbel_recv_wq Receive work queue * @v num_wqes Number of work queue entries - * @v type Queue pair type * @ret rc Return status code */ static int arbel_create_recv_wq ( struct arbel_recv_work_queue *arbel_recv_wq, - unsigned int num_wqes, - enum ib_queue_pair_type type ) { + unsigned int num_wqes ) { struct arbelprm_recv_wqe *wqe; struct arbelprm_recv_wqe *next_wqe; unsigned int wqe_idx_mask; size_t nds; unsigned int i; unsigned int j; - int rc; /* Allocate work queue */ arbel_recv_wq->wqe_size = ( num_wqes * sizeof ( arbel_recv_wq->wqe[0] ) ); arbel_recv_wq->wqe = malloc_dma ( arbel_recv_wq->wqe_size, sizeof ( arbel_recv_wq->wqe[0] ) ); - if ( ! arbel_recv_wq->wqe ) { - rc = -ENOMEM; - goto err_alloc_wqe; - } + if ( ! arbel_recv_wq->wqe ) + return -ENOMEM; memset ( arbel_recv_wq->wqe, 0, arbel_recv_wq->wqe_size ); - /* Allocate GRH entries, if needed */ - if ( ( type == IB_QPT_SMI ) || ( type == IB_QPT_GSI ) || - ( type == IB_QPT_UD ) ) { - arbel_recv_wq->grh_size = ( num_wqes * - sizeof ( arbel_recv_wq->grh[0] ) ); - arbel_recv_wq->grh = malloc_dma ( arbel_recv_wq->grh_size, - sizeof ( void * ) ); - if ( ! arbel_recv_wq->grh ) { - rc = -ENOMEM; - goto err_alloc_grh; - } - } - /* Link work queue entries */ wqe_idx_mask = ( num_wqes - 1 ); nds = ( ( offsetof ( typeof ( *wqe ), data ) + @@ -953,12 +935,6 @@ static int arbel_create_recv_wq ( struct arbel_recv_work_queue *arbel_recv_wq, } return 0; - - free_dma ( arbel_recv_wq->grh, arbel_recv_wq->grh_size ); - err_alloc_grh: - free_dma ( arbel_recv_wq->wqe, arbel_recv_wq->wqe_size ); - err_alloc_wqe: - return rc; } /** @@ -1009,8 +985,8 @@ static int arbel_create_qp ( struct ib_device *ibdev, if ( ( rc = arbel_create_send_wq ( &arbel_qp->send, qp->send.num_wqes ) ) != 0 ) goto err_create_send_wq; - if ( ( rc = arbel_create_recv_wq ( &arbel_qp->recv, qp->recv.num_wqes, - qp->type ) ) != 0 ) + if ( ( rc = arbel_create_recv_wq ( &arbel_qp->recv, + qp->recv.num_wqes ) ) != 0 ) goto err_create_recv_wq; /* Send and receive work queue entries must be within the same 4GB */ @@ -1102,7 +1078,6 @@ static int arbel_create_qp ( struct ib_device *ibdev, MLX_FILL_1 ( send_db_rec, 1, res, ARBEL_UAR_RES_NONE ); MLX_FILL_1 ( recv_db_rec, 1, res, ARBEL_UAR_RES_NONE ); err_unsupported_address_split: - free_dma ( arbel_qp->recv.grh, arbel_qp->recv.grh_size ); free_dma ( arbel_qp->recv.wqe, arbel_qp->recv.wqe_size ); err_create_recv_wq: free_dma ( arbel_qp->send.wqe, arbel_qp->send.wqe_size ); @@ -1231,9 +1206,8 @@ static void arbel_destroy_qp ( struct ib_device *ibdev, MLX_FILL_1 ( recv_db_rec, 1, res, ARBEL_UAR_RES_NONE ); /* Free memory */ - free_dma ( arbel_qp->recv.grh, arbel_qp->recv.grh_size ); - free_dma ( arbel_qp->recv.wqe, arbel_qp->recv.wqe_size ); free_dma ( arbel_qp->send.wqe, arbel_qp->send.wqe_size ); + free_dma ( arbel_qp->recv.wqe, arbel_qp->recv.wqe_size ); free ( arbel_qp ); /* Mark queue number as free */ @@ -1503,8 +1477,6 @@ static int arbel_post_recv ( struct ib_device *ibdev, struct ib_work_queue *wq = &qp->recv; struct arbel_recv_work_queue *arbel_recv_wq = &arbel_qp->recv; struct arbelprm_recv_wqe *wqe; - struct arbelprm_wqe_segment_data_ptr *data; - struct ib_global_route_header *grh; union arbelprm_doorbell_record *db_rec; unsigned int wqe_idx_mask; @@ -1519,19 +1491,12 @@ static int arbel_post_recv ( struct ib_device *ibdev, wqe = &arbel_recv_wq->wqe[wq->next_idx & wqe_idx_mask].recv; /* Construct work queue entry */ - data = &wqe->data[0]; - if ( arbel_recv_wq->grh ) { - grh = &arbel_recv_wq->grh[wq->next_idx & wqe_idx_mask]; - MLX_FILL_1 ( data, 0, byte_count, sizeof ( *grh ) ); - MLX_FILL_1 ( data, 1, l_key, arbel->lkey ); - MLX_FILL_H ( data, 2, local_address_h, virt_to_bus ( grh ) ); - MLX_FILL_1 ( data, 3, local_address_l, virt_to_bus ( grh ) ); - data++; - } - MLX_FILL_1 ( data, 0, byte_count, iob_tailroom ( iobuf ) ); - MLX_FILL_1 ( data, 1, l_key, arbel->lkey ); - MLX_FILL_H ( data, 2, local_address_h, virt_to_bus ( iobuf->data ) ); - MLX_FILL_1 ( data, 3, local_address_l, virt_to_bus ( iobuf->data ) ); + MLX_FILL_1 ( &wqe->data[0], 0, byte_count, iob_tailroom ( iobuf ) ); + MLX_FILL_1 ( &wqe->data[0], 1, l_key, arbel->lkey ); + MLX_FILL_H ( &wqe->data[0], 2, + local_address_h, virt_to_bus ( iobuf->data ) ); + MLX_FILL_1 ( &wqe->data[0], 3, + local_address_l, virt_to_bus ( iobuf->data ) ); /* Update doorbell record */ barrier(); @@ -1646,16 +1611,17 @@ static int arbel_complete ( struct ib_device *ibdev, MLX_FILL_1 ( &recv_wqe->data[0], 0, byte_count, 0 ); MLX_FILL_1 ( &recv_wqe->data[0], 1, l_key, ARBEL_INVALID_LKEY ); + assert ( len <= iob_tailroom ( iobuf ) ); + iob_put ( iobuf, len ); memset ( &recv_dest, 0, sizeof ( recv_dest ) ); recv_dest.qpn = qpn; switch ( qp->type ) { case IB_QPT_SMI: case IB_QPT_GSI: case IB_QPT_UD: - /* Locate corresponding GRH */ - assert ( arbel_recv_wq->grh != NULL ); - grh = &arbel_recv_wq->grh[wqe_idx]; - len -= sizeof ( *grh ); + assert ( iob_len ( iobuf ) >= sizeof ( *grh ) ); + grh = iobuf->data; + iob_pull ( iobuf, sizeof ( *grh ) ); /* Construct address vector */ source = &recv_source; memset ( source, 0, sizeof ( *source ) ); @@ -1676,8 +1642,6 @@ static int arbel_complete ( struct ib_device *ibdev, assert ( 0 ); return -EINVAL; } - assert ( len <= iob_tailroom ( iobuf ) ); - iob_put ( iobuf, len ); /* Hand off to completion handler */ ib_complete_recv ( ibdev, qp, &recv_dest, source, iobuf, rc ); } @@ -3036,16 +3000,6 @@ static int arbel_probe ( struct pci_device *pci ) { pci_set_drvdata ( pci, arbel ); arbel->pci = pci; - /* Fix up PCI device */ - adjust_pci_device ( pci ); - - /* Map PCI BARs */ - arbel->config = ioremap ( pci_bar_start ( pci, ARBEL_PCI_CONFIG_BAR ), - ARBEL_PCI_CONFIG_BAR_SIZE ); - arbel->uar = ioremap ( ( pci_bar_start ( pci, ARBEL_PCI_UAR_BAR ) + - ARBEL_PCI_UAR_IDX * ARBEL_PCI_UAR_SIZE ), - ARBEL_PCI_UAR_SIZE ); - /* Allocate Infiniband devices */ for ( i = 0 ; i < ARBEL_NUM_PORTS ; i++ ) { ibdev = alloc_ibdev ( 0 ); @@ -3060,6 +3014,16 @@ static int arbel_probe ( struct pci_device *pci ) { ib_set_drvdata ( ibdev, arbel ); } + /* Fix up PCI device */ + adjust_pci_device ( pci ); + + /* Get PCI BARs */ + arbel->config = ioremap ( pci_bar_start ( pci, ARBEL_PCI_CONFIG_BAR ), + ARBEL_PCI_CONFIG_BAR_SIZE ); + arbel->uar = ioremap ( ( pci_bar_start ( pci, ARBEL_PCI_UAR_BAR ) + + ARBEL_PCI_UAR_IDX * ARBEL_PCI_UAR_SIZE ), + ARBEL_PCI_UAR_SIZE ); + /* Reset device */ arbel_reset ( arbel ); @@ -3108,8 +3072,6 @@ static int arbel_probe ( struct pci_device *pci ) { err_alloc_ibdev: for ( i-- ; i >= 0 ; i-- ) ibdev_put ( arbel->ibdev[i] ); - iounmap ( arbel->uar ); - iounmap ( arbel->config ); arbel_free ( arbel ); err_alloc: return rc; @@ -3128,8 +3090,6 @@ static void arbel_remove ( struct pci_device *pci ) { unregister_ibdev ( arbel->ibdev[i] ); for ( i = ( ARBEL_NUM_PORTS - 1 ) ; i >= 0 ; i-- ) ibdev_put ( arbel->ibdev[i] ); - iounmap ( arbel->uar ); - iounmap ( arbel->config ); arbel_free ( arbel ); } diff --git a/roms/ipxe/src/drivers/infiniband/arbel.h b/roms/ipxe/src/drivers/infiniband/arbel.h index 8a5a996a3..73394cd9a 100644 --- a/roms/ipxe/src/drivers/infiniband/arbel.h +++ b/roms/ipxe/src/drivers/infiniband/arbel.h @@ -237,7 +237,7 @@ struct arbelprm_rc_send_wqe { struct arbelprm_wqe_segment_data_ptr data[ARBEL_MAX_GATHER]; } __attribute__ (( packed )); -#define ARBEL_MAX_SCATTER 2 +#define ARBEL_MAX_SCATTER 1 struct arbelprm_recv_wqe { /* The autogenerated header is inconsistent between send and @@ -369,10 +369,6 @@ struct arbel_recv_work_queue { union arbel_recv_wqe *wqe; /** Size of work queue */ size_t wqe_size; - /** GRH buffers (if applicable) */ - struct ib_global_route_header *grh; - /** Size of GRB buffers */ - size_t grh_size; }; /** Number of special queue pairs */ diff --git a/roms/ipxe/src/drivers/infiniband/flexboot_nodnic.c b/roms/ipxe/src/drivers/infiniband/flexboot_nodnic.c deleted file mode 100644 index dea19ca69..000000000 --- a/roms/ipxe/src/drivers/infiniband/flexboot_nodnic.c +++ /dev/null @@ -1,1479 +0,0 @@ -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include <stdio.h> -#include <unistd.h> -#include <errno.h> -#include <byteswap.h> -#include <ipxe/pci.h> -#include <ipxe/malloc.h> -#include <ipxe/umalloc.h> -#include <ipxe/if_ether.h> -#include <ipxe/ethernet.h> -#include <ipxe/vlan.h> -#include <ipxe/io.h> -#include "flexboot_nodnic.h" -#include "mlx_utils/mlx_lib/mlx_nvconfig/mlx_nvconfig.h" -#include "mlx_utils/mlx_lib/mlx_nvconfig/mlx_nvconfig_defaults.h" -#include "mlx_utils/include/public/mlx_pci_gw.h" -#include "mlx_utils/mlx_lib/mlx_vmac/mlx_vmac.h" -#include "mlx_utils/include/public/mlx_types.h" -#include "mlx_utils/include/public/mlx_utils.h" -#include "mlx_utils/include/public/mlx_bail.h" -#include "mlx_nodnic/include/mlx_cmd.h" -#include "mlx_utils/include/public/mlx_memory.h" -#include "mlx_utils/include/public/mlx_pci.h" -#include "mlx_nodnic/include/mlx_device.h" -#include "mlx_nodnic/include/mlx_port.h" - -/*************************************************************************** - * - * Completion queue operations - * - *************************************************************************** - */ -static int flexboot_nodnic_arm_cq ( struct flexboot_nodnic_port *port ) { -#ifndef DEVICE_CX3 - mlx_uint32 val = ( port->eth_cq->next_idx & 0xffff ); - if ( nodnic_port_set ( & port->port_priv, nodnic_port_option_arm_cq, val ) ) { - MLX_DEBUG_ERROR( port->port_priv.device, "Failed to arm the CQ\n" ); - return MLX_FAILED; - } -#else - mlx_utils *utils = port->port_priv.device->utils; - nodnic_port_data_flow_gw *ptr = port->port_priv.data_flow_gw; - mlx_uint32 data = 0; - mlx_uint32 val = 0; - - if ( port->port_priv.device->device_cap.crspace_doorbells == 0 ) { - val = ( port->eth_cq->next_idx & 0xffff ); - if ( nodnic_port_set ( & port->port_priv, nodnic_port_option_arm_cq, val ) ) { - MLX_DEBUG_ERROR( port->port_priv.device, "Failed to arm the CQ\n" ); - return MLX_FAILED; - } - } else { - /* Arming the CQ with CQ CI should be with this format - - * 16 bit - CQ CI - same endianness as the FW (don't swap bytes) - * 15 bit - reserved - * 1 bit - arm CQ - must correct the endianness with the reserved above */ - data = ( ( ( port->eth_cq->next_idx & 0xffff ) << 16 ) | 0x0080 ); - /* Write the new index and update FW that new data was submitted */ - mlx_pci_mem_write ( utils, MlxPciWidthUint32, 0, - ( mlx_uint64 ) & ( ptr->armcq_cq_ci_dword ), 1, &data ); - } -#endif - return 0; -} - -/** - * Create completion queue - * - * @v ibdev Infiniband device - * @v cq Completion queue - * @ret rc Return status code - */ -static int flexboot_nodnic_create_cq ( struct ib_device *ibdev , - struct ib_completion_queue *cq ) { - struct flexboot_nodnic *flexboot_nodnic = ib_get_drvdata ( ibdev ); - struct flexboot_nodnic_port *port = &flexboot_nodnic->port[ibdev->port - 1]; - struct flexboot_nodnic_completion_queue *flexboot_nodnic_cq; - mlx_status status = MLX_SUCCESS; - - flexboot_nodnic_cq = (struct flexboot_nodnic_completion_queue *) - zalloc(sizeof(*flexboot_nodnic_cq)); - if ( flexboot_nodnic_cq == NULL ) { - status = MLX_OUT_OF_RESOURCES; - goto qp_alloc_err; - } - - status = nodnic_port_create_cq(&port->port_priv, - cq->num_cqes * - flexboot_nodnic->callbacks->get_cqe_size(), - &flexboot_nodnic_cq->nodnic_completion_queue - ); - MLX_FATAL_CHECK_STATUS(status, create_err, - "nodnic_port_create_cq failed"); - flexboot_nodnic->callbacks->cqe_set_owner( - flexboot_nodnic_cq->nodnic_completion_queue->cq_virt, - cq->num_cqes); - - - ib_cq_set_drvdata ( cq, flexboot_nodnic_cq ); - return status; -create_err: - free(flexboot_nodnic_cq); -qp_alloc_err: - return status; -} - -/** - * Destroy completion queue - * - * @v ibdev Infiniband device - * @v cq Completion queue - */ -static void flexboot_nodnic_destroy_cq ( struct ib_device *ibdev , - struct ib_completion_queue *cq ) { - struct flexboot_nodnic *flexboot_nodnic = ib_get_drvdata ( ibdev ); - struct flexboot_nodnic_port *port = &flexboot_nodnic->port[ibdev->port - 1]; - struct flexboot_nodnic_completion_queue *flexboot_nodnic_cq = ib_cq_get_drvdata ( cq ); - - nodnic_port_destroy_cq(&port->port_priv, - flexboot_nodnic_cq->nodnic_completion_queue); - - free(flexboot_nodnic_cq); -} - -static -struct ib_work_queue * flexboot_nodnic_find_wq ( struct ib_device *ibdev , - struct ib_completion_queue *cq, - unsigned long qpn, int is_send ) { - struct ib_work_queue *wq; - struct flexboot_nodnic_queue_pair *flexboot_nodnic_qp; - struct flexboot_nodnic *flexboot_nodnic = ib_get_drvdata ( ibdev ); - struct flexboot_nodnic_port *port = &flexboot_nodnic->port[ibdev->port - 1]; - struct nodnic_ring *ring; - mlx_uint32 out_qpn; - list_for_each_entry ( wq, &cq->work_queues, list ) { - flexboot_nodnic_qp = ib_qp_get_drvdata ( wq->qp ); - if( wq->is_send == is_send && wq->is_send == TRUE ) { - ring = &flexboot_nodnic_qp->nodnic_queue_pair->send.nodnic_ring; - } else if( wq->is_send == is_send && wq->is_send == FALSE ) { - ring = &flexboot_nodnic_qp->nodnic_queue_pair->receive.nodnic_ring; - } else { - continue; - } - nodnic_port_get_qpn(&port->port_priv, ring, &out_qpn); - if ( out_qpn == qpn ) - return wq; - } - return NULL; -} - -/** - * Handle completion - * - * @v ibdev Infiniband device - * @v cq Completion queue - * @v cqe Hardware completion queue entry - * @ret rc Return status code - */ -static int flexboot_nodnic_complete ( struct ib_device *ibdev, - struct ib_completion_queue *cq, - struct cqe_data *cqe_data ) { - struct flexboot_nodnic *flexboot_nodnic = ib_get_drvdata ( ibdev ); - struct ib_work_queue *wq; - struct ib_queue_pair *qp; - struct io_buffer *iobuf; - struct ib_address_vector recv_dest; - struct ib_address_vector recv_source; - unsigned long qpn; - unsigned long wqe_idx; - unsigned long wqe_idx_mask; - size_t len; - int rc = 0; - - /* Parse completion */ - qpn = cqe_data->qpn; - - if ( cqe_data->is_error == TRUE ) { - DBGC ( flexboot_nodnic, "flexboot_nodnic %p CQN %#lx syndrome %x vendor %x\n", - flexboot_nodnic, cq->cqn, cqe_data->syndrome, - cqe_data->vendor_err_syndrome ); - rc = -EIO; - /* Don't return immediately; propagate error to completer */ - } - - /* Identify work queue */ - wq = flexboot_nodnic_find_wq( ibdev, cq, qpn, cqe_data->is_send ); - if ( wq == NULL ) { - DBGC ( flexboot_nodnic, - "flexboot_nodnic %p CQN %#lx unknown %s QPN %#lx\n", - flexboot_nodnic, cq->cqn, - ( cqe_data->is_send ? "send" : "recv" ), qpn ); - return -EIO; - } - qp = wq->qp; - - /* Identify work queue entry */ - wqe_idx = cqe_data->wqe_counter; - wqe_idx_mask = ( wq->num_wqes - 1 ); - DBGCP ( flexboot_nodnic, - "NODNIC %p CQN %#lx QPN %#lx %s WQE %#lx completed:\n", - flexboot_nodnic, cq->cqn, qp->qpn, - ( cqe_data->is_send ? "send" : "recv" ), - wqe_idx ); - - /* Identify I/O buffer */ - iobuf = wq->iobufs[wqe_idx & wqe_idx_mask]; - if ( iobuf == NULL ) { - DBGC ( flexboot_nodnic, - "NODNIC %p CQN %#lx QPN %#lx empty %s WQE %#lx\n", - flexboot_nodnic, cq->cqn, qp->qpn, - ( cqe_data->is_send ? "send" : "recv" ), wqe_idx ); - return -EIO; - } - wq->iobufs[wqe_idx & wqe_idx_mask] = NULL; - - if ( cqe_data->is_send == TRUE ) { - /* Hand off to completion handler */ - ib_complete_send ( ibdev, qp, iobuf, rc ); - } else if ( rc != 0 ) { - /* Propagate error to receive completion handler */ - ib_complete_recv ( ibdev, qp, NULL, NULL, iobuf, rc ); - } else { - /* Set received length */ - len = cqe_data->byte_cnt; - assert ( len <= iob_tailroom ( iobuf ) ); - iob_put ( iobuf, len ); - memset ( &recv_dest, 0, sizeof ( recv_dest ) ); - recv_dest.qpn = qpn; - memset ( &recv_source, 0, sizeof ( recv_source ) ); - switch ( qp->type ) { - case IB_QPT_SMI: - case IB_QPT_GSI: - case IB_QPT_UD: - case IB_QPT_RC: - break; - case IB_QPT_ETH: - break; - default: - assert ( 0 ); - return -EINVAL; - } - /* Hand off to completion handler */ - ib_complete_recv ( ibdev, qp, &recv_dest, - &recv_source, iobuf, rc ); - } - - return rc; -} -/** - * Poll completion queue - * - * @v ibdev Infiniband device - * @v cq Completion queues - */ -static void flexboot_nodnic_poll_cq ( struct ib_device *ibdev, - struct ib_completion_queue *cq) { - struct flexboot_nodnic *flexboot_nodnic = ib_get_drvdata ( ibdev ); - struct flexboot_nodnic_completion_queue *flexboot_nodnic_cq = ib_cq_get_drvdata ( cq ); - void *cqe; - mlx_size cqe_size; - struct cqe_data cqe_data; - unsigned int cqe_idx_mask; - int rc; - - cqe_size = flexboot_nodnic->callbacks->get_cqe_size(); - while ( TRUE ) { - /* Look for completion entry */ - cqe_idx_mask = ( cq->num_cqes - 1 ); - cqe = ((uint8_t *)flexboot_nodnic_cq->nodnic_completion_queue->cq_virt) + - cqe_size * (cq->next_idx & cqe_idx_mask); - - /* TODO: check fill_completion */ - flexboot_nodnic->callbacks->fill_completion(cqe, &cqe_data); - if ( cqe_data.owner ^ - ( ( cq->next_idx & cq->num_cqes ) ? 1 : 0 ) ) { - /* Entry still owned by hardware; end of poll */ - break; - } - /* Handle completion */ - rc = flexboot_nodnic_complete ( ibdev, cq, &cqe_data ); - if ( rc != 0 ) { - DBGC ( flexboot_nodnic, "flexboot_nodnic %p CQN %#lx failed to complete: %s\n", - flexboot_nodnic, cq->cqn, strerror ( rc ) ); - DBGC_HDA ( flexboot_nodnic, virt_to_phys ( cqe ), - cqe, sizeof ( *cqe ) ); - } - - /* Update completion queue's index */ - cq->next_idx++; - } -} -/*************************************************************************** - * - * Queue pair operations - * - *************************************************************************** - */ - - -/** - * Create queue pair - * - * @v ibdev Infiniband device - * @v qp Queue pair - * @ret rc Return status code - */ -static int flexboot_nodnic_create_qp ( struct ib_device *ibdev, - struct ib_queue_pair *qp ) { - struct flexboot_nodnic *flexboot_nodnic = ib_get_drvdata ( ibdev ); - struct flexboot_nodnic_port *port = &flexboot_nodnic->port[ibdev->port - 1]; - struct flexboot_nodnic_queue_pair *flexboot_nodnic_qp; - mlx_status status = MLX_SUCCESS; - - flexboot_nodnic_qp = (struct flexboot_nodnic_queue_pair *)zalloc(sizeof(*flexboot_nodnic_qp)); - if ( flexboot_nodnic_qp == NULL ) { - status = MLX_OUT_OF_RESOURCES; - goto qp_alloc_err; - } - - status = nodnic_port_create_qp(&port->port_priv, qp->type, - qp->send.num_wqes * sizeof(struct nodnic_send_wqbb), - qp->send.num_wqes, - qp->recv.num_wqes * sizeof(struct nodnic_recv_wqe), - qp->recv.num_wqes, - &flexboot_nodnic_qp->nodnic_queue_pair); - MLX_FATAL_CHECK_STATUS(status, create_err, - "nodnic_port_create_qp failed"); - ib_qp_set_drvdata ( qp, flexboot_nodnic_qp ); - return status; -create_err: - free(flexboot_nodnic_qp); -qp_alloc_err: - return status; -} - -/** - * Modify queue pair - * - * @v ibdev Infiniband device - * @v qp Queue pair - * @ret rc Return status code - */ -static int flexboot_nodnic_modify_qp ( struct ib_device *ibdev __unused, - struct ib_queue_pair *qp __unused) { - /*not needed*/ - return 0; -} - -/** - * Destroy queue pair - * - * @v ibdev Infiniband device - * @v qp Queue pair - */ -static void flexboot_nodnic_destroy_qp ( struct ib_device *ibdev, - struct ib_queue_pair *qp ) { - struct flexboot_nodnic *flexboot_nodnic = ib_get_drvdata ( ibdev ); - struct flexboot_nodnic_port *port = &flexboot_nodnic->port[ibdev->port - 1]; - struct flexboot_nodnic_queue_pair *flexboot_nodnic_qp = ib_qp_get_drvdata ( qp ); - - nodnic_port_destroy_qp(&port->port_priv, qp->type, - flexboot_nodnic_qp->nodnic_queue_pair); - - free(flexboot_nodnic_qp); -} - -/*************************************************************************** - * - * Work request operations - * - *************************************************************************** - */ - -/** - * Post send work queue entry - * - * @v ibdev Infiniband device - * @v qp Queue pair - * @v av Address vector - * @v iobuf I/O buffer - * @ret rc Return status code - */ -static int flexboot_nodnic_post_send ( struct ib_device *ibdev, - struct ib_queue_pair *qp, - struct ib_address_vector *av, - struct io_buffer *iobuf) { - - struct flexboot_nodnic *flexboot_nodnic = ib_get_drvdata ( ibdev ); - struct flexboot_nodnic_queue_pair *flexboot_nodnic_qp = ib_qp_get_drvdata ( qp ); - struct flexboot_nodnic_port *port = &flexboot_nodnic->port[ibdev->port - 1]; - struct ib_work_queue *wq = &qp->send; - struct nodnic_send_wqbb *wqbb; - nodnic_qp *nodnic_qp = flexboot_nodnic_qp->nodnic_queue_pair; - struct nodnic_send_ring *send_ring = &nodnic_qp->send; - mlx_status status = MLX_SUCCESS; - unsigned int wqe_idx_mask; - unsigned long wqe_idx; - - if ( ( port->port_priv.dma_state == FALSE ) || - ( port->port_priv.port_state & NODNIC_PORT_DISABLING_DMA ) ) { - DBGC ( flexboot_nodnic, "flexboot_nodnic DMA disabled\n"); - status = -ENETDOWN; - goto post_send_done; - } - - /* Allocate work queue entry */ - wqe_idx = wq->next_idx; - wqe_idx_mask = ( wq->num_wqes - 1 ); - if ( wq->iobufs[wqe_idx & wqe_idx_mask] ) { - DBGC ( flexboot_nodnic, "flexboot_nodnic %p QPN %#lx send queue full\n", - flexboot_nodnic, qp->qpn ); - status = -ENOBUFS; - goto post_send_done; - } - wqbb = &send_ring->wqe_virt[wqe_idx & wqe_idx_mask]; - wq->iobufs[wqe_idx & wqe_idx_mask] = iobuf; - - assert ( flexboot_nodnic->callbacks-> - fill_send_wqe[qp->type] != NULL ); - status = flexboot_nodnic->callbacks-> - fill_send_wqe[qp->type] ( ibdev, qp, av, iobuf, - wqbb, wqe_idx ); - if ( status != 0 ) { - DBGC ( flexboot_nodnic, "flexboot_nodnic %p QPN %#lx fill send wqe failed\n", - flexboot_nodnic, qp->qpn ); - goto post_send_done; - } - - wq->next_idx++; - - status = port->port_priv.send_doorbell ( &port->port_priv, - &send_ring->nodnic_ring, ( mlx_uint16 ) wq->next_idx ); - if ( status != 0 ) { - DBGC ( flexboot_nodnic, "flexboot_nodnic %p ring send doorbell failed\n", flexboot_nodnic ); - } - -post_send_done: - return status; -} - -/** - * Post receive work queue entry - * - * @v ibdev Infiniband device - * @v qp Queue pair - * @v iobuf I/O buffer - * @ret rc Return status code - */ -static int flexboot_nodnic_post_recv ( struct ib_device *ibdev, - struct ib_queue_pair *qp, - struct io_buffer *iobuf ) { - struct flexboot_nodnic *flexboot_nodnic = ib_get_drvdata ( ibdev ); - struct flexboot_nodnic_queue_pair *flexboot_nodnic_qp = ib_qp_get_drvdata ( qp ); - struct flexboot_nodnic_port *port = &flexboot_nodnic->port[ibdev->port - 1]; - struct ib_work_queue *wq = &qp->recv; - nodnic_qp *nodnic_qp = flexboot_nodnic_qp->nodnic_queue_pair; - struct nodnic_recv_ring *recv_ring = &nodnic_qp->receive; - struct nodnic_recv_wqe *wqe; - unsigned int wqe_idx_mask; - mlx_status status = MLX_SUCCESS; - - /* Allocate work queue entry */ - wqe_idx_mask = ( wq->num_wqes - 1 ); - if ( wq->iobufs[wq->next_idx & wqe_idx_mask] ) { - DBGC ( flexboot_nodnic, - "flexboot_nodnic %p QPN %#lx receive queue full\n", - flexboot_nodnic, qp->qpn ); - status = -ENOBUFS; - goto post_recv_done; - } - wq->iobufs[wq->next_idx & wqe_idx_mask] = iobuf; - wqe = &((struct nodnic_recv_wqe*)recv_ring->wqe_virt)[wq->next_idx & wqe_idx_mask]; - - MLX_FILL_1 ( &wqe->data[0], 0, byte_count, iob_tailroom ( iobuf ) ); - MLX_FILL_1 ( &wqe->data[0], 1, l_key, flexboot_nodnic->device_priv.lkey ); - MLX_FILL_H ( &wqe->data[0], 2, - local_address_h, virt_to_bus ( iobuf->data ) ); - MLX_FILL_1 ( &wqe->data[0], 3, - local_address_l, virt_to_bus ( iobuf->data ) ); - - wq->next_idx++; - - status = port->port_priv.recv_doorbell ( &port->port_priv, - &recv_ring->nodnic_ring, ( mlx_uint16 ) wq->next_idx ); - if ( status != 0 ) { - DBGC ( flexboot_nodnic, "flexboot_nodnic %p ring receive doorbell failed\n", flexboot_nodnic ); - } -post_recv_done: - return status; -} - -/*************************************************************************** - * - * Event queues - * - *************************************************************************** - */ - -static void flexboot_nodnic_poll_eq ( struct ib_device *ibdev ) { - struct flexboot_nodnic *flexboot_nodnic; - struct flexboot_nodnic_port *port; - struct net_device *netdev; - nodnic_port_state state = 0; - mlx_status status; - - if ( ! ibdev ) { - DBG ( "%s: ibdev = NULL!!!\n", __FUNCTION__ ); - return; - } - - flexboot_nodnic = ib_get_drvdata ( ibdev ); - port = &flexboot_nodnic->port[ibdev->port - 1]; - netdev = port->netdev; - - if ( ! netdev_is_open ( netdev ) ) { - DBG2( "%s: port %d is closed\n", __FUNCTION__, port->ibdev->port ); - return; - } - - /* we don't poll EQ. Just poll link status if it's not active */ - if ( ! netdev_link_ok ( netdev ) ) { - status = nodnic_port_get_state ( &port->port_priv, &state ); - MLX_FATAL_CHECK_STATUS(status, state_err, "nodnic_port_get_state failed"); - - if ( state == nodnic_port_state_active ) { - DBG( "%s: port %d physical link is up\n", __FUNCTION__, - port->ibdev->port ); - port->type->state_change ( flexboot_nodnic, port, 1 ); - } - } -state_err: - return; -} - -/*************************************************************************** - * - * Multicast group operations - * - *************************************************************************** - */ -static int flexboot_nodnic_mcast_attach ( struct ib_device *ibdev, - struct ib_queue_pair *qp, - union ib_gid *gid) { - struct flexboot_nodnic *flexboot_nodnic = ib_get_drvdata ( ibdev ); - struct flexboot_nodnic_port *port = &flexboot_nodnic->port[ibdev->port - 1]; - mlx_mac_address mac; - mlx_status status = MLX_SUCCESS; - - switch (qp->type) { - case IB_QPT_ETH: - memcpy(&mac, &gid, sizeof(mac)); - status = nodnic_port_add_mac_filter(&port->port_priv, mac); - MLX_CHECK_STATUS(flexboot_nodnic->device_priv, status, mac_err, - "nodnic_port_add_mac_filter failed"); - break; - default: - break; - } -mac_err: - return status; -} -static void flexboot_nodnic_mcast_detach ( struct ib_device *ibdev, - struct ib_queue_pair *qp, - union ib_gid *gid ) { - struct flexboot_nodnic *flexboot_nodnic = ib_get_drvdata ( ibdev ); - struct flexboot_nodnic_port *port = &flexboot_nodnic->port[ibdev->port - 1]; - mlx_mac_address mac; - mlx_status status = MLX_SUCCESS; - - switch (qp->type) { - case IB_QPT_ETH: - memcpy(&mac, &gid, sizeof(mac)); - status = nodnic_port_remove_mac_filter(&port->port_priv, mac); - MLX_CHECK_STATUS(flexboot_nodnic->device_priv, status, mac_err, - "nodnic_port_remove_mac_filter failed"); - break; - default: - break; - } -mac_err: - return; -} -/*************************************************************************** - * - * Infiniband link-layer operations - * - *************************************************************************** - */ - -/** - * Initialise Infiniband link - * - * @v ibdev Infiniband device - * @ret rc Return status code - */ -static int flexboot_nodnic_ib_open ( struct ib_device *ibdev __unused) { - int rc = 0; - - /*TODO: add implementation*/ - return rc; -} - -/** - * Close Infiniband link - * - * @v ibdev Infiniband device - */ -static void flexboot_nodnic_ib_close ( struct ib_device *ibdev __unused) { - /*TODO: add implementation*/ -} - -/** - * Inform embedded subnet management agent of a received MAD - * - * @v ibdev Infiniband device - * @v mad MAD - * @ret rc Return status code - */ -static int flexboot_nodnic_inform_sma ( struct ib_device *ibdev __unused, - union ib_mad *mad __unused) { - /*TODO: add implementation*/ - return 0; -} - -/** flexboot_nodnic Infiniband operations */ -static struct ib_device_operations flexboot_nodnic_ib_operations = { - .create_cq = flexboot_nodnic_create_cq, - .destroy_cq = flexboot_nodnic_destroy_cq, - .create_qp = flexboot_nodnic_create_qp, - .modify_qp = flexboot_nodnic_modify_qp, - .destroy_qp = flexboot_nodnic_destroy_qp, - .post_send = flexboot_nodnic_post_send, - .post_recv = flexboot_nodnic_post_recv, - .poll_cq = flexboot_nodnic_poll_cq, - .poll_eq = flexboot_nodnic_poll_eq, - .open = flexboot_nodnic_ib_open, - .close = flexboot_nodnic_ib_close, - .mcast_attach = flexboot_nodnic_mcast_attach, - .mcast_detach = flexboot_nodnic_mcast_detach, - .set_port_info = flexboot_nodnic_inform_sma, - .set_pkey_table = flexboot_nodnic_inform_sma, -}; -/*************************************************************************** - * - * - * - *************************************************************************** - */ - -#define FLEX_NODNIC_TX_POLL_TOUT 500000 -#define FLEX_NODNIC_TX_POLL_USLEEP 10 - -static void flexboot_nodnic_complete_all_tx ( struct flexboot_nodnic_port *port ) { - struct ib_device *ibdev = port->ibdev; - struct ib_completion_queue *cq; - struct ib_work_queue *wq; - int keep_polling = 0; - int timeout = FLEX_NODNIC_TX_POLL_TOUT; - - list_for_each_entry ( cq, &ibdev->cqs, list ) { - do { - ib_poll_cq ( ibdev, cq ); - keep_polling = 0; - list_for_each_entry ( wq, &cq->work_queues, list ) { - if ( wq->is_send ) - keep_polling += ( wq->fill > 0 ); - } - udelay ( FLEX_NODNIC_TX_POLL_USLEEP ); - } while ( keep_polling && ( timeout-- > 0 ) ); - } -} - -static void flexboot_nodnic_port_disable_dma ( struct flexboot_nodnic_port *port ) { - nodnic_port_priv *port_priv = & ( port->port_priv ); - mlx_status status; - - if ( ! ( port_priv->port_state & NODNIC_PORT_OPENED ) ) - return; - - port_priv->port_state |= NODNIC_PORT_DISABLING_DMA; - flexboot_nodnic_complete_all_tx ( port ); - if ( ( status = nodnic_port_disable_dma ( port_priv ) ) ) { - MLX_DEBUG_WARN ( port, "Failed to disable DMA %d\n", status ); - } - - port_priv->port_state &= ~NODNIC_PORT_DISABLING_DMA; -} - -/*************************************************************************** - * - * Ethernet operation - * - *************************************************************************** - */ - -/** Number of flexboot_nodnic Ethernet send work queue entries */ -#define FLEXBOOT_NODNIC_ETH_NUM_SEND_WQES 64 - -/** Number of flexboot_nodnic Ethernet receive work queue entries */ -#define FLEXBOOT_NODNIC_ETH_NUM_RECV_WQES 64 -/** flexboot nodnic Ethernet queue pair operations */ -static struct ib_queue_pair_operations flexboot_nodnic_eth_qp_op = { - .alloc_iob = alloc_iob, -}; - -/** - * Transmit packet via flexboot_nodnic Ethernet device - * - * @v netdev Network device - * @v iobuf I/O buffer - * @ret rc Return status code - */ -static int flexboot_nodnic_eth_transmit ( struct net_device *netdev, - struct io_buffer *iobuf) { - struct flexboot_nodnic_port *port = netdev->priv; - struct ib_device *ibdev = port->ibdev; - struct flexboot_nodnic *flexboot_nodnic = ib_get_drvdata ( ibdev ); - int rc; - - rc = ib_post_send ( ibdev, port->eth_qp, NULL, iobuf); - /* Transmit packet */ - if ( rc != 0) { - DBGC ( flexboot_nodnic, "NODNIC %p port %d could not transmit: %s\n", - flexboot_nodnic, ibdev->port, strerror ( rc ) ); - return rc; - } - - return 0; -} - -/** - * Handle flexboot_nodnic Ethernet device send completion - * - * @v ibdev Infiniband device - * @v qp Queue pair - * @v iobuf I/O buffer - * @v rc Completion status code - */ -static void flexboot_nodnic_eth_complete_send ( struct ib_device *ibdev __unused, - struct ib_queue_pair *qp, - struct io_buffer *iobuf, - int rc) { - struct net_device *netdev = ib_qp_get_ownerdata ( qp ); - - netdev_tx_complete_err ( netdev, iobuf, rc ); -} - -/** - * Handle flexboot_nodnic Ethernet device receive completion - * - * @v ibdev Infiniband device - * @v qp Queue pair - * @v av Address vector, or NULL - * @v iobuf I/O buffer - * @v rc Completion status code - */ -static void flexboot_nodnic_eth_complete_recv ( struct ib_device *ibdev __unused, - struct ib_queue_pair *qp, - struct ib_address_vector *dest __unused, - struct ib_address_vector *source, - struct io_buffer *iobuf, - int rc) { - struct net_device *netdev = ib_qp_get_ownerdata ( qp ); - - if ( rc != 0 ) { - DBG ( "Received packet with error\n" ); - netdev_rx_err ( netdev, iobuf, rc ); - return; - } - - if ( source == NULL ) { - DBG ( "Received packet without address vector\n" ); - netdev_rx_err ( netdev, iobuf, -ENOTTY ); - return; - } - netdev_rx ( netdev, iobuf ); -} - -/** flexboot_nodnic Ethernet device completion operations */ -static struct ib_completion_queue_operations flexboot_nodnic_eth_cq_op = { - .complete_send = flexboot_nodnic_eth_complete_send, - .complete_recv = flexboot_nodnic_eth_complete_recv, -}; - -/** - * Poll flexboot_nodnic Ethernet device - * - * @v netdev Network device - */ -static void flexboot_nodnic_eth_poll ( struct net_device *netdev) { - struct flexboot_nodnic_port *port = netdev->priv; - struct ib_device *ibdev = port->ibdev; - - ib_poll_eq ( ibdev ); -} - -/** - * Open flexboot_nodnic Ethernet device - * - * @v netdev Network device - * @ret rc Return status code - */ -static int flexboot_nodnic_eth_open ( struct net_device *netdev ) { - struct flexboot_nodnic_port *port = netdev->priv; - struct ib_device *ibdev = port->ibdev; - struct flexboot_nodnic *flexboot_nodnic = ib_get_drvdata ( ibdev ); - mlx_status status = MLX_SUCCESS; - struct ib_completion_queue *dummy_cq = NULL; - struct flexboot_nodnic_queue_pair *flexboot_nodnic_qp = NULL; - mlx_uint64 cq_size = 0; - mlx_uint32 qpn = 0; - nodnic_port_state state = nodnic_port_state_down; - - if ( port->port_priv.port_state & NODNIC_PORT_OPENED ) { - DBGC ( flexboot_nodnic, "%s: port %d is already opened\n", - __FUNCTION__, port->ibdev->port ); - return 0; - } - - port->port_priv.port_state |= NODNIC_PORT_OPENED; - - dummy_cq = zalloc ( sizeof ( struct ib_completion_queue ) ); - if ( dummy_cq == NULL ) { - DBGC ( flexboot_nodnic, "%s: Failed to allocate dummy CQ\n", __FUNCTION__ ); - status = MLX_OUT_OF_RESOURCES; - goto err_create_dummy_cq; - } - INIT_LIST_HEAD ( &dummy_cq->work_queues ); - - port->eth_qp = ib_create_qp ( ibdev, IB_QPT_ETH, - FLEXBOOT_NODNIC_ETH_NUM_SEND_WQES, dummy_cq, - FLEXBOOT_NODNIC_ETH_NUM_RECV_WQES, dummy_cq, - &flexboot_nodnic_eth_qp_op, netdev->name ); - if ( !port->eth_qp ) { - DBGC ( flexboot_nodnic, "flexboot_nodnic %p port %d could not create queue pair\n", - flexboot_nodnic, ibdev->port ); - status = MLX_OUT_OF_RESOURCES; - goto err_create_qp; - } - - ib_qp_set_ownerdata ( port->eth_qp, netdev ); - - status = nodnic_port_get_cq_size(&port->port_priv, &cq_size); - MLX_FATAL_CHECK_STATUS(status, get_cq_size_err, - "nodnic_port_get_cq_size failed"); - - port->eth_cq = ib_create_cq ( ibdev, cq_size, - &flexboot_nodnic_eth_cq_op ); - if ( !port->eth_cq ) { - DBGC ( flexboot_nodnic, - "flexboot_nodnic %p port %d could not create completion queue\n", - flexboot_nodnic, ibdev->port ); - status = MLX_OUT_OF_RESOURCES; - goto err_create_cq; - } - port->eth_qp->send.cq = port->eth_cq; - list_del(&port->eth_qp->send.list); - list_add ( &port->eth_qp->send.list, &port->eth_cq->work_queues ); - port->eth_qp->recv.cq = port->eth_cq; - list_del(&port->eth_qp->recv.list); - list_add ( &port->eth_qp->recv.list, &port->eth_cq->work_queues ); - - status = nodnic_port_allocate_eq(&port->port_priv, - flexboot_nodnic->device_priv.device_cap.log_working_buffer_size); - MLX_FATAL_CHECK_STATUS(status, eq_alloc_err, - "nodnic_port_allocate_eq failed"); - - status = nodnic_port_init(&port->port_priv); - MLX_FATAL_CHECK_STATUS(status, init_err, - "nodnic_port_init failed"); - - /* update qp - qpn */ - flexboot_nodnic_qp = ib_qp_get_drvdata ( port->eth_qp ); - status = nodnic_port_get_qpn(&port->port_priv, - &flexboot_nodnic_qp->nodnic_queue_pair->send.nodnic_ring, - &qpn); - MLX_FATAL_CHECK_STATUS(status, qpn_err, - "nodnic_port_get_qpn failed"); - port->eth_qp->qpn = qpn; - - /* Fill receive rings */ - ib_refill_recv ( ibdev, port->eth_qp ); - - status = nodnic_port_enable_dma(&port->port_priv); - MLX_FATAL_CHECK_STATUS(status, dma_err, - "nodnic_port_enable_dma failed"); - - if (flexboot_nodnic->device_priv.device_cap.support_promisc_filter) { - status = nodnic_port_set_promisc(&port->port_priv, TRUE); - MLX_FATAL_CHECK_STATUS(status, promisc_err, - "nodnic_port_set_promisc failed"); - } - - status = nodnic_port_get_state(&port->port_priv, &state); - MLX_FATAL_CHECK_STATUS(status, state_err, - "nodnic_port_get_state failed"); - - port->type->state_change ( - flexboot_nodnic, port, state == nodnic_port_state_active ); - - DBGC ( flexboot_nodnic, "%s: port %d opened (link is %s)\n", - __FUNCTION__, port->ibdev->port, - ( ( state == nodnic_port_state_active ) ? "Up" : "Down" ) ); - - free(dummy_cq); - return 0; -state_err: -promisc_err: -dma_err: -qpn_err: - nodnic_port_close(&port->port_priv); -init_err: - nodnic_port_free_eq(&port->port_priv); -eq_alloc_err: -err_create_cq: -get_cq_size_err: - ib_destroy_qp(ibdev, port->eth_qp ); -err_create_qp: - free(dummy_cq); -err_create_dummy_cq: - port->port_priv.port_state &= ~NODNIC_PORT_OPENED; - return status; -} - -/** - * Close flexboot_nodnic Ethernet device - * - * @v netdev Network device - */ -static void flexboot_nodnic_eth_close ( struct net_device *netdev) { - struct flexboot_nodnic_port *port = netdev->priv; - struct ib_device *ibdev = port->ibdev; - struct flexboot_nodnic *flexboot_nodnic = ib_get_drvdata ( ibdev ); - mlx_status status = MLX_SUCCESS; - - if ( ! ( port->port_priv.port_state & NODNIC_PORT_OPENED ) ) { - DBGC ( flexboot_nodnic, "%s: port %d is already closed\n", - __FUNCTION__, port->ibdev->port ); - return; - } - - if (flexboot_nodnic->device_priv.device_cap.support_promisc_filter) { - if ( ( status = nodnic_port_set_promisc( &port->port_priv, FALSE ) ) ) { - DBGC ( flexboot_nodnic, - "nodnic_port_set_promisc failed (status = %d)\n", status ); - } - } - - flexboot_nodnic_port_disable_dma ( port ); - - port->port_priv.port_state &= ~NODNIC_PORT_OPENED; - - port->type->state_change ( flexboot_nodnic, port, FALSE ); - - /* Close port */ - status = nodnic_port_close(&port->port_priv); - if ( status != MLX_SUCCESS ) { - DBGC ( flexboot_nodnic, "flexboot_nodnic %p port %d could not close port: %s\n", - flexboot_nodnic, ibdev->port, strerror ( status ) ); - /* Nothing we can do about this */ - } - - ib_destroy_qp ( ibdev, port->eth_qp ); - port->eth_qp = NULL; - ib_destroy_cq ( ibdev, port->eth_cq ); - port->eth_cq = NULL; - - nodnic_port_free_eq(&port->port_priv); - - DBGC ( flexboot_nodnic, "%s: port %d closed\n", __FUNCTION__, port->ibdev->port ); -} - -void flexboot_nodnic_eth_irq ( struct net_device *netdev, int enable ) { - struct flexboot_nodnic_port *port = netdev->priv; - - if ( enable ) { - if ( ( port->port_priv.port_state & NODNIC_PORT_OPENED ) && - ! ( port->port_priv.port_state & NODNIC_PORT_DISABLING_DMA ) ) { - flexboot_nodnic_arm_cq ( port ); - } else { - /* do nothing */ - } - } else { - nodnic_device_clear_int( port->port_priv.device ); - } -} - -/** flexboot_nodnic Ethernet network device operations */ -static struct net_device_operations flexboot_nodnic_eth_operations = { - .open = flexboot_nodnic_eth_open, - .close = flexboot_nodnic_eth_close, - .transmit = flexboot_nodnic_eth_transmit, - .poll = flexboot_nodnic_eth_poll, -}; - -/** - * Register flexboot_nodnic Ethernet device - */ -static int flexboot_nodnic_register_netdev ( struct flexboot_nodnic *flexboot_nodnic, - struct flexboot_nodnic_port *port) { - mlx_status status = MLX_SUCCESS; - struct net_device *netdev; - struct ib_device *ibdev = port->ibdev; - union { - uint8_t bytes[8]; - uint32_t dwords[2]; - } mac; - - /* Allocate network devices */ - netdev = alloc_etherdev ( 0 ); - if ( netdev == NULL ) { - DBGC ( flexboot_nodnic, "flexboot_nodnic %p port %d could not allocate net device\n", - flexboot_nodnic, ibdev->port ); - status = MLX_OUT_OF_RESOURCES; - goto alloc_err; - } - port->netdev = netdev; - netdev_init ( netdev, &flexboot_nodnic_eth_operations ); - netdev->dev = ibdev->dev; - netdev->priv = port; - - status = nodnic_port_query(&port->port_priv, - nodnic_port_option_mac_high, - &mac.dwords[0]); - MLX_FATAL_CHECK_STATUS(status, mac_err, - "failed to query mac high"); - status = nodnic_port_query(&port->port_priv, - nodnic_port_option_mac_low, - &mac.dwords[1]); - MLX_FATAL_CHECK_STATUS(status, mac_err, - "failed to query mac low"); - mac.dwords[0] = htonl(mac.dwords[0]); - mac.dwords[1] = htonl(mac.dwords[1]); - memcpy ( netdev->hw_addr, - &mac.bytes[2], ETH_ALEN); - /* Register network device */ - status = register_netdev ( netdev ); - if ( status != MLX_SUCCESS ) { - DBGC ( flexboot_nodnic, - "flexboot_nodnic %p port %d could not register network device: %s\n", - flexboot_nodnic, ibdev->port, strerror ( status ) ); - goto reg_err; - } - return status; -reg_err: -mac_err: - netdev_put ( netdev ); -alloc_err: - return status; -} - -/** - * Handle flexboot_nodnic Ethernet device port state change - */ -static void flexboot_nodnic_state_change_netdev ( struct flexboot_nodnic *flexboot_nodnic __unused, - struct flexboot_nodnic_port *port, - int link_up ) { - struct net_device *netdev = port->netdev; - - if ( link_up ) - netdev_link_up ( netdev ); - else - netdev_link_down ( netdev ); - -} - -/** - * Unregister flexboot_nodnic Ethernet device - */ -static void flexboot_nodnic_unregister_netdev ( struct flexboot_nodnic *flexboot_nodnic __unused, - struct flexboot_nodnic_port *port ) { - struct net_device *netdev = port->netdev; - unregister_netdev ( netdev ); - netdev_nullify ( netdev ); - netdev_put ( netdev ); -} - -/** flexboot_nodnic Ethernet port type */ -static struct flexboot_nodnic_port_type flexboot_nodnic_port_type_eth = { - .register_dev = flexboot_nodnic_register_netdev, - .state_change = flexboot_nodnic_state_change_netdev, - .unregister_dev = flexboot_nodnic_unregister_netdev, -}; - -/*************************************************************************** - * - * PCI interface helper functions - * - *************************************************************************** - */ -static -mlx_status -flexboot_nodnic_allocate_infiniband_devices( struct flexboot_nodnic *flexboot_nodnic_priv ) { - mlx_status status = MLX_SUCCESS; - nodnic_device_priv *device_priv = &flexboot_nodnic_priv->device_priv; - struct pci_device *pci = flexboot_nodnic_priv->pci; - struct ib_device *ibdev = NULL; - unsigned int i = 0; - - /* Allocate Infiniband devices */ - for (; i < device_priv->device_cap.num_ports; i++) { - if ( ! ( flexboot_nodnic_priv->port_mask & ( i + 1 ) ) ) - continue; - ibdev = alloc_ibdev(0); - if (ibdev == NULL) { - status = MLX_OUT_OF_RESOURCES; - goto err_alloc_ibdev; - } - flexboot_nodnic_priv->port[i].ibdev = ibdev; - ibdev->op = &flexboot_nodnic_ib_operations; - ibdev->dev = &pci->dev; - ibdev->port = ( FLEXBOOT_NODNIC_PORT_BASE + i); - ib_set_drvdata(ibdev, flexboot_nodnic_priv); - } - return status; -err_alloc_ibdev: - for ( i-- ; ( signed int ) i >= 0 ; i-- ) - ibdev_put ( flexboot_nodnic_priv->port[i].ibdev ); - return status; -} - -static -mlx_status -flexboot_nodnic_thin_init_ports( struct flexboot_nodnic *flexboot_nodnic_priv ) { - mlx_status status = MLX_SUCCESS; - nodnic_device_priv *device_priv = &flexboot_nodnic_priv->device_priv; - nodnic_port_priv *port_priv = NULL; - unsigned int i = 0; - - for ( i = 0; i < device_priv->device_cap.num_ports; i++ ) { - if ( ! ( flexboot_nodnic_priv->port_mask & ( i + 1 ) ) ) - continue; - port_priv = &flexboot_nodnic_priv->port[i].port_priv; - status = nodnic_port_thin_init( device_priv, port_priv, i ); - MLX_FATAL_CHECK_STATUS(status, thin_init_err, - "flexboot_nodnic_thin_init_ports failed"); - } -thin_init_err: - return status; -} - - -static -mlx_status -flexboot_nodnic_set_ports_type ( struct flexboot_nodnic *flexboot_nodnic_priv ) { - mlx_status status = MLX_SUCCESS; - nodnic_device_priv *device_priv = &flexboot_nodnic_priv->device_priv; - nodnic_port_priv *port_priv = NULL; - nodnic_port_type type = NODNIC_PORT_TYPE_UNKNOWN; - unsigned int i = 0; - - for ( i = 0 ; i < device_priv->device_cap.num_ports ; i++ ) { - if ( ! ( flexboot_nodnic_priv->port_mask & ( i + 1 ) ) ) - continue; - port_priv = &flexboot_nodnic_priv->port[i].port_priv; - status = nodnic_port_get_type(port_priv, &type); - MLX_FATAL_CHECK_STATUS(status, type_err, - "nodnic_port_get_type failed"); - switch ( type ) { - case NODNIC_PORT_TYPE_ETH: - DBGC ( flexboot_nodnic_priv, "Port %d type is Ethernet\n", i ); - flexboot_nodnic_priv->port[i].type = &flexboot_nodnic_port_type_eth; - break; - case NODNIC_PORT_TYPE_IB: - DBGC ( flexboot_nodnic_priv, "Port %d type is Infiniband\n", i ); - status = MLX_UNSUPPORTED; - goto type_err; - default: - DBGC ( flexboot_nodnic_priv, "Port %d type is unknown\n", i ); - status = MLX_UNSUPPORTED; - goto type_err; - } - } -type_err: - return status; -} - -static -mlx_status -flexboot_nodnic_ports_register_dev( struct flexboot_nodnic *flexboot_nodnic_priv ) { - mlx_status status = MLX_SUCCESS; - nodnic_device_priv *device_priv = &flexboot_nodnic_priv->device_priv; - struct flexboot_nodnic_port *port = NULL; - unsigned int i = 0; - - for (; i < device_priv->device_cap.num_ports; i++) { - if ( ! ( flexboot_nodnic_priv->port_mask & ( i + 1 ) ) ) - continue; - port = &flexboot_nodnic_priv->port[i]; - status = port->type->register_dev ( flexboot_nodnic_priv, port ); - MLX_FATAL_CHECK_STATUS(status, reg_err, - "port register_dev failed"); - } -reg_err: - return status; -} - -static -mlx_status -flexboot_nodnic_ports_unregister_dev ( struct flexboot_nodnic *flexboot_nodnic_priv ) { - struct flexboot_nodnic_port *port; - nodnic_device_priv *device_priv = &flexboot_nodnic_priv->device_priv; - int i = (device_priv->device_cap.num_ports - 1); - - for (; i >= 0; i--) { - if ( ! ( flexboot_nodnic_priv->port_mask & ( i + 1 ) ) ) - continue; - port = &flexboot_nodnic_priv->port[i]; - port->type->unregister_dev(flexboot_nodnic_priv, port); - ibdev_put(flexboot_nodnic_priv->port[i].ibdev); - } - return MLX_SUCCESS; -} - -/*************************************************************************** - * - * flexboot nodnic interface - * - *************************************************************************** - */ -__unused static void flexboot_nodnic_enable_dma ( struct flexboot_nodnic *nodnic ) { - nodnic_port_priv *port_priv; - mlx_status status; - int i; - - for ( i = 0; i < nodnic->device_priv.device_cap.num_ports; i++ ) { - if ( ! ( nodnic->port_mask & ( i + 1 ) ) ) - continue; - port_priv = & ( nodnic->port[i].port_priv ); - if ( ! ( port_priv->port_state & NODNIC_PORT_OPENED ) ) - continue; - - if ( ( status = nodnic_port_enable_dma ( port_priv ) ) ) { - MLX_DEBUG_WARN ( nodnic, "Failed to enable DMA %d\n", status ); - } - } -} - -__unused static void flexboot_nodnic_disable_dma ( struct flexboot_nodnic *nodnic ) { - int i; - - for ( i = 0; i < nodnic->device_priv.device_cap.num_ports; i++ ) { - if ( ! ( nodnic->port_mask & ( i + 1 ) ) ) - continue; - flexboot_nodnic_port_disable_dma ( & ( nodnic->port[i] ) ); - } -} - -int flexboot_nodnic_is_supported ( struct pci_device *pci ) { - mlx_utils utils; - mlx_pci_gw_buffer buffer; - mlx_status status; - int is_supported = 0; - - DBG ( "%s: start\n", __FUNCTION__ ); - - memset ( &utils, 0, sizeof ( utils ) ); - - status = mlx_utils_init ( &utils, pci ); - MLX_CHECK_STATUS ( pci, status, utils_init_err, "mlx_utils_init failed" ); - - status = mlx_pci_gw_init ( &utils ); - MLX_CHECK_STATUS ( pci, status, pci_gw_init_err, "mlx_pci_gw_init failed" ); - - status = mlx_pci_gw_read ( &utils, PCI_GW_SPACE_NODNIC, - NODNIC_NIC_INTERFACE_SUPPORTED_OFFSET, &buffer ); - - if ( status == MLX_SUCCESS ) { - buffer >>= NODNIC_NIC_INTERFACE_SUPPORTED_BIT; - is_supported = ( buffer & 0x1 ); - } - - mlx_pci_gw_teardown( &utils ); - -pci_gw_init_err: -utils_init_err: - DBG ( "%s: NODNIC is %s supported (status = %d)\n", - __FUNCTION__, ( is_supported ? "": "not" ), status ); - return is_supported; -} - -void flexboot_nodnic_copy_mac ( uint8_t mac_addr[], uint32_t low_byte, - uint16_t high_byte ) { - union mac_addr { - struct { - uint32_t low_byte; - uint16_t high_byte; - }; - uint8_t mac_addr[ETH_ALEN]; - } mac_addr_aux; - - mac_addr_aux.high_byte = high_byte; - mac_addr_aux.low_byte = low_byte; - - mac_addr[0] = mac_addr_aux.mac_addr[5]; - mac_addr[1] = mac_addr_aux.mac_addr[4]; - mac_addr[2] = mac_addr_aux.mac_addr[3]; - mac_addr[3] = mac_addr_aux.mac_addr[2]; - mac_addr[4] = mac_addr_aux.mac_addr[1]; - mac_addr[5] = mac_addr_aux.mac_addr[0]; -} - -static mlx_status flexboot_nodnic_get_factory_mac ( - struct flexboot_nodnic *flexboot_nodnic_priv, uint8_t port __unused ) { - struct mlx_vmac_query_virt_mac virt_mac; - mlx_status status; - - memset ( & virt_mac, 0, sizeof ( virt_mac ) ); - status = mlx_vmac_query_virt_mac ( flexboot_nodnic_priv->device_priv.utils, - &virt_mac ); - if ( ! status ) { - DBGC ( flexboot_nodnic_priv, "NODNIC %p Failed to set the virtual MAC\n", - flexboot_nodnic_priv ); - } - - return status; -} - -/** - * Set port masking - * - * @v flexboot_nodnic nodnic device - * @ret rc Return status code - */ -static int flexboot_nodnic_set_port_masking ( struct flexboot_nodnic *flexboot_nodnic ) { - unsigned int i; - nodnic_device_priv *device_priv = &flexboot_nodnic->device_priv; - - flexboot_nodnic->port_mask = 0; - for ( i = 0; i < device_priv->device_cap.num_ports; i++ ) { - flexboot_nodnic->port_mask |= (i + 1); - } - - if ( ! flexboot_nodnic->port_mask ) { - /* No port was enabled */ - DBGC ( flexboot_nodnic, "NODNIC %p No port was enabled for " - "booting\n", flexboot_nodnic ); - return -ENETUNREACH; - } - - return 0; -} - -int flexboot_nodnic_probe ( struct pci_device *pci, - struct flexboot_nodnic_callbacks *callbacks, - void *drv_priv __unused ) { - mlx_status status = MLX_SUCCESS; - struct flexboot_nodnic *flexboot_nodnic_priv = NULL; - nodnic_device_priv *device_priv = NULL; - int i = 0; - - if ( ( pci == NULL ) || ( callbacks == NULL ) ) { - DBGC ( flexboot_nodnic_priv, "%s: Bad Parameter\n", __FUNCTION__ ); - return -EINVAL; - } - - flexboot_nodnic_priv = zalloc( sizeof ( *flexboot_nodnic_priv ) ); - if ( flexboot_nodnic_priv == NULL ) { - DBGC ( flexboot_nodnic_priv, "%s: Failed to allocate priv data\n", __FUNCTION__ ); - status = MLX_OUT_OF_RESOURCES; - goto device_err_alloc; - } - - /* Register settings - * Note that pci->priv will be the device private data */ - flexboot_nodnic_priv->pci = pci; - flexboot_nodnic_priv->callbacks = callbacks; - pci_set_drvdata ( pci, flexboot_nodnic_priv ); - - device_priv = &flexboot_nodnic_priv->device_priv; - device_priv->utils = (mlx_utils *)zalloc( sizeof ( mlx_utils ) ); - if ( device_priv->utils == NULL ) { - DBGC ( flexboot_nodnic_priv, "%s: Failed to allocate utils\n", __FUNCTION__ ); - status = MLX_OUT_OF_RESOURCES; - goto utils_err_alloc; - } - - status = mlx_utils_init( device_priv->utils, pci ); - MLX_FATAL_CHECK_STATUS(status, utils_init_err, - "mlx_utils_init failed"); - - /* nodnic init*/ - status = mlx_pci_gw_init( device_priv->utils ); - MLX_FATAL_CHECK_STATUS(status, cmd_init_err, - "mlx_pci_gw_init failed"); - - /* init device */ - status = nodnic_device_init( device_priv ); - MLX_FATAL_CHECK_STATUS(status, device_init_err, - "nodnic_device_init failed"); - - status = nodnic_device_get_cap( device_priv ); - MLX_FATAL_CHECK_STATUS(status, get_cap_err, - "nodnic_device_get_cap failed"); - - status = flexboot_nodnic_set_port_masking ( flexboot_nodnic_priv ); - MLX_FATAL_CHECK_STATUS(status, err_set_masking, - "flexboot_nodnic_set_port_masking failed"); - - status = flexboot_nodnic_allocate_infiniband_devices( flexboot_nodnic_priv ); - MLX_FATAL_CHECK_STATUS(status, err_alloc_ibdev, - "flexboot_nodnic_allocate_infiniband_devices failed"); - - /* port init */ - status = flexboot_nodnic_thin_init_ports( flexboot_nodnic_priv ); - MLX_FATAL_CHECK_STATUS(status, err_thin_init_ports, - "flexboot_nodnic_thin_init_ports failed"); - - /* device reg */ - status = flexboot_nodnic_set_ports_type( flexboot_nodnic_priv ); - MLX_CHECK_STATUS( flexboot_nodnic_priv, status, err_set_ports_types, - "flexboot_nodnic_set_ports_type failed"); - - status = flexboot_nodnic_ports_register_dev( flexboot_nodnic_priv ); - MLX_FATAL_CHECK_STATUS(status, reg_err, - "flexboot_nodnic_ports_register_dev failed"); - - for ( i = 0; i < device_priv->device_cap.num_ports; i++ ) { - if ( ! ( flexboot_nodnic_priv->port_mask & ( i + 1 ) ) ) - continue; - flexboot_nodnic_get_factory_mac ( flexboot_nodnic_priv, i ); - } - - /* Update ETH operations with IRQ function if supported */ - DBGC ( flexboot_nodnic_priv, "%s: %s IRQ function\n", - __FUNCTION__, ( callbacks->irq ? "Valid" : "No" ) ); - flexboot_nodnic_eth_operations.irq = callbacks->irq; - return 0; - - flexboot_nodnic_ports_unregister_dev ( flexboot_nodnic_priv ); -reg_err: -err_set_ports_types: -err_thin_init_ports: -err_alloc_ibdev: -err_set_masking: -get_cap_err: - nodnic_device_teardown ( device_priv ); -device_init_err: - mlx_pci_gw_teardown ( device_priv->utils ); -cmd_init_err: -utils_init_err: - free ( device_priv->utils ); -utils_err_alloc: - free ( flexboot_nodnic_priv ); -device_err_alloc: - return status; -} - -void flexboot_nodnic_remove ( struct pci_device *pci ) -{ - struct flexboot_nodnic *flexboot_nodnic_priv = pci_get_drvdata ( pci ); - nodnic_device_priv *device_priv = & ( flexboot_nodnic_priv->device_priv ); - - flexboot_nodnic_ports_unregister_dev ( flexboot_nodnic_priv ); - nodnic_device_teardown( device_priv ); - mlx_pci_gw_teardown( device_priv->utils ); - free( device_priv->utils ); - free( flexboot_nodnic_priv ); -} diff --git a/roms/ipxe/src/drivers/infiniband/flexboot_nodnic.h b/roms/ipxe/src/drivers/infiniband/flexboot_nodnic.h deleted file mode 100644 index 80272296c..000000000 --- a/roms/ipxe/src/drivers/infiniband/flexboot_nodnic.h +++ /dev/null @@ -1,163 +0,0 @@ -#ifndef SRC_DRIVERS_INFINIBAND_FLEXBOOT_NODNIC_FLEXBOOT_NODNIC_H_ -#define SRC_DRIVERS_INFINIBAND_FLEXBOOT_NODNIC_FLEXBOOT_NODNIC_H_ - -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include "mlx_nodnic/include/mlx_nodnic_data_structures.h" -#include "nodnic_prm.h" -#include <ipxe/io.h> -#include <ipxe/infiniband.h> -#include <ipxe/netdevice.h> - -/* - * If defined, use interrupts in NODNIC driver - */ -#define NODNIC_IRQ_ENABLED - -#define FLEXBOOT_NODNIC_MAX_PORTS 2 -#define FLEXBOOT_NODNIC_PORT_BASE 1 - -#define FLEXBOOT_NODNIC_OPCODE_SEND 0xa - -/* Port protocol */ -enum flexboot_nodnic_protocol { - FLEXBOOT_NODNIC_PROT_IB_IPV6 = 0, - FLEXBOOT_NODNIC_PROT_ETH, - FLEXBOOT_NODNIC_PROT_IB_IPV4, - FLEXBOOT_NODNIC_PROT_FCOE -}; - -/** A flexboot nodnic port */ -struct flexboot_nodnic_port { - /** Infiniband device */ - struct ib_device *ibdev; - /** Network device */ - struct net_device *netdev; - /** nodic port */ - nodnic_port_priv port_priv; - /** Port type */ - struct flexboot_nodnic_port_type *type; - /** Ethernet completion queue */ - struct ib_completion_queue *eth_cq; - /** Ethernet queue pair */ - struct ib_queue_pair *eth_qp; -}; - - -/** A flexboot nodnic queue pair */ -struct flexboot_nodnic_queue_pair { - nodnic_qp *nodnic_queue_pair; -}; - -/** A flexboot nodnic cq */ -struct flexboot_nodnic_completion_queue { - nodnic_cq *nodnic_completion_queue; -}; - -/** A flexboot_nodnic device */ -struct flexboot_nodnic { - /** PCI device */ - struct pci_device *pci; - /** nic specific data*/ - struct flexboot_nodnic_callbacks *callbacks; - /**nodnic device*/ - nodnic_device_priv device_priv; - /**flexboot_nodnic ports*/ - struct flexboot_nodnic_port port[FLEXBOOT_NODNIC_MAX_PORTS]; - /** Device open request counter */ - unsigned int open_count; - /** Port masking */ - u16 port_mask; - /** device private data */ - void *priv_data; -}; - -/** A flexboot_nodnic port type */ -struct flexboot_nodnic_port_type { - /** Register port - * - * @v flexboot_nodnic flexboot_nodnic device - * @v port flexboot_nodnic port - * @ret mlx_status Return status code - */ - mlx_status ( * register_dev ) ( - struct flexboot_nodnic *flexboot_nodnic, - struct flexboot_nodnic_port *port - ); - /** Port state changed - * - * @v flexboot_nodnic flexboot_nodnic device - * @v port flexboot_nodnic port - * @v link_up Link is up - */ - void ( * state_change ) ( - struct flexboot_nodnic *flexboot_nodnic, - struct flexboot_nodnic_port *port, - int link_up - ); - /** Unregister port - * - * @v flexboot_nodnic flexboot_nodnic device - * @v port flexboot_nodnic port - */ - void ( * unregister_dev ) ( - struct flexboot_nodnic *flexboot_nodnic, - struct flexboot_nodnic_port *port - ); -}; - -struct cqe_data{ - mlx_boolean owner; - mlx_uint32 qpn; - mlx_uint32 is_send; - mlx_uint32 is_error; - mlx_uint32 syndrome; - mlx_uint32 vendor_err_syndrome; - mlx_uint32 wqe_counter; - mlx_uint32 byte_cnt; -}; - -struct flexboot_nodnic_callbacks { - mlx_status ( * fill_completion ) ( void *cqe, struct cqe_data *cqe_data ); - mlx_status ( * cqe_set_owner ) ( void *cq, unsigned int num_cqes ); - mlx_size ( * get_cqe_size ) (); - mlx_status ( * fill_send_wqe[5] ) ( - struct ib_device *ibdev, - struct ib_queue_pair *qp, - struct ib_address_vector *av, - struct io_buffer *iobuf, - struct nodnic_send_wqbb *wqbb, - unsigned long wqe_idx - ); - void ( * irq ) ( struct net_device *netdev, int enable ); -}; - -int flexboot_nodnic_probe ( struct pci_device *pci, - struct flexboot_nodnic_callbacks *callbacks, - void *drv_priv ); -void flexboot_nodnic_remove ( struct pci_device *pci ); -void flexboot_nodnic_eth_irq ( struct net_device *netdev, int enable ); -int flexboot_nodnic_is_supported ( struct pci_device *pci ); -void flexboot_nodnic_copy_mac ( uint8_t mac_addr[], uint32_t low_byte, - uint16_t high_byte ); - -#endif /* SRC_DRIVERS_INFINIBAND_FLEXBOOT_NODNIC_FLEXBOOT_NODNIC_H_ */ diff --git a/roms/ipxe/src/drivers/infiniband/golan.c b/roms/ipxe/src/drivers/infiniband/golan.c deleted file mode 100755 index d410fdfb9..000000000 --- a/roms/ipxe/src/drivers/infiniband/golan.c +++ /dev/null @@ -1,2672 +0,0 @@ -/* - * Copyright (C) 2013-2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include <errno.h> -#include <strings.h> -#include <byteswap.h> -#include <ipxe/malloc.h> -#include <ipxe/umalloc.h> -#include <ipxe/infiniband.h> -#include <ipxe/ib_smc.h> -#include <ipxe/iobuf.h> -#include <ipxe/netdevice.h> -#include <ipxe/ethernet.h> -#include <ipxe/if_ether.h> -#include <ipxe/in.h> -#include <ipxe/ipoib.h> -#include "flexboot_nodnic.h" -#include "nodnic_shomron_prm.h" -#include "golan.h" -#include "mlx_utils/include/public/mlx_bail.h" -#include "mlx_utils/mlx_lib/mlx_link_speed/mlx_link_speed.h" -#include "mlx_utils/mlx_lib/mlx_nvconfig/mlx_nvconfig.h" -#include "mlx_utils/include/public/mlx_pci_gw.h" -#include "mlx_nodnic/include/mlx_port.h" - -/******************************************************************************/ -/************* Very simple memory management for umalloced pages **************/ -/******* Temporary solution until full memory management is implemented *******/ -/******************************************************************************/ -#define GOLAN_PAGES 20 -struct golan_page { - struct list_head list; - userptr_t addr; -}; - -static void golan_free_pages ( struct list_head *head ) { - struct golan_page *page, *tmp; - list_for_each_entry_safe ( page, tmp, head, list ) { - list_del ( &page->list ); - ufree ( page->addr ); - free ( page ); - } -} - -static int golan_init_pages ( struct list_head *head ) { - struct golan_page *new_entry; - int rc, i; - - if ( !head ) { - rc = -EINVAL; - goto err_golan_init_pages_bad_param; - } - - INIT_LIST_HEAD ( head ); - - for ( i = 0; i < GOLAN_PAGES; i++ ) { - new_entry = zalloc ( sizeof ( *new_entry ) ); - if ( new_entry == NULL ) { - rc = -ENOMEM; - goto err_golan_init_pages_alloc_page; - } - new_entry->addr = umalloc ( GOLAN_PAGE_SIZE ); - if ( new_entry->addr == UNULL ) { - free ( new_entry ); - rc = -ENOMEM; - goto err_golan_init_pages_alloc_page; - } - list_add ( &new_entry->list, head ); - } - - return 0; - -err_golan_init_pages_alloc_page: - golan_free_pages ( head ); -err_golan_init_pages_bad_param: - return rc; -} - -static userptr_t golan_get_page ( struct list_head *head ) { - struct golan_page *page; - userptr_t addr; - - if ( list_empty ( head ) ) - return UNULL; - - page = list_first_entry ( head, struct golan_page, list ); - list_del ( &page->list ); - addr = page->addr; - free ( page ); - return addr; -} - -/******************************************************************************/ - -const char *golan_qp_state_as_string[] = { - "RESET", - "INIT", - "RTR", - "RTS", - "SQD", - "SQE", - "ERR" -}; - -static inline int golan_check_rc_and_cmd_status ( struct golan_cmd_layout *cmd, int rc ) { - struct golan_outbox_hdr *out_hdr = ( struct golan_outbox_hdr * ) ( cmd->out ); - if ( rc == -EBUSY ) { - DBG ( "HCA is busy (rc = -EBUSY)\n" ); - return rc; - } else if ( out_hdr->status ) { - DBG("%s status = 0x%x - syndrom = 0x%x\n", __FUNCTION__, - out_hdr->status, be32_to_cpu(out_hdr->syndrome)); - return out_hdr->status; - } - return 0; -} - -#define GOLAN_CHECK_RC_AND_CMD_STATUS(_lable) \ - do { \ - if ( ( rc = golan_check_rc_and_cmd_status ( cmd, rc ) ) ) \ - goto _lable; \ - } while (0) - -#define GOLAN_PRINT_RC_AND_CMD_STATUS golan_check_rc_and_cmd_status ( cmd, rc ) - - -struct mbox { - union { - struct golan_cmd_prot_block mblock; - u8 data[MAILBOX_STRIDE]; - __be64 qdata[MAILBOX_STRIDE >> 3]; - }; -}; - -static inline uint32_t ilog2(uint32_t mem) -{ - return ( fls ( mem ) - 1 ); -} - -#define CTRL_SIG_SZ (sizeof(mailbox->mblock) - sizeof(mailbox->mblock.bdata) - 2) - -static inline u8 xor8_buf(void *buf, int len) -{ - u8 sum = 0; - int i; - u8 *ptr = buf; - - for (i = 0; i < len; ++i) - sum ^= ptr[i]; - - return sum; -} - -static inline int verify_block_sig(struct golan_cmd_prot_block *block) -{ - if (xor8_buf(block->rsvd0, sizeof(*block) - sizeof(block->data) - 1) != 0xff) - return -EINVAL; - - if (xor8_buf(block, sizeof(*block)) != 0xff) - return -EINVAL; - return 0; -} - -static inline const char *cmd_status_str(u8 status) -{ - switch (status) { - case 0x0: return "OK"; - case 0x1: return "internal error"; - case 0x2: return "bad operation"; - case 0x3: return "bad parameter"; - case 0x4: return "bad system state"; - case 0x5: return "bad resource"; - case 0x6: return "resource busy"; - case 0x8: return "limits exceeded"; - case 0x9: return "bad resource state"; - case 0xa: return "bad index"; - case 0xf: return "no resources"; - case 0x50: return "bad input length"; - case 0x51: return "bad output length"; - case 0x10: return "bad QP state"; - case 0x30: return "bad packet (discarded)"; - case 0x40: return "bad size too many outstanding CQEs"; - case 0xff: return "Command Timed Out"; - default: return "unknown status"; - } -} - -static inline uint16_t fw_rev_maj(struct golan *golan) -{ - return be32_to_cpu(readl(&golan->iseg->fw_rev)) & 0xffff; -} - -static inline u16 fw_rev_min(struct golan *golan) -{ - return be32_to_cpu(readl(&golan->iseg->fw_rev)) >> 16; -} - -static inline u16 fw_rev_sub(struct golan *golan) -{ - return be32_to_cpu(readl(&golan->iseg->cmdif_rev_fw_sub)) & 0xffff; -} - -static inline u16 cmdif_rev(struct golan *golan) -{ - return be32_to_cpu(readl(&golan->iseg->cmdif_rev_fw_sub)) >> 16; -} - - -static inline struct golan_cmd_layout *get_cmd( struct golan *golan, int idx ) -{ - return golan->cmd.addr + (idx << golan->cmd.log_stride); -} - -static inline void golan_calc_sig(struct golan *golan, uint32_t cmd_idx, - uint32_t inbox_idx, uint32_t outbox_idx) -{ - struct golan_cmd_layout *cmd = get_cmd(golan, cmd_idx); - struct mbox *mailbox = NULL; - - if (inbox_idx != NO_MBOX) { - mailbox = GET_INBOX(golan, inbox_idx); - mailbox->mblock.token = cmd->token; - mailbox->mblock.ctrl_sig = ~xor8_buf(mailbox->mblock.rsvd0, - CTRL_SIG_SZ); - } - if (outbox_idx != NO_MBOX) { - mailbox = GET_OUTBOX(golan, outbox_idx); - mailbox->mblock.token = cmd->token; - mailbox->mblock.ctrl_sig = ~xor8_buf(mailbox->mblock.rsvd0, - CTRL_SIG_SZ); - } - cmd->sig = ~xor8_buf(cmd, sizeof(*cmd)); -} - -/** - * Get Golan FW - */ -static int fw_ver_and_cmdif ( struct golan *golan ) { - DBGC (golan ,"\n[%x:%x]rev maj.min.submin = %x.%x.%x cmdif = %x\n", - golan->iseg->fw_rev, - golan->iseg->cmdif_rev_fw_sub, - fw_rev_maj ( golan ), fw_rev_min ( golan ), - fw_rev_sub ( golan ), cmdif_rev ( golan)); - - if (cmdif_rev ( golan) != PXE_CMDIF_REF) { - DBGC (golan ,"CMDIF %d not supported current is %d\n", - cmdif_rev ( golan ), PXE_CMDIF_REF); - return 1; - } - return 0; -} - -static inline void show_out_status(uint32_t *out) -{ - DBG("%x\n", be32_to_cpu(out[0])); - DBG("%x\n", be32_to_cpu(out[1])); - DBG("%x\n", be32_to_cpu(out[2])); - DBG("%x\n", be32_to_cpu(out[3])); -} -/** - * Check if CMD has finished. - */ -static inline uint32_t is_command_finished( struct golan *golan, int idx) -{ - wmb(); - return !(get_cmd( golan , idx )->status_own & CMD_OWNER_HW); -} - -/** - * Wait for Golan command completion - * - * @v golan Golan device - * @ret rc Return status code - */ -static inline int golan_cmd_wait(struct golan *golan, int idx, const char *command) -{ - unsigned int wait; - int rc = -EBUSY; - - for ( wait = GOLAN_HCR_MAX_WAIT_MS ; wait ; --wait ) { - if (is_command_finished(golan, idx)) { - rc = CMD_STATUS(golan, idx); - rmb(); - break; - } else { - mdelay ( 1 ); - } - } - if (rc) { - DBGC (golan ,"[%s]RC is %s[%x]\n", command, cmd_status_str(rc), rc); - } - - golan->cmd_bm &= ~(1 << idx); - return rc; -} - -/** - * Notify the HW that commands are ready - */ -static inline void send_command(struct golan *golan) -{ - wmb(); //Make sure the command is visible in "memory". - writel(cpu_to_be32(golan->cmd_bm) , &golan->iseg->cmd_dbell); -} - -static inline int send_command_and_wait(struct golan *golan, uint32_t cmd_idx, - uint32_t inbox_idx, uint32_t outbox_idx, const char *command) -{ - golan_calc_sig(golan, cmd_idx, inbox_idx, outbox_idx); - send_command(golan); - return golan_cmd_wait(golan, cmd_idx, command); -} - -/** - * Prepare a FW command, - * In - comamnd idx (Must be valid) - * writes the command parameters. - */ -static inline struct golan_cmd_layout *write_cmd(struct golan *golan, int idx, - uint16_t opcode, uint16_t opmod, - uint16_t inbox_idx, - uint16_t outbox_idx, uint16_t inlen, - uint16_t outlen) -{ - struct golan_cmd_layout *cmd = get_cmd(golan , idx); - struct golan_inbox_hdr *hdr = (struct golan_inbox_hdr *)cmd->in; - static uint8_t token; - - memset(cmd, 0, sizeof(*cmd)); - - cmd->type = GOLAN_PCI_CMD_XPORT; - cmd->status_own = CMD_OWNER_HW; - cmd->outlen = cpu_to_be32(outlen); - cmd->inlen = cpu_to_be32(inlen); - hdr->opcode = cpu_to_be16(opcode); - hdr->opmod = cpu_to_be16(opmod); - - if (inbox_idx != NO_MBOX) { - memset(GET_INBOX(golan, inbox_idx), 0, MAILBOX_SIZE); - cmd->in_ptr = VIRT_2_BE64_BUS(GET_INBOX(golan, inbox_idx)); - cmd->token = ++token; - } - if (outbox_idx != NO_MBOX) { - memset(GET_OUTBOX(golan, outbox_idx), 0, MAILBOX_SIZE); - cmd->out_ptr = VIRT_2_BE64_BUS(GET_OUTBOX(golan, outbox_idx)); - } - - golan->cmd_bm |= 1 << idx; - - assert ( cmd != NULL ); - return cmd; -} - -static inline int golan_core_enable_hca(struct golan *golan) -{ - struct golan_cmd_layout *cmd; - int rc = 0; - - DBGC(golan, "%s\n", __FUNCTION__); - - cmd = write_cmd(golan, DEF_CMD_IDX, GOLAN_CMD_OP_ENABLE_HCA, 0x0, - NO_MBOX, NO_MBOX, - sizeof(struct golan_enable_hca_mbox_in), - sizeof(struct golan_enable_hca_mbox_out)); - - rc = send_command_and_wait(golan, DEF_CMD_IDX, NO_MBOX, NO_MBOX, __FUNCTION__); - GOLAN_PRINT_RC_AND_CMD_STATUS; - return rc; -} - -static inline void golan_disable_hca(struct golan *golan) -{ - struct golan_cmd_layout *cmd; - int rc; - - cmd = write_cmd(golan, DEF_CMD_IDX, GOLAN_CMD_OP_DISABLE_HCA, 0x0, - NO_MBOX, NO_MBOX, - sizeof(struct golan_disable_hca_mbox_in), - sizeof(struct golan_disable_hca_mbox_out)); - rc = send_command_and_wait(golan, DEF_CMD_IDX, NO_MBOX, NO_MBOX, __FUNCTION__); - GOLAN_PRINT_RC_AND_CMD_STATUS; -} - -static inline int golan_set_hca_cap(struct golan *golan) -{ - struct golan_cmd_layout *cmd; - int rc; - - DBGC(golan, "%s\n", __FUNCTION__); - - cmd = write_cmd(golan, DEF_CMD_IDX, GOLAN_CMD_OP_SET_HCA_CAP, 0x0, - GEN_MBOX, NO_MBOX, - sizeof(struct golan_cmd_set_hca_cap_mbox_in), - sizeof(struct golan_cmd_set_hca_cap_mbox_out)); - - golan->caps.flags &= ~GOLAN_DEV_CAP_FLAG_CMDIF_CSUM; - DBGC( golan , "%s caps.uar_sz = %d\n", __FUNCTION__, golan->caps.uar_sz); - DBGC( golan , "%s caps.log_pg_sz = %d\n", __FUNCTION__, golan->caps.log_pg_sz); - DBGC( golan , "%s caps.log_uar_sz = %d\n", __FUNCTION__, be32_to_cpu(golan->caps.uar_page_sz)); - golan->caps.uar_page_sz = 0; - - - memcpy(((struct golan_hca_cap *)GET_INBOX(golan, GEN_MBOX)), - &(golan->caps), - sizeof(struct golan_hca_cap)); - - //if command failed we should reset the caps in golan->caps - rc = send_command_and_wait(golan, DEF_CMD_IDX, GEN_MBOX, NO_MBOX, __FUNCTION__); - GOLAN_PRINT_RC_AND_CMD_STATUS; - return rc; -} - -static inline int golan_qry_hca_cap(struct golan *golan) -{ - struct golan_cmd_layout *cmd; - int rc = 0; - - cmd = write_cmd(golan, DEF_CMD_IDX, GOLAN_CMD_OP_QUERY_HCA_CAP, 0x1, - NO_MBOX, GEN_MBOX, - sizeof(struct golan_cmd_query_hca_cap_mbox_in), - sizeof(struct golan_cmd_query_hca_cap_mbox_out)); - - rc = send_command_and_wait(golan, DEF_CMD_IDX, NO_MBOX, GEN_MBOX, __FUNCTION__); - GOLAN_CHECK_RC_AND_CMD_STATUS( err_query_hca_cap ); - - memcpy(&(golan->caps), - ((struct golan_hca_cap *)GET_OUTBOX(golan, GEN_MBOX)), - sizeof(struct golan_hca_cap)); -err_query_hca_cap: - return rc; -} - -static inline int golan_take_pages ( struct golan *golan, uint32_t pages, __be16 func_id ) { - uint32_t out_num_entries = 0; - int size_ibox = sizeof(struct golan_manage_pages_inbox); - int size_obox = sizeof(struct golan_manage_pages_outbox); - int rc = 0; - - DBGC(golan, "%s\n", __FUNCTION__); - - while ( pages > 0 ) { - uint32_t pas_num = min(pages, MAX_PASE_MBOX); - unsigned i; - struct golan_cmd_layout *cmd; - struct golan_manage_pages_inbox *in; - struct golan_manage_pages_outbox_data *out; - - size_ibox += (pas_num * GOLAN_PAS_SIZE); - size_obox += (pas_num * GOLAN_PAS_SIZE); - - cmd = write_cmd(golan, MEM_CMD_IDX, GOLAN_CMD_OP_MANAGE_PAGES, GOLAN_PAGES_TAKE, - MEM_MBOX, MEM_MBOX, - size_ibox, - size_obox); - - in = (struct golan_manage_pages_inbox *)cmd->in; /* Warning (WE CANT USE THE LAST 2 FIELDS) */ - - in->func_id = func_id; /* Already BE */ - in->num_entries = cpu_to_be32(pas_num); - - if ( ( rc = send_command_and_wait(golan, MEM_CMD_IDX, MEM_MBOX, MEM_MBOX, __FUNCTION__) ) == 0 ) { - out = (struct golan_manage_pages_outbox_data *)GET_OUTBOX(golan, MEM_MBOX); - out_num_entries = be32_to_cpu(((struct golan_manage_pages_outbox *)(cmd->out))->num_entries); - for (i = 0; i < out_num_entries; ++i) { - ufree(BE64_BUS_2_USR(out->pas[i])); - } - } else { - if ( rc == -EBUSY ) { - DBGC (golan ,"HCA is busy (rc = -EBUSY)\n" ); - } else { - DBGC (golan ,"%s: rc =0x%x[%s]<%x> syn 0x%x[0x%x] for %d pages\n", - __FUNCTION__, rc, cmd_status_str(rc), - CMD_SYND(golan, MEM_CMD_IDX), - get_cmd( golan , MEM_CMD_IDX )->status_own, - be32_to_cpu(CMD_SYND(golan, MEM_CMD_IDX)), pas_num); - } - return rc; - } - - pages -= out_num_entries; - } - DBGC( golan , "%s Pages handled\n", __FUNCTION__); - return 0; -} - -static inline int golan_provide_pages ( struct golan *golan , uint32_t pages, __be16 func_id ) { - struct mbox *mailbox; - int size_ibox = sizeof(struct golan_manage_pages_inbox); - int size_obox = sizeof(struct golan_manage_pages_outbox); - int rc = 0; - - DBGC(golan, "%s\n", __FUNCTION__); - - while ( pages > 0 ) { - uint32_t pas_num = min(pages, MAX_PASE_MBOX); - unsigned i, j; - struct golan_cmd_layout *cmd; - struct golan_manage_pages_inbox *in; - userptr_t addr = 0; - - mailbox = GET_INBOX(golan, MEM_MBOX); - size_ibox += (pas_num * GOLAN_PAS_SIZE); - size_obox += (pas_num * GOLAN_PAS_SIZE); - - cmd = write_cmd(golan, MEM_CMD_IDX, GOLAN_CMD_OP_MANAGE_PAGES, GOLAN_PAGES_GIVE, - MEM_MBOX, MEM_MBOX, - size_ibox, - size_obox); - - in = (struct golan_manage_pages_inbox *)cmd->in; /* Warning (WE CANT USE THE LAST 2 FIELDS) */ - - in->func_id = func_id; /* Already BE */ - in->num_entries = cpu_to_be32(pas_num); - - for ( i = 0 , j = MANAGE_PAGES_PSA_OFFSET; i < pas_num; ++i ,++j ) { - if (!(addr = umalloc(GOLAN_PAGE_SIZE))) { - rc = -ENOMEM; - DBGC (golan ,"Couldnt allocated page \n"); - goto malloc_dma_failed; - } - if (GOLAN_PAGE_MASK & user_to_phys(addr, 0)) { - DBGC (golan ,"Addr not Page alligned [%lx %lx]\n", user_to_phys(addr, 0), addr); - } - mailbox->mblock.data[j] = USR_2_BE64_BUS(addr); - } - - if ( ( rc = send_command_and_wait(golan, MEM_CMD_IDX, MEM_MBOX, MEM_MBOX, __FUNCTION__) ) == 0 ) { - pages -= pas_num; - golan->total_dma_pages += pas_num; - } else { - if ( rc == -EBUSY ) { - DBGC (golan ,"HCA is busy (rc = -EBUSY)\n" ); - } else { - DBGC (golan ,"%s: rc =0x%x[%s]<%x> syn 0x%x[0x%x] for %d pages\n", - __FUNCTION__, rc, cmd_status_str(rc), - CMD_SYND(golan, MEM_CMD_IDX), - get_cmd( golan , MEM_CMD_IDX )->status_own, - be32_to_cpu(CMD_SYND(golan, MEM_CMD_IDX)), pas_num); - } - ufree ( addr ); - goto err_send_command; - } - } - DBGC( golan , "%s Pages handled\n", __FUNCTION__); - return 0; - -err_send_command: -malloc_dma_failed: - /* Go over In box and free pages */ - /* Send Error to FW */ - /* What is next - Disable HCA? */ - DBGC (golan ,"%s Failed (rc = 0x%x)\n", __FUNCTION__, rc); - return rc; -} - -static inline int golan_handle_pages(struct golan *golan, - enum golan_qry_pages_mode qry, - enum golan_manage_pages_mode mode) -{ - struct golan_cmd_layout *cmd; - - int rc = 0; - int32_t pages; - uint16_t total_pages; - __be16 func_id; - - DBGC(golan, "%s\n", __FUNCTION__); - - cmd = write_cmd(golan, MEM_CMD_IDX, GOLAN_CMD_OP_QUERY_PAGES, qry, - NO_MBOX, NO_MBOX, - sizeof(struct golan_query_pages_inbox), - sizeof(struct golan_query_pages_outbox)); - - rc = send_command_and_wait(golan, MEM_CMD_IDX, NO_MBOX, NO_MBOX, __FUNCTION__); - GOLAN_CHECK_RC_AND_CMD_STATUS( err_handle_pages_query ); - - pages = be32_to_cpu(QRY_PAGES_OUT(golan, MEM_CMD_IDX)->num_pages); - - DBGC( golan , "%s pages needed: %d\n", __FUNCTION__, pages); - - func_id = QRY_PAGES_OUT(golan, MEM_CMD_IDX)->func_id; - - total_pages = (( pages >= 0 ) ? pages : ( pages * ( -1 ) )); - - if ( mode == GOLAN_PAGES_GIVE ) { - rc = golan_provide_pages(golan, total_pages, func_id); - } else { - rc = golan_take_pages(golan, golan->total_dma_pages, func_id); - golan->total_dma_pages = 0; - } - - if ( rc ) { - DBGC (golan , "Failed to %s pages (rc = %d) - DMA pages allocated = %d\n", - ( ( mode == GOLAN_PAGES_GIVE ) ? "give" : "take" ), rc , golan->total_dma_pages ); - return rc; - } - - return 0; - -err_handle_pages_query: - DBGC (golan ,"%s Qyery pages failed (rc = 0x%x)\n", __FUNCTION__, rc); - return rc; -} - -static inline int golan_set_access_reg ( struct golan *golan __attribute__ (( unused )), uint32_t reg __attribute__ (( unused ))) -{ -#if 0 - write_cmd(golan, _CMD_IDX, GOLAN_CMD_OP_QUERY_PAGES, 0x0, - NO_MBOX, NO_MBOX, - sizeof(struct golan_reg_host_endianess), - sizeof(struct golan_reg_host_endianess)); - in->arg = cpu_to_be32(arg); - in->register_id = cpu_to_be16(reg_num); -#endif - DBGC (golan ," %s Not implemented yet\n", __FUNCTION__); - return 0; -} - -static inline void golan_cmd_uninit ( struct golan *golan ) -{ - free_dma(golan->mboxes.outbox, GOLAN_PAGE_SIZE); - free_dma(golan->mboxes.inbox, GOLAN_PAGE_SIZE); - free_dma(golan->cmd.addr, GOLAN_PAGE_SIZE); -} - -/** - * Initialise Golan Command Q parameters - * -- Alocate a 4kb page for the Command Q - * -- Read the stride and log num commands available - * -- Write the address to cmdq_phy_addr in iseg - * @v golan Golan device - */ -static inline int golan_cmd_init ( struct golan *golan ) -{ - int rc = 0; - uint32_t addr_l_sz; - - if (!(golan->cmd.addr = malloc_dma(GOLAN_PAGE_SIZE , GOLAN_PAGE_SIZE))) { - rc = -ENOMEM; - goto malloc_dma_failed; - } - if (!(golan->mboxes.inbox = malloc_dma(GOLAN_PAGE_SIZE , GOLAN_PAGE_SIZE))) { - rc = -ENOMEM; - goto malloc_dma_inbox_failed; - } - if (!(golan->mboxes.outbox = malloc_dma(GOLAN_PAGE_SIZE , GOLAN_PAGE_SIZE))) { - rc = -ENOMEM; - goto malloc_dma_outbox_failed; - } - addr_l_sz = be32_to_cpu(readl(&golan->iseg->cmdq_addr_l_sz)); - - golan->cmd.log_stride = addr_l_sz & 0xf; - golan->cmd.size = 1 << (( addr_l_sz >> 4 ) & 0xf); - - addr_l_sz = virt_to_bus(golan->cmd.addr); - writel(0 /* cpu_to_be32(golan->cmd.addr) >> 32 */, &golan->iseg->cmdq_addr_h); - writel(cpu_to_be32(addr_l_sz), &golan->iseg->cmdq_addr_l_sz); - wmb(); //Make sure the addr is visible in "memory". - - addr_l_sz = be32_to_cpu(readl(&golan->iseg->cmdq_addr_l_sz)); - - DBGC( golan , "%s Command interface was initialized\n", __FUNCTION__); - return 0; - -malloc_dma_outbox_failed: - free_dma(golan->mboxes.inbox, GOLAN_PAGE_SIZE); -malloc_dma_inbox_failed: - free_dma(golan->cmd.addr, GOLAN_PAGE_SIZE); -malloc_dma_failed: - DBGC (golan ,"%s Failed to initialize command interface (rc = 0x%x)\n", - __FUNCTION__, rc); - return rc; -} - -static inline int golan_hca_init(struct golan *golan) -{ - struct golan_cmd_layout *cmd; - int rc = 0; - - DBGC(golan, "%s\n", __FUNCTION__); - - cmd = write_cmd(golan, DEF_CMD_IDX, GOLAN_CMD_OP_INIT_HCA, 0x0, - NO_MBOX, NO_MBOX, - sizeof(struct golan_cmd_init_hca_mbox_in), - sizeof(struct golan_cmd_init_hca_mbox_out)); - - rc = send_command_and_wait(golan, DEF_CMD_IDX, NO_MBOX, NO_MBOX, __FUNCTION__); - GOLAN_PRINT_RC_AND_CMD_STATUS; - return rc; -} - -static inline void golan_teardown_hca(struct golan *golan, enum golan_teardown op_mod) -{ - struct golan_cmd_layout *cmd; - int rc; - - DBGC (golan, "%s in\n", __FUNCTION__); - - cmd = write_cmd(golan, DEF_CMD_IDX, GOLAN_CMD_OP_TEARDOWN_HCA, op_mod, - NO_MBOX, NO_MBOX, - sizeof(struct golan_cmd_teardown_hca_mbox_in), - sizeof(struct golan_cmd_teardown_hca_mbox_out)); - - rc = send_command_and_wait(golan, DEF_CMD_IDX, NO_MBOX, NO_MBOX, __FUNCTION__); - GOLAN_PRINT_RC_AND_CMD_STATUS; - - DBGC (golan, "%s HCA teardown compleated\n", __FUNCTION__); -} - -static inline int golan_alloc_uar(struct golan *golan) -{ - struct golan_uar *uar = &golan->uar; - struct golan_cmd_layout *cmd; - struct golan_alloc_uar_mbox_out *out; - int rc; - - cmd = write_cmd(golan, DEF_CMD_IDX, GOLAN_CMD_OP_ALLOC_UAR, 0x0, - NO_MBOX, NO_MBOX, - sizeof(struct golan_alloc_uar_mbox_in), - sizeof(struct golan_alloc_uar_mbox_out)); - - rc = send_command_and_wait(golan, DEF_CMD_IDX, NO_MBOX, NO_MBOX, __FUNCTION__); - GOLAN_CHECK_RC_AND_CMD_STATUS( err_alloc_uar_cmd ); - out = (struct golan_alloc_uar_mbox_out *) ( cmd->out ); - - uar->index = be32_to_cpu(out->uarn) & 0xffffff; - - uar->phys = (pci_bar_start(golan->pci, GOLAN_HCA_BAR) + (uar->index << GOLAN_PAGE_SHIFT)); - uar->virt = (void *)(ioremap(uar->phys, GOLAN_PAGE_SIZE)); - - DBGC( golan , "%s: UAR allocated with index 0x%x\n", __FUNCTION__, uar->index); - return 0; - -err_alloc_uar_cmd: - DBGC (golan ,"%s [%d] out\n", __FUNCTION__, rc); - return rc; -} - -static void golan_dealloc_uar(struct golan *golan) -{ - struct golan_cmd_layout *cmd; - uint32_t uar_index = golan->uar.index; - int rc; - - DBGC (golan, "%s in\n", __FUNCTION__); - - cmd = write_cmd(golan, DEF_CMD_IDX, GOLAN_CMD_OP_DEALLOC_UAR, 0x0, - NO_MBOX, NO_MBOX, - sizeof(struct golan_free_uar_mbox_in), - sizeof(struct golan_free_uar_mbox_out)); - - ((struct golan_free_uar_mbox_in *)(cmd->in))->uarn = cpu_to_be32(uar_index); - rc = send_command_and_wait(golan, DEF_CMD_IDX, NO_MBOX, NO_MBOX, __FUNCTION__); - GOLAN_PRINT_RC_AND_CMD_STATUS; - golan->uar.index = 0; - - DBGC (golan, "%s UAR (0x%x) was destroyed\n", __FUNCTION__, uar_index); -} - -static void golan_eq_update_ci(struct golan_event_queue *eq, int arm) -{ - __be32 *addr = eq->doorbell + (arm ? 0 : 2); - u32 val = (eq->cons_index & 0xffffff) | (eq->eqn << 24); - writel(cpu_to_be32(val) , addr); - /* We still want ordering, just not swabbing, so add a barrier */ - wmb(); -} - -static int golan_create_eq(struct golan *golan) -{ - struct golan_event_queue *eq = &golan->eq; - struct golan_create_eq_mbox_in_data *in; - struct golan_cmd_layout *cmd; - struct golan_create_eq_mbox_out *out; - int rc, i; - userptr_t addr; - - eq->cons_index = 0; - eq->size = GOLAN_NUM_EQES * sizeof(eq->eqes[0]); - addr = golan_get_page ( &golan->pages ); - if (!addr) { - rc = -ENOMEM; - goto err_create_eq_eqe_alloc; - } - eq->eqes = (struct golan_eqe *)user_to_virt(addr, 0); - - /* Set EQEs ownership bit to HW ownership */ - for (i = 0; i < GOLAN_NUM_EQES; ++i) { - eq->eqes[i].owner = GOLAN_EQE_HW_OWNERSHIP; - } - - cmd = write_cmd(golan, DEF_CMD_IDX, GOLAN_CMD_OP_CREATE_EQ, 0x0, - GEN_MBOX, NO_MBOX, - sizeof(struct golan_create_eq_mbox_in) + GOLAN_PAS_SIZE, - sizeof(struct golan_create_eq_mbox_out)); - - in = (struct golan_create_eq_mbox_in_data *)GET_INBOX(golan, GEN_MBOX); - - /* Fill the physical address of the page */ - in->pas[0] = USR_2_BE64_BUS(addr); - in->ctx.log_sz_usr_page = cpu_to_be32((ilog2(GOLAN_NUM_EQES)) << 24 | golan->uar.index); - DBGC( golan , "UAR idx %x (BE %x)\n", golan->uar.index, in->ctx.log_sz_usr_page); - in->events_mask = cpu_to_be64(1 << GOLAN_EVENT_TYPE_PORT_CHANGE); - - rc = send_command_and_wait(golan, DEF_CMD_IDX, GEN_MBOX, NO_MBOX, __FUNCTION__); - GOLAN_CHECK_RC_AND_CMD_STATUS( err_create_eq_cmd ); - out = (struct golan_create_eq_mbox_out *)cmd->out; - - eq->eqn = out->eq_number; - eq->doorbell = ((void *)golan->uar.virt) + GOLAN_EQ_DOORBELL_OFFSET; - - /* EQs are created in ARMED state */ - golan_eq_update_ci(eq, GOLAN_EQ_UNARMED); - - DBGC( golan , "%s: Event queue created (EQN = 0x%x)\n", __FUNCTION__, eq->eqn); - return 0; - -err_create_eq_cmd: - ufree(virt_to_user(golan->eq.eqes)); -err_create_eq_eqe_alloc: - DBGC (golan ,"%s [%d] out\n", __FUNCTION__, rc); - return rc; -} - -static void golan_destory_eq(struct golan *golan) -{ - struct golan_cmd_layout *cmd; - struct golan_destroy_eq_mbox_in *in; - uint8_t eqn = golan->eq.eqn; - int rc; - - DBGC (golan, "%s in\n", __FUNCTION__); - - cmd = write_cmd(golan, DEF_CMD_IDX, GOLAN_CMD_OP_DESTROY_EQ, 0x0, - NO_MBOX, NO_MBOX, - sizeof(struct golan_destroy_eq_mbox_in), - sizeof(struct golan_destroy_eq_mbox_out)); - - in = GOLAN_MBOX_IN ( cmd, in ); - in->eqn = eqn; - rc = send_command_and_wait(golan, DEF_CMD_IDX, NO_MBOX, NO_MBOX, __FUNCTION__); - GOLAN_PRINT_RC_AND_CMD_STATUS; - - ufree(virt_to_user(golan->eq.eqes)); - golan->eq.eqn = 0; - - DBGC( golan, "%s Event queue (0x%x) was destroyed\n", __FUNCTION__, eqn); -} - -static int golan_alloc_pd(struct golan *golan) -{ - struct golan_cmd_layout *cmd; - struct golan_alloc_pd_mbox_out *out; - int rc; - - cmd = write_cmd(golan, DEF_CMD_IDX, GOLAN_CMD_OP_ALLOC_PD, 0x0, - NO_MBOX, NO_MBOX, - sizeof(struct golan_alloc_pd_mbox_in), - sizeof(struct golan_alloc_pd_mbox_out)); - - rc = send_command_and_wait(golan, DEF_CMD_IDX, NO_MBOX, NO_MBOX, __FUNCTION__); - GOLAN_CHECK_RC_AND_CMD_STATUS( err_alloc_pd_cmd ); - out = (struct golan_alloc_pd_mbox_out *) ( cmd->out ); - - golan->pdn = (be32_to_cpu(out->pdn) & 0xffffff); - DBGC( golan , "%s: Protection domain created (PDN = 0x%x)\n", __FUNCTION__, - golan->pdn); - return 0; - -err_alloc_pd_cmd: - DBGC (golan ,"%s [%d] out\n", __FUNCTION__, rc); - return rc; -} - -static void golan_dealloc_pd(struct golan *golan) -{ - struct golan_cmd_layout *cmd; - uint32_t pdn = golan->pdn; - int rc; - - DBGC (golan,"%s in\n", __FUNCTION__); - - cmd = write_cmd(golan, DEF_CMD_IDX, GOLAN_CMD_OP_DEALLOC_PD, 0x0, - NO_MBOX, NO_MBOX, - sizeof(struct golan_alloc_pd_mbox_in), - sizeof(struct golan_alloc_pd_mbox_out)); - - ((struct golan_dealloc_pd_mbox_in *)(cmd->in))->pdn = cpu_to_be32(pdn); - rc = send_command_and_wait(golan, DEF_CMD_IDX, NO_MBOX, NO_MBOX, __FUNCTION__); - GOLAN_PRINT_RC_AND_CMD_STATUS; - golan->pdn = 0; - - DBGC (golan ,"%s Protection domain (0x%x) was destroyed\n", __FUNCTION__, pdn); -} - -static int golan_create_mkey(struct golan *golan) -{ - struct golan_create_mkey_mbox_in_data *in; - struct golan_cmd_layout *cmd; - struct golan_create_mkey_mbox_out *out; - int rc; - - cmd = write_cmd(golan, DEF_CMD_IDX, GOLAN_CMD_OP_CREATE_MKEY, 0x0, - GEN_MBOX, NO_MBOX, - sizeof(struct golan_create_mkey_mbox_in), - sizeof(struct golan_create_mkey_mbox_out)); - - in = (struct golan_create_mkey_mbox_in_data *)GET_INBOX(golan, GEN_MBOX); - - in->seg.flags = GOLAN_IB_ACCESS_LOCAL_WRITE | GOLAN_IB_ACCESS_LOCAL_READ; - in->seg.flags_pd = cpu_to_be32(golan->pdn | GOLAN_MKEY_LEN64); - in->seg.qpn_mkey7_0 = cpu_to_be32(0xffffff << GOLAN_CREATE_MKEY_SEG_QPN_BIT); - - rc = send_command_and_wait(golan, DEF_CMD_IDX, GEN_MBOX, NO_MBOX, __FUNCTION__); - GOLAN_CHECK_RC_AND_CMD_STATUS( err_create_mkey_cmd ); - out = (struct golan_create_mkey_mbox_out *) ( cmd->out ); - - golan->mkey = ((be32_to_cpu(out->mkey) & 0xffffff) << 8); - DBGC( golan , "%s: Got DMA Key for local access read/write (MKEY = 0x%x)\n", - __FUNCTION__, golan->mkey); - return 0; -err_create_mkey_cmd: - DBGC (golan ,"%s [%d] out\n", __FUNCTION__, rc); - return rc; -} - -static void golan_destroy_mkey(struct golan *golan) -{ - struct golan_cmd_layout *cmd; - u32 mkey = golan->mkey; - int rc; - - cmd = write_cmd(golan, DEF_CMD_IDX, GOLAN_CMD_OP_DESTROY_MKEY, 0x0, - NO_MBOX, NO_MBOX, - sizeof(struct golan_destroy_mkey_mbox_in), - sizeof(struct golan_destroy_mkey_mbox_out)); - ((struct golan_destroy_mkey_mbox_in *)(cmd->in))->mkey = cpu_to_be32(mkey >> 8); - rc = send_command_and_wait(golan, DEF_CMD_IDX, NO_MBOX, NO_MBOX, __FUNCTION__); - GOLAN_PRINT_RC_AND_CMD_STATUS; - golan->mkey = 0; - - DBGC( golan , "%s DMA Key (0x%x) for local access write was destroyed\n" - , __FUNCTION__, mkey); -} - - -/** - * Initialise Golan PCI parameters - * - * @v golan Golan device - */ -static inline void golan_pci_init(struct golan *golan) -{ - struct pci_device *pci = golan->pci; - - /* Fix up PCI device */ - adjust_pci_device ( pci ); - - /* Get HCA BAR */ - golan->iseg = ioremap ( pci_bar_start ( pci, GOLAN_HCA_BAR), - GOLAN_PCI_CONFIG_BAR_SIZE ); -} - -static inline struct golan *golan_alloc() -{ - void *golan = zalloc(sizeof(struct golan)); - if ( !golan ) - goto err_zalloc; - - return golan; - -err_zalloc: - return NULL; -} - -/** - * Create completion queue - * - * @v ibdev Infiniband device - * @v cq Completion queue - * @ret rc Return status code - */ -static int golan_create_cq(struct ib_device *ibdev, - struct ib_completion_queue *cq) -{ - struct golan *golan = ib_get_drvdata(ibdev); - struct golan_completion_queue *golan_cq; - struct golan_cmd_layout *cmd; - struct golan_create_cq_mbox_in_data *in; - struct golan_create_cq_mbox_out *out; - int rc; - unsigned int i; - userptr_t addr; - - golan_cq = zalloc(sizeof(*golan_cq)); - if (!golan_cq) { - rc = -ENOMEM; - goto err_create_cq; - } - golan_cq->size = sizeof(golan_cq->cqes[0]) * cq->num_cqes; - golan_cq->doorbell_record = malloc_dma(GOLAN_CQ_DB_RECORD_SIZE, - GOLAN_CQ_DB_RECORD_SIZE); - if (!golan_cq->doorbell_record) { - rc = -ENOMEM; - goto err_create_cq_db_alloc; - } - - addr = golan_get_page ( &golan->pages ); - if (!addr) { - rc = -ENOMEM; - goto err_create_cq_cqe_alloc; - } - golan_cq->cqes = (struct golan_cqe64 *)user_to_virt(addr, 0); - - /* Set CQEs ownership bit to HW ownership */ - for (i = 0; i < cq->num_cqes; ++i) { - golan_cq->cqes[i].op_own = ((GOLAN_CQE_OPCODE_NOT_VALID << - GOLAN_CQE_OPCODE_BIT) | - GOLAN_CQE_HW_OWNERSHIP); - } - - cmd = write_cmd(golan, DEF_CMD_IDX, GOLAN_CMD_OP_CREATE_CQ, 0x0, - GEN_MBOX, NO_MBOX, - sizeof(struct golan_create_cq_mbox_in) + GOLAN_PAS_SIZE, - sizeof(struct golan_create_cq_mbox_out)); - - in = (struct golan_create_cq_mbox_in_data *)GET_INBOX(golan, GEN_MBOX); - - /* Fill the physical address of the page */ - in->pas[0] = USR_2_BE64_BUS(addr); - in->ctx.cqe_sz_flags = GOLAN_CQE_SIZE_64 << 5; - in->ctx.log_sz_usr_page = cpu_to_be32(((ilog2(cq->num_cqes)) << 24) | golan->uar.index); - in->ctx.c_eqn = cpu_to_be16(golan->eq.eqn); - in->ctx.db_record_addr = VIRT_2_BE64_BUS(golan_cq->doorbell_record); - - rc = send_command_and_wait(golan, DEF_CMD_IDX, GEN_MBOX, NO_MBOX, __FUNCTION__); - GOLAN_CHECK_RC_AND_CMD_STATUS( err_create_cq_cmd ); - out = (struct golan_create_cq_mbox_out *) ( cmd->out ); - - cq->cqn = (be32_to_cpu(out->cqn) & 0xffffff); - - ib_cq_set_drvdata(cq, golan_cq); - - DBGC( golan , "%s CQ created successfully (CQN = 0x%lx)\n", __FUNCTION__, cq->cqn); - return 0; - -err_create_cq_cmd: - ufree(virt_to_user(golan_cq->cqes)); -err_create_cq_cqe_alloc: - free_dma(golan_cq->doorbell_record, GOLAN_CQ_DB_RECORD_SIZE); -err_create_cq_db_alloc: - free ( golan_cq ); -err_create_cq: - DBGC (golan ,"%s out rc = 0x%x\n", __FUNCTION__, rc); - return rc; -} - -/** - * Destroy completion queue - * - * @v ibdev Infiniband device - * @v cq Completion queue - */ -static void golan_destroy_cq(struct ib_device *ibdev, - struct ib_completion_queue *cq) -{ - struct golan *golan = ib_get_drvdata(ibdev); - struct golan_completion_queue *golan_cq = ib_cq_get_drvdata(cq); - struct golan_cmd_layout *cmd; - uint32_t cqn = cq->cqn; - int rc; - - DBGC (golan, "%s in\n", __FUNCTION__); - - cmd = write_cmd(golan, DEF_CMD_IDX, GOLAN_CMD_OP_DESTROY_CQ, 0x0, - NO_MBOX, NO_MBOX, - sizeof(struct golan_destroy_cq_mbox_in), - sizeof(struct golan_destroy_cq_mbox_out)); - ((struct golan_destroy_cq_mbox_in *)(cmd->in))->cqn = cpu_to_be32(cqn); - rc = send_command_and_wait(golan, DEF_CMD_IDX, NO_MBOX, NO_MBOX, __FUNCTION__); - GOLAN_PRINT_RC_AND_CMD_STATUS; - cq->cqn = 0; - - ib_cq_set_drvdata(cq, NULL); - ufree(virt_to_user(golan_cq->cqes)); - free_dma(golan_cq->doorbell_record, GOLAN_CQ_DB_RECORD_SIZE); - free(golan_cq); - - DBGC (golan, "%s CQ number 0x%x was destroyed\n", __FUNCTION__, cqn); -} - -static void golan_cq_clean(struct ib_completion_queue *cq) -{ - ib_poll_cq(cq->ibdev, cq); -} - -static int golan_qp_type_to_st(enum ib_queue_pair_type type) -{ - int qpt = type; - - switch (qpt) { - case IB_QPT_RC: - return GOLAN_QP_ST_RC; - case IB_QPT_UD: - return GOLAN_QP_ST_UD; - case IB_QPT_SMI: - return GOLAN_QP_ST_QP0; - case IB_QPT_GSI: - return GOLAN_QP_ST_QP1; - case IB_QPT_ETH: - default: - return -EINVAL; - } -} -#if 0 -static int golan_is_special_qp(enum ib_queue_pair_type type) -{ - return (type == IB_QPT_GSI || type == IB_QPT_SMI); -} -#endif -static int golan_create_qp_aux(struct ib_device *ibdev, - struct ib_queue_pair *qp, - int *qpn) -{ - struct golan *golan = ib_get_drvdata(ibdev); - struct golan_queue_pair *golan_qp; - struct golan_create_qp_mbox_in_data *in; - struct golan_cmd_layout *cmd; - struct golan_wqe_data_seg *data; - struct golan_create_qp_mbox_out *out; - userptr_t addr; - uint32_t wqe_size_in_bytes; - uint32_t max_qp_size_in_wqes; - unsigned int i; - int rc; - - golan_qp = zalloc(sizeof(*golan_qp)); - if (!golan_qp) { - rc = -ENOMEM; - goto err_create_qp; - } - - if ( ( qp->type == IB_QPT_SMI ) || ( qp->type == IB_QPT_GSI ) || - ( qp->type == IB_QPT_UD ) ) { - golan_qp->rq.grh_size = ( qp->recv.num_wqes * - sizeof ( golan_qp->rq.grh[0] )); - } - - /* Calculate receive queue size */ - golan_qp->rq.size = qp->recv.num_wqes * GOLAN_RECV_WQE_SIZE; - if (GOLAN_RECV_WQE_SIZE > be16_to_cpu(golan->caps.max_wqe_sz_rq)) { - DBGC (golan ,"%s receive wqe size [%zd] > max wqe size [%d]\n", __FUNCTION__, - GOLAN_RECV_WQE_SIZE, be16_to_cpu(golan->caps.max_wqe_sz_rq)); - rc = -EINVAL; - goto err_create_qp_rq_size; - } - - wqe_size_in_bytes = sizeof(golan_qp->sq.wqes[0]); - /* Calculate send queue size */ - if (wqe_size_in_bytes > be16_to_cpu(golan->caps.max_wqe_sz_sq)) { - DBGC (golan ,"%s send WQE size [%d] > max WQE size [%d]\n", __FUNCTION__, - wqe_size_in_bytes, - be16_to_cpu(golan->caps.max_wqe_sz_sq)); - rc = -EINVAL; - goto err_create_qp_sq_wqe_size; - } - golan_qp->sq.size = (qp->send.num_wqes * wqe_size_in_bytes); - max_qp_size_in_wqes = (1 << ((uint32_t)(golan->caps.log_max_qp_sz))); - if (qp->send.num_wqes > max_qp_size_in_wqes) { - DBGC (golan ,"%s send wq size [%d] > max wq size [%d]\n", __FUNCTION__, - golan_qp->sq.size, max_qp_size_in_wqes); - rc = -EINVAL; - goto err_create_qp_sq_size; - } - - golan_qp->size = golan_qp->sq.size + golan_qp->rq.size; - - /* allocate dma memory for WQEs (1 page is enough) - should change it */ - addr = golan_get_page ( &golan->pages ); - if (!addr) { - rc = -ENOMEM; - goto err_create_qp_wqe_alloc; - } - golan_qp->wqes = user_to_virt(addr, 0); - golan_qp->rq.wqes = golan_qp->wqes; - golan_qp->sq.wqes = golan_qp->wqes + golan_qp->rq.size;//(union golan_send_wqe *)& - //(((struct golan_recv_wqe_ud *)(golan_qp->wqes))[qp->recv.num_wqes]); - - if ( golan_qp->rq.grh_size ) { - golan_qp->rq.grh = ( golan_qp->wqes + - golan_qp->sq.size + - golan_qp->rq.size ); - } - - /* Invalidate all WQEs */ - data = &golan_qp->rq.wqes[0].data[0]; - for ( i = 0 ; i < ( golan_qp->rq.size / sizeof ( *data ) ); i++ ){ - data->lkey = cpu_to_be32 ( GOLAN_INVALID_LKEY ); - data++; - } - - golan_qp->doorbell_record = malloc_dma(sizeof(struct golan_qp_db), - sizeof(struct golan_qp_db)); - if (!golan_qp->doorbell_record) { - rc = -ENOMEM; - goto err_create_qp_db_alloc; - } - memset(golan_qp->doorbell_record, 0, sizeof(struct golan_qp_db)); - - cmd = write_cmd(golan, DEF_CMD_IDX, GOLAN_CMD_OP_CREATE_QP, 0x0, - GEN_MBOX, NO_MBOX, - sizeof(struct golan_create_qp_mbox_in) + GOLAN_PAS_SIZE, - sizeof(struct golan_create_qp_mbox_out)); - - in = (struct golan_create_qp_mbox_in_data *)GET_INBOX(golan, GEN_MBOX); - - /* Fill the physical address of the page */ - in->pas[0] = USR_2_BE64_BUS(addr); - in->ctx.qp_counter_set_usr_page = cpu_to_be32(golan->uar.index); - - in->ctx.flags_pd = cpu_to_be32(golan->pdn); - in->ctx.flags = cpu_to_be32((golan_qp_type_to_st(qp->type) - << GOLAN_QP_CTX_ST_BIT) | - (GOLAN_QP_PM_MIGRATED << - GOLAN_QP_CTX_PM_STATE_BIT)); -// cgs set to 0, initialy. -// atomic mode - in->ctx.rq_size_stride = ((ilog2(qp->recv.num_wqes) << - GOLAN_QP_CTX_RQ_SIZE_BIT) | - (sizeof(golan_qp->rq.wqes[0]) / GOLAN_RECV_WQE_SIZE)); - in->ctx.sq_crq_size = cpu_to_be16(ilog2(golan_qp->sq.size / GOLAN_SEND_WQE_BB_SIZE) - << GOLAN_QP_CTX_SQ_SIZE_BIT); - in->ctx.cqn_send = cpu_to_be32(qp->send.cq->cqn); - in->ctx.cqn_recv = cpu_to_be32(qp->recv.cq->cqn); - in->ctx.db_rec_addr = VIRT_2_BE64_BUS(golan_qp->doorbell_record); - - rc = send_command_and_wait(golan, DEF_CMD_IDX, GEN_MBOX, NO_MBOX, __FUNCTION__); - GOLAN_CHECK_RC_AND_CMD_STATUS( err_create_qp_cmd ); - out = (struct golan_create_qp_mbox_out *)cmd->out; - - *qpn = (be32_to_cpu(out->qpn) & 0xffffff); - /* - * Hardware wants QPN written in big-endian order (after - * shifting) for send doorbell. Precompute this value to save - * a little bit when posting sends. - */ - golan_qp->doorbell_qpn = cpu_to_be32(*qpn << 8); - golan_qp->state = GOLAN_IB_QPS_RESET; - - ib_qp_set_drvdata(qp, golan_qp); - - return 0; - -err_create_qp_cmd: - free_dma(golan_qp->doorbell_record, sizeof(struct golan_qp_db)); -err_create_qp_db_alloc: - ufree((userptr_t)golan_qp->wqes); -err_create_qp_wqe_alloc: -err_create_qp_sq_size: -err_create_qp_sq_wqe_size: -err_create_qp_rq_size: - free ( golan_qp ); -err_create_qp: - return rc; -} - -/** - * Create queue pair - * - * @v ibdev Infiniband device - * @v qp Queue pair - * @ret rc Return status code - */ -static int golan_create_qp(struct ib_device *ibdev, - struct ib_queue_pair *qp) -{ - int rc, qpn = -1; - - switch (qp->type) { - case IB_QPT_UD: - case IB_QPT_SMI: - case IB_QPT_GSI: - rc = golan_create_qp_aux(ibdev, qp, &qpn); - if (rc) { - DBG ( "%s Failed to create QP (rc = 0x%x)\n", __FUNCTION__, rc); - return rc; - } - qp->qpn = qpn; - - break; - case IB_QPT_ETH: - case IB_QPT_RC: - default: - DBG ( "%s unsupported QP type (0x%x)\n", __FUNCTION__, qp->type); - return -EINVAL; - } - - return 0; -} - -static int golan_modify_qp_rst_to_init(struct ib_device *ibdev, - struct ib_queue_pair *qp __unused, - struct golan_modify_qp_mbox_in_data *in) -{ - int rc = 0; - - in->ctx.qkey = cpu_to_be32((uint32_t)(qp->qkey)); - - in->ctx.pri_path.port = ibdev->port; - in->ctx.flags |= cpu_to_be32(GOLAN_QP_PM_MIGRATED << GOLAN_QP_CTX_PM_STATE_BIT); - in->ctx.pri_path.pkey_index = 0; /* default index */ - /* QK is 0 */ - /* QP cntr set 0 */ - return rc; -} - -static int golan_modify_qp_init_to_rtr(struct ib_device *ibdev __unused, - struct ib_queue_pair *qp __unused, - struct golan_modify_qp_mbox_in_data *in) -{ - int rc = 0; - - in->optparam = 0; - return rc; -} - -static int golan_modify_qp_rtr_to_rts(struct ib_device *ibdev __unused, - struct ib_queue_pair *qp __unused, - struct golan_modify_qp_mbox_in_data *in __unused) -{ - int rc = 0; - - in->optparam = 0; - /* In good flow psn in 0 */ - return rc; -} - -static int golan_modify_qp_to_rst(struct ib_device *ibdev, - struct ib_queue_pair *qp) -{ - struct golan *golan = ib_get_drvdata(ibdev); - struct golan_queue_pair *golan_qp = ib_qp_get_drvdata(qp); - struct golan_cmd_layout *cmd; - int rc; - - cmd = write_cmd(golan, DEF_CMD_IDX, GOLAN_CMD_OP_2RST_QP, 0x0, - NO_MBOX, NO_MBOX, - sizeof(struct golan_modify_qp_mbox_in), - sizeof(struct golan_modify_qp_mbox_out)); - ((struct golan_modify_qp_mbox_in *)(cmd->in))->qpn = cpu_to_be32(qp->qpn); - rc = send_command_and_wait(golan, DEF_CMD_IDX, NO_MBOX, NO_MBOX, __FUNCTION__); - GOLAN_CHECK_RC_AND_CMD_STATUS( err_modify_qp_2rst_cmd ); - - golan_qp->state = GOLAN_IB_QPS_RESET; - DBGC( golan , "%s QP number 0x%lx was modified to RESET\n", - __FUNCTION__, qp->qpn); - - return 0; - -err_modify_qp_2rst_cmd: - DBGC (golan ,"%s Failed to modify QP number 0x%lx (rc = 0x%x)\n", - __FUNCTION__, qp->qpn, rc); - return rc; -} - -static int (*golan_modify_qp_methods[])(struct ib_device *ibdev, - struct ib_queue_pair *qp, - struct golan_modify_qp_mbox_in_data *in) = { - - [GOLAN_IB_QPS_RESET] = golan_modify_qp_rst_to_init, - [GOLAN_IB_QPS_INIT] = golan_modify_qp_init_to_rtr, - [GOLAN_IB_QPS_RTR] = golan_modify_qp_rtr_to_rts -}; - -static int golan_modify_qp(struct ib_device *ibdev, - struct ib_queue_pair *qp) -{ - struct golan *golan = ib_get_drvdata(ibdev); - struct golan_queue_pair *golan_qp = ib_qp_get_drvdata(qp); - struct golan_modify_qp_mbox_in_data *in; - struct golan_cmd_layout *cmd; - enum golan_ib_qp_state prev_state; - int rc; - int modify_cmd[] = {GOLAN_CMD_OP_RST2INIT_QP, - GOLAN_CMD_OP_INIT2RTR_QP, - GOLAN_CMD_OP_RTR2RTS_QP}; - - while (golan_qp->state < GOLAN_IB_QPS_RTS) { - prev_state = golan_qp->state; - cmd = write_cmd(golan, DEF_CMD_IDX, modify_cmd[golan_qp->state], 0x0, - GEN_MBOX, NO_MBOX, - sizeof(struct golan_modify_qp_mbox_in), - sizeof(struct golan_modify_qp_mbox_out)); - - in = (struct golan_modify_qp_mbox_in_data *)GET_INBOX(golan, GEN_MBOX); - ((struct golan_modify_qp_mbox_in *)(cmd->in))->qpn = cpu_to_be32(qp->qpn); - rc = golan_modify_qp_methods[golan_qp->state](ibdev, qp, in); - if (rc) { - goto err_modify_qp_fill_inbox; - } -// in->ctx.qp_counter_set_usr_page = cpu_to_be32(golan->uar.index); - rc = send_command_and_wait(golan, DEF_CMD_IDX, GEN_MBOX, NO_MBOX, __FUNCTION__); - GOLAN_CHECK_RC_AND_CMD_STATUS( err_modify_qp_cmd ); - - ++(golan_qp->state); - - DBGC( golan , "%s QP number 0x%lx was modified from %s to %s\n", - __FUNCTION__, qp->qpn, golan_qp_state_as_string[prev_state], - golan_qp_state_as_string[golan_qp->state]); - } - - DBGC( golan , "%s QP number 0x%lx is ready to receive/send packets.\n", - __FUNCTION__, qp->qpn); - return 0; - -err_modify_qp_cmd: -err_modify_qp_fill_inbox: - DBGC (golan ,"%s Failed to modify QP number 0x%lx (rc = 0x%x)\n", - __FUNCTION__, qp->qpn, rc); - return rc; -} - -/** - * Destroy queue pair - * - * @v ibdev Infiniband device - * @v qp Queue pair - */ -static void golan_destroy_qp(struct ib_device *ibdev, - struct ib_queue_pair *qp) -{ - struct golan *golan = ib_get_drvdata(ibdev); - struct golan_queue_pair *golan_qp = ib_qp_get_drvdata(qp); - struct golan_cmd_layout *cmd; - unsigned long qpn = qp->qpn; - int rc; - - DBGC (golan, "%s in\n", __FUNCTION__); - - if (golan_qp->state != GOLAN_IB_QPS_RESET) { - if (golan_modify_qp_to_rst(ibdev, qp)) { - DBGC (golan ,"%s Failed to modify QP 0x%lx to RESET\n", __FUNCTION__, - qp->qpn); - } - } - - if (qp->recv.cq) { - golan_cq_clean(qp->recv.cq); - } - if (qp->send.cq && (qp->send.cq != qp->recv.cq)) { - golan_cq_clean(qp->send.cq); - } - - cmd = write_cmd(golan, DEF_CMD_IDX, GOLAN_CMD_OP_DESTROY_QP, 0x0, - NO_MBOX, NO_MBOX, - sizeof(struct golan_destroy_qp_mbox_in), - sizeof(struct golan_destroy_qp_mbox_out)); - ((struct golan_destroy_qp_mbox_in *)(cmd->in))->qpn = cpu_to_be32(qpn); - rc = send_command_and_wait(golan, DEF_CMD_IDX, NO_MBOX, NO_MBOX, __FUNCTION__); - GOLAN_PRINT_RC_AND_CMD_STATUS; - qp->qpn = 0; - - ib_qp_set_drvdata(qp, NULL); - free_dma(golan_qp->doorbell_record, sizeof(struct golan_qp_db)); - ufree((userptr_t)golan_qp->wqes); - free(golan_qp); - - DBGC( golan ,"%s QP 0x%lx was destroyed\n", __FUNCTION__, qpn); -} - -/** - * Calculate transmission rate - * - * @v av Address vector - * @ret golan_rate Golan rate - */ -static unsigned int golan_rate(enum ib_rate rate) { - return (((rate >= IB_RATE_2_5) && (rate <= IB_RATE_120)) ? (rate + 5) : 0); -} - -/** - * Post send work queue entry - * - * @v ibdev Infiniband device - * @v qp Queue pair - * @v av Address vector - * @v iobuf I/O buffer - * @ret rc Return status code - */ -static int golan_post_send(struct ib_device *ibdev, - struct ib_queue_pair *qp, - struct ib_address_vector *av, - struct io_buffer *iobuf) -{ - struct golan *golan = ib_get_drvdata(ibdev); - struct golan_queue_pair *golan_qp = ib_qp_get_drvdata(qp); - struct golan_send_wqe_ud *wqe = NULL; - struct golan_av *datagram = NULL; - unsigned long wqe_idx_mask; - unsigned long wqe_idx; - struct golan_wqe_data_seg *data = NULL; - struct golan_wqe_ctrl_seg *ctrl = NULL; -// static uint8_t toggle = 0; - - - wqe_idx_mask = (qp->send.num_wqes - 1); - wqe_idx = (qp->send.next_idx & wqe_idx_mask); - if (qp->send.iobufs[wqe_idx]) { - DBGC (golan ,"%s Send queue of QPN 0x%lx is full\n", __FUNCTION__, qp->qpn); - return -ENOMEM; - } - - qp->send.iobufs[wqe_idx] = iobuf; - - // change to this - //wqe_size_in_octa_words = golan_qp->sq.wqe_size_in_wqebb >> 4; - - wqe = &golan_qp->sq.wqes[wqe_idx].ud; - - //CHECK HW OWNERSHIP BIT ??? - - memset(wqe, 0, sizeof(*wqe)); - - ctrl = &wqe->ctrl; - ctrl->opmod_idx_opcode = cpu_to_be32(GOLAN_SEND_OPCODE | - ((u32)(golan_qp->sq.next_idx) << - GOLAN_WQE_CTRL_WQE_IDX_BIT)); - ctrl->qpn_ds = cpu_to_be32(GOLAN_SEND_UD_WQE_SIZE >> 4) | - golan_qp->doorbell_qpn; - ctrl->fm_ce_se = 0x8;//10 - 0 - 0 - data = &wqe->data; - data->byte_count = cpu_to_be32(iob_len(iobuf)); - data->lkey = cpu_to_be32(golan->mkey); - data->addr = VIRT_2_BE64_BUS(iobuf->data); - - datagram = &wqe->datagram; - datagram->key.qkey.qkey = cpu_to_be32(av->qkey); - datagram->dqp_dct = cpu_to_be32((1 << 31) | av->qpn); - datagram->stat_rate_sl = ((golan_rate(av->rate) << 4) | av->sl); - datagram->fl_mlid = (ibdev->lid & 0x007f); /* take only the 7 low bits of the LID */ - datagram->rlid = cpu_to_be16(av->lid); - datagram->grh_gid_fl = cpu_to_be32(av->gid_present << 30); - memcpy(datagram->rgid, av->gid.bytes, 16 /* sizeof(datagram->rgid) */); - - /* - * Make sure that descriptors are written before - * updating doorbell record and ringing the doorbell - */ - ++(qp->send.next_idx); - golan_qp->sq.next_idx = (golan_qp->sq.next_idx + GOLAN_WQEBBS_PER_SEND_UD_WQE); - golan_qp->doorbell_record->send_db = cpu_to_be16(golan_qp->sq.next_idx); - wmb(); - writeq(*((__be64 *)ctrl), golan->uar.virt + 0x800);// + -// ((toggle++ & 0x1) ? 0x100 : 0x0)); - return 0; -} - -/** - * Post receive work queue entry - * - * @v ibdev Infiniband device - * @v qp Queue pair - * @v iobuf I/O buffer - * @ret rc Return status code - */ -static int golan_post_recv(struct ib_device *ibdev, - struct ib_queue_pair *qp, - struct io_buffer *iobuf) -{ - struct golan *golan = ib_get_drvdata(ibdev); - struct golan_queue_pair *golan_qp = ib_qp_get_drvdata(qp); - struct ib_work_queue *wq = &qp->recv; - struct golan_recv_wqe_ud *wqe; - struct ib_global_route_header *grh; - struct golan_wqe_data_seg *data; - unsigned int wqe_idx_mask; - - /* Allocate work queue entry */ - wqe_idx_mask = (wq->num_wqes - 1); - if (wq->iobufs[wq->next_idx & wqe_idx_mask]) { - DBGC (golan ,"%s Receive queue of QPN 0x%lx is full\n", __FUNCTION__, qp->qpn); - return -ENOMEM; - } - - wq->iobufs[wq->next_idx & wqe_idx_mask] = iobuf; - wqe = & golan_qp->rq.wqes[wq->next_idx & wqe_idx_mask]; - - memset(wqe, 0, sizeof(*wqe)); - data = &wqe->data[0]; - if ( golan_qp->rq.grh ) { - grh = &golan_qp->rq.grh[wq->next_idx & wqe_idx_mask]; - data->byte_count = cpu_to_be32 ( sizeof ( *grh ) ); - data->lkey = cpu_to_be32 ( golan->mkey ); - data->addr = VIRT_2_BE64_BUS ( grh ); - data++; - } - - data->byte_count = cpu_to_be32(iob_tailroom(iobuf)); - data->lkey = cpu_to_be32(golan->mkey); - data->addr = VIRT_2_BE64_BUS(iobuf->data); - - ++wq->next_idx; - - /* - * Make sure that descriptors are written before - * updating doorbell record and ringing the doorbell - */ - wmb(); - golan_qp->doorbell_record->recv_db = cpu_to_be16(qp->recv.next_idx & 0xffff); - - return 0; -} - -static int golan_query_vport_context ( struct ib_device *ibdev ) { - struct golan *golan = ib_get_drvdata ( ibdev ); - struct golan_cmd_layout *cmd; - struct golan_query_hca_vport_context_inbox *in; - struct golan_query_hca_vport_context_data *context_data; - int rc; - - cmd = write_cmd ( golan, DEF_CMD_IDX, GOLAN_CMD_OP_QUERY_HCA_VPORT_CONTEXT, - 0x0, GEN_MBOX, GEN_MBOX, - sizeof(struct golan_query_hca_vport_context_inbox), - sizeof(struct golan_query_hca_vport_context_outbox) ); - - in = GOLAN_MBOX_IN ( cmd, in ); - in->port_num = (u8)ibdev->port; - - rc = send_command_and_wait ( golan, DEF_CMD_IDX, GEN_MBOX, GEN_MBOX, __FUNCTION__ ); - GOLAN_CHECK_RC_AND_CMD_STATUS( err_query_vport_context_cmd ); - - context_data = (struct golan_query_hca_vport_context_data *)( GET_OUTBOX ( golan, GEN_MBOX ) ); - - ibdev->node_guid.dwords[0] = context_data->node_guid[0]; - ibdev->node_guid.dwords[1] = context_data->node_guid[1]; - ibdev->lid = be16_to_cpu( context_data->lid ); - ibdev->sm_lid = be16_to_cpu( context_data->sm_lid ); - ibdev->sm_sl = context_data->sm_sl; - ibdev->port_state = context_data->port_state; - - return 0; -err_query_vport_context_cmd: - DBGC (golan ,"%s [%d] out\n", __FUNCTION__, rc); - return rc; -} - - -static int golan_query_vport_gid ( struct ib_device *ibdev ) { - struct golan *golan = ib_get_drvdata( ibdev ); - struct golan_cmd_layout *cmd; - struct golan_query_hca_vport_gid_inbox *in; - union ib_gid *ib_gid; - int rc; - - cmd = write_cmd( golan, DEF_CMD_IDX, GOLAN_CMD_OP_QUERY_HCA_VPORT_GID, - 0x0, GEN_MBOX, GEN_MBOX, - sizeof(struct golan_query_hca_vport_gid_inbox), - sizeof(struct golan_query_hca_vport_gid_outbox) ); - - in = GOLAN_MBOX_IN ( cmd, in ); - in->port_num = (u8)ibdev->port; - in->gid_index = 0; - rc = send_command_and_wait ( golan, DEF_CMD_IDX, GEN_MBOX, GEN_MBOX, __FUNCTION__ ); - GOLAN_CHECK_RC_AND_CMD_STATUS( err_query_vport_gid_cmd ); - - ib_gid = (union ib_gid *)( GET_OUTBOX ( golan, GEN_MBOX ) ); - - memcpy ( &ibdev->gid, ib_gid, sizeof(ibdev->gid) ); - - return 0; -err_query_vport_gid_cmd: - DBGC ( golan, "%s [%d] out\n", __FUNCTION__, rc); - return rc; -} - -static int golan_query_vport_pkey ( struct ib_device *ibdev ) { - struct golan *golan = ib_get_drvdata ( ibdev ); - struct golan_cmd_layout *cmd; - struct golan_query_hca_vport_pkey_inbox *in; - //struct golan_query_hca_vport_pkey_data *pkey_table; - int pkey_table_size_in_entries = (1 << (7 + golan->caps.pkey_table_size)); - int rc; - - cmd = write_cmd ( golan, DEF_CMD_IDX, GOLAN_CMD_OP_QUERY_HCA_VPORT_PKEY, - 0x0, GEN_MBOX, GEN_MBOX, - sizeof(struct golan_query_hca_vport_pkey_inbox), - sizeof(struct golan_outbox_hdr) + 8 + - sizeof(struct golan_query_hca_vport_pkey_data) * pkey_table_size_in_entries ); - - in = GOLAN_MBOX_IN ( cmd, in ); - in->port_num = (u8)ibdev->port; - in->pkey_index = 0xffff; - rc = send_command_and_wait ( golan, DEF_CMD_IDX, GEN_MBOX, GEN_MBOX, __FUNCTION__ ); - GOLAN_CHECK_RC_AND_CMD_STATUS( err_query_vport_pkey_cmd ); - - //pkey_table = (struct golan_query_hca_vport_pkey_data *)( GET_OUTBOX ( golan, GEN_MBOX ) ); - - return 0; -err_query_vport_pkey_cmd: - DBGC (golan ,"%s [%d] out\n", __FUNCTION__, rc); - return rc; -} - -static int golan_get_ib_info ( struct ib_device *ibdev ) { - int rc; - - rc = golan_query_vport_context ( ibdev ); - if ( rc != 0 ) { - DBG ( "golan_get_ib_info: golan_query_vport_context Failed (rc = %d)\n",rc ); - goto err_query_vport_context; - } - - rc = golan_query_vport_gid ( ibdev ); - if ( rc != 0 ) { - DBG ( "golan_get_ib_info: golan_query_vport_gid Failed (rc = %d)\n",rc ); - goto err_query_vport_gid; - } - - rc = golan_query_vport_pkey ( ibdev ); - if ( rc != 0 ) { - DBG ( "golan_get_ib_info: golan_query_vport_pkey Failed (rc = %d)\n",rc ); - goto err_query_vport_pkey; - } - return rc; -err_query_vport_pkey: -err_query_vport_gid: -err_query_vport_context: - DBG ( "%s [%d] out\n", __FUNCTION__, rc); - return rc; -} - -static int golan_complete(struct ib_device *ibdev, - struct ib_completion_queue *cq, - struct golan_cqe64 *cqe64) -{ - struct golan *golan = ib_get_drvdata(ibdev); - struct ib_work_queue *wq; - struct golan_queue_pair *golan_qp; - struct ib_queue_pair *qp; - struct io_buffer *iobuf = NULL; - struct ib_address_vector recv_dest; - struct ib_address_vector recv_source; - struct ib_global_route_header *grh; - struct golan_err_cqe *err_cqe64; - int gid_present, idx; - u16 wqe_ctr; - uint8_t opcode; - static int error_state; - uint32_t qpn = be32_to_cpu(cqe64->sop_drop_qpn) & 0xffffff; - int is_send = 0; - size_t len; - - opcode = cqe64->op_own >> GOLAN_CQE_OPCODE_BIT; - DBGC2( golan , "%s completion with opcode 0x%x\n", __FUNCTION__, opcode); - - if (opcode == GOLAN_CQE_REQ || opcode == GOLAN_CQE_REQ_ERR) { - is_send = 1; - } else { - is_send = 0; - } - if (opcode == GOLAN_CQE_REQ_ERR || opcode == GOLAN_CQE_RESP_ERR) { - err_cqe64 = (struct golan_err_cqe *)cqe64; - int i = 0; - if (!error_state++) { - DBGC (golan ,"\n"); - for ( i = 0 ; i < 16 ; i += 2 ) { - DBGC (golan ,"%x %x\n", - be32_to_cpu(((uint32_t *)(err_cqe64))[i]), - be32_to_cpu(((uint32_t *)(err_cqe64))[i + 1])); - } - DBGC (golan ,"CQE with error: Syndrome(0x%x), VendorSynd(0x%x), HW_SYN(0x%x)\n", - err_cqe64->syndrome, err_cqe64->vendor_err_synd, - err_cqe64->hw_syndrom); - } - } - /* Identify work queue */ - wq = ib_find_wq(cq, qpn, is_send); - if (!wq) { - DBGC (golan ,"%s unknown %s QPN 0x%x in CQN 0x%lx\n", - __FUNCTION__, (is_send ? "send" : "recv"), qpn, cq->cqn); - return -EINVAL; - } - - qp = wq->qp; - golan_qp = ib_qp_get_drvdata ( qp ); - - wqe_ctr = be16_to_cpu(cqe64->wqe_counter); - if (is_send) { - wqe_ctr &= ((GOLAN_WQEBBS_PER_SEND_UD_WQE * wq->num_wqes) - 1); - idx = wqe_ctr / GOLAN_WQEBBS_PER_SEND_UD_WQE; - } else { - idx = wqe_ctr & (wq->num_wqes - 1); - } - - iobuf = wq->iobufs[idx]; - if (!iobuf) { - DBGC (golan ,"%s IO Buffer 0x%x not found in QPN 0x%x\n", - __FUNCTION__, idx, qpn); - return -EINVAL; - } - wq->iobufs[idx] = NULL; - - if (is_send) { - ib_complete_send(ibdev, qp, iobuf, (opcode == GOLAN_CQE_REQ_ERR)); - } else { - len = be32_to_cpu(cqe64->byte_cnt); - memset(&recv_dest, 0, sizeof(recv_dest)); - recv_dest.qpn = qpn; - /* Construct address vector */ - memset(&recv_source, 0, sizeof(recv_source)); - switch (qp->type) { - case IB_QPT_SMI: - case IB_QPT_GSI: - case IB_QPT_UD: - /* Locate corresponding GRH */ - assert ( golan_qp->rq.grh != NULL ); - grh = &golan_qp->rq.grh[ idx ]; - - recv_source.qpn = be32_to_cpu(cqe64->flags_rqpn) & 0xffffff; - recv_source.lid = be16_to_cpu(cqe64->slid); - recv_source.sl = (be32_to_cpu(cqe64->flags_rqpn) >> 24) & 0xf; - gid_present = (be32_to_cpu(cqe64->flags_rqpn) >> 28) & 3; - if (!gid_present) { - recv_dest.gid_present = recv_source.gid_present = 0; - } else { - recv_dest.gid_present = recv_source.gid_present = 1; - //if (recv_source.gid_present == 0x1) { - memcpy(&recv_source.gid, &grh->sgid, sizeof(recv_source.gid)); - memcpy(&recv_dest.gid, &grh->dgid, sizeof(recv_dest.gid)); - //} else { // recv_source.gid_present = 0x3 - /* GRH is located in the upper 64 byte of the CQE128 - * currently not supported */ - //; - //} - } - len -= sizeof ( *grh ); - break; - case IB_QPT_RC: - case IB_QPT_ETH: - default: - DBGC (golan ,"%s Unsupported QP type (0x%x)\n", __FUNCTION__, qp->type); - return -EINVAL; - } - assert(len <= iob_tailroom(iobuf)); - iob_put(iobuf, len); - ib_complete_recv(ibdev, qp, &recv_dest, &recv_source, iobuf, (opcode == GOLAN_CQE_RESP_ERR)); - } - return 0; -} - -static int golan_is_hw_ownership(struct ib_completion_queue *cq, - struct golan_cqe64 *cqe64) -{ - return ((cqe64->op_own & GOLAN_CQE_OWNER_MASK) != - ((cq->next_idx >> ilog2(cq->num_cqes)) & 1)); -} -static void golan_poll_cq(struct ib_device *ibdev, - struct ib_completion_queue *cq) -{ - unsigned int i; - int rc = 0; - unsigned int cqe_idx_mask; - struct golan_cqe64 *cqe64; - struct golan_completion_queue *golan_cq = ib_cq_get_drvdata(cq); - struct golan *golan = ib_get_drvdata(ibdev); - - for (i = 0; i < cq->num_cqes; ++i) { - /* Look for completion entry */ - cqe_idx_mask = (cq->num_cqes - 1); - cqe64 = &golan_cq->cqes[cq->next_idx & cqe_idx_mask]; - /* temporary valid only for 64 byte CQE */ - if (golan_is_hw_ownership(cq, cqe64) || - ((cqe64->op_own >> GOLAN_CQE_OPCODE_BIT) == - GOLAN_CQE_OPCODE_NOT_VALID)) { - break; /* HW ownership */ - } - - DBGC2( golan , "%s CQN 0x%lx [%ld] \n", __FUNCTION__, cq->cqn, cq->next_idx); - /* - * Make sure we read CQ entry contents after we've checked the - * ownership bit. (PRM - 6.5.3.2) - */ - rmb(); - rc = golan_complete(ibdev, cq, cqe64); - if (rc != 0) { - DBGC (golan ,"%s CQN 0x%lx failed to complete\n", __FUNCTION__, cq->cqn); - } - - /* Update completion queue's index */ - cq->next_idx++; - - /* Update doorbell record */ - *(golan_cq->doorbell_record) = cpu_to_be32(cq->next_idx & 0xffffff); - } -} - -static const char *golan_eqe_type_str(u8 type) -{ - switch (type) { - case GOLAN_EVENT_TYPE_COMP: - return "GOLAN_EVENT_TYPE_COMP"; - case GOLAN_EVENT_TYPE_PATH_MIG: - return "GOLAN_EVENT_TYPE_PATH_MIG"; - case GOLAN_EVENT_TYPE_COMM_EST: - return "GOLAN_EVENT_TYPE_COMM_EST"; - case GOLAN_EVENT_TYPE_SQ_DRAINED: - return "GOLAN_EVENT_TYPE_SQ_DRAINED"; - case GOLAN_EVENT_TYPE_SRQ_LAST_WQE: - return "GOLAN_EVENT_TYPE_SRQ_LAST_WQE"; - case GOLAN_EVENT_TYPE_SRQ_RQ_LIMIT: - return "GOLAN_EVENT_TYPE_SRQ_RQ_LIMIT"; - case GOLAN_EVENT_TYPE_CQ_ERROR: - return "GOLAN_EVENT_TYPE_CQ_ERROR"; - case GOLAN_EVENT_TYPE_WQ_CATAS_ERROR: - return "GOLAN_EVENT_TYPE_WQ_CATAS_ERROR"; - case GOLAN_EVENT_TYPE_PATH_MIG_FAILED: - return "GOLAN_EVENT_TYPE_PATH_MIG_FAILED"; - case GOLAN_EVENT_TYPE_WQ_INVAL_REQ_ERROR: - return "GOLAN_EVENT_TYPE_WQ_INVAL_REQ_ERROR"; - case GOLAN_EVENT_TYPE_WQ_ACCESS_ERROR: - return "GOLAN_EVENT_TYPE_WQ_ACCESS_ERROR"; - case GOLAN_EVENT_TYPE_SRQ_CATAS_ERROR: - return "GOLAN_EVENT_TYPE_SRQ_CATAS_ERROR"; - case GOLAN_EVENT_TYPE_INTERNAL_ERROR: - return "GOLAN_EVENT_TYPE_INTERNAL_ERROR"; - case GOLAN_EVENT_TYPE_PORT_CHANGE: - return "GOLAN_EVENT_TYPE_PORT_CHANGE"; - case GOLAN_EVENT_TYPE_GPIO_EVENT: - return "GOLAN_EVENT_TYPE_GPIO_EVENT"; - case GOLAN_EVENT_TYPE_REMOTE_CONFIG: - return "GOLAN_EVENT_TYPE_REMOTE_CONFIG"; - case GOLAN_EVENT_TYPE_DB_BF_CONGESTION: - return "GOLAN_EVENT_TYPE_DB_BF_CONGESTION"; - case GOLAN_EVENT_TYPE_STALL_EVENT: - return "GOLAN_EVENT_TYPE_STALL_EVENT"; - case GOLAN_EVENT_TYPE_CMD: - return "GOLAN_EVENT_TYPE_CMD"; - case GOLAN_EVENT_TYPE_PAGE_REQUEST: - return "GOLAN_EVENT_TYPE_PAGE_REQUEST"; - default: - return "Unrecognized event"; - } -} - -static const char *golan_eqe_port_subtype_str(u8 subtype) -{ - switch (subtype) { - case GOLAN_PORT_CHANGE_SUBTYPE_DOWN: - return "GOLAN_PORT_CHANGE_SUBTYPE_DOWN"; - case GOLAN_PORT_CHANGE_SUBTYPE_ACTIVE: - return "GOLAN_PORT_CHANGE_SUBTYPE_ACTIVE"; - case GOLAN_PORT_CHANGE_SUBTYPE_INITIALIZED: - return "GOLAN_PORT_CHANGE_SUBTYPE_INITIALIZED"; - case GOLAN_PORT_CHANGE_SUBTYPE_LID: - return "GOLAN_PORT_CHANGE_SUBTYPE_LID"; - case GOLAN_PORT_CHANGE_SUBTYPE_PKEY: - return "GOLAN_PORT_CHANGE_SUBTYPE_PKEY"; - case GOLAN_PORT_CHANGE_SUBTYPE_GUID: - return "GOLAN_PORT_CHANGE_SUBTYPE_GUID"; - case GOLAN_PORT_CHANGE_SUBTYPE_CLIENT_REREG: - return "GOLAN_PORT_CHANGE_SUBTYPE_CLIENT_REREG"; - default: - return "Unrecognized event"; - } -} - -/** - * Update Infiniband parameters using Commands - * - * @v ibdev Infiniband device - * @ret rc Return status code - */ -static int golan_ib_update ( struct ib_device *ibdev ) { - int rc; - - /* Get IB parameters */ - if ( ( rc = golan_get_ib_info ( ibdev ) ) != 0 ) - return rc; - - /* Notify Infiniband core of potential link state change */ - ib_link_state_changed ( ibdev ); - - return 0; -} - -static inline void golan_handle_port_event(struct golan *golan, struct golan_eqe *eqe) -{ - struct ib_device *ibdev; - u8 port; - - port = (eqe->data.port.port >> 4) & 0xf; - ibdev = golan->ports[port - 1].ibdev; - - if ( ! ib_is_open ( ibdev ) ) - return; - - switch (eqe->sub_type) { - case GOLAN_PORT_CHANGE_SUBTYPE_CLIENT_REREG: - case GOLAN_PORT_CHANGE_SUBTYPE_ACTIVE: - golan_ib_update ( ibdev ); - case GOLAN_PORT_CHANGE_SUBTYPE_DOWN: - case GOLAN_PORT_CHANGE_SUBTYPE_LID: - case GOLAN_PORT_CHANGE_SUBTYPE_PKEY: - case GOLAN_PORT_CHANGE_SUBTYPE_GUID: - case GOLAN_PORT_CHANGE_SUBTYPE_INITIALIZED: - DBGC( golan , "%s event %s(%d) (sub event %s(%d))arrived on port %d\n", - __FUNCTION__, golan_eqe_type_str(eqe->type), eqe->type, - golan_eqe_port_subtype_str(eqe->sub_type), - eqe->sub_type, port); - break; - default: - DBGC (golan ,"%s Port event with unrecognized subtype: port %d, sub_type %d\n", - __FUNCTION__, port, eqe->sub_type); - } -} - -static struct golan_eqe *golan_next_eqe_sw(struct golan_event_queue *eq) -{ - uint32_t entry = (eq->cons_index & (GOLAN_NUM_EQES - 1)); - struct golan_eqe *eqe = &(eq->eqes[entry]); - return ((eqe->owner != ((eq->cons_index >> ilog2(GOLAN_NUM_EQES)) & 1)) ? NULL : eqe); -} - - -/** - * Poll event queue - * - * @v ibdev Infiniband device - */ -static void golan_poll_eq(struct ib_device *ibdev) -{ - struct golan *golan = ib_get_drvdata(ibdev); - struct golan_event_queue *eq = &(golan->eq); - struct golan_eqe *eqe; - u32 cqn; - int counter = 0; - - while ((eqe = golan_next_eqe_sw(eq)) && (counter < GOLAN_NUM_EQES)) { - /* - * Make sure we read EQ entry contents after we've - * checked the ownership bit. - */ - rmb(); - - DBGC( golan , "%s eqn %d, eqe type %s\n", __FUNCTION__, eq->eqn, - golan_eqe_type_str(eqe->type)); - switch (eqe->type) { - case GOLAN_EVENT_TYPE_COMP: - /* We dont need to handle completion events since we - * poll all the CQs after polling the EQ */ - break; - case GOLAN_EVENT_TYPE_PATH_MIG: - case GOLAN_EVENT_TYPE_COMM_EST: - case GOLAN_EVENT_TYPE_SQ_DRAINED: - case GOLAN_EVENT_TYPE_SRQ_LAST_WQE: - case GOLAN_EVENT_TYPE_WQ_CATAS_ERROR: - case GOLAN_EVENT_TYPE_PATH_MIG_FAILED: - case GOLAN_EVENT_TYPE_WQ_INVAL_REQ_ERROR: - case GOLAN_EVENT_TYPE_WQ_ACCESS_ERROR: - case GOLAN_EVENT_TYPE_SRQ_RQ_LIMIT: - case GOLAN_EVENT_TYPE_SRQ_CATAS_ERROR: - DBGC( golan , "%s event %s(%d) arrived\n", __FUNCTION__, - golan_eqe_type_str(eqe->type), eqe->type); - break; - case GOLAN_EVENT_TYPE_CMD: -// golan_cmd_comp_handler(be32_to_cpu(eqe->data.cmd.vector)); - break; - case GOLAN_EVENT_TYPE_PORT_CHANGE: - golan_handle_port_event(golan, eqe); - break; - case GOLAN_EVENT_TYPE_CQ_ERROR: - cqn = be32_to_cpu(eqe->data.cq_err.cqn) & 0xffffff; - DBGC (golan ,"CQ error on CQN 0x%x, syndrom 0x%x\n", - cqn, eqe->data.cq_err.syndrome); -// mlx5_cq_event(dev, cqn, eqe->type); - break; - case GOLAN_EVENT_TYPE_PAGE_REQUEST: - { - /* we should check if we get this event while we - * waiting for a command */ - u16 func_id = be16_to_cpu(eqe->data.req_pages.func_id); - s16 npages = be16_to_cpu(eqe->data.req_pages.num_pages); - - DBGC (golan ,"%s page request for func 0x%x, napges %d\n", - __FUNCTION__, func_id, npages); - golan_provide_pages(golan, npages, func_id); - } - break; - default: - DBGC (golan ,"%s Unhandled event 0x%x on EQ 0x%x\n", __FUNCTION__, - eqe->type, eq->eqn); - break; - } - - ++eq->cons_index; - golan_eq_update_ci(eq, GOLAN_EQ_UNARMED); - ++counter; - } -} - -/** - * Attach to multicast group - * - * @v ibdev Infiniband device - * @v qp Queue pair - * @v gid Multicast GID - * @ret rc Return status code - */ -static int golan_mcast_attach(struct ib_device *ibdev, - struct ib_queue_pair *qp, - union ib_gid *gid) -{ - struct golan *golan = ib_get_drvdata(ibdev); - struct golan_cmd_layout *cmd; - int rc; - - if ( qp == NULL ) { - DBGC( golan, "%s: Invalid pointer, could not attach QPN to MCG\n", - __FUNCTION__ ); - return -EFAULT; - } - - cmd = write_cmd(golan, DEF_CMD_IDX, GOLAN_CMD_OP_ATTACH_TO_MCG, 0x0, - GEN_MBOX, NO_MBOX, - sizeof(struct golan_attach_mcg_mbox_in), - sizeof(struct golan_attach_mcg_mbox_out)); - ((struct golan_attach_mcg_mbox_in *)(cmd->in))->qpn = cpu_to_be32(qp->qpn); - - memcpy(GET_INBOX(golan, GEN_MBOX), gid, sizeof(*gid)); - - rc = send_command_and_wait(golan, DEF_CMD_IDX, GEN_MBOX, NO_MBOX, __FUNCTION__); - GOLAN_CHECK_RC_AND_CMD_STATUS( err_attach_to_mcg_cmd ); - - DBGC( golan , "%s: QPN 0x%lx was attached to MCG\n", __FUNCTION__, qp->qpn); - return 0; -err_attach_to_mcg_cmd: - DBGC (golan ,"%s [%d] out\n", __FUNCTION__, rc); - return rc; -} - -/** - * Detach from multicast group - * - * @v ibdev Infiniband device - * @v qp Queue pair - * @v gid Multicast GID - * @ret rc Return status code - */ -static void golan_mcast_detach(struct ib_device *ibdev, - struct ib_queue_pair *qp, - union ib_gid *gid) -{ - struct golan *golan = ib_get_drvdata(ibdev); - struct golan_cmd_layout *cmd; - int rc; - - cmd = write_cmd(golan, DEF_CMD_IDX, GOLAN_CMD_OP_DETACH_FROM_MCG, 0x0, - GEN_MBOX, NO_MBOX, - sizeof(struct golan_detach_mcg_mbox_in), - sizeof(struct golan_detach_mcg_mbox_out)); - ((struct golan_detach_mcg_mbox_in *)(cmd->in))->qpn = cpu_to_be32(qp->qpn); - - memcpy(GET_INBOX(golan, GEN_MBOX), gid, sizeof(*gid)); - - rc = send_command_and_wait(golan, DEF_CMD_IDX, GEN_MBOX, NO_MBOX, __FUNCTION__); - GOLAN_PRINT_RC_AND_CMD_STATUS; - - DBGC( golan , "%s: QPN 0x%lx was detached from MCG\n", __FUNCTION__, qp->qpn); -} - -/** - * Inform embedded subnet management agent of a received MAD - * - * @v ibdev Infiniband device - * @v mad MAD - * @ret rc Return status code - */ -static int golan_inform_sma(struct ib_device *ibdev, - union ib_mad *mad) -{ - if (!ibdev || !mad) { - return 1; - } - - return 0; -} - -static int golan_register_ibdev(struct golan_port *port) -{ - struct ib_device *ibdev = port->ibdev; - int rc; - - golan_get_ib_info ( ibdev ); - /* Register Infiniband device */ - if ((rc = register_ibdev(ibdev)) != 0) { - DBG ( "%s port %d could not register IB device: (rc = %d)\n", - __FUNCTION__, ibdev->port, rc); - return rc; - } - - port->netdev = ipoib_netdev( ibdev ); - - return 0; -} - -static inline void golan_bring_down(struct golan *golan) -{ - - DBGC(golan, "%s: start\n", __FUNCTION__); - - if (~golan->flags & GOLAN_OPEN) { - DBGC(golan, "%s: end (already closed)\n", __FUNCTION__); - return; - } - - golan_destroy_mkey(golan); - golan_dealloc_pd(golan); - golan_destory_eq(golan); - golan_dealloc_uar(golan); - golan_teardown_hca(golan, GOLAN_TEARDOWN_GRACEFUL); - golan_handle_pages(golan, GOLAN_REG_PAGES , GOLAN_PAGES_TAKE); - golan_disable_hca(golan); - golan_cmd_uninit(golan); - golan->flags &= ~GOLAN_OPEN; - DBGC(golan, "%s: end\n", __FUNCTION__); -} - -static int golan_set_link_speed ( struct golan *golan ){ - mlx_utils utils; - mlx_status status; - int i = 0; - - memset ( &utils, 0, sizeof ( utils ) ); - - status = mlx_utils_init ( &utils, golan->pci ); - MLX_CHECK_STATUS ( golan->pci, status, utils_init_err, "mlx_utils_init failed" ); - - status = mlx_pci_gw_init ( &utils ); - MLX_CHECK_STATUS ( golan->pci, status, pci_gw_init_err, "mlx_pci_gw_init failed" ); - - for ( i = 0; i < golan->caps.num_ports; ++i ) { - status = mlx_set_link_speed( &utils, i + 1, LINK_SPEED_IB, LINK_SPEED_SDR ); - MLX_CHECK_STATUS ( golan->pci, status, set_link_speed_err, "mlx_set_link_speed failed" ); - } - -set_link_speed_err: - mlx_pci_gw_teardown( &utils ); -pci_gw_init_err: -utils_init_err: - return status; -} - -static inline int golan_bring_up(struct golan *golan) -{ - int rc = 0; - DBGC(golan, "%s\n", __FUNCTION__); - - if (golan->flags & GOLAN_OPEN) - return 0; - - if (( rc = golan_cmd_init(golan) )) - goto out; - - if (( rc = golan_core_enable_hca(golan) )) - goto cmd_uninit; - - /* Query for need for boot pages */ - if (( rc = golan_handle_pages(golan, GOLAN_BOOT_PAGES, GOLAN_PAGES_GIVE) )) - goto disable; - - if (( rc = golan_qry_hca_cap(golan) )) - goto pages; - - if (( rc = golan_set_hca_cap(golan) )) - goto pages; - - if (( rc = golan_handle_pages(golan, GOLAN_INIT_PAGES, GOLAN_PAGES_GIVE) )) - goto pages; - - if (( rc = golan_set_link_speed ( golan ) )) - goto pages_teardown; - - //Reg Init? - if (( rc = golan_hca_init(golan) )) - goto pages_2; - - if (( rc = golan_alloc_uar(golan) )) - goto teardown; - - if (( rc = golan_create_eq(golan) )) - goto de_uar; - - if (( rc = golan_alloc_pd(golan) )) - goto de_eq; - - if (( rc = golan_create_mkey(golan) )) - goto de_pd; - - golan->flags |= GOLAN_OPEN; - return 0; - - golan_destroy_mkey(golan); -de_pd: - golan_dealloc_pd(golan); -de_eq: - golan_destory_eq(golan); -de_uar: - golan_dealloc_uar(golan); -teardown: - golan_teardown_hca(golan, GOLAN_TEARDOWN_GRACEFUL); -pages_2: -pages_teardown: - golan_handle_pages(golan, GOLAN_INIT_PAGES, GOLAN_PAGES_TAKE); -pages: - golan_handle_pages(golan, GOLAN_BOOT_PAGES, GOLAN_PAGES_TAKE); -disable: - golan_disable_hca(golan); -cmd_uninit: - golan_cmd_uninit(golan); -out: - return rc; -} - -/** - * Close Infiniband link - * - * @v ibdev Infiniband device - */ -static void golan_ib_close ( struct ib_device *ibdev __unused ) {} - -/** - * Initialise Infiniband link - * - * @v ibdev Infiniband device - * @ret rc Return status code - */ -static int golan_ib_open ( struct ib_device *ibdev ) { - DBG ( "%s start\n", __FUNCTION__ ); - - if ( ! ibdev ) - return -EINVAL; - - golan_ib_update ( ibdev ); - - DBG ( "%s end\n", __FUNCTION__ ); - return 0; -} - -/** Golan Infiniband operations */ -static struct ib_device_operations golan_ib_operations = { - .create_cq = golan_create_cq, - .destroy_cq = golan_destroy_cq, - .create_qp = golan_create_qp, - .modify_qp = golan_modify_qp, - .destroy_qp = golan_destroy_qp, - .post_send = golan_post_send, - .post_recv = golan_post_recv, - .poll_cq = golan_poll_cq, - .poll_eq = golan_poll_eq, - .open = golan_ib_open, - .close = golan_ib_close, - .mcast_attach = golan_mcast_attach, - .mcast_detach = golan_mcast_detach, - .set_port_info = golan_inform_sma, - .set_pkey_table = golan_inform_sma, -}; - -static int golan_probe_normal ( struct pci_device *pci ) { - struct golan *golan; - struct ib_device *ibdev; - struct golan_port *port; - int i; - int rc = 0; - - golan = golan_alloc(); - if ( !golan ) { - rc = -ENOMEM; - goto err_golan_alloc; - } - - if ( golan_init_pages( &golan->pages ) ) { - rc = -ENOMEM; - goto err_golan_golan_init_pages; - } - - /* Setup PCI bus and HCA BAR */ - pci_set_drvdata( pci, golan ); - golan->pci = pci; - golan_pci_init( golan ); - /* config command queues */ - if ( fw_ver_and_cmdif( golan ) ) { - rc = -1; - goto err_fw_ver_cmdif; - } - - if ( golan_bring_up( golan ) ) { - DBGC (golan ,"golan bringup failed\n"); - rc = -1; - goto err_golan_bringup; - } - - /* Allocate Infiniband devices */ - for (i = 0; i < golan->caps.num_ports; ++i) { - ibdev = alloc_ibdev( 0 ); - if ( !ibdev ) { - rc = -ENOMEM; - goto err_golan_probe_alloc_ibdev; - } - golan->ports[i].ibdev = ibdev; - golan->ports[i].vep_number = 0; - ibdev->op = &golan_ib_operations; - ibdev->dev = &pci->dev; - ibdev->port = (GOLAN_PORT_BASE + i); - ib_set_drvdata( ibdev, golan ); - } - - /* Register devices */ - for ( i = 0; i < golan->caps.num_ports; ++i ) { - port = &golan->ports[i]; - if ((rc = golan_register_ibdev ( port ) ) != 0 ) - goto err_golan_probe_register_ibdev; - } - - return 0; - - i = golan->caps.num_ports; -err_golan_probe_register_ibdev: - for ( i-- ; ( signed int ) i >= 0 ; i-- ) - unregister_ibdev ( golan->ports[i].ibdev ); - - i = golan->caps.num_ports; -err_golan_probe_alloc_ibdev: - for ( i-- ; ( signed int ) i >= 0 ; i-- ) - ibdev_put ( golan->ports[i].ibdev ); - - golan_bring_down ( golan ); -err_golan_bringup: -err_fw_ver_cmdif: - iounmap( golan->iseg ); - golan_free_pages( &golan->pages ); -err_golan_golan_init_pages: - free ( golan ); -err_golan_alloc: - DBGC (golan ,"%s rc = %d\n", __FUNCTION__, rc); - return rc; -} - -static void golan_remove_normal ( struct pci_device *pci ) { - struct golan *golan = pci_get_drvdata(pci); - struct golan_port *port; - int i; - - DBGC(golan, "%s\n", __FUNCTION__); - - for ( i = ( golan->caps.num_ports - 1 ) ; i >= 0 ; i-- ) { - port = &golan->ports[i]; - unregister_ibdev ( port->ibdev ); - } - for ( i = ( golan->caps.num_ports - 1 ) ; i >= 0 ; i-- ) { - netdev_nullify ( golan->ports[i].netdev ); - netdev_put ( golan->ports[i].netdev ); - } - for ( i = ( golan->caps.num_ports - 1 ) ; i >= 0 ; i-- ) { - ibdev_put ( golan->ports[i].ibdev ); - } - - golan_bring_down(golan); - iounmap( golan->iseg ); - golan_free_pages( &golan->pages ); - free(golan); -} - -/*************************************************************************** - * NODNIC operations - **************************************************************************/ -static mlx_status shomron_fill_eth_send_wqe ( struct ib_device *ibdev, - struct ib_queue_pair *qp, struct ib_address_vector *av __unused, - struct io_buffer *iobuf, struct nodnic_send_wqbb *wqbb, - unsigned long wqe_index ) { - mlx_status status = MLX_SUCCESS; - struct flexboot_nodnic *flexboot_nodnic = ib_get_drvdata ( ibdev ); - struct shomron_nodnic_eth_send_wqe *eth_wqe = NULL; - struct flexboot_nodnic_port *port = &flexboot_nodnic->port[ibdev->port - 1]; - struct flexboot_nodnic_queue_pair *flexboot_nodnic_qp = - ib_qp_get_drvdata ( qp ); - nodnic_qp *nodnic_qp = flexboot_nodnic_qp->nodnic_queue_pair; - struct nodnic_send_ring *send_ring = &nodnic_qp->send; - mlx_uint32 qpn = 0; - - eth_wqe = (struct shomron_nodnic_eth_send_wqe *)wqbb; - memset ( ( ( ( void * ) eth_wqe ) ), 0, - ( sizeof ( *eth_wqe ) ) ); - - status = nodnic_port_get_qpn(&port->port_priv, &send_ring->nodnic_ring, - &qpn); - if ( status != MLX_SUCCESS ) { - DBG("nodnic_port_get_qpn failed\n"); - goto err; - } - -#define SHOMRON_GENERATE_CQE 0x3 -#define SHOMRON_INLINE_HEADERS_SIZE 18 -#define SHOMRON_INLINE_HEADERS_OFFSET 32 - MLX_FILL_2 ( ð_wqe->ctrl, 0, opcode, FLEXBOOT_NODNIC_OPCODE_SEND, - wqe_index, wqe_index & 0xFFFF); - MLX_FILL_2 ( ð_wqe->ctrl, 1, ds, 0x4 , qpn, qpn ); - MLX_FILL_1 ( ð_wqe->ctrl, 2, - ce, SHOMRON_GENERATE_CQE /* generate completion */ - ); - MLX_FILL_2 ( ð_wqe->ctrl, 7, - inline_headers1, - cpu_to_be16(*(mlx_uint16 *)iobuf->data), - inline_headers_size, SHOMRON_INLINE_HEADERS_SIZE - ); - memcpy((void *)ð_wqe->ctrl + SHOMRON_INLINE_HEADERS_OFFSET, - iobuf->data + 2, SHOMRON_INLINE_HEADERS_SIZE - 2); - iob_pull(iobuf, SHOMRON_INLINE_HEADERS_SIZE); - MLX_FILL_1 ( ð_wqe->data[0], 0, - byte_count, iob_len ( iobuf ) ); - MLX_FILL_1 ( ð_wqe->data[0], 1, l_key, - flexboot_nodnic->device_priv.lkey ); - MLX_FILL_H ( ð_wqe->data[0], 2, - local_address_h, virt_to_bus ( iobuf->data ) ); - MLX_FILL_1 ( ð_wqe->data[0], 3, - local_address_l, virt_to_bus ( iobuf->data ) ); -err: - return status; -} - -static mlx_status shomron_fill_completion( void *cqe, struct cqe_data *cqe_data ) { - union shomronprm_completion_entry *cq_entry; - uint32_t opcode; - - cq_entry = (union shomronprm_completion_entry *)cqe; - cqe_data->owner = MLX_GET ( &cq_entry->normal, owner ); - opcode = MLX_GET ( &cq_entry->normal, opcode ); -#define FLEXBOOT_NODNIC_OPCODE_CQ_SEND 0 -#define FLEXBOOT_NODNIC_OPCODE_CQ_RECV 2 -#define FLEXBOOT_NODNIC_OPCODE_CQ_SEND_ERR 13 -#define FLEXBOOT_NODNIC_OPCODE_CQ_RECV_ERR 14 - cqe_data->is_error = - ( opcode >= FLEXBOOT_NODNIC_OPCODE_CQ_RECV_ERR); - if ( cqe_data->is_error ) { - cqe_data->syndrome = MLX_GET ( &cq_entry->error, syndrome ); - cqe_data->vendor_err_syndrome = - MLX_GET ( &cq_entry->error, vendor_error_syndrome ); - cqe_data->is_send = - (opcode == FLEXBOOT_NODNIC_OPCODE_CQ_SEND_ERR); - } else { - cqe_data->is_send = - (opcode == FLEXBOOT_NODNIC_OPCODE_CQ_SEND); - cqe_data->wqe_counter = MLX_GET ( &cq_entry->normal, wqe_counter ); - cqe_data->byte_cnt = MLX_GET ( &cq_entry->normal, byte_cnt ); - - } - if ( cqe_data->is_send == TRUE ) - cqe_data->qpn = MLX_GET ( &cq_entry->normal, qpn ); - else - cqe_data->qpn = MLX_GET ( &cq_entry->normal, srqn ); - - return 0; -} - -static mlx_status shomron_cqe_set_owner ( void *cq, unsigned int num_cqes ) { - unsigned int i = 0; - union shomronprm_completion_entry *cq_list; - - cq_list = (union shomronprm_completion_entry *)cq; - for ( ; i < num_cqes ; i++ ) - MLX_FILL_1 ( &cq_list[i].normal, 15, owner, 1 ); - return 0; -} - -static mlx_size shomron_get_cqe_size () { - return sizeof ( union shomronprm_completion_entry ); -} - -struct flexboot_nodnic_callbacks shomron_nodnic_callbacks = { - .get_cqe_size = shomron_get_cqe_size, - .fill_send_wqe[IB_QPT_ETH] = shomron_fill_eth_send_wqe, - .fill_completion = shomron_fill_completion, - .cqe_set_owner = shomron_cqe_set_owner, - .irq = flexboot_nodnic_eth_irq, -}; - -static int shomron_nodnic_supported = 0; - -static int shomron_nodnic_is_supported ( struct pci_device *pci ) { - if ( pci->device == 0x1011 ) - return 0; - - return flexboot_nodnic_is_supported ( pci ); -} -/**************************************************************************/ - -static int golan_probe ( struct pci_device *pci ) { - int rc = -ENOTSUP; - - DBG ( "%s: start\n", __FUNCTION__ ); - - if ( ! pci ) { - DBG ( "%s: PCI is NULL\n", __FUNCTION__ ); - rc = -EINVAL; - goto probe_done; - } - - shomron_nodnic_supported = shomron_nodnic_is_supported ( pci ); - if ( shomron_nodnic_supported ) { - rc = flexboot_nodnic_probe ( pci, &shomron_nodnic_callbacks, NULL ); - if ( rc == 0 ) { - DBG ( "%s: Using NODNIC driver\n", __FUNCTION__ ); - goto probe_done; - } - shomron_nodnic_supported = 0; - } - - if ( ! shomron_nodnic_supported ) { - DBG ( "%s: Using normal driver\n", __FUNCTION__ ); - rc = golan_probe_normal ( pci ); - } - -probe_done: - DBG ( "%s: rc = %d\n", __FUNCTION__, rc ); - return rc; -} - -static void golan_remove ( struct pci_device *pci ) { - DBG ( "%s: start\n", __FUNCTION__ ); - - if ( ! shomron_nodnic_supported ) { - DBG ( "%s: Using normal driver remove\n", __FUNCTION__ ); - golan_remove_normal ( pci ); - return; - } - - DBG ( "%s: Using NODNIC driver remove\n", __FUNCTION__ ); - - flexboot_nodnic_remove ( pci ); - - DBG ( "%s: end\n", __FUNCTION__ ); -} - -static struct pci_device_id golan_nics[] = { - PCI_ROM ( 0x15b3, 0x1011, "ConnectIB", "ConnectIB HCA driver: DevID 4113", 0 ), - PCI_ROM ( 0x15b3, 0x1013, "ConnectX-4", "ConnectX-4 HCA driver, DevID 4115", 0 ), - PCI_ROM ( 0x15b3, 0x1015, "ConnectX-4Lx", "ConnectX-4Lx HCA driver, DevID 4117", 0 ), -}; - -struct pci_driver golan_driver __pci_driver = { - .ids = golan_nics, - .id_count = (sizeof(golan_nics) / sizeof(golan_nics[0])), - .probe = golan_probe, - .remove = golan_remove, -}; diff --git a/roms/ipxe/src/drivers/infiniband/golan.h b/roms/ipxe/src/drivers/infiniband/golan.h deleted file mode 100755 index a6cb4e744..000000000 --- a/roms/ipxe/src/drivers/infiniband/golan.h +++ /dev/null @@ -1,326 +0,0 @@ -#ifndef _GOLAN_H_ -#define _GOLAN_H_ - -/* - * Copyright (C) 2013-2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include <byteswap.h> -#include <errno.h> -#include <stdio.h> -#include <unistd.h> -#include <ipxe/io.h> -#include <ipxe/pci.h> -#include <ipxe/pcibackup.h> -#include "CIB_PRM.h" - -#define GOLAN_PCI_CONFIG_BAR_SIZE 0x100000//HERMON_PCI_CONFIG_BAR_SIZE //TODO: What is the BAR size? - -#define GOLAN_PAS_SIZE sizeof(uint64_t) - -#define GOLAN_INVALID_LKEY 0x00000100UL - -#define GOLAN_MAX_PORTS 2 -#define GOLAN_PORT_BASE 1 - -#define MELLANOX_VID 0x15b3 -#define GOLAN_HCA_BAR PCI_BASE_ADDRESS_0 //BAR 0 - -#define GOLAN_HCR_MAX_WAIT_MS 10000 - -#define min(a,b) ((a)<(b)?(a):(b)) - -#define GOLAN_PAGE_SHIFT 12 -#define GOLAN_PAGE_SIZE (1 << GOLAN_PAGE_SHIFT) -#define GOLAN_PAGE_MASK (GOLAN_PAGE_SIZE - 1) - -#define MAX_MBOX ( GOLAN_PAGE_SIZE / MAILBOX_STRIDE ) -#define DEF_CMD_IDX 1 -#define MEM_CMD_IDX 0 -#define NO_MBOX 0xffff -#define MEM_MBOX MEM_CMD_IDX -#define GEN_MBOX DEF_CMD_IDX - -#define CMD_IF_REV 4 - -#define MAX_PASE_MBOX ((GOLAN_CMD_PAS_CNT) - 2) - -#define CMD_STATUS( golan , idx ) ((struct golan_outbox_hdr *)(get_cmd( (golan) , (idx) )->out))->status -#define CMD_SYND( golan , idx ) ((struct golan_outbox_hdr *)(get_cmd( (golan) , (idx) )->out))->syndrome -#define QRY_PAGES_OUT( golan, idx ) ((struct golan_query_pages_outbox *)(get_cmd( (golan) , (idx) )->out)) - -#define VIRT_2_BE64_BUS( addr ) cpu_to_be64(((unsigned long long )virt_to_bus(addr))) -#define BE64_BUS_2_VIRT( addr ) bus_to_virt(be64_to_cpu(addr)) -#define USR_2_BE64_BUS( addr ) cpu_to_be64(((unsigned long long )user_to_phys(addr, 0))) -#define BE64_BUS_2_USR( addr ) be64_to_cpu(phys_to_user(addr)) - -#define GET_INBOX(golan, idx) (&(((struct mbox *)(golan->mboxes.inbox))[idx])) -#define GET_OUTBOX(golan, idx) (&(((struct mbox *)(golan->mboxes.outbox))[idx])) - -#define GOLAN_MBOX_IN( cmd_ptr, in_ptr ) ( { \ - union { \ - __be32 raw[4]; \ - typeof ( *(in_ptr) ) cooked; \ - } *u = container_of ( &(cmd_ptr)->in[0], typeof ( *u ), raw[0] ); \ - &u->cooked; } ) - -#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) - -/* Fw status fields */ -typedef enum { - NO_ERRORS = 0x0, - SIGNATURE_ERROR = 0x1, - TOKEN_ERROR = 0x2, - BAD_BLOCK_NUMBER = 0x3, - BAD_OUTPUT_POINTER = 0x4, // pointer not align to mailbox size - BAD_INPUT_POINTER = 0x5, // pointer not align to mailbox size - INTERNAL_ERROR = 0x6, - INPUT_LEN_ERROR = 0x7, // input length less than 0x8. - OUTPUT_LEN_ERROR = 0x8, // output length less than 0x8. - RESERVE_NOT_ZERO = 0x9, - BAD_CMD_TYPE = 0x10, -} return_hdr_t; - -struct golan_cmdq_md { - void *addr; - u16 log_stride; - u16 size; -}; - -struct golan_uar { - uint32_t index; - void *virt; - unsigned long phys; -}; - -/* Queue Pair */ -#define GOLAN_SEND_WQE_BB_SIZE 64 -#define GOLAN_SEND_UD_WQE_SIZE sizeof(struct golan_send_wqe_ud) -#define GOLAN_RECV_WQE_SIZE sizeof(struct golan_recv_wqe_ud) -#define GOLAN_WQEBBS_PER_SEND_UD_WQE DIV_ROUND_UP(GOLAN_SEND_UD_WQE_SIZE, GOLAN_SEND_WQE_BB_SIZE) -#define GOLAN_SEND_OPCODE 0x0a -#define GOLAN_WQE_CTRL_WQE_IDX_BIT 8 - -enum golan_ib_qp_state { - GOLAN_IB_QPS_RESET, - GOLAN_IB_QPS_INIT, - GOLAN_IB_QPS_RTR, - GOLAN_IB_QPS_RTS, - GOLAN_IB_QPS_SQD, - GOLAN_IB_QPS_SQE, - GOLAN_IB_QPS_ERR -}; - -struct golan_send_wqe_ud { - struct golan_wqe_ctrl_seg ctrl; - struct golan_av datagram; - struct golan_wqe_data_seg data; -}; - -union golan_send_wqe { - struct golan_send_wqe_ud ud; - uint8_t pad[GOLAN_WQEBBS_PER_SEND_UD_WQE * GOLAN_SEND_WQE_BB_SIZE]; -}; - -struct golan_recv_wqe_ud { - struct golan_wqe_data_seg data[2]; -}; - -struct golan_recv_wq { - struct golan_recv_wqe_ud *wqes; - /* WQ size in bytes */ - int size; - /* In SQ, it will be increased in wqe_size (number of WQEBBs per WQE) */ - u16 next_idx; - /** GRH buffers (if applicable) */ - struct ib_global_route_header *grh; - /** Size of GRH buffers */ - size_t grh_size; -}; - -struct golan_send_wq { - union golan_send_wqe *wqes; - /* WQ size in bytes */ - int size; - /* In SQ, it will be increased in wqe_size (number of WQEBBs per WQE) */ - u16 next_idx; -}; - -struct golan_queue_pair { - void *wqes; - int size; - struct golan_recv_wq rq; - struct golan_send_wq sq; - struct golan_qp_db *doorbell_record; - u32 doorbell_qpn; - enum golan_ib_qp_state state; -}; - -/* Completion Queue */ -#define GOLAN_CQE_OPCODE_NOT_VALID 0x0f -#define GOLAN_CQE_OPCODE_BIT 4 -#define GOLAN_CQ_DB_RECORD_SIZE sizeof(uint64_t) -#define GOLAN_CQE_OWNER_MASK 1 - -#define MANAGE_PAGES_PSA_OFFSET 0 -#define PXE_CMDIF_REF 5 - -enum { - GOLAN_CQE_SW_OWNERSHIP = 0x0, - GOLAN_CQE_HW_OWNERSHIP = 0x1 -}; - -enum { - GOLAN_CQE_SIZE_64 = 0, - GOLAN_CQE_SIZE_128 = 1 -}; - -struct golan_completion_queue { - struct golan_cqe64 *cqes; - int size; - __be64 *doorbell_record; -}; - - -/* Event Queue */ -#define GOLAN_EQE_SIZE sizeof(struct golan_eqe) -#define GOLAN_NUM_EQES 8 -#define GOLAN_EQ_DOORBELL_OFFSET 0x40 - -#define GOLAN_EQ_MAP_ALL_EVENTS \ - ((1 << GOLAN_EVENT_TYPE_PATH_MIG )| \ - (1 << GOLAN_EVENT_TYPE_COMM_EST )| \ - (1 << GOLAN_EVENT_TYPE_SQ_DRAINED )| \ - (1 << GOLAN_EVENT_TYPE_SRQ_LAST_WQE )| \ - (1 << GOLAN_EVENT_TYPE_SRQ_RQ_LIMIT )| \ - (1 << GOLAN_EVENT_TYPE_CQ_ERROR )| \ - (1 << GOLAN_EVENT_TYPE_WQ_CATAS_ERROR )| \ - (1 << GOLAN_EVENT_TYPE_PATH_MIG_FAILED )| \ - (1 << GOLAN_EVENT_TYPE_WQ_INVAL_REQ_ERROR )| \ - (1 << GOLAN_EVENT_TYPE_WQ_ACCESS_ERROR )| \ - (1 << GOLAN_EVENT_TYPE_SRQ_CATAS_ERROR )| \ - (1 << GOLAN_EVENT_TYPE_INTERNAL_ERROR )| \ - (1 << GOLAN_EVENT_TYPE_PORT_CHANGE )| \ - (1 << GOLAN_EVENT_TYPE_GPIO_EVENT )| \ - (1 << GOLAN_EVENT_TYPE_CLIENT_RE_REGISTER )| \ - (1 << GOLAN_EVENT_TYPE_REMOTE_CONFIG )| \ - (1 << GOLAN_EVENT_TYPE_DB_BF_CONGESTION )| \ - (1 << GOLAN_EVENT_TYPE_STALL_EVENT )| \ - (1 << GOLAN_EVENT_TYPE_PACKET_DROPPED )| \ - (1 << GOLAN_EVENT_TYPE_CMD )| \ - (1 << GOLAN_EVENT_TYPE_PAGE_REQUEST )) - -enum golan_event { - GOLAN_EVENT_TYPE_COMP = 0x0, - - GOLAN_EVENT_TYPE_PATH_MIG = 0x01, - GOLAN_EVENT_TYPE_COMM_EST = 0x02, - GOLAN_EVENT_TYPE_SQ_DRAINED = 0x03, - GOLAN_EVENT_TYPE_SRQ_LAST_WQE = 0x13, - GOLAN_EVENT_TYPE_SRQ_RQ_LIMIT = 0x14, - - GOLAN_EVENT_TYPE_CQ_ERROR = 0x04, - GOLAN_EVENT_TYPE_WQ_CATAS_ERROR = 0x05, - GOLAN_EVENT_TYPE_PATH_MIG_FAILED = 0x07, - GOLAN_EVENT_TYPE_WQ_INVAL_REQ_ERROR = 0x10, - GOLAN_EVENT_TYPE_WQ_ACCESS_ERROR = 0x11, - GOLAN_EVENT_TYPE_SRQ_CATAS_ERROR = 0x12, - - GOLAN_EVENT_TYPE_INTERNAL_ERROR = 0x08, - GOLAN_EVENT_TYPE_PORT_CHANGE = 0x09, - GOLAN_EVENT_TYPE_GPIO_EVENT = 0x15, -// GOLAN_EVENT_TYPE_CLIENT_RE_REGISTER = 0x16, - GOLAN_EVENT_TYPE_REMOTE_CONFIG = 0x19, - - GOLAN_EVENT_TYPE_DB_BF_CONGESTION = 0x1a, - GOLAN_EVENT_TYPE_STALL_EVENT = 0x1b, - - GOLAN_EVENT_TYPE_PACKET_DROPPED = 0x1f, - - GOLAN_EVENT_TYPE_CMD = 0x0a, - GOLAN_EVENT_TYPE_PAGE_REQUEST = 0x0b, - GOLAN_EVENT_TYPE_PAGE_FAULT = 0x0C, -}; - -enum golan_port_sub_event { - GOLAN_PORT_CHANGE_SUBTYPE_DOWN = 1, - GOLAN_PORT_CHANGE_SUBTYPE_ACTIVE = 4, - GOLAN_PORT_CHANGE_SUBTYPE_INITIALIZED = 5, - GOLAN_PORT_CHANGE_SUBTYPE_LID = 6, - GOLAN_PORT_CHANGE_SUBTYPE_PKEY = 7, - GOLAN_PORT_CHANGE_SUBTYPE_GUID = 8, - GOLAN_PORT_CHANGE_SUBTYPE_CLIENT_REREG = 9 -}; - - -enum { - GOLAN_EQE_SW_OWNERSHIP = 0x0, - GOLAN_EQE_HW_OWNERSHIP = 0x1 -}; - -enum { - GOLAN_EQ_UNARMED = 0, - GOLAN_EQ_ARMED = 1, -}; - -struct golan_event_queue { - uint8_t eqn; - uint64_t mask; - struct golan_eqe *eqes; - int size; - __be32 *doorbell; - uint32_t cons_index; -}; - -struct golan_port { - /** Infiniband device */ - struct ib_device *ibdev; - /** Network device */ - struct net_device *netdev; - /** VEP number */ - u8 vep_number; -}; - -struct golan_mboxes { - void *inbox; - void *outbox; -}; - -#define GOLAN_OPEN 0x1 - -struct golan { - struct pci_device *pci; - struct golan_hca_init_seg *iseg; - struct golan_cmdq_md cmd; - struct golan_hca_cap caps; /* stored as big indian*/ - struct golan_mboxes mboxes; - struct list_head pages; - uint32_t cmd_bm; - uint32_t total_dma_pages; - struct golan_uar uar; - struct golan_event_queue eq; - uint32_t pdn; - u32 mkey; - u32 flags; - - struct golan_port ports[GOLAN_MAX_PORTS]; -}; - -#endif /* _GOLAN_H_*/ diff --git a/roms/ipxe/src/drivers/infiniband/hermon.c b/roms/ipxe/src/drivers/infiniband/hermon.c index 79d606093..a9c728706 100644 --- a/roms/ipxe/src/drivers/infiniband/hermon.c +++ b/roms/ipxe/src/drivers/infiniband/hermon.c @@ -1111,8 +1111,6 @@ static int hermon_create_qp ( struct ib_device *ibdev, struct hermon *hermon = ib_get_drvdata ( ibdev ); struct hermon_queue_pair *hermon_qp; struct hermonprm_qp_ee_state_transitions qpctx; - struct hermonprm_wqe_segment_data_ptr *data; - unsigned int i; int rc; /* Calculate queue pair number */ @@ -1149,14 +1147,8 @@ static int hermon_create_qp ( struct ib_device *ibdev, sizeof ( hermon_qp->send.wqe[0] ) ); hermon_qp->recv.wqe_size = ( qp->recv.num_wqes * sizeof ( hermon_qp->recv.wqe[0] ) ); - if ( ( qp->type == IB_QPT_SMI ) || ( qp->type == IB_QPT_GSI ) || - ( qp->type == IB_QPT_UD ) ) { - hermon_qp->recv.grh_size = ( qp->recv.num_wqes * - sizeof ( hermon_qp->recv.grh[0] )); - } hermon_qp->wqe_size = ( hermon_qp->send.wqe_size + - hermon_qp->recv.wqe_size + - hermon_qp->recv.grh_size ); + hermon_qp->recv.wqe_size ); hermon_qp->wqe = malloc_dma ( hermon_qp->wqe_size, sizeof ( hermon_qp->send.wqe[0] ) ); if ( ! hermon_qp->wqe ) { @@ -1164,21 +1156,9 @@ static int hermon_create_qp ( struct ib_device *ibdev, goto err_alloc_wqe; } hermon_qp->send.wqe = hermon_qp->wqe; - hermon_qp->recv.wqe = ( hermon_qp->wqe + hermon_qp->send.wqe_size ); - if ( hermon_qp->recv.grh_size ) { - hermon_qp->recv.grh = ( hermon_qp->wqe + - hermon_qp->send.wqe_size + - hermon_qp->recv.wqe_size ); - } - - /* Initialise work queue entries */ memset ( hermon_qp->send.wqe, 0xff, hermon_qp->send.wqe_size ); + hermon_qp->recv.wqe = ( hermon_qp->wqe + hermon_qp->send.wqe_size ); memset ( hermon_qp->recv.wqe, 0, hermon_qp->recv.wqe_size ); - data = &hermon_qp->recv.wqe[0].recv.data[0]; - for ( i = 0 ; i < ( hermon_qp->recv.wqe_size / sizeof ( *data ) ); i++){ - MLX_FILL_1 ( data, 1, l_key, HERMON_INVALID_LKEY ); - data++; - } /* Allocate MTT entries */ if ( ( rc = hermon_alloc_mtt ( hermon, hermon_qp->wqe, @@ -1653,8 +1633,6 @@ static int hermon_post_recv ( struct ib_device *ibdev, struct ib_work_queue *wq = &qp->recv; struct hermon_recv_work_queue *hermon_recv_wq = &hermon_qp->recv; struct hermonprm_recv_wqe *wqe; - struct hermonprm_wqe_segment_data_ptr *data; - struct ib_global_route_header *grh; unsigned int wqe_idx_mask; /* Allocate work queue entry */ @@ -1668,19 +1646,12 @@ static int hermon_post_recv ( struct ib_device *ibdev, wqe = &hermon_recv_wq->wqe[wq->next_idx & wqe_idx_mask].recv; /* Construct work queue entry */ - data = &wqe->data[0]; - if ( hermon_qp->recv.grh ) { - grh = &hermon_qp->recv.grh[wq->next_idx & wqe_idx_mask]; - MLX_FILL_1 ( data, 0, byte_count, sizeof ( *grh ) ); - MLX_FILL_1 ( data, 1, l_key, hermon->lkey ); - MLX_FILL_H ( data, 2, local_address_h, virt_to_bus ( grh ) ); - MLX_FILL_1 ( data, 3, local_address_l, virt_to_bus ( grh ) ); - data++; - } - MLX_FILL_1 ( data, 0, byte_count, iob_tailroom ( iobuf ) ); - MLX_FILL_1 ( data, 1, l_key, hermon->lkey ); - MLX_FILL_H ( data, 2, local_address_h, virt_to_bus ( iobuf->data ) ); - MLX_FILL_1 ( data, 3, local_address_l, virt_to_bus ( iobuf->data ) ); + MLX_FILL_1 ( &wqe->data[0], 0, byte_count, iob_tailroom ( iobuf ) ); + MLX_FILL_1 ( &wqe->data[0], 1, l_key, hermon->lkey ); + MLX_FILL_H ( &wqe->data[0], 2, + local_address_h, virt_to_bus ( iobuf->data ) ); + MLX_FILL_1 ( &wqe->data[0], 3, + local_address_l, virt_to_bus ( iobuf->data ) ); /* Update work queue's index */ wq->next_idx++; @@ -1705,7 +1676,6 @@ static int hermon_complete ( struct ib_device *ibdev, struct ib_completion_queue *cq, union hermonprm_completion_entry *cqe ) { struct hermon *hermon = ib_get_drvdata ( ibdev ); - struct hermon_queue_pair *hermon_qp; struct ib_work_queue *wq; struct ib_queue_pair *qp; struct io_buffer *iobuf; @@ -1743,7 +1713,6 @@ static int hermon_complete ( struct ib_device *ibdev, return -EIO; } qp = wq->qp; - hermon_qp = ib_qp_get_drvdata ( qp ); /* Identify work queue entry */ wqe_idx = MLX_GET ( &cqe->normal, wqe_counter ); @@ -1769,6 +1738,8 @@ static int hermon_complete ( struct ib_device *ibdev, } else { /* Set received length */ len = MLX_GET ( &cqe->normal, byte_cnt ); + assert ( len <= iob_tailroom ( iobuf ) ); + iob_put ( iobuf, len ); memset ( &recv_dest, 0, sizeof ( recv_dest ) ); recv_dest.qpn = qpn; memset ( &recv_source, 0, sizeof ( recv_source ) ); @@ -1776,10 +1747,9 @@ static int hermon_complete ( struct ib_device *ibdev, case IB_QPT_SMI: case IB_QPT_GSI: case IB_QPT_UD: - /* Locate corresponding GRH */ - assert ( hermon_qp->recv.grh != NULL ); - grh = &hermon_qp->recv.grh[ wqe_idx & wqe_idx_mask ]; - len -= sizeof ( *grh ); + assert ( iob_len ( iobuf ) >= sizeof ( *grh ) ); + grh = iobuf->data; + iob_pull ( iobuf, sizeof ( *grh ) ); /* Construct address vector */ source = &recv_source; source->qpn = MLX_GET ( &cqe->normal, srq_rqpn ); @@ -1805,8 +1775,6 @@ static int hermon_complete ( struct ib_device *ibdev, assert ( 0 ); return -EINVAL; } - assert ( len <= iob_tailroom ( iobuf ) ); - iob_put ( iobuf, len ); /* Hand off to completion handler */ ib_complete_recv ( ibdev, qp, &recv_dest, source, iobuf, rc ); } @@ -3274,7 +3242,7 @@ static int hermon_eth_open ( struct net_device *netdev ) { port->eth_qp = ib_create_qp ( ibdev, IB_QPT_ETH, HERMON_ETH_NUM_SEND_WQES, port->eth_cq, HERMON_ETH_NUM_RECV_WQES, port->eth_cq, - &hermon_eth_qp_op, netdev->name ); + &hermon_eth_qp_op ); if ( ! port->eth_qp ) { DBGC ( hermon, "Hermon %p port %d could not create queue " "pair\n", hermon, ibdev->port ); @@ -3780,6 +3748,24 @@ static void hermon_free ( struct hermon *hermon ) { } /** + * Initialise Hermon PCI parameters + * + * @v hermon Hermon device + */ +static void hermon_pci_init ( struct hermon *hermon ) { + struct pci_device *pci = hermon->pci; + + /* Fix up PCI device */ + adjust_pci_device ( pci ); + + /* Get PCI BARs */ + hermon->config = ioremap ( pci_bar_start ( pci, HERMON_PCI_CONFIG_BAR), + HERMON_PCI_CONFIG_BAR_SIZE ); + hermon->uar = ioremap ( pci_bar_start ( pci, HERMON_PCI_UAR_BAR ), + HERMON_UAR_NON_EQ_PAGE * HERMON_PAGE_SIZE ); +} + +/** * Probe PCI device * * @v pci PCI device @@ -3803,14 +3789,8 @@ static int hermon_probe ( struct pci_device *pci ) { pci_set_drvdata ( pci, hermon ); hermon->pci = pci; - /* Fix up PCI device */ - adjust_pci_device ( pci ); - - /* Map PCI BARs */ - hermon->config = ioremap ( pci_bar_start ( pci, HERMON_PCI_CONFIG_BAR ), - HERMON_PCI_CONFIG_BAR_SIZE ); - hermon->uar = ioremap ( pci_bar_start ( pci, HERMON_PCI_UAR_BAR ), - HERMON_UAR_NON_EQ_PAGE * HERMON_PAGE_SIZE ); + /* Initialise PCI parameters */ + hermon_pci_init ( hermon ); /* Reset device */ hermon_reset ( hermon ); @@ -3905,8 +3885,6 @@ static int hermon_probe ( struct pci_device *pci ) { err_get_cap: hermon_stop_firmware ( hermon ); err_start_firmware: - iounmap ( hermon->uar ); - iounmap ( hermon->config ); hermon_free ( hermon ); err_alloc: return rc; @@ -3932,8 +3910,6 @@ static void hermon_remove ( struct pci_device *pci ) { } for ( i = ( hermon->cap.num_ports - 1 ) ; i >= 0 ; i-- ) ibdev_put ( hermon->port[i].ibdev ); - iounmap ( hermon->uar ); - iounmap ( hermon->config ); hermon_free ( hermon ); } @@ -3957,12 +3933,8 @@ static int hermon_bofm_probe ( struct pci_device *pci ) { pci_set_drvdata ( pci, hermon ); hermon->pci = pci; - /* Fix up PCI device */ - adjust_pci_device ( pci ); - - /* Map PCI BAR */ - hermon->config = ioremap ( pci_bar_start ( pci, HERMON_PCI_CONFIG_BAR ), - HERMON_PCI_CONFIG_BAR_SIZE ); + /* Initialise PCI parameters */ + hermon_pci_init ( hermon ); /* Initialise BOFM device */ bofm_init ( &hermon->bofm, pci, &hermon_bofm_operations ); @@ -3977,7 +3949,6 @@ static int hermon_bofm_probe ( struct pci_device *pci ) { return 0; err_bofm_register: - iounmap ( hermon->config ); hermon_free ( hermon ); err_alloc: return rc; @@ -3992,7 +3963,6 @@ static void hermon_bofm_remove ( struct pci_device *pci ) { struct hermon *hermon = pci_get_drvdata ( pci ); bofm_unregister ( &hermon->bofm ); - iounmap ( hermon->config ); hermon_free ( hermon ); } diff --git a/roms/ipxe/src/drivers/infiniband/hermon.h b/roms/ipxe/src/drivers/infiniband/hermon.h index 61e285781..e0b028f26 100644 --- a/roms/ipxe/src/drivers/infiniband/hermon.h +++ b/roms/ipxe/src/drivers/infiniband/hermon.h @@ -515,7 +515,7 @@ struct hermonprm_eth_send_wqe { struct hermonprm_wqe_segment_data_ptr data[HERMON_MAX_GATHER]; } __attribute__ (( packed )); -#define HERMON_MAX_SCATTER 2 +#define HERMON_MAX_SCATTER 1 struct hermonprm_recv_wqe { struct hermonprm_wqe_segment_data_ptr data[HERMON_MAX_SCATTER]; @@ -686,10 +686,6 @@ struct hermon_recv_work_queue { union hermon_recv_wqe *wqe; /** Size of work queue */ size_t wqe_size; - /** GRH buffers (if applicable) */ - struct ib_global_route_header *grh; - /** Size of GRH buffers */ - size_t grh_size; /** Doorbell record */ struct hermonprm_qp_db_record *doorbell; }; diff --git a/roms/ipxe/src/drivers/infiniband/linda.c b/roms/ipxe/src/drivers/infiniband/linda.c index 77d50d110..a6ae9f529 100644 --- a/roms/ipxe/src/drivers/infiniband/linda.c +++ b/roms/ipxe/src/drivers/infiniband/linda.c @@ -112,21 +112,32 @@ struct linda { * This card requires atomic 64-bit accesses. Strange things happen * if you try to use 32-bit accesses; sometimes they work, sometimes * they don't, sometimes you get random data. + * + * These accessors use the "movq" MMX instruction, and so won't work + * on really old Pentiums (which won't have PCIe anyway, so this is + * something of a moot point). */ /** * Read Linda qword register * * @v linda Linda device - * @v qword Register buffer to read into + * @v dwords Register buffer to read into * @v offset Register offset */ -static void linda_readq ( struct linda *linda, uint64_t *qword, +static void linda_readq ( struct linda *linda, uint32_t *dwords, unsigned long offset ) { - *qword = readq ( linda->regs + offset ); + void *addr = ( linda->regs + offset ); + + __asm__ __volatile__ ( "movq (%1), %%mm0\n\t" + "movq %%mm0, (%0)\n\t" + : : "r" ( dwords ), "r" ( addr ) : "memory" ); + + DBGIO ( "[%08lx] => %08x%08x\n", + virt_to_phys ( addr ), dwords[1], dwords[0] ); } #define linda_readq( _linda, _ptr, _offset ) \ - linda_readq ( (_linda), (_ptr)->u.qwords, (_offset) ) + linda_readq ( (_linda), (_ptr)->u.dwords, (_offset) ) #define linda_readq_array8b( _linda, _ptr, _offset, _idx ) \ linda_readq ( (_linda), (_ptr), ( (_offset) + ( (_idx) * 8 ) ) ) #define linda_readq_array64k( _linda, _ptr, _offset, _idx ) \ @@ -136,15 +147,22 @@ static void linda_readq ( struct linda *linda, uint64_t *qword, * Write Linda qword register * * @v linda Linda device - * @v qword Register buffer to write + * @v dwords Register buffer to write * @v offset Register offset */ -static void linda_writeq ( struct linda *linda, const uint64_t *qword, +static void linda_writeq ( struct linda *linda, const uint32_t *dwords, unsigned long offset ) { - writeq ( *qword, ( linda->regs + offset ) ); + void *addr = ( linda->regs + offset ); + + DBGIO ( "[%08lx] <= %08x%08x\n", + virt_to_phys ( addr ), dwords[1], dwords[0] ); + + __asm__ __volatile__ ( "movq (%0), %%mm0\n\t" + "movq %%mm0, (%1)\n\t" + : : "r" ( dwords ), "r" ( addr ) : "memory" ); } #define linda_writeq( _linda, _ptr, _offset ) \ - linda_writeq ( (_linda), (_ptr)->u.qwords, (_offset) ) + linda_writeq ( (_linda), (_ptr)->u.dwords, (_offset) ) #define linda_writeq_array8b( _linda, _ptr, _offset, _idx ) \ linda_writeq ( (_linda), (_ptr), ( (_offset) + ( (_idx) * 8 ) ) ) #define linda_writeq_array64k( _linda, _ptr, _offset, _idx ) \ @@ -1271,15 +1289,8 @@ static void linda_complete_recv ( struct ib_device *ibdev, /* Completing the eager buffer described in * this header entry. */ - if ( payload_len <= iob_tailroom ( iobuf ) ) { - iob_put ( iobuf, payload_len ); - rc = ( err ? - -EIO : ( useegrbfr ? 0 : -ECANCELED ) ); - } else { - DBGC ( linda, "Linda %p bad payload len %zd\n", - linda, payload_len ); - rc = -EPROTO; - } + iob_put ( iobuf, payload_len ); + rc = ( err ? -EIO : ( useegrbfr ? 0 : -ECANCELED ) ); /* Redirect to target QP if necessary */ if ( qp != intended_qp ) { DBGC ( linda, "Linda %p redirecting QPN %ld " @@ -1290,7 +1301,7 @@ static void linda_complete_recv ( struct ib_device *ibdev, intended_qp->recv.fill++; } ib_complete_recv ( ibdev, intended_qp, &dest, &source, - iobuf, rc ); + iobuf, rc); } else { /* Completing on a skipped-over eager buffer */ ib_complete_recv ( ibdev, qp, &dest, &source, iobuf, @@ -2334,7 +2345,7 @@ static int linda_probe ( struct pci_device *pci ) { /* Fix up PCI device */ adjust_pci_device ( pci ); - /* Map PCI BARs */ + /* Get PCI BARs */ linda->regs = ioremap ( pci->membase, LINDA_BAR0_SIZE ); DBGC2 ( linda, "Linda %p has BAR at %08lx\n", linda, pci->membase ); @@ -2395,7 +2406,6 @@ static int linda_probe ( struct pci_device *pci ) { err_init_ib_serdes: err_read_eeprom: err_init_i2c: - iounmap ( linda->regs ); ibdev_put ( ibdev ); err_alloc_ibdev: return rc; @@ -2413,7 +2423,6 @@ static void linda_remove ( struct pci_device *pci ) { unregister_ibdev ( ibdev ); linda_fini_recv ( linda ); linda_fini_send ( linda ); - iounmap ( linda->regs ); ibdev_put ( ibdev ); } diff --git a/roms/ipxe/src/drivers/infiniband/linda.h b/roms/ipxe/src/drivers/infiniband/linda.h index 44c7686f4..46a920a17 100644 --- a/roms/ipxe/src/drivers/infiniband/linda.h +++ b/roms/ipxe/src/drivers/infiniband/linda.h @@ -33,8 +33,8 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); * */ -#define PSEUDOBIT_LITTLE_ENDIAN -#include <ipxe/pseudobit.h> +#define BITOPS_LITTLE_ENDIAN +#include <ipxe/bitops.h> #include "qib_7220_regs.h" struct ib_device; diff --git a/roms/ipxe/src/drivers/infiniband/mlx_nodnic/include/mlx_cmd.h b/roms/ipxe/src/drivers/infiniband/mlx_nodnic/include/mlx_cmd.h deleted file mode 100644 index e1e89b4c3..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_nodnic/include/mlx_cmd.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef NODNIC_CMD_H_ -#define NODNIC_CMD_H_ - -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include "mlx_nodnic_data_structures.h" -#include "../../mlx_utils/include/public/mlx_utils.h" -#include "../../mlx_utils/include/public/mlx_pci_gw.h" - -mlx_status -nodnic_cmd_read( - IN nodnic_device_priv *device_priv, - IN mlx_uint32 address, - OUT mlx_pci_gw_buffer *buffer - ); - -mlx_status -nodnic_cmd_write( - IN nodnic_device_priv *device_priv, - IN mlx_uint32 address, - IN mlx_pci_gw_buffer buffer - ); - -#endif /* STUB_NODNIC_CMD_H_ */ diff --git a/roms/ipxe/src/drivers/infiniband/mlx_nodnic/include/mlx_device.h b/roms/ipxe/src/drivers/infiniband/mlx_nodnic/include/mlx_device.h deleted file mode 100644 index b0cc7f723..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_nodnic/include/mlx_device.h +++ /dev/null @@ -1,80 +0,0 @@ -#ifndef NODNIC_DEVICE_H_ -#define NODNIC_DEVICE_H_ - -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include "mlx_nodnic_data_structures.h" - -#define NODIC_SUPPORTED_REVISION 1 -//Initialization segment -#define NODNIC_CMDQ_PHY_ADDR_HIGH_OFFSET 0x10 -#define NODNIC_CMDQ_PHY_ADDR_LOW_OFFSET 0x14 -#define NODNIC_NIC_INTERFACE_OFFSET 0x14 -#define NODNIC_INITIALIZING_OFFSET 0x1fc -#define NODNIC_NIC_INTERFACE_SUPPORTED_OFFSET 0x1fc -#define NODNIC_LOCATION_OFFSET 0x240 - -#define NODNIC_CMDQ_PHY_ADDR_LOW_MASK 0xFFFFE000 -#define NODNIC_NIC_INTERFACE_SUPPORTED_MASK 0x4000000 - -#define NODNIC_NIC_INTERFACE_BIT 9 -#define NODNIC_DISABLE_INTERFACE_BIT 8 -#define NODNIC_NIC_INTERFACE_SUPPORTED_BIT 26 -#define NODNIC_INITIALIZING_BIT 31 - -#define NODNIC_NIC_DISABLE_INT_OFFSET 0x100c - -//nodnic segment -#define NODNIC_REVISION_OFFSET 0x0 -#define NODNIC_HARDWARE_FORMAT_OFFSET 0x0 - - - -mlx_status -nodnic_device_init( - IN nodnic_device_priv *device_priv - ); - -mlx_status -nodnic_device_teardown( - IN nodnic_device_priv *device_priv - ); - - -mlx_status -nodnic_device_get_cap( - IN nodnic_device_priv *device_priv - ); - -mlx_status -nodnic_device_clear_int ( - IN nodnic_device_priv *device_priv - ); - -mlx_status -nodnic_device_get_fw_version( - IN nodnic_device_priv *device_priv, - OUT mlx_uint16 *fw_ver_minor, - OUT mlx_uint16 *fw_ver_sub_minor, - OUT mlx_uint16 *fw_ver_major - ); -#endif /* STUB_NODNIC_DEVICE_H_ */ diff --git a/roms/ipxe/src/drivers/infiniband/mlx_nodnic/include/mlx_nodnic_data_structures.h b/roms/ipxe/src/drivers/infiniband/mlx_nodnic/include/mlx_nodnic_data_structures.h deleted file mode 100644 index f58213b98..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_nodnic/include/mlx_nodnic_data_structures.h +++ /dev/null @@ -1,201 +0,0 @@ -#ifndef NODNIC_NODNICDATASTRUCTURES_H_ -#define NODNIC_NODNICDATASTRUCTURES_H_ - -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include "../../mlx_utils/include/public/mlx_utils.h" - -/* todo: fix coding convention */ -#define NODNIC_MEMORY_ALIGN 0x1000 - -#define NODNIC_MAX_MAC_FILTERS 5 -#define NODNIC_MAX_MGID_FILTERS 4 - -typedef struct _nodnic_device_priv nodnic_device_priv; -typedef struct _nodnic_port_priv nodnic_port_priv; -typedef struct _nodnic_device_capabilites nodnic_device_capabilites; -typedef struct _nodnic_qp nodnic_qp; -typedef struct _nodnic_cq nodnic_cq; -typedef struct _nodnic_eq nodnic_eq; - -/* NODNIC Port states - * Bit 0 - port open/close - * Bit 1 - port is [not] in disabling DMA - * 0 - closed and not disabling DMA - * 1 - opened and not disabling DMA - * 3 - opened and disabling DMA - */ -#define NODNIC_PORT_OPENED 0b00000001 -#define NODNIC_PORT_DISABLING_DMA 0b00000010 - -typedef enum { - ConnectX3 = 0, - Connectx4 -}nodnic_hardware_format; - - -typedef enum { - NODNIC_QPT_SMI, - NODNIC_QPT_GSI, - NODNIC_QPT_UD, - NODNIC_QPT_RC, - NODNIC_QPT_ETH, -}nodnic_queue_pair_type; -typedef enum { - NODNIC_PORT_TYPE_IB = 0, - NODNIC_PORT_TYPE_ETH, - NODNIC_PORT_TYPE_UNKNOWN, -}nodnic_port_type; - - -#define RECV_WQE_SIZE 16 -#define NODNIC_WQBB_SIZE 64 -/** A nodnic send wqbb */ -struct nodnic_send_wqbb { - mlx_uint8 force_align[NODNIC_WQBB_SIZE]; -}; -struct nodnic_ring { - mlx_uint32 offset; - /** Work queue entries */ - /* TODO: add to memory entity */ - mlx_physical_address wqe_physical; - mlx_void *map; - /** Size of work queue */ - mlx_size wq_size; - /** Next work queue entry index - * - * This is the index of the next entry to be filled (i.e. the - * first empty entry). This value is not bounded by num_wqes; - * users must logical-AND with (num_wqes-1) to generate an - * array index. - */ - mlx_uint32 num_wqes; - mlx_uint32 qpn; - mlx_uint32 next_idx; - mlx_uint32 ring_pi; -}; - -struct nodnic_send_ring{ - struct nodnic_ring nodnic_ring; - struct nodnic_send_wqbb *wqe_virt; -}; - - -struct nodnic_recv_ring{ - struct nodnic_ring nodnic_ring; - void *wqe_virt; -}; -struct _nodnic_qp{ - nodnic_queue_pair_type type; - struct nodnic_send_ring send; - struct nodnic_recv_ring receive; -}; - -struct _nodnic_cq{ - /** cq entries */ - mlx_void *cq_virt; - mlx_physical_address cq_physical; - mlx_void *map; - /** cq */ - mlx_size cq_size; -}; - -struct _nodnic_eq{ - mlx_void *eq_virt; - mlx_physical_address eq_physical; - mlx_void *map; - mlx_size eq_size; -}; -struct _nodnic_device_capabilites{ - mlx_boolean support_mac_filters; - mlx_boolean support_promisc_filter; - mlx_boolean support_promisc_multicast_filter; - mlx_uint8 log_working_buffer_size; - mlx_uint8 log_pkey_table_size; - mlx_boolean num_ports; // 0 - single port, 1 - dual port - mlx_uint8 log_max_ring_size; -#ifdef DEVICE_CX3 - mlx_uint8 crspace_doorbells; -#endif -}; - -#ifdef DEVICE_CX3 -/* This is the structure of the data in the scratchpad - * Read/Write data from/to its field using PCI accesses only */ -typedef struct _nodnic_port_data_flow_gw nodnic_port_data_flow_gw; -struct _nodnic_port_data_flow_gw { - mlx_uint32 send_doorbell; - mlx_uint32 recv_doorbell; - mlx_uint32 reserved2[2]; - mlx_uint32 armcq_cq_ci_dword; - mlx_uint32 dma_en; -} __attribute__ ((packed)); -#endif - -struct _nodnic_device_priv{ - mlx_boolean is_initiailzied; - mlx_utils *utils; - - //nodnic structure offset in init segment - mlx_uint32 device_offset; - - nodnic_device_capabilites device_cap; - - mlx_uint8 nodnic_revision; - nodnic_hardware_format hardware_format; - mlx_uint32 pd; - mlx_uint32 lkey; - mlx_uint64 device_guid; - nodnic_port_priv *ports; -#ifdef DEVICE_CX3 - mlx_void *crspace_clear_int; -#endif -}; - -struct _nodnic_port_priv{ - nodnic_device_priv *device; - mlx_uint32 port_offset; - mlx_uint8 port_state; - mlx_boolean network_state; - mlx_boolean dma_state; - nodnic_port_type port_type; - mlx_uint8 port_num; - nodnic_eq eq; - mlx_mac_address mac_filters[5]; - mlx_status (*send_doorbell)( - IN nodnic_port_priv *port_priv, - IN struct nodnic_ring *ring, - IN mlx_uint16 index); - mlx_status (*recv_doorbell)( - IN nodnic_port_priv *port_priv, - IN struct nodnic_ring *ring, - IN mlx_uint16 index); - mlx_status (*set_dma)( - IN nodnic_port_priv *port_priv, - IN mlx_boolean value); -#ifdef DEVICE_CX3 - nodnic_port_data_flow_gw *data_flow_gw; -#endif -}; - - -#endif /* STUB_NODNIC_NODNICDATASTRUCTURES_H_ */ diff --git a/roms/ipxe/src/drivers/infiniband/mlx_nodnic/include/mlx_port.h b/roms/ipxe/src/drivers/infiniband/mlx_nodnic/include/mlx_port.h deleted file mode 100644 index 4fd96a6da..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_nodnic/include/mlx_port.h +++ /dev/null @@ -1,229 +0,0 @@ -#ifndef NODNIC_PORT_H_ -#define NODNIC_PORT_H_ - -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include "mlx_nodnic_data_structures.h" - -#define NODNIC_PORT_MAC_FILTERS_OFFSET 0x10 - -typedef enum { - nodnic_port_option_link_type = 0, - nodnic_port_option_mac_low, - nodnic_port_option_mac_high, - nodnic_port_option_log_cq_size, - nodnic_port_option_reset_needed, - nodnic_port_option_mac_filters_en, - nodnic_port_option_port_state, - nodnic_port_option_network_en, - nodnic_port_option_dma_en, - nodnic_port_option_eq_addr_low, - nodnic_port_option_eq_addr_high, - nodnic_port_option_cq_addr_low, - nodnic_port_option_cq_addr_high, - nodnic_port_option_port_management_change_event, - nodnic_port_option_port_promisc_en, - nodnic_port_option_arm_cq, - nodnic_port_option_port_promisc_multicast_en, -#ifdef DEVICE_CX3 - nodnic_port_option_crspace_en, -#endif -}nodnic_port_option; - -struct nodnic_port_data_entry{ - nodnic_port_option option; - mlx_uint32 offset; - mlx_uint8 align; - mlx_uint32 mask; -}; - -struct nodnic_qp_data_entry{ - nodnic_queue_pair_type type; - mlx_uint32 send_offset; - mlx_uint32 recv_offset; -}; - - -typedef enum { - nodnic_port_state_down = 0, - nodnic_port_state_initialize, - nodnic_port_state_armed, - nodnic_port_state_active, -}nodnic_port_state; - -mlx_status -nodnic_port_get_state( - IN nodnic_port_priv *port_priv, - OUT nodnic_port_state *state - ); - -mlx_status -nodnic_port_get_type( - IN nodnic_port_priv *port_priv, - OUT nodnic_port_type *type - ); - -mlx_status -nodnic_port_query( - IN nodnic_port_priv *port_priv, - IN nodnic_port_option option, - OUT mlx_uint32 *out - ); - -mlx_status -nodnic_port_set( - IN nodnic_port_priv *port_priv, - IN nodnic_port_option option, - IN mlx_uint32 in - ); - -mlx_status -nodnic_port_create_cq( - IN nodnic_port_priv *port_priv, - IN mlx_size cq_size, - OUT nodnic_cq **cq - ); - -mlx_status -nodnic_port_destroy_cq( - IN nodnic_port_priv *port_priv, - IN nodnic_cq *cq - ); - -mlx_status -nodnic_port_create_qp( - IN nodnic_port_priv *port_priv, - IN nodnic_queue_pair_type type, - IN mlx_size send_wq_size, - IN mlx_uint32 send_wqe_num, - IN mlx_size receive_wq_size, - IN mlx_uint32 recv_wqe_num, - OUT nodnic_qp **qp - ); - -mlx_status -nodnic_port_destroy_qp( - IN nodnic_port_priv *port_priv, - IN nodnic_queue_pair_type type, - IN nodnic_qp *qp - ); -mlx_status -nodnic_port_get_qpn( - IN nodnic_port_priv *port_priv, - IN struct nodnic_ring *ring, - OUT mlx_uint32 *qpn - ); -mlx_status -nodnic_port_update_ring_doorbell( - IN nodnic_port_priv *port_priv, - IN struct nodnic_ring *ring, - IN mlx_uint16 index - ); -mlx_status -nodnic_port_get_cq_size( - IN nodnic_port_priv *port_priv, - OUT mlx_uint64 *cq_size - ); - -mlx_status -nodnic_port_allocate_eq( - IN nodnic_port_priv *port_priv, - IN mlx_uint8 log_eq_size - ); -mlx_status -nodnic_port_free_eq( - IN nodnic_port_priv *port_priv - ); - -mlx_status -nodnic_port_add_mac_filter( - IN nodnic_port_priv *port_priv, - IN mlx_mac_address mac - ); - -mlx_status -nodnic_port_remove_mac_filter( - IN nodnic_port_priv *port_priv, - IN mlx_mac_address mac - ); -mlx_status -nodnic_port_add_mgid_filter( - IN nodnic_port_priv *port_priv, - IN mlx_mac_address mac - ); - -mlx_status -nodnic_port_remove_mgid_filter( - IN nodnic_port_priv *port_priv, - IN mlx_mac_address mac - ); -mlx_status -nodnic_port_thin_init( - IN nodnic_device_priv *device_priv, - IN nodnic_port_priv *port_priv, - IN mlx_uint8 port_index - ); - -mlx_status -nodnic_port_set_promisc( - IN nodnic_port_priv *port_priv, - IN mlx_boolean value - ); - -mlx_status -nodnic_port_set_promisc_multicast( - IN nodnic_port_priv *port_priv, - IN mlx_boolean value - ); - -mlx_status -nodnic_port_init( - IN nodnic_port_priv *port_priv - ); - -mlx_status -nodnic_port_close( - IN nodnic_port_priv *port_priv - ); - -mlx_status -nodnic_port_enable_dma( - IN nodnic_port_priv *port_priv - ); - -mlx_status -nodnic_port_disable_dma( - IN nodnic_port_priv *port_priv - ); - -mlx_status -nodnic_port_read_reset_needed( - IN nodnic_port_priv *port_priv, - OUT mlx_boolean *reset_needed - ); - -mlx_status -nodnic_port_read_port_management_change_event( - IN nodnic_port_priv *port_priv, - OUT mlx_boolean *change_event - ); -#endif /* STUB_NODNIC_PORT_H_ */ diff --git a/roms/ipxe/src/drivers/infiniband/mlx_nodnic/src/mlx_cmd.c b/roms/ipxe/src/drivers/infiniband/mlx_nodnic/src/mlx_cmd.c deleted file mode 100644 index 69f85358b..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_nodnic/src/mlx_cmd.c +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include "../include/mlx_cmd.h" -#include "../../mlx_utils/include/public/mlx_pci_gw.h" -#include "../../mlx_utils/include/public/mlx_bail.h" -#include "../../mlx_utils/include/public/mlx_pci.h" -#include "../../mlx_utils/include/public/mlx_logging.h" - -mlx_status -nodnic_cmd_read( - IN nodnic_device_priv *device_priv, - IN mlx_uint32 address, - OUT mlx_pci_gw_buffer *buffer - ) -{ - mlx_status status = MLX_SUCCESS; - mlx_utils *utils = NULL; - - if ( device_priv == NULL || buffer == NULL ) { - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - - utils = device_priv->utils; - - status = mlx_pci_gw_read(utils, PCI_GW_SPACE_NODNIC, address, buffer); - MLX_CHECK_STATUS(device_priv, status, read_error,"mlx_pci_gw_read failed"); - -read_error: -bad_param: - return status; -} - -mlx_status -nodnic_cmd_write( - IN nodnic_device_priv *device_priv, - IN mlx_uint32 address, - IN mlx_pci_gw_buffer buffer - ) -{ - mlx_status status = MLX_SUCCESS; - mlx_utils *utils = NULL; - - - if ( device_priv == NULL ) { - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - - utils = device_priv->utils; - - - status = mlx_pci_gw_write(utils, PCI_GW_SPACE_NODNIC, address, buffer); - MLX_CHECK_STATUS(device_priv, status, write_error,"mlx_pci_gw_write failed"); -write_error: -bad_param: - return status; -} diff --git a/roms/ipxe/src/drivers/infiniband/mlx_nodnic/src/mlx_device.c b/roms/ipxe/src/drivers/infiniband/mlx_nodnic/src/mlx_device.c deleted file mode 100644 index 4acc94fa6..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_nodnic/src/mlx_device.c +++ /dev/null @@ -1,339 +0,0 @@ -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include "../include/mlx_device.h" -#include "../include/mlx_cmd.h" -#include "../../mlx_utils/include/public/mlx_bail.h" -#include "../../mlx_utils/include/public/mlx_pci.h" -#include "../../mlx_utils/include/public/mlx_memory.h" -#include "../../mlx_utils/include/public/mlx_logging.h" - -#define CHECK_BIT(field, offset) (((field) & ((mlx_uint32)1 << (offset))) != 0) - -static -mlx_status -check_nodnic_interface_supported( - IN nodnic_device_priv* device_priv, - OUT mlx_boolean *out - ) -{ - mlx_status status = MLX_SUCCESS; - mlx_uint32 output = 0; - status = nodnic_cmd_read(device_priv, NODNIC_NIC_INTERFACE_SUPPORTED_OFFSET, - &output); - MLX_FATAL_CHECK_STATUS(status, read_error, "failed to read nic_interface_supported"); - *out = CHECK_BIT(output, NODNIC_NIC_INTERFACE_SUPPORTED_BIT); -read_error: - return status; -} - -static -mlx_status -wait_for_device_initialization( - IN nodnic_device_priv* device_priv - ) -{ - mlx_status status = MLX_SUCCESS; - mlx_uint8 try = 0; - mlx_uint32 buffer = 0; - -#define CHECK_DEVICE_INIT_TRIES 10 - for( ; try < CHECK_DEVICE_INIT_TRIES ; try++){ - status = nodnic_cmd_read(device_priv, NODNIC_INITIALIZING_OFFSET, &buffer); - MLX_CHECK_STATUS(device_priv, status, read_error, "failed to read initializing"); - if( !CHECK_BIT(buffer, NODNIC_INITIALIZING_BIT)){ - goto init_done; - } - mlx_utils_delay_in_ms(100); - } - status = MLX_FAILED; -read_error: -init_done: - return status; -} - -static -mlx_status -disable_nodnic_inteface( - IN nodnic_device_priv *device_priv - ) -{ - mlx_status status = MLX_SUCCESS; - mlx_uint32 buffer = 0; - - buffer = (1 << NODNIC_DISABLE_INTERFACE_BIT); - status = nodnic_cmd_write(device_priv, NODNIC_CMDQ_PHY_ADDR_LOW_OFFSET, buffer); - MLX_FATAL_CHECK_STATUS(status, write_err, "failed to write cmdq_phy_addr + nic_interface"); - - status = wait_for_device_initialization(device_priv); - MLX_FATAL_CHECK_STATUS(status, init_err, "failed to initialize device"); -init_err: -write_err: - return status; -} -static -mlx_status -nodnic_device_start_nodnic( - IN nodnic_device_priv *device_priv - ) -{ - mlx_status status = MLX_SUCCESS; - mlx_uint32 buffer = 0; - mlx_boolean nodnic_supported = 0; - - status = wait_for_device_initialization(device_priv); - MLX_FATAL_CHECK_STATUS(status, wait_for_fw_err, "failed to initialize device"); - - status = check_nodnic_interface_supported(device_priv, &nodnic_supported); - MLX_FATAL_CHECK_STATUS(status, read_err,"failed to check nic_interface_supported"); - - if( nodnic_supported == 0 ){ - status = MLX_UNSUPPORTED; - goto nodnic_unsupported; - } - buffer = (1 << NODNIC_NIC_INTERFACE_BIT); - status = nodnic_cmd_write(device_priv, NODNIC_NIC_INTERFACE_OFFSET, buffer); - MLX_FATAL_CHECK_STATUS(status, write_err, "failed to write cmdq_phy_addr + nic_interface"); - - status = wait_for_device_initialization(device_priv); - MLX_FATAL_CHECK_STATUS(status, init_err, "failed to initialize device"); -init_err: -read_err: -write_err: -nodnic_unsupported: -wait_for_fw_err: - return status; -} - -static -mlx_status -nodnic_device_get_nodnic_data( - IN nodnic_device_priv *device_priv - ) -{ - mlx_status status = MLX_SUCCESS; - mlx_uint32 buffer = 0; - - status = nodnic_cmd_read(device_priv, NODNIC_LOCATION_OFFSET, &device_priv->device_offset); - MLX_FATAL_CHECK_STATUS(status, nodnic_offset_read_err, "failed to read nodnic offset"); - - status = nodnic_cmd_read(device_priv, - device_priv->device_offset + NODNIC_REVISION_OFFSET, &buffer); - MLX_FATAL_CHECK_STATUS(status, nodnic_revision_read_err, "failed to read nodnic revision"); - - device_priv->nodnic_revision = (buffer >> 24) & 0xFF; - if( device_priv->nodnic_revision != NODIC_SUPPORTED_REVISION ){ - MLX_DEBUG_ERROR(device_priv, "nodnic revision not supported\n"); - status = MLX_UNSUPPORTED; - goto unsupported_revision; - } - - status = nodnic_cmd_read(device_priv, - device_priv->device_offset + NODNIC_HARDWARE_FORMAT_OFFSET, &buffer); - MLX_FATAL_CHECK_STATUS(status, nodnic_hardware_format_read_err, "failed to read nodnic revision"); - device_priv->hardware_format = (buffer >> 16) & 0xFF; - - return status; - -unsupported_revision: -nodnic_hardware_format_read_err: -nodnic_offset_read_err: -nodnic_revision_read_err: - disable_nodnic_inteface(device_priv); - return status; -} - -mlx_status -nodnic_device_clear_int ( - IN nodnic_device_priv *device_priv - ) -{ - mlx_status status = MLX_SUCCESS; - mlx_uint32 disable = 1; -#ifndef DEVICE_CX3 - status = nodnic_cmd_write(device_priv, NODNIC_NIC_DISABLE_INT_OFFSET, disable); - MLX_CHECK_STATUS(device_priv, status, clear_int_done, "failed writing to disable_bit"); -#else - mlx_utils *utils = device_priv->utils; - mlx_uint64 clear_int = (mlx_uint64)(device_priv->crspace_clear_int); - mlx_uint32 swapped = 0; - - if (device_priv->device_cap.crspace_doorbells == 0) { - status = nodnic_cmd_write(device_priv, NODNIC_NIC_DISABLE_INT_OFFSET, disable); - MLX_CHECK_STATUS(device_priv, status, clear_int_done, "failed writing to disable_bit"); - } else { - /* Write the new index and update FW that new data was submitted */ - disable = 0x80000000; - mlx_memory_cpu_to_be32(utils, disable, &swapped); - mlx_pci_mem_write (utils, MlxPciWidthUint32, 0, clear_int, 1, &swapped); - mlx_pci_mem_read (utils, MlxPciWidthUint32, 0, clear_int, 1, &swapped); - } -#endif -clear_int_done: - return status; -} - -mlx_status -nodnic_device_init( - IN nodnic_device_priv *device_priv - ) -{ - mlx_status status = MLX_SUCCESS; - - if( device_priv == NULL ){ - status = MLX_INVALID_PARAMETER; - goto parm_err; - } - status = nodnic_device_start_nodnic(device_priv); - MLX_FATAL_CHECK_STATUS(status, start_nodnic_err, "nodnic_device_start_nodnic failed"); - - status = nodnic_device_get_nodnic_data(device_priv); - MLX_FATAL_CHECK_STATUS(status, data_err, "nodnic_device_get_nodnic_data failed"); - return status; -data_err: -start_nodnic_err: -parm_err: - return status; -} - -mlx_status -nodnic_device_teardown( - IN nodnic_device_priv *device_priv - ) -{ - mlx_status status = MLX_SUCCESS; - status = disable_nodnic_inteface(device_priv); - MLX_FATAL_CHECK_STATUS(status, disable_failed, "failed to disable nodnic interface"); -disable_failed: - return status; -} - -mlx_status -nodnic_device_get_cap( - IN nodnic_device_priv *device_priv - ) -{ - mlx_status status = MLX_SUCCESS; - nodnic_device_capabilites *device_cap = NULL; - mlx_uint32 buffer = 0; - mlx_uint64 guid_l = 0; - mlx_uint64 guid_h = 0; - if( device_priv == NULL ){ - status = MLX_INVALID_PARAMETER; - goto parm_err; - } - - device_cap = &device_priv->device_cap; - - //get device capabilities - status = nodnic_cmd_read(device_priv, device_priv->device_offset + 0x0, &buffer); - MLX_FATAL_CHECK_STATUS(status, read_err, "failed to read nodnic first dword"); - -#define NODNIC_DEVICE_SUPPORT_MAC_FILTERS_OFFSET 15 -#define NODNIC_DEVICE_SUPPORT_PROMISC_FILTER_OFFSET 14 -#define NODNIC_DEVICE_SUPPORT_PROMISC_MULT_FILTER_OFFSET 13 -#define NODNIC_DEVICE_LOG_WORKING_BUFFER_SIZE_OFFSET 8 -#define NODNIC_DEVICE_LOG_WORKING_BUFFER_SIZE_MASK 0x7 -#define NODNIC_DEVICE_LOG_PKEY_TABLE_SIZE_OFFSET 4 -#define NODNIC_DEVICE_LOG_PKEY_TABLE_SIZE_MASK 0xF -#define NODNIC_DEVICE_NUM_PORTS_OFFSET 0 - device_cap->support_mac_filters = CHECK_BIT(buffer, NODNIC_DEVICE_SUPPORT_MAC_FILTERS_OFFSET); - - device_cap->support_promisc_filter = CHECK_BIT(buffer, NODNIC_DEVICE_SUPPORT_PROMISC_FILTER_OFFSET); - - device_cap->support_promisc_multicast_filter = CHECK_BIT(buffer, NODNIC_DEVICE_SUPPORT_PROMISC_MULT_FILTER_OFFSET); - - device_cap->log_working_buffer_size = - (buffer >> NODNIC_DEVICE_LOG_WORKING_BUFFER_SIZE_OFFSET) & NODNIC_DEVICE_LOG_WORKING_BUFFER_SIZE_MASK; - - device_cap->log_pkey_table_size = - (buffer >> NODNIC_DEVICE_LOG_PKEY_TABLE_SIZE_OFFSET) & NODNIC_DEVICE_LOG_PKEY_TABLE_SIZE_MASK; - - device_cap->num_ports = CHECK_BIT(buffer, NODNIC_DEVICE_NUM_PORTS_OFFSET) + 1; - -#ifdef DEVICE_CX3 -#define NODNIC_DEVICE_CRSPACE_DB_OFFSET 12 - device_cap->crspace_doorbells = CHECK_BIT(buffer, NODNIC_DEVICE_CRSPACE_DB_OFFSET); -#endif - - status = nodnic_cmd_read(device_priv, device_priv->device_offset + 0x4, &buffer); - MLX_FATAL_CHECK_STATUS(status, read_err, "failed to read nodnic second dword"); - -#define NODNIC_DEVICE_LOG_MAX_RING_SIZE_OFFSET 24 -#define NODNIC_DEVICE_LOG_MAX_RING_SIZE_MASK 0x3F -#define NODNIC_DEVICE_PD_MASK 0xFFFFFF - device_cap->log_max_ring_size = - (buffer >> NODNIC_DEVICE_LOG_MAX_RING_SIZE_OFFSET) & NODNIC_DEVICE_LOG_MAX_RING_SIZE_MASK; - - //get device magic numbers - device_priv->pd = buffer & NODNIC_DEVICE_PD_MASK; - - status = nodnic_cmd_read(device_priv, device_priv->device_offset + 0x8, &buffer); - MLX_FATAL_CHECK_STATUS(status, read_err, "failed to read nodnic third dword"); - device_priv->lkey = buffer; - -#ifdef DEVICE_CX3 - if ( device_cap->crspace_doorbells ) { - status = nodnic_cmd_read(device_priv, device_priv->device_offset + 0x18, &buffer); - MLX_FATAL_CHECK_STATUS(status, read_err, "failed to read nodnic_crspace_clear_int address"); - device_priv->crspace_clear_int = device_priv->utils->config + buffer; - } -#endif - - status = nodnic_cmd_read(device_priv, device_priv->device_offset + 0x10, (mlx_uint32*)&guid_h); - MLX_FATAL_CHECK_STATUS(status, read_err, "failed to read nodnic guid_h"); - status = nodnic_cmd_read(device_priv, device_priv->device_offset + 0x14, (mlx_uint32*)&guid_l); - MLX_FATAL_CHECK_STATUS(status, read_err, "failed to read nodnic guid_l"); - device_priv->device_guid = guid_l | (guid_h << 32); -read_err: -parm_err: - return status; -} - -mlx_status -nodnic_device_get_fw_version( - IN nodnic_device_priv *device_priv, - OUT mlx_uint16 *fw_ver_minor, - OUT mlx_uint16 *fw_ver_sub_minor, - OUT mlx_uint16 *fw_ver_major - ){ - mlx_status status = MLX_SUCCESS; - mlx_uint32 buffer = 0; - - if( device_priv == NULL ){ - status = MLX_INVALID_PARAMETER; - goto parm_err; - } - - status = nodnic_cmd_read(device_priv, 0x0, &buffer); - MLX_CHECK_STATUS(device_priv, status, read_err, "failed to read fw revision major and minor"); - - *fw_ver_minor = (mlx_uint16)(buffer >> 16); - *fw_ver_major = (mlx_uint16)buffer; - - status = nodnic_cmd_read(device_priv, 0x4, &buffer); - MLX_CHECK_STATUS(device_priv, status, read_err, "failed to read fw revision sub minor"); - - *fw_ver_sub_minor = (mlx_uint16)buffer; -read_err: -parm_err: - return status; -} diff --git a/roms/ipxe/src/drivers/infiniband/mlx_nodnic/src/mlx_port.c b/roms/ipxe/src/drivers/infiniband/mlx_nodnic/src/mlx_port.c deleted file mode 100644 index a7afdab65..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_nodnic/src/mlx_port.c +++ /dev/null @@ -1,1038 +0,0 @@ -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include "../include/mlx_port.h" -#include "../include/mlx_cmd.h" -#include "../../mlx_utils/include/public/mlx_memory.h" -#include "../../mlx_utils/include/public/mlx_pci.h" -#include "../../mlx_utils/include/public/mlx_bail.h" - -#define PortDataEntry( _option, _offset, _align, _mask) { \ - .option = _option, \ - .offset = _offset, \ - .align = _align, \ - .mask = _mask, \ - } - -#define QpDataEntry( _type, _send_offset, _recv_offset) { \ - .type = _type, \ - .send_offset = _send_offset, \ - .recv_offset = _recv_offset, \ - } - - -struct nodnic_port_data_entry nodnic_port_data_table[] = { - PortDataEntry(nodnic_port_option_link_type, 0x0, 4, 0x1), - PortDataEntry(nodnic_port_option_mac_low, 0xc, 0, 0xFFFFFFFF), - PortDataEntry(nodnic_port_option_mac_high, 0x8, 0, 0xFFFF), - PortDataEntry(nodnic_port_option_log_cq_size, 0x6c, 0, 0x3F), - PortDataEntry(nodnic_port_option_reset_needed, 0x0, 31, 0x1), - PortDataEntry(nodnic_port_option_mac_filters_en, 0x4, 0, 0x1F), - PortDataEntry(nodnic_port_option_port_state, 0x0, 0, 0xF), - PortDataEntry(nodnic_port_option_network_en, 0x4, 31, 0x1), - PortDataEntry(nodnic_port_option_dma_en, 0x4, 30, 0x1), - PortDataEntry(nodnic_port_option_eq_addr_low, 0x74, 0, 0xFFFFFFFF), - PortDataEntry(nodnic_port_option_eq_addr_high, 0x70, 0, 0xFFFFFFFF), - PortDataEntry(nodnic_port_option_cq_addr_low, 0x6c, 12, 0xFFFFF), - PortDataEntry(nodnic_port_option_cq_addr_high, 0x68, 0, 0xFFFFFFFF), - PortDataEntry(nodnic_port_option_port_management_change_event, 0x0, 30, 0x1), - PortDataEntry(nodnic_port_option_port_promisc_en, 0x4, 29, 0x1), - PortDataEntry(nodnic_port_option_arm_cq, 0x78, 8, 0xffff), - PortDataEntry(nodnic_port_option_port_promisc_multicast_en, 0x4, 28, 0x1), -#ifdef DEVICE_CX3 - PortDataEntry(nodnic_port_option_crspace_en, 0x4, 27, 0x1), -#endif -}; - -#define MAX_QP_DATA_ENTRIES 5 -struct nodnic_qp_data_entry nodnic_qp_data_teable[MAX_QP_DATA_ENTRIES] = { - QpDataEntry(NODNIC_QPT_SMI, 0, 0), - QpDataEntry(NODNIC_QPT_GSI, 0, 0), - QpDataEntry(NODNIC_QPT_UD, 0, 0), - QpDataEntry(NODNIC_QPT_RC, 0, 0), - QpDataEntry(NODNIC_QPT_ETH, 0x80, 0xC0), -}; - -#define MAX_NODNIC_PORTS 2 -int nodnic_port_offset_table[MAX_NODNIC_PORTS] = { - 0x100, //port 1 offset - 0x280, //port 1 offset -}; - -mlx_status -nodnic_port_get_state( - IN nodnic_port_priv *port_priv, - OUT nodnic_port_state *state - ) -{ - mlx_status status = MLX_SUCCESS; - mlx_uint32 out = 0; - - status = nodnic_port_query(port_priv, - nodnic_port_option_port_state, &out); - MLX_CHECK_STATUS(port_priv->device, status, query_err, - "nodnic_port_query failed"); - *state = (nodnic_port_state)out; -query_err: - return status; -} -mlx_status -nodnic_port_get_type( - IN nodnic_port_priv *port_priv, - OUT nodnic_port_type *type - ) -{ - mlx_status status = MLX_SUCCESS; - mlx_uint32 out = 0; - - if ( port_priv->port_type == NODNIC_PORT_TYPE_UNKNOWN){ - status = nodnic_port_query(port_priv, - nodnic_port_option_link_type, &out); - MLX_FATAL_CHECK_STATUS(status, query_err, - "nodnic_port_query failed"); - port_priv->port_type = (nodnic_port_type)out; - } - *type = port_priv->port_type; -query_err: - return status; -} - -mlx_status -nodnic_port_query( - IN nodnic_port_priv *port_priv, - IN nodnic_port_option option, - OUT mlx_uint32 *out - ) -{ - mlx_status status = MLX_SUCCESS; - nodnic_device_priv *device_priv = NULL; - struct nodnic_port_data_entry *data_entry; - mlx_uint32 buffer = 0; - if( port_priv == NULL || out == NULL){ - status = MLX_INVALID_PARAMETER; - goto invalid_parm; - } - device_priv = port_priv->device; - - data_entry = &nodnic_port_data_table[option]; - - status = nodnic_cmd_read(device_priv, - port_priv->port_offset + data_entry->offset , &buffer); - MLX_CHECK_STATUS(device_priv, status, read_err, - "nodnic_cmd_read failed"); - *out = (buffer >> data_entry->align) & data_entry->mask; -read_err: -invalid_parm: - return status; -} - -mlx_status -nodnic_port_set( - IN nodnic_port_priv *port_priv, - IN nodnic_port_option option, - IN mlx_uint32 in - ) -{ - mlx_status status = MLX_SUCCESS; - nodnic_device_priv *device_priv = NULL; - struct nodnic_port_data_entry *data_entry; - mlx_uint32 buffer = 0; - - if( port_priv == NULL ){ - MLX_DEBUG_FATAL_ERROR("port_priv is NULL\n"); - status = MLX_INVALID_PARAMETER; - goto invalid_parm; - } - device_priv = port_priv->device; - data_entry = &nodnic_port_data_table[option]; - - if( in > data_entry->mask ){ - MLX_DEBUG_FATAL_ERROR("in > data_entry->mask (%d > %d)\n", - in, data_entry->mask); - status = MLX_INVALID_PARAMETER; - goto invalid_parm; - } - status = nodnic_cmd_read(device_priv, - port_priv->port_offset + data_entry->offset, &buffer); - MLX_FATAL_CHECK_STATUS(status, read_err, - "nodnic_cmd_read failed"); - buffer = buffer & ~(data_entry->mask << data_entry->align); - buffer = buffer | (in << data_entry->align); - status = nodnic_cmd_write(device_priv, - port_priv->port_offset + data_entry->offset, buffer); - MLX_FATAL_CHECK_STATUS(status, write_err, - "nodnic_cmd_write failed"); -write_err: -read_err: -invalid_parm: - return status; -} - -mlx_status -nodnic_port_read_reset_needed( - IN nodnic_port_priv *port_priv, - OUT mlx_boolean *reset_needed - ) -{ - mlx_status status = MLX_SUCCESS; - mlx_uint32 out = 0; - status = nodnic_port_query(port_priv, - nodnic_port_option_reset_needed, &out); - MLX_CHECK_STATUS(port_priv->device, status, query_err, - "nodnic_port_query failed"); - *reset_needed = (mlx_boolean)out; -query_err: - return status; -} - -mlx_status -nodnic_port_read_port_management_change_event( - IN nodnic_port_priv *port_priv, - OUT mlx_boolean *change_event - ) -{ - mlx_status status = MLX_SUCCESS; - mlx_uint32 out = 0; - status = nodnic_port_query(port_priv, - nodnic_port_option_port_management_change_event, &out); - MLX_CHECK_STATUS(port_priv->device, status, query_err, - "nodnic_port_query failed"); - *change_event = (mlx_boolean)out; -query_err: - return status; -} - -mlx_status -nodnic_port_create_cq( - IN nodnic_port_priv *port_priv, - IN mlx_size cq_size, - OUT nodnic_cq **cq - ) -{ - mlx_status status = MLX_SUCCESS; - nodnic_device_priv *device_priv = NULL; - mlx_uint64 address = 0; - if( port_priv == NULL || cq == NULL){ - status = MLX_INVALID_PARAMETER; - goto invalid_parm; - } - - device_priv = port_priv->device; - - status = mlx_memory_zalloc(device_priv->utils, - sizeof(nodnic_cq),(mlx_void **)cq); - MLX_FATAL_CHECK_STATUS(status, alloc_err, - "cq priv allocation error"); - - (*cq)->cq_size = cq_size; - status = mlx_memory_alloc_dma(device_priv->utils, - (*cq)->cq_size, NODNIC_MEMORY_ALIGN, - &(*cq)->cq_virt); - MLX_FATAL_CHECK_STATUS(status, dma_alloc_err, - "cq allocation error"); - - status = mlx_memory_map_dma(device_priv->utils, - (*cq)->cq_virt, - (*cq)->cq_size, - &(*cq)->cq_physical, - &(*cq)->map); - MLX_FATAL_CHECK_STATUS(status, cq_map_err, - "cq map error"); - - /* update cq address */ -#define NODIC_CQ_ADDR_HIGH 0x68 -#define NODIC_CQ_ADDR_LOW 0x6c - address = (mlx_uint64)(*cq)->cq_physical; - nodnic_port_set(port_priv, nodnic_port_option_cq_addr_low, - (mlx_uint32)(address >> 12)); - address = address >> 32; - nodnic_port_set(port_priv, nodnic_port_option_cq_addr_high, - (mlx_uint32)address); - - return status; - mlx_memory_ummap_dma(device_priv->utils, (*cq)->map); -cq_map_err: - mlx_memory_free_dma(device_priv->utils, (*cq)->cq_size, - (void **)&((*cq)->cq_virt)); -dma_alloc_err: - mlx_memory_free(device_priv->utils, (void **)cq); -alloc_err: -invalid_parm: - return status; -} - -mlx_status -nodnic_port_destroy_cq( - IN nodnic_port_priv *port_priv, - IN nodnic_cq *cq - ) -{ - mlx_status status = MLX_SUCCESS; - nodnic_device_priv *device_priv = NULL; - - if( port_priv == NULL || cq == NULL){ - status = MLX_INVALID_PARAMETER; - goto invalid_parm; - } - device_priv = port_priv->device; - - mlx_memory_ummap_dma(device_priv->utils, cq->map); - - mlx_memory_free_dma(device_priv->utils, cq->cq_size, - (void **)&(cq->cq_virt)); - - mlx_memory_free(device_priv->utils, (void **)&cq); -invalid_parm: - return status; -} -mlx_status -nodnic_port_create_qp( - IN nodnic_port_priv *port_priv, - IN nodnic_queue_pair_type type, - IN mlx_size send_wq_size, - IN mlx_uint32 send_wqe_num, - IN mlx_size receive_wq_size, - IN mlx_uint32 recv_wqe_num, - OUT nodnic_qp **qp - ) -{ - mlx_status status = MLX_SUCCESS; - nodnic_device_priv *device_priv = NULL; - mlx_uint32 max_ring_size = 0; - mlx_uint64 address = 0; - mlx_uint32 log_size = 0; - if( port_priv == NULL || qp == NULL){ - status = MLX_INVALID_PARAMETER; - goto invalid_parm; - } - - device_priv = port_priv->device; - max_ring_size = (1 << device_priv->device_cap.log_max_ring_size); - if( send_wq_size > max_ring_size || - receive_wq_size > max_ring_size ){ - status = MLX_INVALID_PARAMETER; - goto invalid_parm; - } - - status = mlx_memory_zalloc(device_priv->utils, - sizeof(nodnic_qp),(mlx_void **)qp); - MLX_FATAL_CHECK_STATUS(status, alloc_err, - "qp allocation error"); - - if( nodnic_qp_data_teable[type].send_offset == 0 || - nodnic_qp_data_teable[type].recv_offset == 0){ - status = MLX_INVALID_PARAMETER; - goto invalid_type; - } - - (*qp)->send.nodnic_ring.offset = port_priv->port_offset + - nodnic_qp_data_teable[type].send_offset; - (*qp)->receive.nodnic_ring.offset = port_priv->port_offset + - nodnic_qp_data_teable[type].recv_offset; - - status = mlx_memory_alloc_dma(device_priv->utils, - send_wq_size, NODNIC_MEMORY_ALIGN, - (void*)&(*qp)->send.wqe_virt); - MLX_FATAL_CHECK_STATUS(status, send_alloc_err, - "send wq allocation error"); - - status = mlx_memory_alloc_dma(device_priv->utils, - receive_wq_size, NODNIC_MEMORY_ALIGN, - &(*qp)->receive.wqe_virt); - MLX_FATAL_CHECK_STATUS(status, receive_alloc_err, - "receive wq allocation error"); - - status = mlx_memory_map_dma(device_priv->utils, - (*qp)->send.wqe_virt, - send_wq_size, - &(*qp)->send.nodnic_ring.wqe_physical, - &(*qp)->send.nodnic_ring.map); - MLX_FATAL_CHECK_STATUS(status, send_map_err, - "send wq map error"); - - status = mlx_memory_map_dma(device_priv->utils, - (*qp)->receive.wqe_virt, - receive_wq_size, - &(*qp)->receive.nodnic_ring.wqe_physical, - &(*qp)->receive.nodnic_ring.map); - MLX_FATAL_CHECK_STATUS(status, receive_map_err, - "receive wq map error"); - - (*qp)->send.nodnic_ring.wq_size = send_wq_size; - (*qp)->send.nodnic_ring.num_wqes = send_wqe_num; - (*qp)->receive.nodnic_ring.wq_size = receive_wq_size; - (*qp)->receive.nodnic_ring.num_wqes = recv_wqe_num; - - /* Set Ownership bit in Send/receive queue (0 - recv ; 1 - send) */ - mlx_memory_set(device_priv->utils, (*qp)->send.wqe_virt, 0xff, send_wq_size ); - mlx_memory_set(device_priv->utils, (*qp)->receive.wqe_virt, 0, recv_wqe_num ); - - /* update send ring */ -#define NODIC_RING_QP_ADDR_HIGH 0x0 -#define NODIC_RING_QP_ADDR_LOW 0x4 - address = (mlx_uint64)(*qp)->send.nodnic_ring.wqe_physical; - status = nodnic_cmd_write(device_priv, (*qp)->send.nodnic_ring.offset + - NODIC_RING_QP_ADDR_HIGH, - (mlx_uint32)(address >> 32)); - MLX_FATAL_CHECK_STATUS(status, write_send_addr_err, - "send address write error 1"); - mlx_utils_ilog2((*qp)->send.nodnic_ring.wq_size, &log_size); - address = address | log_size; - status = nodnic_cmd_write(device_priv, (*qp)->send.nodnic_ring.offset + - NODIC_RING_QP_ADDR_LOW, - (mlx_uint32)address); - MLX_FATAL_CHECK_STATUS(status, write_send_addr_err, - "send address write error 2"); - /* update receive ring */ - address = (mlx_uint64)(*qp)->receive.nodnic_ring.wqe_physical; - status = nodnic_cmd_write(device_priv, (*qp)->receive.nodnic_ring.offset + - NODIC_RING_QP_ADDR_HIGH, - (mlx_uint32)(address >> 32)); - MLX_FATAL_CHECK_STATUS(status, write_recv_addr_err, - "receive address write error 1"); - mlx_utils_ilog2((*qp)->receive.nodnic_ring.wq_size, &log_size); - address = address | log_size; - status = nodnic_cmd_write(device_priv, (*qp)->receive.nodnic_ring.offset + - NODIC_RING_QP_ADDR_LOW, - (mlx_uint32)address); - MLX_FATAL_CHECK_STATUS(status, write_recv_addr_err, - "receive address write error 2"); - - return status; -write_recv_addr_err: -write_send_addr_err: - mlx_memory_ummap_dma(device_priv->utils, (*qp)->receive.nodnic_ring.map); -receive_map_err: - mlx_memory_ummap_dma(device_priv->utils, (*qp)->send.nodnic_ring.map); -send_map_err: - mlx_memory_free_dma(device_priv->utils, receive_wq_size, - &((*qp)->receive.wqe_virt)); -receive_alloc_err: - mlx_memory_free_dma(device_priv->utils, send_wq_size, - (void **)&((*qp)->send.wqe_virt)); -send_alloc_err: -invalid_type: - mlx_memory_free(device_priv->utils, (void **)qp); -alloc_err: -invalid_parm: - return status; -} - -mlx_status -nodnic_port_destroy_qp( - IN nodnic_port_priv *port_priv, - IN nodnic_queue_pair_type type __attribute__((unused)), - IN nodnic_qp *qp - ) -{ - mlx_status status = MLX_SUCCESS; - nodnic_device_priv *device_priv = port_priv->device; - - status = mlx_memory_ummap_dma(device_priv->utils, - qp->receive.nodnic_ring.map); - if( status != MLX_SUCCESS){ - MLX_DEBUG_ERROR(device_priv, "mlx_memory_ummap_dma failed (Status = %d)\n", status); - } - - status = mlx_memory_ummap_dma(device_priv->utils, qp->send.nodnic_ring.map); - if( status != MLX_SUCCESS){ - MLX_DEBUG_ERROR(device_priv, "mlx_memory_ummap_dma failed (Status = %d)\n", status); - } - - status = mlx_memory_free_dma(device_priv->utils, - qp->receive.nodnic_ring.wq_size, - (void **)&(qp->receive.wqe_virt)); - if( status != MLX_SUCCESS){ - MLX_DEBUG_ERROR(device_priv, "mlx_memory_free_dma failed (Status = %d)\n", status); - } - status = mlx_memory_free_dma(device_priv->utils, - qp->send.nodnic_ring.wq_size, - (void **)&(qp->send.wqe_virt)); - if( status != MLX_SUCCESS){ - MLX_DEBUG_ERROR(device_priv, "mlx_memory_free_dma failed (Status = %d)\n", status); - } - status = mlx_memory_free(device_priv->utils, (void **)&qp); - if( status != MLX_SUCCESS){ - MLX_DEBUG_ERROR(device_priv, "mlx_memory_free failed (Status = %d)\n", status); - } - return status; -} - -mlx_status -nodnic_port_get_qpn( - IN nodnic_port_priv *port_priv, - IN struct nodnic_ring *ring, - OUT mlx_uint32 *qpn - ) -{ - mlx_status status = MLX_SUCCESS; - mlx_uint32 buffer = 0; - if( ring == NULL || qpn == NULL){ - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - if( ring->qpn != 0 ){ - *qpn = ring->qpn; - goto success; - } -#define NODNIC_RING_QPN_OFFSET 0xc -#define NODNIC_RING_QPN_MASK 0xFFFFFF - status = nodnic_cmd_read(port_priv->device, - ring->offset + NODNIC_RING_QPN_OFFSET, - &buffer); - MLX_FATAL_CHECK_STATUS(status, read_err, - "nodnic_cmd_read failed"); - ring->qpn = buffer & NODNIC_RING_QPN_MASK; - *qpn = ring->qpn; -read_err: -success: -bad_param: - return status; -} - -#ifdef DEVICE_CX3 -static -mlx_status -nodnic_port_send_db_connectx3( - IN nodnic_port_priv *port_priv, - IN struct nodnic_ring *ring __attribute__((unused)), - IN mlx_uint16 index - ) -{ - nodnic_port_data_flow_gw *ptr = port_priv->data_flow_gw; - mlx_uint32 index32 = index; - mlx_pci_mem_write(port_priv->device->utils, MlxPciWidthUint32, 0, - (mlx_uint64)&(ptr->send_doorbell), 1, &index32); - return MLX_SUCCESS; -} - -static -mlx_status -nodnic_port_recv_db_connectx3( - IN nodnic_port_priv *port_priv, - IN struct nodnic_ring *ring __attribute__((unused)), - IN mlx_uint16 index - ) -{ - nodnic_port_data_flow_gw *ptr = port_priv->data_flow_gw; - mlx_uint32 index32 = index; - mlx_pci_mem_write(port_priv->device->utils, MlxPciWidthUint32, 0, - (mlx_uint64)&(ptr->recv_doorbell), 1, &index32); - return MLX_SUCCESS; -} -#endif - -mlx_status -nodnic_port_update_ring_doorbell( - IN nodnic_port_priv *port_priv, - IN struct nodnic_ring *ring, - IN mlx_uint16 index - ) -{ - mlx_status status = MLX_SUCCESS; - mlx_uint32 buffer = 0; - if( ring == NULL ){ - status = MLX_INVALID_PARAMETER; - goto bad_param; - } -#define NODNIC_RING_RING_OFFSET 0x8 - buffer = (mlx_uint32)((index & 0xFFFF)<< 8); - status = nodnic_cmd_write(port_priv->device, - ring->offset + NODNIC_RING_RING_OFFSET, - buffer); - MLX_CHECK_STATUS(port_priv->device, status, write_err, - "nodnic_cmd_write failed"); -write_err: -bad_param: - return status; -} - -mlx_status -nodnic_port_get_cq_size( - IN nodnic_port_priv *port_priv, - OUT mlx_uint64 *cq_size - ) -{ - mlx_status status = MLX_SUCCESS; - mlx_uint32 out = 0; - status = nodnic_port_query(port_priv, nodnic_port_option_log_cq_size, &out); - MLX_FATAL_CHECK_STATUS(status, query_err, - "nodnic_port_query failed"); - *cq_size = 1 << out; -query_err: - return status; -} - -mlx_status -nodnic_port_allocate_eq( - IN nodnic_port_priv *port_priv, - IN mlx_uint8 log_eq_size - ) -{ - mlx_status status = MLX_SUCCESS; - nodnic_device_priv *device_priv = NULL; - mlx_uint64 address = 0; - - if( port_priv == NULL ){ - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - - device_priv = port_priv->device; - port_priv->eq.eq_size = ( ( 1 << log_eq_size ) * 1024 ); /* Size is in KB */ - status = mlx_memory_alloc_dma(device_priv->utils, - port_priv->eq.eq_size, - NODNIC_MEMORY_ALIGN, - &port_priv->eq.eq_virt); - MLX_FATAL_CHECK_STATUS(status, alloc_err, - "eq allocation error"); - - status = mlx_memory_map_dma(device_priv->utils, - port_priv->eq.eq_virt, - port_priv->eq.eq_size, - &port_priv->eq.eq_physical, - &port_priv->eq.map); - MLX_FATAL_CHECK_STATUS(status, map_err, - "eq map error"); - - address = port_priv->eq.eq_physical; - status = nodnic_port_set(port_priv, nodnic_port_option_eq_addr_low, - (mlx_uint32)address); - MLX_FATAL_CHECK_STATUS(status, set_err, - "failed to set eq addr low"); - address = (address >> 32); - status = nodnic_port_set(port_priv, nodnic_port_option_eq_addr_high, - (mlx_uint32)address); - MLX_FATAL_CHECK_STATUS(status, set_err, - "failed to set eq addr high"); - return status; -set_err: - mlx_memory_ummap_dma(device_priv->utils, port_priv->eq.map); -map_err: - mlx_memory_free_dma(device_priv->utils, - port_priv->eq.eq_size, - (void **)&(port_priv->eq.eq_virt)); -alloc_err: -bad_param: - return status; -} -mlx_status -nodnic_port_free_eq( - IN nodnic_port_priv *port_priv - ) -{ - mlx_status status = MLX_SUCCESS; - nodnic_device_priv *device_priv = NULL; - - if( port_priv == NULL ){ - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - - device_priv = port_priv->device; - mlx_memory_ummap_dma(device_priv->utils, port_priv->eq.map); - - mlx_memory_free_dma(device_priv->utils, - port_priv->eq.eq_size, - (void **)&(port_priv->eq.eq_virt)); - -bad_param: - return status; -} - -mlx_status -nodnic_port_add_mac_filter( - IN nodnic_port_priv *port_priv, - IN mlx_mac_address mac - ) -{ - mlx_status status = MLX_SUCCESS; - nodnic_device_priv *device= NULL;; - mlx_uint8 index = 0; - mlx_uint32 out = 0; - mlx_uint32 mac_filters_en = 0; - mlx_uint32 address = 0; - mlx_mac_address zero_mac; - mlx_utils *utils = NULL; - - if( port_priv == NULL){ - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - - memset(&zero_mac, 0, sizeof(zero_mac)); - - device = port_priv->device; - utils = device->utils; - - /* check if mac already exists */ - for( ; index < NODNIC_MAX_MAC_FILTERS ; index ++) { - mlx_memory_cmp(utils, &port_priv->mac_filters[index], &mac, - sizeof(mac), &out); - if ( out == 0 ){ - status = MLX_FAILED; - goto already_exists; - } - } - - /* serch for available mac filter slot */ - for (index = 0 ; index < NODNIC_MAX_MAC_FILTERS ; index ++) { - mlx_memory_cmp(utils, &port_priv->mac_filters[index], &zero_mac, - sizeof(zero_mac), &out); - if ( out == 0 ){ - break; - } - } - if ( index >= NODNIC_MAX_MAC_FILTERS ){ - status = MLX_FAILED; - goto mac_list_full; - } - - status = nodnic_port_query(port_priv, nodnic_port_option_mac_filters_en, - &mac_filters_en); - MLX_CHECK_STATUS(device, status , query_err, - "nodnic_port_query failed"); - if(mac_filters_en & (1 << index)){ - status = MLX_FAILED; - goto mac_list_full; - } - port_priv->mac_filters[index] = mac; - - // set mac filter - address = port_priv->port_offset + NODNIC_PORT_MAC_FILTERS_OFFSET + - (0x8 * index); - - status = nodnic_cmd_write(device, address, mac.high ); - MLX_CHECK_STATUS(device, status, write_err, "set mac high failed"); - status = nodnic_cmd_write(device, address + 0x4, mac.low ); - MLX_CHECK_STATUS(device, status, write_err, "set mac low failed"); - - // enable mac filter - mac_filters_en = mac_filters_en | (1 << index); - status = nodnic_port_set(port_priv, nodnic_port_option_mac_filters_en, - mac_filters_en); - MLX_CHECK_STATUS(device, status , set_err, - "nodnic_port_set failed"); -set_err: -write_err: -query_err: -mac_list_full: -already_exists: -bad_param: - return status; -} - -mlx_status -nodnic_port_remove_mac_filter( - IN nodnic_port_priv *port_priv, - IN mlx_mac_address mac - ) -{ - mlx_status status = MLX_SUCCESS; - nodnic_device_priv *device= NULL;; - mlx_uint8 index = 0; - mlx_uint32 out = 0; - mlx_uint32 mac_filters_en = 0; - mlx_mac_address zero_mac; - mlx_utils *utils = NULL; - - if( port_priv == NULL){ - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - - memset(&zero_mac, 0, sizeof(zero_mac)); - - device = port_priv->device; - utils = device->utils; - - /* serch for mac filter */ - for( ; index < NODNIC_MAX_MAC_FILTERS ; index ++) { - mlx_memory_cmp(utils, &port_priv->mac_filters[index], &mac, - sizeof(mac), &out); - if ( out == 0 ){ - break; - } - } - if ( index == NODNIC_MAX_MAC_FILTERS ){ - status = MLX_FAILED; - goto mac_not_found; - } - - status = nodnic_port_query(port_priv, nodnic_port_option_mac_filters_en, - &mac_filters_en); - MLX_CHECK_STATUS(device, status , query_err, - "nodnic_port_query failed"); - if((mac_filters_en & (1 << index)) == 0){ - status = MLX_FAILED; - goto mac_not_en; - } - port_priv->mac_filters[index] = zero_mac; - - // disable mac filter - mac_filters_en = mac_filters_en & ~(1 << index); - status = nodnic_port_set(port_priv, nodnic_port_option_mac_filters_en, - mac_filters_en); - MLX_CHECK_STATUS(device, status , set_err, - "nodnic_port_set failed"); -set_err: -query_err: -mac_not_en: -mac_not_found: -bad_param: - return status; -} - -static -mlx_status -nodnic_port_set_network( - IN nodnic_port_priv *port_priv, - IN mlx_boolean value - ) -{ - mlx_status status = MLX_SUCCESS; - /*mlx_uint32 network_valid = 0; - mlx_uint8 try = 0;*/ - - status = nodnic_port_set(port_priv, nodnic_port_option_network_en, value); - MLX_CHECK_STATUS(port_priv->device, status, set_err, - "nodnic_port_set failed"); - port_priv->network_state = value; -set_err: - return status; -} - -#ifdef DEVICE_CX3 -static -mlx_status -nodnic_port_set_dma_connectx3( - IN nodnic_port_priv *port_priv, - IN mlx_boolean value - ) -{ - mlx_utils *utils = port_priv->device->utils; - nodnic_port_data_flow_gw *ptr = port_priv->data_flow_gw; - mlx_uint32 data = (value ? 0xffffffff : 0x0); - mlx_pci_mem_write(utils, MlxPciWidthUint32, 0, - (mlx_uint64)&(ptr->dma_en), 1, &data); - return MLX_SUCCESS; -} -#endif - -static -mlx_status -nodnic_port_set_dma( - IN nodnic_port_priv *port_priv, - IN mlx_boolean value - ) -{ - return nodnic_port_set(port_priv, nodnic_port_option_dma_en, value); -} - -static -mlx_status -nodnic_port_check_and_set_dma( - IN nodnic_port_priv *port_priv, - IN mlx_boolean value - ) -{ - mlx_status status = MLX_SUCCESS; - if ( port_priv->dma_state == value ) { - MLX_DEBUG_WARN(port_priv->device, - "nodnic_port_check_and_set_dma: already %s\n", - (value ? "enabled" : "disabled")); - status = MLX_SUCCESS; - goto set_out; - } - - status = port_priv->set_dma(port_priv, value); - MLX_CHECK_STATUS(port_priv->device, status, set_err, - "nodnic_port_set failed"); - port_priv->dma_state = value; -set_err: -set_out: - return status; -} - - -mlx_status -nodnic_port_set_promisc( - IN nodnic_port_priv *port_priv, - IN mlx_boolean value - ){ - mlx_status status = MLX_SUCCESS; - mlx_uint32 buffer = value; - - status = nodnic_port_set(port_priv, nodnic_port_option_port_promisc_en, buffer); - MLX_CHECK_STATUS(port_priv->device, status, set_err, - "nodnic_port_set failed"); -set_err: - return status; -} - -mlx_status -nodnic_port_set_promisc_multicast( - IN nodnic_port_priv *port_priv, - IN mlx_boolean value - ){ - mlx_status status = MLX_SUCCESS; - mlx_uint32 buffer = value; - - status = nodnic_port_set(port_priv, nodnic_port_option_port_promisc_multicast_en, buffer); - MLX_CHECK_STATUS(port_priv->device, status, set_err, - "nodnic_port_set failed"); -set_err: - return status; -} - -mlx_status -nodnic_port_init( - IN nodnic_port_priv *port_priv - ) -{ - mlx_status status = MLX_SUCCESS; - - if( port_priv == NULL ){ - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - - status = nodnic_port_set_network(port_priv, TRUE); - MLX_FATAL_CHECK_STATUS(status, set_err, - "nodnic_port_set_network failed"); -set_err: -bad_param: - return status; -} - -mlx_status -nodnic_port_close( - IN nodnic_port_priv *port_priv - ) -{ - mlx_status status = MLX_SUCCESS; - - if( port_priv == NULL ){ - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - - status = nodnic_port_set_network(port_priv, FALSE); - MLX_FATAL_CHECK_STATUS(status, set_err, - "nodnic_port_set_network failed"); -set_err: -bad_param: - return status; -} - -mlx_status -nodnic_port_enable_dma( - IN nodnic_port_priv *port_priv - ) -{ - mlx_status status = MLX_SUCCESS; - - if( port_priv == NULL ){ - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - - status = nodnic_port_check_and_set_dma(port_priv, TRUE); - MLX_CHECK_STATUS(port_priv->device, status, set_err, - "nodnic_port_check_and_set_dma failed"); -set_err: -bad_param: - return status; -} - -mlx_status -nodnic_port_disable_dma( - IN nodnic_port_priv *port_priv - ) -{ - mlx_status status = MLX_SUCCESS; - - if( port_priv == NULL ){ - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - - status = nodnic_port_check_and_set_dma(port_priv, FALSE); - MLX_CHECK_STATUS(port_priv->device, status, set_err, - "nodnic_port_check_and_set_dma failed"); -set_err: -bad_param: - return status; -} - -mlx_status -nodnic_port_thin_init( - IN nodnic_device_priv *device_priv, - IN nodnic_port_priv *port_priv, - IN mlx_uint8 port_index - ) -{ - mlx_status status = MLX_SUCCESS; - mlx_boolean reset_needed = 0; -#ifdef DEVICE_CX3 - mlx_uint32 offset; -#endif - - if( device_priv == NULL || port_priv == NULL || port_index > 1){ - status = MLX_INVALID_PARAMETER; - goto invalid_parm; - } - - port_priv->device = device_priv; - - port_priv->port_offset = device_priv->device_offset + - nodnic_port_offset_table[port_index]; - - port_priv->port_num = port_index + 1; - - port_priv->send_doorbell = nodnic_port_update_ring_doorbell; - port_priv->recv_doorbell = nodnic_port_update_ring_doorbell; - port_priv->set_dma = nodnic_port_set_dma; -#ifdef DEVICE_CX3 - if (device_priv->device_cap.crspace_doorbells) { - status = nodnic_cmd_read(device_priv, (port_priv->port_offset + 0x100), - &offset); - if (status != MLX_SUCCESS) { - return status; - } else { - port_priv->data_flow_gw = (nodnic_port_data_flow_gw *) - (device_priv->utils->config + offset); - } - if ( nodnic_port_set ( port_priv, nodnic_port_option_crspace_en, 1 ) ) { - return MLX_FAILED; - } - port_priv->send_doorbell = nodnic_port_send_db_connectx3; - port_priv->recv_doorbell = nodnic_port_recv_db_connectx3; - port_priv->set_dma = nodnic_port_set_dma_connectx3; - } -#endif - /* clear reset_needed */ - nodnic_port_read_reset_needed(port_priv, &reset_needed); - - port_priv->port_type = NODNIC_PORT_TYPE_UNKNOWN; -invalid_parm: - return status; -} diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils/include/private/mlx_memory_priv.h b/roms/ipxe/src/drivers/infiniband/mlx_utils/include/private/mlx_memory_priv.h deleted file mode 100644 index 1f8ba89ea..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils/include/private/mlx_memory_priv.h +++ /dev/null @@ -1,113 +0,0 @@ -#ifndef MLXUTILS_INCLUDE_PRIVATE_MEMORYPRIV_H_ -#define MLXUTILS_INCLUDE_PRIVATE_MEMORYPRIV_H_ - -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include "../../../mlx_utils/include/public/mlx_utils.h" - -mlx_status -mlx_memory_alloc_priv( - IN mlx_utils *utils, - IN mlx_size size, - OUT mlx_void **ptr - ); - -mlx_status -mlx_memory_zalloc_priv( - IN mlx_utils *utils, - IN mlx_size size, - OUT mlx_void **ptr - ); - -mlx_status -mlx_memory_free_priv( - IN mlx_utils *utils, - IN mlx_void *ptr - ); -mlx_status -mlx_memory_alloc_dma_priv( - IN mlx_utils *utils, - IN mlx_size size , - IN mlx_size align, - OUT mlx_void **ptr - ); - -mlx_status -mlx_memory_free_dma_priv( - IN mlx_utils *utils, - IN mlx_size size , - IN mlx_void *ptr - ); -mlx_status -mlx_memory_map_dma_priv( - IN mlx_utils *utils, - IN mlx_void *addr , - IN mlx_size number_of_bytes, - OUT mlx_physical_address *phys_addr, - OUT mlx_void **mapping - ); - -mlx_status -mlx_memory_ummap_dma_priv( - IN mlx_utils *utils, - IN mlx_void *mapping - ); - -mlx_status -mlx_memory_cmp_priv( - IN mlx_utils *utils, - IN mlx_void *first_block, - IN mlx_void *second_block, - IN mlx_size size, - OUT mlx_uint32 *out - ); - -mlx_status -mlx_memory_set_priv( - IN mlx_utils *utils, - IN mlx_void *block, - IN mlx_int32 value, - IN mlx_size size - ); - -mlx_status -mlx_memory_cpy_priv( - IN mlx_utils *utils, - OUT mlx_void *destination_buffer, - IN mlx_void *source_buffer, - IN mlx_size length - ); - -mlx_status -mlx_memory_cpu_to_be32_priv( - IN mlx_utils *utils, - IN mlx_uint32 source, - IN mlx_uint32 *destination - ); - -mlx_status -mlx_memory_be32_to_cpu_priv( - IN mlx_utils *utils, - IN mlx_uint32 source, - IN mlx_uint32 *destination - ); -#endif /* STUB_MLXUTILS_INCLUDE_PRIVATE_MEMORYPRIV_H_ */ diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils/include/private/mlx_pci_priv.h b/roms/ipxe/src/drivers/infiniband/mlx_utils/include/private/mlx_pci_priv.h deleted file mode 100644 index 89cad75eb..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils/include/private/mlx_pci_priv.h +++ /dev/null @@ -1,72 +0,0 @@ -#ifndef STUB_MLXUTILS_INCLUDE_PRIVATE_PCIPRIV_H_ -#define STUB_MLXUTILS_INCLUDE_PRIVATE_PCIPRIV_H_ - -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include "../../include/public/mlx_pci.h" -#include "../../include/public/mlx_utils.h" - -mlx_status -mlx_pci_init_priv( - IN mlx_utils *utils - ); - -mlx_status -mlx_pci_read_priv( - IN mlx_utils *utils, - IN mlx_pci_width width, - IN mlx_uint32 offset, - IN mlx_uintn count, - OUT mlx_void *buffer - ); - -mlx_status -mlx_pci_write_priv( - IN mlx_utils *utils, - IN mlx_pci_width width, - IN mlx_uint32 offset, - IN mlx_uintn count, - IN mlx_void *buffer - ); - -mlx_status -mlx_pci_mem_read_priv( - IN mlx_utils *utils, - IN mlx_pci_width width, - IN mlx_uint8 bar_index, - IN mlx_uint64 offset, - IN mlx_uintn count, - OUT mlx_void *buffer - ); - -mlx_status -mlx_pci_mem_write_priv( - IN mlx_utils *utils, - IN mlx_pci_width width, - IN mlx_uint8 bar_index, - IN mlx_uint64 offset, - IN mlx_uintn count, - IN mlx_void *buffer - ); - - -#endif /* STUB_MLXUTILS_INCLUDE_PRIVATE_PCIPRIV_H_ */ diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils/include/private/mlx_utils_priv.h b/roms/ipxe/src/drivers/infiniband/mlx_utils/include/private/mlx_utils_priv.h deleted file mode 100644 index 268b76fad..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils/include/private/mlx_utils_priv.h +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef SRC_DRIVERS_INFINIBAND_MLX_UTILS_INCLUDE_PRIVATE_MLX_UTILS_PRIV_H_ -#define SRC_DRIVERS_INFINIBAND_MLX_UTILS_INCLUDE_PRIVATE_MLX_UTILS_PRIV_H_ - -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include "../../include/public/mlx_utils.h" - -mlx_status -mlx_utils_delay_in_ms_priv( - IN mlx_uint32 msecs - ); - -mlx_status -mlx_utils_delay_in_us_priv( - IN mlx_uint32 usecs - ); - -mlx_status -mlx_utils_ilog2_priv( - IN mlx_uint32 i, - OUT mlx_uint32 *log - ); - -mlx_status -mlx_utils_init_lock_priv( - OUT void **lock - ); - -mlx_status -mlx_utils_free_lock_priv( - IN void *lock - ); - -mlx_status -mlx_utils_acquire_lock_priv ( - IN void *lock - ); - -mlx_status -mlx_utils_release_lock_priv ( - IN void *lock - ); - -mlx_status -mlx_utils_rand_priv ( - IN mlx_utils *utils, - OUT mlx_uint32 *rand_num - ); -#endif /* SRC_DRIVERS_INFINIBAND_MLX_UTILS_INCLUDE_PRIVATE_MLX_UTILS_PRIV_H_ */ diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils/include/public/mlx_bail.h b/roms/ipxe/src/drivers/infiniband/mlx_utils/include/public/mlx_bail.h deleted file mode 100644 index a4f4b37b1..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils/include/public/mlx_bail.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef INCLUDE_PUBLIC_MLXBAIL_H_ -#define INCLUDE_PUBLIC_MLXBAIL_H_ - -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include "mlx_types.h" - -#define MLX_BAIL_ERROR(id, status,message) MLX_CHECK_STATUS(id, status, bail, message) - -#define MLX_FATAL_CHECK_STATUS(status, label, message) \ - do { \ - if (status != MLX_SUCCESS) { \ - MLX_DEBUG_FATAL_ERROR(message " (Status = %d)\n", status); \ - goto label; \ - } \ - } while (0) - -#define MLX_CHECK_STATUS(id, status, label, message) \ - do { \ - if (status != MLX_SUCCESS) { \ - MLX_DEBUG_ERROR(id, message " (Status = %d)\n", status);\ - goto label; \ - } \ - } while (0) - - - -#endif /* INCLUDE_PUBLIC_MLXBAIL_H_ */ diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils/include/public/mlx_icmd.h b/roms/ipxe/src/drivers/infiniband/mlx_utils/include/public/mlx_icmd.h deleted file mode 100644 index 1ed423daf..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils/include/public/mlx_icmd.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef MLXUTILS_INCLUDE_PUBLIC_MLX_ICMD_H_ -#define MLXUTILS_INCLUDE_PUBLIC_MLX_ICMD_H_ -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include "mlx_utils.h" - -#define MLX_ICMD_MB_ADDR 0x100000 -#define MLX_ICMD_MB_SIZE_ADDR 0x1000 -#define MLX_ICMD_CTRL_ADDR 0x0 - -#define MLX_ICMD_SEMAPHORE_ADDR 0x0 - -#define MLX_ICMD_SEMAPHORE_ID 1234 - -enum { - FLASH_REG_ACCESS = 0x9001, - GET_FW_INFO = 0x8007, - QUERY_VIRTUAL_MAC = 0x9003, - SET_VIRTUAL_MAC = 0x9004, - QUERY_WOL_ROL = 0x9005, - SET_WOL_ROL = 0x9006, - OCBB_INIT = 0x9007, - OCBB_QUERY_HEADER_STATUS = 0x9008, - OCBB_QUERY_ETOC_STATUS = 0x9009, - OCBB_QUERY_SET_EVENT = 0x900A, - OCSD_INIT = 0xf004, -}; - -struct mlx_icmd_ocsd { - mlx_uint32 reserved; - mlx_uint64 address; -}; - -mlx_status -mlx_icmd_send_command( - IN mlx_utils *utils, - IN mlx_uint16 opcode, - IN OUT mlx_void* data, - IN mlx_uint32 write_data_size, - IN mlx_uint32 read_data_size - ); - -#endif /* MLXUTILS_INCLUDE_PUBLIC_MLX_ICMD_H_ */ diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils/include/public/mlx_logging.h b/roms/ipxe/src/drivers/infiniband/mlx_utils/include/public/mlx_logging.h deleted file mode 100644 index 7b7b852d1..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils/include/public/mlx_logging.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef PUBLIC_INCLUDE_MLX_LOGGER_H_ -#define PUBLIC_INCLUDE_MLX_LOGGER_H_ - -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include "../../../mlx_utils_flexboot/include/mlx_logging_priv.h" - -#define MLX_DEBUG_FATAL_ERROR(...) MLX_DEBUG_FATAL_ERROR_PRIVATE(__VA_ARGS__) -#define MLX_DEBUG_ERROR(...) MLX_DEBUG_ERROR_PRIVATE(__VA_ARGS__) -#define MLX_DEBUG_WARN(...) MLX_DEBUG_WARN_PRIVATE(__VA_ARGS__) -#define MLX_DEBUG_INFO1(...) MLX_DEBUG_INFO1_PRIVATE(__VA_ARGS__) -#define MLX_DEBUG_INFO2(...) MLX_DEBUG_INFO2_PRIVATE(__VA_ARGS__) -#define MLX_DBG_ERROR(...) MLX_DBG_ERROR_PRIVATE(__VA_ARGS__) -#define MLX_DBG_WARN(...) MLX_DBG_WARN_PRIVATE(__VA_ARGS__) -#define MLX_DBG_INFO1(...) MLX_DBG_INFO1_PRIVATE(__VA_ARGS__) -#define MLX_DBG_INFO2(...) MLX_DBG_INFO2_PRIVATE(__VA_ARGS__) - -#define MLX_TRACE_1_START() MLX_DBG_INFO1_PRIVATE("Start\n") -#define MLX_TRACE_1_END() MLX_DBG_INFO1_PRIVATE("End\n") -#define MLX_TRACE_1_END_STATUS(status) MLX_DBG_INFO1_PRIVATE("End (%s=%d)\n", #status,status) -#define MLX_TRACE_2_START() MLX_DBG_INFO2_PRIVATE("Start\n") -#define MLX_TRACE_2_END() MLX_DBG_INFO2_PRIVATE("End\n") -#define MLX_TRACE_2_END_STATUS(status) MLX_DBG_INFO2_PRIVATE("End (%s=%d)\n", #status,status) - - - -#endif /* PUBLIC_INCLUDE_MLX_LOGGER_H_ */ diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils/include/public/mlx_memory.h b/roms/ipxe/src/drivers/infiniband/mlx_utils/include/public/mlx_memory.h deleted file mode 100644 index 056756666..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils/include/public/mlx_memory.h +++ /dev/null @@ -1,115 +0,0 @@ -#ifndef MLXUTILS_INCLUDE_PUBLIC_MEMORY_H_ -#define MLXUTILS_INCLUDE_PUBLIC_MEMORY_H_ - -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include "mlx_utils.h" - - -mlx_status -mlx_memory_alloc( - IN mlx_utils *utils, - IN mlx_size size, - OUT mlx_void **ptr - ); - -mlx_status -mlx_memory_zalloc( - IN mlx_utils *utils, - IN mlx_size size, - OUT mlx_void **ptr - ); - -mlx_status -mlx_memory_free( - IN mlx_utils *utils, - IN mlx_void **ptr - ); -mlx_status -mlx_memory_alloc_dma( - IN mlx_utils *utils, - IN mlx_size size , - IN mlx_size align, - OUT mlx_void **ptr - ); - -mlx_status -mlx_memory_free_dma( - IN mlx_utils *utils, - IN mlx_size size , - IN mlx_void **ptr - ); -mlx_status -mlx_memory_map_dma( - IN mlx_utils *utils, - IN mlx_void *Addr , - IN mlx_size NumberOfBytes, - OUT mlx_physical_address *PhysAddr, - OUT mlx_void **Mapping - ); - -mlx_status -mlx_memory_ummap_dma( - IN mlx_utils *utils, - IN mlx_void *Mapping - ); - -mlx_status -mlx_memory_cmp( - IN mlx_utils *utils, - IN mlx_void *first_block, - IN mlx_void *second_block, - IN mlx_size size, - OUT mlx_uint32 *out - ); - -mlx_status -mlx_memory_set( - IN mlx_utils *utils, - IN mlx_void *block, - IN mlx_int32 value, - IN mlx_size size - ); - -mlx_status -mlx_memory_cpy( - IN mlx_utils *utils, - OUT mlx_void *destination_buffer, - IN mlx_void *source_buffer, - IN mlx_size length - ); - -mlx_status -mlx_memory_cpu_to_be32( - IN mlx_utils *utils, - IN mlx_uint32 source, - IN mlx_uint32 *destination - ); - -mlx_status -mlx_memory_be32_to_cpu( - IN mlx_utils *utils, - IN mlx_uint32 source, - IN mlx_uint32 *destination - ); - -#endif /* STUB_MLXUTILS_INCLUDE_PUBLIC_MEMORY_H_ */ diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils/include/public/mlx_pci.h b/roms/ipxe/src/drivers/infiniband/mlx_utils/include/public/mlx_pci.h deleted file mode 100644 index 416bdb66b..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils/include/public/mlx_pci.h +++ /dev/null @@ -1,78 +0,0 @@ -#ifndef STUB_MLXUTILS_INCLUDE_PUBLIC_PCI_H_ -#define STUB_MLXUTILS_INCLUDE_PUBLIC_PCI_H_ - -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include "mlx_utils.h" - -typedef enum { - MlxPciWidthUint8 = 0, - MlxPciWidthUint16, - MlxPciWidthUint32, - MlxPciWidthUint64, -} mlx_pci_width; - -mlx_status -mlx_pci_init( - IN mlx_utils *utils - ); - -mlx_status -mlx_pci_read( - IN mlx_utils *utils, - IN mlx_pci_width width, - IN mlx_uint32 offset, - IN mlx_uintn count, - OUT mlx_void *buffer - ); - -mlx_status -mlx_pci_write( - IN mlx_utils *utils, - IN mlx_pci_width width, - IN mlx_uint32 offset, - IN mlx_uintn count, - IN mlx_void *buffer - ); - -mlx_status -mlx_pci_mem_read( - IN mlx_utils *utils, - IN mlx_pci_width width, - IN mlx_uint8 bar_index, - IN mlx_uint64 offset, - IN mlx_uintn count, - OUT mlx_void *buffer - ); - -mlx_status -mlx_pci_mem_write( - IN mlx_utils *utils, - IN mlx_pci_width width, - IN mlx_uint8 bar_index, - IN mlx_uint64 offset, - IN mlx_uintn count, - IN mlx_void *buffer - ); - - -#endif /* STUB_MLXUTILS_INCLUDE_PUBLIC_PCI_H_ */ diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils/include/public/mlx_pci_gw.h b/roms/ipxe/src/drivers/infiniband/mlx_utils/include/public/mlx_pci_gw.h deleted file mode 100644 index c074a22e5..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils/include/public/mlx_pci_gw.h +++ /dev/null @@ -1,81 +0,0 @@ -#ifndef INCLUDE_PUBLIC_MLX_PCI_GW_H_ -#define INCLUDE_PUBLIC_MLX_PCI_GW_H_ - -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include "mlx_utils.h" - -#define PCI_GW_FIRST_CAPABILITY_POINTER_OFFSET 0x34 - -#define PCI_GW_CAPABILITY_ID 0x9 - -#define PCI_GW_CAPABILITY_ID_OFFSET 0x0 -#define PCI_GW_CAPABILITY_NEXT_POINTER_OFFSET 0x1 -#define PCI_GW_CAPABILITY_SPACE_OFFSET 0x4 -#define PCI_GW_CAPABILITY_STATUS_OFFSET 0x7 -#define PCI_GW_CAPABILITY_COUNTER_OFFSET 0x8 -#define PCI_GW_CAPABILITY_SEMAPHORE_OFFSET 0xC -#define PCI_GW_CAPABILITY_ADDRESS_OFFSET 0x10 -#define PCI_GW_CAPABILITY_FLAG_OFFSET 0x10 -#define PCI_GW_CAPABILITY_DATA_OFFSET 0x14 - -#define PCI_GW_SEMPHORE_TRIES 3000000 -#define PCI_GW_GET_OWNERSHIP_TRIES 5000 -#define PCI_GW_READ_FLAG_TRIES 3000000 - -#define PCI_GW_WRITE_FLAG 0x80000000 - -#define PCI_GW_SPACE_NODNIC 0x4 -#define PCI_GW_SPACE_ALL_ICMD 0x3 -#define PCI_GW_SPACE_SEMAPHORE 0xa -#define PCI_GW_SPACE_CR0 0x2 - -typedef mlx_uint32 mlx_pci_gw_buffer; - - -mlx_status -mlx_pci_gw_init( - IN mlx_utils *utils - ); -mlx_status -mlx_pci_gw_teardown( - IN mlx_utils *utils - ); -mlx_status -mlx_pci_gw_read( - IN mlx_utils *utils, - IN mlx_pci_gw_space space, - IN mlx_uint32 address, - OUT mlx_pci_gw_buffer *buffer - ); - -mlx_status -mlx_pci_gw_write( - IN mlx_utils *utils, - IN mlx_pci_gw_space space, - IN mlx_uint32 address, - IN mlx_pci_gw_buffer buffer - ); - - - -#endif /* INCLUDE_PUBLIC_MLX_PCI_GW_H_ */ diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils/include/public/mlx_types.h b/roms/ipxe/src/drivers/infiniband/mlx_utils/include/public/mlx_types.h deleted file mode 100644 index 9c66567a3..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils/include/public/mlx_types.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef INCLUDE_PUBLIC_MLXTYPES_H_ -#define INCLUDE_PUBLIC_MLXTYPES_H_ - -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include "../../../mlx_utils_flexboot/include/mlx_types_priv.h" - -#endif /* INCLUDE_PUBLIC_MLXBAIL_H_ */ diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils/include/public/mlx_utils.h b/roms/ipxe/src/drivers/infiniband/mlx_utils/include/public/mlx_utils.h deleted file mode 100644 index 46ad97c3b..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils/include/public/mlx_utils.h +++ /dev/null @@ -1,106 +0,0 @@ -#ifndef MLXUTILS_INCLUDE_PUBLIC_MLXUTILS_H_ -#define MLXUTILS_INCLUDE_PUBLIC_MLXUTILS_H_ - -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include "mlx_logging.h" -#include "mlx_types.h" - -#define IN -#define OUT - -typedef mlx_uint16 mlx_pci_gw_space; - -typedef struct{ - mlx_uint32 pci_cmd_offset; - mlx_pci_gw_space space; -} __attribute__ (( packed )) mlx_pci_gw; - -typedef struct { - mlx_boolean icmd_opened; - mlx_boolean took_semaphore; - mlx_uint32 max_cmd_size; -} __attribute__ (( packed )) mlx_icmd ; - -typedef struct{ - mlx_pci *pci; - mlx_pci_gw pci_gw; - mlx_icmd icmd; - void *lock; -#ifdef DEVICE_CX3 - /* ACCESS to BAR0 */ - void *config; -#endif -} __attribute__ (( packed )) mlx_utils; - -mlx_status -mlx_utils_init( - IN mlx_utils *utils, - IN mlx_pci *pci - ); - -mlx_status -mlx_utils_teardown( - IN mlx_utils *utils - ); -mlx_status -mlx_utils_delay_in_ms( - IN mlx_uint32 msecs - ); - -mlx_status -mlx_utils_delay_in_us( - IN mlx_uint32 usecs - ); - -mlx_status -mlx_utils_ilog2( - IN mlx_uint32 i, - OUT mlx_uint32 *log - ); - -mlx_status -mlx_utils_init_lock( - IN OUT mlx_utils *utils - ); - -mlx_status -mlx_utils_free_lock( - IN OUT mlx_utils *utils - ); - -mlx_status -mlx_utils_acquire_lock ( - IN OUT mlx_utils *utils - ); - -mlx_status -mlx_utils_release_lock ( - IN OUT mlx_utils *utils - ); - -mlx_status -mlx_utils_rand ( - IN mlx_utils *utils, - OUT mlx_uint32 *rand_num - ); -#endif /* STUB_MLXUTILS_INCLUDE_PUBLIC_MLXUTILS_H_ */ diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_blink_leds/mlx_blink_leds.c b/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_blink_leds/mlx_blink_leds.c deleted file mode 100644 index ba56e72f2..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_blink_leds/mlx_blink_leds.c +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include "../../mlx_lib/mlx_blink_leds/mlx_blink_leds.h" -#include "../../include/public/mlx_memory.h" -#include "../../include/public/mlx_bail.h" - -mlx_status -mlx_blink_leds( - IN mlx_utils *utils, - IN mlx_uint16 secs - ) -{ - mlx_status status = MLX_SUCCESS; - struct mlx_led_control led_control; - mlx_uint32 reg_status; - - if (utils == NULL ) { - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - mlx_memory_set(utils, &led_control, 0, sizeof(led_control)); - led_control.beacon_duration = secs; - status = mlx_reg_access(utils, REG_ID_MLCR, REG_ACCESS_WRITE, &led_control, sizeof(led_control), - ®_status); - MLX_CHECK_STATUS(utils, status, reg_err, "mlx_reg_access failed "); - if (reg_status != 0) { - MLX_DEBUG_ERROR(utils,"mlx_reg_access failed with status = %d\n", reg_status); - status = MLX_FAILED; - goto reg_err; - } -reg_err: -bad_param: - return status; -} - diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_blink_leds/mlx_blink_leds.h b/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_blink_leds/mlx_blink_leds.h deleted file mode 100644 index 886645fe2..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_blink_leds/mlx_blink_leds.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef MLX_BLINK_LEDS_H_ -#define MLX_BLINK_LEDS_H_ - -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include "../../mlx_lib/mlx_reg_access/mlx_reg_access.h" -#include "../../include/public/mlx_utils.h" - -struct mlx_led_control { - mlx_uint32 reserved1 :16; - mlx_uint32 port :8; - mlx_uint32 bla :8; -/* -------------- */ - mlx_uint32 beacon_duration :16; - mlx_uint32 reserved2 :16; -/* -------------- */ - mlx_uint32 beacon_remain :16; - mlx_uint32 reserved3 :16; -}; - -mlx_status -mlx_blink_leds( - IN mlx_utils *utils, - IN mlx_uint16 secs - ); - -#endif /* MLX_NVCONFIG_H_ */ diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_link_speed/mlx_link_speed.c b/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_link_speed/mlx_link_speed.c deleted file mode 100644 index d31553024..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_link_speed/mlx_link_speed.c +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include "../../mlx_lib/mlx_link_speed/mlx_link_speed.h" -#include "../../include/public/mlx_memory.h" -#include "../../include/public/mlx_bail.h" - -mlx_status -mlx_set_link_speed( - IN mlx_utils *utils, - IN mlx_uint8 port_num, - IN LINK_SPEED_TYPE type, - IN LINK_SPEED speed - ) -{ - mlx_status status = MLX_SUCCESS; - struct mlx_link_speed link_speed; - mlx_uint32 reg_status; - - if (utils == NULL) { - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - - mlx_memory_set(utils, &link_speed, 0, sizeof(link_speed)); - - link_speed.loacl_port = port_num; - link_speed.proto_mask = 1 << type; - - status = mlx_reg_access(utils, REG_ID_PTYS, REG_ACCESS_READ, &link_speed, - sizeof(link_speed), ®_status); - - MLX_CHECK_STATUS(utils, status, reg_err, "mlx_reg_access failed "); - if (reg_status != 0) { - MLX_DEBUG_ERROR(utils,"mlx_reg_access failed with status = %d\n", reg_status); - status = MLX_FAILED; - goto reg_err; - } - switch (speed) { - case LINK_SPEED_1GB: - link_speed.eth_proto_admin = link_speed.eth_proto_capability & LINK_SPEED_1GB_MASK; - break; - case LINK_SPEED_10GB: - link_speed.eth_proto_admin = link_speed.eth_proto_capability & LINK_SPEED_10GB_MASK; - break; - case LINK_SPEED_40GB: - link_speed.eth_proto_admin = link_speed.eth_proto_capability & LINK_SPEED_40GB_MASK; - break; - case LINK_SPEED_100GB: - link_speed.eth_proto_admin = link_speed.eth_proto_capability & LINK_SPEED_100GB_MASK; - break; - case LINK_SPEED_SDR: - link_speed.ib_proto_admin = link_speed.ib_proto_capability & LINK_SPEED_SDR_MASK; - break; - case LINK_SPEED_DEFAULT: - if (type == LINK_SPEED_ETH) { - link_speed.eth_proto_admin = link_speed.eth_proto_capability; - } else { - link_speed.ib_proto_admin = link_speed.ib_proto_capability; - } - break; - } - status = mlx_reg_access(utils, REG_ID_PTYS, REG_ACCESS_WRITE, &link_speed, - sizeof(link_speed), ®_status); - MLX_CHECK_STATUS(utils, status, reg_err, "mlx_reg_access failed "); - if (reg_status != 0) { - MLX_DEBUG_ERROR(utils,"mlx_reg_access failed with status = %d\n", reg_status); - status = MLX_FAILED; - goto reg_err; - } -reg_err: -bad_param: - return status; -} - -mlx_status -mlx_get_max_speed( - IN mlx_utils *utils, - IN mlx_uint8 port_num, - IN LINK_SPEED_TYPE type, - OUT mlx_uint64 *speed - ) -{ - mlx_status status = MLX_SUCCESS; - struct mlx_link_speed link_speed; - mlx_uint32 reg_status; - mlx_uint64 speed_giga = 0; - mlx_uint8 lanes_number = 1; - - *speed = 0; - if (utils == NULL) { - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - - mlx_memory_set(utils, &link_speed, 0, sizeof(link_speed)); - - link_speed.loacl_port = port_num; - link_speed.proto_mask = 1 << type; - - status = mlx_reg_access(utils, REG_ID_PTYS, REG_ACCESS_READ, &link_speed, - sizeof(link_speed), ®_status); - MLX_CHECK_STATUS(utils, status, reg_err, "mlx_reg_access failed "); - if (reg_status != 0) { - MLX_DEBUG_ERROR(utils,"mlx_reg_access failed with status = %d\n", reg_status); - status = MLX_FAILED; - goto reg_err; - } - - if ( type == LINK_SPEED_ETH ) { - if ( link_speed.eth_proto_capability & LINK_SPEED_100GB_MASK ) { - speed_giga = 100; - } else if ( link_speed.eth_proto_capability & LINK_SPEED_56GB_MASK ) { - speed_giga = 56; - } else if ( link_speed.eth_proto_capability & LINK_SPEED_50GB_MASK ) { - speed_giga = 50; - } else if ( link_speed.eth_proto_capability & LINK_SPEED_40GB_MASK ) { - speed_giga = 40; - } else if (link_speed.eth_proto_capability & LINK_SPEED_25GB_MASK) { - speed_giga = 25; - } else if ( link_speed.eth_proto_capability & LINK_SPEED_20GB_MASK ) { - speed_giga = 20; - } else if ( link_speed.eth_proto_capability & LINK_SPEED_10GB_MASK) { - speed_giga = 10; - } else if ( link_speed.eth_proto_capability & LINK_SPEED_1GB_MASK ) { - speed_giga = 1; - } - } else { - if ( link_speed.ib_proto_capability & LINK_SPEED_EDR_MASK ) { - speed_giga = 25; - } else if ( link_speed.ib_proto_capability & LINK_SPEED_EDR20_MASK ) { - speed_giga = 20; - } else if ( link_speed.ib_proto_capability & LINK_SPEED_FDR_MASK ) { - speed_giga = 14; - } else if ( link_speed.ib_proto_capability & LINK_SPEED_QDR_MASK ) { - speed_giga = 10; - } else if ( link_speed.ib_proto_capability & LINK_SPEED_DDR_MASK ) { - speed_giga = 5; - } else if ( link_speed.ib_proto_capability & LINK_SPEED_SDR_MASK ) { - speed_giga = 2.5; - } - if ( link_speed.ib_link_width_capability & LINK_SPEED_WITDH_12_MASK ) { - lanes_number = 12; - } else if ( link_speed.ib_link_width_capability & LINK_SPEED_WITDH_8_MASK ) { - lanes_number = 8; - } else if (link_speed.ib_link_width_capability & LINK_SPEED_WITDH_4_MASK ) { - lanes_number = 4; - } else if (link_speed.ib_link_width_capability & LINK_SPEED_WITDH_2_MASK ) { - lanes_number = 2; - } else if (link_speed.ib_link_width_capability & LINK_SPEED_WITDH_1_MASK ) { - lanes_number = 1; - } - speed_giga = speed_giga * lanes_number; - } - // Return data in bits - *speed = speed_giga * GIGA_TO_BIT; -reg_err: -bad_param: - return status; -} - - diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_link_speed/mlx_link_speed.h b/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_link_speed/mlx_link_speed.h deleted file mode 100644 index 15b28f57a..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_link_speed/mlx_link_speed.h +++ /dev/null @@ -1,145 +0,0 @@ -#ifndef MLX_LINK_SPEED_H_ -#define MLX_LINK_SPEED_H_ - -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include "../../mlx_lib/mlx_reg_access/mlx_reg_access.h" -#include "../../include/public/mlx_utils.h" - -#define LINK_SPEED_100GB_MASK (ETH_SPEED_ENABLE_MASK_100GBASECR4 | ETH_SPEED_ENABLE_MASK_100GBASESR4 | ETH_SPEED_ENABLE_MASK_100GBASEKR4 | ETH_SPEED_ENABLE_MASK_100GBASELR4) -#define LINK_SPEED_56GB_MASK (ETH_SPEED_ENABLE_MASK_56GBASER4) -#define LINK_SPEED_50GB_MASK (ETH_SPEED_ENABLE_MASK_50GBASECR2 | ETH_SPEED_ENABLE_MASK_50GBASEKR2) -#define LINK_SPEED_40GB_MASK (ETH_SPEED_ENABLE_MASK_40GBASECR4 | ETH_SPEED_ENABLE_MASK_40GBASEKR4 | ETH_SPEED_ENABLE_MASK_40GBASESR4 | ETH_SPEED_ENABLE_MASK_40GBASELR4) -#define LINK_SPEED_25GB_MASK (ETH_SPEED_ENABLE_MASK_25GBASECR | ETH_SPEED_ENABLE_MASK_25GBASEKR | ETH_SPEED_ENABLE_MASK_25GBASESR) -#define LINK_SPEED_20GB_MASK (ETH_SPEED_ENABLE_MASK_20GBASER2) -#define LINK_SPEED_10GB_MASK (ETH_SPEED_ENABLE_MASK_10GBASECR | ETH_SPEED_ENABLE_MASK_10GBASESR | ETH_SPEED_ENABLE_MASK_10GBASELR | ETH_SPEED_ENABLE_MASK_10GBASEKR) -#define LINK_SPEED_1GB_MASK (ETH_SPEED_ENABLE_MASK_1000BASECX | ETH_SPEED_ENABLE_MASK_1000BASEKX | ETH_SPEED_ENABLE_MASK_100BaseTX | ETH_SPEED_ENABLE_MASK_1000BASET) - -#define LINK_SPEED_SDR_MASK 0x1 -#define LINK_SPEED_DDR_MASK 0x2 -#define LINK_SPEED_QDR_MASK 0xC -#define LINK_SPEED_FDR_MASK 0x10 -#define LINK_SPEED_EDR20_MASK 0x200 -#define LINK_SPEED_EDR_MASK 0x20 - -#define LINK_SPEED_WITDH_1_MASK 0x1 -#define LINK_SPEED_WITDH_2_MASK 0x2 -#define LINK_SPEED_WITDH_4_MASK 0x4 -#define LINK_SPEED_WITDH_8_MASK 0x8 -#define LINK_SPEED_WITDH_12_MASK 0x10 - -#define GIGA_TO_BIT 0x40000000 - -enum { - ETH_SPEED_ENABLE_MASK_1000BASECX = 0x0001, - ETH_SPEED_ENABLE_MASK_1000BASEKX = 0x0002, - ETH_SPEED_ENABLE_MASK_10GBASECX4 = 0x0004, - ETH_SPEED_ENABLE_MASK_10GBASEKX4 = 0x0008, - ETH_SPEED_ENABLE_MASK_10GBASEKR = 0x0010, - ETH_SPEED_ENABLE_MASK_20GBASER2 = 0x0020, - ETH_SPEED_ENABLE_MASK_40GBASECR4 = 0x0040, - ETH_SPEED_ENABLE_MASK_40GBASEKR4 = 0x0080, - ETH_SPEED_ENABLE_MASK_56GBASER4 = 0x0100, - ETH_SPEED_ENABLE_MASK_10GBASECR = 0x1000, - ETH_SPEED_ENABLE_MASK_10GBASESR = 0x2000, - ETH_SPEED_ENABLE_MASK_10GBASELR = 0x4000, - ETH_SPEED_ENABLE_MASK_40GBASESR4 = 0x8000, - ETH_SPEED_ENABLE_MASK_40GBASELR4 = 0x10000, - ETH_SPEED_ENABLE_MASK_50GBASEKR4 = 0x80000, - ETH_SPEED_ENABLE_MASK_100GBASECR4 = 0x100000, - ETH_SPEED_ENABLE_MASK_100GBASESR4 = 0x200000, - ETH_SPEED_ENABLE_MASK_100GBASEKR4 = 0x400000, - ETH_SPEED_ENABLE_MASK_100GBASELR4 = 0x800000, - ETH_SPEED_ENABLE_MASK_100BaseTX = 0x1000000, - ETH_SPEED_ENABLE_MASK_1000BASET = 0x2000000, - ETH_SPEED_ENABLE_MASK_10GBASET = 0x4000000, - ETH_SPEED_ENABLE_MASK_25GBASECR = 0x8000000, - ETH_SPEED_ENABLE_MASK_25GBASEKR = 0x10000000, - ETH_SPEED_ENABLE_MASK_25GBASESR = 0x20000000, - ETH_SPEED_ENABLE_MASK_50GBASECR2 = 0x40000000, - ETH_SPEED_ENABLE_MASK_50GBASEKR2 = 0x80000000, - ETH_SPEED_ENABLE_MASK_BAD = 0xffff, -}; - - -typedef enum { - LINK_SPEED_IB = 0, - LINK_SPEED_FC, - LINK_SPEED_ETH, -} LINK_SPEED_TYPE; - -typedef enum { - LINK_SPEED_1GB = 0, - LINK_SPEED_10GB, - LINK_SPEED_40GB, - LINK_SPEED_100GB, - LINK_SPEED_SDR, - LINK_SPEED_DEFAULT, -} LINK_SPEED; - -struct mlx_link_speed { - mlx_uint32 proto_mask :3; - mlx_uint32 reserved1 :13; - mlx_uint32 loacl_port :8; - mlx_uint32 reserved2 :8; - /* -------------- */ - mlx_uint32 reserved3 :32; - /* -------------- */ - mlx_uint32 reserved4 :32; - /* -------------- */ - mlx_uint32 eth_proto_capability :32; - /* -------------- */ - mlx_uint32 ib_proto_capability :16; - mlx_uint32 ib_link_width_capability :16; - /* -------------- */ - mlx_uint32 reserved5 :32; - /* -------------- */ - mlx_uint32 eth_proto_admin :32; - /* -------------- */ - mlx_uint32 ib_proto_admin :16; - mlx_uint32 ib_link_width_admin :16; - /* -------------- */ - mlx_uint32 reserved6 :32; - /* -------------- */ - mlx_uint32 eth_proto_oper :32; - /* -------------- */ - mlx_uint32 ib_proto_oper :16; - mlx_uint32 ib_link_width_oper :16; -}; - -mlx_status -mlx_set_link_speed( - IN mlx_utils *utils, - IN mlx_uint8 port_num, - IN LINK_SPEED_TYPE type, - IN LINK_SPEED speed - ); - -mlx_status -mlx_get_max_speed( - IN mlx_utils *utils, - IN mlx_uint8 port_num, - IN LINK_SPEED_TYPE type, - OUT mlx_uint64 *speed - ); - -#endif /* MLX_LINK_SPEED_H_ */ diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_mtu/mlx_mtu.c b/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_mtu/mlx_mtu.c deleted file mode 100644 index 755730284..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_mtu/mlx_mtu.c +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include "mlx_mtu.h" -#include "mlx_memory.h" -#include "mlx_bail.h" - -mlx_status -mlx_get_max_mtu( - IN mlx_utils *utils, - IN mlx_uint8 port_num, - OUT mlx_uint32 *max_mtu - ) -{ - mlx_status status = MLX_SUCCESS; - struct mlx_mtu mtu; - mlx_uint32 reg_status; - *max_mtu = 0; - - if (utils == NULL) { - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - - mlx_memory_set(utils, &mtu, 0, sizeof(mtu)); - - mtu.local_port = port_num; - - status = mlx_reg_access(utils, REG_ID_PMTU, REG_ACCESS_READ, &mtu, - sizeof(mtu), ®_status); - MLX_CHECK_STATUS(utils, status, reg_err, "mlx_reg_access failed "); - if (reg_status != 0) { - MLX_DEBUG_ERROR(utils,"mlx_reg_access failed with status = %d\n", reg_status); - status = MLX_FAILED; - goto reg_err; - } - // Return data in bits - *max_mtu = mtu.max_mtu * BYTE_TO_BIT; -reg_err: -bad_param: - return status; -} diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_mtu/mlx_mtu.h b/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_mtu/mlx_mtu.h deleted file mode 100644 index c6222625c..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_mtu/mlx_mtu.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef MLX_MTU_H_ -#define MLX_MTU_H_ - -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include "mlx_reg_access.h" -#include "mlx_utils.h" - -#define BYTE_TO_BIT 0x8 - -struct mlx_mtu { - mlx_uint32 reserved1 :16; - mlx_uint32 local_port :8; - mlx_uint32 reserved2 :8; - /* -------------- */ - mlx_uint32 reserved3 :16; - mlx_uint32 max_mtu :16; - /* -------------- */ - mlx_uint32 reserved4 :16; - mlx_uint32 admin_mtu :16; - /* -------------- */ - mlx_uint32 reserved5 :16; - mlx_uint32 oper_mtu :16; -}; - -mlx_status -mlx_get_max_mtu( - IN mlx_utils *utils, - IN mlx_uint8 port_num, - OUT mlx_uint32 *max_mtu - ); - -#endif /* MLX_MTU_H_ */ diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_nvconfig/mlx_nvconfig.c b/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_nvconfig/mlx_nvconfig.c deleted file mode 100644 index 2277e0c76..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_nvconfig/mlx_nvconfig.c +++ /dev/null @@ -1,295 +0,0 @@ -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include "../../mlx_lib/mlx_nvconfig/mlx_nvconfig.h" -#include "../../include/public/mlx_memory.h" -#include "../../include/public/mlx_bail.h" - -#define TlvMappingEntry( _tlv_type, _real_tlv_type, _class_code, _fw_reset_needed) { \ - .tlv_type = _tlv_type, \ - .real_tlv_type = _real_tlv_type, \ - .class_code = _class_code, \ - .fw_reset_needed = _fw_reset_needed, \ - } - -struct nvconfig_tlv_mapping nvconfig_tlv_mapping[] = { - TlvMappingEntry(0x10, 0x10, NVRAM_TLV_CLASS_HOST, TRUE), - TlvMappingEntry(0x12, 0x12, NVRAM_TLV_CLASS_PHYSICAL_PORT, TRUE), - TlvMappingEntry(0x80, 0x80, NVRAM_TLV_CLASS_GLOBAL, TRUE), - TlvMappingEntry(0x81, 0x81, NVRAM_TLV_CLASS_GLOBAL, TRUE), - TlvMappingEntry(0x100, 0x100, NVRAM_TLV_CLASS_GLOBAL, TRUE), - TlvMappingEntry(0x2001, 0x195, NVRAM_TLV_CLASS_HOST, FALSE), - TlvMappingEntry(0x2010, 0x210, NVRAM_TLV_CLASS_HOST, FALSE), - TlvMappingEntry(0x2011, 0x211, NVRAM_TLV_CLASS_GLOBAL, FALSE), - TlvMappingEntry(0x2020, 0x2020, NVRAM_TLV_CLASS_PHYSICAL_PORT, FALSE), - TlvMappingEntry(0x2021, 0x221, NVRAM_TLV_CLASS_HOST, FALSE), - TlvMappingEntry(0x2023, 0x223, NVRAM_TLV_CLASS_HOST, FALSE), - TlvMappingEntry(0x2100, 0x230, NVRAM_TLV_CLASS_HOST, FALSE), - TlvMappingEntry(0x2101, 0x231, NVRAM_TLV_CLASS_HOST, FALSE), - TlvMappingEntry(0x2102, 0x232, NVRAM_TLV_CLASS_HOST, FALSE), - TlvMappingEntry(0x2103, 0x233, NVRAM_TLV_CLASS_HOST, FALSE), - TlvMappingEntry(0x2104, 0x234, NVRAM_TLV_CLASS_HOST, FALSE), - TlvMappingEntry(0x2105, 0x235, NVRAM_TLV_CLASS_HOST, FALSE), - TlvMappingEntry(0x2106, 0x236, NVRAM_TLV_CLASS_HOST, FALSE), - TlvMappingEntry(0x2107, 0x237, NVRAM_TLV_CLASS_HOST, FALSE), - TlvMappingEntry(0x2108, 0x238, NVRAM_TLV_CLASS_HOST, FALSE), - TlvMappingEntry(0x2109, 0x239, NVRAM_TLV_CLASS_HOST, FALSE), - TlvMappingEntry(0x210A, 0x23A, NVRAM_TLV_CLASS_HOST, FALSE), - TlvMappingEntry(0x2200, 0x240, NVRAM_TLV_CLASS_HOST, FALSE), - TlvMappingEntry(0x2201, 0x241, NVRAM_TLV_CLASS_HOST, FALSE), - TlvMappingEntry(0x2202, 0x242, NVRAM_TLV_CLASS_HOST, FALSE), - TlvMappingEntry(0x2203, 0x243, NVRAM_TLV_CLASS_HOST, FALSE), - TlvMappingEntry(0x2204, 0x244, NVRAM_TLV_CLASS_HOST, FALSE), - TlvMappingEntry(0x2205, 0x245, NVRAM_TLV_CLASS_HOST, FALSE), - TlvMappingEntry(0x2207, 0x247, NVRAM_TLV_CLASS_HOST, FALSE), - TlvMappingEntry(0, 0, 0, 0), -}; - -static -mlx_status -nvconfig_set_fw_reset_level( - IN mlx_utils *utils, - IN mlx_uint16 tlv_type - ) -{ -#define WARM_REBOOT_RESET ((mlx_uint64)0x1 << 38) - mlx_status status = MLX_SUCCESS; - mlx_uint32 reg_status; - mlx_uint64 mfrl = WARM_REBOOT_RESET ; - mlx_uint8 index = 0; - mlx_boolean reset_needed = FALSE; - - for (index = 0 ; nvconfig_tlv_mapping[index].tlv_type != 0 ; index++) { - if (nvconfig_tlv_mapping[index].tlv_type == tlv_type) { - reset_needed = nvconfig_tlv_mapping[index].fw_reset_needed; - } - } - - if (reset_needed == FALSE) { - goto no_fw_reset_needed; - } - status = mlx_reg_access(utils, REG_ID_MFRL, REG_ACCESS_WRITE, &mfrl, sizeof(mfrl), - ®_status); - MLX_CHECK_STATUS(utils, status, reg_err, "mlx_reg_access failed "); - - if (reg_status != 0) { - MLX_DEBUG_ERROR(utils,"nvconfig_set_fw_reset_level failed with status = %d\n", reg_status); - status = MLX_FAILED; - goto reg_err; - } -reg_err: -no_fw_reset_needed: - return status; -} - - -static -mlx_status -nvconfig_get_tlv_type_and_class( - IN mlx_uint16 tlv_type, - OUT mlx_uint16 *real_tlv_type, - OUT NVRAM_CLASS_CODE *class_code - ) -{ - mlx_uint8 index = 0; - for ( ; nvconfig_tlv_mapping[index].tlv_type != 0 ; index ++) { - if ( nvconfig_tlv_mapping[index].tlv_type == tlv_type) { - *real_tlv_type = nvconfig_tlv_mapping[index].real_tlv_type; - *class_code = nvconfig_tlv_mapping[index].class_code; - return MLX_SUCCESS; - } - } - return MLX_NOT_FOUND; -} -static -void -nvconfig_fill_tlv_type( - IN mlx_uint8 port, - IN NVRAM_CLASS_CODE class_code, - IN mlx_uint16 tlv_type, - OUT union nvconfig_tlv_type *nvconfig_tlv_type - ) -{ - switch (class_code) { - case NVRAM_TLV_CLASS_GLOBAL: - nvconfig_tlv_type->global.param_class = NVRAM_TLV_CLASS_GLOBAL; - nvconfig_tlv_type->global.param_idx = tlv_type; - break; - case NVRAM_TLV_CLASS_HOST: - nvconfig_tlv_type->per_host.param_class = NVRAM_TLV_CLASS_HOST; - nvconfig_tlv_type->per_host.param_idx = tlv_type; - break; - case NVRAM_TLV_CLASS_PHYSICAL_PORT: - nvconfig_tlv_type->per_port.param_class = NVRAM_TLV_CLASS_PHYSICAL_PORT; - nvconfig_tlv_type->per_port.param_idx = tlv_type; - nvconfig_tlv_type->per_port.port = port; - break; - } -} -mlx_status -nvconfig_query_capability( - IN mlx_utils *utils, - IN mlx_uint8 port, - IN mlx_uint16 tlv_type, - OUT mlx_boolean *read_supported, - OUT mlx_boolean *write_supported - ) -{ - mlx_status status = MLX_SUCCESS; - struct nvconfig_nvqc nvqc; - mlx_uint32 reg_status; - NVRAM_CLASS_CODE class_code; - mlx_uint16 real_tlv_type; - - if (utils == NULL || read_supported == NULL || write_supported == NULL) { - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - - status = nvconfig_get_tlv_type_and_class(tlv_type, &real_tlv_type, &class_code); - MLX_CHECK_STATUS(utils, status, tlv_not_supported, "tlv not supported"); - - mlx_memory_set(utils, &nvqc, 0, sizeof(nvqc)); - nvconfig_fill_tlv_type(port, class_code, real_tlv_type, &nvqc.tlv_type); - - status = mlx_reg_access(utils, REG_ID_NVQC, REG_ACCESS_READ, &nvqc, sizeof(nvqc), - ®_status); - MLX_CHECK_STATUS(utils, status, reg_err, "mlx_reg_access failed "); - if (reg_status != 0) { - MLX_DEBUG_ERROR(utils,"mlx_reg_access failed with status = %d\n", reg_status); - status = MLX_FAILED; - goto reg_err; - } - *read_supported = nvqc.support_rd; - *write_supported = nvqc.support_wr; -reg_err: -tlv_not_supported: -bad_param: - return status; -} - -mlx_status -nvconfig_nvdata_invalidate( - IN mlx_utils *utils, - IN mlx_uint8 port, - IN mlx_uint16 tlv_type - ) -{ - mlx_status status = MLX_SUCCESS; - struct nvconfig_header nv_header; - mlx_uint32 reg_status; - NVRAM_CLASS_CODE class_code; - mlx_uint16 real_tlv_type; - - if (utils == NULL) { - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - - status = nvconfig_get_tlv_type_and_class(tlv_type, &real_tlv_type, &class_code); - MLX_CHECK_STATUS(utils, status, tlv_not_supported, "tlv not supported"); - - mlx_memory_set(utils, &nv_header, 0, sizeof(nv_header)); - nvconfig_fill_tlv_type(port, class_code, real_tlv_type, &nv_header.tlv_type); - - status = mlx_reg_access(utils, REG_ID_NVDI, REG_ACCESS_WRITE, &nv_header, sizeof(nv_header), - ®_status); - MLX_CHECK_STATUS(utils, status, reg_err, "mlx_reg_access failed "); - if (reg_status != 0) { - MLX_DEBUG_ERROR(utils,"mlx_reg_access failed with status = %d\n", reg_status); - status = MLX_FAILED; - goto reg_err; - } -reg_err: -tlv_not_supported: -bad_param: - return status; -} - -mlx_status -nvconfig_nvdata_access( - IN mlx_utils *utils, - IN mlx_uint8 port, - IN mlx_uint16 tlv_type, - IN REG_ACCESS_OPT opt, - IN mlx_size data_size, - IN NV_DEFAULT_OPT def_en, - IN OUT mlx_uint8 *version, - IN OUT mlx_void *data - ) -{ - mlx_status status = MLX_SUCCESS; - struct nvconfig_nvda nvda; - mlx_uint32 reg_status; - mlx_uint32 real_size_to_read; - mlx_uint32 index; - NVRAM_CLASS_CODE class_code; - mlx_uint16 real_tlv_type; - mlx_size data_size_align_to_dword; - - if (utils == NULL || data == NULL || data_size > NVCONFIG_MAX_TLV_SIZE) { - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - - status = nvconfig_get_tlv_type_and_class(tlv_type, &real_tlv_type, &class_code); - MLX_CHECK_STATUS(utils, status, tlv_not_supported, "tlv not supported"); - - data_size_align_to_dword = ((data_size + 3) / sizeof(mlx_uint32)) * sizeof(mlx_uint32); - mlx_memory_set(utils, &nvda, 0, sizeof(nvda)); - nvda.nv_header.length = data_size_align_to_dword; - nvda.nv_header.rd_en = 0; - nvda.nv_header.def_en = def_en; - nvda.nv_header.over_en = 1; - nvda.nv_header.version = *version; - - nvconfig_fill_tlv_type(port, class_code, real_tlv_type, &nvda.nv_header.tlv_type); - - mlx_memory_cpy(utils, nvda.data, data, data_size); - for (index = 0 ; index * 4 < NVCONFIG_MAX_TLV_SIZE ; index++) { - mlx_memory_be32_to_cpu(utils,(((mlx_uint32 *)nvda.data)[index]), ((mlx_uint32 *)nvda.data) + index); - } - status = mlx_reg_access(utils, REG_ID_NVDA, opt, &nvda, - data_size_align_to_dword + sizeof(nvda.nv_header), ®_status); - MLX_CHECK_STATUS(utils, status, reg_err, "mlx_reg_access failed "); - if (reg_status != 0) { - MLX_DEBUG_ERROR(utils,"mlx_reg_access failed with status = %d\n", reg_status); - status = MLX_FAILED; - goto reg_err; - } - for (index = 0 ; index * 4 < NVCONFIG_MAX_TLV_SIZE ; index++) { - mlx_memory_cpu_to_be32(utils,(((mlx_uint32 *)nvda.data)[index]), ((mlx_uint32 *)nvda.data) + index); - } - if (opt == REG_ACCESS_READ) { - real_size_to_read = (nvda.nv_header.length > data_size) ? data_size : - nvda.nv_header.length; - mlx_memory_cpy(utils, data, nvda.data, real_size_to_read); - *version = nvda.nv_header.version; - } else { - nvconfig_set_fw_reset_level(utils, tlv_type); - } -reg_err: -tlv_not_supported: -bad_param: - return status; -} - - diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_nvconfig/mlx_nvconfig.h b/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_nvconfig/mlx_nvconfig.h deleted file mode 100644 index 8333e8368..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_nvconfig/mlx_nvconfig.h +++ /dev/null @@ -1,140 +0,0 @@ -#ifndef MLX_NVCONFIG_H_ -#define MLX_NVCONFIG_H_ - -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include "../mlx_reg_access/mlx_reg_access.h" -#include "../../include/public/mlx_utils.h" - -typedef enum { - NVRAM_TLV_CLASS_GLOBAL = 0, - NVRAM_TLV_CLASS_PHYSICAL_PORT = 1, - NVRAM_TLV_CLASS_HOST = 3, -} NVRAM_CLASS_CODE; - -struct nvconfig_tlv_type_per_port { - mlx_uint32 param_idx :16; - mlx_uint32 port :8; - mlx_uint32 param_class :8; -}; - -struct nvconfig_tlv_type_per_host { - mlx_uint32 param_idx :10; - mlx_uint32 function :8; - mlx_uint32 host :6; - mlx_uint32 param_class :8; -}; - -struct nvconfig_tlv_type_global { - mlx_uint32 param_idx :24; - mlx_uint32 param_class :8; -}; - -struct nvconfig_tlv_mapping{ - mlx_uint16 tlv_type; - mlx_uint16 real_tlv_type; - NVRAM_CLASS_CODE class_code; - mlx_boolean fw_reset_needed; -}; - -union nvconfig_tlv_type { - struct nvconfig_tlv_type_per_port per_port; - struct nvconfig_tlv_type_per_host per_host; - struct nvconfig_tlv_type_global global; -}; - - -struct nvconfig_nvqc { - union nvconfig_tlv_type tlv_type; -/* -------------- */ - mlx_uint32 support_rd :1; /*the configuration item is supported and can be read */ - mlx_uint32 support_wr :1; /*the configuration item is supported and can be updated */ - mlx_uint32 reserved1 :2; - mlx_uint32 version :4; /*The maximum version of the configuration item currently supported by the firmware. */ - mlx_uint32 reserved2 :24; -}; - - -struct nvconfig_header { - mlx_uint32 length :9; /*Size of configuration item data in bytes between 0..256 */ - mlx_uint32 reserved0 :3; - mlx_uint32 version :4; /* Configuration item version */ - mlx_uint32 reserved1 :7; - - mlx_uint32 def_en :1; /*Choose whether to access the default value or the user-defined value. - 0x0 Read or write the user-defined value. - 0x1 Read the default value (only valid for reads).*/ - - mlx_uint32 rd_en :1; /*enables reading the TLV by lower priorities - 0 - TLV can be read by the subsequent lifecycle priorities. - 1 - TLV cannot be read by the subsequent lifecycle priorities. */ - mlx_uint32 over_en :1; /*enables overwriting the TLV by lower priorities - 0 - Can only be overwritten by the current lifecycle priority - 1 - Allowed to be overwritten by subsequent lifecycle priorities */ - mlx_uint32 header_type :2; - mlx_uint32 priority :2; - mlx_uint32 valid :2; -/* -------------- */ - union nvconfig_tlv_type tlv_type;; -/* -------------- */ - mlx_uint32 crc :16; - mlx_uint32 reserved :16; -}; - -#define NVCONFIG_MAX_TLV_SIZE 256 - -struct nvconfig_nvda { - struct nvconfig_header nv_header; - mlx_uint8 data[NVCONFIG_MAX_TLV_SIZE]; -}; - - -mlx_status -nvconfig_query_capability( - IN mlx_utils *utils, - IN mlx_uint8 port, - IN mlx_uint16 tlv_type, - OUT mlx_boolean *read_supported, - OUT mlx_boolean *write_supported - ); - - -mlx_status -nvconfig_nvdata_invalidate( - IN mlx_utils *utils, - IN mlx_uint8 port, - IN mlx_uint16 tlv_type - ); - -mlx_status -nvconfig_nvdata_access( - IN mlx_utils *utils, - IN mlx_uint8 port, - IN mlx_uint16 tlv_type, - IN REG_ACCESS_OPT opt, - IN mlx_size data_size, - IN NV_DEFAULT_OPT def_en, - IN OUT mlx_uint8 *version, - IN OUT mlx_void *data - ); - -#endif /* MLX_NVCONFIG_H_ */ diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_nvconfig/mlx_nvconfig_defaults.c b/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_nvconfig/mlx_nvconfig_defaults.c deleted file mode 100644 index 77eda8a5c..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_nvconfig/mlx_nvconfig_defaults.c +++ /dev/null @@ -1,482 +0,0 @@ -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE( GPL2_OR_LATER); - -#include "../../mlx_lib/mlx_nvconfig/mlx_nvconfig.h" -#include "../../include/public/mlx_memory.h" -#include "../../include/public/mlx_bail.h" -#include "../../mlx_lib/mlx_nvconfig/mlx_nvconfig_defaults.h" - -struct tlv_default { - mlx_uint16 tlv_type; - mlx_size data_size; - mlx_status (*set_defaults)( IN void *data, IN int status, - OUT void *def_struct); -}; - -#define TlvDefaultEntry( _tlv_type, _data_size, _set_defaults) { \ - .tlv_type = _tlv_type, \ - .data_size = sizeof ( _data_size ), \ - .set_defaults = _set_defaults, \ - } - -static -mlx_status -nvconfig_get_boot_default_conf( - IN void *data, - IN int status, - OUT void *def_struct - ) -{ - union mlx_nvconfig_nic_boot_conf *nic_boot_conf = - (union mlx_nvconfig_nic_boot_conf *) data; - struct mlx_nvconfig_port_conf_defaults *port_conf_def = - (struct mlx_nvconfig_port_conf_defaults *) def_struct; - - /* boot_option_rom_en is deprecated - enabled always */ - port_conf_def->boot_option_rom_en = DEFAULT_OPTION_ROM_EN; - - MLX_CHECK_STATUS(NULL, status, nvdata_access_err, - "TLV not found. Using hard-coded defaults "); - port_conf_def->boot_vlan = nic_boot_conf->vlan_id; - port_conf_def->boot_protocol = nic_boot_conf->legacy_boot_prot; - port_conf_def->boot_retry_count = nic_boot_conf->boot_retry_count; - port_conf_def->boot_vlan_en = nic_boot_conf->en_vlan; - - return MLX_SUCCESS; - -nvdata_access_err: - port_conf_def->boot_vlan = DEFAULT_BOOT_VLAN; - port_conf_def->boot_protocol = DEFAULT_BOOT_PROTOCOL; - - return status; -} - -static -mlx_status -nvconfig_get_boot_ext_default_conf( - IN void *data, - IN int status, - OUT void *def_struct - ) -{ - union mlx_nvconfig_nic_boot_ext_conf *nic_boot_ext_conf = - (union mlx_nvconfig_nic_boot_ext_conf *) data; - struct mlx_nvconfig_port_conf_defaults *port_conf_def = - (struct mlx_nvconfig_port_conf_defaults *) def_struct; - - MLX_CHECK_STATUS(NULL, status, nvdata_access_err, - "TLV not found. Using hard-coded defaults "); - port_conf_def->linkup_timeout = nic_boot_ext_conf->linkup_timeout; - port_conf_def->ip_ver = nic_boot_ext_conf->ip_ver; - - return MLX_SUCCESS; - -nvdata_access_err: - port_conf_def->linkup_timeout = DEFAULT_BOOT_LINK_UP_TO; - port_conf_def->ip_ver = DEFAULT_BOOT_IP_VER; - - return status; -} - -static -mlx_status -nvconfig_get_iscsi_init_dhcp_default_conf( - IN void *data, - IN int status, - OUT void *def_struct - ) -{ - union mlx_nvconfig_iscsi_init_dhcp_conf *iscsi_init_dhcp_conf = - (union mlx_nvconfig_iscsi_init_dhcp_conf *) data; - struct mlx_nvconfig_port_conf_defaults *port_conf_def = - (struct mlx_nvconfig_port_conf_defaults *) def_struct; - - MLX_CHECK_STATUS(NULL, status, nvdata_access_err, - "TLV not found. Using hard-coded defaults "); - port_conf_def->iscsi_dhcp_params_en = iscsi_init_dhcp_conf->dhcp_iscsi_en; - port_conf_def->iscsi_ipv4_dhcp_en = iscsi_init_dhcp_conf->ipv4_dhcp_en; - - return MLX_SUCCESS; - -nvdata_access_err: - port_conf_def->iscsi_dhcp_params_en = DEFAULT_ISCSI_DHCP_PARAM_EN; - port_conf_def->iscsi_ipv4_dhcp_en = DEFAULT_ISCSI_IPV4_DHCP_EN; - - return status; -} - -static -mlx_status -nvconfig_get_ib_boot_default_conf( - IN void *data, - IN int status, - OUT void *def_struct - ) -{ - union mlx_nvconfig_nic_ib_boot_conf *ib_boot_conf = - (union mlx_nvconfig_nic_ib_boot_conf *) data; - struct mlx_nvconfig_port_conf_defaults *port_conf_def = - (struct mlx_nvconfig_port_conf_defaults *) def_struct; - - MLX_CHECK_STATUS(NULL, status, nvdata_access_err, - "nvconfig_nvdata_default_access failed "); - port_conf_def->boot_pkey = ib_boot_conf->boot_pkey; - -nvdata_access_err: - return status; -} - -static -mlx_status -nvconfig_get_wol_default_conf( - IN void *data, - IN int status, - OUT void *def_struct - ) -{ - union mlx_nvconfig_wol_conf *wol_conf = (union mlx_nvconfig_wol_conf *) data; - struct mlx_nvconfig_port_conf_defaults *port_conf_def = - (struct mlx_nvconfig_port_conf_defaults *) def_struct; - - MLX_CHECK_STATUS(NULL, status, nvdata_access_err, - "nvconfig_nvdata_default_access failed "); - port_conf_def->en_wol_magic = wol_conf->en_wol_magic; - -nvdata_access_err: - return status; -} - -static -mlx_status -nvconfig_get_iscsi_gen_default_conf( - IN void *data, - IN int status, - OUT void *def_struct) -{ - union mlx_nvconfig_iscsi_general *iscsi_gen = - (union mlx_nvconfig_iscsi_general *) data; - struct mlx_nvconfig_port_conf_defaults *port_conf_def = - (struct mlx_nvconfig_port_conf_defaults *) def_struct; - - MLX_CHECK_STATUS(NULL, status, nvdata_access_err, - "nvconfig_nvdata_default_access failed "); - port_conf_def->iscsi_boot_to_target = iscsi_gen->boot_to_target; - port_conf_def->iscsi_vlan_en = iscsi_gen->vlan_en; - port_conf_def->iscsi_tcp_timestamps_en = iscsi_gen->tcp_timestamps_en; - port_conf_def->iscsi_chap_mutual_auth_en = iscsi_gen->chap_mutual_auth_en; - port_conf_def->iscsi_chap_auth_en = iscsi_gen->chap_auth_en; - port_conf_def->iscsi_lun_busy_retry_count = iscsi_gen->lun_busy_retry_count; - port_conf_def->iscsi_link_up_delay_time = iscsi_gen->link_up_delay_time; - -nvdata_access_err: - return status; -} - -static -mlx_status -nvconfig_get_ib_dhcp_default_conf( - IN void *data, - IN int status, - OUT void *def_struct - ) -{ - union mlx_nvconfig_ib_dhcp_conf *ib_dhcp = - (union mlx_nvconfig_ib_dhcp_conf *) data; - struct mlx_nvconfig_port_conf_defaults *port_conf_def = - (struct mlx_nvconfig_port_conf_defaults *) def_struct; - - MLX_CHECK_STATUS(NULL, status, nvdata_access_err, - "nvconfig_nvdata_default_access failed "); - port_conf_def->client_identifier = ib_dhcp->client_identifier; - port_conf_def->mac_admin_bit = ib_dhcp->mac_admin_bit; - -nvdata_access_err: - return status; -} - -static -mlx_status -nvconfig_get_ocsd_ocbb_default_conf( IN void *data, - IN int status, OUT void *def_struct) { - union mlx_nvconfig_ocsd_ocbb_conf *ocsd_ocbb = - (union mlx_nvconfig_ocsd_ocbb_conf *) data; - struct mlx_nvconfig_conf_defaults *conf_def = - (struct mlx_nvconfig_conf_defaults *) def_struct; - - MLX_CHECK_STATUS(NULL, status, nvdata_access_err, - "TLV not found. Using hard-coded defaults "); - conf_def->ocsd_ocbb_en = ocsd_ocbb->ocsd_ocbb_en; - - return MLX_SUCCESS; - -nvdata_access_err: - conf_def->ocsd_ocbb_en = DEFAULT_OCSD_OCBB_EN; - - return status; -} - -static -mlx_status -nvconfig_get_vpi_link_default_conf( - IN void *data, - IN int status, - OUT void *def_struct - ) -{ - union mlx_nvconfig_vpi_link_conf *vpi_link = - (union mlx_nvconfig_vpi_link_conf *) data; - struct mlx_nvconfig_port_conf_defaults *port_conf_def = - (struct mlx_nvconfig_port_conf_defaults *) def_struct; - - MLX_CHECK_STATUS(NULL, status, nvdata_access_err, - "nvconfig_nvdata_default_access failed "); - port_conf_def->network_link_type = vpi_link->network_link_type; - port_conf_def->default_link_type = vpi_link->default_link_type; - -nvdata_access_err: - return status; -} - -static -mlx_status -nvconfig_get_rom_banner_to_default_conf( - IN void *data, - IN int status, - OUT void *def_struct - ) -{ - union mlx_nvconfig_rom_banner_timeout_conf *rom_banner_timeout_conf = - (union mlx_nvconfig_rom_banner_timeout_conf *) data; - struct mlx_nvconfig_conf_defaults *conf_def = - (struct mlx_nvconfig_conf_defaults *) def_struct; - - MLX_CHECK_STATUS(NULL, status, nvdata_access_err, - "TLV not found. Using hard-coded defaults "); - conf_def->flexboot_menu_to = rom_banner_timeout_conf->rom_banner_to; - - return MLX_SUCCESS; - -nvdata_access_err: - conf_def->flexboot_menu_to = DEFAULT_FLEXBOOT_MENU_TO; - - return status; -} - -static -mlx_status -nvconfig_get_nv_virt_caps_default_conf( - IN void *data, - IN int status, - OUT void *def_struct - ) -{ - union mlx_nvconfig_virt_caps *nv_virt_caps = - (union mlx_nvconfig_virt_caps *) data; - struct mlx_nvconfig_conf_defaults *conf_def = - (struct mlx_nvconfig_conf_defaults *) def_struct; - - MLX_CHECK_STATUS(NULL, status, nvdata_access_err, - "TLV not found. Using hard-coded defaults "); - conf_def->max_vfs = nv_virt_caps->max_vfs_per_pf; - - return MLX_SUCCESS; - -nvdata_access_err: - conf_def->max_vfs = DEFAULT_MAX_VFS; - - return status; -} - -static -mlx_status -nvconfig_get_nv_virt_default_conf( - IN void *data, - IN int status, - OUT void *def_struct - ) -{ - union mlx_nvconfig_virt_conf *nv_virt_conf = - (union mlx_nvconfig_virt_conf *) data; - struct mlx_nvconfig_conf_defaults *conf_def = - (struct mlx_nvconfig_conf_defaults *) def_struct; - - MLX_CHECK_STATUS(NULL, status, nvdata_access_err, - "nvconfig_nvdata_default_access failed "); - conf_def->total_vfs = nv_virt_conf->num_of_vfs; - conf_def->sriov_en = nv_virt_conf->virt_mode; - -nvdata_access_err: - return status; -} - -static struct tlv_default tlv_port_defaults[] = { - TlvDefaultEntry(BOOT_SETTINGS_TYPE, union mlx_nvconfig_nic_boot_conf, &nvconfig_get_boot_default_conf), - TlvDefaultEntry(BOOT_SETTINGS_EXT_TYPE, union mlx_nvconfig_nic_boot_ext_conf, &nvconfig_get_boot_ext_default_conf), - TlvDefaultEntry(ISCSI_INITIATOR_DHCP_CONF_TYPE, union mlx_nvconfig_iscsi_init_dhcp_conf, &nvconfig_get_iscsi_init_dhcp_default_conf), - TlvDefaultEntry(IB_BOOT_SETTING_TYPE, union mlx_nvconfig_nic_ib_boot_conf, &nvconfig_get_ib_boot_default_conf), - TlvDefaultEntry(WAKE_ON_LAN_TYPE, union mlx_nvconfig_wol_conf, &nvconfig_get_wol_default_conf), - TlvDefaultEntry(ISCSI_GENERAL_SETTINGS_TYPE, union mlx_nvconfig_iscsi_general, &nvconfig_get_iscsi_gen_default_conf), - TlvDefaultEntry(IB_DHCP_SETTINGS_TYPE, union mlx_nvconfig_ib_dhcp_conf, &nvconfig_get_ib_dhcp_default_conf), - TlvDefaultEntry(VPI_LINK_TYPE, union mlx_nvconfig_vpi_link_conf, &nvconfig_get_vpi_link_default_conf), -}; - -static struct tlv_default tlv_general_defaults[] = { - TlvDefaultEntry(BANNER_TO_TYPE, union mlx_nvconfig_rom_banner_timeout_conf, &nvconfig_get_rom_banner_to_default_conf), - TlvDefaultEntry(GLOPAL_PCI_CAPS_TYPE, union mlx_nvconfig_virt_caps, &nvconfig_get_nv_virt_caps_default_conf), - TlvDefaultEntry(GLOPAL_PCI_SETTINGS_TYPE, union mlx_nvconfig_virt_conf, &nvconfig_get_nv_virt_default_conf), - TlvDefaultEntry(OCSD_OCBB_TYPE, union mlx_nvconfig_ocsd_ocbb_conf, &nvconfig_get_ocsd_ocbb_default_conf), -}; - -static -mlx_status -nvconfig_nvdata_default_access( - IN mlx_utils *utils, - IN mlx_uint8 port, - IN mlx_uint16 tlv_type, - IN mlx_size data_size, - OUT mlx_void *data - ) -{ - mlx_status status = MLX_SUCCESS; - mlx_uint32 index; - mlx_uint8 version = 0; - - status = nvconfig_nvdata_access(utils, port, tlv_type, REG_ACCESS_READ, - data_size, TLV_ACCESS_DEFAULT_EN, &version, data); - MLX_CHECK_STATUS(NULL, status, nvdata_access_err, - "nvconfig_nvdata_access failed "); - for (index = 0; index * 4 < data_size; index++) { - mlx_memory_be32_to_cpu(utils, (((mlx_uint32 *) data)[index]), - ((mlx_uint32 *) data) + index); - } - -nvdata_access_err: - return status; -} - -static -mlx_status -nvconfig_nvdata_read_default_value( - IN mlx_utils *utils, - IN mlx_uint8 modifier, - IN struct tlv_default *def, - OUT void *def_struct - ) -{ - mlx_status status = MLX_SUCCESS; - void *data = NULL; - - status = mlx_memory_zalloc(utils, def->data_size,&data); - MLX_CHECK_STATUS(utils, status, memory_err, - "mlx_memory_zalloc failed "); - status = nvconfig_nvdata_default_access(utils, modifier, def->tlv_type, - def->data_size, data); - def->set_defaults(data, status, def_struct); - mlx_memory_free(utils, &data); - -memory_err: - return status; -} - -static -void -nvconfig_nvdata_read_default_values( - IN mlx_utils *utils, - IN mlx_uint8 modifier, - IN struct tlv_default defaults_table[], - IN mlx_uint8 defaults_table_size, - OUT void *def_strct - ) -{ - struct tlv_default *defs; - unsigned int i; - - for (i = 0; i < defaults_table_size; i++) { - defs = &defaults_table[i]; - nvconfig_nvdata_read_default_value(utils, modifier, defs, def_strct); - } -} - -mlx_status -nvconfig_read_port_default_values( - IN mlx_utils *utils, - IN mlx_uint8 port, - OUT struct mlx_nvconfig_port_conf_defaults *port_conf_def - ) -{ - mlx_status status = MLX_SUCCESS; - - if (utils == NULL || port_conf_def == NULL) { - status = MLX_INVALID_PARAMETER; - MLX_DEBUG_ERROR(utils,"bad params."); - goto bad_param; - } - mlx_memory_set(utils, port_conf_def, 0, sizeof(*port_conf_def)); - nvconfig_nvdata_read_default_values(utils, port, tlv_port_defaults, - (sizeof(tlv_port_defaults)/sizeof(tlv_port_defaults[0])), - port_conf_def); - -bad_param: - return status; -} - -mlx_status -nvconfig_read_general_default_values( - IN mlx_utils *utils, - OUT struct mlx_nvconfig_conf_defaults *conf_def - ) -{ - mlx_status status = MLX_SUCCESS; - - if (utils == NULL || conf_def == NULL) { - status = MLX_INVALID_PARAMETER; - MLX_DEBUG_ERROR(utils,"bad params."); - goto bad_param; - } - mlx_memory_set(utils, conf_def, 0, sizeof(*conf_def)); - nvconfig_nvdata_read_default_values(utils, 0, tlv_general_defaults, - (sizeof(tlv_general_defaults)/sizeof(tlv_general_defaults[0])), - conf_def); - -bad_param: - return status; -} - -mlx_status -nvconfig_read_rom_ini_values( - IN mlx_utils *utils, - OUT struct mlx_nvcofnig_romini *rom_ini - ) -{ - mlx_status status = MLX_SUCCESS; - - if (utils == NULL || rom_ini == NULL) { - status = MLX_INVALID_PARAMETER; - MLX_DEBUG_ERROR(utils,"bad params."); - goto bad_param; - } - mlx_memory_set(utils, rom_ini, 0, sizeof(*rom_ini)); - - status = nvconfig_nvdata_default_access(utils, 0, GLOBAL_ROM_INI_TYPE, - sizeof(*rom_ini), rom_ini); -bad_param: - return status; -} diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_nvconfig/mlx_nvconfig_defaults.h b/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_nvconfig/mlx_nvconfig_defaults.h deleted file mode 100644 index 163c2a35f..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_nvconfig/mlx_nvconfig_defaults.h +++ /dev/null @@ -1,94 +0,0 @@ -#ifndef MLX_NVCONFIG_DEFAULTS_H_ -#define MLX_NVCONFIG_DEFAULTS_H_ - -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); -#include "mlx_nvconfig_prm.h" -/* - * Default values - */ -#define DEFAULT_FLEXBOOT_MENU_TO 4 -#define DEFAULT_MAX_VFS 8 -#define DEFAULT_BOOT_PROTOCOL 1 -#define DEFAULT_OPTION_ROM_EN 1 -#define DEFAULT_BOOT_VLAN 1 -#define DEFAULT_ISCSI_DHCP_PARAM_EN 1 -#define DEFAULT_ISCSI_IPV4_DHCP_EN 1 -#define DEFAULT_OCSD_OCBB_EN 1 -#define DEFAULT_BOOT_IP_VER 0 -#define DEFAULT_BOOT_LINK_UP_TO 0 - -struct mlx_nvconfig_port_conf_defaults { - mlx_uint8 pptx; - mlx_uint8 pprx; - mlx_boolean boot_option_rom_en; - mlx_boolean boot_vlan_en; - mlx_uint8 boot_retry_count; - mlx_uint8 boot_protocol; - mlx_uint8 boot_vlan; - mlx_uint8 boot_pkey; - mlx_boolean en_wol_magic; - mlx_uint8 network_link_type; - mlx_uint8 iscsi_boot_to_target; - mlx_boolean iscsi_vlan_en; - mlx_boolean iscsi_tcp_timestamps_en; - mlx_boolean iscsi_chap_mutual_auth_en; - mlx_boolean iscsi_chap_auth_en; - mlx_boolean iscsi_dhcp_params_en; - mlx_boolean iscsi_ipv4_dhcp_en; - mlx_uint8 iscsi_lun_busy_retry_count; - mlx_uint8 iscsi_link_up_delay_time; - mlx_uint8 client_identifier; - mlx_uint8 mac_admin_bit; - mlx_uint8 default_link_type; - mlx_uint8 linkup_timeout; - mlx_uint8 ip_ver; -}; - -struct mlx_nvconfig_conf_defaults { - mlx_uint8 max_vfs; - mlx_uint8 total_vfs; - mlx_uint8 sriov_en; - mlx_uint8 maximum_uar_bar_size; - mlx_uint8 uar_bar_size; - mlx_uint8 flexboot_menu_to; - mlx_boolean ocsd_ocbb_en; -}; - -mlx_status -nvconfig_read_port_default_values( - IN mlx_utils *utils, - IN mlx_uint8 port, - OUT struct mlx_nvconfig_port_conf_defaults *port_conf_def - ); - -mlx_status -nvconfig_read_general_default_values( - IN mlx_utils *utils, - OUT struct mlx_nvconfig_conf_defaults *conf_def - ); - -mlx_status -nvconfig_read_rom_ini_values( - IN mlx_utils *utils, - OUT struct mlx_nvcofnig_romini *rom_ini - ); -#endif /* MLX_NVCONFIG_DEFAULTS_H_ */ diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_nvconfig/mlx_nvconfig_prm.h b/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_nvconfig/mlx_nvconfig_prm.h deleted file mode 100644 index 5b3af1e78..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_nvconfig/mlx_nvconfig_prm.h +++ /dev/null @@ -1,259 +0,0 @@ -#ifndef MLX_NVCONFIG_PRM_H_ -#define MLX_NVCONFIG_PRM_H_ - -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include "../../include/public/mlx_types.h" - -enum { - WAKE_ON_LAN_TYPE = 0x10, - VIRTUALIZATION_TYPE = 0x11, - VPI_LINK_TYPE = 0x12, - BOOT_SETTINGS_EXT_TYPE = 0x2001, - BANNER_TO_TYPE = 0x2010, - OCSD_OCBB_TYPE = 0x2011, - FLOW_CONTROL_TYPE = 0x2020, - BOOT_SETTINGS_TYPE = 0x2021, - ISCSI_GENERAL_SETTINGS_TYPE = 0x2100, - IB_BOOT_SETTING_TYPE = 0x2022, - IB_DHCP_SETTINGS_TYPE = 0x2023, - GLOPAL_PCI_SETTINGS_TYPE = 0x80, - GLOPAL_PCI_CAPS_TYPE = 0x81, - GLOBAL_ROM_INI_TYPE = 0x100, - - // Types for iSCSI strings - DHCP_VEND_ID = 0x2101, - ISCSI_INITIATOR_IPV4_ADDR = 0x2102, - ISCSI_INITIATOR_SUBNET = 0x2103, - ISCSI_INITIATOR_IPV4_GATEWAY = 0x2104, - ISCSI_INITIATOR_IPV4_PRIM_DNS = 0x2105, - ISCSI_INITIATOR_IPV4_SECDNS = 0x2106, - ISCSI_INITIATOR_NAME = 0x2107, - ISCSI_INITIATOR_CHAP_ID = 0x2108, - ISCSI_INITIATOR_CHAP_PWD = 0x2109, - ISCSI_INITIATOR_DHCP_CONF_TYPE = 0x210a, - - CONNECT_FIRST_TGT = 0x2200, - FIRST_TGT_IP_ADDRESS = 0x2201, - FIRST_TGT_TCP_PORT = 0x2202, - FIRST_TGT_BOOT_LUN = 0x2203, - FIRST_TGT_ISCSI_NAME = 0x2204, - FIRST_TGT_CHAP_ID = 0x2205, - FIRST_TGT_CHAP_PWD = 0x2207, -}; - -union mlx_nvconfig_nic_boot_conf { - struct { - mlx_uint32 vlan_id : 12; - mlx_uint32 link_speed : 4; - mlx_uint32 legacy_boot_prot : 8; - mlx_uint32 boot_retry_count : 3; - mlx_uint32 boot_strap_type : 3; - mlx_uint32 en_vlan : 1; - mlx_uint32 en_option_rom : 1; - }; - mlx_uint32 dword; -}; - -union mlx_nvconfig_nic_boot_ext_conf { - struct { - mlx_uint32 linkup_timeout : 8; - mlx_uint32 ip_ver : 2; - mlx_uint32 reserved0 : 22; - }; - mlx_uint32 dword; -}; - -union mlx_nvconfig_rom_banner_timeout_conf { - struct { - mlx_uint32 rom_banner_to : 4; - mlx_uint32 reserved : 28; - }; - mlx_uint32 dword; -}; - -union mlx_nvconfig_virt_conf { - struct { - mlx_uint32 reserved0 :24; - mlx_uint32 pf_bar_size_valid :1; - mlx_uint32 vf_bar_size_valid :1; - mlx_uint32 num_pf_msix_valid :1; - mlx_uint32 num_vf_msix_valid :1; - mlx_uint32 num_pfs_valid :1; - mlx_uint32 fpp_valid :1; - mlx_uint32 full_vf_qos_valid :1; - mlx_uint32 sriov_valid :1; - /*-------------------*/ - mlx_uint32 num_of_vfs :16; - mlx_uint32 num_of_pfs :4; - mlx_uint32 reserved1 :9; - mlx_uint32 fpp_en :1; - mlx_uint32 full_vf_qos :1; - mlx_uint32 virt_mode :1; //sriov_en - /*-------------------*/ - mlx_uint32 log_pf_uar_bar_size :6; - mlx_uint32 log_vf_uar_bar_size :6; - mlx_uint32 num_pf_msix :10; - mlx_uint32 num_vf_msix :10; - }; - mlx_uint32 dword[3]; -}; - -union mlx_nvconfig_virt_caps { - struct { - mlx_uint32 reserved0 :24; - mlx_uint32 max_vfs_per_pf_valid :1; - mlx_uint32 max_total_msix_valid :1; - mlx_uint32 max_total_bar_valid :1; - mlx_uint32 num_pfs_supported :1; - mlx_uint32 num_vf_msix_supported :1; - mlx_uint32 num_pf_msix_supported :1; - mlx_uint32 vf_bar_size_supported :1; - mlx_uint32 pf_bar_size_supported :1; - /*-------------------*/ - mlx_uint32 max_vfs_per_pf :16; - mlx_uint32 max_num_pfs :4; - mlx_uint32 reserved1 :9; - mlx_uint32 fpp_support :1; - mlx_uint32 vf_qos_control_support :1; - mlx_uint32 sriov_support :1; - /*-------------------*/ - mlx_uint32 max_log_pf_uar_bar_size :6; - mlx_uint32 max_log_vf_uar_bar_size :6; - mlx_uint32 max_num_pf_msix :10; - mlx_uint32 max_num_vf_msix :10; - /*-------------------*/ - mlx_uint32 max_total_msix; - /*-------------------*/ - mlx_uint32 max_total_bar; - }; - mlx_uint32 dword[5]; -}; - -union mlx_nvconfig_iscsi_init_dhcp_conf { - struct { - mlx_uint32 reserved0 :30; - mlx_uint32 dhcp_iscsi_en :1; - mlx_uint32 ipv4_dhcp_en :1; - - }; - mlx_uint32 dword; -}; - -union mlx_nvconfig_nic_ib_boot_conf { - struct { - mlx_uint32 boot_pkey : 16; - mlx_uint32 reserved0 : 16; - }; - mlx_uint32 dword; -}; - -union mlx_nvconfig_wol_conf { - struct { - mlx_uint32 reserved0 :9; - mlx_uint32 en_wol_passwd :1; - mlx_uint32 en_wol_magic :1; - mlx_uint32 reserved1 :21; - mlx_uint32 reserved2 :32; - }; - mlx_uint32 dword[2]; -}; - -union mlx_nvconfig_iscsi_general { - struct { - mlx_uint32 reserved0 :22; - mlx_uint32 boot_to_target :2; - mlx_uint32 reserved1 :2; - mlx_uint32 vlan_en :1; - mlx_uint32 tcp_timestamps_en :1; - mlx_uint32 chap_mutual_auth_en :1; - mlx_uint32 chap_auth_en :1; - mlx_uint32 reserved2 :2; - /*-------------------*/ - mlx_uint32 vlan :12; - mlx_uint32 reserved3 :20; - /*-------------------*/ - mlx_uint32 lun_busy_retry_count:8; - mlx_uint32 link_up_delay_time :8; - mlx_uint32 reserved4 :16; - }; - mlx_uint32 dword[3]; -}; - -union mlx_nvconfig_ib_dhcp_conf { - struct { - mlx_uint32 reserved :24; - mlx_uint32 client_identifier :4; - mlx_uint32 mac_admin_bit :4; - }; - mlx_uint32 dword; -}; - -union mlx_nvconfig_ocsd_ocbb_conf { - struct { - mlx_uint32 reserved :31; - mlx_uint32 ocsd_ocbb_en :1; - }; - mlx_uint32 dword; -}; - -union mlx_nvconfig_vpi_link_conf { - struct { - mlx_uint32 network_link_type :2; - mlx_uint32 default_link_type :2; - mlx_uint32 reserved :28; - }; - mlx_uint32 dword; -}; - -struct mlx_nvcofnig_romini { - mlx_uint32 reserved0 :1; - mlx_uint32 shared_memory_en :1; - mlx_uint32 hii_vpi_en :1; - mlx_uint32 tech_enum :1; - mlx_uint32 reserved1 :4; - mlx_uint32 static_component_name_string :1; - mlx_uint32 hii_iscsi_configuration :1; - mlx_uint32 hii_ibm_aim :1; - mlx_uint32 hii_platform_setup :1; - mlx_uint32 hii_bdf_decimal :1; - mlx_uint32 hii_read_only :1; - mlx_uint32 reserved2 :10; - mlx_uint32 mac_enum :1; - mlx_uint32 port_enum :1; - mlx_uint32 flash_en :1; - mlx_uint32 fmp_en :1; - mlx_uint32 bofm_en :1; - mlx_uint32 platform_to_driver_en :1; - mlx_uint32 hii_en :1; - mlx_uint32 undi_en :1; - /* -------------- */ - mlx_uint64 dhcp_user_class; - /* -------------- */ - mlx_uint32 reserved3 :22; - mlx_uint32 uri_boot_retry_delay :4; - mlx_uint32 uri_boot_retry :4; - mlx_uint32 option_rom_debug :1; - mlx_uint32 promiscuous_vlan :1; -}; - -#endif /* MLX_NVCONFIG_PRM_H_ */ diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_ocbb/mlx_ocbb.c b/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_ocbb/mlx_ocbb.c deleted file mode 100644 index 3852efbf1..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_ocbb/mlx_ocbb.c +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include "mlx_ocbb.h" -#include "mlx_icmd.h" -#include "mlx_bail.h" - -mlx_status -mlx_ocbb_init ( - IN mlx_utils *utils, - IN mlx_uint64 address - ) -{ - mlx_status status = MLX_SUCCESS; - struct mlx_ocbb_init ocbb_init; - ocbb_init.address_hi = (mlx_uint32)(address >> 32); - ocbb_init.address_lo = (mlx_uint32)address; - - if (utils == NULL) { - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - - status = mlx_icmd_send_command( - utils, - OCBB_INIT, - &ocbb_init, - sizeof(ocbb_init), - 0 - ); - MLX_CHECK_STATUS(utils, status, icmd_err, "mlx_icmd_send_command failed"); -icmd_err: -bad_param: - return status; -} - -mlx_status -mlx_ocbb_query_header_status ( - IN mlx_utils *utils, - OUT mlx_uint8 *ocbb_status - ) -{ - mlx_status status = MLX_SUCCESS; - struct mlx_ocbb_query_status ocbb_query_status; - - if (utils == NULL) { - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - - status = mlx_icmd_send_command( - utils, - OCBB_QUERY_HEADER_STATUS, - &ocbb_query_status, - 0, - sizeof(ocbb_query_status) - ); - MLX_CHECK_STATUS(utils, status, icmd_err, "mlx_icmd_send_command failed"); - *ocbb_status = ocbb_query_status.status; -icmd_err: -bad_param: - return status; -} - -mlx_status -mlx_ocbb_query_etoc_status ( - IN mlx_utils *utils, - OUT mlx_uint8 *ocbb_status - ) -{ - mlx_status status = MLX_SUCCESS; - struct mlx_ocbb_query_status ocbb_query_status; - - if (utils == NULL) { - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - - status = mlx_icmd_send_command( - utils, - OCBB_QUERY_ETOC_STATUS, - &ocbb_query_status, - 0, - sizeof(ocbb_query_status) - ); - MLX_CHECK_STATUS(utils, status, icmd_err, "mlx_icmd_send_command failed"); - *ocbb_status = ocbb_query_status.status; -icmd_err: -bad_param: - return status; -} - -mlx_status -mlx_ocbb_set_event ( - IN mlx_utils *utils, - IN mlx_uint64 event_data, - IN mlx_uint8 event_number, - IN mlx_uint8 event_length, - IN mlx_uint8 data_length, - IN mlx_uint8 data_start_offset - ) -{ - mlx_status status = MLX_SUCCESS; - struct mlx_ocbb_set_event ocbb_event; - - if (utils == NULL) { - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - - ocbb_event.data_length = data_length; - ocbb_event.data_start_offset = data_start_offset; - ocbb_event.event_number = event_number; - ocbb_event.event_data = event_data; - ocbb_event.event_length = event_length; - status = mlx_icmd_send_command( - utils, - OCBB_QUERY_SET_EVENT, - &ocbb_event, - sizeof(ocbb_event), - 0 - ); - MLX_CHECK_STATUS(utils, status, icmd_err, "mlx_icmd_send_command failed"); -icmd_err: -bad_param: - return status; -} diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_ocbb/mlx_ocbb.h b/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_ocbb/mlx_ocbb.h deleted file mode 100644 index 49312b98f..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_ocbb/mlx_ocbb.h +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef MLX_OCBB_H_ -#define MLX_OCBB_H_ - -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include "mlx_utils.h" - -#define MLX_OCBB_EVENT_DATA_SIZE 2 -struct mlx_ocbb_init { - mlx_uint32 address_hi; - mlx_uint32 address_lo; -}; - -struct mlx_ocbb_query_status { - mlx_uint32 reserved :24; - mlx_uint32 status :8; -}; - -struct mlx_ocbb_set_event { - mlx_uint64 event_data; - mlx_uint32 event_number :8; - mlx_uint32 event_length :8; - mlx_uint32 data_length :8; - mlx_uint32 data_start_offset :8; -}; - -mlx_status -mlx_ocbb_init ( - IN mlx_utils *utils, - IN mlx_uint64 address - ); - -mlx_status -mlx_ocbb_query_header_status ( - IN mlx_utils *utils, - OUT mlx_uint8 *ocbb_status - ); - -mlx_status -mlx_ocbb_query_etoc_status ( - IN mlx_utils *utils, - OUT mlx_uint8 *ocbb_status - ); - -mlx_status -mlx_ocbb_set_event ( - IN mlx_utils *utils, - IN mlx_uint64 EventData, - IN mlx_uint8 EventNumber, - IN mlx_uint8 EventLength, - IN mlx_uint8 DataLength, - IN mlx_uint8 DataStartOffset - ); -#endif /* MLX_OCBB_H_ */ diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_reg_access/mlx_reg_access.c b/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_reg_access/mlx_reg_access.c deleted file mode 100644 index 143ab1b0e..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_reg_access/mlx_reg_access.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include "../../mlx_lib/mlx_reg_access/mlx_reg_access.h" -#include "../../include/public/mlx_icmd.h" -#include "../../include/public/mlx_bail.h" -#include "../../include/public/mlx_memory.h" - -static -mlx_status -init_operation_tlv( - IN struct mail_box_tlv *mail_box_tlv, - IN mlx_uint16 reg_id, - IN REG_ACCESS_OPT reg_opt - ) -{ -#define TLV_OPERATION 1 - mail_box_tlv->operation_tlv.Type = TLV_OPERATION; -#define MAD_CLASS_REG_ACCESS 1 - mail_box_tlv->operation_tlv.cls = MAD_CLASS_REG_ACCESS; -#define TLV_OPERATION_SIZE 4 - mail_box_tlv->operation_tlv.len = TLV_OPERATION_SIZE; - mail_box_tlv->operation_tlv.method = reg_opt; - mail_box_tlv->operation_tlv.register_id = reg_id; - return MLX_SUCCESS; -} - -mlx_status -mlx_reg_access( - IN mlx_utils *utils, - IN mlx_uint16 reg_id, - IN REG_ACCESS_OPT reg_opt, - IN OUT mlx_void *reg_data, - IN mlx_size reg_size, - OUT mlx_uint32 *reg_status - ) -{ - mlx_status status = MLX_SUCCESS; - struct mail_box_tlv mail_box_tlv; - - if (utils == NULL || reg_data == NULL || reg_status == NULL - || reg_size > REG_ACCESS_MAX_REG_SIZE) { - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - - mlx_memory_set(utils, &mail_box_tlv, 0, sizeof(mail_box_tlv)); - - init_operation_tlv(&mail_box_tlv, reg_id, reg_opt); - -#define REG_ACCESS_TLV_REG 3 -#define REG_TLV_HEADER_LEN 4 -#define OP_TLV_SIZE 16 - mail_box_tlv.reg_tlv.Type = REG_ACCESS_TLV_REG; - mail_box_tlv.reg_tlv.len = ((reg_size + REG_TLV_HEADER_LEN + 3) >> 2); // length is in dwords round up - mlx_memory_cpy(utils, &mail_box_tlv.reg_tlv.data, reg_data, reg_size); - - reg_size += OP_TLV_SIZE + REG_TLV_HEADER_LEN; - - status = mlx_icmd_send_command(utils, FLASH_REG_ACCESS, &mail_box_tlv, reg_size, reg_size); - MLX_CHECK_STATUS(utils, status, icmd_err, "failed to send icmd"); - - mlx_memory_cpy(utils, reg_data, &mail_box_tlv.reg_tlv.data, - reg_size - (OP_TLV_SIZE + REG_TLV_HEADER_LEN)); - - *reg_status = mail_box_tlv.operation_tlv.status; -icmd_err: -bad_param: - return status; -} - - diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_reg_access/mlx_reg_access.h b/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_reg_access/mlx_reg_access.h deleted file mode 100644 index 9fbf51631..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_reg_access/mlx_reg_access.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#ifndef MLX_REG_ACCESS_H_ -#define MLX_REG_ACCESS_H_ - -#include "../../include/public/mlx_icmd.h" - -#define REG_ACCESS_MAX_REG_SIZE 236 - -typedef enum { - REG_ACCESS_READ = 1, - REG_ACCESS_WRITE = 2, -} REG_ACCESS_OPT; - -typedef enum { - TLV_ACCESS_DEFAULT_DIS = 0, - TLV_ACCESS_DEFAULT_EN = 1, -} NV_DEFAULT_OPT; - -#define REG_ID_NVDA 0x9024 -#define REG_ID_NVDI 0x9025 -#define REG_ID_NVIA 0x9029 -#define REG_ID_MLCR 0x902b -#define REG_ID_NVQC 0x9030 -#define REG_ID_MFRL 0x9028 -#define REG_ID_PTYS 0x5004 -#define REG_ID_PMTU 0x5003 - -struct operation_tlv { - mlx_uint32 reserved0 :8; /* bit_offset:0 */ /* element_size: 8 */ - mlx_uint32 status :7; /* bit_offset:8 */ /* element_size: 7 */ - mlx_uint32 dr :1; /* bit_offset:15 */ /* element_size: 1 */ - mlx_uint32 len :11; /* bit_offset:16 */ /* element_size: 11 */ - mlx_uint32 Type :5; /* bit_offset:27 */ /* element_size: 5 */ - mlx_uint32 cls :8; /* bit_offset:32 */ /* element_size: 8 */ - mlx_uint32 method :7; /* bit_offset:40 */ /* element_size: 7 */ - mlx_uint32 r :1; /* bit_offset:47 */ /* element_size: 1 */ - mlx_uint32 register_id :16; /* bit_offset:48 */ /* element_size: 16 */ - mlx_uint64 tid ; /* bit_offset:64 */ /* element_size: 64 */ -}; - -struct reg_tlv { - mlx_uint32 reserved0 :16; /* bit_offset:0 */ /* element_size: 16 */ - mlx_uint32 len :11; /* bit_offset:16 */ /* element_size: 11 */ - mlx_uint32 Type :5; /* bit_offset:27 */ /* element_size: 5 */ - mlx_uint8 data[REG_ACCESS_MAX_REG_SIZE]; -}; - -struct mail_box_tlv { - struct operation_tlv operation_tlv; - struct reg_tlv reg_tlv; -}; -mlx_status -mlx_reg_access( - IN mlx_utils *utils, - IN mlx_uint16 reg_id, - IN REG_ACCESS_OPT reg_opt, - IN OUT mlx_void *reg_data, - IN mlx_size reg_size, - OUT mlx_uint32 *reg_status - ); - -#endif /* MLX_REG_ACCESS_H_ */ diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_vmac/mlx_vmac.c b/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_vmac/mlx_vmac.c deleted file mode 100644 index 65d04c967..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_vmac/mlx_vmac.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include "../../mlx_lib/mlx_vmac/mlx_vmac.h" -#include "../../include/public/mlx_icmd.h" -#include "../../include/public/mlx_bail.h" - -mlx_status -mlx_vmac_query_virt_mac ( - IN mlx_utils *utils, - OUT struct mlx_vmac_query_virt_mac *virt_mac - ) -{ - mlx_status status = MLX_SUCCESS; - if (utils == NULL || virt_mac == NULL) { - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - - status = mlx_icmd_send_command( - utils, - QUERY_VIRTUAL_MAC, - virt_mac, - 0, - sizeof(*virt_mac) - ); - MLX_CHECK_STATUS(utils, status, icmd_err, "mlx_icmd_send_command failed"); -icmd_err: -bad_param: - return status; -} - -mlx_status -mlx_vmac_set_virt_mac ( - IN mlx_utils *utils, - OUT struct mlx_vmac_set_virt_mac *virt_mac - ) -{ - mlx_status status = MLX_SUCCESS; - if (utils == NULL || virt_mac == NULL) { - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - - status = mlx_icmd_send_command( - utils, - SET_VIRTUAL_MAC, - virt_mac, - sizeof(*virt_mac), - 0 - ); - MLX_CHECK_STATUS(utils, status, icmd_err, "mlx_icmd_send_command failed"); -icmd_err: -bad_param: - return status; -} diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_vmac/mlx_vmac.h b/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_vmac/mlx_vmac.h deleted file mode 100644 index 2214d9189..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_vmac/mlx_vmac.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef MLX_VMAC_H_ -#define MLX_VMAC_H_ - -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include "../../include/public/mlx_utils.h" - -struct mlx_vmac_query_virt_mac { - mlx_uint32 reserved0 :30; - mlx_uint32 mac_aux_v :1; - mlx_uint32 virtual_mac_en :1; - mlx_uint32 parmanent_mac_high :16; - mlx_uint32 reserved1 :16; - mlx_uint32 parmanent_mac_low :32; - mlx_uint32 virtual_mac_high :16; - mlx_uint32 Reserved2 :16; - mlx_uint32 virtual_mac_low :32; -}; - -struct mlx_vmac_set_virt_mac { - mlx_uint32 Reserved0 :30; - mlx_uint32 mac_aux_v :1; - mlx_uint32 virtual_mac_en :1; - mlx_uint32 reserved1 :32; - mlx_uint32 reserved2 :32; - mlx_uint32 virtual_mac_high; - mlx_uint32 virtual_mac_low; -}; - -mlx_status -mlx_vmac_query_virt_mac ( - IN mlx_utils *utils, - OUT struct mlx_vmac_query_virt_mac *virt_mac - ); - -mlx_status -mlx_vmac_set_virt_mac ( - IN mlx_utils *utils, - OUT struct mlx_vmac_set_virt_mac *virt_mac - ); -#endif /* MLX_VMAC_H_ */ diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_wol_rol/mlx_wol_rol.c b/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_wol_rol/mlx_wol_rol.c deleted file mode 100644 index a6c23c4a1..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_wol_rol/mlx_wol_rol.c +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include "mlx_wol_rol.h" -#include "mlx_icmd.h" -#include "mlx_memory.h" -#include "mlx_bail.h" - -mlx_status -mlx_set_wol ( - IN mlx_utils *utils, - IN mlx_uint8 wol_mask - ) -{ - mlx_status status = MLX_SUCCESS; - struct mlx_wol_rol wol_rol; - - if (utils == NULL) { - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - - mlx_memory_set(utils, &wol_rol, 0, sizeof(wol_rol)); - wol_rol.wol_mode_valid = TRUE; - wol_rol.wol_mode = wol_mask; - status = mlx_icmd_send_command( - utils, - SET_WOL_ROL, - &wol_rol, - sizeof(wol_rol), - 0 - ); - MLX_CHECK_STATUS(utils, status, icmd_err, "mlx_icmd_send_command failed"); -icmd_err: -bad_param: - return status; -} - -mlx_status -mlx_query_wol ( - IN mlx_utils *utils, - OUT mlx_uint8 *wol_mask - ) -{ - mlx_status status = MLX_SUCCESS; - struct mlx_wol_rol wol_rol; - - if (utils == NULL || wol_mask == NULL) { - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - - mlx_memory_set(utils, &wol_rol, 0, sizeof(wol_rol)); - status = mlx_icmd_send_command( - utils, - QUERY_WOL_ROL, - &wol_rol, - 0, - sizeof(wol_rol) - ); - MLX_CHECK_STATUS(utils, status, icmd_err, "mlx_icmd_send_command failed"); - *wol_mask = wol_rol.wol_mode; -icmd_err: -bad_param: - return status; -} diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_wol_rol/mlx_wol_rol.h b/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_wol_rol/mlx_wol_rol.h deleted file mode 100644 index 610419d5d..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils/mlx_lib/mlx_wol_rol/mlx_wol_rol.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef MLX_WOL_ROL_H_ -#define MLX_WOL_ROL_H_ - -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - - -#include "mlx_utils.h" - -typedef enum { - WOL_MODE_DISABLE = 0x0, - WOL_MODE_SECURE = 0x2, - WOL_MODE_MAGIC = 0x4, - WOL_MODE_ARP = 0x8, - WOL_MODE_BC = 0x10, - WOL_MODE_MC = 0x20, - WOL_MODE_UC = 0x40, - WOL_MODE_PHY = 0x80, -} WOL_MODE; - -struct mlx_wol_rol { - mlx_uint32 reserved0 :32; - mlx_uint32 reserved1 :32; - mlx_uint32 wol_mode :8; - mlx_uint32 rol_mode :8; - mlx_uint32 reserved3 :14; - mlx_uint32 wol_mode_valid :1; - mlx_uint32 rol_mode_valid :1; -}; - -mlx_status -mlx_set_wol ( - IN mlx_utils *utils, - IN mlx_uint8 wol_mask - ); - -mlx_status -mlx_query_wol ( - IN mlx_utils *utils, - OUT mlx_uint8 *wol_mask - ); - -#endif /* MLX_WOL_ROL_H_ */ diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils/src/private/uefi/mlx_logging_impl.c b/roms/ipxe/src/drivers/infiniband/mlx_utils/src/private/uefi/mlx_logging_impl.c deleted file mode 100644 index 4386ad9b9..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils/src/private/uefi/mlx_logging_impl.c +++ /dev/null @@ -1,9 +0,0 @@ -MlxDebugLogImpl() - { - DBGC((DEBUG),""); - } -MlxInfoLogImpl() -{ - DBGC((INFO),""); - } -} diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils/src/public/mlx_icmd.c b/roms/ipxe/src/drivers/infiniband/mlx_utils/src/public/mlx_icmd.c deleted file mode 100644 index f7d365dee..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils/src/public/mlx_icmd.c +++ /dev/null @@ -1,371 +0,0 @@ -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include "../../include/public/mlx_bail.h" -#include "../../include/public/mlx_icmd.h" -#include "../../include/public/mlx_pci_gw.h" -#include "../../include/public/mlx_utils.h" - -static -mlx_status -mlx_icmd_get_semaphore( - IN mlx_utils *utils - ) -{ - mlx_status status = MLX_SUCCESS; - mlx_uint32 retries = 0; - mlx_uint32 semaphore_id; - mlx_uint32 buffer; - if (utils == NULL) { - status = MLX_INVALID_PARAMETER; - goto invalid_param; - } - - status = mlx_utils_rand(utils, &semaphore_id); - MLX_CHECK_STATUS(utils, status, rand_err, "failed to get random number"); -#define ICMD_GET_SEMAPHORE_TRIES 2560 - for (retries = 0 ; retries < ICMD_GET_SEMAPHORE_TRIES ; retries++) { - status = mlx_pci_gw_read( utils, PCI_GW_SPACE_SEMAPHORE, - MLX_ICMD_SEMAPHORE_ADDR, &buffer); - MLX_CHECK_STATUS(utils, status, read_err, "failed to read icmd semaphore"); - if (buffer != 0) { - mlx_utils_delay_in_ms(10); - continue; - } - mlx_pci_gw_write( utils, PCI_GW_SPACE_SEMAPHORE, - MLX_ICMD_SEMAPHORE_ADDR, semaphore_id); - MLX_CHECK_STATUS(utils, status, set_err, "failed to set icmd semaphore"); - status = mlx_pci_gw_read( utils, PCI_GW_SPACE_SEMAPHORE, - MLX_ICMD_SEMAPHORE_ADDR, &buffer); - MLX_CHECK_STATUS(utils, status, read_err, "failed to read icmd semaphore"); - if (semaphore_id == buffer) { - status = MLX_SUCCESS; - utils->icmd.took_semaphore = TRUE; - break; - } - mlx_utils_delay_in_ms(10); - } - if (semaphore_id != buffer) { - status = MLX_FAILED; - } -read_err: -set_err: -rand_err: -invalid_param: - return status; -} -static -mlx_status -mlx_icmd_clear_semaphore( - IN mlx_utils *utils - ) -{ - mlx_status status = MLX_SUCCESS; - - if (utils == NULL) { - status = MLX_INVALID_PARAMETER; - goto invalid_param; - } - - if (utils->icmd.took_semaphore == FALSE) { - goto semaphore_not_taken; - } - status = mlx_pci_gw_write( utils, PCI_GW_SPACE_SEMAPHORE, - MLX_ICMD_SEMAPHORE_ADDR, 0); - MLX_CHECK_STATUS(utils, status, read_err, "failed to clear icmd semaphore"); - - utils->icmd.took_semaphore = FALSE; -read_err: -semaphore_not_taken: -invalid_param: - return status; -} - -static -mlx_status -mlx_icmd_init( - IN mlx_utils *utils - ) -{ - mlx_status status = MLX_SUCCESS; - - if (utils == NULL) { - status = MLX_INVALID_PARAMETER; - goto invalid_param; - } - if (utils->icmd.icmd_opened == TRUE) { - goto already_opened; - } - - utils->icmd.took_semaphore = FALSE; - - status = mlx_pci_gw_read( utils, PCI_GW_SPACE_ALL_ICMD, - MLX_ICMD_MB_SIZE_ADDR, &utils->icmd.max_cmd_size); - MLX_CHECK_STATUS(utils, status, read_err, "failed to read icmd mail box size"); - - utils->icmd.icmd_opened = TRUE; -read_err: -already_opened: -invalid_param: - return status; -} - -static -mlx_status -mlx_icmd_set_opcode( - IN mlx_utils *utils, - IN mlx_uint16 opcode - ) -{ - mlx_status status = MLX_SUCCESS; - mlx_uint32 buffer; - - if (utils == NULL) { - status = MLX_INVALID_PARAMETER; - goto invalid_param; - } - - status = mlx_pci_gw_read( utils, PCI_GW_SPACE_ALL_ICMD, - MLX_ICMD_CTRL_ADDR, &buffer); - MLX_CHECK_STATUS(utils, status, read_err, "failed to read icmd ctrl"); - -#define MLX_ICMD_OPCODE_ALIGN 16 -#define MLX_ICMD_OPCODE_MASK 0xffff - - buffer = buffer & ~(MLX_ICMD_OPCODE_MASK << MLX_ICMD_OPCODE_ALIGN); - buffer = buffer | (opcode << MLX_ICMD_OPCODE_ALIGN); - - status = mlx_pci_gw_write( utils, PCI_GW_SPACE_ALL_ICMD, - MLX_ICMD_CTRL_ADDR, buffer); - MLX_CHECK_STATUS(utils, status, write_err, "failed to write icmd ctrl"); -write_err: -read_err: -invalid_param: - return status; -} - -static -mlx_status -mlx_icmd_go( - IN mlx_utils *utils - ) -{ - mlx_status status = MLX_SUCCESS; - mlx_uint32 buffer; - mlx_uint32 busy; - mlx_uint32 wait_iteration = 0; - - if (utils == NULL) { - status = MLX_INVALID_PARAMETER; - goto invalid_param; - } - - status = mlx_pci_gw_read( utils, PCI_GW_SPACE_ALL_ICMD, - MLX_ICMD_CTRL_ADDR, &buffer); - MLX_CHECK_STATUS(utils, status, read_err, "failed to read icmd ctrl"); - -#define MLX_ICMD_BUSY_ALIGN 0 -#define MLX_ICMD_BUSY_MASK 0x1 - - busy = (buffer >> MLX_ICMD_BUSY_ALIGN) & MLX_ICMD_BUSY_MASK; - if (busy != 0) { - status = MLX_FAILED; - goto already_busy; - } - - buffer = buffer | (1 << MLX_ICMD_BUSY_ALIGN); - - status = mlx_pci_gw_write( utils, PCI_GW_SPACE_ALL_ICMD, - MLX_ICMD_CTRL_ADDR, buffer); - MLX_CHECK_STATUS(utils, status, write_err, "failed to write icmd ctrl"); - -#define MLX_ICMD_BUSY_MAX_ITERATIONS 1024 - do { - if (++wait_iteration > MLX_ICMD_BUSY_MAX_ITERATIONS) { - status = MLX_FAILED; - MLX_DEBUG_ERROR(utils, "ICMD time out"); - goto busy_timeout; - } - - mlx_utils_delay_in_ms(10); - status = mlx_pci_gw_read( utils, PCI_GW_SPACE_ALL_ICMD, - MLX_ICMD_CTRL_ADDR, &buffer); - MLX_CHECK_STATUS(utils, status, read_err, "failed to read icmd ctrl"); - busy = (buffer >> MLX_ICMD_BUSY_ALIGN) & MLX_ICMD_BUSY_MASK; - } while (busy != 0); - -busy_timeout: -write_err: -already_busy: -read_err: -invalid_param: - return status; -} - -static -mlx_status -mlx_icmd_get_status( - IN mlx_utils *utils, - OUT mlx_uint32 *out_status - ) -{ - mlx_status status = MLX_SUCCESS; - mlx_uint32 buffer; - - if (utils == NULL || out_status == NULL) { - status = MLX_INVALID_PARAMETER; - goto invalid_param; - } - - status = mlx_pci_gw_read( utils, PCI_GW_SPACE_ALL_ICMD, - MLX_ICMD_CTRL_ADDR, &buffer); - MLX_CHECK_STATUS(utils, status, read_err, "failed to read icmd ctrl"); - -#define MLX_ICMD_STATUS_ALIGN 8 -#define MLX_ICMD_STATUS_MASK 0xff - - *out_status = (buffer >> MLX_ICMD_STATUS_ALIGN) & MLX_ICMD_STATUS_MASK; - -read_err: -invalid_param: - return status; -} - -static -mlx_status -mlx_icmd_write_buffer( - IN mlx_utils *utils, - IN mlx_void* data, - IN mlx_uint32 data_size - ) -{ - mlx_status status = MLX_SUCCESS; - mlx_uint32 data_offset = 0; - mlx_size dword_size = sizeof(mlx_uint32); - - if (utils == NULL || data == NULL) { - status = MLX_INVALID_PARAMETER; - goto invalid_param; - } - - for (data_offset = 0 ; data_offset*dword_size < data_size ; data_offset++) { - status = mlx_pci_gw_write( utils, PCI_GW_SPACE_ALL_ICMD, - MLX_ICMD_MB_ADDR + data_offset*dword_size, - ((mlx_uint32*)data)[data_offset]); - MLX_CHECK_STATUS(utils, status, write_err, "failed to write icmd MB"); - } -write_err: -invalid_param: - return status; -} - - -static -mlx_status -mlx_icmd_read_buffer( - IN mlx_utils *utils, - OUT mlx_void* data, - IN mlx_uint32 data_size - ) -{ - mlx_status status = MLX_SUCCESS; - mlx_uint32 data_offset = 0; - mlx_size dword_size = sizeof(mlx_uint32); - - if (utils == NULL || data == NULL) { - status = MLX_INVALID_PARAMETER; - goto invalid_param; - } - - for (data_offset = 0 ; data_offset*dword_size < data_size ; data_offset++) { - status = mlx_pci_gw_read( utils, PCI_GW_SPACE_ALL_ICMD, - MLX_ICMD_MB_ADDR + data_offset*dword_size, - (mlx_uint32*)data + data_offset); - MLX_CHECK_STATUS(utils, status, read_err, "failed to read icmd MB"); - } -read_err: -invalid_param: - return status; -} -mlx_status -mlx_icmd_send_command( - IN mlx_utils *utils, - IN mlx_uint16 opcode, - IN OUT mlx_void* data, - IN mlx_uint32 write_data_size, - IN mlx_uint32 read_data_size - ) -{ - mlx_status status = MLX_SUCCESS; - mlx_uint32 icmd_status = MLX_FAILED; - - if (utils == NULL || data == NULL) { - status = MLX_INVALID_PARAMETER; - goto invalid_param; - } - status = mlx_icmd_init(utils); - MLX_CHECK_STATUS(utils, status, open_err, "failed to open icmd"); - - if (write_data_size > utils->icmd.max_cmd_size || - read_data_size > utils->icmd.max_cmd_size) { - status = MLX_INVALID_PARAMETER; - goto size_err; - } - - status = mlx_icmd_get_semaphore(utils); - MLX_CHECK_STATUS(utils, status, semaphore_err, "failed to get icmd semaphore"); - - status = mlx_icmd_set_opcode(utils, opcode); - MLX_CHECK_STATUS(utils, status, opcode_err, "failed to set icmd opcode"); - - if (write_data_size != 0) { - status = mlx_icmd_write_buffer(utils, data, write_data_size); - MLX_CHECK_STATUS(utils, status, opcode_err, "failed to write icmd MB"); - } - - status = mlx_icmd_go(utils); - MLX_CHECK_STATUS(utils, status, go_err, "failed to activate icmd"); - - status = mlx_icmd_get_status(utils, &icmd_status); - MLX_CHECK_STATUS(utils, status, get_status_err, "failed to set icmd opcode"); - - if (icmd_status != 0) { - MLX_DEBUG_ERROR(utils, "icmd failed with status = %d\n", icmd_status); - status = MLX_FAILED; - goto icmd_failed; - } - if (read_data_size != 0) { - status = mlx_icmd_read_buffer(utils, data, read_data_size); - MLX_CHECK_STATUS(utils, status, read_err, "failed to read icmd MB"); - } -read_err: -icmd_failed: -get_status_err: -go_err: -opcode_err: - mlx_icmd_clear_semaphore(utils); -semaphore_err: -size_err: -open_err: -invalid_param: - return status; -} diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils/src/public/mlx_memory.c b/roms/ipxe/src/drivers/infiniband/mlx_utils/src/public/mlx_memory.c deleted file mode 100644 index 5aa5a53d2..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils/src/public/mlx_memory.c +++ /dev/null @@ -1,238 +0,0 @@ -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include <stddef.h> -#include "../../include/private/mlx_memory_priv.h" -#include "../../include/public/mlx_memory.h" - -mlx_status -mlx_memory_alloc( - IN mlx_utils *utils, - IN mlx_size size, - OUT mlx_void **ptr - ) -{ - mlx_status status = MLX_SUCCESS; - *ptr = NULL; - if ( utils == NULL || size == 0 || *ptr != NULL ){ - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - status = mlx_memory_alloc_priv(utils, size, ptr); -bad_param: - return status; -} - -mlx_status -mlx_memory_zalloc( - IN mlx_utils *utils, - IN mlx_size size, - OUT mlx_void **ptr - ) -{ - mlx_status status = MLX_SUCCESS; - *ptr = NULL; - if ( utils == NULL || size == 0 || *ptr != NULL ){ - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - status = mlx_memory_zalloc_priv(utils, size, ptr); -bad_param: - return status; -} - -mlx_status -mlx_memory_free( - IN mlx_utils *utils, - IN mlx_void **ptr - ) -{ - mlx_status status = MLX_SUCCESS; - if ( utils == NULL || ptr == NULL || *ptr == NULL ){ - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - status = mlx_memory_free_priv(utils, *ptr); - *ptr = NULL; -bad_param: - return status; -} -mlx_status -mlx_memory_alloc_dma( - IN mlx_utils *utils, - IN mlx_size size , - IN mlx_size align, - OUT mlx_void **ptr - ) -{ - mlx_status status = MLX_SUCCESS; - *ptr = NULL; - if ( utils == NULL || size == 0 || *ptr != NULL ){ - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - status = mlx_memory_alloc_dma_priv(utils, size, align, ptr); -bad_param: - return status; -} - -mlx_status -mlx_memory_free_dma( - IN mlx_utils *utils, - IN mlx_size size , - IN mlx_void **ptr - ) -{ - mlx_status status = MLX_SUCCESS; - if ( utils == NULL || size == 0 || ptr == NULL || *ptr == NULL ){ - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - status = mlx_memory_free_dma_priv(utils, size, *ptr); - *ptr = NULL; -bad_param: - return status; -} - -mlx_status -mlx_memory_map_dma( - IN mlx_utils *utils, - IN mlx_void *addr , - IN mlx_size number_of_bytes, - OUT mlx_physical_address *phys_addr, - OUT mlx_void **mapping - ) -{ - mlx_status status = MLX_SUCCESS; - if ( utils == NULL || phys_addr == NULL ){ - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - status = mlx_memory_map_dma_priv(utils, addr, number_of_bytes, phys_addr, mapping); -bad_param: - return status; -} - -mlx_status -mlx_memory_ummap_dma( - IN mlx_utils *utils, - IN mlx_void *mapping - ) -{ - mlx_status status = MLX_SUCCESS; - if ( utils == NULL){ - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - status = mlx_memory_ummap_dma_priv(utils, mapping); -bad_param: - return status; -} - -mlx_status -mlx_memory_cmp( - IN mlx_utils *utils, - IN mlx_void *first_block, - IN mlx_void *second_block, - IN mlx_size size, - OUT mlx_uint32 *out - ) -{ - mlx_status status = MLX_SUCCESS; - if ( utils == NULL || first_block == NULL || second_block == NULL || - out == NULL){ - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - status = mlx_memory_cmp_priv(utils, first_block, second_block, size, out); -bad_param: - return status; -} - -mlx_status -mlx_memory_set( - IN mlx_utils *utils, - IN mlx_void *block, - IN mlx_int32 value, - IN mlx_size size - ) -{ - mlx_status status = MLX_SUCCESS; - if ( utils == NULL || block == NULL){ - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - status = mlx_memory_set_priv(utils, block, value, size); -bad_param: - return status; -} - -mlx_status -mlx_memory_cpy( - IN mlx_utils *utils, - OUT mlx_void *destination_buffer, - IN mlx_void *source_buffer, - IN mlx_size length - ) -{ - mlx_status status = MLX_SUCCESS; - if ( utils == NULL || destination_buffer == NULL || source_buffer == NULL){ - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - status = mlx_memory_cpy_priv(utils, destination_buffer, source_buffer, length); -bad_param: - return status; -} - -mlx_status -mlx_memory_cpu_to_be32( - IN mlx_utils *utils, - IN mlx_uint32 source, - IN mlx_uint32 *destination - ) -{ - mlx_status status = MLX_SUCCESS; - if ( utils == NULL || destination == NULL ){ - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - status = mlx_memory_cpu_to_be32_priv(utils, source, destination); -bad_param: - return status; -} - -mlx_status -mlx_memory_be32_to_cpu( - IN mlx_utils *utils, - IN mlx_uint32 source, - IN mlx_uint32 *destination - ) -{ - mlx_status status = MLX_SUCCESS; - if ( utils == NULL || destination == NULL ){ - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - status = mlx_memory_be32_to_cpu_priv(utils, source, destination); -bad_param: - return status; -} diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils/src/public/mlx_pci.c b/roms/ipxe/src/drivers/infiniband/mlx_utils/src/public/mlx_pci.c deleted file mode 100644 index 91c44d991..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils/src/public/mlx_pci.c +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include <stddef.h> -#include "../../include/private/mlx_pci_priv.h" -#include "../../include/public/mlx_pci.h" - -mlx_status -mlx_pci_init( - IN mlx_utils *utils - ) -{ - mlx_status status = MLX_SUCCESS; - if( utils == NULL){ - status = MLX_INVALID_PARAMETER; - goto bail; - } - status = mlx_pci_init_priv(utils); -bail: - return status; -} - -mlx_status -mlx_pci_read( - IN mlx_utils *utils, - IN mlx_pci_width width, - IN mlx_uint32 offset, - IN mlx_uintn count, - OUT mlx_void *buffer - ) -{ - mlx_status status = MLX_SUCCESS; - if( utils == NULL || count == 0){ - status = MLX_INVALID_PARAMETER; - goto bail; - } - status = mlx_pci_read_priv(utils, width, offset, count, buffer); -bail: - return status; -} - -mlx_status -mlx_pci_write( - IN mlx_utils *utils, - IN mlx_pci_width width, - IN mlx_uint32 offset, - IN mlx_uintn count, - IN mlx_void *buffer - ) -{ - mlx_status status = MLX_SUCCESS; - if( utils == NULL || count == 0){ - status = MLX_INVALID_PARAMETER; - goto bail; - } - status = mlx_pci_write_priv(utils, width, offset, count, buffer); -bail: - return status; -} - -mlx_status -mlx_pci_mem_read( - IN mlx_utils *utils, - IN mlx_pci_width width, - IN mlx_uint8 bar_index, - IN mlx_uint64 offset, - IN mlx_uintn count, - OUT mlx_void *buffer - ) -{ - mlx_status status = MLX_SUCCESS; - if( utils == NULL || count == 0){ - status = MLX_INVALID_PARAMETER; - goto bail; - } - status = mlx_pci_mem_read_priv(utils, bar_index, width, offset, count, buffer); -bail: - return status; -} - -mlx_status -mlx_pci_mem_write( - IN mlx_utils *utils, - IN mlx_pci_width width, - IN mlx_uint8 bar_index, - IN mlx_uint64 offset, - IN mlx_uintn count, - IN mlx_void *buffer - ) -{ - mlx_status status = MLX_SUCCESS; - if( utils == NULL || count == 0){ - status = MLX_INVALID_PARAMETER; - goto bail; - } - status = mlx_pci_mem_write_priv(utils, width, bar_index, offset, count, buffer); -bail: - return status; -} diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils/src/public/mlx_pci_gw.c b/roms/ipxe/src/drivers/infiniband/mlx_utils/src/public/mlx_pci_gw.c deleted file mode 100644 index 30c1e644e..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils/src/public/mlx_pci_gw.c +++ /dev/null @@ -1,392 +0,0 @@ -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include "../../include/public/mlx_pci_gw.h" -#include "../../include/public/mlx_bail.h" -#include "../../include/public/mlx_pci.h" -#include "../../include/public/mlx_logging.h" - -/* Lock/unlock GW on each VSEC access */ -#undef VSEC_DEBUG - -static -mlx_status -mlx_pci_gw_check_capability_id( - IN mlx_utils *utils, - IN mlx_uint8 cap_pointer, - OUT mlx_boolean *bool - ) -{ - mlx_status status = MLX_SUCCESS; - mlx_uint8 offset = cap_pointer + PCI_GW_CAPABILITY_ID_OFFSET; - mlx_uint8 id = 0; - status = mlx_pci_read(utils, MlxPciWidthUint8, offset, - 1, &id); - MLX_CHECK_STATUS(utils, status, read_err,"failed to read capability id"); - *bool = ( id == PCI_GW_CAPABILITY_ID ); -read_err: - return status; -} - -static -mlx_status -mlx_pci_gw_get_ownership( - IN mlx_utils *utils - ) -{ - mlx_status status = MLX_SUCCESS; - mlx_uint32 cap_offset = utils->pci_gw.pci_cmd_offset; - mlx_uint32 semaphore = 0; - mlx_uint32 counter = 0; - mlx_uint32 get_semaphore_try = 0; - mlx_uint32 get_ownership_try = 0; - - for( ; get_ownership_try < PCI_GW_GET_OWNERSHIP_TRIES; get_ownership_try ++){ - for( ; get_semaphore_try <= PCI_GW_SEMPHORE_TRIES ; get_semaphore_try++){ - status = mlx_pci_read(utils, MlxPciWidthUint32, cap_offset + PCI_GW_CAPABILITY_SEMAPHORE_OFFSET, - 1, &semaphore); - MLX_CHECK_STATUS(utils, status, read_err,"failed to read semaphore"); - if( semaphore == 0 ){ - break; - } - mlx_utils_delay_in_us(10); - } - if( semaphore != 0 ){ - status = MLX_FAILED; - goto semaphore_err; - } - - status = mlx_pci_read(utils, MlxPciWidthUint32, cap_offset + PCI_GW_CAPABILITY_COUNTER_OFFSET, - 1, &counter); - MLX_CHECK_STATUS(utils, status, read_err, "failed to read counter"); - - status = mlx_pci_write(utils, MlxPciWidthUint32, cap_offset + PCI_GW_CAPABILITY_SEMAPHORE_OFFSET, - 1, &counter); - MLX_CHECK_STATUS(utils, status, write_err,"failed to write semaphore"); - - status = mlx_pci_read(utils, MlxPciWidthUint32, cap_offset + PCI_GW_CAPABILITY_SEMAPHORE_OFFSET, - 1, &semaphore); - MLX_CHECK_STATUS(utils, status, read_err,"failed to read semaphore"); - if( counter == semaphore ){ - break; - } - } - if( counter != semaphore ){ - status = MLX_FAILED; - } -write_err: -read_err: -semaphore_err: - return status; -} - -static -mlx_status -mlx_pci_gw_free_ownership( - IN mlx_utils *utils - ) -{ - mlx_status status = MLX_SUCCESS; - mlx_uint32 cap_offset = utils->pci_gw.pci_cmd_offset; - mlx_uint32 value = 0; - - status = mlx_pci_write(utils, MlxPciWidthUint32, cap_offset + PCI_GW_CAPABILITY_SEMAPHORE_OFFSET, - 1, &value); - MLX_CHECK_STATUS(utils, status, write_err,"failed to write semaphore"); -write_err: - return status; -} - -static -mlx_status -mlx_pci_gw_set_space( - IN mlx_utils *utils, - IN mlx_pci_gw_space space - ) -{ - mlx_status status = MLX_SUCCESS; - mlx_uint32 cap_offset = utils->pci_gw.pci_cmd_offset;; - mlx_uint8 space_status = 0; - - /* set nodnic*/ - status = mlx_pci_write(utils, MlxPciWidthUint16, cap_offset + PCI_GW_CAPABILITY_SPACE_OFFSET, 1, &space); - MLX_CHECK_STATUS(utils, status, read_error,"failed to write capability space"); - - status = mlx_pci_read(utils, MlxPciWidthUint8, cap_offset + PCI_GW_CAPABILITY_STATUS_OFFSET, 1, &space_status); - MLX_CHECK_STATUS(utils, status, read_error,"failed to read capability status"); - if( (space_status & 0x20) == 0){ - status = MLX_FAILED; - goto space_unsupported; - } -read_error: -space_unsupported: - return status; -} - -static -mlx_status -mlx_pci_gw_wait_for_flag_value( - IN mlx_utils *utils, - IN mlx_boolean value - ) -{ - mlx_status status = MLX_SUCCESS; - mlx_uint32 try = 0; - mlx_uint32 cap_offset = utils->pci_gw.pci_cmd_offset; - mlx_uint32 flag = 0; - - for(; try < PCI_GW_READ_FLAG_TRIES ; try ++ ) { - status = mlx_pci_read(utils, MlxPciWidthUint32, cap_offset + PCI_GW_CAPABILITY_FLAG_OFFSET, 1, &flag); - MLX_CHECK_STATUS(utils, status, read_error, "failed to read capability flag"); - if( ((flag & 0x80000000) != 0) == value ){ - goto flag_valid; - } - mlx_utils_delay_in_us(10); - } - status = MLX_FAILED; -flag_valid: -read_error: - return status; -} -static -mlx_status -mlx_pci_gw_search_capability( - IN mlx_utils *utils, - OUT mlx_uint32 *cap_offset - ) -{ - mlx_status status = MLX_SUCCESS; - mlx_uint8 cap_pointer = 0; - mlx_boolean is_capability = FALSE; - - if( cap_offset == NULL || utils == NULL){ - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - - //get first capability pointer - status = mlx_pci_read(utils, MlxPciWidthUint8, PCI_GW_FIRST_CAPABILITY_POINTER_OFFSET, - 1, &cap_pointer); - MLX_CHECK_STATUS(utils, status, read_err, - "failed to read capability pointer"); - - //search the right capability - while( cap_pointer != 0 ){ - status = mlx_pci_gw_check_capability_id(utils, cap_pointer, &is_capability); - MLX_CHECK_STATUS(utils, status, check_err - ,"failed to check capability id"); - - if( is_capability == TRUE ){ - *cap_offset = cap_pointer; - break; - } - - status = mlx_pci_read(utils, MlxPciWidthUint8, cap_pointer + - PCI_GW_CAPABILITY_NEXT_POINTER_OFFSET , - 1, &cap_pointer); - MLX_CHECK_STATUS(utils, status, read_err, - "failed to read capability pointer"); - } - if( is_capability != TRUE ){ - status = MLX_NOT_FOUND; - } -check_err: -read_err: -bad_param: - return status; -} - -mlx_status -mlx_pci_gw_init( - IN mlx_utils *utils - ) -{ - mlx_status status = MLX_SUCCESS; - mlx_pci_gw *pci_gw = NULL; - - if( utils == NULL){ - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - - pci_gw = &utils->pci_gw; - - status = mlx_pci_gw_search_capability(utils, &pci_gw->pci_cmd_offset); - MLX_CHECK_STATUS(utils, status, cap_err, - "mlx_pci_gw_search_capability failed"); - -#if ! defined ( VSEC_DEBUG ) - status = mlx_pci_gw_get_ownership(utils); - MLX_CHECK_STATUS(utils, status, ownership_err,"failed to get ownership"); -ownership_err: -#endif -cap_err: -bad_param: - return status; -} - -mlx_status -mlx_pci_gw_teardown( - IN mlx_utils *utils __attribute__ ((unused)) - ) -{ -#if ! defined ( VSEC_DEBUG ) - mlx_pci_gw_free_ownership(utils); -#endif - return MLX_SUCCESS; -} - -mlx_status -mlx_pci_gw_read( - IN mlx_utils *utils, - IN mlx_pci_gw_space space, - IN mlx_uint32 address, - OUT mlx_pci_gw_buffer *buffer - ) -{ - mlx_status status = MLX_SUCCESS; - mlx_pci_gw *pci_gw = NULL; - mlx_uint32 cap_offset = 0; - - if (utils == NULL || buffer == NULL || utils->pci_gw.pci_cmd_offset == 0) { - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - - mlx_utils_acquire_lock(utils); - - pci_gw = &utils->pci_gw; - cap_offset = pci_gw->pci_cmd_offset; - -#if ! defined ( VSEC_DEBUG ) - if (pci_gw->space != space) { - status = mlx_pci_gw_set_space(utils, space); - MLX_CHECK_STATUS(utils, status, space_error,"failed to set space"); - pci_gw->space = space; - } -#else - status = mlx_pci_gw_get_ownership(utils); - MLX_CHECK_STATUS(utils, status, ownership_err,"failed to get ownership"); - - status = mlx_pci_gw_set_space(utils, space); - MLX_CHECK_STATUS(utils, status, space_error,"failed to set space"); - pci_gw->space = space; -#endif - - status = mlx_pci_write(utils, MlxPciWidthUint32, cap_offset + PCI_GW_CAPABILITY_ADDRESS_OFFSET, 1, &address); - MLX_CHECK_STATUS(utils, status, read_error,"failed to write capability address"); - -#if defined ( DEVICE_CX3 ) - /* WA for PCI issue (race) */ - mlx_utils_delay_in_us ( 10 ); -#endif - - status = mlx_pci_gw_wait_for_flag_value(utils, TRUE); - MLX_CHECK_STATUS(utils, status, read_error, "flag failed to change"); - - status = mlx_pci_read(utils, MlxPciWidthUint32, cap_offset + PCI_GW_CAPABILITY_DATA_OFFSET, 1, buffer); - MLX_CHECK_STATUS(utils, status, read_error,"failed to read capability data"); - -#if defined ( VSEC_DEBUG ) - status = mlx_pci_gw_free_ownership(utils); - MLX_CHECK_STATUS(utils, status, free_err, - "mlx_pci_gw_free_ownership failed"); -free_err: - mlx_utils_release_lock(utils); - return status; -#endif -read_error: -space_error: -#if defined ( VSEC_DEBUG ) - mlx_pci_gw_free_ownership(utils); -ownership_err: -#endif -mlx_utils_release_lock(utils); -bad_param: - return status; -} - -mlx_status -mlx_pci_gw_write( - IN mlx_utils *utils, - IN mlx_pci_gw_space space, - IN mlx_uint32 address, - IN mlx_pci_gw_buffer buffer - ) -{ - mlx_status status = MLX_SUCCESS; - mlx_pci_gw *pci_gw = NULL; - mlx_uint32 cap_offset = 0; - mlx_uint32 fixed_address = address | PCI_GW_WRITE_FLAG; - - if (utils == NULL || utils->pci_gw.pci_cmd_offset == 0) { - status = MLX_INVALID_PARAMETER; - goto bad_param; - } - - mlx_utils_acquire_lock(utils); - - pci_gw = &utils->pci_gw; - cap_offset = pci_gw->pci_cmd_offset; - -#if ! defined ( VSEC_DEBUG ) - if (pci_gw->space != space) { - status = mlx_pci_gw_set_space(utils, space); - MLX_CHECK_STATUS(utils, status, space_error,"failed to set space"); - pci_gw->space = space; - } -#else - status = mlx_pci_gw_get_ownership(utils); - MLX_CHECK_STATUS(utils, status, ownership_err,"failed to get ownership"); - - status = mlx_pci_gw_set_space(utils, space); - MLX_CHECK_STATUS(utils, status, space_error,"failed to set space"); - pci_gw->space = space; -#endif - status = mlx_pci_write(utils, MlxPciWidthUint32, cap_offset + PCI_GW_CAPABILITY_DATA_OFFSET, 1, &buffer); - MLX_CHECK_STATUS(utils, status, read_error,"failed to write capability data"); - - status = mlx_pci_write(utils, MlxPciWidthUint32, cap_offset + PCI_GW_CAPABILITY_ADDRESS_OFFSET, 1, &fixed_address); - MLX_CHECK_STATUS(utils, status, read_error,"failed to write capability address"); - - status = mlx_pci_gw_wait_for_flag_value(utils, FALSE); - MLX_CHECK_STATUS(utils, status, read_error, "flag failed to change"); -#if defined ( VSEC_DEBUG ) - status = mlx_pci_gw_free_ownership(utils); - MLX_CHECK_STATUS(utils, status, free_err, - "mlx_pci_gw_free_ownership failed"); -free_err: -mlx_utils_release_lock(utils); - return status; -#endif -read_error: -space_error: -#if defined ( VSEC_DEBUG ) - mlx_pci_gw_free_ownership(utils); -ownership_err: -#endif -mlx_utils_release_lock(utils); -bad_param: - return status; -} - - - diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils/src/public/mlx_utils.c b/roms/ipxe/src/drivers/infiniband/mlx_utils/src/public/mlx_utils.c deleted file mode 100644 index c824b17e9..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils/src/public/mlx_utils.c +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#include <stddef.h> -#include "../../include/private/mlx_utils_priv.h" -#include "../../include/public/mlx_pci.h" -#include "../../include/public/mlx_utils.h" - -mlx_status -mlx_utils_init( - IN mlx_utils *utils, - IN mlx_pci *pci - ) -{ - mlx_status status = MLX_SUCCESS; - if( pci == NULL || utils == NULL ){ - status = MLX_INVALID_PARAMETER; - goto bail; - } - utils->pci = pci; - status = mlx_pci_init(utils); - status = mlx_utils_init_lock(utils); -bail: - return status; -} - -mlx_status -mlx_utils_teardown( - IN mlx_utils *utils __attribute__ ((unused)) - ) -{ - mlx_status status = MLX_SUCCESS; - mlx_utils_free_lock(utils); - return status; -} - -mlx_status -mlx_utils_delay_in_ms( - IN mlx_uint32 msecs - ) -{ - mlx_utils_delay_in_ms_priv(msecs); - return MLX_SUCCESS; -} -mlx_status -mlx_utils_delay_in_us( - IN mlx_uint32 usecs - ) -{ - mlx_utils_delay_in_us_priv(usecs); - return MLX_SUCCESS; -} -mlx_status -mlx_utils_ilog2( - IN mlx_uint32 i, - OUT mlx_uint32 *log - ) -{ - mlx_utils_ilog2_priv(i, log); - return MLX_SUCCESS; -} - -mlx_status -mlx_utils_init_lock( - IN OUT mlx_utils *utils - ) -{ - return mlx_utils_init_lock_priv(&(utils->lock)); - -} - -mlx_status -mlx_utils_free_lock( - IN OUT mlx_utils *utils - ) -{ - return mlx_utils_free_lock_priv(utils->lock); -} - -mlx_status -mlx_utils_acquire_lock ( - IN OUT mlx_utils *utils - ) -{ - return mlx_utils_acquire_lock_priv(utils->lock); -} - -mlx_status -mlx_utils_release_lock ( - IN OUT mlx_utils *utils - ) -{ - return mlx_utils_release_lock_priv(utils->lock); -} - -mlx_status -mlx_utils_rand ( - IN mlx_utils *utils, - OUT mlx_uint32 *rand_num - ) -{ - return mlx_utils_rand_priv(utils, rand_num); -} diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils_flexboot/include/mlx_logging_priv.h b/roms/ipxe/src/drivers/infiniband/mlx_utils_flexboot/include/mlx_logging_priv.h deleted file mode 100644 index af7e86f44..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils_flexboot/include/mlx_logging_priv.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * DebugPriv.h - * - * Created on: Jan 19, 2015 - * Author: maord - */ - -#ifndef STUB_MLXUTILS_INCLUDE_PRIVATE_FLEXBOOT_DEBUG_H_ -#define STUB_MLXUTILS_INCLUDE_PRIVATE_FLEXBOOT_DEBUG_H_ - -#include <stdio.h> -#include <compiler.h> - -#define MLX_DEBUG_FATAL_ERROR_PRIVATE(...) do { \ - DBG("%s: ",__func__); \ - DBG(__VA_ARGS__); \ - } while ( 0 ) - -#define MLX_DEBUG_ERROR_PRIVATE(id, ...) do { \ - DBGC(id, "%s: ",__func__); \ - DBGC(id, __VA_ARGS__); \ - } while ( 0 ) - -#define MLX_DEBUG_WARN_PRIVATE(id, ...) do { \ - DBGC(id, "%s: ",__func__); \ - DBGC(id, __VA_ARGS__); \ - } while ( 0 ) - -#define MLX_DEBUG_INFO1_PRIVATE(id, ...) do { \ - DBGC(id, "%s: ",__func__); \ - DBGC(id, __VA_ARGS__); \ - } while ( 0 ) - -#define MLX_DEBUG_INFO2_PRIVATE(id, ...) do { \ - DBGC2(id, "%s: ",__func__); \ - DBGC2(id, __VA_ARGS__); \ - } while ( 0 ) - -#define MLX_DBG_ERROR_PRIVATE(...) do { \ - DBG("%s: ",__func__); \ - DBG(__VA_ARGS__); \ - } while ( 0 ) - -#define MLX_DBG_WARN_PRIVATE(...) do { \ - DBG("%s: ",__func__); \ - DBG(__VA_ARGS__); \ - } while ( 0 ) - -#define MLX_DBG_INFO1_PRIVATE(...) do { \ - DBG("%s: ",__func__); \ - DBG(__VA_ARGS__); \ - } while ( 0 ) - -#define MLX_DBG_INFO2_PRIVATE(...) do { \ - DBG2("%s: ",__func__); \ - DBG2(__VA_ARGS__); \ - } while ( 0 ) - - - -#endif /* STUB_MLXUTILS_INCLUDE_PRIVATE_FLEXBOOT_DEBUG_H_ */ diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils_flexboot/include/mlx_types_priv.h b/roms/ipxe/src/drivers/infiniband/mlx_utils_flexboot/include/mlx_types_priv.h deleted file mode 100644 index feaeae679..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils_flexboot/include/mlx_types_priv.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * types.h - * - * Created on: Jan 18, 2015 - * Author: maord - */ - -#ifndef A_MLXUTILS_INCLUDE_PUBLIC_TYPES_H_ -#define A_MLXUTILS_INCLUDE_PUBLIC_TYPES_H_ -#include <stdint.h> -//#include <errno.h> -#include <ipxe/pci.h> - -#define MLX_SUCCESS 0 -#define MLX_OUT_OF_RESOURCES (-1) -//(-ENOMEM) -#define MLX_INVALID_PARAMETER (-2) -//(-EINVAL) -#define MLX_UNSUPPORTED (-3) -//(-ENOSYS) -#define MLX_NOT_FOUND (-4) - -#define MLX_FAILED (-5) - -#undef TRUE -#define TRUE 1 -#undef FALSE -#define FALSE !TRUE - -typedef int mlx_status; - -typedef uint8_t mlx_uint8; -typedef uint16_t mlx_uint16; -typedef uint32_t mlx_uint32; -typedef uint64_t mlx_uint64; -typedef uint32_t mlx_uintn; - -typedef int8_t mlx_int8; -typedef int16_t mlx_int16;; -typedef int32_t mlx_int32; -typedef int64_t mlx_int64; -typedef uint8_t mlx_boolean; - -typedef struct pci_device mlx_pci; - -typedef size_t mlx_size; - -typedef void mlx_void; - -#define MAC_ADDR_LEN 6 -typedef unsigned long mlx_physical_address; -typedef union { - struct { - uint32_t low; - uint32_t high; - } __attribute__ (( packed )); - uint8_t addr[MAC_ADDR_LEN]; -} mlx_mac_address; - -#endif /* A_MLXUTILS_INCLUDE_PUBLIC_TYPES_H_ */ diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils_flexboot/src/mlx_memory_priv.c b/roms/ipxe/src/drivers/infiniband/mlx_utils_flexboot/src/mlx_memory_priv.c deleted file mode 100644 index cb9e759bf..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils_flexboot/src/mlx_memory_priv.c +++ /dev/null @@ -1,172 +0,0 @@ -/* - * MemoryPriv.c - * - * Created on: Jan 21, 2015 - * Author: maord - */ - -#include <ipxe/malloc.h> -#include <stddef.h> -#include <byteswap.h> -#include <ipxe/io.h> -#include "../../mlx_utils/include/private/mlx_memory_priv.h" - - -mlx_status -mlx_memory_alloc_priv( - IN mlx_utils *utils __attribute__ ((unused)), - IN mlx_size size, - OUT mlx_void **ptr - ) -{ - mlx_status status = MLX_SUCCESS; - *ptr = malloc(size); - if(*ptr == NULL){ - status = MLX_OUT_OF_RESOURCES; - } - return status; -} - -mlx_status -mlx_memory_zalloc_priv( - IN mlx_utils *utils __attribute__ ((unused)), - IN mlx_size size, - OUT mlx_void **ptr - ) -{ - mlx_status status = MLX_SUCCESS; - *ptr = zalloc(size); - if(*ptr == NULL){ - status = MLX_OUT_OF_RESOURCES; - } - return status; -} - -mlx_status -mlx_memory_free_priv( - IN mlx_utils *utils __attribute__ ((unused)), - IN mlx_void *ptr - ) -{ - mlx_status status = MLX_SUCCESS; - free(ptr); - return status; -} -mlx_status -mlx_memory_alloc_dma_priv( - IN mlx_utils *utils __attribute__ ((unused)), - IN mlx_size size , - IN mlx_size align, - OUT mlx_void **ptr - ) -{ - mlx_status status = MLX_SUCCESS; - *ptr = malloc_dma(size, align); - if (*ptr == NULL) { - status = MLX_OUT_OF_RESOURCES; - } else { - memset(*ptr, 0, size); - } - return status; -} - -mlx_status -mlx_memory_free_dma_priv( - IN mlx_utils *utils __attribute__ ((unused)), - IN mlx_size size , - IN mlx_void *ptr - ) -{ - mlx_status status = MLX_SUCCESS; - free_dma(ptr, size); - return status; -} -mlx_status -mlx_memory_map_dma_priv( - IN mlx_utils *utils __attribute__ ((unused)), - IN mlx_void *addr , - IN mlx_size number_of_bytes __attribute__ ((unused)), - OUT mlx_physical_address *phys_addr, - OUT mlx_void **mapping __attribute__ ((unused)) - ) -{ - mlx_status status = MLX_SUCCESS; - *phys_addr = virt_to_bus(addr); - return status; -} - -mlx_status -mlx_memory_ummap_dma_priv( - IN mlx_utils *utils __attribute__ ((unused)), - IN mlx_void *mapping __attribute__ ((unused)) - ) -{ - mlx_status status = MLX_SUCCESS; - return status; -} - -mlx_status -mlx_memory_cmp_priv( - IN mlx_utils *utils __unused, - IN mlx_void *first_block, - IN mlx_void *second_block, - IN mlx_size size, - OUT mlx_uint32 *out - ) -{ - mlx_status status = MLX_SUCCESS; - *out = memcmp(first_block, second_block, size); - return status; -} - -mlx_status -mlx_memory_set_priv( - IN mlx_utils *utils __unused, - IN mlx_void *block, - IN mlx_int32 value, - IN mlx_size size - ) -{ - mlx_status status = MLX_SUCCESS; - memset(block, value, size); - return status; -} - -mlx_status -mlx_memory_cpy_priv( - IN mlx_utils *utils __unused, - OUT mlx_void *destination_buffer, - IN mlx_void *source_buffer, - IN mlx_size length - ) -{ - mlx_status status = MLX_SUCCESS; - memcpy(destination_buffer, source_buffer, length); - return status; -} - -mlx_status -mlx_memory_cpu_to_be32_priv( - IN mlx_utils *utils __unused, - IN mlx_uint32 source, - IN mlx_uint32 *destination - ) -{ - mlx_status status = MLX_SUCCESS; - *destination = cpu_to_be32(source); - return status; -} - - -mlx_status -mlx_memory_be32_to_cpu_priv( - IN mlx_utils *utils __unused, - IN mlx_uint32 source, - IN mlx_uint32 *destination - ) -{ - mlx_status status = MLX_SUCCESS; - *destination = be32_to_cpu(source); - return status; -} - diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils_flexboot/src/mlx_pci_priv.c b/roms/ipxe/src/drivers/infiniband/mlx_utils_flexboot/src/mlx_pci_priv.c deleted file mode 100644 index f8caefdce..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils_flexboot/src/mlx_pci_priv.c +++ /dev/null @@ -1,182 +0,0 @@ -/* - * MlxPciPriv.c - * - * Created on: Jan 21, 2015 - * Author: maord - */ - -#include <ipxe/pci.h> -#include "../../mlx_utils/include/private/mlx_pci_priv.h" - - -static -mlx_status -mlx_pci_config_byte( - IN mlx_utils *utils, - IN mlx_boolean read, - IN mlx_uint32 offset, - IN OUT mlx_uint8 *buffer - ) -{ - mlx_status status = MLX_SUCCESS; - if (read) { - status = pci_read_config_byte(utils->pci, offset, buffer); - }else { - status = pci_write_config_byte(utils->pci, offset, *buffer); - } - return status; -} - -static -mlx_status -mlx_pci_config_word( - IN mlx_utils *utils, - IN mlx_boolean read, - IN mlx_uint32 offset, - IN OUT mlx_uint16 *buffer - ) -{ - mlx_status status = MLX_SUCCESS; - if (read) { - status = pci_read_config_word(utils->pci, offset, buffer); - }else { - status = pci_write_config_word(utils->pci, offset, *buffer); - } - return status; -} - -static -mlx_status -mlx_pci_config_dword( - IN mlx_utils *utils, - IN mlx_boolean read, - IN mlx_uint32 offset, - IN OUT mlx_uint32 *buffer - ) -{ - mlx_status status = MLX_SUCCESS; - if (read) { - status = pci_read_config_dword(utils->pci, offset, buffer); - }else { - status = pci_write_config_dword(utils->pci, offset, *buffer); - } - return status; -} -static -mlx_status -mlx_pci_config( - IN mlx_utils *utils, - IN mlx_boolean read, - IN mlx_pci_width width, - IN mlx_uint32 offset, - IN mlx_uintn count, - IN OUT mlx_void *buffer - ) -{ - mlx_status status = MLX_SUCCESS; - mlx_uint8 *tmp = (mlx_uint8*)buffer; - mlx_uintn iteration = 0; - if( width == MlxPciWidthUint64) { - width = MlxPciWidthUint32; - count = count * 2; - } - - for(;iteration < count ; iteration++) { - switch (width){ - case MlxPciWidthUint8: - status = mlx_pci_config_byte(utils, read , offset++, tmp++); - break; - case MlxPciWidthUint16: - status = mlx_pci_config_word(utils, read , offset, (mlx_uint16*)tmp); - tmp += 2; - offset += 2; - break; - case MlxPciWidthUint32: - status = mlx_pci_config_dword(utils, read , offset, (mlx_uint32*)tmp); - tmp += 4; - offset += 4; - break; - default: - status = MLX_INVALID_PARAMETER; - } - if(status != MLX_SUCCESS) { - goto config_error; - } - } -config_error: - return status; -} -mlx_status -mlx_pci_init_priv( - IN mlx_utils *utils - ) -{ - mlx_status status = MLX_SUCCESS; - adjust_pci_device ( utils->pci ); -#ifdef DEVICE_CX3 - utils->config = ioremap ( pci_bar_start ( utils->pci, PCI_BASE_ADDRESS_0), - 0x100000 ); -#endif - return status; -} - -mlx_status -mlx_pci_read_priv( - IN mlx_utils *utils, - IN mlx_pci_width width, - IN mlx_uint32 offset, - IN mlx_uintn count, - OUT mlx_void *buffer - ) -{ - mlx_status status = MLX_SUCCESS; - status = mlx_pci_config(utils, TRUE, width, offset, count, buffer); - return status; -} - -mlx_status -mlx_pci_write_priv( - IN mlx_utils *utils, - IN mlx_pci_width width, - IN mlx_uint32 offset, - IN mlx_uintn count, - IN mlx_void *buffer - ) -{ - mlx_status status = MLX_SUCCESS; - status = mlx_pci_config(utils, FALSE, width, offset, count, buffer); - return status; -} - -mlx_status -mlx_pci_mem_read_priv( - IN mlx_utils *utils __attribute__ ((unused)), - IN mlx_pci_width width __attribute__ ((unused)), - IN mlx_uint8 bar_index __attribute__ ((unused)), - IN mlx_uint64 offset, - IN mlx_uintn count __attribute__ ((unused)), - OUT mlx_void *buffer - ) -{ - if (buffer == NULL || width != MlxPciWidthUint32) - return MLX_INVALID_PARAMETER; - *((mlx_uint32 *)buffer) = readl(offset); - return MLX_SUCCESS; -} - -mlx_status -mlx_pci_mem_write_priv( - IN mlx_utils *utils __attribute__ ((unused)), - IN mlx_pci_width width __attribute__ ((unused)), - IN mlx_uint8 bar_index __attribute__ ((unused)), - IN mlx_uint64 offset, - IN mlx_uintn count __attribute__ ((unused)), - IN mlx_void *buffer - ) -{ - if (buffer == NULL || width != MlxPciWidthUint32) - return MLX_INVALID_PARAMETER; - barrier(); - writel(*((mlx_uint32 *)buffer), offset); - return MLX_SUCCESS; -} diff --git a/roms/ipxe/src/drivers/infiniband/mlx_utils_flexboot/src/mlx_utils_priv.c b/roms/ipxe/src/drivers/infiniband/mlx_utils_flexboot/src/mlx_utils_priv.c deleted file mode 100644 index 5fca406fc..000000000 --- a/roms/ipxe/src/drivers/infiniband/mlx_utils_flexboot/src/mlx_utils_priv.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - * MlxUtilsPriv.c - * - * Created on: Jan 25, 2015 - * Author: maord - */ - -#include <unistd.h> -#include <stdlib.h> -#include <strings.h> -#include "../../mlx_utils/include/private/mlx_utils_priv.h" - -mlx_status -mlx_utils_delay_in_ms_priv( - IN mlx_uint32 msecs - ) -{ - mdelay(msecs); - return MLX_SUCCESS; -} - -mlx_status -mlx_utils_delay_in_us_priv( - IN mlx_uint32 usecs - ) -{ - udelay(usecs); - return MLX_SUCCESS; -} - -mlx_status -mlx_utils_ilog2_priv( - IN mlx_uint32 i, - OUT mlx_uint32 *log - ) -{ - *log = ( fls ( i ) - 1 ); - return MLX_SUCCESS; -} - -mlx_status -mlx_utils_init_lock_priv( - OUT void **lock __unused - ) -{ - return MLX_SUCCESS; -} - -mlx_status -mlx_utils_free_lock_priv( - IN void *lock __unused - ) -{ - return MLX_SUCCESS; -} - -mlx_status -mlx_utils_acquire_lock_priv ( - IN void *lock __unused - ) -{ - return MLX_SUCCESS; -} - -mlx_status -mlx_utils_release_lock_priv ( - IN void *lock __unused - ) -{ - return MLX_SUCCESS; -} - -mlx_status -mlx_utils_rand_priv ( - IN mlx_utils *utils __unused, - OUT mlx_uint32 *rand_num - ) -{ - do { - *rand_num = rand(); - } while ( *rand_num == 0 ); - return MLX_SUCCESS; -} diff --git a/roms/ipxe/src/drivers/infiniband/nodnic_prm.h b/roms/ipxe/src/drivers/infiniband/nodnic_prm.h deleted file mode 100644 index 5e0fa9890..000000000 --- a/roms/ipxe/src/drivers/infiniband/nodnic_prm.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#ifndef SRC_DRIVERS_INFINIBAND_MLX_NODNIC_INCLUDE_PRM_NODNIC_PRM_H_ -#define SRC_DRIVERS_INFINIBAND_MLX_NODNIC_INCLUDE_PRM_NODNIC_PRM_H_ - -#include "mlx_bitops.h" - -struct nodnic_wqe_segment_data_ptr_st { /* Little Endian */ - pseudo_bit_t byte_count[0x0001f]; - pseudo_bit_t always0[0x00001]; -/* -------------- */ - pseudo_bit_t l_key[0x00020]; -/* -------------- */ - pseudo_bit_t local_address_h[0x00020]; -/* -------------- */ - pseudo_bit_t local_address_l[0x00020]; -/* -------------- */ -}; - -struct MLX_DECLARE_STRUCT ( nodnic_wqe_segment_data_ptr ); - -#define HERMON_MAX_SCATTER 1 - -struct nodnic_recv_wqe { - struct nodnic_wqe_segment_data_ptr data[HERMON_MAX_SCATTER]; -} __attribute__ (( packed )); - -#endif /* SRC_DRIVERS_INFINIBAND_MLX_NODNIC_INCLUDE_PRM_NODNIC_PRM_H_ */ diff --git a/roms/ipxe/src/drivers/infiniband/nodnic_shomron_prm.h b/roms/ipxe/src/drivers/infiniband/nodnic_shomron_prm.h deleted file mode 100644 index 85cd97187..000000000 --- a/roms/ipxe/src/drivers/infiniband/nodnic_shomron_prm.h +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (C) 2015 Mellanox Technologies Ltd. - * - * 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER ); - -#ifndef SRC_DRIVERS_INFINIBAND_MLX_NODNIC_INCLUDE_PRM_NODNIC_SHOMRON_PRM_H_ -#define SRC_DRIVERS_INFINIBAND_MLX_NODNIC_INCLUDE_PRM_NODNIC_SHOMRON_PRM_H_ - - - -#include "nodnic_prm.h" - - -#define SHOMRON_MAX_GATHER 1 - -/* Send wqe segment ctrl */ - -struct shomronprm_wqe_segment_ctrl_send_st { /* Little Endian */ - pseudo_bit_t opcode[0x00008]; - pseudo_bit_t wqe_index[0x00010]; - pseudo_bit_t reserved1[0x00008]; -/* -------------- */ - pseudo_bit_t ds[0x00006]; /* descriptor (wqe) size in 16bytes chunk */ - pseudo_bit_t reserved2[0x00002]; - pseudo_bit_t qpn[0x00018]; -/* -------------- */ - pseudo_bit_t reserved3[0x00002]; - pseudo_bit_t ce[0x00002]; - pseudo_bit_t reserved4[0x0001c]; -/* -------------- */ - pseudo_bit_t reserved5[0x00040]; -/* -------------- */ - pseudo_bit_t mss[0x0000e]; - pseudo_bit_t reserved6[0x0000e]; - pseudo_bit_t cs13_inner[0x00001]; - pseudo_bit_t cs14_inner[0x00001]; - pseudo_bit_t cs13[0x00001]; - pseudo_bit_t cs14[0x00001]; -/* -------------- */ - pseudo_bit_t reserved7[0x00020]; -/* -------------- */ - pseudo_bit_t inline_headers1[0x00010]; - pseudo_bit_t inline_headers_size[0x0000a]; //sum size of inline_hdr1+inline_hdrs (0x10) - pseudo_bit_t reserved8[0x00006]; -/* -------------- */ - pseudo_bit_t inline_headers2[0x00020]; -/* -------------- */ - pseudo_bit_t inline_headers3[0x00020]; -/* -------------- */ - pseudo_bit_t inline_headers4[0x00020]; -/* -------------- */ - pseudo_bit_t inline_headers5[0x00020]; -}; - - - -/* Completion Queue Entry Format #### michal - fixed by gdror */ - -struct shomronprm_completion_queue_entry_st { /* Little Endian */ - - pseudo_bit_t reserved1[0x00080]; -/* -------------- */ - pseudo_bit_t reserved2[0x00010]; - pseudo_bit_t ml_path[0x00007]; - pseudo_bit_t reserved3[0x00009]; -/* -------------- */ - pseudo_bit_t slid[0x00010]; - pseudo_bit_t reserved4[0x00010]; -/* -------------- */ - pseudo_bit_t rqpn[0x00018]; - pseudo_bit_t sl[0x00004]; - pseudo_bit_t l3_hdr[0x00002]; - pseudo_bit_t reserved5[0x00002]; -/* -------------- */ - pseudo_bit_t reserved10[0x00020]; -/* -------------- */ - pseudo_bit_t srqn[0x00018]; - pseudo_bit_t reserved11[0x0008]; -/* -------------- */ - pseudo_bit_t pkey_index[0x00020]; -/* -------------- */ - pseudo_bit_t reserved6[0x00020]; -/* -------------- */ - pseudo_bit_t byte_cnt[0x00020]; -/* -------------- */ - pseudo_bit_t reserved7[0x00040]; -/* -------------- */ - pseudo_bit_t qpn[0x00018]; - pseudo_bit_t rx_drop_counter[0x00008]; -/* -------------- */ - pseudo_bit_t owner[0x00001]; - pseudo_bit_t reserved8[0x00003]; - pseudo_bit_t opcode[0x00004]; - pseudo_bit_t reserved9[0x00008]; - pseudo_bit_t wqe_counter[0x00010]; -}; - - -/* Completion with Error CQE #### michal - gdror fixed */ - -struct shomronprm_completion_with_error_st { /* Little Endian */ - pseudo_bit_t reserved1[0x001a0]; - /* -------------- */ - pseudo_bit_t syndrome[0x00008]; - pseudo_bit_t vendor_error_syndrome[0x00008]; - pseudo_bit_t reserved2[0x00010]; - /* -------------- */ - pseudo_bit_t reserved3[0x00040]; -}; - - -struct MLX_DECLARE_STRUCT ( shomronprm_wqe_segment_ctrl_send ); -struct MLX_DECLARE_STRUCT ( shomronprm_completion_queue_entry ); -struct MLX_DECLARE_STRUCT ( shomronprm_completion_with_error ); - -struct shomron_nodnic_eth_send_wqe { - struct shomronprm_wqe_segment_ctrl_send ctrl; - struct nodnic_wqe_segment_data_ptr data[SHOMRON_MAX_GATHER]; -} __attribute__ (( packed )); - -union shomronprm_completion_entry { - struct shomronprm_completion_queue_entry normal; - struct shomronprm_completion_with_error error; -} __attribute__ (( packed )); - - -#endif /* SRC_DRIVERS_INFINIBAND_MLX_NODNIC_INCLUDE_PRM_NODNIC_SHOMRON_PRM_H_ */ diff --git a/roms/ipxe/src/drivers/infiniband/qib7322.c b/roms/ipxe/src/drivers/infiniband/qib7322.c index af7006e04..e22f2349a 100644 --- a/roms/ipxe/src/drivers/infiniband/qib7322.c +++ b/roms/ipxe/src/drivers/infiniband/qib7322.c @@ -137,21 +137,32 @@ struct qib7322 { * This card requires atomic 64-bit accesses. Strange things happen * if you try to use 32-bit accesses; sometimes they work, sometimes * they don't, sometimes you get random data. + * + * These accessors use the "movq" MMX instruction, and so won't work + * on really old Pentiums (which won't have PCIe anyway, so this is + * something of a moot point). */ /** * Read QIB7322 qword register * * @v qib7322 QIB7322 device - * @v qword Register buffer to read into + * @v dwords Register buffer to read into * @v offset Register offset */ -static void qib7322_readq ( struct qib7322 *qib7322, uint64_t *qword, +static void qib7322_readq ( struct qib7322 *qib7322, uint32_t *dwords, unsigned long offset ) { - *qword = readq ( qib7322->regs + offset ); + void *addr = ( qib7322->regs + offset ); + + __asm__ __volatile__ ( "movq (%1), %%mm0\n\t" + "movq %%mm0, (%0)\n\t" + : : "r" ( dwords ), "r" ( addr ) : "memory" ); + + DBGIO ( "[%08lx] => %08x%08x\n", + virt_to_phys ( addr ), dwords[1], dwords[0] ); } #define qib7322_readq( _qib7322, _ptr, _offset ) \ - qib7322_readq ( (_qib7322), (_ptr)->u.qwords, (_offset) ) + qib7322_readq ( (_qib7322), (_ptr)->u.dwords, (_offset) ) #define qib7322_readq_array8b( _qib7322, _ptr, _offset, _idx ) \ qib7322_readq ( (_qib7322), (_ptr), ( (_offset) + ( (_idx) * 8 ) ) ) #define qib7322_readq_array64k( _qib7322, _ptr, _offset, _idx ) \ @@ -163,15 +174,22 @@ static void qib7322_readq ( struct qib7322 *qib7322, uint64_t *qword, * Write QIB7322 qword register * * @v qib7322 QIB7322 device - * @v qword Register buffer to write + * @v dwords Register buffer to write * @v offset Register offset */ -static void qib7322_writeq ( struct qib7322 *qib7322, const uint64_t *qword, +static void qib7322_writeq ( struct qib7322 *qib7322, const uint32_t *dwords, unsigned long offset ) { - writeq ( *qword, ( qib7322->regs + offset ) ); + void *addr = ( qib7322->regs + offset ); + + DBGIO ( "[%08lx] <= %08x%08x\n", + virt_to_phys ( addr ), dwords[1], dwords[0] ); + + __asm__ __volatile__ ( "movq (%0), %%mm0\n\t" + "movq %%mm0, (%1)\n\t" + : : "r" ( dwords ), "r" ( addr ) : "memory" ); } #define qib7322_writeq( _qib7322, _ptr, _offset ) \ - qib7322_writeq ( (_qib7322), (_ptr)->u.qwords, (_offset) ) + qib7322_writeq ( (_qib7322), (_ptr)->u.dwords, (_offset) ) #define qib7322_writeq_array8b( _qib7322, _ptr, _offset, _idx ) \ qib7322_writeq ( (_qib7322), (_ptr), ( (_offset) + ( (_idx) * 8 ) ) ) #define qib7322_writeq_array64k( _qib7322, _ptr, _offset, _idx ) \ @@ -1507,15 +1525,8 @@ static void qib7322_complete_recv ( struct ib_device *ibdev, /* Completing the eager buffer described in * this header entry. */ - if ( payload_len <= iob_tailroom ( iobuf ) ) { - iob_put ( iobuf, payload_len ); - rc = ( err ? - -EIO : ( useegrbfr ? 0 : -ECANCELED ) ); - } else { - DBGC ( qib7322, "QIB7322 %p bad payload len " - "%zd\n", qib7322, payload_len ); - rc = -EPROTO; - } + iob_put ( iobuf, payload_len ); + rc = ( err ? -EIO : ( useegrbfr ? 0 : -ECANCELED ) ); /* Redirect to target QP if necessary */ if ( qp != intended_qp ) { DBGC2 ( qib7322, "QIB7322 %p redirecting QPN " @@ -1526,7 +1537,7 @@ static void qib7322_complete_recv ( struct ib_device *ibdev, intended_qp->recv.fill++; } ib_complete_recv ( ibdev, intended_qp, &dest, &source, - iobuf, rc ); + iobuf, rc); } else { /* Completing on a skipped-over eager buffer */ ib_complete_recv ( ibdev, qp, &dest, &source, iobuf, @@ -2296,7 +2307,7 @@ static int qib7322_probe ( struct pci_device *pci ) { /* Fix up PCI device */ adjust_pci_device ( pci ); - /* Map PCI BARs */ + /* Get PCI BARs */ qib7322->regs = ioremap ( pci->membase, QIB7322_BAR0_SIZE ); DBGC2 ( qib7322, "QIB7322 %p has BAR at %08lx\n", qib7322, pci->membase ); @@ -2391,7 +2402,6 @@ static int qib7322_probe ( struct pci_device *pci ) { err_init_recv: err_read_eeprom: err_init_i2c: - iounmap ( qib7322->regs ); free ( qib7322 ); err_alloc_qib7322: return rc; @@ -2414,7 +2424,6 @@ static void qib7322_remove ( struct pci_device *pci ) { ibdev_put ( qib7322->ibdev[i] ); qib7322_fini_send ( qib7322 ); qib7322_fini_recv ( qib7322 ); - iounmap ( qib7322->regs ); free ( qib7322 ); } diff --git a/roms/ipxe/src/drivers/infiniband/qib7322.h b/roms/ipxe/src/drivers/infiniband/qib7322.h index dab95cfc0..72797b240 100644 --- a/roms/ipxe/src/drivers/infiniband/qib7322.h +++ b/roms/ipxe/src/drivers/infiniband/qib7322.h @@ -33,8 +33,8 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); * */ -#define PSEUDOBIT_LITTLE_ENDIAN -#include <ipxe/pseudobit.h> +#define BITOPS_LITTLE_ENDIAN +#include <ipxe/bitops.h> #include "qib_7322_regs.h" /** A QIB7322 GPIO register */ diff --git a/roms/ipxe/src/drivers/net/3c595.c b/roms/ipxe/src/drivers/net/3c595.c index 92d38cfc5..2338c54b7 100644 --- a/roms/ipxe/src/drivers/net/3c595.c +++ b/roms/ipxe/src/drivers/net/3c595.c @@ -391,7 +391,7 @@ vxsetlink(void) { int i, j; char *reason, *warning; - static signed char prev_conn = -1; + static char prev_conn = -1; if (prev_conn == -1) { prev_conn = vx_connector; diff --git a/roms/ipxe/src/drivers/net/3c5x9.c b/roms/ipxe/src/drivers/net/3c5x9.c index d7c09f77c..4d9bc8d9e 100644 --- a/roms/ipxe/src/drivers/net/3c5x9.c +++ b/roms/ipxe/src/drivers/net/3c5x9.c @@ -108,7 +108,7 @@ static void t509_enable ( struct nic *nic ) { else if (connector == utp) { GO_WINDOW(nic->ioaddr,4); outw(ENABLE_UTP, nic->ioaddr + EP_W4_MEDIA_TYPE); - mdelay(2000); /* Give time for media to negotiate */ + sleep(2); /* Give time for media to negotiate */ GO_WINDOW(nic->ioaddr,1); } diff --git a/roms/ipxe/src/drivers/net/acm.c b/roms/ipxe/src/drivers/net/acm.c deleted file mode 100644 index 16dab4be8..000000000 --- a/roms/ipxe/src/drivers/net/acm.c +++ /dev/null @@ -1,529 +0,0 @@ -/* - * Copyright (C) 2015 Michael Brown <mbrown@fensystems.co.uk>. - * - * 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 (at your option) 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 <stdint.h> -#include <string.h> -#include <errno.h> -#include <byteswap.h> -#include <ipxe/profile.h> -#include <ipxe/usb.h> -#include <ipxe/usbnet.h> -#include <ipxe/rndis.h> -#include "acm.h" - -/** @file - * - * USB RNDIS driver - * - */ - -/** Interrupt completion profiler */ -static struct profiler acm_intr_profiler __profiler = - { .name = "acm.intr" }; - -/** Bulk IN completion profiler */ -static struct profiler acm_in_profiler __profiler = - { .name = "acm.in" }; - -/** Bulk OUT profiler */ -static struct profiler acm_out_profiler __profiler = - { .name = "acm.out" }; - -/****************************************************************************** - * - * USB RNDIS communications interface - * - ****************************************************************************** - */ - -/** - * Complete interrupt transfer - * - * @v ep USB endpoint - * @v iobuf I/O buffer - * @v rc Completion status code - */ -static void acm_intr_complete ( struct usb_endpoint *ep, - struct io_buffer *iobuf, int rc ) { - struct acm_device *acm = container_of ( ep, struct acm_device, - usbnet.intr ); - struct rndis_device *rndis = acm->rndis; - struct usb_setup_packet *message; - - /* Profile completions */ - profile_start ( &acm_intr_profiler ); - - /* Ignore packets cancelled when the endpoint closes */ - if ( ! ep->open ) - goto ignore; - - /* Drop packets with errors */ - if ( rc != 0 ) { - DBGC ( acm, "ACM %p interrupt failed: %s\n", - acm, strerror ( rc ) ); - DBGC_HDA ( acm, 0, iobuf->data, iob_len ( iobuf ) ); - goto error; - } - - /* Extract message header */ - if ( iob_len ( iobuf ) < sizeof ( *message ) ) { - DBGC ( acm, "ACM %p underlength interrupt:\n", acm ); - DBGC_HDA ( acm, 0, iobuf->data, iob_len ( iobuf ) ); - rc = -EINVAL; - goto error; - } - message = iobuf->data; - - /* Parse message header */ - switch ( message->request ) { - - case cpu_to_le16 ( CDC_RESPONSE_AVAILABLE ) : - case cpu_to_le16 ( 0x0001 ) : /* qemu seems to use this value */ - acm->responded = 1; - break; - - default: - DBGC ( acm, "ACM %p unrecognised interrupt:\n", acm ); - DBGC_HDA ( acm, 0, iobuf->data, iob_len ( iobuf ) ); - rc = -ENOTSUP; - goto error; - } - - /* Free I/O buffer */ - free_iob ( iobuf ); - profile_stop ( &acm_intr_profiler ); - - return; - - error: - rndis_rx_err ( rndis, iob_disown ( iobuf ), rc ); - ignore: - free_iob ( iobuf ); - return; -} - -/** Interrupt endpoint operations */ -static struct usb_endpoint_driver_operations acm_intr_operations = { - .complete = acm_intr_complete, -}; - -/****************************************************************************** - * - * USB RNDIS data interface - * - ****************************************************************************** - */ - -/** - * Complete bulk IN transfer - * - * @v ep USB endpoint - * @v iobuf I/O buffer - * @v rc Completion status code - */ -static void acm_in_complete ( struct usb_endpoint *ep, struct io_buffer *iobuf, - int rc ) { - struct acm_device *acm = container_of ( ep, struct acm_device, - usbnet.in ); - struct rndis_device *rndis = acm->rndis; - - /* Profile receive completions */ - profile_start ( &acm_in_profiler ); - - /* Ignore packets cancelled when the endpoint closes */ - if ( ! ep->open ) - goto ignore; - - /* Record USB errors against the RNDIS device */ - if ( rc != 0 ) { - DBGC ( acm, "ACM %p bulk IN failed: %s\n", - acm, strerror ( rc ) ); - goto error; - } - - /* Hand off to RNDIS */ - rndis_rx ( rndis, iob_disown ( iobuf ) ); - - profile_stop ( &acm_in_profiler ); - return; - - error: - rndis_rx_err ( rndis, iob_disown ( iobuf ), rc ); - ignore: - free_iob ( iobuf ); -} - -/** Bulk IN endpoint operations */ -static struct usb_endpoint_driver_operations acm_in_operations = { - .complete = acm_in_complete, -}; - -/** - * Transmit packet - * - * @v acm USB RNDIS device - * @v iobuf I/O buffer - * @ret rc Return status code - */ -static int acm_out_transmit ( struct acm_device *acm, - struct io_buffer *iobuf ) { - int rc; - - /* Profile transmissions */ - profile_start ( &acm_out_profiler ); - - /* Enqueue I/O buffer */ - if ( ( rc = usb_stream ( &acm->usbnet.out, iobuf, 0 ) ) != 0 ) - return rc; - - profile_stop ( &acm_out_profiler ); - return 0; -} - -/** - * Complete bulk OUT transfer - * - * @v ep USB endpoint - * @v iobuf I/O buffer - * @v rc Completion status code - */ -static void acm_out_complete ( struct usb_endpoint *ep, struct io_buffer *iobuf, - int rc ) { - struct acm_device *acm = container_of ( ep, struct acm_device, - usbnet.out ); - struct rndis_device *rndis = acm->rndis; - - /* Report TX completion */ - rndis_tx_complete_err ( rndis, iobuf, rc ); -} - -/** Bulk OUT endpoint operations */ -static struct usb_endpoint_driver_operations acm_out_operations = { - .complete = acm_out_complete, -}; - -/****************************************************************************** - * - * USB RNDIS control interface - * - ****************************************************************************** - */ - -/** - * Send control packet - * - * @v acm USB RNDIS device - * @v iobuf I/O buffer - * @ret rc Return status code - */ -static int acm_control_transmit ( struct acm_device *acm, - struct io_buffer *iobuf ) { - struct rndis_device *rndis = acm->rndis; - struct usb_device *usb = acm->usb; - int rc; - - /* Send packet as an encapsulated command */ - if ( ( rc = cdc_send_encapsulated_command ( usb, acm->usbnet.comms, - iobuf->data, - iob_len ( iobuf ) ) ) != 0){ - DBGC ( acm, "ACM %p could not send encapsulated command: %s\n", - acm, strerror ( rc ) ); - return rc; - } - - /* Complete packet immediately */ - rndis_tx_complete ( rndis, iobuf ); - - return 0; -} - -/** - * Receive control packet - * - * @v acm USB RNDIS device - * @ret rc Return status code - */ -static int acm_control_receive ( struct acm_device *acm ) { - struct rndis_device *rndis = acm->rndis; - struct usb_device *usb = acm->usb; - struct io_buffer *iobuf; - struct rndis_header *header; - size_t mtu = ACM_RESPONSE_MTU; - size_t len; - int rc; - - /* Allocate I/O buffer */ - iobuf = alloc_iob ( mtu ); - if ( ! iobuf ) { - rc = -ENOMEM; - goto err_alloc; - } - - /* Get encapsulated response */ - if ( ( rc = cdc_get_encapsulated_response ( usb, acm->usbnet.comms, - iobuf->data, mtu ) ) != 0 ){ - DBGC ( acm, "ACM %p could not get encapsulated response: %s\n", - acm, strerror ( rc ) ); - goto err_get_response; - } - - /* Fix up buffer length */ - header = iobuf->data; - len = le32_to_cpu ( header->len ); - if ( len > mtu ) { - DBGC ( acm, "ACM %p overlength encapsulated response\n", acm ); - DBGC_HDA ( acm, 0, iobuf->data, mtu ); - rc = -EPROTO; - goto err_len; - } - iob_put ( iobuf, len ); - - /* Hand off to RNDIS */ - rndis_rx ( rndis, iob_disown ( iobuf ) ); - - return 0; - - err_len: - err_get_response: - free_iob ( iobuf ); - err_alloc: - return rc; -} - -/****************************************************************************** - * - * RNDIS interface - * - ****************************************************************************** - */ - -/** - * Open RNDIS device - * - * @v rndis RNDIS device - * @ret rc Return status code - */ -static int acm_open ( struct rndis_device *rndis ) { - struct acm_device *acm = rndis->priv; - int rc; - - /* Open USB network device */ - if ( ( rc = usbnet_open ( &acm->usbnet ) ) != 0 ) - goto err_open; - - return 0; - - usbnet_close ( &acm->usbnet ); - err_open: - return rc; -} - -/** - * Close RNDIS device - * - * @v rndis RNDIS device - */ -static void acm_close ( struct rndis_device *rndis ) { - struct acm_device *acm = rndis->priv; - - /* Close USB network device */ - usbnet_close ( &acm->usbnet ); -} - -/** - * Transmit packet - * - * @v rndis RNDIS device - * @v iobuf I/O buffer - * @ret rc Return status code - */ -static int acm_transmit ( struct rndis_device *rndis, - struct io_buffer *iobuf ) { - struct acm_device *acm = rndis->priv; - struct rndis_header *header = iobuf->data; - - /* Sanity check */ - assert ( iob_len ( iobuf ) >= sizeof ( *header ) ); - assert ( iob_len ( iobuf ) == le32_to_cpu ( header->len ) ); - - /* Transmit packet via appropriate mechanism */ - if ( header->type == cpu_to_le32 ( RNDIS_PACKET_MSG ) ) { - return acm_out_transmit ( acm, iobuf ); - } else { - return acm_control_transmit ( acm, iobuf ); - } -} - -/** - * Poll for completed and received packets - * - * @v rndis RNDIS device - */ -static void acm_poll ( struct rndis_device *rndis ) { - struct acm_device *acm = rndis->priv; - int rc; - - /* Poll USB bus */ - usb_poll ( acm->bus ); - - /* Refill rings */ - if ( ( rc = usbnet_refill ( &acm->usbnet ) ) != 0 ) - rndis_rx_err ( rndis, NULL, rc ); - - /* Retrieve encapsulated response, if applicable */ - if ( acm->responded ) { - - /* Clear flag */ - acm->responded = 0; - - /* Get encapsulated response */ - if ( ( rc = acm_control_receive ( acm ) ) != 0 ) - rndis_rx_err ( rndis, NULL, rc ); - } -} - -/** USB RNDIS operations */ -static struct rndis_operations acm_operations = { - .open = acm_open, - .close = acm_close, - .transmit = acm_transmit, - .poll = acm_poll, -}; - -/****************************************************************************** - * - * USB interface - * - ****************************************************************************** - */ - -/** - * Probe device - * - * @v func USB function - * @v config Configuration descriptor - * @ret rc Return status code - */ -static int acm_probe ( struct usb_function *func, - struct usb_configuration_descriptor *config ) { - struct usb_device *usb = func->usb; - struct rndis_device *rndis; - struct acm_device *acm; - int rc; - - /* Allocate and initialise structure */ - rndis = alloc_rndis ( sizeof ( *acm ) ); - if ( ! rndis ) { - rc = -ENOMEM; - goto err_alloc; - } - rndis_init ( rndis, &acm_operations ); - rndis->netdev->dev = &func->dev; - acm = rndis->priv; - acm->usb = usb; - acm->bus = usb->port->hub->bus; - acm->rndis = rndis; - usbnet_init ( &acm->usbnet, func, &acm_intr_operations, - &acm_in_operations, &acm_out_operations ); - usb_refill_init ( &acm->usbnet.intr, 0, 0, ACM_INTR_MAX_FILL ); - usb_refill_init ( &acm->usbnet.in, 0, ACM_IN_MTU, ACM_IN_MAX_FILL ); - - /* Describe USB network device */ - if ( ( rc = usbnet_describe ( &acm->usbnet, config ) ) != 0 ) { - DBGC ( acm, "ACM %p could not describe: %s\n", - acm, strerror ( rc ) ); - goto err_describe; - } - - /* Register RNDIS device */ - if ( ( rc = register_rndis ( rndis ) ) != 0 ) - goto err_register; - - usb_func_set_drvdata ( func, acm ); - return 0; - - unregister_rndis ( rndis ); - err_register: - err_describe: - free_rndis ( rndis ); - err_alloc: - return rc; -} - -/** - * Remove device - * - * @v func USB function - */ -static void acm_remove ( struct usb_function *func ) { - struct acm_device *acm = usb_func_get_drvdata ( func ); - struct rndis_device *rndis = acm->rndis; - - /* Unregister RNDIS device */ - unregister_rndis ( rndis ); - - /* Free RNDIS device */ - free_rndis ( rndis ); -} - -/** USB CDC-ACM device IDs */ -static struct usb_device_id cdc_acm_ids[] = { - { - .name = "cdc-acm", - .vendor = USB_ANY_ID, - .product = USB_ANY_ID, - }, -}; - -/** USB CDC-ACM driver */ -struct usb_driver cdc_acm_driver __usb_driver = { - .ids = cdc_acm_ids, - .id_count = ( sizeof ( cdc_acm_ids ) / sizeof ( cdc_acm_ids[0] ) ), - .class = USB_CLASS_ID ( USB_CLASS_CDC, USB_SUBCLASS_CDC_ACM, - USB_PROTOCOL_ACM_RNDIS ), - .score = USB_SCORE_DEPRECATED, - .probe = acm_probe, - .remove = acm_remove, -}; - -/** USB RF-RNDIS device IDs */ -static struct usb_device_id rf_rndis_ids[] = { - { - .name = "rf-rndis", - .vendor = USB_ANY_ID, - .product = USB_ANY_ID, - }, -}; - -/** USB RF-RNDIS driver */ -struct usb_driver rf_rndis_driver __usb_driver = { - .ids = rf_rndis_ids, - .id_count = ( sizeof ( rf_rndis_ids ) / sizeof ( rf_rndis_ids[0] ) ), - .class = USB_CLASS_ID ( USB_CLASS_WIRELESS, USB_SUBCLASS_WIRELESS_RADIO, - USB_PROTOCOL_RADIO_RNDIS ), - .score = USB_SCORE_DEPRECATED, - .probe = acm_probe, - .remove = acm_remove, -}; diff --git a/roms/ipxe/src/drivers/net/acm.h b/roms/ipxe/src/drivers/net/acm.h deleted file mode 100644 index d4944967b..000000000 --- a/roms/ipxe/src/drivers/net/acm.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef _ACM_H -#define _ACM_H - -/** @file - * - * USB RNDIS Ethernet driver - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#include <ipxe/usb.h> -#include <ipxe/cdc.h> - -/** CDC-ACM subclass */ -#define USB_SUBCLASS_CDC_ACM 0x02 - -/** CDC-ACM RNDIS device protocol */ -#define USB_PROTOCOL_ACM_RNDIS 0xff - -/** Class code for wireless devices */ -#define USB_CLASS_WIRELESS 0xe0 - -/** Radio frequency device subclass */ -#define USB_SUBCLASS_WIRELESS_RADIO 0x01 - -/** Radio frequency RNDIS device protocol */ -#define USB_PROTOCOL_RADIO_RNDIS 0x03 - -/** A USB RNDIS network device */ -struct acm_device { - /** USB device */ - struct usb_device *usb; - /** USB bus */ - struct usb_bus *bus; - /** RNDIS device */ - struct rndis_device *rndis; - /** USB network device */ - struct usbnet_device usbnet; - - /** An encapsulated response is available */ - int responded; -}; - -/** Interrupt maximum fill level - * - * This is a policy decision. - */ -#define ACM_INTR_MAX_FILL 2 - -/** Bulk IN maximum fill level - * - * This is a policy decision. - */ -#define ACM_IN_MAX_FILL 8 - -/** Bulk IN buffer size - * - * This is a policy decision. - */ -#define ACM_IN_MTU 2048 - -/** Encapsulated response buffer size - * - * This is a policy decision. - */ -#define ACM_RESPONSE_MTU 128 - -#endif /* _ACM_H */ diff --git a/roms/ipxe/src/drivers/net/ath/ath.h b/roms/ipxe/src/drivers/net/ath/ath.h index d6a037394..42ad59f78 100644 --- a/roms/ipxe/src/drivers/net/ath/ath.h +++ b/roms/ipxe/src/drivers/net/ath/ath.h @@ -101,6 +101,8 @@ static inline u32 get_unaligned_le32(const void *p) */ #define ATH_KEYMAX 128 /* max key cache size we handle */ +static const u8 ath_bcast_mac[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; + struct ath_ani { int caldone; unsigned int longcal_timer; @@ -227,6 +229,10 @@ struct ath_common { int btcoex_enabled; }; +struct io_buffer *ath_rxbuf_alloc(struct ath_common *common, + u32 len, + u32 *iob_addr); + void ath_hw_setbssidmask(struct ath_common *common); int ath_hw_keyreset(struct ath_common *common, u16 entry); void ath_hw_cycle_counters_update(struct ath_common *common); diff --git a/roms/ipxe/src/drivers/net/ath/ath5k/ath5k.c b/roms/ipxe/src/drivers/net/ath/ath5k/ath5k.c index a6a65a2e9..92c4ffdf4 100644 --- a/roms/ipxe/src/drivers/net/ath/ath5k/ath5k.c +++ b/roms/ipxe/src/drivers/net/ath/ath5k/ath5k.c @@ -85,6 +85,46 @@ static struct pci_device_id ath5k_nics[] = { PCI_ROM(0x168c, 0x001d, "ath2417", "Atheros 2417 Nala", AR5K_AR5212), }; +/* Known SREVs */ +static const struct ath5k_srev_name srev_names[] = { + { "5210", AR5K_VERSION_MAC, AR5K_SREV_AR5210 }, + { "5311", AR5K_VERSION_MAC, AR5K_SREV_AR5311 }, + { "5311A", AR5K_VERSION_MAC, AR5K_SREV_AR5311A }, + { "5311B", AR5K_VERSION_MAC, AR5K_SREV_AR5311B }, + { "5211", AR5K_VERSION_MAC, AR5K_SREV_AR5211 }, + { "5212", AR5K_VERSION_MAC, AR5K_SREV_AR5212 }, + { "5213", AR5K_VERSION_MAC, AR5K_SREV_AR5213 }, + { "5213A", AR5K_VERSION_MAC, AR5K_SREV_AR5213A }, + { "2413", AR5K_VERSION_MAC, AR5K_SREV_AR2413 }, + { "2414", AR5K_VERSION_MAC, AR5K_SREV_AR2414 }, + { "5424", AR5K_VERSION_MAC, AR5K_SREV_AR5424 }, + { "5413", AR5K_VERSION_MAC, AR5K_SREV_AR5413 }, + { "5414", AR5K_VERSION_MAC, AR5K_SREV_AR5414 }, + { "2415", AR5K_VERSION_MAC, AR5K_SREV_AR2415 }, + { "5416", AR5K_VERSION_MAC, AR5K_SREV_AR5416 }, + { "5418", AR5K_VERSION_MAC, AR5K_SREV_AR5418 }, + { "2425", AR5K_VERSION_MAC, AR5K_SREV_AR2425 }, + { "2417", AR5K_VERSION_MAC, AR5K_SREV_AR2417 }, + { "xxxxx", AR5K_VERSION_MAC, AR5K_SREV_UNKNOWN }, + { "5110", AR5K_VERSION_RAD, AR5K_SREV_RAD_5110 }, + { "5111", AR5K_VERSION_RAD, AR5K_SREV_RAD_5111 }, + { "5111A", AR5K_VERSION_RAD, AR5K_SREV_RAD_5111A }, + { "2111", AR5K_VERSION_RAD, AR5K_SREV_RAD_2111 }, + { "5112", AR5K_VERSION_RAD, AR5K_SREV_RAD_5112 }, + { "5112A", AR5K_VERSION_RAD, AR5K_SREV_RAD_5112A }, + { "5112B", AR5K_VERSION_RAD, AR5K_SREV_RAD_5112B }, + { "2112", AR5K_VERSION_RAD, AR5K_SREV_RAD_2112 }, + { "2112A", AR5K_VERSION_RAD, AR5K_SREV_RAD_2112A }, + { "2112B", AR5K_VERSION_RAD, AR5K_SREV_RAD_2112B }, + { "2413", AR5K_VERSION_RAD, AR5K_SREV_RAD_2413 }, + { "5413", AR5K_VERSION_RAD, AR5K_SREV_RAD_5413 }, + { "2316", AR5K_VERSION_RAD, AR5K_SREV_RAD_2316 }, + { "2317", AR5K_VERSION_RAD, AR5K_SREV_RAD_2317 }, + { "5424", AR5K_VERSION_RAD, AR5K_SREV_RAD_5424 }, + { "5133", AR5K_VERSION_RAD, AR5K_SREV_RAD_5133 }, + { "xxxxx", AR5K_VERSION_RAD, AR5K_SREV_UNKNOWN }, +}; + #define ATH5K_SPMBL_NO 1 #define ATH5K_SPMBL_YES 2 #define ATH5K_SPMBL_BOTH 3 diff --git a/roms/ipxe/src/drivers/net/ath/ath5k/ath5k_phy.c b/roms/ipxe/src/drivers/net/ath/ath5k/ath5k_phy.c index c2a66a4d3..7891d39ea 100644 --- a/roms/ipxe/src/drivers/net/ath/ath5k/ath5k_phy.c +++ b/roms/ipxe/src/drivers/net/ath/ath5k/ath5k_phy.c @@ -1219,12 +1219,12 @@ static int ath5k_hw_rf5110_calibrate(struct ath5k_hw *ah, /* Update radio registers */ ath5k_hw_reg_write(ah, (phy_sig & ~(AR5K_PHY_SIG_FIRPWR)) | - AR5K_REG_SM(-1U, AR5K_PHY_SIG_FIRPWR), AR5K_PHY_SIG); + AR5K_REG_SM(-1, AR5K_PHY_SIG_FIRPWR), AR5K_PHY_SIG); ath5k_hw_reg_write(ah, (phy_agc & ~(AR5K_PHY_AGCCOARSE_HI | AR5K_PHY_AGCCOARSE_LO)) | - AR5K_REG_SM(-1U, AR5K_PHY_AGCCOARSE_HI) | - AR5K_REG_SM(-127U, AR5K_PHY_AGCCOARSE_LO), AR5K_PHY_AGCCOARSE); + AR5K_REG_SM(-1, AR5K_PHY_AGCCOARSE_HI) | + AR5K_REG_SM(-127, AR5K_PHY_AGCCOARSE_LO), AR5K_PHY_AGCCOARSE); ath5k_hw_reg_write(ah, (phy_sat & ~(AR5K_PHY_ADCSAT_ICNT | AR5K_PHY_ADCSAT_THR)) | diff --git a/roms/ipxe/src/drivers/net/ath/ath5k/ath5k_reset.c b/roms/ipxe/src/drivers/net/ath/ath5k/ath5k_reset.c index 73765a7b0..2f36a4e9a 100644 --- a/roms/ipxe/src/drivers/net/ath/ath5k/ath5k_reset.c +++ b/roms/ipxe/src/drivers/net/ath/ath5k/ath5k_reset.c @@ -134,6 +134,14 @@ static int ath5k_hw_write_ofdm_timings(struct ath5k_hw *ah, return 0; } + +/* + * index into rates for control rates, we can set it up like this because + * this is only used for AR5212 and we know it supports G mode + */ +static const unsigned int control_rates[] = + { 0, 1, 1, 1, 4, 4, 6, 6, 8, 8, 8, 8 }; + /** * ath5k_hw_write_rate_duration - fill rate code to duration table * diff --git a/roms/ipxe/src/drivers/net/ath/ath9k/ar9002_initvals.h b/roms/ipxe/src/drivers/net/ath/ath9k/ar9002_initvals.h index f9a92c9b7..d7a5ac09f 100644 --- a/roms/ipxe/src/drivers/net/ath/ath9k/ar9002_initvals.h +++ b/roms/ipxe/src/drivers/net/ath/ath9k/ar9002_initvals.h @@ -16,7 +16,7 @@ FILE_LICENCE ( BSD2 ); -static __unused const u32 ar9280Modes_9280_2[][6] = { +static const u32 ar9280Modes_9280_2[][6] = { {0x00001030, 0x00000230, 0x00000460, 0x000002c0, 0x00000160, 0x000001e0}, {0x00001070, 0x00000168, 0x000002d0, 0x00000318, 0x0000018c, 0x000001e0}, {0x000010b0, 0x00000e60, 0x00001cc0, 0x00007c70, 0x00003e38, 0x00001180}, @@ -65,7 +65,7 @@ static __unused const u32 ar9280Modes_9280_2[][6] = { {0x00007894, 0x5a508000, 0x5a508000, 0x5a508000, 0x5a508000, 0x5a508000}, }; -static __unused const u32 ar9280Common_9280_2[][2] = { +static const u32 ar9280Common_9280_2[][2] = { /* Addr allmodes */ {0x0000000c, 0x00000000}, {0x00000030, 0x00020015}, @@ -409,7 +409,7 @@ static __unused const u32 ar9280Common_9280_2[][2] = { {0x00007898, 0x2a850160}, }; -static __unused const u32 ar9280Modes_fast_clock_9280_2[][3] = { +static const u32 ar9280Modes_fast_clock_9280_2[][3] = { /* Addr 5G_HT20 5G_HT40 */ {0x00001030, 0x00000268, 0x000004d0}, {0x00001070, 0x0000018c, 0x00000318}, @@ -426,7 +426,7 @@ static __unused const u32 ar9280Modes_fast_clock_9280_2[][3] = { {0x00009918, 0x0000000b, 0x00000016}, }; -static __unused const u32 ar9280Modes_backoff_23db_rxgain_9280_2[][6] = { +static const u32 ar9280Modes_backoff_23db_rxgain_9280_2[][6] = { {0x00009a00, 0x00008184, 0x00008184, 0x00000290, 0x00000290, 0x00000290}, {0x00009a04, 0x00008188, 0x00008188, 0x00000300, 0x00000300, 0x00000300}, {0x00009a08, 0x0000818c, 0x0000818c, 0x00000304, 0x00000304, 0x00000304}, @@ -559,7 +559,7 @@ static __unused const u32 ar9280Modes_backoff_23db_rxgain_9280_2[][6] = { {0x0000a848, 0x00001066, 0x00001066, 0x00001055, 0x00001055, 0x00001055}, }; -static __unused const u32 ar9280Modes_original_rxgain_9280_2[][6] = { +static const u32 ar9280Modes_original_rxgain_9280_2[][6] = { {0x00009a00, 0x00008184, 0x00008184, 0x00008000, 0x00008000, 0x00008000}, {0x00009a04, 0x00008188, 0x00008188, 0x00008000, 0x00008000, 0x00008000}, {0x00009a08, 0x0000818c, 0x0000818c, 0x00008000, 0x00008000, 0x00008000}, @@ -692,7 +692,7 @@ static __unused const u32 ar9280Modes_original_rxgain_9280_2[][6] = { {0x0000a848, 0x00001066, 0x00001066, 0x00001063, 0x00001063, 0x00001063}, }; -static __unused const u32 ar9280Modes_backoff_13db_rxgain_9280_2[][6] = { +static const u32 ar9280Modes_backoff_13db_rxgain_9280_2[][6] = { {0x00009a00, 0x00008184, 0x00008184, 0x00000290, 0x00000290, 0x00000290}, {0x00009a04, 0x00008188, 0x00008188, 0x00000300, 0x00000300, 0x00000300}, {0x00009a08, 0x0000818c, 0x0000818c, 0x00000304, 0x00000304, 0x00000304}, @@ -825,7 +825,7 @@ static __unused const u32 ar9280Modes_backoff_13db_rxgain_9280_2[][6] = { {0x0000a848, 0x00001066, 0x00001066, 0x0000105a, 0x0000105a, 0x0000105a}, }; -static __unused const u32 ar9280Modes_high_power_tx_gain_9280_2[][6] = { +static const u32 ar9280Modes_high_power_tx_gain_9280_2[][6] = { {0x0000a274, 0x0a19e652, 0x0a19e652, 0x0a1aa652, 0x0a1aa652, 0x0a1aa652}, {0x0000a27c, 0x050739ce, 0x050739ce, 0x050739ce, 0x050739ce, 0x050739ce}, {0x0000a300, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, @@ -859,7 +859,7 @@ static __unused const u32 ar9280Modes_high_power_tx_gain_9280_2[][6] = { {0x00007844, 0xf258a480, 0xf258a480, 0xf258a480, 0xf258a480, 0xf258a480}, }; -static __unused const u32 ar9280Modes_original_tx_gain_9280_2[][6] = { +static const u32 ar9280Modes_original_tx_gain_9280_2[][6] = { {0x0000a274, 0x0a19c652, 0x0a19c652, 0x0a1aa652, 0x0a1aa652, 0x0a1aa652}, {0x0000a27c, 0x050701ce, 0x050701ce, 0x050701ce, 0x050701ce, 0x050701ce}, {0x0000a300, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, @@ -893,7 +893,7 @@ static __unused const u32 ar9280Modes_original_tx_gain_9280_2[][6] = { {0x00007844, 0x92592480, 0x92592480, 0x92592480, 0x92592480, 0x92592480}, }; -static __unused const u32 ar9280PciePhy_clkreq_off_L1_9280[][2] = { +static const u32 ar9280PciePhy_clkreq_off_L1_9280[][2] = { /* Addr allmodes */ {0x00004040, 0x9248fd00}, {0x00004040, 0x24924924}, @@ -907,7 +907,7 @@ static __unused const u32 ar9280PciePhy_clkreq_off_L1_9280[][2] = { {0x00004044, 0x00000000}, }; -static __unused const u32 ar9280PciePhy_clkreq_always_on_L1_9280[][2] = { +static const u32 ar9280PciePhy_clkreq_always_on_L1_9280[][2] = { /* Addr allmodes */ {0x00004040, 0x9248fd00}, {0x00004040, 0x24924924}, @@ -921,7 +921,7 @@ static __unused const u32 ar9280PciePhy_clkreq_always_on_L1_9280[][2] = { {0x00004044, 0x00000000}, }; -static __unused const u32 ar9285PciePhy_clkreq_always_on_L1_9285[][2] = { +static const u32 ar9285PciePhy_clkreq_always_on_L1_9285[][2] = { /* Addr allmodes */ {0x00004040, 0x9248fd00}, {0x00004040, 0x24924924}, @@ -935,7 +935,7 @@ static __unused const u32 ar9285PciePhy_clkreq_always_on_L1_9285[][2] = { {0x00004044, 0x00000000}, }; -static __unused const u32 ar9285PciePhy_clkreq_off_L1_9285[][2] = { +static const u32 ar9285PciePhy_clkreq_off_L1_9285[][2] = { /* Addr allmodes */ {0x00004040, 0x9248fd00}, {0x00004040, 0x24924924}, @@ -949,7 +949,7 @@ static __unused const u32 ar9285PciePhy_clkreq_off_L1_9285[][2] = { {0x00004044, 0x00000000}, }; -static __unused const u32 ar9285Modes_9285_1_2[][6] = { +static const u32 ar9285Modes_9285_1_2[][6] = { {0x00001030, 0x00000230, 0x00000460, 0x000002c0, 0x00000160, 0x000001e0}, {0x00001070, 0x00000168, 0x000002d0, 0x00000318, 0x0000018c, 0x000001e0}, {0x000010b0, 0x00000e60, 0x00001cc0, 0x00007c70, 0x00003e38, 0x00001180}, @@ -1254,7 +1254,7 @@ static __unused const u32 ar9285Modes_9285_1_2[][6] = { {0x0000a358, 0x7999aa02, 0x7999aa02, 0x7999aa0e, 0x7999aa0e, 0x7999aa0e}, }; -static __unused const u32 ar9285Common_9285_1_2[][2] = { +static const u32 ar9285Common_9285_1_2[][2] = { /* Addr allmodes */ {0x0000000c, 0x00000000}, {0x00000030, 0x00020045}, @@ -1574,7 +1574,7 @@ static __unused const u32 ar9285Common_9285_1_2[][2] = { {0x00007870, 0x10142c00}, }; -static __unused const u32 ar9285Modes_high_power_tx_gain_9285_1_2[][6] = { +static const u32 ar9285Modes_high_power_tx_gain_9285_1_2[][6] = { {0x0000a300, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, {0x0000a304, 0x00000000, 0x00000000, 0x00006200, 0x00006200, 0x00000000}, {0x0000a308, 0x00000000, 0x00000000, 0x00008201, 0x00008201, 0x00000000}, @@ -1614,7 +1614,7 @@ static __unused const u32 ar9285Modes_high_power_tx_gain_9285_1_2[][6] = { {0x0000a3e0, 0x000000e7, 0x000000e7, 0x000000e7, 0x000000e7, 0x000000e7}, }; -static __unused const u32 ar9285Modes_original_tx_gain_9285_1_2[][6] = { +static const u32 ar9285Modes_original_tx_gain_9285_1_2[][6] = { {0x0000a300, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, {0x0000a304, 0x00000000, 0x00000000, 0x00009200, 0x00009200, 0x00000000}, {0x0000a308, 0x00000000, 0x00000000, 0x00010208, 0x00010208, 0x00000000}, @@ -1654,7 +1654,7 @@ static __unused const u32 ar9285Modes_original_tx_gain_9285_1_2[][6] = { {0x0000a3e0, 0x0000039c, 0x0000039c, 0x0000039c, 0x0000039c, 0x0000039c}, }; -static __unused const u32 ar9285Modes_XE2_0_normal_power[][6] = { +static const u32 ar9285Modes_XE2_0_normal_power[][6] = { {0x0000a300, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, {0x0000a304, 0x00000000, 0x00000000, 0x00009200, 0x00009200, 0x00000000}, {0x0000a308, 0x00000000, 0x00000000, 0x00010208, 0x00010208, 0x00000000}, @@ -1694,7 +1694,7 @@ static __unused const u32 ar9285Modes_XE2_0_normal_power[][6] = { {0x0000a3e0, 0x0000039c, 0x0000039c, 0x0000039c, 0x0000039c, 0x0000039c}, }; -static __unused const u32 ar9285Modes_XE2_0_high_power[][6] = { +static const u32 ar9285Modes_XE2_0_high_power[][6] = { {0x0000a300, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, {0x0000a304, 0x00000000, 0x00000000, 0x00006200, 0x00006200, 0x00000000}, {0x0000a308, 0x00000000, 0x00000000, 0x00008201, 0x00008201, 0x00000000}, @@ -1734,7 +1734,7 @@ static __unused const u32 ar9285Modes_XE2_0_high_power[][6] = { {0x0000a3e0, 0x000000e7, 0x000000e7, 0x000000e7, 0x000000e7, 0x000000e7}, }; -static __unused const u32 ar9285PciePhy_clkreq_always_on_L1_9285_1_2[][2] = { +static const u32 ar9285PciePhy_clkreq_always_on_L1_9285_1_2[][2] = { /* Addr allmodes */ {0x00004040, 0x9248fd00}, {0x00004040, 0x24924924}, @@ -1748,7 +1748,7 @@ static __unused const u32 ar9285PciePhy_clkreq_always_on_L1_9285_1_2[][2] = { {0x00004044, 0x00000000}, }; -static __unused const u32 ar9285PciePhy_clkreq_off_L1_9285_1_2[][2] = { +static const u32 ar9285PciePhy_clkreq_off_L1_9285_1_2[][2] = { /* Addr allmodes */ {0x00004040, 0x9248fd00}, {0x00004040, 0x24924924}, @@ -1762,7 +1762,7 @@ static __unused const u32 ar9285PciePhy_clkreq_off_L1_9285_1_2[][2] = { {0x00004044, 0x00000000}, }; -static __unused const u32 ar9287Modes_9287_1_1[][6] = { +static const u32 ar9287Modes_9287_1_1[][6] = { {0x00001030, 0x00000000, 0x00000000, 0x000002c0, 0x00000160, 0x000001e0}, {0x00001070, 0x00000000, 0x00000000, 0x00000318, 0x0000018c, 0x000001e0}, {0x000010b0, 0x00000000, 0x00000000, 0x00007c70, 0x00003e38, 0x00001180}, @@ -1808,7 +1808,7 @@ static __unused const u32 ar9287Modes_9287_1_1[][6] = { {0x0000a3d8, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, }; -static __unused const u32 ar9287Common_9287_1_1[][2] = { +static const u32 ar9287Common_9287_1_1[][2] = { /* Addr allmodes */ {0x0000000c, 0x00000000}, {0x00000030, 0x00020015}, @@ -2177,21 +2177,21 @@ static __unused const u32 ar9287Common_9287_1_1[][2] = { {0x000078b8, 0x2a850160}, }; -static __unused const u32 ar9287Common_normal_cck_fir_coeff_9287_1_1[][2] = { +static const u32 ar9287Common_normal_cck_fir_coeff_9287_1_1[][2] = { /* Addr allmodes */ {0x0000a1f4, 0x00fffeff}, {0x0000a1f8, 0x00f5f9ff}, {0x0000a1fc, 0xb79f6427}, }; -static __unused const u32 ar9287Common_japan_2484_cck_fir_coeff_9287_1_1[][2] = { +static const u32 ar9287Common_japan_2484_cck_fir_coeff_9287_1_1[][2] = { /* Addr allmodes */ {0x0000a1f4, 0x00000000}, {0x0000a1f8, 0xefff0301}, {0x0000a1fc, 0xca9228ee}, }; -static __unused const u32 ar9287Modes_tx_gain_9287_1_1[][6] = { +static const u32 ar9287Modes_tx_gain_9287_1_1[][6] = { {0x0000a300, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, {0x0000a304, 0x00000000, 0x00000000, 0x00004002, 0x00004002, 0x00004002}, {0x0000a308, 0x00000000, 0x00000000, 0x00008004, 0x00008004, 0x00008004}, @@ -2239,7 +2239,7 @@ static __unused const u32 ar9287Modes_tx_gain_9287_1_1[][6] = { {0x0000a274, 0x0a180000, 0x0a180000, 0x0a1aa000, 0x0a1aa000, 0x0a1aa000}, }; -static __unused const u32 ar9287Modes_rx_gain_9287_1_1[][6] = { +static const u32 ar9287Modes_rx_gain_9287_1_1[][6] = { {0x00009a00, 0x00000000, 0x00000000, 0x0000a120, 0x0000a120, 0x0000a120}, {0x00009a04, 0x00000000, 0x00000000, 0x0000a124, 0x0000a124, 0x0000a124}, {0x00009a08, 0x00000000, 0x00000000, 0x0000a128, 0x0000a128, 0x0000a128}, @@ -2500,7 +2500,7 @@ static __unused const u32 ar9287Modes_rx_gain_9287_1_1[][6] = { {0x0000a848, 0x00000000, 0x00000000, 0x00001067, 0x00001067, 0x00001067}, }; -static __unused const u32 ar9287PciePhy_clkreq_always_on_L1_9287_1_1[][2] = { +static const u32 ar9287PciePhy_clkreq_always_on_L1_9287_1_1[][2] = { /* Addr allmodes */ {0x00004040, 0x9248fd00}, {0x00004040, 0x24924924}, @@ -2514,7 +2514,7 @@ static __unused const u32 ar9287PciePhy_clkreq_always_on_L1_9287_1_1[][2] = { {0x00004044, 0x00000000}, }; -static __unused const u32 ar9287PciePhy_clkreq_off_L1_9287_1_1[][2] = { +static const u32 ar9287PciePhy_clkreq_off_L1_9287_1_1[][2] = { /* Addr allmodes */ {0x00004040, 0x9248fd00}, {0x00004040, 0x24924924}, @@ -2528,7 +2528,7 @@ static __unused const u32 ar9287PciePhy_clkreq_off_L1_9287_1_1[][2] = { {0x00004044, 0x00000000}, }; -static __unused const u32 ar9271Modes_9271[][6] = { +static const u32 ar9271Modes_9271[][6] = { {0x00001030, 0x00000230, 0x00000460, 0x000002c0, 0x00000160, 0x000001e0}, {0x00001070, 0x00000168, 0x000002d0, 0x00000318, 0x0000018c, 0x000001e0}, {0x000010b0, 0x00000e60, 0x00001cc0, 0x00007c70, 0x00003e38, 0x00001180}, @@ -2834,7 +2834,7 @@ static __unused const u32 ar9271Modes_9271[][6] = { {0x0000a358, 0x7999aa02, 0x7999aa02, 0x7999aa0e, 0x7999aa0e, 0x7999aa0e}, }; -static __unused const u32 ar9271Common_9271[][2] = { +static const u32 ar9271Common_9271[][2] = { /* Addr allmodes */ {0x0000000c, 0x00000000}, {0x00000030, 0x00020045}, @@ -3163,26 +3163,26 @@ static __unused const u32 ar9271Common_9271[][2] = { {0x0000d384, 0xf3307ff0}, }; -static __unused const u32 ar9271Common_normal_cck_fir_coeff_9271[][2] = { +static const u32 ar9271Common_normal_cck_fir_coeff_9271[][2] = { /* Addr allmodes */ {0x0000a1f4, 0x00fffeff}, {0x0000a1f8, 0x00f5f9ff}, {0x0000a1fc, 0xb79f6427}, }; -static __unused const u32 ar9271Common_japan_2484_cck_fir_coeff_9271[][2] = { +static const u32 ar9271Common_japan_2484_cck_fir_coeff_9271[][2] = { /* Addr allmodes */ {0x0000a1f4, 0x00000000}, {0x0000a1f8, 0xefff0301}, {0x0000a1fc, 0xca9228ee}, }; -static __unused const u32 ar9271Modes_9271_1_0_only[][6] = { +static const u32 ar9271Modes_9271_1_0_only[][6] = { {0x00009910, 0x30002311, 0x30002311, 0x30002311, 0x30002311, 0x30002311}, {0x00009828, 0x0a020001, 0x0a020001, 0x0a020001, 0x0a020001, 0x0a020001}, }; -static __unused const u32 ar9271Modes_9271_ANI_reg[][6] = { +static const u32 ar9271Modes_9271_ANI_reg[][6] = { {0x00009850, 0x6d4000e2, 0x6d4000e2, 0x6d4000e2, 0x6d4000e2, 0x6d4000e2}, {0x0000985c, 0x3139605e, 0x3139605e, 0x3137605e, 0x3137605e, 0x3139605e}, {0x00009858, 0x7ec84d2e, 0x7ec84d2e, 0x7ec84d2e, 0x7ec84d2e, 0x7ec84d2e}, @@ -3193,7 +3193,7 @@ static __unused const u32 ar9271Modes_9271_ANI_reg[][6] = { {0x000099c0, 0x05eea6d4, 0x05eea6d4, 0x05eea6d4, 0x05eea6d4, 0x05eea6d4}, }; -static __unused const u32 ar9271Modes_normal_power_tx_gain_9271[][6] = { +static const u32 ar9271Modes_normal_power_tx_gain_9271[][6] = { {0x0000a300, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, {0x0000a304, 0x00000000, 0x00000000, 0x00009200, 0x00009200, 0x00000000}, {0x0000a308, 0x00000000, 0x00000000, 0x00010208, 0x00010208, 0x00000000}, @@ -3229,7 +3229,7 @@ static __unused const u32 ar9271Modes_normal_power_tx_gain_9271[][6] = { {0x0000a3e0, 0x000003bd, 0x000003bd, 0x000003bd, 0x000003bd, 0x000003bd}, }; -static __unused const u32 ar9271Modes_high_power_tx_gain_9271[][6] = { +static const u32 ar9271Modes_high_power_tx_gain_9271[][6] = { {0x0000a300, 0x00000000, 0x00000000, 0x00010000, 0x00010000, 0x00000000}, {0x0000a304, 0x00000000, 0x00000000, 0x00016200, 0x00016200, 0x00000000}, {0x0000a308, 0x00000000, 0x00000000, 0x00018201, 0x00018201, 0x00000000}, diff --git a/roms/ipxe/src/drivers/net/ath/ath9k/ar9003_2p2_initvals.h b/roms/ipxe/src/drivers/net/ath/ath9k/ar9003_2p2_initvals.h index b1303bbaa..e8ac70da5 100644 --- a/roms/ipxe/src/drivers/net/ath/ath9k/ar9003_2p2_initvals.h +++ b/roms/ipxe/src/drivers/net/ath/ath9k/ar9003_2p2_initvals.h @@ -19,7 +19,7 @@ /* AR9003 2.2 */ -static __unused const u32 ar9300_2p2_radio_postamble[][5] = { +static const u32 ar9300_2p2_radio_postamble[][5] = { /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */ {0x0001609c, 0x0dd08f29, 0x0dd08f29, 0x0b283f31, 0x0b283f31}, {0x000160ac, 0xa4653c00, 0xa4653c00, 0x24652800, 0x24652800}, @@ -32,7 +32,7 @@ static __unused const u32 ar9300_2p2_radio_postamble[][5] = { {0x00016940, 0x10804008, 0x10804008, 0x50804008, 0x50804008}, }; -static __unused const u32 ar9300Modes_lowest_ob_db_tx_gain_table_2p2[][5] = { +static const u32 ar9300Modes_lowest_ob_db_tx_gain_table_2p2[][5] = { /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */ {0x0000a2dc, 0x00033800, 0x00033800, 0x03aaa352, 0x03aaa352}, {0x0000a2e0, 0x0003c000, 0x0003c000, 0x03ccc584, 0x03ccc584}, @@ -138,7 +138,7 @@ static __unused const u32 ar9300Modes_lowest_ob_db_tx_gain_table_2p2[][5] = { {0x00016868, 0x6db6db6c, 0x6db6db6c, 0x6db6db6c, 0x6db6db6c}, }; -static __unused const u32 ar9300Modes_fast_clock_2p2[][3] = { +static const u32 ar9300Modes_fast_clock_2p2[][3] = { /* Addr 5G_HT20 5G_HT40 */ {0x00001030, 0x00000268, 0x000004d0}, {0x00001070, 0x0000018c, 0x00000318}, @@ -151,7 +151,7 @@ static __unused const u32 ar9300Modes_fast_clock_2p2[][3] = { {0x0000a254, 0x00000898, 0x00001130}, }; -static __unused const u32 ar9300_2p2_radio_core[][2] = { +static const u32 ar9300_2p2_radio_core[][2] = { /* Addr allmodes */ {0x00016000, 0x36db6db6}, {0x00016004, 0x6db6db40}, @@ -295,7 +295,7 @@ static __unused const u32 ar9300_2p2_radio_core[][2] = { {0x00016bd4, 0x00000000}, }; -static __unused const u32 ar9300Common_rx_gain_table_merlin_2p2[][2] = { +static const u32 ar9300Common_rx_gain_table_merlin_2p2[][2] = { /* Addr allmodes */ {0x0000a000, 0x02000101}, {0x0000a004, 0x02000102}, @@ -555,7 +555,7 @@ static __unused const u32 ar9300Common_rx_gain_table_merlin_2p2[][2] = { {0x0000b1fc, 0x00000776}, }; -static __unused const u32 ar9300_2p2_mac_postamble[][5] = { +static const u32 ar9300_2p2_mac_postamble[][5] = { /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */ {0x00001030, 0x00000230, 0x00000460, 0x000002c0, 0x00000160}, {0x00001070, 0x00000168, 0x000002d0, 0x00000318, 0x0000018c}, @@ -567,12 +567,12 @@ static __unused const u32 ar9300_2p2_mac_postamble[][5] = { {0x00008318, 0x00003e80, 0x00007d00, 0x00006880, 0x00003440}, }; -static __unused const u32 ar9300_2p2_soc_postamble[][5] = { +static const u32 ar9300_2p2_soc_postamble[][5] = { /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */ {0x00007010, 0x00000023, 0x00000023, 0x00000023, 0x00000023}, }; -static __unused const u32 ar9200_merlin_2p2_radio_core[][2] = { +static const u32 ar9200_merlin_2p2_radio_core[][2] = { /* Addr allmodes */ {0x00007800, 0x00040000}, {0x00007804, 0xdb005012}, @@ -614,7 +614,7 @@ static __unused const u32 ar9200_merlin_2p2_radio_core[][2] = { {0x00007894, 0x5a108000}, }; -static __unused const u32 ar9300_2p2_baseband_postamble[][5] = { +static const u32 ar9300_2p2_baseband_postamble[][5] = { /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */ {0x00009810, 0xd00a8005, 0xd00a8005, 0xd00a8011, 0xd00a8011}, {0x00009820, 0x206a022e, 0x206a022e, 0x206a012e, 0x206a012e}, @@ -670,7 +670,7 @@ static __unused const u32 ar9300_2p2_baseband_postamble[][5] = { {0x0000c284, 0x00000000, 0x00000000, 0x00000150, 0x00000150}, }; -static __unused const u32 ar9300_2p2_baseband_core[][2] = { +static const u32 ar9300_2p2_baseband_core[][2] = { /* Addr allmodes */ {0x00009800, 0xafe68e30}, {0x00009804, 0xfd14e000}, @@ -833,7 +833,7 @@ static __unused const u32 ar9300_2p2_baseband_core[][2] = { {0x0000c420, 0x00000000}, }; -static __unused const u32 ar9300Modes_high_power_tx_gain_table_2p2[][5] = { +static const u32 ar9300Modes_high_power_tx_gain_table_2p2[][5] = { /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */ {0x0000a2dc, 0x0380c7fc, 0x0380c7fc, 0x03aaa352, 0x03aaa352}, {0x0000a2e0, 0x0000f800, 0x0000f800, 0x03ccc584, 0x03ccc584}, @@ -939,7 +939,7 @@ static __unused const u32 ar9300Modes_high_power_tx_gain_table_2p2[][5] = { {0x00016868, 0x6eb6db6c, 0x6eb6db6c, 0x6eb6db6c, 0x6eb6db6c}, }; -static __unused const u32 ar9300Modes_high_ob_db_tx_gain_table_2p2[][5] = { +static const u32 ar9300Modes_high_ob_db_tx_gain_table_2p2[][5] = { /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */ {0x0000a2dc, 0x01feee00, 0x01feee00, 0x03aaa352, 0x03aaa352}, {0x0000a2e0, 0x0000f000, 0x0000f000, 0x03ccc584, 0x03ccc584}, @@ -1045,7 +1045,7 @@ static __unused const u32 ar9300Modes_high_ob_db_tx_gain_table_2p2[][5] = { {0x00016868, 0x6db6db6c, 0x6db6db6c, 0x6db6db6c, 0x6db6db6c}, }; -static __unused const u32 ar9300Common_rx_gain_table_2p2[][2] = { +static const u32 ar9300Common_rx_gain_table_2p2[][2] = { /* Addr allmodes */ {0x0000a000, 0x00010000}, {0x0000a004, 0x00030002}, @@ -1305,7 +1305,7 @@ static __unused const u32 ar9300Common_rx_gain_table_2p2[][2] = { {0x0000b1fc, 0x00000196}, }; -static __unused const u32 ar9300Modes_low_ob_db_tx_gain_table_2p2[][5] = { +static const u32 ar9300Modes_low_ob_db_tx_gain_table_2p2[][5] = { /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */ {0x0000a2dc, 0x00033800, 0x00033800, 0x03aaa352, 0x03aaa352}, {0x0000a2e0, 0x0003c000, 0x0003c000, 0x03ccc584, 0x03ccc584}, @@ -1411,7 +1411,7 @@ static __unused const u32 ar9300Modes_low_ob_db_tx_gain_table_2p2[][5] = { {0x00016868, 0x6db6db6c, 0x6db6db6c, 0x6db6db6c, 0x6db6db6c}, }; -static __unused const u32 ar9300_2p2_mac_core[][2] = { +static const u32 ar9300_2p2_mac_core[][2] = { /* Addr allmodes */ {0x00000008, 0x00000000}, {0x00000030, 0x00020085}, @@ -1570,7 +1570,7 @@ static __unused const u32 ar9300_2p2_mac_core[][2] = { {0x000083d0, 0x000301ff}, }; -static __unused const u32 ar9300Common_wo_xlna_rx_gain_table_2p2[][2] = { +static const u32 ar9300Common_wo_xlna_rx_gain_table_2p2[][2] = { /* Addr allmodes */ {0x0000a000, 0x00010000}, {0x0000a004, 0x00030002}, @@ -1830,7 +1830,7 @@ static __unused const u32 ar9300Common_wo_xlna_rx_gain_table_2p2[][2] = { {0x0000b1fc, 0x00000196}, }; -static __unused const u32 ar9300_2p2_soc_preamble[][2] = { +static const u32 ar9300_2p2_soc_preamble[][2] = { /* Addr allmodes */ {0x000040a4, 0x00a0c1c9}, {0x00007008, 0x00000000}, @@ -1840,21 +1840,21 @@ static __unused const u32 ar9300_2p2_soc_preamble[][2] = { {0x00007048, 0x00000008}, }; -static __unused const u32 ar9300PciePhy_pll_on_clkreq_disable_L1_2p2[][2] = { +static const u32 ar9300PciePhy_pll_on_clkreq_disable_L1_2p2[][2] = { /* Addr allmodes */ {0x00004040, 0x0821265e}, {0x00004040, 0x0008003b}, {0x00004044, 0x00000000}, }; -static __unused const u32 ar9300PciePhy_clkreq_enable_L1_2p2[][2] = { +static const u32 ar9300PciePhy_clkreq_enable_L1_2p2[][2] = { /* Addr allmodes */ {0x00004040, 0x08253e5e}, {0x00004040, 0x0008003b}, {0x00004044, 0x00000000}, }; -static __unused const u32 ar9300PciePhy_clkreq_disable_L1_2p2[][2] = { +static const u32 ar9300PciePhy_clkreq_disable_L1_2p2[][2] = { /* Addr allmodes */ {0x00004040, 0x08213e5e}, {0x00004040, 0x0008003b}, diff --git a/roms/ipxe/src/drivers/net/ath/ath9k/ar9340_initvals.h b/roms/ipxe/src/drivers/net/ath/ath9k/ar9340_initvals.h index 784080b16..815a8af1b 100644 --- a/roms/ipxe/src/drivers/net/ath/ath9k/ar9340_initvals.h +++ b/roms/ipxe/src/drivers/net/ath/ath9k/ar9340_initvals.h @@ -17,7 +17,7 @@ #ifndef INITVALS_9340_H #define INITVALS_9340_H -static __unused const u32 ar9340_1p0_radio_postamble[][5] = { +static const u32 ar9340_1p0_radio_postamble[][5] = { /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */ {0x000160ac, 0xa4646800, 0xa4646800, 0xa4646800, 0xa4646800}, {0x0001610c, 0x08000000, 0x08000000, 0x00000000, 0x00000000}, @@ -26,7 +26,7 @@ static __unused const u32 ar9340_1p0_radio_postamble[][5] = { {0x00016540, 0x10804000, 0x10804000, 0x50804000, 0x50804000}, }; -static __unused const u32 ar9340Modes_lowest_ob_db_tx_gain_table_1p0[][5] = { +static const u32 ar9340Modes_lowest_ob_db_tx_gain_table_1p0[][5] = { /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */ {0x0000a410, 0x000050d9, 0x000050d9, 0x000050d9, 0x000050d9}, {0x0000a500, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, @@ -99,7 +99,7 @@ static __unused const u32 ar9340Modes_lowest_ob_db_tx_gain_table_1p0[][5] = { {0x00016448, 0x24925266, 0x24925266, 0x24925266, 0x24925266}, }; -static __unused const u32 ar9340Modes_fast_clock_1p0[][3] = { +static const u32 ar9340Modes_fast_clock_1p0[][3] = { /* Addr 5G_HT20 5G_HT40 */ {0x00001030, 0x00000268, 0x000004d0}, {0x00001070, 0x0000018c, 0x00000318}, @@ -112,7 +112,7 @@ static __unused const u32 ar9340Modes_fast_clock_1p0[][3] = { {0x0000a254, 0x00000898, 0x00001130}, }; -static __unused const u32 ar9340_1p0_radio_core[][2] = { +static const u32 ar9340_1p0_radio_core[][2] = { /* Addr allmodes */ {0x00016000, 0x36db6db6}, {0x00016004, 0x6db6db40}, @@ -218,13 +218,13 @@ static __unused const u32 ar9340_1p0_radio_core[][2] = { {0x000167d4, 0x00000000}, }; -static __unused const u32 ar9340_1p0_radio_core_40M[][2] = { +static const u32 ar9340_1p0_radio_core_40M[][2] = { {0x0001609c, 0x02566f3a}, {0x000160ac, 0xa4647c00}, {0x000160b0, 0x01885f5a}, }; -static __unused const u32 ar9340_1p0_mac_postamble[][5] = { +static const u32 ar9340_1p0_mac_postamble[][5] = { /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */ {0x00001030, 0x00000230, 0x00000460, 0x000002c0, 0x00000160}, {0x00001070, 0x00000168, 0x000002d0, 0x00000318, 0x0000018c}, @@ -236,12 +236,12 @@ static __unused const u32 ar9340_1p0_mac_postamble[][5] = { {0x00008318, 0x00003e80, 0x00007d00, 0x00006880, 0x00003440}, }; -static __unused const u32 ar9340_1p0_soc_postamble[][5] = { +static const u32 ar9340_1p0_soc_postamble[][5] = { /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */ {0x00007010, 0x00000023, 0x00000023, 0x00000023, 0x00000023}, }; -static __unused const u32 ar9340_1p0_baseband_postamble[][5] = { +static const u32 ar9340_1p0_baseband_postamble[][5] = { /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */ {0x00009810, 0xd00a8005, 0xd00a8005, 0xd00a8011, 0xd00a8011}, {0x00009820, 0x206a022e, 0x206a022e, 0x206a022e, 0x206a022e}, @@ -288,7 +288,7 @@ static __unused const u32 ar9340_1p0_baseband_postamble[][5] = { {0x0000b284, 0x00000000, 0x00000000, 0x00000150, 0x00000150}, }; -static __unused const u32 ar9340_1p0_baseband_core[][2] = { +static const u32 ar9340_1p0_baseband_core[][2] = { /* Addr allmodes */ {0x00009800, 0xafe68e30}, {0x00009804, 0xfd14e000}, @@ -464,7 +464,7 @@ static __unused const u32 ar9340_1p0_baseband_core[][2] = { {0x0000b420, 0x00000000}, }; -static __unused const u32 ar9340Modes_high_power_tx_gain_table_1p0[][5] = { +static const u32 ar9340Modes_high_power_tx_gain_table_1p0[][5] = { /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */ {0x0000a410, 0x000050d8, 0x000050d8, 0x000050d9, 0x000050d9}, {0x0000a500, 0x00002220, 0x00002220, 0x00000000, 0x00000000}, @@ -537,7 +537,7 @@ static __unused const u32 ar9340Modes_high_power_tx_gain_table_1p0[][5] = { {0x00016448, 0x24925266, 0x24925266, 0x24925266, 0x24925266}, }; -static __unused const u32 ar9340Modes_high_ob_db_tx_gain_table_1p0[][5] = { +static const u32 ar9340Modes_high_ob_db_tx_gain_table_1p0[][5] = { /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */ {0x0000a410, 0x000050d8, 0x000050d8, 0x000050d9, 0x000050d9}, {0x0000a500, 0x00002220, 0x00002220, 0x00000000, 0x00000000}, @@ -609,7 +609,7 @@ static __unused const u32 ar9340Modes_high_ob_db_tx_gain_table_1p0[][5] = { {0x00016444, 0x03b6d2e4, 0x03b6d2e4, 0x03b6d2e4, 0x03b6d2e4}, {0x00016448, 0x8e481266, 0x8e481266, 0x8e481266, 0x8e481266}, }; -static __unused const u32 ar9340Modes_ub124_tx_gain_table_1p0[][5] = { +static const u32 ar9340Modes_ub124_tx_gain_table_1p0[][5] = { /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */ {0x0000a410, 0x000050d8, 0x000050d8, 0x000050d9, 0x000050d9}, {0x0000a500, 0x00002220, 0x00002220, 0x00000000, 0x00000000}, @@ -683,7 +683,7 @@ static __unused const u32 ar9340Modes_ub124_tx_gain_table_1p0[][5] = { }; -static __unused const u32 ar9340Common_rx_gain_table_1p0[][2] = { +static const u32 ar9340Common_rx_gain_table_1p0[][2] = { /* Addr allmodes */ {0x0000a000, 0x00010000}, {0x0000a004, 0x00030002}, @@ -943,7 +943,7 @@ static __unused const u32 ar9340Common_rx_gain_table_1p0[][2] = { {0x0000b1fc, 0x00000196}, }; -static __unused const u32 ar9340Modes_low_ob_db_tx_gain_table_1p0[][5] = { +static const u32 ar9340Modes_low_ob_db_tx_gain_table_1p0[][5] = { /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */ {0x0000a410, 0x000050d9, 0x000050d9, 0x000050d9, 0x000050d9}, {0x0000a500, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, @@ -1016,7 +1016,7 @@ static __unused const u32 ar9340Modes_low_ob_db_tx_gain_table_1p0[][5] = { {0x00016448, 0x24925266, 0x24925266, 0x24925266, 0x24925266}, }; -static __unused const u32 ar9340Modes_mixed_ob_db_tx_gain_table_1p0[][5] = { +static const u32 ar9340Modes_mixed_ob_db_tx_gain_table_1p0[][5] = { /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */ {0x0000a410, 0x000050d9, 0x000050d9, 0x000050d9, 0x000050d9}, {0x0000a500, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, @@ -1089,7 +1089,7 @@ static __unused const u32 ar9340Modes_mixed_ob_db_tx_gain_table_1p0[][5] = { {0x00016448, 0x24927266, 0x24927266, 0x8e482266, 0x8e482266}, }; -static __unused const u32 ar9340_1p0_mac_core[][2] = { +static const u32 ar9340_1p0_mac_core[][2] = { /* Addr allmodes */ {0x00000008, 0x00000000}, {0x00000030, 0x00020085}, @@ -1253,7 +1253,7 @@ static __unused const u32 ar9340_1p0_mac_core[][2] = { {0x000083d0, 0x000301ff}, }; -static __unused const u32 ar9340Common_wo_xlna_rx_gain_table_1p0[][2] = { +static const u32 ar9340Common_wo_xlna_rx_gain_table_1p0[][2] = { /* Addr allmodes */ {0x0000a000, 0x00010000}, {0x0000a004, 0x00030002}, @@ -1513,7 +1513,7 @@ static __unused const u32 ar9340Common_wo_xlna_rx_gain_table_1p0[][2] = { {0x0000b1fc, 0x00000196}, }; -static __unused const u32 ar9340_1p0_soc_preamble[][2] = { +static const u32 ar9340_1p0_soc_preamble[][2] = { /* Addr allmodes */ {0x000040a4, 0x00a0c1c9}, {0x00007008, 0x00000000}, diff --git a/roms/ipxe/src/drivers/net/ath/ath9k/ar9485_initvals.h b/roms/ipxe/src/drivers/net/ath/ath9k/ar9485_initvals.h index c854398aa..611ea6ce8 100644 --- a/roms/ipxe/src/drivers/net/ath/ath9k/ar9485_initvals.h +++ b/roms/ipxe/src/drivers/net/ath/ath9k/ar9485_initvals.h @@ -17,7 +17,7 @@ #ifndef INITVALS_9485_H #define INITVALS_9485_H -static __unused const u32 ar9485_1_1_mac_core[][2] = { +static const u32 ar9485_1_1_mac_core[][2] = { /* Addr allmodes */ {0x00000008, 0x00000000}, {0x00000030, 0x00020085}, @@ -179,7 +179,7 @@ static __unused const u32 ar9485_1_1_mac_core[][2] = { {0x000083d0, 0x000301ff}, }; -static __unused const u32 ar9485_1_1_baseband_core[][2] = { +static const u32 ar9485_1_1_baseband_core[][2] = { /* Addr allmodes */ {0x00009800, 0xafe68e30}, {0x00009804, 0xfd14e000}, @@ -316,7 +316,7 @@ static __unused const u32 ar9485_1_1_baseband_core[][2] = { {0x0000a7dc, 0x00000000}, }; -static __unused const u32 ar9485Common_1_1[][2] = { +static const u32 ar9485Common_1_1[][2] = { /* Addr allmodes */ {0x00007010, 0x00000022}, {0x00007020, 0x00000000}, @@ -324,7 +324,7 @@ static __unused const u32 ar9485Common_1_1[][2] = { {0x00007038, 0x000004c2}, }; -static __unused const u32 ar9485_1_1_baseband_postamble[][5] = { +static const u32 ar9485_1_1_baseband_postamble[][5] = { /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */ {0x00009810, 0xd00a8005, 0xd00a8005, 0xd00a8005, 0xd00a8005}, {0x00009820, 0x206a002e, 0x206a002e, 0x206a002e, 0x206a002e}, @@ -369,7 +369,7 @@ static __unused const u32 ar9485_1_1_baseband_postamble[][5] = { {0x0000be18, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, }; -static __unused const u32 ar9485Modes_high_ob_db_tx_gain_1_1[][5] = { +static const u32 ar9485Modes_high_ob_db_tx_gain_1_1[][5] = { /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */ {0x000098bc, 0x00000002, 0x00000002, 0x00000002, 0x00000002}, {0x0000a410, 0x000050d9, 0x000050d9, 0x000050d8, 0x000050d8}, @@ -442,7 +442,7 @@ static __unused const u32 ar9485Modes_high_ob_db_tx_gain_1_1[][5] = { {0x00016048, 0x6c924260, 0x6c924260, 0x6c924260, 0x6c924260}, }; -static __unused const u32 ar9485_modes_lowest_ob_db_tx_gain_1_1[][5] = { +static const u32 ar9485_modes_lowest_ob_db_tx_gain_1_1[][5] = { /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */ {0x000098bc, 0x00000002, 0x00000002, 0x00000002, 0x00000002}, {0x0000a410, 0x000050d9, 0x000050d9, 0x000050d8, 0x000050d8}, @@ -515,7 +515,7 @@ static __unused const u32 ar9485_modes_lowest_ob_db_tx_gain_1_1[][5] = { {0x00016048, 0x6c924260, 0x6c924260, 0x6c924260, 0x6c924260}, }; -static __unused const u32 ar9485_1_1_radio_postamble[][2] = { +static const u32 ar9485_1_1_radio_postamble[][2] = { /* Addr allmodes */ {0x0001609c, 0x0b283f31}, {0x000160ac, 0x24611800}, @@ -524,7 +524,7 @@ static __unused const u32 ar9485_1_1_radio_postamble[][2] = { {0x00016140, 0x10804008}, }; -static __unused const u32 ar9485_1_1_mac_postamble[][5] = { +static const u32 ar9485_1_1_mac_postamble[][5] = { /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */ {0x00001030, 0x00000230, 0x00000460, 0x000002c0, 0x00000160}, {0x00001070, 0x00000168, 0x000002d0, 0x00000318, 0x0000018c}, @@ -536,7 +536,7 @@ static __unused const u32 ar9485_1_1_mac_postamble[][5] = { {0x00008318, 0x00003e80, 0x00007d00, 0x00006880, 0x00003440}, }; -static __unused const u32 ar9485_1_1_radio_core[][2] = { +static const u32 ar9485_1_1_radio_core[][2] = { /* Addr allmodes */ {0x00016000, 0x36db6db6}, {0x00016004, 0x6db6db40}, @@ -601,14 +601,14 @@ static __unused const u32 ar9485_1_1_radio_core[][2] = { {0x00016c44, 0x12000000}, }; -static __unused const u32 ar9485_1_1_pcie_phy_pll_on_clkreq_enable_L1[][2] = { +static const u32 ar9485_1_1_pcie_phy_pll_on_clkreq_enable_L1[][2] = { /* Addr allmodes */ {0x00018c00, 0x10052e5e}, {0x00018c04, 0x000801d8}, {0x00018c08, 0x0000080c}, }; -static __unused const u32 ar9485Modes_high_power_tx_gain_1_1[][5] = { +static const u32 ar9485Modes_high_power_tx_gain_1_1[][5] = { /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */ {0x000098bc, 0x00000002, 0x00000002, 0x00000002, 0x00000002}, {0x0000a410, 0x000050d9, 0x000050d9, 0x000050d8, 0x000050d8}, @@ -681,7 +681,7 @@ static __unused const u32 ar9485Modes_high_power_tx_gain_1_1[][5] = { {0x00016048, 0x6c924260, 0x6c924260, 0x6c924260, 0x6c924260}, }; -static __unused const u32 ar9485_1_1[][2] = { +static const u32 ar9485_1_1[][2] = { /* Addr allmodes */ {0x0000a580, 0x00000000}, {0x0000a584, 0x00000000}, @@ -701,7 +701,7 @@ static __unused const u32 ar9485_1_1[][2] = { {0x0000a5bc, 0x00000000}, }; -static __unused const u32 ar9485_modes_green_ob_db_tx_gain_1_1[][5] = { +static const u32 ar9485_modes_green_ob_db_tx_gain_1_1[][5] = { /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */ {0x000098bc, 0x00000003, 0x00000003, 0x00000003, 0x00000003}, {0x0000a410, 0x000050d9, 0x000050d9, 0x000050d8, 0x000050d8}, @@ -774,14 +774,14 @@ static __unused const u32 ar9485_modes_green_ob_db_tx_gain_1_1[][5] = { {0x00016048, 0x6c924260, 0x6c924260, 0x6c924260, 0x6c924260}, }; -static __unused const u32 ar9485_1_1_pcie_phy_clkreq_disable_L1[][2] = { +static const u32 ar9485_1_1_pcie_phy_clkreq_disable_L1[][2] = { /* Addr allmodes */ {0x00018c00, 0x10013e5e}, {0x00018c04, 0x000801d8}, {0x00018c08, 0x0000080c}, }; -static __unused const u32 ar9485_1_1_soc_preamble[][2] = { +static const u32 ar9485_1_1_soc_preamble[][2] = { /* Addr allmodes */ {0x00004014, 0xba280400}, {0x00004090, 0x00aa10aa}, @@ -793,14 +793,14 @@ static __unused const u32 ar9485_1_1_soc_preamble[][2] = { {0x00007048, 0x00000002}, }; -static __unused const u32 ar9485_1_1_baseband_core_txfir_coeff_japan_2484[][2] = { +static const u32 ar9485_1_1_baseband_core_txfir_coeff_japan_2484[][2] = { /* Addr allmodes */ {0x0000a398, 0x00000000}, {0x0000a39c, 0x6f7f0301}, {0x0000a3a0, 0xca9228ee}, }; -static __unused const u32 ar9485Modes_low_ob_db_tx_gain_1_1[][5] = { +static const u32 ar9485Modes_low_ob_db_tx_gain_1_1[][5] = { /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */ {0x000098bc, 0x00000002, 0x00000002, 0x00000002, 0x00000002}, {0x0000a410, 0x000050d9, 0x000050d9, 0x000050d8, 0x000050d8}, @@ -873,21 +873,21 @@ static __unused const u32 ar9485Modes_low_ob_db_tx_gain_1_1[][5] = { {0x00016048, 0x6c924260, 0x6c924260, 0x6c924260, 0x6c924260}, }; -static __unused const u32 ar9485_fast_clock_1_1_baseband_postamble[][3] = { +static const u32 ar9485_fast_clock_1_1_baseband_postamble[][3] = { /* Addr 5G_HT2 5G_HT40 */ {0x00009e00, 0x03721821, 0x03721821}, {0x0000a230, 0x0000400b, 0x00004016}, {0x0000a254, 0x00000898, 0x00001130}, }; -static __unused const u32 ar9485_1_1_pcie_phy_pll_on_clkreq_disable_L1[][2] = { +static const u32 ar9485_1_1_pcie_phy_pll_on_clkreq_disable_L1[][2] = { /* Addr allmodes */ {0x00018c00, 0x10012e5e}, {0x00018c04, 0x000801d8}, {0x00018c08, 0x0000080c}, }; -static __unused const u32 ar9485_common_rx_gain_1_1[][2] = { +static const u32 ar9485_common_rx_gain_1_1[][2] = { /* Addr allmodes */ {0x0000a000, 0x00010000}, {0x0000a004, 0x00030002}, @@ -1019,14 +1019,14 @@ static __unused const u32 ar9485_common_rx_gain_1_1[][2] = { {0x0000a1fc, 0x00000296}, }; -static __unused const u32 ar9485_1_1_pcie_phy_clkreq_enable_L1[][2] = { +static const u32 ar9485_1_1_pcie_phy_clkreq_enable_L1[][2] = { /* Addr allmodes */ {0x00018c00, 0x10053e5e}, {0x00018c04, 0x000801d8}, {0x00018c08, 0x0000080c}, }; -static __unused const u32 ar9485Common_wo_xlna_rx_gain_1_1[][2] = { +static const u32 ar9485Common_wo_xlna_rx_gain_1_1[][2] = { /* Addr allmodes */ {0x0000a000, 0x00060005}, {0x0000a004, 0x00810080}, diff --git a/roms/ipxe/src/drivers/net/ath/ath9k/ath9k_eeprom.c b/roms/ipxe/src/drivers/net/ath/ath9k/ath9k_eeprom.c index a20423790..f552acaa3 100644 --- a/roms/ipxe/src/drivers/net/ath/ath9k/ath9k_eeprom.c +++ b/roms/ipxe/src/drivers/net/ath/ath9k/ath9k_eeprom.c @@ -368,9 +368,10 @@ void ath9k_hw_get_gain_boundaries_pdadcs(struct ath_hw *ah, if (match) { if (AR_SREV_9287(ah)) { + /* FIXME: array overrun? */ for (i = 0; i < numXpdGains; i++) { minPwrT4[i] = data_9287[idxL].pwrPdg[i][0]; - maxPwrT4[i] = data_9287[idxL].pwrPdg[i][intercepts - 1]; + maxPwrT4[i] = data_9287[idxL].pwrPdg[i][4]; ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i], data_9287[idxL].pwrPdg[i], data_9287[idxL].vpdPdg[i], @@ -380,7 +381,7 @@ void ath9k_hw_get_gain_boundaries_pdadcs(struct ath_hw *ah, } else if (eeprom_4k) { for (i = 0; i < numXpdGains; i++) { minPwrT4[i] = data_4k[idxL].pwrPdg[i][0]; - maxPwrT4[i] = data_4k[idxL].pwrPdg[i][intercepts - 1]; + maxPwrT4[i] = data_4k[idxL].pwrPdg[i][4]; ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i], data_4k[idxL].pwrPdg[i], data_4k[idxL].vpdPdg[i], @@ -390,7 +391,7 @@ void ath9k_hw_get_gain_boundaries_pdadcs(struct ath_hw *ah, } else { for (i = 0; i < numXpdGains; i++) { minPwrT4[i] = data_def[idxL].pwrPdg[i][0]; - maxPwrT4[i] = data_def[idxL].pwrPdg[i][intercepts - 1]; + maxPwrT4[i] = data_def[idxL].pwrPdg[i][4]; ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i], data_def[idxL].pwrPdg[i], data_def[idxL].vpdPdg[i], diff --git a/roms/ipxe/src/drivers/net/ath/ath9k/ath9k_init.c b/roms/ipxe/src/drivers/net/ath/ath9k/ath9k_init.c index 98a0d6d59..03de7701a 100644 --- a/roms/ipxe/src/drivers/net/ath/ath9k/ath9k_init.c +++ b/roms/ipxe/src/drivers/net/ath/ath9k/ath9k_init.c @@ -22,7 +22,6 @@ FILE_LICENCE ( BSD2 ); #include <ipxe/malloc.h> #include <ipxe/pci_io.h> #include <ipxe/pci.h> -#include <ipxe/ethernet.h> #include "ath9k.h" @@ -350,7 +349,7 @@ static void ath9k_init_misc(struct ath_softc *sc) ath9k_hw_set_diversity(sc->sc_ah, 1); sc->rx.defant = ath9k_hw_getdefantenna(sc->sc_ah); - memcpy(common->bssidmask, eth_broadcast, ETH_ALEN); + memcpy(common->bssidmask, ath_bcast_mac, ETH_ALEN); } static int ath9k_init_softc(u16 devid, struct ath_softc *sc, u16 subsysid, diff --git a/roms/ipxe/src/drivers/net/ath/ath9k/ath9k_recv.c b/roms/ipxe/src/drivers/net/ath/ath9k/ath9k_recv.c index 0ffe9d45a..ba363c676 100644 --- a/roms/ipxe/src/drivers/net/ath/ath9k/ath9k_recv.c +++ b/roms/ipxe/src/drivers/net/ath/ath9k/ath9k_recv.c @@ -98,6 +98,7 @@ int ath_rx_init(struct ath_softc *sc, int nbufs) { struct ath_common *common = ath9k_hw_common(sc->sc_ah); struct io_buffer *iob; + u32 *iob_addr = NULL; struct ath_buf *bf; int error = 0; @@ -121,14 +122,15 @@ int ath_rx_init(struct ath_softc *sc, int nbufs) } list_for_each_entry(bf, &sc->rx.rxbuf, list) { - iob = alloc_iob_raw ( common->rx_bufsize, common->cachelsz, 0 ); + iob = ath_rxbuf_alloc(common, common->rx_bufsize, + iob_addr); if (iob == NULL) { error = -ENOMEM; goto err; } bf->bf_mpdu = iob; - bf->bf_buf_addr = virt_to_bus ( iob->data ); + bf->bf_buf_addr = *iob_addr; } sc->rx.rxlink = NULL; @@ -431,6 +433,7 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush, int hp __unused) { struct ath_buf *bf; struct io_buffer *iob = NULL, *requeue_iob; + u32 *requeue_iob_addr = NULL; struct ath_hw *ah = sc->sc_ah; struct ath_common *common = ath9k_hw_common(ah); /* @@ -473,8 +476,7 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush, int hp __unused) /* Ensure we always have an iob to requeue once we are done * processing the current buffer's iob */ - requeue_iob = alloc_iob_raw ( common->rx_bufsize, - common->cachelsz, 0 ); + requeue_iob = ath_rxbuf_alloc(common, common->rx_bufsize, requeue_iob_addr); /* If there is no memory we ignore the current RX'd frame, * tell hardware it can give us a new frame using the old @@ -489,7 +491,7 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush, int hp __unused) /* We will now give hardware our shiny new allocated iob */ bf->bf_mpdu = requeue_iob; - bf->bf_buf_addr = virt_to_bus ( requeue_iob->data ); + bf->bf_buf_addr = *requeue_iob_addr; /* * change the default rx antenna if rx diversity chooses the diff --git a/roms/ipxe/src/drivers/net/ath/ath_main.c b/roms/ipxe/src/drivers/net/ath/ath_main.c new file mode 100644 index 000000000..85d159a36 --- /dev/null +++ b/roms/ipxe/src/drivers/net/ath/ath_main.c @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2009 Atheros Communications Inc. + * + * Modified for iPXE by Scott K Logan <logans@cottsay.net> July 2011 + * Original from Linux kernel 3.0.1 + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <ipxe/io.h> + +#include "ath.h" + +struct io_buffer *ath_rxbuf_alloc(struct ath_common *common, + u32 len, + u32 *iob_addr) +{ + struct io_buffer *iob; + u32 off; + + /* + * Cache-line-align. This is important (for the + * 5210 at least) as not doing so causes bogus data + * in rx'd frames. + */ + + /* Note: the kernel can allocate a value greater than + * what we ask it to give us. We really only need 4 KB as that + * is this hardware supports and in fact we need at least 3849 + * as that is the MAX AMSDU size this hardware supports. + * Unfortunately this means we may get 8 KB here from the + * kernel... and that is actually what is observed on some + * systems :( */ + iob = alloc_iob(len + common->cachelsz - 1); + if (iob != NULL) { + *iob_addr = virt_to_bus(iob->data); + off = ((unsigned long) iob->data) % common->cachelsz; + if (off != 0) + { + iob_reserve(iob, common->cachelsz - off); + *iob_addr += common->cachelsz - off; + } + } else { + DBG("ath: iobuffer alloc of size %d failed\n", len); + return NULL; + } + + return iob; +} diff --git a/roms/ipxe/src/drivers/net/axge.c b/roms/ipxe/src/drivers/net/axge.c deleted file mode 100644 index ab59a8be7..000000000 --- a/roms/ipxe/src/drivers/net/axge.c +++ /dev/null @@ -1,798 +0,0 @@ -/* - * Copyright (C) 2016 Michael Brown <mbrown@fensystems.co.uk>. - * - * 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 (at your option) 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 <stdint.h> -#include <string.h> -#include <unistd.h> -#include <errno.h> -#include <ipxe/netdevice.h> -#include <ipxe/ethernet.h> -#include <ipxe/if_ether.h> -#include <ipxe/profile.h> -#include <ipxe/usb.h> -#include "axge.h" - -/** @file - * - * Asix 10/100/1000 USB Ethernet driver - * - * Large chunks of functionality are undocumented in the available - * datasheets. The gaps are deduced from combinations of the Linux - * driver, the FreeBSD driver, and experimentation with the hardware. - */ - -/** Interrupt completion profiler */ -static struct profiler axge_intr_profiler __profiler = - { .name = "axge.intr" }; - -/** Bulk IN completion profiler */ -static struct profiler axge_in_profiler __profiler = - { .name = "axge.in" }; - -/** Bulk OUT profiler */ -static struct profiler axge_out_profiler __profiler = - { .name = "axge.out" }; - -/** Default bulk IN configuration - * - * The Linux and FreeBSD drivers have set of magic constants which are - * chosen based on both the Ethernet and USB link speeds. - * - * Experimentation shows that setting the "timer" value to zero seems - * to prevent the device from ever coalescing multiple packets into a - * single bulk IN transfer. This allows us to get away with using a - * 2kB receive I/O buffer and a zerocopy receive path. - */ -static struct axge_bulk_in_control axge_bicr = { - .ctrl = 7, - .timer = cpu_to_le16 ( 0 ), - .size = 0, - .ifg = 0, -}; - -/****************************************************************************** - * - * Register access - * - ****************************************************************************** - */ - -/** - * Read register - * - * @v asix AXGE device - * @v offset Register offset - * @v data Data buffer - * @v len Length of data - * @ret rc Return status code - */ -static inline int axge_read_register ( struct axge_device *axge, - unsigned int offset, void *data, - size_t len ) { - - return usb_control ( axge->usb, AXGE_READ_MAC_REGISTER, - offset, len, data, len ); -} - -/** - * Read one-byte register - * - * @v asix AXGE device - * @v offset Register offset - * @v value Value to fill in - * @ret rc Return status code - */ -static inline int axge_read_byte ( struct axge_device *axge, - unsigned int offset, uint8_t *value ) { - - return axge_read_register ( axge, offset, value, sizeof ( *value ) ); -} - -/** - * Read two-byte register - * - * @v asix AXGE device - * @v offset Register offset - * @v value Value to fill in - * @ret rc Return status code - */ -static inline int axge_read_word ( struct axge_device *axge, - unsigned int offset, uint16_t *value ) { - - return axge_read_register ( axge, offset, value, sizeof ( *value ) ); -} - -/** - * Read four-byte register - * - * @v asix AXGE device - * @v offset Register offset - * @v value Value to fill in - * @ret rc Return status code - */ -static inline int axge_read_dword ( struct axge_device *axge, - unsigned int offset, uint32_t *value ) { - - return axge_read_register ( axge, offset, value, sizeof ( *value ) ); -} - -/** - * Write register - * - * @v asix AXGE device - * @v offset Register offset - * @v data Data buffer - * @v len Length of data - * @ret rc Return status code - */ -static inline int axge_write_register ( struct axge_device *axge, - unsigned int offset, void *data, - size_t len ) { - - return usb_control ( axge->usb, AXGE_WRITE_MAC_REGISTER, - offset, len, data, len ); -} - -/** - * Write one-byte register - * - * @v asix AXGE device - * @v offset Register offset - * @v value Value - * @ret rc Return status code - */ -static inline int axge_write_byte ( struct axge_device *axge, - unsigned int offset, uint8_t value ) { - - return axge_write_register ( axge, offset, &value, sizeof ( value )); -} - -/** - * Write two-byte register - * - * @v asix AXGE device - * @v offset Register offset - * @v value Value - * @ret rc Return status code - */ -static inline int axge_write_word ( struct axge_device *axge, - unsigned int offset, uint16_t value ) { - - return axge_write_register ( axge, offset, &value, sizeof ( value )); -} - -/** - * Write one-byte register - * - * @v asix AXGE device - * @v offset Register offset - * @v value Value - * @ret rc Return status code - */ -static inline int axge_write_dword ( struct axge_device *axge, - unsigned int offset, uint32_t value ) { - - return axge_write_register ( axge, offset, &value, sizeof ( value )); -} - -/****************************************************************************** - * - * Link status - * - ****************************************************************************** - */ - -/** - * Get link status - * - * @v asix AXGE device - * @ret rc Return status code - */ -static int axge_check_link ( struct axge_device *axge ) { - struct net_device *netdev = axge->netdev; - uint8_t plsr; - int rc; - - /* Read physical link status register */ - if ( ( rc = axge_read_byte ( axge, AXGE_PLSR, &plsr ) ) != 0 ) { - DBGC ( axge, "AXGE %p could not read PLSR: %s\n", - axge, strerror ( rc ) ); - return rc; - } - - /* Update link status */ - if ( plsr & AXGE_PLSR_EPHY_ANY ) { - DBGC ( axge, "AXGE %p link up (PLSR %02x)\n", axge, plsr ); - netdev_link_up ( netdev ); - } else { - DBGC ( axge, "AXGE %p link down (PLSR %02x)\n", axge, plsr ); - netdev_link_down ( netdev ); - } - - return 0; -} - -/****************************************************************************** - * - * AXGE communications interface - * - ****************************************************************************** - */ - -/** - * Complete interrupt transfer - * - * @v ep USB endpoint - * @v iobuf I/O buffer - * @v rc Completion status code - */ -static void axge_intr_complete ( struct usb_endpoint *ep, - struct io_buffer *iobuf, int rc ) { - struct axge_device *axge = container_of ( ep, struct axge_device, - usbnet.intr ); - struct net_device *netdev = axge->netdev; - struct axge_interrupt *intr; - size_t len = iob_len ( iobuf ); - unsigned int link_ok; - - /* Profile completions */ - profile_start ( &axge_intr_profiler ); - - /* Ignore packets cancelled when the endpoint closes */ - if ( ! ep->open ) - goto ignore; - - /* Drop packets with errors */ - if ( rc != 0 ) { - DBGC ( axge, "AXGE %p interrupt failed: %s\n", - axge, strerror ( rc ) ); - DBGC_HDA ( axge, 0, iobuf->data, iob_len ( iobuf ) ); - goto error; - } - - /* Extract message header */ - if ( len < sizeof ( *intr ) ) { - DBGC ( axge, "AXGE %p underlength interrupt:\n", axge ); - DBGC_HDA ( axge, 0, iobuf->data, iob_len ( iobuf ) ); - rc = -EINVAL; - goto error; - } - intr = iobuf->data; - - /* Check magic signature */ - if ( intr->magic != cpu_to_le16 ( AXGE_INTR_MAGIC ) ) { - DBGC ( axge, "AXGE %p malformed interrupt:\n", axge ); - DBGC_HDA ( axge, 0, iobuf->data, iob_len ( iobuf ) ); - rc = -EINVAL; - goto error; - } - - /* Extract link status */ - link_ok = ( intr->link & cpu_to_le16 ( AXGE_INTR_LINK_PPLS ) ); - if ( link_ok && ! netdev_link_ok ( netdev ) ) { - DBGC ( axge, "AXGE %p link up\n", axge ); - netdev_link_up ( netdev ); - } else if ( netdev_link_ok ( netdev ) && ! link_ok ) { - DBGC ( axge, "AXGE %p link down\n", axge ); - netdev_link_down ( netdev ); - } - - /* Free I/O buffer */ - free_iob ( iobuf ); - profile_stop ( &axge_intr_profiler ); - - return; - - error: - netdev_rx_err ( netdev, iob_disown ( iobuf ), rc ); - ignore: - free_iob ( iobuf ); - return; -} - -/** Interrupt endpoint operations */ -static struct usb_endpoint_driver_operations axge_intr_operations = { - .complete = axge_intr_complete, -}; - -/****************************************************************************** - * - * AXGE data interface - * - ****************************************************************************** - */ - -/** - * Complete bulk IN transfer - * - * @v ep USB endpoint - * @v iobuf I/O buffer - * @v rc Completion status code - */ -static void axge_in_complete ( struct usb_endpoint *ep, - struct io_buffer *iobuf, int rc ) { - struct axge_device *axge = container_of ( ep, struct axge_device, - usbnet.in ); - struct net_device *netdev = axge->netdev; - struct axge_rx_footer *ftr; - struct axge_rx_descriptor *desc; - struct io_buffer *pkt; - unsigned int count; - unsigned int offset; - size_t len; - size_t padded_len; - - /* Profile receive completions */ - profile_start ( &axge_in_profiler ); - - /* Ignore packets cancelled when the endpoint closes */ - if ( ! ep->open ) - goto ignore; - - /* Record USB errors against the network device */ - if ( rc != 0 ) { - DBGC ( axge, "AXGE %p bulk IN failed: %s\n", - axge, strerror ( rc ) ); - goto error; - } - - /* Sanity check */ - if ( iob_len ( iobuf ) < sizeof ( *ftr ) ) { - DBGC ( axge, "AXGE %p underlength bulk IN:\n", axge ); - DBGC_HDA ( axge, 0, iobuf->data, iob_len ( iobuf ) ); - rc = -EINVAL; - goto error; - } - - /* Parse ftr, strip ftr and descriptors */ - iob_unput ( iobuf, sizeof ( *ftr ) ); - ftr = ( iobuf->data + iob_len ( iobuf ) ); - count = le16_to_cpu ( ftr->count ); - if ( count == 0 ) { - DBGC ( axge, "AXGE %p zero-packet bulk IN:\n", axge ); - DBGC_HDA ( axge, 0, iobuf->data, iob_len ( iobuf ) ); - goto ignore; - } - offset = le16_to_cpu ( ftr->offset ); - if ( ( iob_len ( iobuf ) < offset ) || - ( ( iob_len ( iobuf ) - offset ) < ( count * sizeof ( *desc ) ) )){ - DBGC ( axge, "AXGE %p malformed bulk IN footer:\n", axge ); - DBGC_HDA ( axge, 0, iobuf->data, iob_len ( iobuf ) ); - rc = -EINVAL; - goto error; - } - desc = ( iobuf->data + offset ); - iob_unput ( iobuf, ( iob_len ( iobuf ) - offset ) ); - - /* Process packets */ - for ( ; count-- ; desc++ ) { - - /* Parse descriptor */ - len = ( le16_to_cpu ( desc->len_flags ) & AXGE_RX_LEN_MASK ); - padded_len = ( ( len + AXGE_RX_LEN_PAD_ALIGN - 1 ) & - ~( AXGE_RX_LEN_PAD_ALIGN - 1 ) ); - if ( iob_len ( iobuf ) < padded_len ) { - DBGC ( axge, "AXGE %p malformed bulk IN descriptor:\n", - axge ); - DBGC_HDA ( axge, 0, iobuf->data, iob_len ( iobuf ) ); - rc = -EINVAL; - goto error; - } - - /* Check for previous dropped packets */ - if ( desc->len_flags & cpu_to_le16 ( AXGE_RX_CRC_ERROR ) ) - netdev_rx_err ( netdev, NULL, -EIO ); - if ( desc->len_flags & cpu_to_le16 ( AXGE_RX_DROP_ERROR ) ) - netdev_rx_err ( netdev, NULL, -ENOBUFS ); - - /* Allocate new I/O buffer, if applicable */ - if ( count ) { - - /* More packets remain: allocate a new buffer */ - pkt = alloc_iob ( AXGE_IN_RESERVE + len ); - if ( ! pkt ) { - /* Record error and continue */ - netdev_rx_err ( netdev, NULL, -ENOMEM ); - iob_pull ( iobuf, padded_len ); - continue; - } - iob_reserve ( pkt, AXGE_IN_RESERVE ); - memcpy ( iob_put ( pkt, len ), iobuf->data, len ); - iob_pull ( iobuf, padded_len ); - - } else { - - /* This is the last (or only) packet: use this buffer */ - iob_unput ( iobuf, ( padded_len - len ) ); - pkt = iob_disown ( iobuf ); - } - - /* Hand off to network stack */ - netdev_rx ( netdev, iob_disown ( pkt ) ); - } - - assert ( iobuf == NULL ); - profile_stop ( &axge_in_profiler ); - return; - - error: - netdev_rx_err ( netdev, iob_disown ( iobuf ), rc ); - ignore: - free_iob ( iobuf ); -} - -/** Bulk IN endpoint operations */ -static struct usb_endpoint_driver_operations axge_in_operations = { - .complete = axge_in_complete, -}; - -/** - * Transmit packet - * - * @v asix AXGE device - * @v iobuf I/O buffer - * @ret rc Return status code - */ -static int axge_out_transmit ( struct axge_device *axge, - struct io_buffer *iobuf ) { - struct axge_tx_header *hdr; - size_t len = iob_len ( iobuf ); - int rc; - - /* Profile transmissions */ - profile_start ( &axge_out_profiler ); - - /* Prepend header */ - if ( ( rc = iob_ensure_headroom ( iobuf, sizeof ( *hdr ) ) ) != 0 ) - return rc; - hdr = iob_push ( iobuf, sizeof ( *hdr ) ); - hdr->len = cpu_to_le32 ( len ); - hdr->wtf = 0; - - /* Enqueue I/O buffer */ - if ( ( rc = usb_stream ( &axge->usbnet.out, iobuf, 0 ) ) != 0 ) - return rc; - - profile_stop ( &axge_out_profiler ); - return 0; -} - -/** - * Complete bulk OUT transfer - * - * @v ep USB endpoint - * @v iobuf I/O buffer - * @v rc Completion status code - */ -static void axge_out_complete ( struct usb_endpoint *ep, - struct io_buffer *iobuf, int rc ) { - struct axge_device *axge = container_of ( ep, struct axge_device, - usbnet.out ); - struct net_device *netdev = axge->netdev; - - /* Report TX completion */ - netdev_tx_complete_err ( netdev, iobuf, rc ); -} - -/** Bulk OUT endpoint operations */ -static struct usb_endpoint_driver_operations axge_out_operations = { - .complete = axge_out_complete, -}; - -/****************************************************************************** - * - * Network device interface - * - ****************************************************************************** - */ - -/** - * Open network device - * - * @v netdev Network device - * @ret rc Return status code - */ -static int axge_open ( struct net_device *netdev ) { - struct axge_device *axge = netdev->priv; - uint16_t rcr; - int rc; - - /* Open USB network device */ - if ( ( rc = usbnet_open ( &axge->usbnet ) ) != 0 ) { - DBGC ( axge, "AXGE %p could not open: %s\n", - axge, strerror ( rc ) ); - goto err_open; - } - - /* Set MAC address */ - if ( ( rc = axge_write_register ( axge, AXGE_NIDR, - netdev->ll_addr, ETH_ALEN ) ) !=0){ - DBGC ( axge, "AXGE %p could not set MAC address: %s\n", - axge, strerror ( rc ) ); - goto err_write_mac; - } - - /* Enable receiver */ - rcr = cpu_to_le16 ( AXGE_RCR_PRO | AXGE_RCR_AMALL | - AXGE_RCR_AB | AXGE_RCR_SO ); - if ( ( rc = axge_write_word ( axge, AXGE_RCR, rcr ) ) != 0 ) { - DBGC ( axge, "AXGE %p could not write RCR: %s\n", - axge, strerror ( rc ) ); - goto err_write_rcr; - } - - /* Update link status */ - axge_check_link ( axge ); - - return 0; - - axge_write_word ( axge, AXGE_RCR, 0 ); - err_write_rcr: - err_write_mac: - usbnet_close ( &axge->usbnet ); - err_open: - return rc; -} - -/** - * Close network device - * - * @v netdev Network device - */ -static void axge_close ( struct net_device *netdev ) { - struct axge_device *axge = netdev->priv; - - /* Disable receiver */ - axge_write_word ( axge, AXGE_RCR, 0 ); - - /* Close USB network device */ - usbnet_close ( &axge->usbnet ); -} - -/** - * Transmit packet - * - * @v netdev Network device - * @v iobuf I/O buffer - * @ret rc Return status code - */ -static int axge_transmit ( struct net_device *netdev, - struct io_buffer *iobuf ) { - struct axge_device *axge = netdev->priv; - int rc; - - /* Transmit packet */ - if ( ( rc = axge_out_transmit ( axge, iobuf ) ) != 0 ) - return rc; - - return 0; -} - -/** - * Poll for completed and received packets - * - * @v netdev Network device - */ -static void axge_poll ( struct net_device *netdev ) { - struct axge_device *axge = netdev->priv; - int rc; - - /* Poll USB bus */ - usb_poll ( axge->bus ); - - /* Refill endpoints */ - if ( ( rc = usbnet_refill ( &axge->usbnet ) ) != 0 ) - netdev_rx_err ( netdev, NULL, rc ); -} - -/** AXGE network device operations */ -static struct net_device_operations axge_operations = { - .open = axge_open, - .close = axge_close, - .transmit = axge_transmit, - .poll = axge_poll, -}; - -/****************************************************************************** - * - * USB interface - * - ****************************************************************************** - */ - -/** - * Probe device - * - * @v func USB function - * @v config Configuration descriptor - * @ret rc Return status code - */ -static int axge_probe ( struct usb_function *func, - struct usb_configuration_descriptor *config ) { - struct usb_device *usb = func->usb; - struct net_device *netdev; - struct axge_device *axge; - uint16_t epprcr; - uint16_t msr; - uint8_t csr; - int rc; - - /* Allocate and initialise structure */ - netdev = alloc_etherdev ( sizeof ( *axge ) ); - if ( ! netdev ) { - rc = -ENOMEM; - goto err_alloc; - } - netdev_init ( netdev, &axge_operations ); - netdev->dev = &func->dev; - axge = netdev->priv; - memset ( axge, 0, sizeof ( *axge ) ); - axge->usb = usb; - axge->bus = usb->port->hub->bus; - axge->netdev = netdev; - usbnet_init ( &axge->usbnet, func, &axge_intr_operations, - &axge_in_operations, &axge_out_operations ); - usb_refill_init ( &axge->usbnet.intr, 0, 0, AXGE_INTR_MAX_FILL ); - usb_refill_init ( &axge->usbnet.in, AXGE_IN_RESERVE, - AXGE_IN_MTU, AXGE_IN_MAX_FILL ); - DBGC ( axge, "AXGE %p on %s\n", axge, func->name ); - - /* Describe USB network device */ - if ( ( rc = usbnet_describe ( &axge->usbnet, config ) ) != 0 ) { - DBGC ( axge, "AXGE %p could not describe: %s\n", - axge, strerror ( rc ) ); - goto err_describe; - } - - /* Fetch MAC address */ - if ( ( rc = axge_read_register ( axge, AXGE_NIDR, netdev->hw_addr, - ETH_ALEN ) ) != 0 ) { - DBGC ( axge, "AXGE %p could not fetch MAC address: %s\n", - axge, strerror ( rc ) ); - goto err_read_mac; - } - - /* Power up PHY */ - if ( ( rc = axge_write_word ( axge, AXGE_EPPRCR, 0 ) ) != 0 ) { - DBGC ( axge, "AXGE %p could not write EPPRCR: %s\n", - axge, strerror ( rc ) ); - goto err_write_epprcr_off; - } - epprcr = cpu_to_le16 ( AXGE_EPPRCR_IPRL ); - if ( ( rc = axge_write_word ( axge, AXGE_EPPRCR, epprcr ) ) != 0){ - DBGC ( axge, "AXGE %p could not write EPPRCR: %s\n", - axge, strerror ( rc ) ); - goto err_write_epprcr_on; - } - mdelay ( AXGE_EPPRCR_DELAY_MS ); - - /* Select clocks */ - csr = ( AXGE_CSR_BCS | AXGE_CSR_ACS ); - if ( ( rc = axge_write_byte ( axge, AXGE_CSR, csr ) ) != 0){ - DBGC ( axge, "AXGE %p could not write CSR: %s\n", - axge, strerror ( rc ) ); - goto err_write_csr; - } - mdelay ( AXGE_CSR_DELAY_MS ); - - /* Configure bulk IN pipeline */ - if ( ( rc = axge_write_register ( axge, AXGE_BICR, &axge_bicr, - sizeof ( axge_bicr ) ) ) != 0 ){ - DBGC ( axge, "AXGE %p could not write BICR: %s\n", - axge, strerror ( rc ) ); - goto err_write_bicr; - } - - /* Set medium status */ - msr = cpu_to_le16 ( AXGE_MSR_GM | AXGE_MSR_FD | AXGE_MSR_RFC | - AXGE_MSR_TFC | AXGE_MSR_RE ); - if ( ( rc = axge_write_word ( axge, AXGE_MSR, msr ) ) != 0 ) { - DBGC ( axge, "AXGE %p could not write MSR: %s\n", - axge, strerror ( rc ) ); - goto err_write_msr; - } - - /* Register network device */ - if ( ( rc = register_netdev ( netdev ) ) != 0 ) - goto err_register; - - /* Update link status */ - axge_check_link ( axge ); - - usb_func_set_drvdata ( func, axge ); - return 0; - - unregister_netdev ( netdev ); - err_register: - err_write_msr: - err_write_bicr: - err_write_csr: - err_write_epprcr_on: - err_write_epprcr_off: - err_read_mac: - err_describe: - netdev_nullify ( netdev ); - netdev_put ( netdev ); - err_alloc: - return rc; -} - -/** - * Remove device - * - * @v func USB function - */ -static void axge_remove ( struct usb_function *func ) { - struct axge_device *axge = usb_func_get_drvdata ( func ); - struct net_device *netdev = axge->netdev; - - unregister_netdev ( netdev ); - netdev_nullify ( netdev ); - netdev_put ( netdev ); -} - -/** AXGE device IDs */ -static struct usb_device_id axge_ids[] = { - { - .name = "ax88179", - .vendor = 0x0b95, - .product = 0x1790, - }, - { - .name = "ax88178a", - .vendor = 0x0b95, - .product = 0x178a, - }, - { - .name = "dub1312", - .vendor = 0x2001, - .product = 0x4a00, - }, - { - .name = "axge-sitecom", - .vendor = 0x0df6, - .product = 0x0072, - }, - { - .name = "axge-samsung", - .vendor = 0x04e8, - .product = 0xa100, - }, - { - .name = "onelinkdock", - .vendor = 0x17ef, - .product = 0x304b, - }, -}; - -/** AXGE driver */ -struct usb_driver axge_driver __usb_driver = { - .ids = axge_ids, - .id_count = ( sizeof ( axge_ids ) / sizeof ( axge_ids[0] ) ), - .class = USB_CLASS_ID ( USB_ANY_ID, USB_ANY_ID, USB_ANY_ID ), - .score = USB_SCORE_NORMAL, - .probe = axge_probe, - .remove = axge_remove, -}; diff --git a/roms/ipxe/src/drivers/net/axge.h b/roms/ipxe/src/drivers/net/axge.h deleted file mode 100644 index 65bf911c5..000000000 --- a/roms/ipxe/src/drivers/net/axge.h +++ /dev/null @@ -1,174 +0,0 @@ -#ifndef _AXGE_H -#define _AXGE_H - -/** @file - * - * Asix 10/100/1000 USB Ethernet driver - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#include <ipxe/usb.h> -#include <ipxe/usbnet.h> - -/** Read MAC register */ -#define AXGE_READ_MAC_REGISTER \ - ( USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE | \ - USB_REQUEST_TYPE ( 0x01 ) ) - -/** Write MAC register */ -#define AXGE_WRITE_MAC_REGISTER \ - ( USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE | \ - USB_REQUEST_TYPE ( 0x01 ) ) - -/** Physical Link Status Register */ -#define AXGE_PLSR 0x02 -#define AXGE_PLSR_EPHY_10 0x10 /**< Ethernet at 10Mbps */ -#define AXGE_PLSR_EPHY_100 0x20 /**< Ethernet at 100Mbps */ -#define AXGE_PLSR_EPHY_1000 0x40 /**< Ethernet at 1000Mbps */ -#define AXGE_PLSR_EPHY_ANY \ - ( AXGE_PLSR_EPHY_10 | \ - AXGE_PLSR_EPHY_100 | \ - AXGE_PLSR_EPHY_1000 ) - -/** RX Control Register */ -#define AXGE_RCR 0x0b -#define AXGE_RCR_PRO 0x0001 /**< Promiscuous mode */ -#define AXGE_RCR_AMALL 0x0002 /**< Accept all multicasts */ -#define AXGE_RCR_AB 0x0008 /**< Accept broadcasts */ -#define AXGE_RCR_SO 0x0080 /**< Start operation */ - -/** Node ID Register */ -#define AXGE_NIDR 0x10 - -/** Medium Status Register */ -#define AXGE_MSR 0x22 -#define AXGE_MSR_GM 0x0001 /**< Gigabit mode */ -#define AXGE_MSR_FD 0x0002 /**< Full duplex */ -#define AXGE_MSR_RFC 0x0010 /**< RX flow control enable */ -#define AXGE_MSR_TFC 0x0020 /**< TX flow control enable */ -#define AXGE_MSR_RE 0x0100 /**< Receive enable */ - -/** Ethernet PHY Power and Reset Control Register */ -#define AXGE_EPPRCR 0x26 -#define AXGE_EPPRCR_IPRL 0x0020 /**< Undocumented */ - -/** Delay after initialising EPPRCR */ -#define AXGE_EPPRCR_DELAY_MS 200 - -/** Bulk IN Control Register (undocumented) */ -#define AXGE_BICR 0x2e - -/** Bulk IN Control (undocumented) */ -struct axge_bulk_in_control { - /** Control */ - uint8_t ctrl; - /** Timer */ - uint16_t timer; - /** Size */ - uint8_t size; - /** Inter-frame gap */ - uint8_t ifg; -} __attribute__ (( packed )); - -/** Clock Select Register (undocumented) */ -#define AXGE_CSR 0x33 -#define AXGE_CSR_BCS 0x01 /**< Undocumented */ -#define AXGE_CSR_ACS 0x02 /**< Undocumented */ - -/** Delay after initialising CSR */ -#define AXGE_CSR_DELAY_MS 100 - -/** Transmit packet header */ -struct axge_tx_header { - /** Packet length */ - uint32_t len; - /** Answers on a postcard, please */ - uint32_t wtf; -} __attribute__ (( packed )); - -/** Receive packet footer */ -struct axge_rx_footer { - /** Packet count */ - uint16_t count; - /** Header offset */ - uint16_t offset; -} __attribute__ (( packed )); - -/** Receive packet descriptor */ -struct axge_rx_descriptor { - /** Checksum information */ - uint16_t check; - /** Length and error flags */ - uint16_t len_flags; -} __attribute__ (( packed )); - -/** Receive packet length mask */ -#define AXGE_RX_LEN_MASK 0x1fff - -/** Receive packet length alignment */ -#define AXGE_RX_LEN_PAD_ALIGN 8 - -/** Receive packet CRC error */ -#define AXGE_RX_CRC_ERROR 0x2000 - -/** Receive packet dropped error */ -#define AXGE_RX_DROP_ERROR 0x8000 - -/** Interrupt data */ -struct axge_interrupt { - /** Magic signature */ - uint16_t magic; - /** Link state */ - uint16_t link; - /** PHY register MR01 */ - uint16_t mr01; - /** PHY register MR05 */ - uint16_t mr05; -} __attribute__ (( packed )); - -/** Interrupt magic signature */ -#define AXGE_INTR_MAGIC 0x00a1 - -/** Link is up */ -#define AXGE_INTR_LINK_PPLS 0x0001 - -/** An AXGE network device */ -struct axge_device { - /** USB device */ - struct usb_device *usb; - /** USB bus */ - struct usb_bus *bus; - /** Network device */ - struct net_device *netdev; - /** USB network device */ - struct usbnet_device usbnet; -}; - -/** Interrupt maximum fill level - * - * This is a policy decision. - */ -#define AXGE_INTR_MAX_FILL 2 - -/** Bulk IN maximum fill level - * - * This is a policy decision. - */ -#define AXGE_IN_MAX_FILL 8 - -/** Bulk IN buffer size - * - * This is a policy decision. - */ -#define AXGE_IN_MTU 2048 - -/** Amount of space to reserve at start of bulk IN buffers - * - * This is required to allow for protocols such as ARP which may reuse - * a received I/O buffer for transmission. - */ -#define AXGE_IN_RESERVE sizeof ( struct axge_tx_header ) - -#endif /* _AXGE_H */ diff --git a/roms/ipxe/src/drivers/net/dm96xx.c b/roms/ipxe/src/drivers/net/dm96xx.c index 61b957be9..58d8dd964 100644 --- a/roms/ipxe/src/drivers/net/dm96xx.c +++ b/roms/ipxe/src/drivers/net/dm96xx.c @@ -532,8 +532,8 @@ static int dm96xx_probe ( struct usb_function *func, dm96xx->netdev = netdev; usbnet_init ( &dm96xx->usbnet, func, &dm96xx_intr_operations, &dm96xx_in_operations, &dm96xx_out_operations ); - usb_refill_init ( &dm96xx->usbnet.intr, 0, 0, DM96XX_INTR_MAX_FILL ); - usb_refill_init ( &dm96xx->usbnet.in, 0, DM96XX_IN_MTU, + usb_refill_init ( &dm96xx->usbnet.intr, 0, DM96XX_INTR_MAX_FILL ); + usb_refill_init ( &dm96xx->usbnet.in, DM96XX_IN_MTU, DM96XX_IN_MAX_FILL ); DBGC ( dm96xx, "DM96XX %p on %s\n", dm96xx, func->name ); @@ -666,8 +666,6 @@ static struct usb_device_id dm96xx_ids[] = { struct usb_driver dm96xx_driver __usb_driver = { .ids = dm96xx_ids, .id_count = ( sizeof ( dm96xx_ids ) / sizeof ( dm96xx_ids[0] ) ), - .class = USB_CLASS_ID ( USB_ANY_ID, USB_ANY_ID, USB_ANY_ID ), - .score = USB_SCORE_NORMAL, .probe = dm96xx_probe, .remove = dm96xx_remove, }; diff --git a/roms/ipxe/src/drivers/net/ecm.c b/roms/ipxe/src/drivers/net/ecm.c index f2d9161c1..8c84ea9e9 100644 --- a/roms/ipxe/src/drivers/net/ecm.c +++ b/roms/ipxe/src/drivers/net/ecm.c @@ -437,8 +437,8 @@ static int ecm_probe ( struct usb_function *func, ecm->netdev = netdev; usbnet_init ( &ecm->usbnet, func, &ecm_intr_operations, &ecm_in_operations, &ecm_out_operations ); - usb_refill_init ( &ecm->usbnet.intr, 0, 0, ECM_INTR_MAX_FILL ); - usb_refill_init ( &ecm->usbnet.in, 0, ECM_IN_MTU, ECM_IN_MAX_FILL ); + usb_refill_init ( &ecm->usbnet.intr, 0, ECM_INTR_MAX_FILL ); + usb_refill_init ( &ecm->usbnet.in, ECM_IN_MTU, ECM_IN_MAX_FILL ); DBGC ( ecm, "ECM %p on %s\n", ecm, func->name ); /* Describe USB network device */ @@ -503,6 +503,11 @@ static struct usb_device_id ecm_ids[] = { .name = "cdc-ecm", .vendor = USB_ANY_ID, .product = USB_ANY_ID, + .class = { + .class = USB_CLASS_CDC, + .subclass = USB_SUBCLASS_CDC_ECM, + .protocol = 0, + }, }, }; @@ -510,8 +515,6 @@ static struct usb_device_id ecm_ids[] = { struct usb_driver ecm_driver __usb_driver = { .ids = ecm_ids, .id_count = ( sizeof ( ecm_ids ) / sizeof ( ecm_ids[0] ) ), - .class = USB_CLASS_ID ( USB_CLASS_CDC, USB_SUBCLASS_CDC_ECM, 0 ), - .score = USB_SCORE_NORMAL, .probe = ecm_probe, .remove = ecm_remove, }; diff --git a/roms/ipxe/src/drivers/net/efi/nii.c b/roms/ipxe/src/drivers/net/efi/nii.c index d68b36cc3..b91848f5c 100644 --- a/roms/ipxe/src/drivers/net/efi/nii.c +++ b/roms/ipxe/src/drivers/net/efi/nii.c @@ -1125,8 +1125,8 @@ int nii_start ( struct efi_device *efidev ) { /* Register network device */ if ( ( rc = register_netdev ( netdev ) ) != 0 ) goto err_register_netdev; - DBGC ( nii, "NII %s registered as %s for %s\n", nii->dev.name, - netdev->name, efi_handle_name ( device ) ); + DBGC ( nii, "NII %s registered as %s for %p %s\n", nii->dev.name, + netdev->name, device, efi_handle_name ( device ) ); /* Set initial link state (if media detection is not supported) */ if ( ! nii->media ) diff --git a/roms/ipxe/src/drivers/net/efi/snp.c b/roms/ipxe/src/drivers/net/efi/snp.c index fbd606902..acfcfba9f 100644 --- a/roms/ipxe/src/drivers/net/efi/snp.c +++ b/roms/ipxe/src/drivers/net/efi/snp.c @@ -48,8 +48,8 @@ static int snp_supported ( EFI_HANDLE device ) { /* Check that this is not a device we are providing ourselves */ if ( find_snpdev ( device ) != NULL ) { - DBGCP ( device, "SNP %s is provided by this binary\n", - efi_handle_name ( device ) ); + DBGCP ( device, "SNP %p %s is provided by this binary\n", + device, efi_handle_name ( device ) ); return -ENOTTY; } @@ -58,12 +58,12 @@ static int snp_supported ( EFI_HANDLE device ) { &efi_simple_network_protocol_guid, NULL, efi_image_handle, device, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))!=0){ - DBGCP ( device, "SNP %s is not an SNP device\n", - efi_handle_name ( device ) ); + DBGCP ( device, "SNP %p %s is not an SNP device\n", + device, efi_handle_name ( device ) ); return -EEFI ( efirc ); } - DBGC ( device, "SNP %s is an SNP device\n", - efi_handle_name ( device ) ); + DBGC ( device, "SNP %p %s is an SNP device\n", + device, efi_handle_name ( device ) ); return 0; } @@ -80,8 +80,8 @@ static int nii_supported ( EFI_HANDLE device ) { /* Check that this is not a device we are providing ourselves */ if ( find_snpdev ( device ) != NULL ) { - DBGCP ( device, "NII %s is provided by this binary\n", - efi_handle_name ( device ) ); + DBGCP ( device, "NII %p %s is provided by this binary\n", + device, efi_handle_name ( device ) ); return -ENOTTY; } @@ -90,12 +90,12 @@ static int nii_supported ( EFI_HANDLE device ) { &efi_nii31_protocol_guid, NULL, efi_image_handle, device, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))!=0){ - DBGCP ( device, "NII %s is not an NII device\n", - efi_handle_name ( device ) ); + DBGCP ( device, "NII %p %s is not an NII device\n", + device, efi_handle_name ( device ) ); return -EEFI ( efirc ); } - DBGC ( device, "NII %s is an NII device\n", - efi_handle_name ( device ) ); + DBGC ( device, "NII %p %s is an NII device\n", + device, efi_handle_name ( device ) ); return 0; } diff --git a/roms/ipxe/src/drivers/net/efi/snpnet.c b/roms/ipxe/src/drivers/net/efi/snpnet.c index 88474b0be..96642c4ca 100644 --- a/roms/ipxe/src/drivers/net/efi/snpnet.c +++ b/roms/ipxe/src/drivers/net/efi/snpnet.c @@ -191,7 +191,6 @@ static void snpnet_poll_tx ( struct net_device *netdev ) { int rc; /* Get status */ - txbuf = NULL; if ( ( efirc = snp->snp->GetStatus ( snp->snp, &irq, &txbuf ) ) != 0 ) { rc = -EEFI ( efirc ); DBGC ( snp, "SNP %s could not get status: %s\n", @@ -432,8 +431,8 @@ int snpnet_start ( struct efi_device *efidev ) { ( EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE )))!=0){ rc = -EEFI ( efirc ); - DBGC ( device, "SNP %s cannot open SNP protocol: %s\n", - efi_handle_name ( device ), strerror ( rc ) ); + DBGC ( device, "SNP %p %s cannot open SNP protocol: %s\n", + device, efi_handle_name ( device ), strerror ( rc ) ); DBGC_EFI_OPENERS ( device, device, &efi_simple_network_protocol_guid ); goto err_open_protocol; @@ -464,30 +463,32 @@ int snpnet_start ( struct efi_device *efidev ) { if ( ( mode->State == EfiSimpleNetworkStopped ) && ( ( efirc = snp->snp->Start ( snp->snp ) ) != 0 ) ) { rc = -EEFI ( efirc ); - DBGC ( device, "SNP %s could not start: %s\n", + DBGC ( device, "SNP %p %s could not start: %s\n", device, efi_handle_name ( device ), strerror ( rc ) ); goto err_start; } if ( ( mode->State == EfiSimpleNetworkInitialized ) && ( ( efirc = snp->snp->Shutdown ( snp->snp ) ) != 0 ) ) { rc = -EEFI ( efirc ); - DBGC ( device, "SNP %s could not shut down: %s\n", + DBGC ( device, "SNP %p %s could not shut down: %s\n", device, efi_handle_name ( device ), strerror ( rc ) ); goto err_shutdown; } /* Populate network device parameters */ if ( mode->HwAddressSize != netdev->ll_protocol->hw_addr_len ) { - DBGC ( device, "SNP %s has invalid hardware address length " - "%d\n", efi_handle_name ( device ), mode->HwAddressSize); + DBGC ( device, "SNP %p %s has invalid hardware address " + "length %d\n", device, efi_handle_name ( device ), + mode->HwAddressSize ); rc = -ENOTSUP; goto err_hw_addr_len; } memcpy ( netdev->hw_addr, &mode->PermanentAddress, netdev->ll_protocol->hw_addr_len ); if ( mode->HwAddressSize != netdev->ll_protocol->ll_addr_len ) { - DBGC ( device, "SNP %s has invalid link-layer address length " - "%d\n", efi_handle_name ( device ), mode->HwAddressSize); + DBGC ( device, "SNP %p %s has invalid link-layer address " + "length %d\n", device, efi_handle_name ( device ), + mode->HwAddressSize ); rc = -ENOTSUP; goto err_ll_addr_len; } @@ -499,8 +500,8 @@ int snpnet_start ( struct efi_device *efidev ) { /* Register network device */ if ( ( rc = register_netdev ( netdev ) ) != 0 ) goto err_register_netdev; - DBGC ( device, "SNP %s registered as %s\n", - efi_handle_name ( device ), netdev->name ); + DBGC ( device, "SNP %p %s registered as %s\n", + device, efi_handle_name ( device ), netdev->name ); /* Set initial link state */ if ( snp->snp->Mode->MediaPresentSupported ) { @@ -546,7 +547,7 @@ void snpnet_stop ( struct efi_device *efidev ) { /* Stop SNP protocol */ if ( ( efirc = snp->snp->Stop ( snp->snp ) ) != 0 ) { rc = -EEFI ( efirc ); - DBGC ( device, "SNP %s could not stop: %s\n", + DBGC ( device, "SNP %p %s could not stop: %s\n", device, efi_handle_name ( device ), strerror ( rc ) ); /* Nothing we can do about this */ } diff --git a/roms/ipxe/src/drivers/net/efi/snponly.c b/roms/ipxe/src/drivers/net/efi/snponly.c index cb7ea1bbc..73abfdbf4 100644 --- a/roms/ipxe/src/drivers/net/efi/snponly.c +++ b/roms/ipxe/src/drivers/net/efi/snponly.c @@ -81,14 +81,14 @@ static int chained_locate ( struct chained_protocol *chained ) { /* Locate handle supporting this protocol */ if ( ( rc = efi_locate_device ( device, chained->protocol, &parent ) ) != 0 ) { - DBGC ( device, "CHAINED %s does not support %s: %s\n", - efi_handle_name ( device ), + DBGC ( device, "CHAINED %p %s does not support %s: %s\n", + device, efi_handle_name ( device ), efi_guid_ntoa ( chained->protocol ), strerror ( rc ) ); goto err_locate_device; } - DBGC ( device, "CHAINED %s found %s on ", efi_handle_name ( device ), - efi_guid_ntoa ( chained->protocol ) ); - DBGC ( device, "%s\n", efi_handle_name ( parent ) ); + DBGC ( device, "CHAINED %p %s found %s on ", device, + efi_handle_name ( device ), efi_guid_ntoa ( chained->protocol )); + DBGC ( device, "%p %s\n", parent, efi_handle_name ( parent ) ); /* Get protocol instance */ if ( ( efirc = bs->OpenProtocol ( parent, chained->protocol, @@ -96,11 +96,11 @@ static int chained_locate ( struct chained_protocol *chained ) { device, EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){ rc = -EEFI ( efirc ); - DBGC ( device, "CHAINED %s could not open %s on ", - efi_handle_name ( device ), + DBGC ( device, "CHAINED %p %s could not open %s on ", + device, efi_handle_name ( device ), efi_guid_ntoa ( chained->protocol ) ); - DBGC ( device, "%s: %s\n", - efi_handle_name ( parent ), strerror ( rc ) ); + DBGC ( device, "%p %s: %s\n", + parent, efi_handle_name ( parent ), strerror ( rc ) ); goto err_open_protocol; } @@ -130,25 +130,25 @@ static int chained_supported ( EFI_HANDLE device, efi_image_handle, device, EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){ rc = -EEFI ( efirc ); - DBGCP ( device, "CHAINED %s is not a %s device\n", - efi_handle_name ( device ), + DBGCP ( device, "CHAINED %p %s is not a %s device\n", + device, efi_handle_name ( device ), efi_guid_ntoa ( chained->protocol ) ); goto err_open_protocol; } /* Test for a match against the chainloading device */ if ( interface != chained->interface ) { - DBGC ( device, "CHAINED %s %p is not the chainloaded %s\n", - efi_handle_name ( device ), interface, - efi_guid_ntoa ( chained->protocol ) ); + DBGC ( device, "CHAINED %p %s %p is not the chainloaded " + "%s\n", device, efi_handle_name ( device ), + interface, efi_guid_ntoa ( chained->protocol ) ); rc = -ENOTTY; goto err_no_match; } /* Success */ rc = 0; - DBGC ( device, "CHAINED %s %p is the chainloaded %s\n", - efi_handle_name ( device ), interface, + DBGC ( device, "CHAINED %p %s %p is the chainloaded %s\n", + device, efi_handle_name ( device ), interface, efi_guid_ntoa ( chained->protocol ) ); err_no_match: diff --git a/roms/ipxe/src/drivers/net/eoib.c b/roms/ipxe/src/drivers/net/eoib.c deleted file mode 100644 index f58e74b7d..000000000 --- a/roms/ipxe/src/drivers/net/eoib.c +++ /dev/null @@ -1,895 +0,0 @@ -/* - * Copyright (C) 2016 Michael Brown <mbrown@fensystems.co.uk>. - * - * 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 <stdio.h> -#include <string.h> -#include <errno.h> -#include <ipxe/errortab.h> -#include <ipxe/malloc.h> -#include <ipxe/iobuf.h> -#include <ipxe/if_ether.h> -#include <ipxe/netdevice.h> -#include <ipxe/ethernet.h> -#include <ipxe/infiniband.h> -#include <ipxe/ib_mcast.h> -#include <ipxe/ib_pathrec.h> -#include <ipxe/eoib.h> - -/** @file - * - * Ethernet over Infiniband - * - */ - -/** Number of EoIB send work queue entries */ -#define EOIB_NUM_SEND_WQES 8 - -/** Number of EoIB receive work queue entries */ -#define EOIB_NUM_RECV_WQES 4 - -/** Number of EoIB completion queue entries */ -#define EOIB_NUM_CQES 16 - -/** Link status for "broadcast join in progress" */ -#define EINPROGRESS_JOINING __einfo_error ( EINFO_EINPROGRESS_JOINING ) -#define EINFO_EINPROGRESS_JOINING __einfo_uniqify \ - ( EINFO_EINPROGRESS, 0x01, "Joining" ) - -/** Human-readable message for the link status */ -struct errortab eoib_errors[] __errortab = { - __einfo_errortab ( EINFO_EINPROGRESS_JOINING ), -}; - -/** List of EoIB devices */ -static LIST_HEAD ( eoib_devices ); - -static struct net_device_operations eoib_operations; - -/**************************************************************************** - * - * EoIB peer cache - * - **************************************************************************** - */ - -/** An EoIB peer cache entry */ -struct eoib_peer { - /** List of EoIB peer cache entries */ - struct list_head list; - /** Ethernet MAC */ - uint8_t mac[ETH_ALEN]; - /** Infiniband address vector */ - struct ib_address_vector av; -}; - -/** - * Find EoIB peer cache entry - * - * @v eoib EoIB device - * @v mac Ethernet MAC - * @ret peer EoIB peer, or NULL if not found - */ -static struct eoib_peer * eoib_find_peer ( struct eoib_device *eoib, - const uint8_t *mac ) { - struct eoib_peer *peer; - - /* Find peer cache entry */ - list_for_each_entry ( peer, &eoib->peers, list ) { - if ( memcmp ( mac, peer->mac, sizeof ( peer->mac ) ) == 0 ) { - /* Move peer to start of list */ - list_del ( &peer->list ); - list_add ( &peer->list, &eoib->peers ); - return peer; - } - } - - return NULL; -} - -/** - * Create EoIB peer cache entry - * - * @v eoib EoIB device - * @v mac Ethernet MAC - * @ret peer EoIB peer, or NULL on error - */ -static struct eoib_peer * eoib_create_peer ( struct eoib_device *eoib, - const uint8_t *mac ) { - struct eoib_peer *peer; - - /* Allocate and initialise peer cache entry */ - peer = zalloc ( sizeof ( *peer ) ); - if ( peer ) { - memcpy ( peer->mac, mac, sizeof ( peer->mac ) ); - list_add ( &peer->list, &eoib->peers ); - } - return peer; -} - -/** - * Flush EoIB peer cache - * - * @v eoib EoIB device - */ -static void eoib_flush_peers ( struct eoib_device *eoib ) { - struct eoib_peer *peer; - struct eoib_peer *tmp; - - list_for_each_entry_safe ( peer, tmp, &eoib->peers, list ) { - list_del ( &peer->list ); - free ( peer ); - } -} - -/** - * Discard some entries from the peer cache - * - * @ret discarded Number of cached items discarded - */ -static unsigned int eoib_discard ( void ) { - struct net_device *netdev; - struct eoib_device *eoib; - struct eoib_peer *peer; - unsigned int discarded = 0; - - /* Try to discard one cache entry for each EoIB device */ - for_each_netdev ( netdev ) { - - /* Skip non-EoIB devices */ - if ( netdev->op != &eoib_operations ) - continue; - eoib = netdev->priv; - - /* Discard least recently used cache entry (if any) */ - list_for_each_entry_reverse ( peer, &eoib->peers, list ) { - list_del ( &peer->list ); - free ( peer ); - discarded++; - break; - } - } - - return discarded; -} - -/** EoIB cache discarder */ -struct cache_discarder eoib_discarder __cache_discarder ( CACHE_EXPENSIVE ) = { - .discard = eoib_discard, -}; - -/** - * Find destination address vector - * - * @v eoib EoIB device - * @v mac Ethernet MAC - * @ret av Address vector, or NULL to send as broadcast - */ -static struct ib_address_vector * eoib_tx_av ( struct eoib_device *eoib, - const uint8_t *mac ) { - struct ib_device *ibdev = eoib->ibdev; - struct eoib_peer *peer; - int rc; - - /* If this is a broadcast or multicast MAC address, then send - * this packet as a broadcast. - */ - if ( is_multicast_ether_addr ( mac ) ) { - DBGCP ( eoib, "EoIB %s %s TX multicast\n", - eoib->name, eth_ntoa ( mac ) ); - return NULL; - } - - /* If we have no peer cache entry, then create one and send - * this packet as a broadcast. - */ - peer = eoib_find_peer ( eoib, mac ); - if ( ! peer ) { - DBGC ( eoib, "EoIB %s %s TX unknown\n", - eoib->name, eth_ntoa ( mac ) ); - eoib_create_peer ( eoib, mac ); - return NULL; - } - - /* If we have not yet recorded a received GID and QPN for this - * peer cache entry, then send this packet as a broadcast. - */ - if ( ! peer->av.gid_present ) { - DBGCP ( eoib, "EoIB %s %s TX not yet recorded\n", - eoib->name, eth_ntoa ( mac ) ); - return NULL; - } - - /* If we have not yet resolved a path to this peer, then send - * this packet as a broadcast. - */ - if ( ( rc = ib_resolve_path ( ibdev, &peer->av ) ) != 0 ) { - DBGCP ( eoib, "EoIB %s %s TX not yet resolved\n", - eoib->name, eth_ntoa ( mac ) ); - return NULL; - } - - /* Force use of GRH even for local destinations */ - peer->av.gid_present = 1; - - /* We have a fully resolved peer: send this packet as a - * unicast. - */ - DBGCP ( eoib, "EoIB %s %s TX " IB_GID_FMT " QPN %#lx\n", eoib->name, - eth_ntoa ( mac ), IB_GID_ARGS ( &peer->av.gid ), peer->av.qpn ); - return &peer->av; -} - -/** - * Record source address vector - * - * @v eoib EoIB device - * @v mac Ethernet MAC - * @v lid Infiniband LID - */ -static void eoib_rx_av ( struct eoib_device *eoib, const uint8_t *mac, - const struct ib_address_vector *av ) { - const union ib_gid *gid = &av->gid; - unsigned long qpn = av->qpn; - struct eoib_peer *peer; - - /* Sanity checks */ - if ( ! av->gid_present ) { - DBGC ( eoib, "EoIB %s %s RX with no GID\n", - eoib->name, eth_ntoa ( mac ) ); - return; - } - - /* Find peer cache entry (if any) */ - peer = eoib_find_peer ( eoib, mac ); - if ( ! peer ) { - DBGCP ( eoib, "EoIB %s %s RX " IB_GID_FMT " (ignored)\n", - eoib->name, eth_ntoa ( mac ), IB_GID_ARGS ( gid ) ); - return; - } - - /* Some dubious EoIB implementations utilise an Ethernet-to- - * EoIB gateway that will send packets from the wrong QPN. - */ - if ( eoib_has_gateway ( eoib ) && - ( memcmp ( gid, &eoib->gateway.gid, sizeof ( *gid ) ) == 0 ) ) { - qpn = eoib->gateway.qpn; - } - - /* Do nothing if peer cache entry is complete and correct */ - if ( ( peer->av.lid == av->lid ) && ( peer->av.qpn == qpn ) ) { - DBGCP ( eoib, "EoIB %s %s RX unchanged\n", - eoib->name, eth_ntoa ( mac ) ); - return; - } - - /* Update peer cache entry */ - peer->av.qpn = qpn; - peer->av.qkey = eoib->broadcast.qkey; - peer->av.gid_present = 1; - memcpy ( &peer->av.gid, gid, sizeof ( peer->av.gid ) ); - DBGC ( eoib, "EoIB %s %s RX " IB_GID_FMT " QPN %#lx\n", eoib->name, - eth_ntoa ( mac ), IB_GID_ARGS ( &peer->av.gid ), peer->av.qpn ); -} - -/**************************************************************************** - * - * EoIB network device - * - **************************************************************************** - */ - -/** - * Transmit packet via EoIB network device - * - * @v netdev Network device - * @v iobuf I/O buffer - * @ret rc Return status code - */ -static int eoib_transmit ( struct net_device *netdev, - struct io_buffer *iobuf ) { - struct eoib_device *eoib = netdev->priv; - struct eoib_header *eoib_hdr; - struct ethhdr *ethhdr; - struct ib_address_vector *av; - size_t zlen; - - /* Sanity checks */ - assert ( iob_len ( iobuf ) >= sizeof ( *ethhdr ) ); - assert ( iob_headroom ( iobuf ) >= sizeof ( *eoib_hdr ) ); - - /* Look up destination address vector */ - ethhdr = iobuf->data; - av = eoib_tx_av ( eoib, ethhdr->h_dest ); - - /* Prepend EoIB header */ - eoib_hdr = iob_push ( iobuf, sizeof ( *eoib_hdr ) ); - eoib_hdr->magic = htons ( EOIB_MAGIC ); - eoib_hdr->reserved = 0; - - /* Pad buffer to minimum Ethernet frame size */ - zlen = ( sizeof ( *eoib_hdr ) + ETH_ZLEN ); - assert ( zlen <= IOB_ZLEN ); - if ( iob_len ( iobuf ) < zlen ) - iob_pad ( iobuf, zlen ); - - /* If we have no unicast address then send as a broadcast, - * with a duplicate sent to the gateway if applicable. - */ - if ( ! av ) { - av = &eoib->broadcast; - if ( eoib_has_gateway ( eoib ) ) - eoib->duplicate ( eoib, iobuf ); - } - - /* Post send work queue entry */ - return ib_post_send ( eoib->ibdev, eoib->qp, av, iobuf ); -} - -/** - * Handle EoIB send completion - * - * @v ibdev Infiniband device - * @v qp Queue pair - * @v iobuf I/O buffer - * @v rc Completion status code - */ -static void eoib_complete_send ( struct ib_device *ibdev __unused, - struct ib_queue_pair *qp, - struct io_buffer *iobuf, int rc ) { - struct eoib_device *eoib = ib_qp_get_ownerdata ( qp ); - - netdev_tx_complete_err ( eoib->netdev, iobuf, rc ); -} - -/** - * Handle EoIB receive completion - * - * @v ibdev Infiniband device - * @v qp Queue pair - * @v dest Destination address vector, or NULL - * @v source Source address vector, or NULL - * @v iobuf I/O buffer - * @v rc Completion status code - */ -static void eoib_complete_recv ( struct ib_device *ibdev __unused, - struct ib_queue_pair *qp, - struct ib_address_vector *dest __unused, - struct ib_address_vector *source, - struct io_buffer *iobuf, int rc ) { - struct eoib_device *eoib = ib_qp_get_ownerdata ( qp ); - struct net_device *netdev = eoib->netdev; - struct eoib_header *eoib_hdr; - struct ethhdr *ethhdr; - - /* Record errors */ - if ( rc != 0 ) { - netdev_rx_err ( netdev, iobuf, rc ); - return; - } - - /* Sanity check */ - if ( iob_len ( iobuf ) < ( sizeof ( *eoib_hdr ) + sizeof ( *ethhdr ) )){ - DBGC ( eoib, "EoIB %s received packet too short to " - "contain EoIB and Ethernet headers\n", eoib->name ); - DBGC_HD ( eoib, iobuf->data, iob_len ( iobuf ) ); - netdev_rx_err ( netdev, iobuf, -EIO ); - return; - } - if ( ! source ) { - DBGC ( eoib, "EoIB %s received packet without address " - "vector\n", eoib->name ); - netdev_rx_err ( netdev, iobuf, -ENOTTY ); - return; - } - - /* Strip EoIB header */ - iob_pull ( iobuf, sizeof ( *eoib_hdr ) ); - - /* Update neighbour cache entry, if any */ - ethhdr = iobuf->data; - eoib_rx_av ( eoib, ethhdr->h_source, source ); - - /* Hand off to network layer */ - netdev_rx ( netdev, iobuf ); -} - -/** EoIB completion operations */ -static struct ib_completion_queue_operations eoib_cq_op = { - .complete_send = eoib_complete_send, - .complete_recv = eoib_complete_recv, -}; - -/** EoIB queue pair operations */ -static struct ib_queue_pair_operations eoib_qp_op = { - .alloc_iob = alloc_iob, -}; - -/** - * Poll EoIB network device - * - * @v netdev Network device - */ -static void eoib_poll ( struct net_device *netdev ) { - struct eoib_device *eoib = netdev->priv; - struct ib_device *ibdev = eoib->ibdev; - - /* Poll Infiniband device */ - ib_poll_eq ( ibdev ); - - /* Poll the retry timers (required for EoIB multicast join) */ - retry_poll(); -} - -/** - * Handle EoIB broadcast multicast group join completion - * - * @v membership Multicast group membership - * @v rc Status code - */ -static void eoib_join_complete ( struct ib_mc_membership *membership, int rc ) { - struct eoib_device *eoib = - container_of ( membership, struct eoib_device, membership ); - - /* Record join status as link status */ - netdev_link_err ( eoib->netdev, rc ); -} - -/** - * Join EoIB broadcast multicast group - * - * @v eoib EoIB device - * @ret rc Return status code - */ -static int eoib_join_broadcast_group ( struct eoib_device *eoib ) { - int rc; - - /* Join multicast group */ - if ( ( rc = ib_mcast_join ( eoib->ibdev, eoib->qp, - &eoib->membership, &eoib->broadcast, - eoib->mask, eoib_join_complete ) ) != 0 ) { - DBGC ( eoib, "EoIB %s could not join broadcast group: %s\n", - eoib->name, strerror ( rc ) ); - return rc; - } - - return 0; -} - -/** - * Leave EoIB broadcast multicast group - * - * @v eoib EoIB device - */ -static void eoib_leave_broadcast_group ( struct eoib_device *eoib ) { - - /* Leave multicast group */ - ib_mcast_leave ( eoib->ibdev, eoib->qp, &eoib->membership ); -} - -/** - * Handle link status change - * - * @v eoib EoIB device - */ -static void eoib_link_state_changed ( struct eoib_device *eoib ) { - struct net_device *netdev = eoib->netdev; - struct ib_device *ibdev = eoib->ibdev; - int rc; - - /* Leave existing broadcast group */ - if ( eoib->qp ) - eoib_leave_broadcast_group ( eoib ); - - /* Update broadcast GID based on potentially-new partition key */ - eoib->broadcast.gid.words[2] = htons ( ibdev->pkey | IB_PKEY_FULL ); - - /* Set net device link state to reflect Infiniband link state */ - rc = ib_link_rc ( ibdev ); - netdev_link_err ( netdev, ( rc ? rc : -EINPROGRESS_JOINING ) ); - - /* Join new broadcast group */ - if ( ib_is_open ( ibdev ) && ib_link_ok ( ibdev ) && eoib->qp && - ( ( rc = eoib_join_broadcast_group ( eoib ) ) != 0 ) ) { - DBGC ( eoib, "EoIB %s could not rejoin broadcast group: " - "%s\n", eoib->name, strerror ( rc ) ); - netdev_link_err ( netdev, rc ); - return; - } -} - -/** - * Open EoIB network device - * - * @v netdev Network device - * @ret rc Return status code - */ -static int eoib_open ( struct net_device *netdev ) { - struct eoib_device *eoib = netdev->priv; - struct ib_device *ibdev = eoib->ibdev; - int rc; - - /* Open IB device */ - if ( ( rc = ib_open ( ibdev ) ) != 0 ) { - DBGC ( eoib, "EoIB %s could not open %s: %s\n", - eoib->name, ibdev->name, strerror ( rc ) ); - goto err_ib_open; - } - - /* Allocate completion queue */ - eoib->cq = ib_create_cq ( ibdev, EOIB_NUM_CQES, &eoib_cq_op ); - if ( ! eoib->cq ) { - DBGC ( eoib, "EoIB %s could not allocate completion queue\n", - eoib->name ); - rc = -ENOMEM; - goto err_create_cq; - } - - /* Allocate queue pair */ - eoib->qp = ib_create_qp ( ibdev, IB_QPT_UD, EOIB_NUM_SEND_WQES, - eoib->cq, EOIB_NUM_RECV_WQES, eoib->cq, - &eoib_qp_op, netdev->name ); - if ( ! eoib->qp ) { - DBGC ( eoib, "EoIB %s could not allocate queue pair\n", - eoib->name ); - rc = -ENOMEM; - goto err_create_qp; - } - ib_qp_set_ownerdata ( eoib->qp, eoib ); - - /* Fill receive rings */ - ib_refill_recv ( ibdev, eoib->qp ); - - /* Fake a link status change to join the broadcast group */ - eoib_link_state_changed ( eoib ); - - return 0; - - ib_destroy_qp ( ibdev, eoib->qp ); - eoib->qp = NULL; - err_create_qp: - ib_destroy_cq ( ibdev, eoib->cq ); - eoib->cq = NULL; - err_create_cq: - ib_close ( ibdev ); - err_ib_open: - return rc; -} - -/** - * Close EoIB network device - * - * @v netdev Network device - */ -static void eoib_close ( struct net_device *netdev ) { - struct eoib_device *eoib = netdev->priv; - struct ib_device *ibdev = eoib->ibdev; - - /* Flush peer cache */ - eoib_flush_peers ( eoib ); - - /* Leave broadcast group */ - eoib_leave_broadcast_group ( eoib ); - - /* Tear down the queues */ - ib_destroy_qp ( ibdev, eoib->qp ); - eoib->qp = NULL; - ib_destroy_cq ( ibdev, eoib->cq ); - eoib->cq = NULL; - - /* Close IB device */ - ib_close ( ibdev ); -} - -/** EoIB network device operations */ -static struct net_device_operations eoib_operations = { - .open = eoib_open, - .close = eoib_close, - .transmit = eoib_transmit, - .poll = eoib_poll, -}; - -/** - * Create EoIB device - * - * @v ibdev Infiniband device - * @v hw_addr Ethernet MAC - * @v broadcast Broadcast address vector - * @v name Interface name (or NULL to use default) - * @ret rc Return status code - */ -int eoib_create ( struct ib_device *ibdev, const uint8_t *hw_addr, - struct ib_address_vector *broadcast, const char *name ) { - struct net_device *netdev; - struct eoib_device *eoib; - int rc; - - /* Allocate network device */ - netdev = alloc_etherdev ( sizeof ( *eoib ) ); - if ( ! netdev ) { - rc = -ENOMEM; - goto err_alloc; - } - netdev_init ( netdev, &eoib_operations ); - eoib = netdev->priv; - netdev->dev = ibdev->dev; - eoib->netdev = netdev; - eoib->ibdev = ibdev_get ( ibdev ); - memcpy ( &eoib->broadcast, broadcast, sizeof ( eoib->broadcast ) ); - INIT_LIST_HEAD ( &eoib->peers ); - - /* Set MAC address */ - memcpy ( netdev->hw_addr, hw_addr, ETH_ALEN ); - - /* Set interface name, if applicable */ - if ( name ) - snprintf ( netdev->name, sizeof ( netdev->name ), "%s", name ); - eoib->name = netdev->name; - - /* Add to list of EoIB devices */ - list_add_tail ( &eoib->list, &eoib_devices ); - - /* Register network device */ - if ( ( rc = register_netdev ( netdev ) ) != 0 ) - goto err_register; - - DBGC ( eoib, "EoIB %s created for %s MAC %s\n", - eoib->name, ibdev->name, eth_ntoa ( hw_addr ) ); - DBGC ( eoib, "EoIB %s broadcast GID " IB_GID_FMT "\n", - eoib->name, IB_GID_ARGS ( &broadcast->gid ) ); - return 0; - - unregister_netdev ( netdev ); - err_register: - list_del ( &eoib->list ); - ibdev_put ( ibdev ); - netdev_nullify ( netdev ); - netdev_put ( netdev ); - err_alloc: - return rc; -} - -/** - * Find EoIB device - * - * @v ibdev Infiniband device - * @v hw_addr Original Ethernet MAC - * @ret eoib EoIB device - */ -struct eoib_device * eoib_find ( struct ib_device *ibdev, - const uint8_t *hw_addr ) { - struct eoib_device *eoib; - - list_for_each_entry ( eoib, &eoib_devices, list ) { - if ( ( eoib->ibdev == ibdev ) && - ( memcmp ( eoib->netdev->hw_addr, hw_addr, - ETH_ALEN ) == 0 ) ) - return eoib; - } - return NULL; -} - -/** - * Remove EoIB device - * - * @v eoib EoIB device - */ -void eoib_destroy ( struct eoib_device *eoib ) { - struct net_device *netdev = eoib->netdev; - - /* Unregister network device */ - unregister_netdev ( netdev ); - - /* Remove from list of network devices */ - list_del ( &eoib->list ); - - /* Drop reference to Infiniband device */ - ibdev_put ( eoib->ibdev ); - - /* Free network device */ - DBGC ( eoib, "EoIB %s destroyed\n", eoib->name ); - netdev_nullify ( netdev ); - netdev_put ( netdev ); -} - -/** - * Probe EoIB device - * - * @v ibdev Infiniband device - * @ret rc Return status code - */ -static int eoib_probe ( struct ib_device *ibdev __unused ) { - - /* EoIB devices are not created automatically */ - return 0; -} - -/** - * Handle device or link status change - * - * @v ibdev Infiniband device - */ -static void eoib_notify ( struct ib_device *ibdev ) { - struct eoib_device *eoib; - - /* Handle link status change for any attached EoIB devices */ - list_for_each_entry ( eoib, &eoib_devices, list ) { - if ( eoib->ibdev != ibdev ) - continue; - eoib_link_state_changed ( eoib ); - } -} - -/** - * Remove EoIB device - * - * @v ibdev Infiniband device - */ -static void eoib_remove ( struct ib_device *ibdev ) { - struct eoib_device *eoib; - struct eoib_device *tmp; - - /* Remove any attached EoIB devices */ - list_for_each_entry_safe ( eoib, tmp, &eoib_devices, list ) { - if ( eoib->ibdev != ibdev ) - continue; - eoib_destroy ( eoib ); - } -} - -/** EoIB driver */ -struct ib_driver eoib_driver __ib_driver = { - .name = "EoIB", - .probe = eoib_probe, - .notify = eoib_notify, - .remove = eoib_remove, -}; - -/**************************************************************************** - * - * EoIB heartbeat packets - * - **************************************************************************** - */ - -/** - * Silently ignore incoming EoIB heartbeat packets - * - * @v iobuf I/O buffer - * @v netdev Network device - * @v ll_source Link-layer source address - * @v flags Packet flags - * @ret rc Return status code - */ -static int eoib_heartbeat_rx ( struct io_buffer *iobuf, - struct net_device *netdev __unused, - const void *ll_dest __unused, - const void *ll_source __unused, - unsigned int flags __unused ) { - free_iob ( iobuf ); - return 0; -} - -/** - * Transcribe EoIB heartbeat address - * - * @v net_addr EoIB heartbeat address - * @ret string "<EoIB>" - * - * This operation is meaningless for the EoIB heartbeat protocol. - */ -static const char * eoib_heartbeat_ntoa ( const void *net_addr __unused ) { - return "<EoIB>"; -} - -/** EoIB heartbeat network protocol */ -struct net_protocol eoib_heartbeat_protocol __net_protocol = { - .name = "EoIB", - .net_proto = htons ( EOIB_MAGIC ), - .rx = eoib_heartbeat_rx, - .ntoa = eoib_heartbeat_ntoa, -}; - -/**************************************************************************** - * - * EoIB gateway - * - **************************************************************************** - * - * Some dubious EoIB implementations require all broadcast traffic to - * be sent twice: once to the actual broadcast group, and once as a - * unicast to the EoIB-to-Ethernet gateway. This somewhat curious - * design arises since the EoIB-to-Ethernet gateway hardware lacks the - * ability to attach a queue pair to a multicast GID (or LID), and so - * cannot receive traffic sent to the broadcast group. - * - */ - -/** - * Transmit duplicate packet to the EoIB gateway - * - * @v eoib EoIB device - * @v original Original I/O buffer - */ -static void eoib_duplicate ( struct eoib_device *eoib, - struct io_buffer *original ) { - struct net_device *netdev = eoib->netdev; - struct ib_device *ibdev = eoib->ibdev; - struct ib_address_vector *av = &eoib->gateway; - size_t len = iob_len ( original ); - struct io_buffer *copy; - int rc; - - /* Create copy of I/O buffer */ - copy = alloc_iob ( len ); - if ( ! copy ) { - rc = -ENOMEM; - goto err_alloc; - } - memcpy ( iob_put ( copy, len ), original->data, len ); - - /* Append to network device's transmit queue */ - list_add_tail ( ©->list, &original->list ); - - /* Resolve path to gateway */ - if ( ( rc = ib_resolve_path ( ibdev, av ) ) != 0 ) { - DBGC ( eoib, "EoIB %s no path to gateway: %s\n", - eoib->name, strerror ( rc ) ); - goto err_path; - } - - /* Force use of GRH even for local destinations */ - av->gid_present = 1; - - /* Post send work queue entry */ - if ( ( rc = ib_post_send ( eoib->ibdev, eoib->qp, av, copy ) ) != 0 ) - goto err_post_send; - - return; - - err_post_send: - err_path: - err_alloc: - netdev_tx_complete_err ( netdev, copy, rc ); -} - -/** - * Set EoIB gateway - * - * @v eoib EoIB device - * @v av Address vector, or NULL to clear gateway - */ -void eoib_set_gateway ( struct eoib_device *eoib, - struct ib_address_vector *av ) { - - if ( av ) { - DBGC ( eoib, "EoIB %s using gateway " IB_GID_FMT "\n", - eoib->name, IB_GID_ARGS ( &av->gid ) ); - memcpy ( &eoib->gateway, av, sizeof ( eoib->gateway ) ); - eoib->duplicate = eoib_duplicate; - } else { - DBGC ( eoib, "EoIB %s not using gateway\n", eoib->name ); - eoib->duplicate = NULL; - } -} diff --git a/roms/ipxe/src/drivers/net/etherfabric.c b/roms/ipxe/src/drivers/net/etherfabric.c index 2cd41d4ca..29d117443 100644 --- a/roms/ipxe/src/drivers/net/etherfabric.c +++ b/roms/ipxe/src/drivers/net/etherfabric.c @@ -4006,7 +4006,7 @@ efab_init_mac ( struct efab_nic *efab ) * because we want to use it, or because we're about * to reset the mac anyway */ - mdelay ( 2000 ); + sleep ( 2 ); if ( ! efab->link_up ) { EFAB_ERR ( "!\n" ); diff --git a/roms/ipxe/src/drivers/net/intel.c b/roms/ipxe/src/drivers/net/intel.c index 127f5c7e7..6309e9aa5 100644 --- a/roms/ipxe/src/drivers/net/intel.c +++ b/roms/ipxe/src/drivers/net/intel.c @@ -295,23 +295,14 @@ static int intel_reset ( struct intel_nic *intel ) { writel ( ctrl, intel->regs + INTEL_CTRL ); mdelay ( INTEL_RESET_DELAY_MS ); - /* On some models (notably ICH), the PHY reset mechanism - * appears to be broken. In particular, the PHY_CTRL register - * will be correctly loaded from NVM but the values will not - * be propagated to the "OEM bits" PHY register. This - * typically has the effect of dropping the link speed to - * 10Mbps. - * - * Work around this problem by skipping the PHY reset if - * either (a) the link is already up, or (b) this particular - * NIC is known to be broken. + /* If link is already up, do not attempt to reset the PHY. On + * some models (notably ICH), performing a PHY reset seems to + * drop the link speed to 10Mbps. */ status = readl ( intel->regs + INTEL_STATUS ); - if ( ( intel->flags & INTEL_NO_PHY_RST ) || - ( status & INTEL_STATUS_LU ) ) { - DBGC ( intel, "INTEL %p %sMAC reset (ctrl %08x)\n", intel, - ( ( intel->flags & INTEL_NO_PHY_RST ) ? "forced " : "" ), - ctrl ); + if ( status & INTEL_STATUS_LU ) { + DBGC ( intel, "INTEL %p MAC reset (ctrl %08x)\n", + intel, ctrl ); return 0; } @@ -1038,7 +1029,7 @@ static struct pci_device_id intel_nics[] = { PCI_ROM ( 0x8086, 0x10f5, "82567lm", "82567LM", 0 ), PCI_ROM ( 0x8086, 0x10f6, "82574l", "82574L", 0 ), PCI_ROM ( 0x8086, 0x1501, "82567v-3", "82567V-3", INTEL_PBS_ERRATA ), - PCI_ROM ( 0x8086, 0x1502, "82579lm", "82579LM", INTEL_NO_PHY_RST ), + PCI_ROM ( 0x8086, 0x1502, "82579lm", "82579LM", 0 ), PCI_ROM ( 0x8086, 0x1503, "82579v", "82579V", 0 ), PCI_ROM ( 0x8086, 0x150a, "82576ns", "82576NS", 0 ), PCI_ROM ( 0x8086, 0x150c, "82583v", "82583V", 0 ), @@ -1057,18 +1048,14 @@ static struct pci_device_id intel_nics[] = { PCI_ROM ( 0x8086, 0x1526, "82576-5", "82576", 0 ), PCI_ROM ( 0x8086, 0x1527, "82580-f2", "82580 Fiber", 0 ), PCI_ROM ( 0x8086, 0x1533, "i210", "I210", 0 ), - PCI_ROM ( 0x8086, 0x1539, "i211", "I211", 0 ), - PCI_ROM ( 0x8086, 0x153a, "i217lm", "I217-LM", INTEL_NO_PHY_RST ), + PCI_ROM ( 0x8086, 0x153a, "i217lm", "I217-LM", 0 ), PCI_ROM ( 0x8086, 0x153b, "i217v", "I217-V", 0 ), PCI_ROM ( 0x8086, 0x1559, "i218v", "I218-V", 0), PCI_ROM ( 0x8086, 0x155a, "i218lm", "I218-LM", 0), - PCI_ROM ( 0x8086, 0x157b, "i210-2", "I210", 0 ), - PCI_ROM ( 0x8086, 0x15a0, "i218lm-2", "I218-LM", INTEL_NO_PHY_RST ), + PCI_ROM ( 0x8086, 0x15a0, "i218lm-2", "I218-LM", 0 ), PCI_ROM ( 0x8086, 0x15a1, "i218v-2", "I218-V", 0 ), - PCI_ROM ( 0x8086, 0x15a2, "i218lm-3", "I218-LM", INTEL_NO_PHY_RST ), - PCI_ROM ( 0x8086, 0x15a3, "i218v-3", "I218-V", INTEL_NO_PHY_RST ), - PCI_ROM ( 0x8086, 0x15b7, "i219lm-2", "I219-LM (2)", 0 ), - PCI_ROM ( 0x8086, 0x15b8, "i219v-2", "I219-V (2)", 0 ), + PCI_ROM ( 0x8086, 0x15a2, "i218lm-3", "I218-LM", 0 ), + PCI_ROM ( 0x8086, 0x15a3, "i218v-3", "I218-V", 0 ), PCI_ROM ( 0x8086, 0x294c, "82566dc-2", "82566DC-2", 0 ), PCI_ROM ( 0x8086, 0x2e6e, "cemedia", "CE Media Processor", 0 ), }; diff --git a/roms/ipxe/src/drivers/net/intel.h b/roms/ipxe/src/drivers/net/intel.h index 16a72a11b..ce9e3f467 100644 --- a/roms/ipxe/src/drivers/net/intel.h +++ b/roms/ipxe/src/drivers/net/intel.h @@ -99,8 +99,8 @@ struct intel_descriptor { #define INTEL_IRQ_TXQE 0x00000002UL /**< Transmit queue empty */ #define INTEL_IRQ_LSC 0x00000004UL /**< Link status change */ #define INTEL_IRQ_RXDMT0 0x00000010UL /**< Receive queue low */ -#define INTEL_IRQ_RXO 0x00000040UL /**< Receive overrun */ #define INTEL_IRQ_RXT0 0x00000080UL /**< Receive timer */ +#define INTEL_IRQ_RXO 0x00000400UL /**< Receive overrun */ /** Interrupt Mask Set/Read Register */ #define INTEL_IMS 0x000d0UL @@ -301,8 +301,6 @@ enum intel_flags { INTEL_PBS_ERRATA = 0x0001, /** VMware missing interrupt workaround required */ INTEL_VMWARE = 0x0002, - /** PHY reset is broken */ - INTEL_NO_PHY_RST = 0x0004, }; /** diff --git a/roms/ipxe/src/drivers/net/ipoib.c b/roms/ipxe/src/drivers/net/ipoib.c index 8a65c87ba..6552d764e 100644 --- a/roms/ipxe/src/drivers/net/ipoib.c +++ b/roms/ipxe/src/drivers/net/ipoib.c @@ -65,23 +65,13 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); "Missing REMAC for IPv4 packet (ARP sent)" ) /** Number of IPoIB send work queue entries */ -#define IPOIB_NUM_SEND_WQES 8 +#define IPOIB_NUM_SEND_WQES 2 /** Number of IPoIB receive work queue entries */ #define IPOIB_NUM_RECV_WQES 4 /** Number of IPoIB completion entries */ -#define IPOIB_NUM_CQES 16 - -/** An IPoIB broadcast address */ -struct ipoib_broadcast { - /** MAC address */ - struct ipoib_mac mac; - /** Address vector */ - struct ib_address_vector av; - /** Multicast group membership */ - struct ib_mc_membership membership; -}; +#define IPOIB_NUM_CQES 8 /** An IPoIB device */ struct ipoib_device { @@ -89,16 +79,22 @@ struct ipoib_device { struct net_device *netdev; /** Underlying Infiniband device */ struct ib_device *ibdev; - /** List of IPoIB devices */ - struct list_head list; /** Completion queue */ struct ib_completion_queue *cq; /** Queue pair */ struct ib_queue_pair *qp; /** Local MAC */ struct ipoib_mac mac; - /** Broadcast address */ - struct ipoib_broadcast broadcast; + /** Broadcast MAC */ + struct ipoib_mac broadcast; + /** Joined to IPv4 broadcast multicast group + * + * This flag indicates whether or not we have initiated the + * join to the IPv4 broadcast multicast group. + */ + int broadcast_joined; + /** IPv4 broadcast multicast group membership */ + struct ib_mc_membership broadcast_membership; /** REMAC cache */ struct list_head peers; }; @@ -120,9 +116,6 @@ struct errortab ipoib_errors[] __errortab = { __einfo_errortab ( EINFO_EINPROGRESS_JOINING ), }; -/** List of all IPoIB devices */ -static LIST_HEAD ( ipoib_devices ); - static struct net_device_operations ipoib_operations; /**************************************************************************** @@ -157,7 +150,7 @@ static struct ipoib_mac * ipoib_find_remac ( struct ipoib_device *ipoib, * multicasts as broadcasts for simplicity. */ if ( is_multicast_ether_addr ( remac ) ) - return &ipoib->broadcast.mac; + return &ipoib->broadcast; /* Try to find via REMAC cache */ list_for_each_entry ( peer, &ipoib->peers, list ) { @@ -503,10 +496,8 @@ static int ipoib_transmit ( struct net_device *netdev, struct ethhdr *ethhdr; struct iphdr *iphdr; struct ipoib_hdr *ipoib_hdr; - struct ipoib_remac *remac; struct ipoib_mac *mac; - struct ib_address_vector *dest; - struct ib_address_vector av; + struct ib_address_vector dest; uint16_t net_proto; int rc; @@ -524,32 +515,12 @@ static int ipoib_transmit ( struct net_device *netdev, /* Strip eIPoIB header */ ethhdr = iobuf->data; - remac = ( ( struct ipoib_remac * ) ethhdr->h_dest ); net_proto = ethhdr->h_protocol; iob_pull ( iobuf, sizeof ( *ethhdr ) ); /* Identify destination address */ - if ( is_multicast_ether_addr ( remac ) ) { - - /* Transmit multicasts as broadcasts, for simplicity */ - dest = &ipoib->broadcast.av; - - } else if ( ( mac = ipoib_find_remac ( ipoib, remac ) ) ) { - - /* Construct address vector from IPoIB MAC */ - dest = &av; - memset ( dest, 0, sizeof ( *dest ) ); - dest->qpn = ( ntohl ( mac->flags__qpn ) & IB_QPN_MASK ); - dest->qkey = ipoib->broadcast.av.qkey; - dest->gid_present = 1; - memcpy ( &dest->gid, &mac->gid, sizeof ( dest->gid ) ); - if ( ( rc = ib_resolve_path ( ibdev, dest ) ) != 0 ) { - /* Path not resolved yet */ - return rc; - } - - } else { - + mac = ipoib_find_remac ( ipoib, ( ( void * ) ethhdr->h_dest ) ); + if ( ! mac ) { /* Generate a new ARP request (if possible) to trigger * population of the REMAC cache entry. */ @@ -586,8 +557,17 @@ static int ipoib_transmit ( struct net_device *netdev, ipoib_hdr->proto = net_proto; ipoib_hdr->reserved = 0; - /* Transmit packet */ - return ib_post_send ( ibdev, ipoib->qp, dest, iobuf ); + /* Construct address vector */ + memset ( &dest, 0, sizeof ( dest ) ); + dest.qpn = ( ntohl ( mac->flags__qpn ) & IB_QPN_MASK ); + dest.gid_present = 1; + memcpy ( &dest.gid, &mac->gid, sizeof ( dest.gid ) ); + if ( ( rc = ib_resolve_path ( ibdev, &dest ) ) != 0 ) { + /* Path not resolved yet */ + return rc; + } + + return ib_post_send ( ibdev, ipoib->qp, &dest, iobuf ); } /** @@ -671,8 +651,9 @@ static void ipoib_complete_recv ( struct ib_device *ibdev __unused, ethhdr->h_protocol = net_proto; /* Construct destination address */ - if ( dest->gid_present && IB_GID_MULTICAST ( &dest->gid ) ) { - /* Multicast GID: use the Ethernet broadcast address */ + if ( dest->gid_present && ( memcmp ( &dest->gid, &ipoib->broadcast.gid, + sizeof ( dest->gid ) ) == 0 ) ) { + /* Broadcast GID; use the Ethernet broadcast address */ memcpy ( ðhdr->h_dest, eth_broadcast, sizeof ( ethhdr->h_dest ) ); } else { @@ -746,13 +727,18 @@ static void ipoib_poll ( struct net_device *netdev ) { /** * Handle IPv4 broadcast multicast group join completion * + * @v ibdev Infiniband device + * @v qp Queue pair * @v membership Multicast group membership * @v rc Status code + * @v mad Response MAD (or NULL on error) */ -void ipoib_join_complete ( struct ib_mc_membership *membership, int rc ) { +void ipoib_join_complete ( struct ib_device *ibdev __unused, + struct ib_queue_pair *qp __unused, + struct ib_mc_membership *membership, int rc, + union ib_mad *mad __unused ) { struct ipoib_device *ipoib = container_of ( membership, - struct ipoib_device, - broadcast.membership ); + struct ipoib_device, broadcast_membership ); /* Record join status as link status */ netdev_link_err ( ipoib->netdev, rc ); @@ -767,15 +753,15 @@ void ipoib_join_complete ( struct ib_mc_membership *membership, int rc ) { static int ipoib_join_broadcast_group ( struct ipoib_device *ipoib ) { int rc; - /* Join multicast group */ if ( ( rc = ib_mcast_join ( ipoib->ibdev, ipoib->qp, - &ipoib->broadcast.membership, - &ipoib->broadcast.av, 0, + &ipoib->broadcast_membership, + &ipoib->broadcast.gid, ipoib_join_complete ) ) != 0 ) { DBGC ( ipoib, "IPoIB %p could not join broadcast group: %s\n", ipoib, strerror ( rc ) ); return rc; } + ipoib->broadcast_joined = 1; return 0; } @@ -787,19 +773,21 @@ static int ipoib_join_broadcast_group ( struct ipoib_device *ipoib ) { */ static void ipoib_leave_broadcast_group ( struct ipoib_device *ipoib ) { - /* Leave multicast group */ - ib_mcast_leave ( ipoib->ibdev, ipoib->qp, - &ipoib->broadcast.membership ); + if ( ipoib->broadcast_joined ) { + ib_mcast_leave ( ipoib->ibdev, ipoib->qp, + &ipoib->broadcast_membership ); + ipoib->broadcast_joined = 0; + } } /** * Handle link status change * - * @v ipoib IPoIB device + * @v ibdev Infiniband device */ -static void ipoib_link_state_changed ( struct ipoib_device *ipoib ) { - struct ib_device *ibdev = ipoib->ibdev; - struct net_device *netdev = ipoib->netdev; +static void ipoib_link_state_changed ( struct ib_device *ibdev ) { + struct net_device *netdev = ib_get_ownerdata ( ibdev ); + struct ipoib_device *ipoib = netdev->priv; int rc; /* Leave existing broadcast group */ @@ -810,17 +798,10 @@ static void ipoib_link_state_changed ( struct ipoib_device *ipoib ) { memcpy ( &ipoib->mac.gid.s.prefix, &ibdev->gid.s.prefix, sizeof ( ipoib->mac.gid.s.prefix ) ); - /* Update broadcast MAC GID based on potentially-new partition key */ - ipoib->broadcast.mac.gid.words[2] = + /* Update broadcast GID based on potentially-new partition key */ + ipoib->broadcast.gid.words[2] = htons ( ibdev->pkey | IB_PKEY_FULL ); - /* Construct broadcast address vector from broadcast MAC address */ - memset ( &ipoib->broadcast.av, 0, sizeof ( ipoib->broadcast.av ) ); - ipoib->broadcast.av.qpn = IB_QPN_BROADCAST; - ipoib->broadcast.av.gid_present = 1; - memcpy ( &ipoib->broadcast.av.gid, &ipoib->broadcast.mac.gid, - sizeof ( ipoib->broadcast.av.gid ) ); - /* Set net device link state to reflect Infiniband link state */ rc = ib_link_rc ( ibdev ); netdev_link_err ( netdev, ( rc ? rc : -EINPROGRESS_JOINING ) ); @@ -865,7 +846,7 @@ static int ipoib_open ( struct net_device *netdev ) { /* Allocate queue pair */ ipoib->qp = ib_create_qp ( ibdev, IB_QPT_UD, IPOIB_NUM_SEND_WQES, ipoib->cq, IPOIB_NUM_RECV_WQES, ipoib->cq, - &ipoib_qp_op, netdev->name ); + &ipoib_qp_op ); if ( ! ipoib->qp ) { DBGC ( ipoib, "IPoIB %p could not allocate queue pair\n", ipoib ); @@ -881,7 +862,7 @@ static int ipoib_open ( struct net_device *netdev ) { ib_refill_recv ( ibdev, ipoib->qp ); /* Fake a link status change to join the broadcast group */ - ipoib_link_state_changed ( ipoib ); + ipoib_link_state_changed ( ibdev ); return 0; @@ -947,6 +928,7 @@ static int ipoib_probe ( struct ib_device *ibdev ) { return -ENOMEM; netdev_init ( netdev, &ipoib_operations ); ipoib = netdev->priv; + ib_set_ownerdata ( ibdev, netdev ); netdev->dev = ibdev->dev; memset ( ipoib, 0, sizeof ( *ipoib ) ); ipoib->netdev = netdev; @@ -956,18 +938,14 @@ static int ipoib_probe ( struct ib_device *ibdev ) { /* Extract hardware address */ memcpy ( netdev->hw_addr, &ibdev->gid.s.guid, sizeof ( ibdev->gid.s.guid ) ); - memcpy ( netdev->ll_addr, ibdev->lemac, ETH_ALEN ); /* Set local MAC address */ memcpy ( &ipoib->mac.gid.s.guid, &ibdev->gid.s.guid, sizeof ( ipoib->mac.gid.s.guid ) ); /* Set default broadcast MAC address */ - memcpy ( &ipoib->broadcast.mac, &ipoib_broadcast, - sizeof ( ipoib->broadcast.mac ) ); - - /* Add to list of IPoIB devices */ - list_add_tail ( &ipoib->list, &ipoib_devices ); + memcpy ( &ipoib->broadcast, &ipoib_broadcast, + sizeof ( ipoib->broadcast ) ); /* Register network device */ if ( ( rc = register_netdev ( netdev ) ) != 0 ) @@ -975,74 +953,29 @@ static int ipoib_probe ( struct ib_device *ibdev ) { return 0; - unregister_netdev ( netdev ); err_register_netdev: - list_del ( &ipoib->list ); netdev_nullify ( netdev ); netdev_put ( netdev ); return rc; } /** - * Handle device or link status change - * - * @v ibdev Infiniband device - */ -static void ipoib_notify ( struct ib_device *ibdev ) { - struct ipoib_device *ipoib; - - /* Handle link status change for any attached IPoIB devices */ - list_for_each_entry ( ipoib, &ipoib_devices, list ) { - if ( ipoib->ibdev != ibdev ) - continue; - ipoib_link_state_changed ( ipoib ); - } -} - -/** * Remove IPoIB device * * @v ibdev Infiniband device */ static void ipoib_remove ( struct ib_device *ibdev ) { - struct ipoib_device *ipoib; - struct ipoib_device *tmp; - struct net_device *netdev; + struct net_device *netdev = ib_get_ownerdata ( ibdev ); - /* Remove any attached IPoIB devices */ - list_for_each_entry_safe ( ipoib, tmp, &ipoib_devices, list ) { - if ( ipoib->ibdev != ibdev ) - continue; - netdev = ipoib->netdev; - unregister_netdev ( netdev ); - list_del ( &ipoib->list ); - netdev_nullify ( netdev ); - netdev_put ( netdev ); - } + unregister_netdev ( netdev ); + netdev_nullify ( netdev ); + netdev_put ( netdev ); } /** IPoIB driver */ struct ib_driver ipoib_driver __ib_driver = { .name = "IPoIB", .probe = ipoib_probe, - .notify = ipoib_notify, + .notify = ipoib_link_state_changed, .remove = ipoib_remove, }; - -/** - * Find IPoIB network device - * - * @v ibdev Infiniband device - * @ret netdev IPoIB network device, or NULL if not found - */ -struct net_device * ipoib_netdev ( struct ib_device *ibdev ) { - struct ipoib_device *ipoib; - - /* Find matching IPoIB device */ - list_for_each_entry ( ipoib, &ipoib_devices, list ) { - if ( ipoib->ibdev != ibdev ) - continue; - return ipoib->netdev; - } - return NULL; -} diff --git a/roms/ipxe/src/drivers/net/ncm.c b/roms/ipxe/src/drivers/net/ncm.c index 1837291f7..10728d2a1 100644 --- a/roms/ipxe/src/drivers/net/ncm.c +++ b/roms/ipxe/src/drivers/net/ncm.c @@ -186,7 +186,7 @@ static int ncm_in_prefill ( struct ncm_device *ncm ) { count = NCM_IN_MIN_COUNT; if ( ( count * mtu ) > NCM_IN_MAX_SIZE ) continue; - usb_refill_init ( &ncm->usbnet.in, 0, mtu, count ); + usb_refill_init ( &ncm->usbnet.in, mtu, count ); if ( ( rc = usb_prefill ( &ncm->usbnet.in ) ) != 0 ) { DBGC ( ncm, "NCM %p could not prefill %dx %zd-byte " "buffers for bulk IN\n", ncm, count, mtu ); @@ -453,15 +453,6 @@ static int ncm_open ( struct net_device *netdev ) { goto err_set_ntb_input_size; } - /* Set MAC address */ - if ( ( rc = usb_control ( usb, NCM_SET_NET_ADDRESS, 0, - ncm->usbnet.comms, netdev->ll_addr, - netdev->ll_protocol->ll_addr_len ) ) != 0 ) { - DBGC ( ncm, "NCM %p could not set MAC address: %s\n", - ncm, strerror ( rc ) ); - /* Ignore error and continue */ - } - /* Open USB network device */ if ( ( rc = usbnet_open ( &ncm->usbnet ) ) != 0 ) { DBGC ( ncm, "NCM %p could not open: %s\n", @@ -575,7 +566,7 @@ static int ncm_probe ( struct usb_function *func, ncm->netdev = netdev; usbnet_init ( &ncm->usbnet, func, &ncm_intr_operations, &ncm_in_operations, &ncm_out_operations ); - usb_refill_init ( &ncm->usbnet.intr, 0, 0, NCM_INTR_COUNT ); + usb_refill_init ( &ncm->usbnet.intr, 0, NCM_INTR_COUNT ); DBGC ( ncm, "NCM %p on %s\n", ncm, func->name ); /* Describe USB network device */ @@ -664,6 +655,11 @@ static struct usb_device_id ncm_ids[] = { .name = "cdc-ncm", .vendor = USB_ANY_ID, .product = USB_ANY_ID, + .class = { + .class = USB_CLASS_CDC, + .subclass = USB_SUBCLASS_CDC_NCM, + .protocol = 0, + }, }, }; @@ -671,8 +667,6 @@ static struct usb_device_id ncm_ids[] = { struct usb_driver ncm_driver __usb_driver = { .ids = ncm_ids, .id_count = ( sizeof ( ncm_ids ) / sizeof ( ncm_ids[0] ) ), - .class = USB_CLASS_ID ( USB_CLASS_CDC, USB_SUBCLASS_CDC_NCM, 0 ), - .score = USB_SCORE_NORMAL, .probe = ncm_probe, .remove = ncm_remove, }; diff --git a/roms/ipxe/src/drivers/net/ncm.h b/roms/ipxe/src/drivers/net/ncm.h index 6b0d21cdb..a9565a56b 100644 --- a/roms/ipxe/src/drivers/net/ncm.h +++ b/roms/ipxe/src/drivers/net/ncm.h @@ -51,11 +51,6 @@ struct ncm_ntb_parameters { uint16_t max; } __attribute__ (( packed )); -/** Set MAC address */ -#define NCM_SET_NET_ADDRESS \ - ( USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE | \ - USB_REQUEST_TYPE ( 0x82 ) ) - /** Set NTB input size */ #define NCM_SET_NTB_INPUT_SIZE \ ( USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE | \ diff --git a/roms/ipxe/src/drivers/net/phantom/phantom.c b/roms/ipxe/src/drivers/net/phantom/phantom.c index 781049ff4..38b66743c 100644 --- a/roms/ipxe/src/drivers/net/phantom/phantom.c +++ b/roms/ipxe/src/drivers/net/phantom/phantom.c @@ -2060,7 +2060,6 @@ static int phantom_probe ( struct pci_device *pci ) { struct net_device *netdev; struct phantom_nic *phantom; struct settings *parent_settings; - unsigned int busdevfn; int rc; /* Allocate Phantom device */ @@ -2091,20 +2090,19 @@ static int phantom_probe ( struct pci_device *pci ) { * B2 will have this fixed; remove this hack when B1 is no * longer in use. */ - busdevfn = pci->busdevfn; - if ( PCI_FUNC ( busdevfn ) == 0 ) { + if ( PCI_FUNC ( pci->busdevfn ) == 0 ) { unsigned int i; for ( i = 0 ; i < 8 ; i++ ) { uint32_t temp; pci->busdevfn = - PCI_BUSDEVFN ( PCI_SEG ( busdevfn ), - PCI_BUS ( busdevfn ), - PCI_SLOT ( busdevfn ), i ); + PCI_BUSDEVFN ( PCI_BUS ( pci->busdevfn ), + PCI_SLOT ( pci->busdevfn ), i ); pci_read_config_dword ( pci, 0xc8, &temp ); pci_read_config_dword ( pci, 0xc8, &temp ); pci_write_config_dword ( pci, 0xc8, 0xf1000 ); } - pci->busdevfn = busdevfn; + pci->busdevfn = PCI_BUSDEVFN ( PCI_BUS ( pci->busdevfn ), + PCI_SLOT ( pci->busdevfn ), 0 ); } /* Initialise the command PEG */ diff --git a/roms/ipxe/src/drivers/net/sis190.c b/roms/ipxe/src/drivers/net/sis190.c index 81f3d9844..991c30f9e 100644 --- a/roms/ipxe/src/drivers/net/sis190.c +++ b/roms/ipxe/src/drivers/net/sis190.c @@ -72,6 +72,12 @@ struct pci_driver sis190_isa_bridge_driver __pci_driver = { static const u32 sis190_intr_mask = RxQEmpty | RxQInt | TxQ1Int | TxQ0Int | RxHalt | TxHalt | LinkChange; +/* + * Maximum number of multicast addresses to filter (vs. Rx-all-multicast). + * The chips use a 64 element hash table based on the Ethernet CRC. + */ +static const int multicast_filter_limit = 32; + static void __mdio_cmd(void *ioaddr, u32 ctl) { unsigned int i; diff --git a/roms/ipxe/src/drivers/net/sis190.h b/roms/ipxe/src/drivers/net/sis190.h index 79f94d2d9..0551333d5 100644 --- a/roms/ipxe/src/drivers/net/sis190.h +++ b/roms/ipxe/src/drivers/net/sis190.h @@ -297,6 +297,13 @@ static struct mii_chip_info { { NULL, { 0x00, 0x00 }, 0, 0 } }; +static const struct { + const char *name; +} sis_chip_info[] = { + { "SiS 190 PCI Fast Ethernet adapter" }, + { "SiS 191 PCI Gigabit Ethernet adapter" }, +}; + static void sis190_phy_task(struct sis190_private *tp); static void sis190_free(struct net_device *dev); static inline void sis190_init_rxfilter(struct net_device *dev); diff --git a/roms/ipxe/src/drivers/net/skge.c b/roms/ipxe/src/drivers/net/skge.c index c3264225b..6384e7647 100755 --- a/roms/ipxe/src/drivers/net/skge.c +++ b/roms/ipxe/src/drivers/net/skge.c @@ -84,6 +84,9 @@ static struct net_device_operations skge_operations = { /* Avoid conditionals by using array */ static const int txqaddr[] = { Q_XA1, Q_XA2 }; static const int rxqaddr[] = { Q_R1, Q_R2 }; +static const u32 rxirqmask[] = { IS_R1_F, IS_R2_F }; +static const u32 txirqmask[] = { IS_XA1_F, IS_XA2_F }; +static const u32 napimask[] = { IS_R1_F|IS_XA1_F, IS_R2_F|IS_XA2_F }; static const u32 portmask[] = { IS_PORT_1, IS_PORT_2 }; /* Determine supported/advertised modes based on hardware. @@ -1919,6 +1922,8 @@ static void skge_tx_clean(struct net_device *dev) skge->tx_ring.to_clean = e; } +static const u8 pause_mc_addr[ETH_ALEN] = { 0x1, 0x80, 0xc2, 0x0, 0x0, 0x1 }; + static inline u16 phy_length(const struct skge_hw *hw, u32 status) { if (hw->chip_id == CHIP_ID_GENESIS) diff --git a/roms/ipxe/src/drivers/net/smsc75xx.c b/roms/ipxe/src/drivers/net/smsc75xx.c index 4ce98ac80..017e02a59 100644 --- a/roms/ipxe/src/drivers/net/smsc75xx.c +++ b/roms/ipxe/src/drivers/net/smsc75xx.c @@ -511,7 +511,6 @@ static int smsc75xx_dump_statistics ( struct smsc75xx_device *smsc75xx ) { */ static int smsc75xx_reset ( struct smsc75xx_device *smsc75xx ) { uint32_t hw_cfg; - unsigned int i; int rc; /* Reset device */ @@ -520,22 +519,18 @@ static int smsc75xx_reset ( struct smsc75xx_device *smsc75xx ) { return rc; /* Wait for reset to complete */ - for ( i = 0 ; i < SMSC75XX_RESET_MAX_WAIT_MS ; i++ ) { + udelay ( SMSC75XX_RESET_DELAY_US ); - /* Check if reset has completed */ - if ( ( rc = smsc75xx_readl ( smsc75xx, SMSC75XX_HW_CFG, - &hw_cfg ) ) != 0 ) - return rc; - if ( ! ( hw_cfg & SMSC75XX_HW_CFG_LRST ) ) - return 0; - - /* Delay */ - mdelay ( 1 ); + /* Check that reset has completed */ + if ( ( rc = smsc75xx_readl ( smsc75xx, SMSC75XX_HW_CFG, + &hw_cfg ) ) != 0 ) + return rc; + if ( hw_cfg & SMSC75XX_HW_CFG_LRST ) { + DBGC ( smsc75xx, "SMSC75XX %p failed to reset\n", smsc75xx ); + return -ETIMEDOUT; } - DBGC ( smsc75xx, "SMSC75XX %p timed out waiting for reset\n", - smsc75xx ); - return -ETIMEDOUT; + return 0; } /****************************************************************************** @@ -984,9 +979,8 @@ static int smsc75xx_probe ( struct usb_function *func, smsc75xx->netdev = netdev; usbnet_init ( &smsc75xx->usbnet, func, &smsc75xx_intr_operations, &smsc75xx_in_operations, &smsc75xx_out_operations ); - usb_refill_init ( &smsc75xx->usbnet.intr, 0, 0, - SMSC75XX_INTR_MAX_FILL ); - usb_refill_init ( &smsc75xx->usbnet.in, 0, SMSC75XX_IN_MTU, + usb_refill_init ( &smsc75xx->usbnet.intr, 0, SMSC75XX_INTR_MAX_FILL ); + usb_refill_init ( &smsc75xx->usbnet.in, SMSC75XX_IN_MTU, SMSC75XX_IN_MAX_FILL ); mii_init ( &smsc75xx->mii, &smsc75xx_mii_operations ); DBGC ( smsc75xx, "SMSC75XX %p on %s\n", smsc75xx, func->name ); @@ -1044,11 +1038,13 @@ static struct usb_device_id smsc75xx_ids[] = { .name = "smsc7500", .vendor = 0x0424, .product = 0x7500, + .class = { 0xff, 0x00, 0xff }, }, { .name = "smsc7505", .vendor = 0x0424, .product = 0x7505, + .class = { 0xff, 0x00, 0xff }, }, }; @@ -1056,8 +1052,6 @@ static struct usb_device_id smsc75xx_ids[] = { struct usb_driver smsc75xx_driver __usb_driver = { .ids = smsc75xx_ids, .id_count = ( sizeof ( smsc75xx_ids ) / sizeof ( smsc75xx_ids[0] ) ), - .class = USB_CLASS_ID ( 0xff, 0x00, 0xff ), - .score = USB_SCORE_NORMAL, .probe = smsc75xx_probe, .remove = smsc75xx_remove, }; diff --git a/roms/ipxe/src/drivers/net/smsc75xx.h b/roms/ipxe/src/drivers/net/smsc75xx.h index ae81fc168..2463b72a1 100644 --- a/roms/ipxe/src/drivers/net/smsc75xx.h +++ b/roms/ipxe/src/drivers/net/smsc75xx.h @@ -280,8 +280,8 @@ struct smsc75xx_device { uint32_t int_sts; }; -/** Maximum time to wait for reset (in milliseconds) */ -#define SMSC75XX_RESET_MAX_WAIT_MS 100 +/** Reset delay (in microseconds) */ +#define SMSC75XX_RESET_DELAY_US 2 /** Maximum time to wait for EEPROM (in milliseconds) */ #define SMSC75XX_EEPROM_MAX_WAIT_MS 100 diff --git a/roms/ipxe/src/drivers/net/smsc95xx.c b/roms/ipxe/src/drivers/net/smsc95xx.c deleted file mode 100644 index 3d9c0f1aa..000000000 --- a/roms/ipxe/src/drivers/net/smsc95xx.c +++ /dev/null @@ -1,1300 +0,0 @@ -/* - * Copyright (C) 2015 Michael Brown <mbrown@fensystems.co.uk>. - * - * 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 (at your option) 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 <string.h> -#include <unistd.h> -#include <errno.h> -#include <byteswap.h> -#include <ipxe/ethernet.h> -#include <ipxe/usb.h> -#include <ipxe/usbnet.h> -#include <ipxe/profile.h> -#include <ipxe/base16.h> -#include <ipxe/smbios.h> -#include "smsc95xx.h" - -/** @file - * - * SMSC LAN95xx USB Ethernet driver - * - */ - -/** Interrupt completion profiler */ -static struct profiler smsc95xx_intr_profiler __profiler = - { .name = "smsc95xx.intr" }; - -/** Bulk IN completion profiler */ -static struct profiler smsc95xx_in_profiler __profiler = - { .name = "smsc95xx.in" }; - -/** Bulk OUT profiler */ -static struct profiler smsc95xx_out_profiler __profiler = - { .name = "smsc95xx.out" }; - -/****************************************************************************** - * - * Register access - * - ****************************************************************************** - */ - -/** - * Write register (without byte-swapping) - * - * @v smsc95xx SMSC95xx device - * @v address Register address - * @v value Register value - * @ret rc Return status code - */ -static int smsc95xx_raw_writel ( struct smsc95xx_device *smsc95xx, - unsigned int address, uint32_t value ) { - int rc; - - /* Write register */ - DBGCIO ( smsc95xx, "SMSC95XX %p [%03x] <= %08x\n", - smsc95xx, address, le32_to_cpu ( value ) ); - if ( ( rc = usb_control ( smsc95xx->usb, SMSC95XX_REGISTER_WRITE, 0, - address, &value, sizeof ( value ) ) ) != 0 ) { - DBGC ( smsc95xx, "SMSC95XX %p could not write %03x: %s\n", - smsc95xx, address, strerror ( rc ) ); - return rc; - } - - return 0; -} - -/** - * Write register - * - * @v smsc95xx SMSC95xx device - * @v address Register address - * @v value Register value - * @ret rc Return status code - */ -static inline __attribute__ (( always_inline )) int -smsc95xx_writel ( struct smsc95xx_device *smsc95xx, unsigned int address, - uint32_t value ) { - int rc; - - /* Write register */ - if ( ( rc = smsc95xx_raw_writel ( smsc95xx, address, - cpu_to_le32 ( value ) ) ) != 0 ) - return rc; - - return 0; -} - -/** - * Read register (without byte-swapping) - * - * @v smsc95xx SMSC95xx device - * @v address Register address - * @ret value Register value - * @ret rc Return status code - */ -static int smsc95xx_raw_readl ( struct smsc95xx_device *smsc95xx, - unsigned int address, uint32_t *value ) { - int rc; - - /* Read register */ - if ( ( rc = usb_control ( smsc95xx->usb, SMSC95XX_REGISTER_READ, 0, - address, value, sizeof ( *value ) ) ) != 0 ) { - DBGC ( smsc95xx, "SMSC95XX %p could not read %03x: %s\n", - smsc95xx, address, strerror ( rc ) ); - return rc; - } - DBGCIO ( smsc95xx, "SMSC95XX %p [%03x] => %08x\n", - smsc95xx, address, le32_to_cpu ( *value ) ); - - return 0; -} - -/** - * Read register - * - * @v smsc95xx SMSC95xx device - * @v address Register address - * @ret value Register value - * @ret rc Return status code - */ -static inline __attribute__ (( always_inline )) int -smsc95xx_readl ( struct smsc95xx_device *smsc95xx, unsigned int address, - uint32_t *value ) { - int rc; - - /* Read register */ - if ( ( rc = smsc95xx_raw_readl ( smsc95xx, address, value ) ) != 0 ) - return rc; - le32_to_cpus ( value ); - - return 0; -} - -/****************************************************************************** - * - * EEPROM access - * - ****************************************************************************** - */ - -/** - * Wait for EEPROM to become idle - * - * @v smsc95xx SMSC95xx device - * @ret rc Return status code - */ -static int smsc95xx_eeprom_wait ( struct smsc95xx_device *smsc95xx ) { - uint32_t e2p_cmd; - unsigned int i; - int rc; - - /* Wait for EPC_BSY to become clear */ - for ( i = 0 ; i < SMSC95XX_EEPROM_MAX_WAIT_MS ; i++ ) { - - /* Read E2P_CMD and check EPC_BSY */ - if ( ( rc = smsc95xx_readl ( smsc95xx, SMSC95XX_E2P_CMD, - &e2p_cmd ) ) != 0 ) - return rc; - if ( ! ( e2p_cmd & SMSC95XX_E2P_CMD_EPC_BSY ) ) - return 0; - - /* Delay */ - mdelay ( 1 ); - } - - DBGC ( smsc95xx, "SMSC95XX %p timed out waiting for EEPROM\n", - smsc95xx ); - return -ETIMEDOUT; -} - -/** - * Read byte from EEPROM - * - * @v smsc95xx SMSC95xx device - * @v address EEPROM address - * @ret byte Byte read, or negative error - */ -static int smsc95xx_eeprom_read_byte ( struct smsc95xx_device *smsc95xx, - unsigned int address ) { - uint32_t e2p_cmd; - uint32_t e2p_data; - int rc; - - /* Wait for EEPROM to become idle */ - if ( ( rc = smsc95xx_eeprom_wait ( smsc95xx ) ) != 0 ) - return rc; - - /* Initiate read command */ - e2p_cmd = ( SMSC95XX_E2P_CMD_EPC_BSY | SMSC95XX_E2P_CMD_EPC_CMD_READ | - SMSC95XX_E2P_CMD_EPC_ADDR ( address ) ); - if ( ( rc = smsc95xx_writel ( smsc95xx, SMSC95XX_E2P_CMD, - e2p_cmd ) ) != 0 ) - return rc; - - /* Wait for command to complete */ - if ( ( rc = smsc95xx_eeprom_wait ( smsc95xx ) ) != 0 ) - return rc; - - /* Read EEPROM data */ - if ( ( rc = smsc95xx_readl ( smsc95xx, SMSC95XX_E2P_DATA, - &e2p_data ) ) != 0 ) - return rc; - - return SMSC95XX_E2P_DATA_GET ( e2p_data ); -} - -/** - * Read data from EEPROM - * - * @v smsc95xx SMSC95xx device - * @v address EEPROM address - * @v data Data buffer - * @v len Length of data - * @ret rc Return status code - */ -static int smsc95xx_eeprom_read ( struct smsc95xx_device *smsc95xx, - unsigned int address, void *data, - size_t len ) { - uint8_t *bytes; - int byte; - - /* Read bytes */ - for ( bytes = data ; len-- ; address++, bytes++ ) { - byte = smsc95xx_eeprom_read_byte ( smsc95xx, address ); - if ( byte < 0 ) - return byte; - *bytes = byte; - } - - return 0; -} - -/****************************************************************************** - * - * MAC address - * - ****************************************************************************** - */ - -/** - * Fetch MAC address from EEPROM - * - * @v smsc95xx SMSC95xx device - * @v hw_addr Hardware address to fill in - * @ret rc Return status code - */ -static int smsc95xx_fetch_mac_eeprom ( struct smsc95xx_device *smsc95xx, - uint8_t *hw_addr ) { - int rc; - - /* Read MAC address from EEPROM */ - if ( ( rc = smsc95xx_eeprom_read ( smsc95xx, SMSC95XX_EEPROM_MAC, - hw_addr, ETH_ALEN ) ) != 0 ) - return rc; - - /* Check that EEPROM is physically present */ - if ( ! is_valid_ether_addr ( hw_addr ) ) { - DBGC ( smsc95xx, "SMSC95XX %p has no EEPROM (%s)\n", - smsc95xx, eth_ntoa ( hw_addr ) ); - return -ENODEV; - } - - DBGC ( smsc95xx, "SMSC95XX %p using EEPROM MAC %s\n", - smsc95xx, eth_ntoa ( hw_addr ) ); - return 0; -} - -/** - * Construct MAC address for Honeywell VM3 - * - * @v smsc95xx SMSC95xx device - * @v hw_addr Hardware address to fill in - * @ret rc Return status code - */ -static int smsc95xx_fetch_mac_vm3 ( struct smsc95xx_device *smsc95xx, - uint8_t *hw_addr ) { - struct smbios_structure structure; - struct smbios_system_information system; - struct { - char manufacturer[ 10 /* "Honeywell" + NUL */ ]; - char product[ 4 /* "VM3" + NUL */ ]; - char mac[ base16_encoded_len ( ETH_ALEN ) + 1 /* NUL */ ]; - } strings; - int len; - int rc; - - /* Find system information */ - if ( ( rc = find_smbios_structure ( SMBIOS_TYPE_SYSTEM_INFORMATION, 0, - &structure ) ) != 0 ) { - DBGC ( smsc95xx, "SMSC95XX %p could not find system " - "information: %s\n", smsc95xx, strerror ( rc ) ); - return rc; - } - - /* Read system information */ - if ( ( rc = read_smbios_structure ( &structure, &system, - sizeof ( system ) ) ) != 0 ) { - DBGC ( smsc95xx, "SMSC95XX %p could not read system " - "information: %s\n", smsc95xx, strerror ( rc ) ); - return rc; - } - - /* NUL-terminate all strings to be fetched */ - memset ( &strings, 0, sizeof ( strings ) ); - - /* Fetch system manufacturer name */ - len = read_smbios_string ( &structure, system.manufacturer, - strings.manufacturer, - ( sizeof ( strings.manufacturer ) - 1 ) ); - if ( len < 0 ) { - rc = len; - DBGC ( smsc95xx, "SMSC95XX %p could not read manufacturer " - "name: %s\n", smsc95xx, strerror ( rc ) ); - return rc; - } - - /* Fetch system product name */ - len = read_smbios_string ( &structure, system.product, strings.product, - ( sizeof ( strings.product ) - 1 ) ); - if ( len < 0 ) { - rc = len; - DBGC ( smsc95xx, "SMSC95XX %p could not read product name: " - "%s\n", smsc95xx, strerror ( rc ) ); - return rc; - } - - /* Ignore non-VM3 devices */ - if ( ( strcmp ( strings.manufacturer, "Honeywell" ) != 0 ) || - ( strcmp ( strings.product, "VM3" ) != 0 ) ) - return -ENOTTY; - - /* Find OEM strings */ - if ( ( rc = find_smbios_structure ( SMBIOS_TYPE_OEM_STRINGS, 0, - &structure ) ) != 0 ) { - DBGC ( smsc95xx, "SMSC95XX %p could not find OEM strings: %s\n", - smsc95xx, strerror ( rc ) ); - return rc; - } - - /* Fetch MAC address */ - len = read_smbios_string ( &structure, SMSC95XX_VM3_OEM_STRING_MAC, - strings.mac, ( sizeof ( strings.mac ) - 1 )); - if ( len < 0 ) { - rc = len; - DBGC ( smsc95xx, "SMSC95XX %p could not read OEM string: %s\n", - smsc95xx, strerror ( rc ) ); - return rc; - } - - /* Sanity check */ - if ( len != ( ( int ) ( sizeof ( strings.mac ) - 1 ) ) ) { - DBGC ( smsc95xx, "SMSC95XX %p invalid MAC address \"%s\"\n", - smsc95xx, strings.mac ); - return -EINVAL; - } - - /* Decode MAC address */ - len = base16_decode ( strings.mac, hw_addr, ETH_ALEN ); - if ( len < 0 ) { - rc = len; - DBGC ( smsc95xx, "SMSC95XX %p invalid MAC address \"%s\"\n", - smsc95xx, strings.mac ); - return rc; - } - - DBGC ( smsc95xx, "SMSC95XX %p using VM3 MAC %s\n", - smsc95xx, eth_ntoa ( hw_addr ) ); - return 0; -} - -/** - * Fetch MAC address - * - * @v smsc95xx SMSC95xx device - * @v hw_addr Hardware address to fill in - * @ret rc Return status code - */ -static int smsc95xx_fetch_mac ( struct smsc95xx_device *smsc95xx, - uint8_t *hw_addr ) { - int rc; - - /* Read MAC address from EEPROM, if present */ - if ( ( rc = smsc95xx_fetch_mac_eeprom ( smsc95xx, hw_addr ) ) == 0 ) - return 0; - - /* Construct MAC address for Honeywell VM3, if applicable */ - if ( ( rc = smsc95xx_fetch_mac_vm3 ( smsc95xx, hw_addr ) ) == 0 ) - return 0; - - /* Otherwise, generate a random MAC address */ - eth_random_addr ( hw_addr ); - DBGC ( smsc95xx, "SMSC95XX %p using random MAC %s\n", - smsc95xx, eth_ntoa ( hw_addr ) ); - return 0; -} - -/****************************************************************************** - * - * MII access - * - ****************************************************************************** - */ - -/** - * Wait for MII to become idle - * - * @v smsc95xx SMSC95xx device - * @ret rc Return status code - */ -static int smsc95xx_mii_wait ( struct smsc95xx_device *smsc95xx ) { - uint32_t mii_access; - unsigned int i; - int rc; - - /* Wait for MIIBZY to become clear */ - for ( i = 0 ; i < SMSC95XX_MII_MAX_WAIT_MS ; i++ ) { - - /* Read MII_ACCESS and check MIIBZY */ - if ( ( rc = smsc95xx_readl ( smsc95xx, SMSC95XX_MII_ACCESS, - &mii_access ) ) != 0 ) - return rc; - if ( ! ( mii_access & SMSC95XX_MII_ACCESS_MIIBZY ) ) - return 0; - - /* Delay */ - mdelay ( 1 ); - } - - DBGC ( smsc95xx, "SMSC95XX %p timed out waiting for MII\n", - smsc95xx ); - return -ETIMEDOUT; -} - -/** - * Read from MII register - * - * @v mii MII interface - * @v reg Register address - * @ret value Data read, or negative error - */ -static int smsc95xx_mii_read ( struct mii_interface *mii, unsigned int reg ) { - struct smsc95xx_device *smsc95xx = - container_of ( mii, struct smsc95xx_device, mii ); - uint32_t mii_access; - uint32_t mii_data; - int rc; - - /* Wait for MII to become idle */ - if ( ( rc = smsc95xx_mii_wait ( smsc95xx ) ) != 0 ) - return rc; - - /* Initiate read command */ - mii_access = ( SMSC95XX_MII_ACCESS_PHY_ADDRESS | - SMSC95XX_MII_ACCESS_MIIRINDA ( reg ) | - SMSC95XX_MII_ACCESS_MIIBZY ); - if ( ( rc = smsc95xx_writel ( smsc95xx, SMSC95XX_MII_ACCESS, - mii_access ) ) != 0 ) - return rc; - - /* Wait for command to complete */ - if ( ( rc = smsc95xx_mii_wait ( smsc95xx ) ) != 0 ) - return rc; - - /* Read MII data */ - if ( ( rc = smsc95xx_readl ( smsc95xx, SMSC95XX_MII_DATA, - &mii_data ) ) != 0 ) - return rc; - - return SMSC95XX_MII_DATA_GET ( mii_data ); -} - -/** - * Write to MII register - * - * @v mii MII interface - * @v reg Register address - * @v data Data to write - * @ret rc Return status code - */ -static int smsc95xx_mii_write ( struct mii_interface *mii, unsigned int reg, - unsigned int data ) { - struct smsc95xx_device *smsc95xx = - container_of ( mii, struct smsc95xx_device, mii ); - uint32_t mii_access; - uint32_t mii_data; - int rc; - - /* Wait for MII to become idle */ - if ( ( rc = smsc95xx_mii_wait ( smsc95xx ) ) != 0 ) - return rc; - - /* Write MII data */ - mii_data = SMSC95XX_MII_DATA_SET ( data ); - if ( ( rc = smsc95xx_writel ( smsc95xx, SMSC95XX_MII_DATA, - mii_data ) ) != 0 ) - return rc; - - /* Initiate write command */ - mii_access = ( SMSC95XX_MII_ACCESS_PHY_ADDRESS | - SMSC95XX_MII_ACCESS_MIIRINDA ( reg ) | - SMSC95XX_MII_ACCESS_MIIWNR | - SMSC95XX_MII_ACCESS_MIIBZY ); - if ( ( rc = smsc95xx_writel ( smsc95xx, SMSC95XX_MII_ACCESS, - mii_access ) ) != 0 ) - return rc; - - /* Wait for command to complete */ - if ( ( rc = smsc95xx_mii_wait ( smsc95xx ) ) != 0 ) - return rc; - - return 0; -} - -/** MII operations */ -static struct mii_operations smsc95xx_mii_operations = { - .read = smsc95xx_mii_read, - .write = smsc95xx_mii_write, -}; - -/** - * Check link status - * - * @v smsc95xx SMSC95xx device - * @ret rc Return status code - */ -static int smsc95xx_check_link ( struct smsc95xx_device *smsc95xx ) { - struct net_device *netdev = smsc95xx->netdev; - int intr; - int rc; - - /* Read PHY interrupt source */ - intr = mii_read ( &smsc95xx->mii, SMSC95XX_MII_PHY_INTR_SOURCE ); - if ( intr < 0 ) { - rc = intr; - DBGC ( smsc95xx, "SMSC95XX %p could not get PHY interrupt " - "source: %s\n", smsc95xx, strerror ( rc ) ); - return rc; - } - - /* Acknowledge PHY interrupt */ - if ( ( rc = mii_write ( &smsc95xx->mii, SMSC95XX_MII_PHY_INTR_SOURCE, - intr ) ) != 0 ) { - DBGC ( smsc95xx, "SMSC95XX %p could not acknowledge PHY " - "interrupt: %s\n", smsc95xx, strerror ( rc ) ); - return rc; - } - - /* Check link status */ - if ( ( rc = mii_check_link ( &smsc95xx->mii, netdev ) ) != 0 ) { - DBGC ( smsc95xx, "SMSC95XX %p could not check link: %s\n", - smsc95xx, strerror ( rc ) ); - return rc; - } - - DBGC ( smsc95xx, "SMSC95XX %p link %s (intr %#04x)\n", - smsc95xx, ( netdev_link_ok ( netdev ) ? "up" : "down" ), intr ); - return 0; -} - -/****************************************************************************** - * - * Statistics (for debugging) - * - ****************************************************************************** - */ - -/** - * Get RX statistics - * - * @v smsc95xx SMSC95xx device - * @v stats Statistics to fill in - * @ret rc Return status code - */ -static int smsc95xx_get_rx_statistics ( struct smsc95xx_device *smsc95xx, - struct smsc95xx_rx_statistics *stats ) { - int rc; - - /* Get statistics */ - if ( ( rc = usb_control ( smsc95xx->usb, SMSC95XX_GET_STATISTICS, 0, - SMSC95XX_RX_STATISTICS, stats, - sizeof ( *stats ) ) ) != 0 ) { - DBGC ( smsc95xx, "SMSC95XX %p could not get RX statistics: " - "%s\n", smsc95xx, strerror ( rc ) ); - return rc; - } - - return 0; -} - -/** - * Get TX statistics - * - * @v smsc95xx SMSC95xx device - * @v stats Statistics to fill in - * @ret rc Return status code - */ -static int smsc95xx_get_tx_statistics ( struct smsc95xx_device *smsc95xx, - struct smsc95xx_tx_statistics *stats ) { - int rc; - - /* Get statistics */ - if ( ( rc = usb_control ( smsc95xx->usb, SMSC95XX_GET_STATISTICS, 0, - SMSC95XX_TX_STATISTICS, stats, - sizeof ( *stats ) ) ) != 0 ) { - DBGC ( smsc95xx, "SMSC95XX %p could not get TX statistics: " - "%s\n", smsc95xx, strerror ( rc ) ); - return rc; - } - - return 0; -} - -/** - * Dump statistics (for debugging) - * - * @v smsc95xx SMSC95xx device - * @ret rc Return status code - */ -static int smsc95xx_dump_statistics ( struct smsc95xx_device *smsc95xx ) { - struct smsc95xx_rx_statistics rx; - struct smsc95xx_tx_statistics tx; - int rc; - - /* Do nothing unless debugging is enabled */ - if ( ! DBG_LOG ) - return 0; - - /* Get RX statistics */ - if ( ( rc = smsc95xx_get_rx_statistics ( smsc95xx, &rx ) ) != 0 ) - return rc; - - /* Get TX statistics */ - if ( ( rc = smsc95xx_get_tx_statistics ( smsc95xx, &tx ) ) != 0 ) - return rc; - - /* Dump statistics */ - DBGC ( smsc95xx, "SMSC95XX %p RX good %d bad %d crc %d und %d aln %d " - "ovr %d lat %d drp %d\n", smsc95xx, le32_to_cpu ( rx.good ), - le32_to_cpu ( rx.bad ), le32_to_cpu ( rx.crc ), - le32_to_cpu ( rx.undersize ), le32_to_cpu ( rx.alignment ), - le32_to_cpu ( rx.oversize ), le32_to_cpu ( rx.late ), - le32_to_cpu ( rx.dropped ) ); - DBGC ( smsc95xx, "SMSC95XX %p TX good %d bad %d pau %d sgl %d mul %d " - "exc %d lat %d und %d def %d car %d\n", smsc95xx, - le32_to_cpu ( tx.good ), le32_to_cpu ( tx.bad ), - le32_to_cpu ( tx.pause ), le32_to_cpu ( tx.single ), - le32_to_cpu ( tx.multiple ), le32_to_cpu ( tx.excessive ), - le32_to_cpu ( tx.late ), le32_to_cpu ( tx.underrun ), - le32_to_cpu ( tx.deferred ), le32_to_cpu ( tx.carrier ) ); - - return 0; -} - -/****************************************************************************** - * - * Device reset - * - ****************************************************************************** - */ - -/** - * Reset device - * - * @v smsc95xx SMSC95xx device - * @ret rc Return status code - */ -static int smsc95xx_reset ( struct smsc95xx_device *smsc95xx ) { - uint32_t hw_cfg; - uint32_t led_gpio_cfg; - int rc; - - /* Reset device */ - if ( ( rc = smsc95xx_writel ( smsc95xx, SMSC95XX_HW_CFG, - SMSC95XX_HW_CFG_LRST ) ) != 0 ) - return rc; - - /* Wait for reset to complete */ - udelay ( SMSC95XX_RESET_DELAY_US ); - - /* Check that reset has completed */ - if ( ( rc = smsc95xx_readl ( smsc95xx, SMSC95XX_HW_CFG, - &hw_cfg ) ) != 0 ) - return rc; - if ( hw_cfg & SMSC95XX_HW_CFG_LRST ) { - DBGC ( smsc95xx, "SMSC95XX %p failed to reset\n", smsc95xx ); - return -ETIMEDOUT; - } - - /* Configure LEDs */ - led_gpio_cfg = ( SMSC95XX_LED_GPIO_CFG_GPCTL2_NSPD_LED | - SMSC95XX_LED_GPIO_CFG_GPCTL1_NLNKA_LED | - SMSC95XX_LED_GPIO_CFG_GPCTL0_NFDX_LED ); - if ( ( rc = smsc95xx_writel ( smsc95xx, SMSC95XX_LED_GPIO_CFG, - led_gpio_cfg ) ) != 0 ) { - DBGC ( smsc95xx, "SMSC95XX %p could not configure LEDs: %s\n", - smsc95xx, strerror ( rc ) ); - /* Ignore error and continue */ - } - - return 0; -} - -/****************************************************************************** - * - * Endpoint operations - * - ****************************************************************************** - */ - -/** - * Complete interrupt transfer - * - * @v ep USB endpoint - * @v iobuf I/O buffer - * @v rc Completion status code - */ -static void smsc95xx_intr_complete ( struct usb_endpoint *ep, - struct io_buffer *iobuf, int rc ) { - struct smsc95xx_device *smsc95xx = - container_of ( ep, struct smsc95xx_device, usbnet.intr ); - struct net_device *netdev = smsc95xx->netdev; - struct smsc95xx_interrupt *intr; - - /* Profile completions */ - profile_start ( &smsc95xx_intr_profiler ); - - /* Ignore packets cancelled when the endpoint closes */ - if ( ! ep->open ) - goto done; - - /* Record USB errors against the network device */ - if ( rc != 0 ) { - DBGC ( smsc95xx, "SMSC95XX %p interrupt failed: %s\n", - smsc95xx, strerror ( rc ) ); - DBGC_HDA ( smsc95xx, 0, iobuf->data, iob_len ( iobuf ) ); - netdev_rx_err ( netdev, NULL, rc ); - goto done; - } - - /* Extract interrupt data */ - if ( iob_len ( iobuf ) != sizeof ( *intr ) ) { - DBGC ( smsc95xx, "SMSC95XX %p malformed interrupt\n", - smsc95xx ); - DBGC_HDA ( smsc95xx, 0, iobuf->data, iob_len ( iobuf ) ); - netdev_rx_err ( netdev, NULL, rc ); - goto done; - } - intr = iobuf->data; - - /* Record interrupt status */ - smsc95xx->int_sts = le32_to_cpu ( intr->int_sts ); - profile_stop ( &smsc95xx_intr_profiler ); - - done: - /* Free I/O buffer */ - free_iob ( iobuf ); -} - -/** Interrupt endpoint operations */ -static struct usb_endpoint_driver_operations smsc95xx_intr_operations = { - .complete = smsc95xx_intr_complete, -}; - -/** - * Complete bulk IN transfer - * - * @v ep USB endpoint - * @v iobuf I/O buffer - * @v rc Completion status code - */ -static void smsc95xx_in_complete ( struct usb_endpoint *ep, - struct io_buffer *iobuf, int rc ) { - struct smsc95xx_device *smsc95xx = - container_of ( ep, struct smsc95xx_device, usbnet.in ); - struct net_device *netdev = smsc95xx->netdev; - struct smsc95xx_rx_header *header; - - /* Profile completions */ - profile_start ( &smsc95xx_in_profiler ); - - /* Ignore packets cancelled when the endpoint closes */ - if ( ! ep->open ) { - free_iob ( iobuf ); - return; - } - - /* Record USB errors against the network device */ - if ( rc != 0 ) { - DBGC ( smsc95xx, "SMSC95XX %p bulk IN failed: %s\n", - smsc95xx, strerror ( rc ) ); - goto err; - } - - /* Sanity check */ - if ( iob_len ( iobuf ) < ( sizeof ( *header ) + 4 /* CRC */ ) ) { - DBGC ( smsc95xx, "SMSC95XX %p underlength bulk IN\n", - smsc95xx ); - DBGC_HDA ( smsc95xx, 0, iobuf->data, iob_len ( iobuf ) ); - rc = -EINVAL; - goto err; - } - - /* Strip header and CRC */ - header = iobuf->data; - iob_pull ( iobuf, sizeof ( *header ) ); - iob_unput ( iobuf, 4 /* CRC */ ); - - /* Check for errors */ - if ( header->command & cpu_to_le32 ( SMSC95XX_RX_RUNT | - SMSC95XX_RX_LATE | - SMSC95XX_RX_CRC ) ) { - DBGC ( smsc95xx, "SMSC95XX %p receive error (%08x):\n", - smsc95xx, le32_to_cpu ( header->command ) ); - DBGC_HDA ( smsc95xx, 0, iobuf->data, iob_len ( iobuf ) ); - rc = -EIO; - goto err; - } - - /* Hand off to network stack */ - netdev_rx ( netdev, iob_disown ( iobuf ) ); - - profile_stop ( &smsc95xx_in_profiler ); - return; - - err: - /* Hand off to network stack */ - netdev_rx_err ( netdev, iob_disown ( iobuf ), rc ); -} - -/** Bulk IN endpoint operations */ -static struct usb_endpoint_driver_operations smsc95xx_in_operations = { - .complete = smsc95xx_in_complete, -}; - -/** - * Transmit packet - * - * @v smsc95xx SMSC95xx device - * @v iobuf I/O buffer - * @ret rc Return status code - */ -static int smsc95xx_out_transmit ( struct smsc95xx_device *smsc95xx, - struct io_buffer *iobuf ) { - struct smsc95xx_tx_header *header; - size_t len = iob_len ( iobuf ); - int rc; - - /* Profile transmissions */ - profile_start ( &smsc95xx_out_profiler ); - - /* Prepend header */ - if ( ( rc = iob_ensure_headroom ( iobuf, sizeof ( *header ) ) ) != 0 ) - return rc; - header = iob_push ( iobuf, sizeof ( *header ) ); - header->command = cpu_to_le32 ( SMSC95XX_TX_FIRST | SMSC95XX_TX_LAST | - SMSC95XX_TX_LEN ( len ) ); - header->len = cpu_to_le32 ( len ); - - /* Enqueue I/O buffer */ - if ( ( rc = usb_stream ( &smsc95xx->usbnet.out, iobuf, 0 ) ) != 0 ) - return rc; - - profile_stop ( &smsc95xx_out_profiler ); - return 0; -} - -/** - * Complete bulk OUT transfer - * - * @v ep USB endpoint - * @v iobuf I/O buffer - * @v rc Completion status code - */ -static void smsc95xx_out_complete ( struct usb_endpoint *ep, - struct io_buffer *iobuf, int rc ) { - struct smsc95xx_device *smsc95xx = - container_of ( ep, struct smsc95xx_device, usbnet.out ); - struct net_device *netdev = smsc95xx->netdev; - - /* Report TX completion */ - netdev_tx_complete_err ( netdev, iobuf, rc ); -} - -/** Bulk OUT endpoint operations */ -static struct usb_endpoint_driver_operations smsc95xx_out_operations = { - .complete = smsc95xx_out_complete, -}; - -/****************************************************************************** - * - * Network device interface - * - ****************************************************************************** - */ - -/** - * Open network device - * - * @v netdev Network device - * @ret rc Return status code - */ -static int smsc95xx_open ( struct net_device *netdev ) { - struct smsc95xx_device *smsc95xx = netdev->priv; - union smsc95xx_mac mac; - int rc; - - /* Clear stored interrupt status */ - smsc95xx->int_sts = 0; - - /* Copy MAC address */ - memset ( &mac, 0, sizeof ( mac ) ); - memcpy ( mac.raw, netdev->ll_addr, ETH_ALEN ); - - /* Configure bulk IN empty response */ - if ( ( rc = smsc95xx_writel ( smsc95xx, SMSC95XX_HW_CFG, - SMSC95XX_HW_CFG_BIR ) ) != 0 ) - goto err_hw_cfg; - - /* Open USB network device */ - if ( ( rc = usbnet_open ( &smsc95xx->usbnet ) ) != 0 ) { - DBGC ( smsc95xx, "SMSC95XX %p could not open: %s\n", - smsc95xx, strerror ( rc ) ); - goto err_open; - } - - /* Configure interrupt endpoint */ - if ( ( rc = smsc95xx_writel ( smsc95xx, SMSC95XX_INT_EP_CTL, - ( SMSC95XX_INT_EP_CTL_RXDF_EN | - SMSC95XX_INT_EP_CTL_PHY_EN ) ) ) != 0 ) - goto err_int_ep_ctl; - - /* Configure bulk IN delay */ - if ( ( rc = smsc95xx_writel ( smsc95xx, SMSC95XX_BULK_IN_DLY, - SMSC95XX_BULK_IN_DLY_SET ( 0 ) ) ) != 0 ) - goto err_bulk_in_dly; - - /* Configure MAC */ - if ( ( rc = smsc95xx_writel ( smsc95xx, SMSC95XX_MAC_CR, - ( SMSC95XX_MAC_CR_RXALL | - SMSC95XX_MAC_CR_FDPX | - SMSC95XX_MAC_CR_MCPAS | - SMSC95XX_MAC_CR_PRMS | - SMSC95XX_MAC_CR_PASSBAD | - SMSC95XX_MAC_CR_TXEN | - SMSC95XX_MAC_CR_RXEN ) ) ) != 0 ) - goto err_mac_cr; - - /* Configure transmit datapath */ - if ( ( rc = smsc95xx_writel ( smsc95xx, SMSC95XX_TX_CFG, - SMSC95XX_TX_CFG_ON ) ) != 0 ) - goto err_tx_cfg; - - /* Write MAC address high register */ - if ( ( rc = smsc95xx_raw_writel ( smsc95xx, SMSC95XX_ADDRH, - mac.addr.h ) ) != 0 ) - goto err_addrh; - - /* Write MAC address low register */ - if ( ( rc = smsc95xx_raw_writel ( smsc95xx, SMSC95XX_ADDRL, - mac.addr.l ) ) != 0 ) - goto err_addrl; - - /* Enable PHY interrupts */ - if ( ( rc = mii_write ( &smsc95xx->mii, SMSC95XX_MII_PHY_INTR_MASK, - ( SMSC95XX_PHY_INTR_ANEG_DONE | - SMSC95XX_PHY_INTR_LINK_DOWN ) ) ) != 0 ) { - DBGC ( smsc95xx, "SMSC95XX %p could not set PHY interrupt " - "mask: %s\n", smsc95xx, strerror ( rc ) ); - goto err_phy_intr_mask; - } - - /* Update link status */ - smsc95xx_check_link ( smsc95xx ); - - return 0; - - err_phy_intr_mask: - err_addrl: - err_addrh: - err_tx_cfg: - err_mac_cr: - err_bulk_in_dly: - err_int_ep_ctl: - usbnet_close ( &smsc95xx->usbnet ); - err_open: - err_hw_cfg: - smsc95xx_reset ( smsc95xx ); - return rc; -} - -/** - * Close network device - * - * @v netdev Network device - */ -static void smsc95xx_close ( struct net_device *netdev ) { - struct smsc95xx_device *smsc95xx = netdev->priv; - - /* Close USB network device */ - usbnet_close ( &smsc95xx->usbnet ); - - /* Dump statistics (for debugging) */ - smsc95xx_dump_statistics ( smsc95xx ); - - /* Reset device */ - smsc95xx_reset ( smsc95xx ); -} - -/** - * Transmit packet - * - * @v netdev Network device - * @v iobuf I/O buffer - * @ret rc Return status code - */ -static int smsc95xx_transmit ( struct net_device *netdev, - struct io_buffer *iobuf ) { - struct smsc95xx_device *smsc95xx = netdev->priv; - int rc; - - /* Transmit packet */ - if ( ( rc = smsc95xx_out_transmit ( smsc95xx, iobuf ) ) != 0 ) - return rc; - - return 0; -} - -/** - * Poll for completed and received packets - * - * @v netdev Network device - */ -static void smsc95xx_poll ( struct net_device *netdev ) { - struct smsc95xx_device *smsc95xx = netdev->priv; - uint32_t int_sts; - int rc; - - /* Poll USB bus */ - usb_poll ( smsc95xx->bus ); - - /* Refill endpoints */ - if ( ( rc = usbnet_refill ( &smsc95xx->usbnet ) ) != 0 ) - netdev_rx_err ( netdev, NULL, rc ); - - /* Do nothing more unless there are interrupts to handle */ - int_sts = smsc95xx->int_sts; - if ( ! int_sts ) - return; - - /* Check link status if applicable */ - if ( int_sts & SMSC95XX_INT_STS_PHY_INT ) { - smsc95xx_check_link ( smsc95xx ); - int_sts &= ~SMSC95XX_INT_STS_PHY_INT; - } - - /* Record RX FIFO overflow if applicable */ - if ( int_sts & SMSC95XX_INT_STS_RXDF_INT ) { - DBGC2 ( smsc95xx, "SMSC95XX %p RX FIFO overflowed\n", - smsc95xx ); - netdev_rx_err ( netdev, NULL, -ENOBUFS ); - int_sts &= ~SMSC95XX_INT_STS_RXDF_INT; - } - - /* Check for unexpected interrupts */ - if ( int_sts ) { - DBGC ( smsc95xx, "SMSC95XX %p unexpected interrupt %#08x\n", - smsc95xx, int_sts ); - netdev_rx_err ( netdev, NULL, -ENOTTY ); - } - - /* Clear interrupts */ - if ( ( rc = smsc95xx_writel ( smsc95xx, SMSC95XX_INT_STS, - smsc95xx->int_sts ) ) != 0 ) - netdev_rx_err ( netdev, NULL, rc ); - smsc95xx->int_sts = 0; -} - -/** SMSC95xx network device operations */ -static struct net_device_operations smsc95xx_operations = { - .open = smsc95xx_open, - .close = smsc95xx_close, - .transmit = smsc95xx_transmit, - .poll = smsc95xx_poll, -}; - -/****************************************************************************** - * - * USB interface - * - ****************************************************************************** - */ - -/** - * Probe device - * - * @v func USB function - * @v config Configuration descriptor - * @ret rc Return status code - */ -static int smsc95xx_probe ( struct usb_function *func, - struct usb_configuration_descriptor *config ) { - struct usb_device *usb = func->usb; - struct net_device *netdev; - struct smsc95xx_device *smsc95xx; - int rc; - - /* Allocate and initialise structure */ - netdev = alloc_etherdev ( sizeof ( *smsc95xx ) ); - if ( ! netdev ) { - rc = -ENOMEM; - goto err_alloc; - } - netdev_init ( netdev, &smsc95xx_operations ); - netdev->dev = &func->dev; - smsc95xx = netdev->priv; - memset ( smsc95xx, 0, sizeof ( *smsc95xx ) ); - smsc95xx->usb = usb; - smsc95xx->bus = usb->port->hub->bus; - smsc95xx->netdev = netdev; - usbnet_init ( &smsc95xx->usbnet, func, &smsc95xx_intr_operations, - &smsc95xx_in_operations, &smsc95xx_out_operations ); - usb_refill_init ( &smsc95xx->usbnet.intr, 0, 0, - SMSC95XX_INTR_MAX_FILL ); - usb_refill_init ( &smsc95xx->usbnet.in, - ( sizeof ( struct smsc95xx_tx_header ) - - sizeof ( struct smsc95xx_rx_header ) ), - SMSC95XX_IN_MTU, SMSC95XX_IN_MAX_FILL ); - mii_init ( &smsc95xx->mii, &smsc95xx_mii_operations ); - DBGC ( smsc95xx, "SMSC95XX %p on %s\n", smsc95xx, func->name ); - - /* Describe USB network device */ - if ( ( rc = usbnet_describe ( &smsc95xx->usbnet, config ) ) != 0 ) { - DBGC ( smsc95xx, "SMSC95XX %p could not describe: %s\n", - smsc95xx, strerror ( rc ) ); - goto err_describe; - } - - /* Reset device */ - if ( ( rc = smsc95xx_reset ( smsc95xx ) ) != 0 ) - goto err_reset; - - /* Read MAC address */ - if ( ( rc = smsc95xx_fetch_mac ( smsc95xx, netdev->hw_addr ) ) != 0 ) - goto err_fetch_mac; - - /* Register network device */ - if ( ( rc = register_netdev ( netdev ) ) != 0 ) - goto err_register; - - usb_func_set_drvdata ( func, netdev ); - return 0; - - unregister_netdev ( netdev ); - err_register: - err_fetch_mac: - err_reset: - err_describe: - netdev_nullify ( netdev ); - netdev_put ( netdev ); - err_alloc: - return rc; -} - -/** - * Remove device - * - * @v func USB function - */ -static void smsc95xx_remove ( struct usb_function *func ) { - struct net_device *netdev = usb_func_get_drvdata ( func ); - - unregister_netdev ( netdev ); - netdev_nullify ( netdev ); - netdev_put ( netdev ); -} - -/** SMSC95xx device IDs */ -static struct usb_device_id smsc95xx_ids[] = { - { - .name = "smsc9500", - .vendor = 0x0424, - .product = 0x9500, - }, - { - .name = "smsc9505", - .vendor = 0x0424, - .product = 0x9505, - }, - { - .name = "smsc9500a", - .vendor = 0x0424, - .product = 0x9e00, - }, - { - .name = "smsc9505a", - .vendor = 0x0424, - .product = 0x9e01, - }, - { - .name = "smsc9514", - .vendor = 0x0424, - .product = 0xec00, - }, - { - .name = "smsc9500-s", - .vendor = 0x0424, - .product = 0x9900, - }, - { - .name = "smsc9505-s", - .vendor = 0x0424, - .product = 0x9901, - }, - { - .name = "smsc9500a-s", - .vendor = 0x0424, - .product = 0x9902, - }, - { - .name = "smsc9505a-s", - .vendor = 0x0424, - .product = 0x9903, - }, - { - .name = "smsc9514-s", - .vendor = 0x0424, - .product = 0x9904, - }, - { - .name = "smsc9500a-h", - .vendor = 0x0424, - .product = 0x9905, - }, - { - .name = "smsc9505a-h", - .vendor = 0x0424, - .product = 0x9906, - }, - { - .name = "smsc9500-2", - .vendor = 0x0424, - .product = 0x9907, - }, - { - .name = "smsc9500a-2", - .vendor = 0x0424, - .product = 0x9908, - }, - { - .name = "smsc9514-2", - .vendor = 0x0424, - .product = 0x9909, - }, - { - .name = "smsc9530", - .vendor = 0x0424, - .product = 0x9530, - }, - { - .name = "smsc9730", - .vendor = 0x0424, - .product = 0x9730, - }, - { - .name = "smsc89530", - .vendor = 0x0424, - .product = 0x9e08, - }, -}; - -/** SMSC LAN95xx driver */ -struct usb_driver smsc95xx_driver __usb_driver = { - .ids = smsc95xx_ids, - .id_count = ( sizeof ( smsc95xx_ids ) / sizeof ( smsc95xx_ids[0] ) ), - .class = USB_CLASS_ID ( 0xff, 0x00, 0xff ), - .score = USB_SCORE_NORMAL, - .probe = smsc95xx_probe, - .remove = smsc95xx_remove, -}; diff --git a/roms/ipxe/src/drivers/net/smsc95xx.h b/roms/ipxe/src/drivers/net/smsc95xx.h deleted file mode 100644 index c2512e0ee..000000000 --- a/roms/ipxe/src/drivers/net/smsc95xx.h +++ /dev/null @@ -1,269 +0,0 @@ -#ifndef _SMSC95XX_H -#define _SMSC95XX_H - -/** @file - * - * SMSC LAN95xx USB Ethernet driver - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#include <ipxe/usb.h> -#include <ipxe/usbnet.h> -#include <ipxe/if_ether.h> -#include <ipxe/mii.h> - -/** Register write command */ -#define SMSC95XX_REGISTER_WRITE \ - ( USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE | \ - USB_REQUEST_TYPE ( 0xa0 ) ) - -/** Register read command */ -#define SMSC95XX_REGISTER_READ \ - ( USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE | \ - USB_REQUEST_TYPE ( 0xa1 ) ) - -/** Get statistics command */ -#define SMSC95XX_GET_STATISTICS \ - ( USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE | \ - USB_REQUEST_TYPE ( 0xa2 ) ) - -/** Interrupt status register */ -#define SMSC95XX_INT_STS 0x008 -#define SMSC95XX_INT_STS_RXDF_INT 0x00000800UL /**< RX FIFO overflow */ -#define SMSC95XX_INT_STS_PHY_INT 0x00008000UL /**< PHY interrupt */ - -/** Transmit configuration register */ -#define SMSC95XX_TX_CFG 0x010 -#define SMSC95XX_TX_CFG_ON 0x00000004UL /**< TX enable */ - -/** Hardware configuration register */ -#define SMSC95XX_HW_CFG 0x014 -#define SMSC95XX_HW_CFG_BIR 0x00001000UL /**< Bulk IN use NAK */ -#define SMSC95XX_HW_CFG_LRST 0x00000008UL /**< Soft lite reset */ - -/** LED GPIO configuration register */ -#define SMSC95XX_LED_GPIO_CFG 0x024 -#define SMSC95XX_LED_GPIO_CFG_GPCTL2(x) ( (x) << 24 ) /**< GPIO 2 control */ -#define SMSC95XX_LED_GPIO_CFG_GPCTL2_NSPD_LED \ - SMSC95XX_LED_GPIO_CFG_GPCTL2 ( 1 ) /**< Link speed LED */ -#define SMSC95XX_LED_GPIO_CFG_GPCTL1(x) ( (x) << 20 ) /**< GPIO 1 control */ -#define SMSC95XX_LED_GPIO_CFG_GPCTL1_NLNKA_LED \ - SMSC95XX_LED_GPIO_CFG_GPCTL1 ( 1 ) /**< Activity LED */ -#define SMSC95XX_LED_GPIO_CFG_GPCTL0(x) ( (x) << 16 ) /**< GPIO 0 control */ -#define SMSC95XX_LED_GPIO_CFG_GPCTL0_NFDX_LED \ - SMSC95XX_LED_GPIO_CFG_GPCTL0 ( 1 ) /**< Full-duplex LED */ - -/** EEPROM command register */ -#define SMSC95XX_E2P_CMD 0x030 -#define SMSC95XX_E2P_CMD_EPC_BSY 0x80000000UL /**< EPC busy */ -#define SMSC95XX_E2P_CMD_EPC_CMD_READ 0x00000000UL /**< READ command */ -#define SMSC95XX_E2P_CMD_EPC_ADDR(addr) ( (addr) << 0 ) /**< EPC address */ - -/** EEPROM data register */ -#define SMSC95XX_E2P_DATA 0x034 -#define SMSC95XX_E2P_DATA_GET(e2p_data) \ - ( ( (e2p_data) >> 0 ) & 0xff ) /**< EEPROM data */ - -/** MAC address EEPROM address */ -#define SMSC95XX_EEPROM_MAC 0x01 - -/** Interrupt endpoint control register */ -#define SMSC95XX_INT_EP_CTL 0x068 -#define SMSC95XX_INT_EP_CTL_RXDF_EN 0x00000800UL /**< RX FIFO overflow */ -#define SMSC95XX_INT_EP_CTL_PHY_EN 0x00008000UL /**< PHY interrupt */ - -/** Bulk IN delay register */ -#define SMSC95XX_BULK_IN_DLY 0x06c -#define SMSC95XX_BULK_IN_DLY_SET(ticks) ( (ticks) << 0 ) /**< Delay / 16.7ns */ - -/** MAC control register */ -#define SMSC95XX_MAC_CR 0x100 -#define SMSC95XX_MAC_CR_RXALL 0x80000000UL /**< Receive all */ -#define SMSC95XX_MAC_CR_FDPX 0x00100000UL /**< Full duplex */ -#define SMSC95XX_MAC_CR_MCPAS 0x00080000UL /**< All multicast */ -#define SMSC95XX_MAC_CR_PRMS 0x00040000UL /**< Promiscuous */ -#define SMSC95XX_MAC_CR_PASSBAD 0x00010000UL /**< Pass bad frames */ -#define SMSC95XX_MAC_CR_TXEN 0x00000008UL /**< TX enabled */ -#define SMSC95XX_MAC_CR_RXEN 0x00000004UL /**< RX enabled */ - -/** MAC address high register */ -#define SMSC95XX_ADDRH 0x104 - -/** MAC address low register */ -#define SMSC95XX_ADDRL 0x108 - -/** MII access register */ -#define SMSC95XX_MII_ACCESS 0x114 -#define SMSC95XX_MII_ACCESS_PHY_ADDRESS 0x00000800UL /**< PHY address */ -#define SMSC95XX_MII_ACCESS_MIIRINDA(addr) ( (addr) << 6 ) /**< MII register */ -#define SMSC95XX_MII_ACCESS_MIIWNR 0x00000002UL /**< MII write */ -#define SMSC95XX_MII_ACCESS_MIIBZY 0x00000001UL /**< MII busy */ - -/** MII data register */ -#define SMSC95XX_MII_DATA 0x118 -#define SMSC95XX_MII_DATA_SET(data) ( (data) << 0 ) /**< Set data */ -#define SMSC95XX_MII_DATA_GET(mii_data) \ - ( ( (mii_data) >> 0 ) & 0xffff ) /**< Get data */ - -/** PHY interrupt source MII register */ -#define SMSC95XX_MII_PHY_INTR_SOURCE 29 - -/** PHY interrupt mask MII register */ -#define SMSC95XX_MII_PHY_INTR_MASK 30 - -/** PHY interrupt: auto-negotiation complete */ -#define SMSC95XX_PHY_INTR_ANEG_DONE 0x0040 - -/** PHY interrupt: link down */ -#define SMSC95XX_PHY_INTR_LINK_DOWN 0x0010 - -/** MAC address */ -union smsc95xx_mac { - /** MAC receive address registers */ - struct { - /** MAC receive address low register */ - uint32_t l; - /** MAC receive address high register */ - uint32_t h; - } __attribute__ (( packed )) addr; - /** Raw MAC address */ - uint8_t raw[ETH_ALEN]; -}; - -/** Receive packet header */ -struct smsc95xx_rx_header { - /** Command word */ - uint32_t command; -} __attribute__ (( packed )); - -/** Runt frame */ -#define SMSC95XX_RX_RUNT 0x00004000UL - -/** Late collision */ -#define SMSC95XX_RX_LATE 0x00000040UL - -/** CRC error */ -#define SMSC95XX_RX_CRC 0x00000002UL - -/** Transmit packet header */ -struct smsc95xx_tx_header { - /** Command word */ - uint32_t command; - /** Frame length */ - uint32_t len; -} __attribute__ (( packed )); - -/** First segment */ -#define SMSC95XX_TX_FIRST 0x00002000UL - -/** Last segment */ -#define SMSC95XX_TX_LAST 0x00001000UL - -/** Buffer size */ -#define SMSC95XX_TX_LEN(len) ( (len) << 0 ) - -/** Interrupt packet format */ -struct smsc95xx_interrupt { - /** Current value of INT_STS register */ - uint32_t int_sts; -} __attribute__ (( packed )); - -/** Receive statistics */ -struct smsc95xx_rx_statistics { - /** Good frames */ - uint32_t good; - /** CRC errors */ - uint32_t crc; - /** Runt frame errors */ - uint32_t undersize; - /** Alignment errors */ - uint32_t alignment; - /** Frame too long errors */ - uint32_t oversize; - /** Later collision errors */ - uint32_t late; - /** Bad frames */ - uint32_t bad; - /** Dropped frames */ - uint32_t dropped; -} __attribute__ (( packed )); - -/** Receive statistics */ -#define SMSC95XX_RX_STATISTICS 0 - -/** Transmit statistics */ -struct smsc95xx_tx_statistics { - /** Good frames */ - uint32_t good; - /** Pause frames */ - uint32_t pause; - /** Single collisions */ - uint32_t single; - /** Multiple collisions */ - uint32_t multiple; - /** Excessive collisions */ - uint32_t excessive; - /** Late collisions */ - uint32_t late; - /** Buffer underruns */ - uint32_t underrun; - /** Excessive deferrals */ - uint32_t deferred; - /** Carrier errors */ - uint32_t carrier; - /** Bad frames */ - uint32_t bad; -} __attribute__ (( packed )); - -/** Transmit statistics */ -#define SMSC95XX_TX_STATISTICS 1 - -/** A SMSC95xx network device */ -struct smsc95xx_device { - /** USB device */ - struct usb_device *usb; - /** USB bus */ - struct usb_bus *bus; - /** Network device */ - struct net_device *netdev; - /** USB network device */ - struct usbnet_device usbnet; - /** MII interface */ - struct mii_interface mii; - /** Interrupt status */ - uint32_t int_sts; -}; - -/** Reset delay (in microseconds) */ -#define SMSC95XX_RESET_DELAY_US 2 - -/** Maximum time to wait for EEPROM (in milliseconds) */ -#define SMSC95XX_EEPROM_MAX_WAIT_MS 100 - -/** Maximum time to wait for MII (in milliseconds) */ -#define SMSC95XX_MII_MAX_WAIT_MS 100 - -/** Interrupt maximum fill level - * - * This is a policy decision. - */ -#define SMSC95XX_INTR_MAX_FILL 2 - -/** Bulk IN maximum fill level - * - * This is a policy decision. - */ -#define SMSC95XX_IN_MAX_FILL 8 - -/** Bulk IN buffer size */ -#define SMSC95XX_IN_MTU \ - ( sizeof ( struct smsc95xx_rx_header ) + \ - ETH_FRAME_LEN + 4 /* possible VLAN header */ \ - + 4 /* CRC */ ) - -/** Honeywell VM3 MAC address OEM string index */ -#define SMSC95XX_VM3_OEM_STRING_MAC 2 - -#endif /* _SMSC95XX_H */ diff --git a/roms/ipxe/src/drivers/net/tg3/tg3.c b/roms/ipxe/src/drivers/net/tg3/tg3.c index 1bed06649..42bfa2d99 100644 --- a/roms/ipxe/src/drivers/net/tg3/tg3.c +++ b/roms/ipxe/src/drivers/net/tg3/tg3.c @@ -486,8 +486,6 @@ static void tg3_poll(struct net_device *dev) */ tp->hw_status->status &= ~SD_STATUS_UPDATED; - mb(); - tg3_poll_link(tp); tg3_tx_complete(dev); tg3_rx_complete(dev); @@ -547,7 +545,7 @@ static int tg3_test_dma(struct tg3 *tp) goto out_nofree; } buf_dma = virt_to_bus(buf); - DBGC2(tp->dev, "dma test buffer, virt: %p phys: %#016lx\n", buf, buf_dma); + DBGC2(tp->dev, "dma test buffer, virt: %p phys: %#08x\n", buf, buf_dma); if (tg3_flag(tp, 57765_PLUS)) { tp->dma_rwctrl = DMA_RWCTRL_DIS_CACHE_ALIGNMENT; diff --git a/roms/ipxe/src/drivers/net/tg3/tg3.h b/roms/ipxe/src/drivers/net/tg3/tg3.h index be02c5719..2b85b065b 100644 --- a/roms/ipxe/src/drivers/net/tg3/tg3.h +++ b/roms/ipxe/src/drivers/net/tg3/tg3.h @@ -52,6 +52,7 @@ #define PCI_X_CMD 2 /* Modes & Features */ #define PCI_X_CMD_ERO 0x0002 /* Enable Relaxed Ordering */ +#define PCI_EXP_DEVCTL 8 /* Device Control */ #define PCI_EXP_DEVCTL_RELAX_EN 0x0010 /* Enable relaxed ordering */ #define PCI_EXP_DEVCTL_NOSNOOP_EN 0x0800 /* Enable No Snoop */ #define PCI_EXP_DEVCTL_PAYLOAD 0x00e0 /* Max_Payload_Size */ @@ -2788,7 +2789,7 @@ struct tg3_hw_stats { u8 __reserved4[0xb00-0x9c8]; }; -typedef unsigned long dma_addr_t; +typedef u32 dma_addr_t; /* 'mapping' is superfluous as the chip does not write into * the tx/rx post rings so we could just fetch it from there. @@ -3320,25 +3321,43 @@ void tg3_write_indirect_mbox(struct tg3 *tp, u32 off, u32 val); /* Functions & macros to verify TG3_FLAGS types */ +static inline int variable_test_bit(int nr, volatile const unsigned long *addr) +{ + int oldbit; + + asm volatile("bt %2,%1\n\t" + "sbb %0,%0" + : "=r" (oldbit) + : "m" (*(unsigned long *)addr), "Ir" (nr)); + + return oldbit; +} + static inline int _tg3_flag(enum TG3_FLAGS flag, unsigned long *bits) { - unsigned int index = ( flag / ( 8 * sizeof ( *bits ) ) ); - unsigned int bit = ( flag % ( 8 * sizeof ( *bits ) ) ); - return ( !! ( bits[index] & ( 1UL << bit ) ) ); + return variable_test_bit(flag, bits); +} + +#define BITOP_ADDR(x) "+m" (*(volatile long *) (x)) + +static inline void __set_bit(int nr, volatile unsigned long *addr) +{ + asm volatile("bts %1,%0" : BITOP_ADDR(addr) : "Ir" (nr) : "memory"); } static inline void _tg3_flag_set(enum TG3_FLAGS flag, unsigned long *bits) { - unsigned int index = ( flag / ( 8 * sizeof ( *bits ) ) ); - unsigned int bit = ( flag % ( 8 * sizeof ( *bits ) ) ); - bits[index] |= ( 1UL << bit ); + __set_bit(flag, bits); +} + +static inline void __clear_bit(int nr, volatile unsigned long *addr) +{ + asm volatile("btr %1,%0" : BITOP_ADDR(addr) : "Ir" (nr)); } static inline void _tg3_flag_clear(enum TG3_FLAGS flag, unsigned long *bits) { - unsigned int index = ( flag / ( 8 * sizeof ( *bits ) ) ); - unsigned int bit = ( flag % ( 8 * sizeof ( *bits ) ) ); - bits[index] &= ~( 1UL << bit ); + __clear_bit(flag, bits); } #define tg3_flag(tp, flag) \ diff --git a/roms/ipxe/src/drivers/net/thunderx.c b/roms/ipxe/src/drivers/net/thunderx.c deleted file mode 100644 index 306adc459..000000000 --- a/roms/ipxe/src/drivers/net/thunderx.c +++ /dev/null @@ -1,1706 +0,0 @@ -/* - * Copyright (C) 2016 Michael Brown <mbrown@fensystems.co.uk>. - * - * 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 (at your option) 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 <stdint.h> -#include <string.h> -#include <strings.h> -#include <stdio.h> -#include <unistd.h> -#include <errno.h> -#include <assert.h> -#include <byteswap.h> -#include <ipxe/netdevice.h> -#include <ipxe/ethernet.h> -#include <ipxe/if_ether.h> -#include <ipxe/iobuf.h> -#include <ipxe/malloc.h> -#include <ipxe/pci.h> -#include <ipxe/pciea.h> -#include <ipxe/umalloc.h> -#include "thunderx.h" -#include "thunderxcfg.h" - -/** @file - * - * Cavium ThunderX Ethernet driver - * - */ - -/** List of BGX Ethernet interfaces */ -static LIST_HEAD ( txnic_bgxs ); - -/** List of physical functions */ -static LIST_HEAD ( txnic_pfs ); - -/** Debug colour for physical function and BGX messages */ -#define TXNICCOL(x) ( &txnic_pfs + (x)->node ) - -/** Board configuration protocol */ -static EFI_THUNDER_CONFIG_PROTOCOL *txcfg; -EFI_REQUEST_PROTOCOL ( EFI_THUNDER_CONFIG_PROTOCOL, &txcfg ); - -/****************************************************************************** - * - * Diagnostics - * - ****************************************************************************** - */ - -/** - * Show virtual NIC diagnostics (for debugging) - * - * @v vnic Virtual NIC - */ -static __attribute__ (( unused )) void txnic_diag ( struct txnic *vnic ) { - - DBGC ( vnic, "TXNIC %s SQ %05zx(%05llx)/%05zx(%05llx) %08llx\n", - vnic->name, - ( ( vnic->sq.prod % TXNIC_SQES ) * TXNIC_SQ_STRIDE ), - readq ( vnic->regs + TXNIC_QS_SQ_TAIL(0) ), - ( ( vnic->sq.cons % TXNIC_SQES ) * TXNIC_SQ_STRIDE ), - readq ( vnic->regs + TXNIC_QS_SQ_HEAD(0) ), - readq ( vnic->regs + TXNIC_QS_SQ_STATUS(0) ) ); - DBGC ( vnic, "TXNIC %s RQ %05zx(%05llx)/%05zx(%05llx) %016llx\n", - vnic->name, - ( ( vnic->rq.prod % TXNIC_RQES ) * TXNIC_RQ_STRIDE ), - readq ( vnic->regs + TXNIC_QS_RBDR_TAIL(0) ), - ( ( vnic->rq.cons % TXNIC_RQES ) * TXNIC_RQ_STRIDE ), - readq ( vnic->regs + TXNIC_QS_RBDR_HEAD(0) ), - readq ( vnic->regs + TXNIC_QS_RBDR_STATUS0(0) ) ); - DBGC ( vnic, "TXNIC %s CQ xxxxx(%05llx)/%05x(%05llx) %08llx:%08llx\n", - vnic->name, readq ( vnic->regs + TXNIC_QS_CQ_TAIL(0) ), - ( ( vnic->cq.cons % TXNIC_CQES ) * TXNIC_CQ_STRIDE ), - readq ( vnic->regs + TXNIC_QS_CQ_HEAD(0) ), - readq ( vnic->regs + TXNIC_QS_CQ_STATUS(0) ), - readq ( vnic->regs + TXNIC_QS_CQ_STATUS2(0) ) ); -} - -/****************************************************************************** - * - * Send queue - * - ****************************************************************************** - */ - -/** - * Create send queue - * - * @v vnic Virtual NIC - * @ret rc Return status code - */ -static int txnic_create_sq ( struct txnic *vnic ) { - - /* Reset send queue */ - vnic->sq.prod = 0; - vnic->sq.cons = 0; - writeq ( TXNIC_QS_SQ_CFG_RESET, ( vnic->regs + TXNIC_QS_SQ_CFG(0) ) ); - - /* Configure and enable send queue */ - writeq ( user_to_phys ( vnic->sq.sqe, 0 ), - ( vnic->regs + TXNIC_QS_SQ_BASE(0) ) ); - writeq ( ( TXNIC_QS_SQ_CFG_ENA | TXNIC_QS_SQ_CFG_QSIZE_1K ), - ( vnic->regs + TXNIC_QS_SQ_CFG(0) ) ); - - DBGC ( vnic, "TXNIC %s SQ at [%08lx,%08lx)\n", - vnic->name, user_to_phys ( vnic->sq.sqe, 0 ), - user_to_phys ( vnic->sq.sqe, TXNIC_SQ_SIZE ) ); - return 0; -} - -/** - * Disable send queue - * - * @v vnic Virtual NIC - * @ret rc Return status code - */ -static int txnic_disable_sq ( struct txnic *vnic ) { - uint64_t status; - unsigned int i; - - /* Disable send queue */ - writeq ( 0, ( vnic->regs + TXNIC_QS_SQ_CFG(0) ) ); - - /* Wait for send queue to be stopped */ - for ( i = 0 ; i < TXNIC_SQ_STOP_MAX_WAIT_MS ; i++ ) { - - /* Check if send queue is stopped */ - status = readq ( vnic->regs + TXNIC_QS_SQ_STATUS(0) ); - if ( status & TXNIC_QS_SQ_STATUS_STOPPED ) - return 0; - - /* Delay */ - mdelay ( 1 ); - } - - DBGC ( vnic, "TXNIC %s SQ disable timed out\n", vnic->name ); - return -ETIMEDOUT; -} - -/** - * Destroy send queue - * - * @v vnic Virtual NIC - */ -static void txnic_destroy_sq ( struct txnic *vnic ) { - int rc; - - /* Disable send queue */ - if ( ( rc = txnic_disable_sq ( vnic ) ) != 0 ) { - /* Nothing else we can do */ - return; - } - - /* Reset send queue */ - writeq ( TXNIC_QS_SQ_CFG_RESET, ( vnic->regs + TXNIC_QS_SQ_CFG(0) ) ); -} - -/** - * Send packet - * - * @v vnic Virtual NIC - * @v iobuf I/O buffer - * @ret rc Return status code - */ -static int txnic_send ( struct txnic *vnic, struct io_buffer *iobuf ) { - struct txnic_sqe sqe; - unsigned int sq_idx; - size_t offset; - size_t len; - - /* Get next send queue entry */ - if ( ( vnic->sq.prod - vnic->sq.cons ) >= TXNIC_SQ_FILL ) { - DBGC ( vnic, "TXNIC %s out of send queue entries\n", - vnic->name ); - return -ENOBUFS; - } - sq_idx = ( vnic->sq.prod++ % TXNIC_SQES ); - offset = ( sq_idx * TXNIC_SQ_STRIDE ); - - /* Populate send descriptor */ - len = iob_len ( iobuf ); - memset ( &sqe, 0, sizeof ( sqe ) ); - sqe.hdr.total = cpu_to_le32 ( ( len >= ETH_ZLEN ) ? len : ETH_ZLEN ); - sqe.hdr.subdcnt = ( TXNIC_SQE_SUBDESCS - 1 ); - sqe.hdr.flags = TXNIC_SEND_HDR_FLAGS; - sqe.gather.size = cpu_to_le16 ( len ); - sqe.gather.flags = TXNIC_SEND_GATHER_FLAGS; - sqe.gather.addr = cpu_to_le64 ( virt_to_bus ( iobuf->data ) ); - DBGC2 ( vnic, "TXNIC %s SQE %#03x is [%08lx,%08lx)\n", - vnic->name, sq_idx, virt_to_bus ( iobuf->data ), - ( virt_to_bus ( iobuf->data ) + len ) ); - - /* Copy send descriptor to ring */ - copy_to_user ( vnic->sq.sqe, offset, &sqe, sizeof ( sqe ) ); - - /* Ring doorbell */ - wmb(); - writeq ( TXNIC_SQE_SUBDESCS, ( vnic->regs + TXNIC_QS_SQ_DOOR(0) ) ); - - return 0; -} - -/** - * Complete send queue entry - * - * @v vnic Virtual NIC - * @v cqe Send completion queue entry - */ -static void txnic_complete_sqe ( struct txnic *vnic, - struct txnic_cqe_send *cqe ) { - struct net_device *netdev = vnic->netdev; - unsigned int sq_idx; - unsigned int status; - - /* Parse completion */ - sq_idx = ( le16_to_cpu ( cqe->sqe_ptr ) / TXNIC_SQE_SUBDESCS ); - status = cqe->send_status; - - /* Sanity check */ - assert ( sq_idx == ( vnic->sq.cons % TXNIC_SQES ) ); - - /* Free send queue entry */ - vnic->sq.cons++; - - /* Complete transmission */ - if ( status ) { - DBGC ( vnic, "TXNIC %s SQE %#03x complete (status %#02x)\n", - vnic->name, sq_idx, status ); - netdev_tx_complete_next_err ( netdev, -EIO ); - } else { - DBGC2 ( vnic, "TXNIC %s SQE %#03x complete\n", - vnic->name, sq_idx ); - netdev_tx_complete_next ( netdev ); - } -} - -/****************************************************************************** - * - * Receive queue - * - ****************************************************************************** - */ - -/** - * Create receive queue - * - * @v vnic Virtual NIC - * @ret rc Return status code - */ -static int txnic_create_rq ( struct txnic *vnic ) { - - /* Reset receive buffer descriptor ring */ - vnic->rq.prod = 0; - vnic->rq.cons = 0; - writeq ( TXNIC_QS_RBDR_CFG_RESET, - ( vnic->regs + TXNIC_QS_RBDR_CFG(0) ) ); - - /* Configure and enable receive buffer descriptor ring */ - writeq ( user_to_phys ( vnic->rq.rqe, 0 ), - ( vnic->regs + TXNIC_QS_RBDR_BASE(0) ) ); - writeq ( ( TXNIC_QS_RBDR_CFG_ENA | TXNIC_QS_RBDR_CFG_QSIZE_8K | - TXNIC_QS_RBDR_CFG_LINES ( TXNIC_RQE_SIZE / - TXNIC_LINE_SIZE ) ), - ( vnic->regs + TXNIC_QS_RBDR_CFG(0) ) ); - - /* Enable receive queue */ - writeq ( TXNIC_QS_RQ_CFG_ENA, ( vnic->regs + TXNIC_QS_RQ_CFG(0) ) ); - - DBGC ( vnic, "TXNIC %s RQ at [%08lx,%08lx)\n", - vnic->name, user_to_phys ( vnic->rq.rqe, 0 ), - user_to_phys ( vnic->rq.rqe, TXNIC_RQ_SIZE ) ); - return 0; -} - -/** - * Disable receive queue - * - * @v vnic Virtual NIC - * @ret rc Return status code - */ -static int txnic_disable_rq ( struct txnic *vnic ) { - uint64_t cfg; - unsigned int i; - - /* Disable receive queue */ - writeq ( 0, ( vnic->regs + TXNIC_QS_RQ_CFG(0) ) ); - - /* Wait for receive queue to be disabled */ - for ( i = 0 ; i < TXNIC_RQ_DISABLE_MAX_WAIT_MS ; i++ ) { - - /* Check if receive queue is disabled */ - cfg = readq ( vnic->regs + TXNIC_QS_RQ_CFG(0) ); - if ( ! ( cfg & TXNIC_QS_RQ_CFG_ENA ) ) - return 0; - - /* Delay */ - mdelay ( 1 ); - } - - DBGC ( vnic, "TXNIC %s RQ disable timed out\n", vnic->name ); - return -ETIMEDOUT; -} - -/** - * Destroy receive queue - * - * @v vnic Virtual NIC - */ -static void txnic_destroy_rq ( struct txnic *vnic ) { - unsigned int i; - int rc; - - /* Disable receive queue */ - if ( ( rc = txnic_disable_rq ( vnic ) ) != 0 ) { - /* Leak memory; there's nothing else we can do */ - return; - } - - /* Disable receive buffer descriptor ring */ - writeq ( 0, ( vnic->regs + TXNIC_QS_RBDR_CFG(0) ) ); - - /* Reset receive buffer descriptor ring */ - writeq ( TXNIC_QS_RBDR_CFG_RESET, - ( vnic->regs + TXNIC_QS_RBDR_CFG(0) ) ); - - /* Free any unused I/O buffers */ - for ( i = 0 ; i < TXNIC_RQ_FILL ; i++ ) { - if ( vnic->rq.iobuf[i] ) - free_iob ( vnic->rq.iobuf[i] ); - vnic->rq.iobuf[i] = NULL; - } -} - -/** - * Refill receive queue - * - * @v vnic Virtual NIC - */ -static void txnic_refill_rq ( struct txnic *vnic ) { - struct io_buffer *iobuf; - struct txnic_rqe rqe; - unsigned int rq_idx; - unsigned int rq_iobuf_idx; - unsigned int refilled = 0; - size_t offset; - - /* Refill ring */ - while ( ( vnic->rq.prod - vnic->rq.cons ) < TXNIC_RQ_FILL ) { - - /* Allocate I/O buffer */ - iobuf = alloc_iob ( TXNIC_RQE_SIZE ); - if ( ! iobuf ) { - /* Wait for next refill */ - break; - } - - /* Get next receive descriptor */ - rq_idx = ( vnic->rq.prod++ % TXNIC_RQES ); - offset = ( rq_idx * TXNIC_RQ_STRIDE ); - - /* Populate receive descriptor */ - rqe.rbdre.addr = cpu_to_le64 ( virt_to_bus ( iobuf->data ) ); - DBGC2 ( vnic, "TXNIC %s RQE %#03x is [%08lx,%08lx)\n", - vnic->name, rq_idx, virt_to_bus ( iobuf->data ), - ( virt_to_bus ( iobuf->data ) + TXNIC_RQE_SIZE ) ); - - /* Copy receive descriptor to ring */ - copy_to_user ( vnic->rq.rqe, offset, &rqe, sizeof ( rqe ) ); - refilled++; - - /* Record I/O buffer */ - rq_iobuf_idx = ( rq_idx % TXNIC_RQ_FILL ); - assert ( vnic->rq.iobuf[rq_iobuf_idx] == NULL ); - vnic->rq.iobuf[rq_iobuf_idx] = iobuf; - } - - /* Ring doorbell */ - wmb(); - writeq ( refilled, ( vnic->regs + TXNIC_QS_RBDR_DOOR(0) ) ); -} - -/** - * Complete receive queue entry - * - * @v vnic Virtual NIC - * @v cqe Receive completion queue entry - */ -static void txnic_complete_rqe ( struct txnic *vnic, - struct txnic_cqe_rx *cqe ) { - struct net_device *netdev = vnic->netdev; - struct io_buffer *iobuf; - unsigned int errop; - unsigned int rq_idx; - unsigned int rq_iobuf_idx; - size_t apad_len; - size_t len; - - /* Parse completion */ - errop = cqe->errop; - apad_len = TXNIC_CQE_RX_APAD_LEN ( cqe->apad ); - len = le16_to_cpu ( cqe->len ); - - /* Get next receive I/O buffer */ - rq_idx = ( vnic->rq.cons++ % TXNIC_RQES ); - rq_iobuf_idx = ( rq_idx % TXNIC_RQ_FILL ); - iobuf = vnic->rq.iobuf[rq_iobuf_idx]; - vnic->rq.iobuf[rq_iobuf_idx] = NULL; - - /* Populate I/O buffer */ - iob_reserve ( iobuf, apad_len ); - iob_put ( iobuf, len ); - - /* Hand off to network stack */ - if ( errop ) { - DBGC ( vnic, "TXNIC %s RQE %#03x error (length %zd, errop " - "%#02x)\n", vnic->name, rq_idx, len, errop ); - netdev_rx_err ( netdev, iobuf, -EIO ); - } else { - DBGC2 ( vnic, "TXNIC %s RQE %#03x complete (length %zd)\n", - vnic->name, rq_idx, len ); - netdev_rx ( netdev, iobuf ); - } -} - -/****************************************************************************** - * - * Completion queue - * - ****************************************************************************** - */ - -/** - * Create completion queue - * - * @v vnic Virtual NIC - * @ret rc Return status code - */ -static int txnic_create_cq ( struct txnic *vnic ) { - - /* Reset completion queue */ - vnic->cq.cons = 0; - writeq ( TXNIC_QS_CQ_CFG_RESET, ( vnic->regs + TXNIC_QS_CQ_CFG(0) ) ); - - /* Configure and enable completion queue */ - writeq ( user_to_phys ( vnic->cq.cqe, 0 ), - ( vnic->regs + TXNIC_QS_CQ_BASE(0) ) ); - writeq ( ( TXNIC_QS_CQ_CFG_ENA | TXNIC_QS_CQ_CFG_QSIZE_256 ), - ( vnic->regs + TXNIC_QS_CQ_CFG(0) ) ); - - DBGC ( vnic, "TXNIC %s CQ at [%08lx,%08lx)\n", - vnic->name, user_to_phys ( vnic->cq.cqe, 0 ), - user_to_phys ( vnic->cq.cqe, TXNIC_CQ_SIZE ) ); - return 0; -} - -/** - * Disable completion queue - * - * @v vnic Virtual NIC - * @ret rc Return status code - */ -static int txnic_disable_cq ( struct txnic *vnic ) { - uint64_t cfg; - unsigned int i; - - /* Disable completion queue */ - writeq ( 0, ( vnic->regs + TXNIC_QS_CQ_CFG(0) ) ); - - /* Wait for completion queue to be disabled */ - for ( i = 0 ; i < TXNIC_CQ_DISABLE_MAX_WAIT_MS ; i++ ) { - - /* Check if completion queue is disabled */ - cfg = readq ( vnic->regs + TXNIC_QS_CQ_CFG(0) ); - if ( ! ( cfg & TXNIC_QS_CQ_CFG_ENA ) ) - return 0; - - /* Delay */ - mdelay ( 1 ); - } - - DBGC ( vnic, "TXNIC %s CQ disable timed out\n", vnic->name ); - return -ETIMEDOUT; -} - -/** - * Destroy completion queue - * - * @v vnic Virtual NIC - */ -static void txnic_destroy_cq ( struct txnic *vnic ) { - int rc; - - /* Disable completion queue */ - if ( ( rc = txnic_disable_cq ( vnic ) ) != 0 ) { - /* Leak memory; there's nothing else we can do */ - return; - } - - /* Reset completion queue */ - writeq ( TXNIC_QS_CQ_CFG_RESET, ( vnic->regs + TXNIC_QS_CQ_CFG(0) ) ); -} - -/** - * Poll completion queue - * - * @v vnic Virtual NIC - */ -static void txnic_poll_cq ( struct txnic *vnic ) { - union txnic_cqe cqe; - uint64_t status; - size_t offset; - unsigned int qcount; - unsigned int cq_idx; - unsigned int i; - - /* Get number of completions */ - status = readq ( vnic->regs + TXNIC_QS_CQ_STATUS(0) ); - qcount = TXNIC_QS_CQ_STATUS_QCOUNT ( status ); - if ( ! qcount ) - return; - - /* Process completion queue entries */ - for ( i = 0 ; i < qcount ; i++ ) { - - /* Get completion queue entry */ - cq_idx = ( vnic->cq.cons++ % TXNIC_CQES ); - offset = ( cq_idx * TXNIC_CQ_STRIDE ); - copy_from_user ( &cqe, vnic->cq.cqe, offset, sizeof ( cqe ) ); - - /* Process completion queue entry */ - switch ( cqe.common.cqe_type ) { - case TXNIC_CQE_TYPE_SEND: - txnic_complete_sqe ( vnic, &cqe.send ); - break; - case TXNIC_CQE_TYPE_RX: - txnic_complete_rqe ( vnic, &cqe.rx ); - break; - default: - DBGC ( vnic, "TXNIC %s unknown completion type %d\n", - vnic->name, cqe.common.cqe_type ); - DBGC_HDA ( vnic, user_to_phys ( vnic->cq.cqe, offset ), - &cqe, sizeof ( cqe ) ); - break; - } - } - - /* Ring doorbell */ - writeq ( qcount, ( vnic->regs + TXNIC_QS_CQ_DOOR(0) ) ); -} - -/****************************************************************************** - * - * Virtual NIC - * - ****************************************************************************** - */ - -/** - * Open virtual NIC - * - * @v vnic Virtual NIC - * @ret rc Return status code - */ -static int txnic_open ( struct txnic *vnic ) { - int rc; - - /* Create completion queue */ - if ( ( rc = txnic_create_cq ( vnic ) ) != 0 ) - goto err_create_cq; - - /* Create send queue */ - if ( ( rc = txnic_create_sq ( vnic ) ) != 0 ) - goto err_create_sq; - - /* Create receive queue */ - if ( ( rc = txnic_create_rq ( vnic ) ) != 0 ) - goto err_create_rq; - - /* Refill receive queue */ - txnic_refill_rq ( vnic ); - - return 0; - - txnic_destroy_rq ( vnic ); - err_create_rq: - txnic_destroy_sq ( vnic ); - err_create_sq: - txnic_destroy_cq ( vnic ); - err_create_cq: - return rc; -} - -/** - * Close virtual NIC - * - * @v vnic Virtual NIC - */ -static void txnic_close ( struct txnic *vnic ) { - - /* Destroy receive queue */ - txnic_destroy_rq ( vnic ); - - /* Destroy send queue */ - txnic_destroy_sq ( vnic ); - - /* Destroy completion queue */ - txnic_destroy_cq ( vnic ); -} - -/** - * Poll virtual NIC - * - * @v vnic Virtual NIC - */ -static void txnic_poll ( struct txnic *vnic ) { - - /* Poll completion queue */ - txnic_poll_cq ( vnic ); - - /* Refill receive queue */ - txnic_refill_rq ( vnic ); -} - -/** - * Allocate virtual NIC - * - * @v dev Underlying device - * @v membase Register base address - * @ret vnic Virtual NIC, or NULL on failure - */ -static struct txnic * txnic_alloc ( struct device *dev, - unsigned long membase ) { - struct net_device *netdev; - struct txnic *vnic; - - /* Allocate network device */ - netdev = alloc_etherdev ( sizeof ( *vnic ) ); - if ( ! netdev ) - goto err_alloc_netdev; - netdev->dev = dev; - vnic = netdev->priv; - vnic->netdev = netdev; - vnic->name = dev->name; - - /* Allow caller to reuse netdev->priv. (The generic virtual - * NIC code never assumes that netdev->priv==vnic.) - */ - netdev->priv = NULL; - - /* Allocate completion queue */ - vnic->cq.cqe = umalloc ( TXNIC_CQ_SIZE ); - if ( ! vnic->cq.cqe ) - goto err_alloc_cq; - - /* Allocate send queue */ - vnic->sq.sqe = umalloc ( TXNIC_SQ_SIZE ); - if ( ! vnic->sq.sqe ) - goto err_alloc_sq; - - /* Allocate receive queue */ - vnic->rq.rqe = umalloc ( TXNIC_RQ_SIZE ); - if ( ! vnic->rq.rqe ) - goto err_alloc_rq; - - /* Map registers */ - vnic->regs = ioremap ( membase, TXNIC_VF_BAR_SIZE ); - if ( ! vnic->regs ) - goto err_ioremap; - - return vnic; - - iounmap ( vnic->regs ); - err_ioremap: - ufree ( vnic->rq.rqe ); - err_alloc_rq: - ufree ( vnic->sq.sqe ); - err_alloc_sq: - ufree ( vnic->cq.cqe ); - err_alloc_cq: - netdev_nullify ( netdev ); - netdev_put ( netdev ); - err_alloc_netdev: - return NULL; -} - -/** - * Free virtual NIC - * - * @v vnic Virtual NIC - */ -static void txnic_free ( struct txnic *vnic ) { - struct net_device *netdev = vnic->netdev; - - /* Unmap registers */ - iounmap ( vnic->regs ); - - /* Free receive queue */ - ufree ( vnic->rq.rqe ); - - /* Free send queue */ - ufree ( vnic->sq.sqe ); - - /* Free completion queue */ - ufree ( vnic->cq.cqe ); - - /* Free network device */ - netdev_nullify ( netdev ); - netdev_put ( netdev ); -} - -/****************************************************************************** - * - * Logical MAC virtual NICs - * - ****************************************************************************** - */ - -/** - * Show LMAC diagnostics (for debugging) - * - * @v lmac Logical MAC - */ -static __attribute__ (( unused )) void -txnic_lmac_diag ( struct txnic_lmac *lmac ) { - struct txnic *vnic = lmac->vnic; - uint64_t status1; - uint64_t status2; - uint64_t br_status1; - uint64_t br_status2; - uint64_t br_algn_status; - uint64_t br_pmd_status; - uint64_t an_status; - - /* Read status (clearing latching bits) */ - writeq ( BGX_SPU_STATUS1_RCV_LNK, ( lmac->regs + BGX_SPU_STATUS1 ) ); - writeq ( BGX_SPU_STATUS2_RCVFLT, ( lmac->regs + BGX_SPU_STATUS2 ) ); - status1 = readq ( lmac->regs + BGX_SPU_STATUS1 ); - status2 = readq ( lmac->regs + BGX_SPU_STATUS2 ); - DBGC ( vnic, "TXNIC %s SPU %02llx:%04llx%s%s%s\n", - vnic->name, status1, status2, - ( ( status1 & BGX_SPU_STATUS1_FLT ) ? " FLT" : "" ), - ( ( status1 & BGX_SPU_STATUS1_RCV_LNK ) ? " RCV_LNK" : "" ), - ( ( status2 & BGX_SPU_STATUS2_RCVFLT ) ? " RCVFLT" : "" ) ); - - /* Read BASE-R status (clearing latching bits) */ - writeq ( ( BGX_SPU_BR_STATUS2_LATCHED_LOCK | - BGX_SPU_BR_STATUS2_LATCHED_BER ), - ( lmac->regs + BGX_SPU_BR_STATUS2 ) ); - br_status1 = readq ( lmac->regs + BGX_SPU_BR_STATUS1 ); - br_status2 = readq ( lmac->regs + BGX_SPU_BR_STATUS2 ); - DBGC ( vnic, "TXNIC %s BR %04llx:%04llx%s%s%s%s%s\n", - vnic->name, br_status2, br_status2, - ( ( br_status1 & BGX_SPU_BR_STATUS1_RCV_LNK ) ? " RCV_LNK" : ""), - ( ( br_status1 & BGX_SPU_BR_STATUS1_HI_BER ) ? " HI_BER" : "" ), - ( ( br_status1 & BGX_SPU_BR_STATUS1_BLK_LOCK ) ? - " BLK_LOCK" : "" ), - ( ( br_status2 & BGX_SPU_BR_STATUS2_LATCHED_LOCK ) ? - " LATCHED_LOCK" : "" ), - ( ( br_status2 & BGX_SPU_BR_STATUS2_LATCHED_BER ) ? - " LATCHED_BER" : "" ) ); - - /* Read BASE-R alignment status */ - br_algn_status = readq ( lmac->regs + BGX_SPU_BR_ALGN_STATUS ); - DBGC ( vnic, "TXNIC %s BR ALGN %016llx%s\n", vnic->name, br_algn_status, - ( ( br_algn_status & BGX_SPU_BR_ALGN_STATUS_ALIGND ) ? - " ALIGND" : "" ) ); - - /* Read BASE-R link training status */ - br_pmd_status = readq ( lmac->regs + BGX_SPU_BR_PMD_STATUS ); - DBGC ( vnic, "TXNIC %s BR PMD %04llx\n", vnic->name, br_pmd_status ); - - /* Read autonegotiation status (clearing latching bits) */ - writeq ( ( BGX_SPU_AN_STATUS_PAGE_RX | BGX_SPU_AN_STATUS_LINK_STATUS ), - ( lmac->regs + BGX_SPU_AN_STATUS ) ); - an_status = readq ( lmac->regs + BGX_SPU_AN_STATUS ); - DBGC ( vnic, "TXNIC %s BR AN %04llx%s%s%s%s%s\n", vnic->name, an_status, - ( ( an_status & BGX_SPU_AN_STATUS_XNP_STAT ) ? " XNP_STAT" : ""), - ( ( an_status & BGX_SPU_AN_STATUS_PAGE_RX ) ? " PAGE_RX" : "" ), - ( ( an_status & BGX_SPU_AN_STATUS_AN_COMPLETE ) ? - " AN_COMPLETE" : "" ), - ( ( an_status & BGX_SPU_AN_STATUS_LINK_STATUS ) ? - " LINK_STATUS" : "" ), - ( ( an_status & BGX_SPU_AN_STATUS_LP_AN_ABLE ) ? - " LP_AN_ABLE" : "" ) ); - - /* Read transmit statistics */ - DBGC ( vnic, "TXNIC %s TXF xc %#llx xd %#llx mc %#llx sc %#llx ok " - "%#llx bc %#llx mc %#llx un %#llx pa %#llx\n", vnic->name, - readq ( lmac->regs + BGX_CMR_TX_STAT0 ), - readq ( lmac->regs + BGX_CMR_TX_STAT1 ), - readq ( lmac->regs + BGX_CMR_TX_STAT2 ), - readq ( lmac->regs + BGX_CMR_TX_STAT3 ), - readq ( lmac->regs + BGX_CMR_TX_STAT5 ), - readq ( lmac->regs + BGX_CMR_TX_STAT14 ), - readq ( lmac->regs + BGX_CMR_TX_STAT15 ), - readq ( lmac->regs + BGX_CMR_TX_STAT16 ), - readq ( lmac->regs + BGX_CMR_TX_STAT17 ) ); - DBGC ( vnic, "TXNIC %s TXB ok %#llx hist %#llx:%#llx:%#llx:%#llx:" - "%#llx:%#llx:%#llx:%#llx\n", vnic->name, - readq ( lmac->regs + BGX_CMR_TX_STAT4 ), - readq ( lmac->regs + BGX_CMR_TX_STAT6 ), - readq ( lmac->regs + BGX_CMR_TX_STAT7 ), - readq ( lmac->regs + BGX_CMR_TX_STAT8 ), - readq ( lmac->regs + BGX_CMR_TX_STAT9 ), - readq ( lmac->regs + BGX_CMR_TX_STAT10 ), - readq ( lmac->regs + BGX_CMR_TX_STAT11 ), - readq ( lmac->regs + BGX_CMR_TX_STAT12 ), - readq ( lmac->regs + BGX_CMR_TX_STAT13 ) ); - - /* Read receive statistics */ - DBGC ( vnic, "TXNIC %s RXF ok %#llx pa %#llx nm %#llx ov %#llx er " - "%#llx nc %#llx\n", vnic->name, - readq ( lmac->regs + BGX_CMR_RX_STAT0 ), - readq ( lmac->regs + BGX_CMR_RX_STAT2 ), - readq ( lmac->regs + BGX_CMR_RX_STAT4 ), - readq ( lmac->regs + BGX_CMR_RX_STAT6 ), - readq ( lmac->regs + BGX_CMR_RX_STAT8 ), - readq ( lmac->regs + BGX_CMR_RX_STAT9 ) ); - DBGC ( vnic, "TXNIC %s RXB ok %#llx pa %#llx nm %#llx ov %#llx nc " - "%#llx\n", vnic->name, - readq ( lmac->regs + BGX_CMR_RX_STAT1 ), - readq ( lmac->regs + BGX_CMR_RX_STAT3 ), - readq ( lmac->regs + BGX_CMR_RX_STAT5 ), - readq ( lmac->regs + BGX_CMR_RX_STAT7 ), - readq ( lmac->regs + BGX_CMR_RX_STAT10 ) ); -} - -/** - * Update LMAC link state - * - * @v lmac Logical MAC - */ -static void txnic_lmac_update_link ( struct txnic_lmac *lmac ) { - struct txnic *vnic = lmac->vnic; - struct net_device *netdev = vnic->netdev; - uint64_t status1; - - /* Read status (clearing latching bits) */ - writeq ( BGX_SPU_STATUS1_RCV_LNK, ( lmac->regs + BGX_SPU_STATUS1 ) ); - status1 = readq ( lmac->regs + BGX_SPU_STATUS1 ); - - /* Report link status */ - if ( status1 & BGX_SPU_STATUS1_RCV_LNK ) { - netdev_link_up ( netdev ); - } else { - netdev_link_down ( netdev ); - } -} - -/** - * Poll LMAC link state - * - * @v lmac Logical MAC - */ -static void txnic_lmac_poll_link ( struct txnic_lmac *lmac ) { - struct txnic *vnic = lmac->vnic; - uint64_t intr; - - /* Get interrupt status */ - intr = readq ( lmac->regs + BGX_SPU_INT ); - if ( ! intr ) - return; - DBGC ( vnic, "TXNIC %s INT %04llx%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", - vnic->name, intr, - ( ( intr & BGX_SPU_INT_TRAINING_FAIL ) ? " TRAINING_FAIL" : "" ), - ( ( intr & BGX_SPU_INT_TRAINING_DONE ) ? " TRAINING_DONE" : "" ), - ( ( intr & BGX_SPU_INT_AN_COMPLETE ) ? " AN_COMPLETE" : "" ), - ( ( intr & BGX_SPU_INT_AN_LINK_GOOD ) ? " AN_LINK_GOOD" : "" ), - ( ( intr & BGX_SPU_INT_AN_PAGE_RX ) ? " AN_PAGE_RX" : "" ), - ( ( intr & BGX_SPU_INT_FEC_UNCORR ) ? " FEC_UNCORR" : "" ), - ( ( intr & BGX_SPU_INT_FEC_CORR ) ? " FEC_CORR" : "" ), - ( ( intr & BGX_SPU_INT_BIP_ERR ) ? " BIP_ERR" : "" ), - ( ( intr & BGX_SPU_INT_DBG_SYNC ) ? " DBG_SYNC" : "" ), - ( ( intr & BGX_SPU_INT_ALGNLOS ) ? " ALGNLOS" : "" ), - ( ( intr & BGX_SPU_INT_SYNLOS ) ? " SYNLOS" : "" ), - ( ( intr & BGX_SPU_INT_BITLCKLS ) ? " BITLCKLS" : "" ), - ( ( intr & BGX_SPU_INT_ERR_BLK ) ? " ERR_BLK" : "" ), - ( ( intr & BGX_SPU_INT_RX_LINK_DOWN ) ? " RX_LINK_DOWN" : "" ), - ( ( intr & BGX_SPU_INT_RX_LINK_UP ) ? " RX_LINK_UP" : "" ) ); - - /* Clear interrupt status */ - writeq ( intr, ( lmac->regs + BGX_SPU_INT ) ); - - /* Update link state */ - txnic_lmac_update_link ( lmac ); -} - -/** - * Reset LMAC - * - * @v lmac Logical MAC - */ -static void txnic_lmac_reset ( struct txnic_lmac *lmac ) { - struct txnic_bgx *bgx = lmac->bgx; - struct txnic_pf *pf = bgx->pf; - void *qsregs = ( pf->regs + TXNIC_PF_QS ( lmac->idx ) ); - - /* There is no reset available for the physical function - * aspects of a virtual NIC; we have to explicitly reload a - * sensible set of default values. - */ - writeq ( 0, ( qsregs + TXNIC_PF_QS_CFG ) ); - writeq ( 0, ( qsregs + TXNIC_PF_QS_RQ_CFG(0) ) ); - writeq ( 0, ( qsregs + TXNIC_PF_QS_RQ_DROP_CFG(0) ) ); - writeq ( 0, ( qsregs + TXNIC_PF_QS_RQ_BP_CFG(0) ) ); - writeq ( 0, ( qsregs + TXNIC_PF_QS_SQ_CFG(0) ) ); -} - -/** - * Open network device - * - * @v netdev Network device - * @ret rc Return status code - */ -static int txnic_lmac_open ( struct net_device *netdev ) { - struct txnic_lmac *lmac = netdev->priv; - struct txnic_bgx *bgx = lmac->bgx; - struct txnic_pf *pf = bgx->pf; - struct txnic *vnic = lmac->vnic; - unsigned int vnic_idx = lmac->idx; - unsigned int chan_idx = TXNIC_CHAN_IDX ( vnic_idx ); - unsigned int tl4_idx = TXNIC_TL4_IDX ( vnic_idx ); - unsigned int tl3_idx = TXNIC_TL3_IDX ( vnic_idx ); - unsigned int tl2_idx = TXNIC_TL2_IDX ( vnic_idx ); - void *lmregs = ( pf->regs + TXNIC_PF_LMAC ( vnic_idx ) ); - void *chregs = ( pf->regs + TXNIC_PF_CHAN ( chan_idx ) ); - void *qsregs = ( pf->regs + TXNIC_PF_QS ( vnic_idx ) ); - size_t max_pkt_size; - int rc; - - /* Configure channel/match parse indices */ - writeq ( ( TXNIC_PF_MPI_CFG_VNIC ( vnic_idx ) | - TXNIC_PF_MPI_CFG_RSSI_BASE ( vnic_idx ) ), - ( TXNIC_PF_MPI_CFG ( vnic_idx ) + pf->regs ) ); - writeq ( ( TXNIC_PF_RSSI_RQ_RQ_QS ( vnic_idx ) ), - ( TXNIC_PF_RSSI_RQ ( vnic_idx ) + pf->regs ) ); - - /* Configure LMAC */ - max_pkt_size = ( netdev->max_pkt_len + 4 /* possible VLAN */ ); - writeq ( ( TXNIC_PF_LMAC_CFG_ADJUST_DEFAULT | - TXNIC_PF_LMAC_CFG_MIN_PKT_SIZE ( ETH_ZLEN ) ), - ( TXNIC_PF_LMAC_CFG + lmregs ) ); - writeq ( ( TXNIC_PF_LMAC_CFG2_MAX_PKT_SIZE ( max_pkt_size ) ), - ( TXNIC_PF_LMAC_CFG2 + lmregs ) ); - writeq ( ( TXNIC_PF_LMAC_CREDIT_CC_UNIT_CNT_DEFAULT | - TXNIC_PF_LMAC_CREDIT_CC_PACKET_CNT_DEFAULT | - TXNIC_PF_LMAC_CREDIT_CC_ENABLE ), - ( TXNIC_PF_LMAC_CREDIT + lmregs ) ); - - /* Configure channels */ - writeq ( ( TXNIC_PF_CHAN_TX_CFG_BP_ENA ), - ( TXNIC_PF_CHAN_TX_CFG + chregs ) ); - writeq ( ( TXNIC_PF_CHAN_RX_CFG_CPI_BASE ( vnic_idx ) ), - ( TXNIC_PF_CHAN_RX_CFG + chregs ) ); - writeq ( ( TXNIC_PF_CHAN_RX_BP_CFG_ENA | - TXNIC_PF_CHAN_RX_BP_CFG_BPID ( vnic_idx ) ), - ( TXNIC_PF_CHAN_RX_BP_CFG + chregs ) ); - - /* Configure traffic limiters */ - writeq ( ( TXNIC_PF_TL2_CFG_RR_QUANTUM_DEFAULT ), - ( TXNIC_PF_TL2_CFG ( tl2_idx ) + pf->regs ) ); - writeq ( ( TXNIC_PF_TL3_CFG_RR_QUANTUM_DEFAULT ), - ( TXNIC_PF_TL3_CFG ( tl3_idx ) + pf->regs ) ); - writeq ( ( TXNIC_PF_TL3_CHAN_CHAN ( chan_idx ) ), - ( TXNIC_PF_TL3_CHAN ( tl3_idx ) + pf->regs ) ); - writeq ( ( TXNIC_PF_TL4_CFG_SQ_QS ( vnic_idx ) | - TXNIC_PF_TL4_CFG_RR_QUANTUM_DEFAULT ), - ( TXNIC_PF_TL4_CFG ( tl4_idx ) + pf->regs ) ); - - /* Configure send queue */ - writeq ( ( TXNIC_PF_QS_SQ_CFG_CQ_QS ( vnic_idx ) ), - ( TXNIC_PF_QS_SQ_CFG(0) + qsregs ) ); - writeq ( ( TXNIC_PF_QS_SQ_CFG2_TL4 ( tl4_idx ) ), - ( TXNIC_PF_QS_SQ_CFG2(0) + qsregs ) ); - - /* Configure receive queue */ - writeq ( ( TXNIC_PF_QS_RQ_CFG_CACHING_ALL | - TXNIC_PF_QS_RQ_CFG_CQ_QS ( vnic_idx ) | - TXNIC_PF_QS_RQ_CFG_RBDR_CONT_QS ( vnic_idx ) | - TXNIC_PF_QS_RQ_CFG_RBDR_STRT_QS ( vnic_idx ) ), - ( TXNIC_PF_QS_RQ_CFG(0) + qsregs ) ); - writeq ( ( TXNIC_PF_QS_RQ_BP_CFG_RBDR_BP_ENA | - TXNIC_PF_QS_RQ_BP_CFG_CQ_BP_ENA | - TXNIC_PF_QS_RQ_BP_CFG_BPID ( vnic_idx ) ), - ( TXNIC_PF_QS_RQ_BP_CFG(0) + qsregs ) ); - - /* Enable queue set */ - writeq ( ( TXNIC_PF_QS_CFG_ENA | TXNIC_PF_QS_CFG_VNIC ( vnic_idx ) ), - ( TXNIC_PF_QS_CFG + qsregs ) ); - - /* Open virtual NIC */ - if ( ( rc = txnic_open ( vnic ) ) != 0 ) - goto err_open; - - /* Update link state */ - txnic_lmac_update_link ( lmac ); - - return 0; - - txnic_close ( vnic ); - err_open: - writeq ( 0, ( qsregs + TXNIC_PF_QS_CFG ) ); - return rc; -} - -/** - * Close network device - * - * @v netdev Network device - */ -static void txnic_lmac_close ( struct net_device *netdev ) { - struct txnic_lmac *lmac = netdev->priv; - struct txnic_bgx *bgx = lmac->bgx; - struct txnic_pf *pf = bgx->pf; - struct txnic *vnic = lmac->vnic; - void *qsregs = ( pf->regs + TXNIC_PF_QS ( lmac->idx ) ); - - /* Close virtual NIC */ - txnic_close ( vnic ); - - /* Disable queue set */ - writeq ( 0, ( qsregs + TXNIC_PF_QS_CFG ) ); -} - -/** - * Transmit packet - * - * @v netdev Network device - * @v iobuf I/O buffer - * @ret rc Return status code - */ -static int txnic_lmac_transmit ( struct net_device *netdev, - struct io_buffer *iobuf ) { - struct txnic_lmac *lmac = netdev->priv; - struct txnic *vnic = lmac->vnic; - - return txnic_send ( vnic, iobuf ); -} - -/** - * Poll network device - * - * @v netdev Network device - */ -static void txnic_lmac_poll ( struct net_device *netdev ) { - struct txnic_lmac *lmac = netdev->priv; - struct txnic *vnic = lmac->vnic; - - /* Poll virtual NIC */ - txnic_poll ( vnic ); - - /* Poll link state */ - txnic_lmac_poll_link ( lmac ); -} - -/** Network device operations */ -static struct net_device_operations txnic_lmac_operations = { - .open = txnic_lmac_open, - .close = txnic_lmac_close, - .transmit = txnic_lmac_transmit, - .poll = txnic_lmac_poll, -}; - -/** - * Probe logical MAC virtual NIC - * - * @v lmac Logical MAC - * @ret rc Return status code - */ -static int txnic_lmac_probe ( struct txnic_lmac *lmac ) { - struct txnic_bgx *bgx = lmac->bgx; - struct txnic_pf *pf = bgx->pf; - struct txnic *vnic; - struct net_device *netdev; - unsigned long membase; - int rc; - - /* Sanity check */ - assert ( lmac->vnic == NULL ); - - /* Calculate register base address */ - membase = ( pf->vf_membase + ( lmac->idx * pf->vf_stride ) ); - - /* Allocate and initialise network device */ - vnic = txnic_alloc ( &bgx->pci->dev, membase ); - if ( ! vnic ) { - rc = -ENOMEM; - goto err_alloc; - } - netdev = vnic->netdev; - netdev_init ( netdev, &txnic_lmac_operations ); - netdev->priv = lmac; - lmac->vnic = vnic; - - /* Reset device */ - txnic_lmac_reset ( lmac ); - - /* Set MAC address */ - memcpy ( netdev->hw_addr, lmac->mac.raw, ETH_ALEN ); - - /* Register network device */ - if ( ( rc = register_netdev ( netdev ) ) != 0 ) - goto err_register; - vnic->name = netdev->name; - DBGC ( TXNICCOL ( pf ), "TXNIC %d/%d/%d is %s (%s)\n", pf->node, - bgx->idx, lmac->idx, vnic->name, eth_ntoa ( lmac->mac.raw ) ); - - /* Update link state */ - txnic_lmac_update_link ( lmac ); - - return 0; - - unregister_netdev ( netdev ); - err_register: - txnic_lmac_reset ( lmac ); - txnic_free ( vnic ); - lmac->vnic = NULL; - err_alloc: - return rc; -} - -/** - * Remove logical MAC virtual NIC - * - * @v lmac Logical MAC - */ -static void txnic_lmac_remove ( struct txnic_lmac *lmac ) { - - /* Sanity check */ - assert ( lmac->vnic != NULL ); - - /* Unregister network device */ - unregister_netdev ( lmac->vnic->netdev ); - - /* Reset device */ - txnic_lmac_reset ( lmac ); - - /* Free virtual NIC */ - txnic_free ( lmac->vnic ); - lmac->vnic = NULL; -} - -/** - * Probe all LMACs on a BGX Ethernet interface - * - * @v pf Physical function - * @v bgx BGX Ethernet interface - * @ret rc Return status code - */ -static int txnic_lmac_probe_all ( struct txnic_pf *pf, struct txnic_bgx *bgx ) { - unsigned int bgx_idx; - int lmac_idx; - int count; - int rc; - - /* Sanity checks */ - bgx_idx = bgx->idx; - assert ( pf->node == bgx->node ); - assert ( pf->bgx[bgx_idx] == NULL ); - assert ( bgx->pf == NULL ); - - /* Associate BGX with physical function */ - pf->bgx[bgx_idx] = bgx; - bgx->pf = pf; - - /* Probe all LMACs */ - count = bgx->count; - for ( lmac_idx = 0 ; lmac_idx < count ; lmac_idx++ ) { - if ( ( rc = txnic_lmac_probe ( &bgx->lmac[lmac_idx] ) ) != 0 ) - goto err_probe; - } - - return 0; - - lmac_idx = count; - err_probe: - for ( lmac_idx-- ; lmac_idx >= 0 ; lmac_idx-- ) - txnic_lmac_remove ( &bgx->lmac[lmac_idx] ); - pf->bgx[bgx_idx] = NULL; - bgx->pf = NULL; - return rc; -} - -/** - * Remove all LMACs on a BGX Ethernet interface - * - * @v pf Physical function - * @v bgx BGX Ethernet interface - */ -static void txnic_lmac_remove_all ( struct txnic_pf *pf, - struct txnic_bgx *bgx ) { - unsigned int lmac_idx; - - /* Sanity checks */ - assert ( pf->bgx[bgx->idx] == bgx ); - assert ( bgx->pf == pf ); - - /* Remove all LMACs */ - for ( lmac_idx = 0 ; lmac_idx < bgx->count ; lmac_idx++ ) - txnic_lmac_remove ( &bgx->lmac[lmac_idx] ); - - /* Disassociate BGX from physical function */ - pf->bgx[bgx->idx] = NULL; - bgx->pf = NULL; -} - -/****************************************************************************** - * - * NIC physical function interface - * - ****************************************************************************** - */ - -/** - * Probe PCI device - * - * @v pci PCI device - * @ret rc Return status code - */ -static int txnic_pf_probe ( struct pci_device *pci ) { - struct txnic_pf *pf; - struct txnic_bgx *bgx; - unsigned long membase; - unsigned int i; - int rc; - - /* Allocate and initialise structure */ - pf = zalloc ( sizeof ( *pf ) ); - if ( ! pf ) { - rc = -ENOMEM; - goto err_alloc; - } - pf->pci = pci; - pci_set_drvdata ( pci, pf ); - - /* Get base addresses */ - membase = pciea_bar_start ( pci, PCIEA_BEI_BAR_0 ); - pf->vf_membase = pciea_bar_start ( pci, PCIEA_BEI_VF_BAR_0 ); - pf->vf_stride = pciea_bar_size ( pci, PCIEA_BEI_VF_BAR_0 ); - - /* Calculate node ID */ - pf->node = txnic_address_node ( membase ); - DBGC ( TXNICCOL ( pf ), "TXNIC %d/*/* PF %s at %#lx (VF %#lx+%#lx)\n", - pf->node, pci->dev.name, membase, pf->vf_membase, pf->vf_stride); - - /* Fix up PCI device */ - adjust_pci_device ( pci ); - - /* Map registers */ - pf->regs = ioremap ( membase, TXNIC_PF_BAR_SIZE ); - if ( ! pf->regs ) { - rc = -ENODEV; - goto err_ioremap; - } - - /* Configure physical function */ - writeq ( TXNIC_PF_CFG_ENA, ( pf->regs + TXNIC_PF_CFG ) ); - writeq ( ( TXNIC_PF_BP_CFG_BP_POLL_ENA | - TXNIC_PF_BP_CFG_BP_POLL_DLY_DEFAULT ), - ( pf->regs + TXNIC_PF_BP_CFG ) ); - for ( i = 0 ; i < TXNIC_NUM_BGX ; i++ ) { - writeq ( ( TXNIC_PF_INTF_SEND_CFG_BLOCK_BGX | - TXNIC_PF_INTF_SEND_CFG_BLOCK ( i ) ), - ( pf->regs + TXNIC_PF_INTF_SEND_CFG ( i ) ) ); - writeq ( ( TXNIC_PF_INTF_BP_CFG_BP_ENA | - TXNIC_PF_INTF_BP_CFG_BP_ID_BGX | - TXNIC_PF_INTF_BP_CFG_BP_ID ( i ) ), - ( pf->regs + TXNIC_PF_INTF_BP_CFG ( i ) ) ); - } - writeq ( ( TXNIC_PF_PKIND_CFG_LENERR_EN | - TXNIC_PF_PKIND_CFG_MAXLEN_DISABLE | - TXNIC_PF_PKIND_CFG_MINLEN_DISABLE ), - ( pf->regs + TXNIC_PF_PKIND_CFG(0) ) ); - - /* Add to list of physical functions */ - list_add_tail ( &pf->list, &txnic_pfs ); - - /* Probe all LMACs, if applicable */ - list_for_each_entry ( bgx, &txnic_bgxs, list ) { - if ( bgx->node != pf->node ) - continue; - if ( ( rc = txnic_lmac_probe_all ( pf, bgx ) ) != 0 ) - goto err_probe; - } - - return 0; - - err_probe: - for ( i = 0 ; i < TXNIC_NUM_BGX ; i++ ) { - if ( pf->bgx[i] ) - txnic_lmac_remove_all ( pf, pf->bgx[i] ); - } - list_del ( &pf->list ); - writeq ( 0, ( pf->regs + TXNIC_PF_CFG ) ); - iounmap ( pf->regs ); - err_ioremap: - free ( pf ); - err_alloc: - return rc; -} - -/** - * Remove PCI device - * - * @v pci PCI device - */ -static void txnic_pf_remove ( struct pci_device *pci ) { - struct txnic_pf *pf = pci_get_drvdata ( pci ); - unsigned int i; - - /* Remove all LMACs, if applicable */ - for ( i = 0 ; i < TXNIC_NUM_BGX ; i++ ) { - if ( pf->bgx[i] ) - txnic_lmac_remove_all ( pf, pf->bgx[i] ); - } - - /* Remove from list of physical functions */ - list_del ( &pf->list ); - - /* Disable physical function */ - writeq ( 0, ( pf->regs + TXNIC_PF_CFG ) ); - - /* Unmap registers */ - iounmap ( pf->regs ); - - /* Free physical function */ - free ( pf ); -} - -/** NIC physical function PCI device IDs */ -static struct pci_device_id txnic_pf_ids[] = { - PCI_ROM ( 0x177d, 0xa01e, "thunder-pf", "ThunderX NIC PF", 0 ), -}; - -/** NIC physical function PCI driver */ -struct pci_driver txnic_pf_driver __pci_driver = { - .ids = txnic_pf_ids, - .id_count = ( sizeof ( txnic_pf_ids ) / sizeof ( txnic_pf_ids[0] ) ), - .probe = txnic_pf_probe, - .remove = txnic_pf_remove, -}; - -/****************************************************************************** - * - * BGX interface - * - ****************************************************************************** - */ - -/** LMAC types */ -static struct txnic_lmac_type txnic_lmac_types[] = { - [TXNIC_LMAC_XAUI] = { - .name = "XAUI", - .count = 1, - .lane_to_sds = 0xe4, - }, - [TXNIC_LMAC_RXAUI] = { - .name = "RXAUI", - .count = 2, - .lane_to_sds = 0x0e04, - }, - [TXNIC_LMAC_10G_R] = { - .name = "10GBASE-R", - .count = 4, - .lane_to_sds = 0x00000000, - }, - [TXNIC_LMAC_40G_R] = { - .name = "40GBASE-R", - .count = 1, - .lane_to_sds = 0xe4, - }, -}; - -/** - * Detect BGX Ethernet interface LMAC type - * - * @v bgx BGX Ethernet interface - * @ret type LMAC type, or negative error - */ -static int txnic_bgx_detect ( struct txnic_bgx *bgx ) { - uint64_t config; - uint64_t br_pmd_control; - uint64_t rx_lmacs; - unsigned int type; - - /* We assume that the early (pre-UEFI) firmware will have - * configured at least the LMAC 0 type and use of link - * training, and may have overridden the number of LMACs. - */ - - /* Determine type from LMAC 0 */ - config = readq ( bgx->regs + BGX_CMR_CONFIG ); - type = BGX_CMR_CONFIG_LMAC_TYPE_GET ( config ); - if ( ( type >= ( sizeof ( txnic_lmac_types ) / - sizeof ( txnic_lmac_types[0] ) ) ) || - ( txnic_lmac_types[type].count == 0 ) ) { - DBGC ( TXNICCOL ( bgx ), "TXNIC %d/%d/* BGX unknown type %d\n", - bgx->node, bgx->idx, type ); - return -ENOTTY; - } - bgx->type = &txnic_lmac_types[type]; - - /* Check whether link training is required */ - br_pmd_control = readq ( bgx->regs + BGX_SPU_BR_PMD_CONTROL ); - bgx->training = - ( !! ( br_pmd_control & BGX_SPU_BR_PMD_CONTROL_TRAIN_EN ) ); - - /* Determine number of LMACs */ - rx_lmacs = readq ( bgx->regs + BGX_CMR_RX_LMACS ); - bgx->count = BGX_CMR_RX_LMACS_LMACS_GET ( rx_lmacs ); - if ( ( bgx->count == TXNIC_NUM_LMAC ) && - ( bgx->type->count != TXNIC_NUM_LMAC ) ) { - DBGC ( TXNICCOL ( bgx ), "TXNIC %d/%d/* assuming %d LMACs\n", - bgx->node, bgx->idx, bgx->type->count ); - bgx->count = bgx->type->count; - } - - return type; -} - -/** - * Initialise BGX Ethernet interface - * - * @v bgx BGX Ethernet interface - * @v type LMAC type - */ -static void txnic_bgx_init ( struct txnic_bgx *bgx, unsigned int type ) { - uint64_t global_config; - uint32_t lane_to_sds; - unsigned int i; - - /* Set number of LMACs */ - writeq ( BGX_CMR_RX_LMACS_LMACS_SET ( bgx->count ), - ( bgx->regs + BGX_CMR_RX_LMACS ) ); - writeq ( BGX_CMR_TX_LMACS_LMACS_SET ( bgx->count ), - ( bgx->regs + BGX_CMR_TX_LMACS ) ); - - /* Set LMAC types and lane mappings, and disable all LMACs */ - lane_to_sds = bgx->type->lane_to_sds; - for ( i = 0 ; i < bgx->count ; i++ ) { - writeq ( ( BGX_CMR_CONFIG_LMAC_TYPE_SET ( type ) | - BGX_CMR_CONFIG_LANE_TO_SDS ( lane_to_sds ) ), - ( bgx->regs + BGX_LMAC ( i ) + BGX_CMR_CONFIG ) ); - lane_to_sds >>= 8; - } - - /* Reset all MAC address filtering */ - for ( i = 0 ; i < TXNIC_NUM_DMAC ; i++ ) - writeq ( 0, ( bgx->regs + BGX_CMR_RX_DMAC_CAM ( i ) ) ); - - /* Reset NCSI steering */ - for ( i = 0 ; i < TXNIC_NUM_STEERING ; i++ ) - writeq ( 0, ( bgx->regs + BGX_CMR_RX_STEERING ( i ) ) ); - - /* Enable backpressure to all channels */ - writeq ( BGX_CMR_CHAN_MSK_AND_ALL ( bgx->count ), - ( bgx->regs + BGX_CMR_CHAN_MSK_AND ) ); - - /* Strip FCS */ - global_config = readq ( bgx->regs + BGX_CMR_GLOBAL_CONFIG ); - global_config |= BGX_CMR_GLOBAL_CONFIG_FCS_STRIP; - writeq ( global_config, ( bgx->regs + BGX_CMR_GLOBAL_CONFIG ) ); -} - -/** - * Get MAC address - * - * @v lmac Logical MAC - */ -static void txnic_bgx_mac ( struct txnic_lmac *lmac ) { - struct txnic_bgx *bgx = lmac->bgx; - BOARD_CFG *boardcfg; - NODE_CFG *nodecfg; - BGX_CFG *bgxcfg; - LMAC_CFG *lmaccfg; - - /* Extract MAC from Board Configuration protocol, if available */ - if ( txcfg ) { - boardcfg = txcfg->BoardConfig; - nodecfg = &boardcfg->Node[ bgx->node % MAX_NODES ]; - bgxcfg = &nodecfg->BgxCfg[ bgx->idx % BGX_PER_NODE_COUNT ]; - lmaccfg = &bgxcfg->Lmacs[ lmac->idx % LMAC_PER_BGX_COUNT ]; - lmac->mac.be64 = cpu_to_be64 ( lmaccfg->MacAddress ); - } else { - DBGC ( TXNICCOL ( bgx ), "TXNIC %d/%d/%d has no board " - "configuration protocol\n", bgx->node, bgx->idx, - lmac->idx ); - } - - /* Use random MAC address if none available */ - if ( ! lmac->mac.be64 ) { - DBGC ( TXNICCOL ( bgx ), "TXNIC %d/%d/%d has no MAC address\n", - bgx->node, bgx->idx, lmac->idx ); - eth_random_addr ( lmac->mac.raw ); - } -} - -/** - * Initialise Super PHY Unit (SPU) - * - * @v lmac Logical MAC - */ -static void txnic_bgx_spu_init ( struct txnic_lmac *lmac ) { - struct txnic_bgx *bgx = lmac->bgx; - - /* Reset PHY */ - writeq ( BGX_SPU_CONTROL1_RESET, ( lmac->regs + BGX_SPU_CONTROL1 ) ); - mdelay ( BGX_SPU_RESET_DELAY_MS ); - - /* Power down PHY */ - writeq ( BGX_SPU_CONTROL1_LO_PWR, ( lmac->regs + BGX_SPU_CONTROL1 ) ); - - /* Configure training, if applicable */ - if ( bgx->training ) { - writeq ( 0, ( lmac->regs + BGX_SPU_BR_PMD_LP_CUP ) ); - writeq ( 0, ( lmac->regs + BGX_SPU_BR_PMD_LD_CUP ) ); - writeq ( 0, ( lmac->regs + BGX_SPU_BR_PMD_LD_REP ) ); - writeq ( BGX_SPU_BR_PMD_CONTROL_TRAIN_EN, - ( lmac->regs + BGX_SPU_BR_PMD_CONTROL ) ); - } - - /* Disable forward error correction */ - writeq ( 0, ( lmac->regs + BGX_SPU_FEC_CONTROL ) ); - - /* Disable autonegotiation */ - writeq ( 0, ( lmac->regs + BGX_SPU_AN_CONTROL ) ); - - /* Power up PHY */ - writeq ( 0, ( lmac->regs + BGX_SPU_CONTROL1 ) ); -} - -/** - * Initialise LMAC - * - * @v bgx BGX Ethernet interface - * @v lmac_idx LMAC index - */ -static void txnic_bgx_lmac_init ( struct txnic_bgx *bgx, - unsigned int lmac_idx ) { - struct txnic_lmac *lmac = &bgx->lmac[lmac_idx]; - uint64_t config; - - /* Record associated BGX */ - lmac->bgx = bgx; - - /* Set register base address (already mapped) */ - lmac->regs = ( bgx->regs + BGX_LMAC ( lmac_idx ) ); - - /* Calculate virtual NIC index */ - lmac->idx = TXNIC_VNIC_IDX ( bgx->idx, lmac_idx ); - - /* Set MAC address */ - txnic_bgx_mac ( lmac ); - - /* Initialise PHY */ - txnic_bgx_spu_init ( lmac ); - - /* Accept all multicasts and broadcasts */ - writeq ( ( BGX_CMR_RX_DMAC_CTL_MCST_MODE_ACCEPT | - BGX_CMR_RX_DMAC_CTL_BCST_ACCEPT ), - ( lmac->regs + BGX_CMR_RX_DMAC_CTL ) ); - - /* Enable LMAC */ - config = readq ( lmac->regs + BGX_CMR_CONFIG ); - config |= ( BGX_CMR_CONFIG_ENABLE | - BGX_CMR_CONFIG_DATA_PKT_RX_EN | - BGX_CMR_CONFIG_DATA_PKT_TX_EN ); - writeq ( config, ( lmac->regs + BGX_CMR_CONFIG ) ); -} - -/** - * Probe PCI device - * - * @v pci PCI device - * @ret rc Return status code - */ -static int txnic_bgx_probe ( struct pci_device *pci ) { - struct txnic_bgx *bgx; - struct txnic_pf *pf; - unsigned long membase; - unsigned int i; - int type; - int rc; - - /* Allocate and initialise structure */ - bgx = zalloc ( sizeof ( *bgx ) ); - if ( ! bgx ) { - rc = -ENOMEM; - goto err_alloc; - } - bgx->pci = pci; - pci_set_drvdata ( pci, bgx ); - - /* Get base address */ - membase = pciea_bar_start ( pci, PCIEA_BEI_BAR_0 ); - - /* Calculate node ID and index */ - bgx->node = txnic_address_node ( membase ); - bgx->idx = txnic_address_bgx ( membase ); - - /* Fix up PCI device */ - adjust_pci_device ( pci ); - - /* Map registers */ - bgx->regs = ioremap ( membase, TXNIC_BGX_BAR_SIZE ); - if ( ! bgx->regs ) { - rc = -ENODEV; - goto err_ioremap; - } - - /* Detect LMAC type */ - if ( ( type = txnic_bgx_detect ( bgx ) ) < 0 ) { - rc = type; - goto err_detect; - } - DBGC ( TXNICCOL ( bgx ), "TXNIC %d/%d/* BGX %s at %#lx %dx %s%s\n", - bgx->node, bgx->idx, pci->dev.name, membase, bgx->count, - bgx->type->name, ( bgx->training ? "(training)" : "" ) ); - - /* Initialise interface */ - txnic_bgx_init ( bgx, type ); - - /* Initialise all LMACs */ - for ( i = 0 ; i < bgx->count ; i++ ) - txnic_bgx_lmac_init ( bgx, i ); - - /* Add to list of BGX devices */ - list_add_tail ( &bgx->list, &txnic_bgxs ); - - /* Probe all LMACs, if applicable */ - list_for_each_entry ( pf, &txnic_pfs, list ) { - if ( pf->node != bgx->node ) - continue; - if ( ( rc = txnic_lmac_probe_all ( pf, bgx ) ) != 0 ) - goto err_probe; - } - - return 0; - - if ( bgx->pf ) - txnic_lmac_remove_all ( bgx->pf, bgx ); - list_del ( &bgx->list ); - err_probe: - err_detect: - iounmap ( bgx->regs ); - err_ioremap: - free ( bgx ); - err_alloc: - return rc; -} - -/** - * Remove PCI device - * - * @v pci PCI device - */ -static void txnic_bgx_remove ( struct pci_device *pci ) { - struct txnic_bgx *bgx = pci_get_drvdata ( pci ); - - /* Remove all LMACs, if applicable */ - if ( bgx->pf ) - txnic_lmac_remove_all ( bgx->pf, bgx ); - - /* Remove from list of BGX devices */ - list_del ( &bgx->list ); - - /* Unmap registers */ - iounmap ( bgx->regs ); - - /* Free BGX device */ - free ( bgx ); -} - -/** BGX PCI device IDs */ -static struct pci_device_id txnic_bgx_ids[] = { - PCI_ROM ( 0x177d, 0xa026, "thunder-bgx", "ThunderX BGX", 0 ), -}; - -/** BGX PCI driver */ -struct pci_driver txnic_bgx_driver __pci_driver = { - .ids = txnic_bgx_ids, - .id_count = ( sizeof ( txnic_bgx_ids ) / sizeof ( txnic_bgx_ids[0] ) ), - .probe = txnic_bgx_probe, - .remove = txnic_bgx_remove, -}; diff --git a/roms/ipxe/src/drivers/net/thunderx.h b/roms/ipxe/src/drivers/net/thunderx.h deleted file mode 100644 index 410daf6e2..000000000 --- a/roms/ipxe/src/drivers/net/thunderx.h +++ /dev/null @@ -1,949 +0,0 @@ -#ifndef _THUNDERX_H -#define _THUNDERX_H - -/** @file - * - * Cavium ThunderX Ethernet driver - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#include <stdint.h> -#include <ipxe/list.h> -#include <ipxe/netdevice.h> -#include <ipxe/uaccess.h> - -/****************************************************************************** - * - * Address space - * - ****************************************************************************** - */ - -/** Size of a cache line */ -#define TXNIC_LINE_SIZE 128 - -/** Virtual function BAR size */ -#define TXNIC_VF_BAR_SIZE 0x200000UL - -/** Physical function BAR size */ -#define TXNIC_PF_BAR_SIZE 0x40000000UL - -/** BGX BAR size */ -#define TXNIC_BGX_BAR_SIZE 0x400000UL - -/** Maximum number of BGX Ethernet interfaces (per node) */ -#define TXNIC_NUM_BGX 2 - -/** Maximum number of Logical MACs (per BGX) */ -#define TXNIC_NUM_LMAC 4 - -/** Maximum number of destination MAC addresses (per BGX) */ -#define TXNIC_NUM_DMAC 32 - -/** Maximum number of steering rules (per BGX) */ -#define TXNIC_NUM_STEERING 8 - -/** - * Calculate node ID - * - * @v addr PCI BAR base address - * @ret node Node ID - */ -static inline unsigned int txnic_address_node ( uint64_t addr ) { - - /* Node ID is in bits [45:44] of the hardcoded BAR address */ - return ( ( addr >> 44 ) & 0x3 ); -} - -/** - * Calculate BGX Ethernet interface index - * - * @v addr PCI BAR base address - * @ret index Index - */ -static inline unsigned int txnic_address_bgx ( uint64_t addr ) { - - /* Index is in bit 24 of the hardcoded BAR address */ - return ( ( addr >> 24 ) & 0x1 ); -} - -/****************************************************************************** - * - * Send queue - * - ****************************************************************************** - */ - -/** Send queue configuration */ -#define TXNIC_QS_SQ_CFG(q) ( ( (q) << 18 ) | 0x010800 ) -#define TXNIC_QS_SQ_CFG_ENA ( 1ULL << 19 ) -#define TXNIC_QS_SQ_CFG_RESET ( 1ULL << 17 ) -#define TXNIC_QS_SQ_CFG_QSIZE(sz) ( ( ( uint64_t ) (sz) ) << 8 ) -#define TXNIC_QS_SQ_CFG_QSIZE_1K \ - TXNIC_QS_SQ_CFG_QSIZE ( 0 ) - -/** Send queue base address */ -#define TXNIC_QS_SQ_BASE(q) ( ( (q) << 18 ) | 0x010820 ) - -/** Send queue head pointer */ -#define TXNIC_QS_SQ_HEAD(q) ( ( (q) << 18 ) | 0x010828 ) - -/** Send queue tail pointer */ -#define TXNIC_QS_SQ_TAIL(q) ( ( (q) << 18 ) | 0x010830 ) - -/** Send queue doorbell */ -#define TXNIC_QS_SQ_DOOR(q) ( ( (q) << 18 ) | 0x010838 ) - -/** Send queue status */ -#define TXNIC_QS_SQ_STATUS(q) ( ( (q) << 18 ) | 0x010840 ) -#define TXNIC_QS_SQ_STATUS_STOPPED ( 1ULL << 21 ) - -/** Maximum time to wait for a send queue to stop - * - * This is a policy decision. - */ -#define TXNIC_SQ_STOP_MAX_WAIT_MS 100 - -/** A send header subdescriptor */ -struct txnic_send_header { - /** Total length */ - uint32_t total; - /** Unused */ - uint8_t unused_a[2]; - /** Subdescriptor count */ - uint8_t subdcnt; - /** Flags */ - uint8_t flags; - /** Unused */ - uint8_t unused_b[8]; -} __attribute__ (( packed )); - -/** Flags for send header subdescriptor - * - * These comprise SUBDC=0x1 and PNC=0x1. - */ -#define TXNIC_SEND_HDR_FLAGS 0x14 - -/** A send gather subdescriptor */ -struct txnic_send_gather { - /** Size */ - uint16_t size; - /** Unused */ - uint8_t unused[5]; - /** Flags */ - uint8_t flags; - /** Address */ - uint64_t addr; -} __attribute__ (( packed )); - -/** Flags for send gather subdescriptor - * - * These comprise SUBDC=0x4 and LD_TYPE=0x0. - */ -#define TXNIC_SEND_GATHER_FLAGS 0x40 - -/** A send queue entry - * - * Each send queue entry comprises a single send header subdescriptor - * and a single send gather subdescriptor. - */ -struct txnic_sqe { - /** Send header descriptor */ - struct txnic_send_header hdr; - /** Send gather descriptor */ - struct txnic_send_gather gather; -} __attribute__ (( packed )); - -/** Number of subdescriptors per send queue entry */ -#define TXNIC_SQE_SUBDESCS ( sizeof ( struct txnic_sqe ) / \ - sizeof ( struct txnic_send_header ) ) - -/** Number of send queue entries - * - * The minimum send queue size is 1024 entries. - */ -#define TXNIC_SQES ( 1024 / TXNIC_SQE_SUBDESCS ) - -/** Send queue maximum fill level - * - * This is a policy decision. - */ -#define TXNIC_SQ_FILL 32 - -/** Send queue alignment */ -#define TXNIC_SQ_ALIGN TXNIC_LINE_SIZE - -/** Send queue stride */ -#define TXNIC_SQ_STRIDE sizeof ( struct txnic_sqe ) - -/** Send queue size */ -#define TXNIC_SQ_SIZE ( TXNIC_SQES * TXNIC_SQ_STRIDE ) - -/** A send queue */ -struct txnic_sq { - /** Producer counter */ - unsigned int prod; - /** Consumer counter */ - unsigned int cons; - /** Send queue entries */ - userptr_t sqe; -}; - -/****************************************************************************** - * - * Receive queue - * - ****************************************************************************** - */ - -/** Receive queue configuration */ -#define TXNIC_QS_RQ_CFG(q) ( ( (q) << 18 ) | 0x010600 ) -#define TXNIC_QS_RQ_CFG_ENA ( 1ULL << 1 ) - -/** Maximum time to wait for a receive queue to disable - * - * This is a policy decision. - */ -#define TXNIC_RQ_DISABLE_MAX_WAIT_MS 100 - -/** Receive buffer descriptor ring configuration */ -#define TXNIC_QS_RBDR_CFG(q) ( ( (q) << 18 ) | 0x010c00 ) -#define TXNIC_QS_RBDR_CFG_ENA ( 1ULL << 44 ) -#define TXNIC_QS_RBDR_CFG_RESET ( 1ULL << 43 ) -#define TXNIC_QS_RBDR_CFG_QSIZE(sz) ( ( ( uint64_t ) (sz) ) << 32 ) -#define TXNIC_QS_RBDR_CFG_QSIZE_8K \ - TXNIC_QS_RBDR_CFG_QSIZE ( 0 ) -#define TXNIC_QS_RBDR_CFG_LINES(sz) ( ( ( uint64_t ) (sz) ) << 0 ) - -/** Receive buffer descriptor ring base address */ -#define TXNIC_QS_RBDR_BASE(q) ( ( (q) << 18 ) | 0x010c20 ) - -/** Receive buffer descriptor ring head pointer */ -#define TXNIC_QS_RBDR_HEAD(q) ( ( (q) << 18 ) | 0x010c28 ) - -/** Receive buffer descriptor ring tail pointer */ -#define TXNIC_QS_RBDR_TAIL(q) ( ( (q) << 18 ) | 0x010c30 ) - -/** Receive buffer descriptor ring doorbell */ -#define TXNIC_QS_RBDR_DOOR(q) ( ( (q) << 18 ) | 0x010c38 ) - -/** Receive buffer descriptor ring status 0 */ -#define TXNIC_QS_RBDR_STATUS0(q) ( ( (q) << 18 ) | 0x010c40 ) - -/** A receive buffer descriptor ring entry */ -struct txnic_rbdr_entry { - /** Address */ - uint64_t addr; -} __attribute__ (( packed )); - -/** A receive queue entry */ -struct txnic_rqe { - /** Receive buffer descriptor ring entry */ - struct txnic_rbdr_entry rbdre; -} __attribute__ (( packed )); - -/** Number of receive queue entries - * - * The minimum receive queue size is 8192 entries. - */ -#define TXNIC_RQES 8192 - -/** Receive queue maximum fill level - * - * This is a policy decision. Must not exceed TXNIC_RQES. - */ -#define TXNIC_RQ_FILL 32 - -/** Receive queue entry size - * - * This is a policy decision. - */ -#define TXNIC_RQE_SIZE ( ( ETH_DATA_ALIGN + ETH_FRAME_LEN + \ - 4 /* VLAN */ + TXNIC_LINE_SIZE - 1 ) \ - & ~( TXNIC_LINE_SIZE - 1 ) ) - -/** Receive queue alignment */ -#define TXNIC_RQ_ALIGN TXNIC_LINE_SIZE - -/** Receive queue stride */ -#define TXNIC_RQ_STRIDE sizeof ( struct txnic_rqe ) - -/** Receive queue size */ -#define TXNIC_RQ_SIZE ( TXNIC_RQES * TXNIC_RQ_STRIDE ) - -/** A receive queue */ -struct txnic_rq { - /** Producer counter */ - unsigned int prod; - /** Consumer counter */ - unsigned int cons; - /** Receive queue entries */ - userptr_t rqe; - /** I/O buffers */ - struct io_buffer *iobuf[TXNIC_RQ_FILL]; -}; - -/****************************************************************************** - * - * Completion queue - * - ****************************************************************************** - */ - -/** Completion queue configuration */ -#define TXNIC_QS_CQ_CFG(q) ( ( (q) << 18 ) | 0x010400 ) -#define TXNIC_QS_CQ_CFG_ENA ( 1ULL << 42 ) -#define TXNIC_QS_CQ_CFG_RESET ( 1ULL << 41 ) -#define TXNIC_QS_CQ_CFG_QSIZE(sz) ( ( ( uint64_t ) (sz) ) << 32 ) -#define TXNIC_QS_CQ_CFG_QSIZE_256 \ - TXNIC_QS_CQ_CFG_QSIZE ( 7 ) - -/** Maximum time to wait for a completion queue to disable - * - * This is a policy decision. - */ -#define TXNIC_CQ_DISABLE_MAX_WAIT_MS 100 - -/** Completion queue base address */ -#define TXNIC_QS_CQ_BASE(q) ( ( (q) << 18 ) | 0x010420 ) - -/** Completion queue head pointer */ -#define TXNIC_QS_CQ_HEAD(q) ( ( (q) << 18 ) | 0x010428 ) - -/** Completion queue tail pointer */ -#define TXNIC_QS_CQ_TAIL(q) ( ( (q) << 18 ) | 0x010430 ) - -/** Completion queue doorbell */ -#define TXNIC_QS_CQ_DOOR(q) ( ( (q) << 18 ) | 0x010438 ) - -/** Completion queue status */ -#define TXNIC_QS_CQ_STATUS(q) ( ( (q) << 18 ) | 0x010440 ) -#define TXNIC_QS_CQ_STATUS_QCOUNT(status) \ - ( ( (status) >> 0 ) & 0xffff ) - -/** Completion queue status 2 */ -#define TXNIC_QS_CQ_STATUS2(q) ( ( (q) << 18 ) | 0x010448 ) - -/** A send completion queue entry */ -struct txnic_cqe_send { - /** Status */ - uint8_t send_status; - /** Unused */ - uint8_t unused[4]; - /** Send queue entry pointer */ - uint16_t sqe_ptr; - /** Type */ - uint8_t cqe_type; -} __attribute__ (( packed )); - -/** Send completion queue entry type */ -#define TXNIC_CQE_TYPE_SEND 0x80 - -/** A receive completion queue entry */ -struct txnic_cqe_rx { - /** Error opcode */ - uint8_t errop; - /** Unused */ - uint8_t unused_a[6]; - /** Type */ - uint8_t cqe_type; - /** Unused */ - uint8_t unused_b[1]; - /** Padding */ - uint8_t apad; - /** Unused */ - uint8_t unused_c[4]; - /** Length */ - uint16_t len; -} __attribute__ (( packed )); - -/** Receive completion queue entry type */ -#define TXNIC_CQE_TYPE_RX 0x20 - -/** Applied padding */ -#define TXNIC_CQE_RX_APAD_LEN( apad ) ( (apad) >> 5 ) - -/** Completion queue entry common fields */ -struct txnic_cqe_common { - /** Unused */ - uint8_t unused_a[7]; - /** Type */ - uint8_t cqe_type; -} __attribute__ (( packed )); - -/** A completion queue entry */ -union txnic_cqe { - /** Common fields */ - struct txnic_cqe_common common; - /** Send completion */ - struct txnic_cqe_send send; - /** Receive completion */ - struct txnic_cqe_rx rx; -}; - -/** Number of completion queue entries - * - * The minimum completion queue size is 256 entries. - */ -#define TXNIC_CQES 256 - -/** Completion queue alignment */ -#define TXNIC_CQ_ALIGN 512 - -/** Completion queue stride */ -#define TXNIC_CQ_STRIDE 512 - -/** Completion queue size */ -#define TXNIC_CQ_SIZE ( TXNIC_CQES * TXNIC_CQ_STRIDE ) - -/** A completion queue */ -struct txnic_cq { - /** Consumer counter */ - unsigned int cons; - /** Completion queue entries */ - userptr_t cqe; -}; - -/****************************************************************************** - * - * Virtual NIC - * - ****************************************************************************** - */ - -/** A virtual NIC */ -struct txnic { - /** Registers */ - void *regs; - /** Device name (for debugging) */ - const char *name; - /** Network device */ - struct net_device *netdev; - - /** Send queue */ - struct txnic_sq sq; - /** Receive queue */ - struct txnic_rq rq; - /** Completion queue */ - struct txnic_cq cq; -}; - -/****************************************************************************** - * - * Physical function - * - ****************************************************************************** - */ - -/** Physical function configuration */ -#define TXNIC_PF_CFG 0x000000 -#define TXNIC_PF_CFG_ENA ( 1ULL << 0 ) - -/** Backpressure configuration */ -#define TXNIC_PF_BP_CFG 0x000080 -#define TXNIC_PF_BP_CFG_BP_POLL_ENA ( 1ULL << 6 ) -#define TXNIC_PF_BP_CFG_BP_POLL_DLY(dl) ( ( ( uint64_t ) (dl) ) << 0 ) -#define TXNIC_PF_BP_CFG_BP_POLL_DLY_DEFAULT \ - TXNIC_PF_BP_CFG_BP_POLL_DLY ( 3 ) - -/** Interface send configuration */ -#define TXNIC_PF_INTF_SEND_CFG(in) ( ( (in) << 8 ) | 0x000200 ) -#define TXNIC_PF_INTF_SEND_CFG_BLOCK_BGX ( 1ULL << 3 ) -#define TXNIC_PF_INTF_SEND_CFG_BLOCK(bl) ( ( ( uint64_t ) (bl) ) << 0 ) - -/** Interface backpressure configuration */ -#define TXNIC_PF_INTF_BP_CFG(in) ( ( (in) << 8 ) | 0x000208 ) -#define TXNIC_PF_INTF_BP_CFG_BP_ENA ( 1ULL << 63 ) -#define TXNIC_PF_INTF_BP_CFG_BP_ID_BGX ( 1ULL << 3 ) -#define TXNIC_PF_INTF_BP_CFG_BP_ID(bp) ( ( ( uint64_t ) (bp) ) << 0 ) - -/** Port kind configuration */ -#define TXNIC_PF_PKIND_CFG(pk) ( ( (pk) << 3 ) | 0x000600 ) -#define TXNIC_PF_PKIND_CFG_LENERR_EN ( 1ULL << 33 ) -#define TXNIC_PF_PKIND_CFG_MAXLEN(ct) ( ( ( uint64_t ) (ct) ) << 16 ) -#define TXNIC_PF_PKIND_CFG_MAXLEN_DISABLE \ - TXNIC_PF_PKIND_CFG_MAXLEN ( 0xffff ) -#define TXNIC_PF_PKIND_CFG_MINLEN(ct) ( ( ( uint64_t ) (ct) ) << 0 ) -#define TXNIC_PF_PKIND_CFG_MINLEN_DISABLE \ - TXNIC_PF_PKIND_CFG_MINLEN ( 0x0000 ) - -/** Match parse index configuration */ -#define TXNIC_PF_MPI_CFG(ix) ( ( (ix) << 3 ) | 0x210000 ) -#define TXNIC_PF_MPI_CFG_VNIC(vn) ( ( ( uint64_t ) (vn) ) << 24 ) -#define TXNIC_PF_MPI_CFG_RSSI_BASE(ix) ( ( ( uint64_t ) (ix) ) << 0 ) - -/** RSS indirection receive queue */ -#define TXNIC_PF_RSSI_RQ(ix) ( ( (ix) << 3 ) | 0x220000 ) -#define TXNIC_PF_RSSI_RQ_RQ_QS(qs) ( ( ( uint64_t ) (qs) ) << 3 ) - -/** LMAC registers */ -#define TXNIC_PF_LMAC(lm) ( ( (lm) << 3 ) | 0x240000 ) - -/** LMAC configuration */ -#define TXNIC_PF_LMAC_CFG 0x000000 -#define TXNIC_PF_LMAC_CFG_ADJUST(ad) ( ( ( uint64_t ) (ad) ) << 8 ) -#define TXNIC_PF_LMAC_CFG_ADJUST_DEFAULT \ - TXNIC_PF_LMAC_CFG_ADJUST ( 6 ) -#define TXNIC_PF_LMAC_CFG_MIN_PKT_SIZE(sz) ( ( ( uint64_t ) (sz) ) << 0 ) - -/** LMAC configuration 2 */ -#define TXNIC_PF_LMAC_CFG2 0x000100 -#define TXNIC_PF_LMAC_CFG2_MAX_PKT_SIZE(sz) ( ( ( uint64_t ) (sz) ) << 0 ) - -/** LMAC credit */ -#define TXNIC_PF_LMAC_CREDIT 0x004000 -#define TXNIC_PF_LMAC_CREDIT_CC_UNIT_CNT(ct) ( ( ( uint64_t ) (ct) ) << 12 ) -#define TXNIC_PF_LMAC_CREDIT_CC_UNIT_CNT_DEFAULT \ - TXNIC_PF_LMAC_CREDIT_CC_UNIT_CNT ( 192 ) -#define TXNIC_PF_LMAC_CREDIT_CC_PACKET_CNT(ct) ( ( ( uint64_t ) (ct) ) << 2 ) -#define TXNIC_PF_LMAC_CREDIT_CC_PACKET_CNT_DEFAULT \ - TXNIC_PF_LMAC_CREDIT_CC_PACKET_CNT ( 511 ) -#define TXNIC_PF_LMAC_CREDIT_CC_ENABLE ( 1ULL << 1 ) - -/** Channel registers */ -#define TXNIC_PF_CHAN(ch) ( ( (ch) << 3 ) | 0x400000 ) - -/** Channel transmit configuration */ -#define TXNIC_PF_CHAN_TX_CFG 0x000000 -#define TXNIC_PF_CHAN_TX_CFG_BP_ENA ( 1ULL << 0 ) - -/** Channel receive configuration */ -#define TXNIC_PF_CHAN_RX_CFG 0x020000 -#define TXNIC_PF_CHAN_RX_CFG_CPI_BASE(ix) ( ( ( uint64_t ) (ix) ) << 48 ) - -/** Channel receive backpressure configuration */ -#define TXNIC_PF_CHAN_RX_BP_CFG 0x080000 -#define TXNIC_PF_CHAN_RX_BP_CFG_ENA ( 1ULL << 63 ) -#define TXNIC_PF_CHAN_RX_BP_CFG_BPID(bp) ( ( ( uint64_t ) (bp) ) << 0 ) - -/** Traffic limiter 2 configuration */ -#define TXNIC_PF_TL2_CFG(tl) ( ( (tl) << 3 ) | 0x500000 ) -#define TXNIC_PF_TL2_CFG_RR_QUANTUM(rr) ( ( ( uint64_t ) (rr) ) << 0 ) -#define TXNIC_PF_TL2_CFG_RR_QUANTUM_DEFAULT \ - TXNIC_PF_TL2_CFG_RR_QUANTUM ( 0x905 ) - -/** Traffic limiter 3 configuration */ -#define TXNIC_PF_TL3_CFG(tl) ( ( (tl) << 3 ) | 0x600000 ) -#define TXNIC_PF_TL3_CFG_RR_QUANTUM(rr) ( ( ( uint64_t ) (rr) ) << 0 ) -#define TXNIC_PF_TL3_CFG_RR_QUANTUM_DEFAULT \ - TXNIC_PF_TL3_CFG_RR_QUANTUM ( 0x905 ) - -/** Traffic limiter 3 channel mapping */ -#define TXNIC_PF_TL3_CHAN(tl) ( ( (tl) << 3 ) | 0x620000 ) -#define TXNIC_PF_TL3_CHAN_CHAN(ch) ( ( (ch) & 0x7f ) << 0 ) - -/** Traffic limiter 4 configuration */ -#define TXNIC_PF_TL4_CFG(tl) ( ( (tl) << 3 ) | 0x800000 ) -#define TXNIC_PF_TL4_CFG_SQ_QS(qs) ( ( ( uint64_t ) (qs) ) << 27 ) -#define TXNIC_PF_TL4_CFG_RR_QUANTUM(rr) ( ( ( uint64_t ) (rr) ) << 0 ) -#define TXNIC_PF_TL4_CFG_RR_QUANTUM_DEFAULT \ - TXNIC_PF_TL4_CFG_RR_QUANTUM ( 0x905 ) - -/** Queue set registers */ -#define TXNIC_PF_QS(qs) ( ( (qs) << 21 ) | 0x20000000UL ) - -/** Queue set configuration */ -#define TXNIC_PF_QS_CFG 0x010000 -#define TXNIC_PF_QS_CFG_ENA ( 1ULL << 31 ) -#define TXNIC_PF_QS_CFG_VNIC(vn) ( ( ( uint64_t ) (vn) ) << 0 ) - -/** Receive queue configuration */ -#define TXNIC_PF_QS_RQ_CFG(q) ( ( (q) << 18 ) | 0x010400 ) -#define TXNIC_PF_QS_RQ_CFG_CACHING(cx) ( ( ( uint64_t ) (cx) ) << 26 ) -#define TXNIC_PF_QS_RQ_CFG_CACHING_ALL \ - TXNIC_PF_QS_RQ_CFG_CACHING ( 1 ) -#define TXNIC_PF_QS_RQ_CFG_CQ_QS(qs) ( ( ( uint64_t ) (qs) ) << 19 ) -#define TXNIC_PF_QS_RQ_CFG_RBDR_CONT_QS(qs) ( ( ( uint64_t ) (qs) ) << 9 ) -#define TXNIC_PF_QS_RQ_CFG_RBDR_STRT_QS(qs) ( ( ( uint64_t ) (qs) ) << 1 ) - -/** Receive queue drop configuration */ -#define TXNIC_PF_QS_RQ_DROP_CFG(q) ( ( (q) << 18 ) | 0x010420 ) - -/** Receive queue backpressure configuration */ -#define TXNIC_PF_QS_RQ_BP_CFG(q) ( ( (q) << 18 ) | 0x010500 ) -#define TXNIC_PF_QS_RQ_BP_CFG_RBDR_BP_ENA ( 1ULL << 63 ) -#define TXNIC_PF_QS_RQ_BP_CFG_CQ_BP_ENA ( 1ULL << 62 ) -#define TXNIC_PF_QS_RQ_BP_CFG_BPID(bp) ( ( ( uint64_t ) (bp) ) << 0 ) - -/** Send queue configuration */ -#define TXNIC_PF_QS_SQ_CFG(q) ( ( (q) << 18 ) | 0x010c00 ) -#define TXNIC_PF_QS_SQ_CFG_CQ_QS(qs) ( ( ( uint64_t ) (qs) ) << 3 ) - -/** Send queue configuration 2 */ -#define TXNIC_PF_QS_SQ_CFG2(q) ( ( (q) << 18 ) | 0x010c08 ) -#define TXNIC_PF_QS_SQ_CFG2_TL4(tl) ( ( ( uint64_t ) (tl) ) << 0 ) - -/** A physical function */ -struct txnic_pf { - /** Registers */ - void *regs; - /** PCI device */ - struct pci_device *pci; - /** Node ID */ - unsigned int node; - - /** Virtual function BAR base */ - unsigned long vf_membase; - /** Virtual function BAR stride */ - unsigned long vf_stride; - - /** List of physical functions */ - struct list_head list; - /** BGX Ethernet interfaces (if known) */ - struct txnic_bgx *bgx[TXNIC_NUM_BGX]; -}; - -/** - * Calculate virtual NIC index - * - * @v bgx_idx BGX Ethernet interface index - * @v lmac_idx Logical MAC index - * @ret vnic_idx Virtual NIC index - */ -#define TXNIC_VNIC_IDX( bgx_idx, lmac_idx ) \ - ( ( (bgx_idx) * TXNIC_NUM_LMAC ) + (lmac_idx) ) - -/** - * Calculate BGX Ethernet interface index - * - * @v vnic_idx Virtual NIC index - * @ret bgx_idx BGX Ethernet interface index - */ -#define TXNIC_BGX_IDX( vnic_idx ) ( (vnic_idx) / TXNIC_NUM_LMAC ) - -/** - * Calculate logical MAC index - * - * @v vnic_idx Virtual NIC index - * @ret lmac_idx Logical MAC index - */ -#define TXNIC_LMAC_IDX( vnic_idx ) ( (vnic_idx) % TXNIC_NUM_LMAC ) - -/** - * Calculate traffic limiter 2 index - * - * @v vnic_idx Virtual NIC index - * @v tl2_idx Traffic limiter 2 index - */ -#define TXNIC_TL2_IDX( vnic_idx ) ( (vnic_idx) << 3 ) - -/** - * Calculate traffic limiter 3 index - * - * @v vnic_idx Virtual NIC index - * @v tl3_idx Traffic limiter 3 index - */ -#define TXNIC_TL3_IDX( vnic_idx ) ( (vnic_idx) << 5 ) - -/** - * Calculate traffic limiter 4 index - * - * @v vnic_idx Virtual NIC index - * @v tl4_idx Traffic limiter 4 index - */ -#define TXNIC_TL4_IDX( vnic_idx ) ( (vnic_idx) << 7 ) - -/** - * Calculate channel index - * - * @v vnic_idx Virtual NIC index - * @v chan_idx Channel index - */ -#define TXNIC_CHAN_IDX( vnic_idx ) ( ( TXNIC_BGX_IDX (vnic_idx) << 7 ) | \ - ( TXNIC_LMAC_IDX (vnic_idx) << 4 ) ) - -/****************************************************************************** - * - * BGX Ethernet interface - * - ****************************************************************************** - */ - -/** Per-LMAC registers */ -#define BGX_LMAC(lm) ( ( (lm) << 20 ) | 0x00000000UL ) - -/** CMR configuration */ -#define BGX_CMR_CONFIG 0x000000 -#define BGX_CMR_CONFIG_ENABLE ( 1ULL << 15 ) -#define BGX_CMR_CONFIG_DATA_PKT_RX_EN ( 1ULL << 14 ) -#define BGX_CMR_CONFIG_DATA_PKT_TX_EN ( 1ULL << 13 ) -#define BGX_CMR_CONFIG_LMAC_TYPE_GET(config) \ - ( ( (config) >> 8 ) & 0x7 ) -#define BGX_CMR_CONFIG_LMAC_TYPE_SET(ty) ( ( ( uint64_t ) (ty) ) << 8 ) -#define BGX_CMR_CONFIG_LANE_TO_SDS(ls) ( ( ( uint64_t ) (ls) ) << 0 ) - -/** CMR global configuration */ -#define BGX_CMR_GLOBAL_CONFIG 0x000008 -#define BGX_CMR_GLOBAL_CONFIG_FCS_STRIP ( 1ULL << 6 ) - -/** CMR receive statistics 0 */ -#define BGX_CMR_RX_STAT0 0x000070 - -/** CMR receive statistics 1 */ -#define BGX_CMR_RX_STAT1 0x000078 - -/** CMR receive statistics 2 */ -#define BGX_CMR_RX_STAT2 0x000080 - -/** CMR receive statistics 3 */ -#define BGX_CMR_RX_STAT3 0x000088 - -/** CMR receive statistics 4 */ -#define BGX_CMR_RX_STAT4 0x000090 - -/** CMR receive statistics 5 */ -#define BGX_CMR_RX_STAT5 0x000098 - -/** CMR receive statistics 6 */ -#define BGX_CMR_RX_STAT6 0x0000a0 - -/** CMR receive statistics 7 */ -#define BGX_CMR_RX_STAT7 0x0000a8 - -/** CMR receive statistics 8 */ -#define BGX_CMR_RX_STAT8 0x0000b0 - -/** CMR receive statistics 9 */ -#define BGX_CMR_RX_STAT9 0x0000b8 - -/** CMR receive statistics 10 */ -#define BGX_CMR_RX_STAT10 0x0000c0 - -/** CMR destination MAC control */ -#define BGX_CMR_RX_DMAC_CTL 0x0000e8 -#define BGX_CMR_RX_DMAC_CTL_MCST_MODE(md) ( ( ( uint64_t ) (md) ) << 1 ) -#define BGX_CMR_RX_DMAC_CTL_MCST_MODE_ACCEPT \ - BGX_CMR_RX_DMAC_CTL_MCST_MODE ( 1 ) -#define BGX_CMR_RX_DMAC_CTL_BCST_ACCEPT ( 1ULL << 0 ) - -/** CMR destination MAC CAM */ -#define BGX_CMR_RX_DMAC_CAM(i) ( ( (i) << 3 ) | 0x000200 ) - -/** CMR receive steering */ -#define BGX_CMR_RX_STEERING(i) ( ( (i) << 3 ) | 0x000300 ) - -/** CMR backpressure channel mask AND */ -#define BGX_CMR_CHAN_MSK_AND 0x000450 -#define BGX_CMR_CHAN_MSK_AND_ALL(count) \ - ( 0xffffffffffffffffULL >> ( 16 * ( 4 - (count) ) ) ) - -/** CMR transmit statistics 0 */ -#define BGX_CMR_TX_STAT0 0x000600 - -/** CMR transmit statistics 1 */ -#define BGX_CMR_TX_STAT1 0x000608 - -/** CMR transmit statistics 2 */ -#define BGX_CMR_TX_STAT2 0x000610 - -/** CMR transmit statistics 3 */ -#define BGX_CMR_TX_STAT3 0x000618 - -/** CMR transmit statistics 4 */ -#define BGX_CMR_TX_STAT4 0x000620 - -/** CMR transmit statistics 5 */ -#define BGX_CMR_TX_STAT5 0x000628 - -/** CMR transmit statistics 6 */ -#define BGX_CMR_TX_STAT6 0x000630 - -/** CMR transmit statistics 7 */ -#define BGX_CMR_TX_STAT7 0x000638 - -/** CMR transmit statistics 8 */ -#define BGX_CMR_TX_STAT8 0x000640 - -/** CMR transmit statistics 9 */ -#define BGX_CMR_TX_STAT9 0x000648 - -/** CMR transmit statistics 10 */ -#define BGX_CMR_TX_STAT10 0x000650 - -/** CMR transmit statistics 11 */ -#define BGX_CMR_TX_STAT11 0x000658 - -/** CMR transmit statistics 12 */ -#define BGX_CMR_TX_STAT12 0x000660 - -/** CMR transmit statistics 13 */ -#define BGX_CMR_TX_STAT13 0x000668 - -/** CMR transmit statistics 14 */ -#define BGX_CMR_TX_STAT14 0x000670 - -/** CMR transmit statistics 15 */ -#define BGX_CMR_TX_STAT15 0x000678 - -/** CMR transmit statistics 16 */ -#define BGX_CMR_TX_STAT16 0x000680 - -/** CMR transmit statistics 17 */ -#define BGX_CMR_TX_STAT17 0x000688 - -/** CMR receive logical MACs */ -#define BGX_CMR_RX_LMACS 0x000468 -#define BGX_CMR_RX_LMACS_LMACS_GET(lmacs) \ - ( ( (lmacs) >> 0 ) & 0x7 ) -#define BGX_CMR_RX_LMACS_LMACS_SET(ct) ( ( ( uint64_t ) (ct) ) << 0 ) - -/** CMR transmit logical MACs */ -#define BGX_CMR_TX_LMACS 0x001000 -#define BGX_CMR_TX_LMACS_LMACS_GET(lmacs) \ - ( ( (lmacs) >> 0 ) & 0x7 ) -#define BGX_CMR_TX_LMACS_LMACS_SET(ct) ( ( ( uint64_t ) (ct) ) << 0 ) - -/** SPU control 1 */ -#define BGX_SPU_CONTROL1 0x010000 -#define BGX_SPU_CONTROL1_RESET ( 1ULL << 15 ) -#define BGX_SPU_CONTROL1_LO_PWR ( 1ULL << 11 ) - -/** SPU reset delay */ -#define BGX_SPU_RESET_DELAY_MS 10 - -/** SPU status 1 */ -#define BGX_SPU_STATUS1 0x010008 -#define BGX_SPU_STATUS1_FLT ( 1ULL << 7 ) -#define BGX_SPU_STATUS1_RCV_LNK ( 1ULL << 2 ) - -/** SPU status 2 */ -#define BGX_SPU_STATUS2 0x010020 -#define BGX_SPU_STATUS2_RCVFLT ( 1ULL << 10 ) - -/** SPU BASE-R status 1 */ -#define BGX_SPU_BR_STATUS1 0x010030 -#define BGX_SPU_BR_STATUS1_RCV_LNK ( 1ULL << 12 ) -#define BGX_SPU_BR_STATUS1_HI_BER ( 1ULL << 1 ) -#define BGX_SPU_BR_STATUS1_BLK_LOCK ( 1ULL << 0 ) - -/** SPU BASE-R status 2 */ -#define BGX_SPU_BR_STATUS2 0x010038 -#define BGX_SPU_BR_STATUS2_LATCHED_LOCK ( 1ULL << 15 ) -#define BGX_SPU_BR_STATUS2_LATCHED_BER ( 1ULL << 14 ) - -/** SPU BASE-R alignment status */ -#define BGX_SPU_BR_ALGN_STATUS 0x010050 -#define BGX_SPU_BR_ALGN_STATUS_ALIGND ( 1ULL << 12 ) - -/** SPU BASE-R link training control */ -#define BGX_SPU_BR_PMD_CONTROL 0x010068 -#define BGX_SPU_BR_PMD_CONTROL_TRAIN_EN ( 1ULL << 1 ) - -/** SPU BASE-R link training status */ -#define BGX_SPU_BR_PMD_STATUS 0x010070 - -/** SPU link partner coefficient update */ -#define BGX_SPU_BR_PMD_LP_CUP 0x010078 - -/** SPU local device coefficient update */ -#define BGX_SPU_BR_PMD_LD_CUP 0x010088 - -/** SPU local device status report */ -#define BGX_SPU_BR_PMD_LD_REP 0x010090 - -/** SPU forward error correction control */ -#define BGX_SPU_FEC_CONTROL 0x0100a0 - -/** SPU autonegotation control */ -#define BGX_SPU_AN_CONTROL 0x0100c8 - -/** SPU autonegotiation status */ -#define BGX_SPU_AN_STATUS 0x0100d0 -#define BGX_SPU_AN_STATUS_XNP_STAT ( 1ULL << 7 ) -#define BGX_SPU_AN_STATUS_PAGE_RX ( 1ULL << 6 ) -#define BGX_SPU_AN_STATUS_AN_COMPLETE ( 1ULL << 5 ) -#define BGX_SPU_AN_STATUS_LINK_STATUS ( 1ULL << 2 ) -#define BGX_SPU_AN_STATUS_LP_AN_ABLE ( 1ULL << 0 ) - -/** SPU interrupt */ -#define BGX_SPU_INT 0x010220 -#define BGX_SPU_INT_TRAINING_FAIL ( 1ULL << 14 ) -#define BGX_SPU_INT_TRAINING_DONE ( 1ULL << 13 ) -#define BGX_SPU_INT_AN_COMPLETE ( 1ULL << 12 ) -#define BGX_SPU_INT_AN_LINK_GOOD ( 1ULL << 11 ) -#define BGX_SPU_INT_AN_PAGE_RX ( 1ULL << 10 ) -#define BGX_SPU_INT_FEC_UNCORR ( 1ULL << 9 ) -#define BGX_SPU_INT_FEC_CORR ( 1ULL << 8 ) -#define BGX_SPU_INT_BIP_ERR ( 1ULL << 7 ) -#define BGX_SPU_INT_DBG_SYNC ( 1ULL << 6 ) -#define BGX_SPU_INT_ALGNLOS ( 1ULL << 5 ) -#define BGX_SPU_INT_SYNLOS ( 1ULL << 4 ) -#define BGX_SPU_INT_BITLCKLS ( 1ULL << 3 ) -#define BGX_SPU_INT_ERR_BLK ( 1ULL << 2 ) -#define BGX_SPU_INT_RX_LINK_DOWN ( 1ULL << 1 ) -#define BGX_SPU_INT_RX_LINK_UP ( 1ULL << 0 ) - -/** LMAC types */ -enum txnic_lmac_types { - TXNIC_LMAC_SGMII = 0x0, /**< SGMII/1000BASE-X */ - TXNIC_LMAC_XAUI = 0x1, /**< 10GBASE-X/XAUI or DXAUI */ - TXNIC_LMAC_RXAUI = 0x2, /**< Reduced XAUI */ - TXNIC_LMAC_10G_R = 0x3, /**< 10GBASE-R */ - TXNIC_LMAC_40G_R = 0x4, /**< 40GBASE-R */ -}; - -/** An LMAC type */ -struct txnic_lmac_type { - /** Name */ - const char *name; - /** Number of LMACs */ - uint8_t count; - /** Lane-to-SDS mapping */ - uint32_t lane_to_sds; -}; - -/** An LMAC address */ -union txnic_lmac_address { - struct { - uint8_t pad[2]; - uint8_t raw[ETH_ALEN]; - } __attribute__ (( packed )); - uint64_t be64; -}; - -/** A Logical MAC (LMAC) */ -struct txnic_lmac { - /** Registers */ - void *regs; - /** Containing BGX Ethernet interface */ - struct txnic_bgx *bgx; - /** Virtual NIC index */ - unsigned int idx; - - /** MAC address */ - union txnic_lmac_address mac; - - /** Virtual NIC (if applicable) */ - struct txnic *vnic; -}; - -/** A BGX Ethernet interface */ -struct txnic_bgx { - /** Registers */ - void *regs; - /** PCI device */ - struct pci_device *pci; - /** Node ID */ - unsigned int node; - /** BGX index */ - unsigned int idx; - - /** LMAC type */ - struct txnic_lmac_type *type; - /** Number of LMACs */ - unsigned int count; - /** Link training is in use */ - int training; - - /** List of BGX Ethernet interfaces */ - struct list_head list; - /** Physical function (if known) */ - struct txnic_pf *pf; - - /** Logical MACs */ - struct txnic_lmac lmac[TXNIC_NUM_LMAC]; -}; - -#endif /* _THUNDERX_H */ diff --git a/roms/ipxe/src/drivers/net/thunderxcfg.h b/roms/ipxe/src/drivers/net/thunderxcfg.h deleted file mode 100644 index 235c54319..000000000 --- a/roms/ipxe/src/drivers/net/thunderxcfg.h +++ /dev/null @@ -1,211 +0,0 @@ -#ifndef _THUNDERXCFG_H -#define _THUNDERXCFG_H - -/** @file - * - * Cavium ThunderX Board Configuration - * - * The definitions in this section are extracted from BSD-licensed - * (but non-public) portions of ThunderPkg. - * - */ - -FILE_LICENCE ( BSD2 ); - -#include <ipxe/efi/efi.h> - -/****************************************************************************** - * - * From ThunderxBoardConfig.h - * - ****************************************************************************** - * - * Header file for Cavium ThunderX Board Configurations - * Copyright (c) 2015, Cavium Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR - * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF - * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ - -#define MAX_NODES 2 -#define CLUSTER_COUNT 3 -#define CORE_PER_CLUSTER_COUNT 16 -#define CORE_COUNT (CLUSTER_COUNT*CORE_PER_CLUSTER_COUNT) -#define BGX_PER_NODE_COUNT 2 -#define LMAC_PER_BGX_COUNT 4 -#define PEM_PER_NODE_COUNT 6 -#define LMC_PER_NODE_COUNT 4 -#define DIMM_PER_LMC_COUNT 2 - -#define THUNDERX_CPU_ID(node, cluster, core) (((node) << 16) | ((cluster) << 8) | (core)) - -//TODO: Put common type definitions in separate common include file -typedef enum { - BGX_MODE_SGMII, /* 1 lane, 1.250 Gbaud */ - BGX_MODE_XAUI, /* 4 lanes, 3.125 Gbaud */ - BGX_MODE_DXAUI, /* 4 lanes, 6.250 Gbaud */ - BGX_MODE_RXAUI, /* 2 lanes, 6.250 Gbaud */ - BGX_MODE_XFI, /* 1 lane, 10.3125 Gbaud */ - BGX_MODE_XLAUI, /* 4 lanes, 10.3125 Gbaud */ - BGX_MODE_10G_KR,/* 1 lane, 10.3125 Gbaud */ - BGX_MODE_40G_KR,/* 4 lanes, 10.3125 Gbaud */ - BGX_MODE_UNKNOWN -} BGX_MODE_T; - -typedef enum { - EBB8800, - EBB8804, - CRB_1S, - CRB_2S, - ASIANCAT, - GBT_MT60, - INVENTEC_P3E003, - BOARD_MAX -} BOARD_TYPE; - -typedef struct { - BOOLEAN Enabled; - UINT64 LaneToSds; - UINT64 MacAddress; -} LMAC_CFG; - -typedef struct { - BOOLEAN BgxEnabled; - BGX_MODE_T BgxMode; - UINTN LmacCount; //Maximum number of LMAcs - UINT64 BaseAddress; - UINT64 LmacType; - /* Bit mask of QLMs connected to this BGX */ - UINT64 QlmMask; - UINT64 QlmFreq; - BOOLEAN UseTraining; - LMAC_CFG Lmacs[LMAC_PER_BGX_COUNT]; -} BGX_CFG; - -typedef struct { - BOOLEAN PemUsable; -} PEM_CFG; - -typedef struct { - enum { NotPresent, Empty, Available } Status; - UINT8 Type; - UINT8 SubType; - UINT8 Rank; - UINT16 Mfg; - UINTN SizeMb; - UINTN Speed; - CHAR8 Serial[16]; - CHAR8 PartNo[24]; -} DIMM_CFG; - -typedef struct { - DIMM_CFG DimmCfg[DIMM_PER_LMC_COUNT]; -} LMC_CFG; - -typedef struct { - BOOLEAN Core[CORE_COUNT]; - BGX_CFG BgxCfg[BGX_PER_NODE_COUNT]; - PEM_CFG PemCfg[PEM_PER_NODE_COUNT]; - LMC_CFG LmcCfg[LMC_PER_NODE_COUNT]; - UINT64 RamStart; - UINT64 RamReserve; - UINT64 RamSize; - UINTN CPUSpeed; - UINTN CPUVersion; -} NODE_CFG; - -#define MAX_SERIAL 32 -#define MAX_REVISION 32 -typedef struct { - BOARD_TYPE BoardType; - CHAR8 Serial[MAX_SERIAL]; - CHAR8 Revision[MAX_REVISION]; - UINTN NumNodes; - UINTN BmcBootTwsiBus; - UINTN BmcBootTwsiAddr; - UINTN RtcTwsiBus; - UINTN RtcTwsiAddr; - /* IPMI support*/ - UINTN BmcIpmiTwsiBus; - UINTN BmcIpmiTwsiAddr; - NODE_CFG Node[MAX_NODES]; - UINT16 CpuClusterCount; - UINT16 CpuPerClusterCount; - UINT16 PcieSegmentCount; - UINT64 MacAddrRangeStart; - UINTN DdrSpeed; - UINT64 AcpiOemTableId; -} BOARD_CFG; - -/****************************************************************************** - * - * From ThunderConfigProtocol.h - * - ****************************************************************************** - * - * Thunder board Configuration Protocol - * - * Copyright (c) 2015, Cavium Inc. All rights reserved.<BR> - * - * This program and the accompanying materials are licensed and made - * available under the terms and conditions of the BSD License which - * accompanies this distribution. The full text of the license may - * be found at http://opensource.org/licenses/bsd-license.php - * - * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" - * BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER - * EXPRESS OR IMPLIED. - * - */ - -#define EFI_THUNDER_CONFIG_PROTOCOL_GUID \ - {0xb75a0608, 0x99ff, 0x11e5, {0x9b, 0xeb, 0x00, 0x14, 0xd1, 0xfa, 0x23, 0x5c}} - -/// -/// Forward declaration -/// -typedef struct _EFI_THUNDER_CONFIG_PROTOCOL EFI_THUNDER_CONFIG_PROTOCOL; - -/// -/// Function prototypes -/// -typedef -EFI_STATUS -(EFIAPI *EFI_THUNDER_CONFIG_PROTOCOL_GET_CONFIG)( - IN EFI_THUNDER_CONFIG_PROTOCOL *This, - OUT BOARD_CFG** cfg - ); - -/// -/// Protocol structure -/// -struct _EFI_THUNDER_CONFIG_PROTOCOL { - EFI_THUNDER_CONFIG_PROTOCOL_GET_CONFIG GetConfig; - BOARD_CFG* BoardConfig; -}; - -#endif /* _THUNDERXCFG_H */ diff --git a/roms/ipxe/src/drivers/net/virtio-net.c b/roms/ipxe/src/drivers/net/virtio-net.c index fe0fd4b86..533ccb0c6 100644 --- a/roms/ipxe/src/drivers/net/virtio-net.c +++ b/roms/ipxe/src/drivers/net/virtio-net.c @@ -24,15 +24,14 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <errno.h> #include <stdlib.h> -#include <unistd.h> #include <ipxe/list.h> #include <ipxe/iobuf.h> #include <ipxe/netdevice.h> #include <ipxe/pci.h> #include <ipxe/if_ether.h> #include <ipxe/ethernet.h> -#include <ipxe/virtio-pci.h> #include <ipxe/virtio-ring.h> +#include <ipxe/virtio-pci.h> #include "virtio-net.h" /* @@ -89,12 +88,6 @@ struct virtnet_nic { /** Base pio register address */ unsigned long ioaddr; - /** 0 for legacy, 1 for virtio 1.0 */ - int virtio_version; - - /** Virtio 1.0 device data */ - struct virtio_pci_modern_device vdev; - /** RX/TX virtqueues */ struct vring_virtqueue *virtqueue; @@ -105,7 +98,7 @@ struct virtnet_nic { unsigned int rx_num_iobufs; /** Virtio net packet header, we only need one */ - struct virtio_net_hdr_modern empty_header; + struct virtio_net_hdr empty_header; }; /** Add an iobuf to a virtqueue @@ -122,9 +115,6 @@ static void virtnet_enqueue_iob ( struct net_device *netdev, struct vring_virtqueue *vq = &virtnet->virtqueue[vq_idx]; unsigned int out = ( vq_idx == TX_INDEX ) ? 2 : 0; unsigned int in = ( vq_idx == TX_INDEX ) ? 0 : 2; - size_t header_len = virtnet->virtio_version - ? sizeof ( virtnet->empty_header ) - : sizeof ( virtnet->empty_header.legacy ); struct vring_list list[] = { { /* Share a single zeroed virtio net header between all @@ -133,7 +123,7 @@ static void virtnet_enqueue_iob ( struct net_device *netdev, * header fields get used. */ .addr = ( char* ) &virtnet->empty_header, - .length = header_len, + .length = sizeof ( virtnet->empty_header ), }, { .addr = ( char* ) iobuf->data, @@ -145,8 +135,7 @@ static void virtnet_enqueue_iob ( struct net_device *netdev, virtnet, iobuf, vq_idx ); vring_add_buf ( vq, list, out, in, iobuf, 0 ); - vring_kick ( virtnet->virtio_version ? &virtnet->vdev : NULL, - virtnet->ioaddr, vq, 1 ); + vring_kick ( virtnet->ioaddr, vq, 1 ); } /** Try to keep rx virtqueue filled with iobufs @@ -175,12 +164,12 @@ static void virtnet_refill_rx_virtqueue ( struct net_device *netdev ) { } } -/** Open network device, legacy virtio 0.9.5 +/** Open network device * * @v netdev Network device * @ret rc Return status code */ -static int virtnet_open_legacy ( struct net_device *netdev ) { +static int virtnet_open ( struct net_device *netdev ) { struct virtnet_nic *virtnet = netdev->priv; unsigned long ioaddr = virtnet->ioaddr; u32 features; @@ -221,81 +210,6 @@ static int virtnet_open_legacy ( struct net_device *netdev ) { return 0; } -/** Open network device, modern virtio 1.0 - * - * @v netdev Network device - * @ret rc Return status code - */ -static int virtnet_open_modern ( struct net_device *netdev ) { - struct virtnet_nic *virtnet = netdev->priv; - u64 features; - u8 status; - - /* Negotiate features */ - features = vpm_get_features ( &virtnet->vdev ); - if ( ! ( features & VIRTIO_F_VERSION_1 ) ) { - vpm_add_status ( &virtnet->vdev, VIRTIO_CONFIG_S_FAILED ); - return -EINVAL; - } - vpm_set_features ( &virtnet->vdev, features & ( - ( 1ULL << VIRTIO_NET_F_MAC ) | - ( 1ULL << VIRTIO_F_VERSION_1 ) | - ( 1ULL << VIRTIO_F_ANY_LAYOUT ) ) ); - vpm_add_status ( &virtnet->vdev, VIRTIO_CONFIG_S_FEATURES_OK ); - - status = vpm_get_status ( &virtnet->vdev ); - if ( ! ( status & VIRTIO_CONFIG_S_FEATURES_OK ) ) { - DBGC ( virtnet, "VIRTIO-NET %p device didn't accept features\n", - virtnet ); - vpm_add_status ( &virtnet->vdev, VIRTIO_CONFIG_S_FAILED ); - return -EINVAL; - } - - /* Allocate virtqueues */ - virtnet->virtqueue = zalloc ( QUEUE_NB * - sizeof ( *virtnet->virtqueue ) ); - if ( ! virtnet->virtqueue ) { - vpm_add_status ( &virtnet->vdev, VIRTIO_CONFIG_S_FAILED ); - return -ENOMEM; - } - - /* Initialize rx/tx virtqueues */ - if ( vpm_find_vqs ( &virtnet->vdev, QUEUE_NB, virtnet->virtqueue ) ) { - DBGC ( virtnet, "VIRTIO-NET %p cannot register queues\n", - virtnet ); - free ( virtnet->virtqueue ); - virtnet->virtqueue = NULL; - vpm_add_status ( &virtnet->vdev, VIRTIO_CONFIG_S_FAILED ); - return -ENOENT; - } - - /* Disable interrupts before starting */ - netdev_irq ( netdev, 0 ); - - vpm_add_status ( &virtnet->vdev, VIRTIO_CONFIG_S_DRIVER_OK ); - - /* Initialize rx packets */ - INIT_LIST_HEAD ( &virtnet->rx_iobufs ); - virtnet->rx_num_iobufs = 0; - virtnet_refill_rx_virtqueue ( netdev ); - return 0; -} - -/** Open network device - * - * @v netdev Network device - * @ret rc Return status code - */ -static int virtnet_open ( struct net_device *netdev ) { - struct virtnet_nic *virtnet = netdev->priv; - - if ( virtnet->virtio_version ) { - return virtnet_open_modern ( netdev ); - } else { - return virtnet_open_legacy ( netdev ); - } -} - /** Close network device * * @v netdev Network device @@ -304,19 +218,10 @@ static void virtnet_close ( struct net_device *netdev ) { struct virtnet_nic *virtnet = netdev->priv; struct io_buffer *iobuf; struct io_buffer *next_iobuf; - int i; - if ( virtnet->virtio_version ) { - vpm_reset ( &virtnet->vdev ); - } else { - vp_reset ( virtnet->ioaddr ); - } + vp_reset ( virtnet->ioaddr ); /* Virtqueues can be freed now that NIC is reset */ - for ( i = 0 ; i < QUEUE_NB ; i++ ) { - virtio_pci_unmap_capability ( &virtnet->virtqueue[i].notification ); - } - free ( virtnet->virtqueue ); virtnet->virtqueue = NULL; @@ -397,14 +302,10 @@ static void virtnet_poll ( struct net_device *netdev ) { /* Acknowledge interrupt. This is necessary for UNDI operation and * interrupts that are raised despite VRING_AVAIL_F_NO_INTERRUPT being - * set (that flag is just a hint and the hypervisor does not have to + * set (that flag is just a hint and the hypervisor not not have to * honor it). */ - if ( virtnet->virtio_version ) { - vpm_get_isr ( &virtnet->vdev ); - } else { - vp_get_isr ( virtnet->ioaddr ); - } + vp_get_isr ( virtnet->ioaddr ); virtnet_process_tx_packets ( netdev ); virtnet_process_rx_packets ( netdev ); @@ -437,12 +338,13 @@ static struct net_device_operations virtnet_operations = { }; /** - * Probe PCI device, legacy virtio 0.9.5 + * Probe PCI device * * @v pci PCI device + * @v id PCI ID * @ret rc Return status code */ -static int virtnet_probe_legacy ( struct pci_device *pci ) { +static int virtnet_probe ( struct pci_device *pci ) { unsigned long ioaddr = pci->ioaddr; struct net_device *netdev; struct virtnet_nic *virtnet; @@ -493,154 +395,12 @@ static int virtnet_probe_legacy ( struct pci_device *pci ) { } /** - * Probe PCI device, modern virtio 1.0 - * - * @v pci PCI device - * @v found_dev Set to non-zero if modern device was found (probe may still fail) - * @ret rc Return status code - */ -static int virtnet_probe_modern ( struct pci_device *pci, int *found_dev ) { - struct net_device *netdev; - struct virtnet_nic *virtnet; - u64 features; - int rc, common, isr, notify, config, device; - - common = virtio_pci_find_capability ( pci, VIRTIO_PCI_CAP_COMMON_CFG ); - if ( ! common ) { - DBG ( "Common virtio capability not found!\n" ); - return -ENODEV; - } - *found_dev = 1; - - isr = virtio_pci_find_capability ( pci, VIRTIO_PCI_CAP_ISR_CFG ); - notify = virtio_pci_find_capability ( pci, VIRTIO_PCI_CAP_NOTIFY_CFG ); - config = virtio_pci_find_capability ( pci, VIRTIO_PCI_CAP_PCI_CFG ); - if ( ! isr || ! notify || ! config ) { - DBG ( "Missing virtio capabilities %i/%i/%i/%i\n", - common, isr, notify, config ); - return -EINVAL; - } - device = virtio_pci_find_capability ( pci, VIRTIO_PCI_CAP_DEVICE_CFG ); - - /* Allocate and hook up net device */ - netdev = alloc_etherdev ( sizeof ( *virtnet ) ); - if ( ! netdev ) - return -ENOMEM; - netdev_init ( netdev, &virtnet_operations ); - virtnet = netdev->priv; - - pci_set_drvdata ( pci, netdev ); - netdev->dev = &pci->dev; - - DBGC ( virtnet, "VIRTIO-NET modern %p busaddr=%s irq=%d\n", - virtnet, pci->dev.name, pci->irq ); - - virtnet->vdev.pci = pci; - rc = virtio_pci_map_capability ( pci, common, - sizeof ( struct virtio_pci_common_cfg ), 4, - 0, sizeof ( struct virtio_pci_common_cfg ), - &virtnet->vdev.common ); - if ( rc ) - goto err_map_common; - - rc = virtio_pci_map_capability ( pci, isr, sizeof ( u8 ), 1, - 0, 1, - &virtnet->vdev.isr ); - if ( rc ) - goto err_map_isr; - - virtnet->vdev.notify_cap_pos = notify; - virtnet->vdev.cfg_cap_pos = config; - - /* Map the device capability */ - if ( device ) { - rc = virtio_pci_map_capability ( pci, device, - 0, 4, 0, sizeof ( struct virtio_net_config ), - &virtnet->vdev.device ); - if ( rc ) - goto err_map_device; - } - - /* Enable the PCI device */ - adjust_pci_device ( pci ); - - /* Reset the device and set initial status bits */ - vpm_reset ( &virtnet->vdev ); - vpm_add_status ( &virtnet->vdev, VIRTIO_CONFIG_S_ACKNOWLEDGE ); - vpm_add_status ( &virtnet->vdev, VIRTIO_CONFIG_S_DRIVER ); - - /* Load MAC address */ - if ( device ) { - features = vpm_get_features ( &virtnet->vdev ); - if ( features & ( 1ULL << VIRTIO_NET_F_MAC ) ) { - vpm_get ( &virtnet->vdev, - offsetof ( struct virtio_net_config, mac ), - netdev->hw_addr, ETH_ALEN ); - DBGC ( virtnet, "VIRTIO-NET %p mac=%s\n", virtnet, - eth_ntoa ( netdev->hw_addr ) ); - } - } - - /* We need a valid MAC address */ - if ( ! is_valid_ether_addr ( netdev->hw_addr ) ) { - rc = -EADDRNOTAVAIL; - goto err_mac_address; - } - - /* Register network device */ - if ( ( rc = register_netdev ( netdev ) ) != 0 ) - goto err_register_netdev; - - /* Mark link as up, control virtqueue is not used */ - netdev_link_up ( netdev ); - - virtnet->virtio_version = 1; - return 0; - - unregister_netdev ( netdev ); -err_register_netdev: -err_mac_address: - vpm_reset ( &virtnet->vdev ); - netdev_nullify ( netdev ); - netdev_put ( netdev ); - - virtio_pci_unmap_capability ( &virtnet->vdev.device ); -err_map_device: - virtio_pci_unmap_capability ( &virtnet->vdev.isr ); -err_map_isr: - virtio_pci_unmap_capability ( &virtnet->vdev.common ); -err_map_common: - return rc; -} - -/** - * Probe PCI device - * - * @v pci PCI device - * @ret rc Return status code - */ -static int virtnet_probe ( struct pci_device *pci ) { - int found_modern = 0; - int rc = virtnet_probe_modern ( pci, &found_modern ); - if ( ! found_modern && pci->device < 0x1040 ) { - /* fall back to the legacy probe */ - rc = virtnet_probe_legacy ( pci ); - } - return rc; -} - -/** * Remove device * * @v pci PCI device */ static void virtnet_remove ( struct pci_device *pci ) { struct net_device *netdev = pci_get_drvdata ( pci ); - struct virtnet_nic *virtnet = netdev->priv; - - virtio_pci_unmap_capability ( &virtnet->vdev.device ); - virtio_pci_unmap_capability ( &virtnet->vdev.isr ); - virtio_pci_unmap_capability ( &virtnet->vdev.common ); unregister_netdev ( netdev ); netdev_nullify ( netdev ); @@ -649,7 +409,6 @@ static void virtnet_remove ( struct pci_device *pci ) { static struct pci_device_id virtnet_nics[] = { PCI_ROM(0x1af4, 0x1000, "virtio-net", "Virtio Network Interface", 0), -PCI_ROM(0x1af4, 0x1041, "virtio-net", "Virtio Network Interface 1.0", 0), }; struct pci_driver virtnet_driver __pci_driver = { diff --git a/roms/ipxe/src/drivers/net/virtio-net.h b/roms/ipxe/src/drivers/net/virtio-net.h index c2b4a17cc..3abef28ea 100644 --- a/roms/ipxe/src/drivers/net/virtio-net.h +++ b/roms/ipxe/src/drivers/net/virtio-net.h @@ -14,12 +14,6 @@ #define VIRTIO_NET_F_HOST_TSO6 12 /* Host can handle TSOv6 in. */ #define VIRTIO_NET_F_HOST_ECN 13 /* Host can handle TSO[6] w/ ECN in. */ #define VIRTIO_NET_F_HOST_UFO 14 /* Host can handle UFO in. */ -#define VIRTIO_NET_F_MRG_RXBUF 15 /* Driver can merge receive buffers. */ -#define VIRTIO_NET_F_STATUS 16 /* Configuration status field is available. */ -#define VIRTIO_NET_F_CTRL_VQ 17 /* Control channel is available. */ -#define VIRTIO_NET_F_CTRL_RX 18 /* Control channel RX mode support. */ -#define VIRTIO_NET_F_CTRL_VLAN 19 /* Control channel VLAN filtering. */ -#define VIRTIO_NET_F_GUEST_ANNOUNCE 21 /* Driver can send gratuitous packets. */ struct virtio_net_config { @@ -47,14 +41,4 @@ struct virtio_net_hdr uint16_t csum_start; uint16_t csum_offset; }; - -/* Virtio 1.0 version of the first element of the scatter-gather list. */ -struct virtio_net_hdr_modern -{ - struct virtio_net_hdr legacy; - - /* Used only if VIRTIO_NET_F_MRG_RXBUF: */ - uint16_t num_buffers; -}; - #endif /* _VIRTIO_NET_H_ */ diff --git a/roms/ipxe/src/drivers/net/vmxnet3.c b/roms/ipxe/src/drivers/net/vmxnet3.c index 6a54dbf89..8d4f4b843 100644 --- a/roms/ipxe/src/drivers/net/vmxnet3.c +++ b/roms/ipxe/src/drivers/net/vmxnet3.c @@ -92,24 +92,19 @@ static int vmxnet3_transmit ( struct net_device *netdev, struct io_buffer *iobuf ) { struct vmxnet3_nic *vmxnet = netdev_priv ( netdev ); struct vmxnet3_tx_desc *tx_desc; - unsigned int fill; unsigned int desc_idx; unsigned int generation; /* Check that we have a free transmit descriptor */ - fill = ( vmxnet->count.tx_prod - vmxnet->count.tx_cons ); - if ( fill >= VMXNET3_TX_FILL ) { + desc_idx = ( vmxnet->count.tx_prod % VMXNET3_NUM_TX_DESC ); + generation = ( ( vmxnet->count.tx_prod & VMXNET3_NUM_TX_DESC ) ? + 0 : cpu_to_le32 ( VMXNET3_TXF_GEN ) ); + if ( vmxnet->tx_iobuf[desc_idx] ) { DBGC ( vmxnet, "VMXNET3 %p out of transmit descriptors\n", vmxnet ); return -ENOBUFS; } - /* Locate transmit descriptor */ - desc_idx = ( vmxnet->count.tx_prod % VMXNET3_NUM_TX_DESC ); - generation = ( ( vmxnet->count.tx_prod & VMXNET3_NUM_TX_DESC ) ? - 0 : cpu_to_le32 ( VMXNET3_TXF_GEN ) ); - assert ( vmxnet->tx_iobuf[desc_idx] == NULL ); - /* Increment producer counter */ vmxnet->count.tx_prod++; diff --git a/roms/ipxe/src/drivers/net/vmxnet3.h b/roms/ipxe/src/drivers/net/vmxnet3.h index 5e1e0cb6e..a1671d9dd 100644 --- a/roms/ipxe/src/drivers/net/vmxnet3.h +++ b/roms/ipxe/src/drivers/net/vmxnet3.h @@ -493,9 +493,6 @@ struct vmxnet3_nic { /** MTU size */ #define VMXNET3_MTU ( ETH_FRAME_LEN + 4 /* VLAN */ + 4 /* FCS */ ) -/** Transmit ring maximum fill level */ -#define VMXNET3_TX_FILL ( VMXNET3_NUM_TX_DESC - 1 ) - /** Receive ring maximum fill level */ #define VMXNET3_RX_FILL 8 diff --git a/roms/ipxe/src/drivers/usb/ehci.c b/roms/ipxe/src/drivers/usb/ehci.c index 35cbc8de9..4124692a6 100644 --- a/roms/ipxe/src/drivers/usb/ehci.c +++ b/roms/ipxe/src/drivers/usb/ehci.c @@ -175,61 +175,6 @@ static int ehci_ctrl_reachable ( struct ehci_device *ehci, void *ptr ) { /****************************************************************************** * - * Diagnostics - * - ****************************************************************************** - */ - -/** - * Dump host controller registers - * - * @v ehci EHCI device - */ -static __unused void ehci_dump ( struct ehci_device *ehci ) { - uint8_t caplength; - uint16_t hciversion; - uint32_t hcsparams; - uint32_t hccparams; - uint32_t usbcmd; - uint32_t usbsts; - uint32_t usbintr; - uint32_t frindex; - uint32_t ctrldssegment; - uint32_t periodiclistbase; - uint32_t asynclistaddr; - uint32_t configflag; - - /* Do nothing unless debugging is enabled */ - if ( ! DBG_LOG ) - return; - - /* Dump capability registers */ - caplength = readb ( ehci->cap + EHCI_CAP_CAPLENGTH ); - hciversion = readw ( ehci->cap + EHCI_CAP_HCIVERSION ); - hcsparams = readl ( ehci->cap + EHCI_CAP_HCSPARAMS ); - hccparams = readl ( ehci->cap + EHCI_CAP_HCCPARAMS ); - DBGC ( ehci, "EHCI %s caplen %02x hciversion %04x hcsparams %08x " - "hccparams %08x\n", ehci->name, caplength, hciversion, - hcsparams, hccparams ); - - /* Dump operational registers */ - usbcmd = readl ( ehci->op + EHCI_OP_USBCMD ); - usbsts = readl ( ehci->op + EHCI_OP_USBSTS ); - usbintr = readl ( ehci->op + EHCI_OP_USBINTR ); - frindex = readl ( ehci->op + EHCI_OP_FRINDEX ); - ctrldssegment = readl ( ehci->op + EHCI_OP_CTRLDSSEGMENT ); - periodiclistbase = readl ( ehci->op + EHCI_OP_PERIODICLISTBASE ); - asynclistaddr = readl ( ehci->op + EHCI_OP_ASYNCLISTADDR ); - configflag = readl ( ehci->op + EHCI_OP_CONFIGFLAG ); - DBGC ( ehci, "EHCI %s usbcmd %08x usbsts %08x usbint %08x frindx " - "%08x\n", ehci->name, usbcmd, usbsts, usbintr, frindex ); - DBGC ( ehci, "EHCI %s ctrlds %08x period %08x asyncl %08x cfgflg " - "%08x\n", ehci->name, ctrldssegment, periodiclistbase, - asynclistaddr, configflag ); -} - -/****************************************************************************** - * * USB legacy support * ****************************************************************************** @@ -288,14 +233,6 @@ static void ehci_legacy_claim ( struct ehci_device *ehci, if ( ! legacy ) return; - /* Dump original SMI usage */ - pci_read_config_dword ( pci, ( legacy + EHCI_USBLEGSUP_CTLSTS ), - &ctlsts ); - if ( ctlsts ) { - DBGC ( ehci, "EHCI %s BIOS using SMIs: %08x\n", - ehci->name, ctlsts ); - } - /* Claim ownership */ pci_write_config_byte ( pci, ( legacy + EHCI_USBLEGSUP_OS ), EHCI_USBLEGSUP_OS_OWNED ); @@ -339,11 +276,9 @@ static void ehci_legacy_claim ( struct ehci_device *ehci, */ static void ehci_legacy_release ( struct ehci_device *ehci, struct pci_device *pci ) { - unsigned int legacy = ehci->legacy; - uint32_t ctlsts; /* Do nothing unless legacy support capability is present */ - if ( ! legacy ) + if ( ! ehci->legacy ) return; /* Do nothing if releasing ownership is prevented */ @@ -354,14 +289,8 @@ static void ehci_legacy_release ( struct ehci_device *ehci, } /* Release ownership */ - pci_write_config_byte ( pci, ( legacy + EHCI_USBLEGSUP_OS ), 0 ); + pci_write_config_byte ( pci, ( ehci->legacy + EHCI_USBLEGSUP_OS ), 0 ); DBGC ( ehci, "EHCI %s released ownership to BIOS\n", ehci->name ); - - /* Dump restored SMI usage */ - pci_read_config_dword ( pci, ( legacy + EHCI_USBLEGSUP_CTLSTS ), - &ctlsts ); - DBGC ( ehci, "EHCI %s BIOS reclaimed SMIs: %08x\n", - ehci->name, ctlsts ); } /****************************************************************************** @@ -674,8 +603,6 @@ static int ehci_enqueue ( struct ehci_device *ehci, struct ehci_ring *ring, /* Fail if any portion is unreachable */ for ( i = 0 ; i < count ; i++ ) { - if ( ! xfer[i].len ) - continue; phys = ( virt_to_phys ( xfer[i].data ) + xfer[i].len - 1 ); if ( ( phys > 0xffffffffUL ) && ( ! ehci->addr64 ) ) return -ENOTSUP; @@ -1041,10 +968,10 @@ static uint32_t ehci_endpoint_characteristics ( struct usb_endpoint *ep ) { chr |= EHCI_CHR_TOGGLE; /* Determine endpoint speed */ - if ( usb->speed == USB_SPEED_HIGH ) { + if ( usb->port->speed == USB_SPEED_HIGH ) { chr |= EHCI_CHR_EPS_HIGH; } else { - if ( usb->speed == USB_SPEED_FULL ) { + if ( usb->port->speed == USB_SPEED_FULL ) { chr |= EHCI_CHR_EPS_FULL; } else { chr |= EHCI_CHR_EPS_LOW; @@ -1292,75 +1219,40 @@ static int ehci_endpoint_message ( struct usb_endpoint *ep, } /** - * Calculate number of transfer descriptors - * - * @v len Length of data - * @v zlp Append a zero-length packet - * @ret count Number of transfer descriptors - */ -static unsigned int ehci_endpoint_count ( size_t len, int zlp ) { - unsigned int count; - - /* Split into 16kB transfers. A single transfer can handle up - * to 20kB if it happens to be page-aligned, or up to 16kB - * with arbitrary alignment. We simplify the code by assuming - * that we can fit only 16kB into each transfer. - */ - count = ( ( len + EHCI_MTU - 1 ) / EHCI_MTU ); - - /* Append a zero-length transfer if applicable */ - if ( zlp || ( count == 0 ) ) - count++; - - return count; -} - -/** * Enqueue stream transfer * * @v ep USB endpoint * @v iobuf I/O buffer - * @v zlp Append a zero-length packet + * @v terminate Terminate using a short packet * @ret rc Return status code */ static int ehci_endpoint_stream ( struct usb_endpoint *ep, - struct io_buffer *iobuf, int zlp ) { + struct io_buffer *iobuf, int terminate ) { struct ehci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep ); struct ehci_device *ehci = endpoint->ehci; - void *data = iobuf->data; - size_t len = iob_len ( iobuf ); - unsigned int count = ehci_endpoint_count ( len, zlp ); unsigned int input = ( ep->address & USB_DIR_IN ); - unsigned int flags = ( input ? EHCI_FL_PID_IN : EHCI_FL_PID_OUT ); - struct ehci_transfer xfers[count]; + struct ehci_transfer xfers[2]; struct ehci_transfer *xfer = xfers; - size_t xfer_len; - unsigned int i; + size_t len = iob_len ( iobuf ); int rc; - /* Create transfers */ - for ( i = 0 ; i < count ; i++ ) { - - /* Calculate transfer length */ - xfer_len = EHCI_MTU; - if ( xfer_len > len ) - xfer_len = len; - - /* Create transfer */ - xfer->data = data; - xfer->len = xfer_len; - xfer->flags = flags; - - /* Move to next transfer */ - data += xfer_len; - len -= xfer_len; + /* Create transfer */ + xfer->data = iobuf->data; + xfer->len = len; + xfer->flags = ( EHCI_FL_IOC | + ( input ? EHCI_FL_PID_IN : EHCI_FL_PID_OUT ) ); + xfer++; + if ( terminate && ( ( len & ( ep->mtu - 1 ) ) == 0 ) ) { + xfer->data = NULL; + xfer->len = 0; + assert ( ! input ); + xfer->flags = ( EHCI_FL_IOC | EHCI_FL_PID_OUT ); xfer++; } - xfer[-1].flags |= EHCI_FL_IOC; /* Enqueue transfer */ if ( ( rc = ehci_enqueue ( ehci, &endpoint->ring, iobuf, xfers, - count ) ) != 0 ) + ( xfer - xfers ) ) ) != 0 ) return rc; return 0; diff --git a/roms/ipxe/src/drivers/usb/uhci.c b/roms/ipxe/src/drivers/usb/uhci.c index 528c1be1d..b6bb92560 100644 --- a/roms/ipxe/src/drivers/usb/uhci.c +++ b/roms/ipxe/src/drivers/usb/uhci.c @@ -697,7 +697,7 @@ static int uhci_endpoint_open ( struct usb_endpoint *ep ) { goto err_ring_alloc; endpoint->ring.mtu = ep->mtu; endpoint->ring.flags = UHCI_FL_CERR_MAX; - if ( usb->speed < USB_SPEED_FULL ) + if ( usb->port->speed < USB_SPEED_FULL ) endpoint->ring.flags |= UHCI_FL_LS; endpoint->ring.control = ( UHCI_CONTROL_DEVICE ( usb->address ) | UHCI_CONTROL_ENDPOINT ( ep->address ) ); @@ -835,20 +835,22 @@ static int uhci_endpoint_message ( struct usb_endpoint *ep, * * @v ep USB endpoint * @v iobuf I/O buffer - * @v zlp Append a zero-length packet + * @v terminate Terminate using a short packet * @ret rc Return status code */ static int uhci_endpoint_stream ( struct usb_endpoint *ep, - struct io_buffer *iobuf, int zlp ) { + struct io_buffer *iobuf, int terminate ) { struct uhci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep ); struct uhci_ring *ring = &endpoint->ring; unsigned int count; size_t len; int input; + int zlp; int rc; /* Calculate number of descriptors */ len = iob_len ( iobuf ); + zlp = ( terminate && ( ( len & ( ring->mtu - 1 ) ) == 0 ) ); count = ( ( ( len + ring->mtu - 1 ) / ring->mtu ) + ( zlp ? 1 : 0 ) ); /* Enqueue transfer */ diff --git a/roms/ipxe/src/drivers/usb/usbhub.c b/roms/ipxe/src/drivers/usb/usbhub.c index 47914bcdb..bf2a20005 100644 --- a/roms/ipxe/src/drivers/usb/usbhub.c +++ b/roms/ipxe/src/drivers/usb/usbhub.c @@ -155,10 +155,6 @@ static int hub_open ( struct usb_hub *hub ) { /* Refill interrupt ring */ hub_refill ( hubdev ); - /* Delay to allow ports to stabilise on out-of-spec hubs */ - if ( hubdev->flags & USB_HUB_SLOW_START ) - mdelay ( USB_HUB_SLOW_START_DELAY_MS ); - return 0; usb_endpoint_close ( &hubdev->intr ); @@ -414,9 +410,8 @@ static int hub_probe ( struct usb_function *func, hubdev->usb = usb; hubdev->features = ( enhanced ? USB_HUB_FEATURES_ENHANCED : USB_HUB_FEATURES ); - hubdev->flags = func->id->driver_data; usb_endpoint_init ( &hubdev->intr, usb, &usb_hub_intr_operations ); - usb_refill_init ( &hubdev->intr, 0, 0, USB_HUB_INTR_FILL ); + usb_refill_init ( &hubdev->intr, 0, USB_HUB_INTR_FILL ); process_init_stopped ( &hubdev->refill, &hub_refill_desc, NULL ); /* Locate hub interface descriptor */ @@ -501,10 +496,9 @@ static void hub_remove ( struct usb_function *func ) { unsigned int i; /* If hub has been unplugged, mark all ports as unplugged */ - if ( usb->port->disconnected ) { + if ( usb->port->speed == USB_SPEED_NONE ) { for ( i = 1 ; i <= hub->ports ; i++ ) { port = usb_port ( hub, i ); - port->disconnected = 1; port->speed = USB_SPEED_NONE; } } @@ -523,15 +517,24 @@ static void hub_remove ( struct usb_function *func ) { /** USB hub device IDs */ static struct usb_device_id hub_ids[] = { { - .name = "avocent-hub", - .vendor = 0x0624, - .product = 0x0248, - .driver_data = USB_HUB_SLOW_START, + .name = "hub-1", + .vendor = USB_ANY_ID, + .product = USB_ANY_ID, + .class = { + .class = USB_CLASS_HUB, + .subclass = 0, + .protocol = 0, + }, }, { - .name = "hub", + .name = "hub-2", .vendor = USB_ANY_ID, .product = USB_ANY_ID, + .class = { + .class = USB_CLASS_HUB, + .subclass = 0, + .protocol = 1, + }, }, }; @@ -539,8 +542,6 @@ static struct usb_device_id hub_ids[] = { struct usb_driver usb_hub_driver __usb_driver = { .ids = hub_ids, .id_count = ( sizeof ( hub_ids ) / sizeof ( hub_ids[0] ) ), - .class = USB_CLASS_ID ( USB_CLASS_HUB, 0, USB_ANY_ID ), - .score = USB_SCORE_NORMAL, .probe = hub_probe, .remove = hub_remove, }; diff --git a/roms/ipxe/src/drivers/usb/usbhub.h b/roms/ipxe/src/drivers/usb/usbhub.h index a5f123acc..d7d8f9610 100644 --- a/roms/ipxe/src/drivers/usb/usbhub.h +++ b/roms/ipxe/src/drivers/usb/usbhub.h @@ -257,8 +257,6 @@ struct usb_hub_device { struct usb_hub *hub; /** Features */ unsigned int features; - /** Flags */ - unsigned int flags; /** Interrupt endpoint */ struct usb_endpoint intr; @@ -266,12 +264,6 @@ struct usb_hub_device { struct process refill; }; -/** Hub requires additional settling delay */ -#define USB_HUB_SLOW_START 0x0001 - -/** Additional setting delay for out-of-spec hubs */ -#define USB_HUB_SLOW_START_DELAY_MS 500 - /** Interrupt ring fill level * * This is a policy decision. diff --git a/roms/ipxe/src/drivers/usb/usbio.c b/roms/ipxe/src/drivers/usb/usbio.c deleted file mode 100644 index 153f39421..000000000 --- a/roms/ipxe/src/drivers/usb/usbio.c +++ /dev/null @@ -1,1717 +0,0 @@ -/* - * Copyright (C) 2015 Michael Brown <mbrown@fensystems.co.uk>. - * - * 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 (at your option) 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 <stdlib.h> -#include <string.h> -#include <errno.h> -#include <assert.h> -#include <ipxe/efi/efi.h> -#include <ipxe/efi/efi_driver.h> -#include <ipxe/efi/efi_utils.h> -#include <ipxe/efi/Protocol/UsbIo.h> -#include <ipxe/usb.h> -#include "usbio.h" - -/** @file - * - * EFI_USB_IO_PROTOCOL pseudo Host Controller Interface driver - * - * - * The EFI_USB_IO_PROTOCOL is an almost unbelievably poorly designed - * abstraction of a USB device. It would be just about forgivable for - * an API to support only synchronous operation for bulk OUT - * endpoints. It is imbecilic to support only synchronous operation - * for bulk IN endpoints. This apparently intern-designed API - * throttles a typical NIC down to 1.5% of its maximum throughput. - * That isn't a typo. It really is that slow. - * - * We can't even work around this stupidity by talking to the host - * controller abstraction directly, because an identical limitation - * exists in the EFI_USB2_HC_PROTOCOL. - * - * Unless you derive therapeutic value from watching download progress - * indicators lethargically creep through every single integer from 0 - * to 100, you should use iPXE's native USB host controller drivers - * instead. (Or just upgrade from UEFI to "legacy" BIOS, which will - * produce a similar speed increase.) - * - * - * For added excitement, the EFI_USB_IO_PROTOCOL makes the - * (demonstrably incorrect) assumption that a USB driver needs to - * attach to exactly one interface within a USB device, and provides a - * helper method to retrieve "the" interface descriptor. Since pretty - * much every USB network device requires binding to a pair of - * control+data interfaces, this aspect of EFI_USB_IO_PROTOCOL is of - * no use to us. - * - * We have our own existing code for reading USB descriptors, so we - * don't actually care that the UsbGetInterfaceDescriptor() method - * provided by EFI_USB_IO_PROTOCOL is useless for network devices. We - * can read the descriptors ourselves (via UsbControlTransfer()) and - * get all of the information we need this way. We can even work - * around the fact that EFI_USB_IO_PROTOCOL provides separate handles - * for each of the two interfaces comprising our network device. - * - * However, if we discover that we need to select an alternative - * device configuration (e.g. for devices exposing both RNDIS and - * ECM), then all hell breaks loose. EFI_USB_IO_PROTOCOL starts to - * panic because its cached interface and endpoint descriptors will no - * longer be valid. As mentioned above, the cached descriptors are - * useless for network devices anyway so we _really_ don't care about - * this, but EFI_USB_IO_PROTOCOL certainly cares. It prints out a - * manic warning message containing no fewer than six exclamation - * marks and then literally commits seppuku in the middle of the - * UsbControlTransfer() method by attempting to uninstall itself. - * Quite how the caller is supposed to react when asked to stop using - * the EFI_USB_IO_PROTOCOL instance while in the middle of an - * uninterruptible call to said instance is left as an exercise for - * the interested reader. - * - * There is no sensible way to work around this, so we just - * preemptively fail if asked to change the device configuration, on - * the basis that reporting a sarcastic error message is often - * preferable to jumping through a NULL pointer and crashing the - * system. - */ - -/* Disambiguate the various error causes */ -#define ENOTSUP_MORONIC_SPECIFICATION \ - __einfo_error ( EINFO_ENOTSUP_MORONIC_SPECIFICATION ) -#define EINFO_ENOTSUP_MORONIC_SPECIFICATION \ - __einfo_uniqify ( EINFO_ENOTSUP, 0x01, \ - "EFI_USB_IO_PROTOCOL was designed by morons" ) - -/****************************************************************************** - * - * Device model - * - ****************************************************************************** - */ - -/** - * Determine endpoint interface number - * - * @v usbio USB I/O device - * @v ep USB Endpoint - * @ret interface Interface number, or negative error - */ -static int usbio_interface ( struct usbio_device *usbio, - struct usb_endpoint *ep ) { - EFI_HANDLE handle = usbio->handle; - struct usb_device *usb = ep->usb; - struct usb_configuration_descriptor *config; - struct usb_interface_descriptor *interface; - struct usb_endpoint_descriptor *endpoint; - struct usb_function *func; - unsigned int i; - - /* The control endpoint is not part of a described interface */ - if ( ep->address == USB_EP0_ADDRESS ) - return 0; - - /* Iterate over all interface descriptors looking for a match */ - config = usbio->config; - for_each_config_descriptor ( interface, config ) { - - /* Skip non-interface descriptors */ - if ( interface->header.type != USB_INTERFACE_DESCRIPTOR ) - continue; - - /* Iterate over all endpoint descriptors looking for a match */ - for_each_interface_descriptor ( endpoint, config, interface ) { - - /* Skip non-endpoint descriptors */ - if ( endpoint->header.type != USB_ENDPOINT_DESCRIPTOR ) - continue; - - /* Check endpoint address */ - if ( endpoint->endpoint != ep->address ) - continue; - - /* Check interface belongs to this function */ - list_for_each_entry ( func, &usb->functions, list ) { - - /* Skip non-matching functions */ - if ( func->interface[0] != usbio->first ) - continue; - - /* Iterate over all interfaces for a match */ - for ( i = 0 ; i < func->desc.count ; i++ ) { - if ( interface->interface == - func->interface[i] ) - return interface->interface; - } - } - } - } - - DBGC ( usbio, "USBIO %s cannot find interface for %s", - efi_handle_name ( handle ), usb_endpoint_name ( ep ) ); - return -ENOENT; -} - -/** - * Open USB I/O interface - * - * @v usbio USB I/O device - * @v interface Interface number - * @ret rc Return status code - */ -static int usbio_open ( struct usbio_device *usbio, unsigned int interface ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - EFI_HANDLE handle = usbio->handle; - struct usbio_interface *intf = &usbio->interface[interface]; - EFI_DEVICE_PATH_PROTOCOL *path; - EFI_DEVICE_PATH_PROTOCOL *end; - USB_DEVICE_PATH *usbpath; - union { - void *interface; - EFI_USB_IO_PROTOCOL *io; - } u; - EFI_STATUS efirc; - int rc; - - /* Sanity check */ - assert ( interface < usbio->config->interfaces ); - - /* If interface is already open, just increment the usage count */ - if ( intf->count ) { - intf->count++; - return 0; - } - - /* Construct device path for this interface */ - path = usbio->path; - usbpath = usbio->usbpath; - usbpath->InterfaceNumber = interface; - end = efi_devpath_end ( path ); - - /* Locate handle for this endpoint's interface */ - if ( ( efirc = bs->LocateDevicePath ( &efi_usb_io_protocol_guid, &path, - &intf->handle ) ) != 0 ) { - rc = -EEFI ( efirc ); - DBGC ( usbio, "USBIO %s could not locate ", - efi_handle_name ( handle ) ); - DBGC ( usbio, "%s: %s\n", - efi_devpath_text ( usbio->path ), strerror ( rc ) ); - return rc; - } - - /* Check that expected path was located */ - if ( path != end ) { - DBGC ( usbio, "USBIO %s located incomplete ", - efi_handle_name ( handle ) ); - DBGC ( usbio, "%s\n", efi_handle_name ( intf->handle ) ); - return -EXDEV; - } - - /* Open USB I/O protocol on this handle */ - if ( ( efirc = bs->OpenProtocol ( intf->handle, - &efi_usb_io_protocol_guid, - &u.interface, efi_image_handle, - intf->handle, - ( EFI_OPEN_PROTOCOL_BY_DRIVER | - EFI_OPEN_PROTOCOL_EXCLUSIVE )))!=0){ - rc = -EEFI ( efirc ); - DBGC ( usbio, "USBIO %s cannot open ", - efi_handle_name ( handle ) ); - DBGC ( usbio, "%s: %s\n", - efi_handle_name ( intf->handle ), strerror ( rc ) ); - DBGC_EFI_OPENERS ( usbio, intf->handle, - &efi_usb_io_protocol_guid ); - return rc; - } - intf->io = u.io; - - /* Increment usage count */ - intf->count++; - - return 0; -} - -/** - * Close USB I/O interface - * - * @v usbio USB I/O device - * @v interface Interface number - */ -static void usbio_close ( struct usbio_device *usbio, unsigned int interface ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - struct usbio_interface *intf = &usbio->interface[interface]; - - /* Sanity checks */ - assert ( interface < usbio->config->interfaces ); - assert ( intf->count > 0 ); - - /* Decrement usage count */ - intf->count--; - - /* Do nothing if interface is still in use */ - if ( intf->count ) - return; - - /* Close USB I/O protocol */ - bs->CloseProtocol ( intf->handle, &efi_usb_io_protocol_guid, - efi_image_handle, intf->handle ); -} - -/****************************************************************************** - * - * Control endpoints - * - ****************************************************************************** - */ - -/** - * Open control endpoint - * - * @v endpoint Endpoint - * @ret rc Return status code - */ -static int usbio_control_open ( struct usbio_endpoint *endpoint __unused ) { - - /* Nothing to do */ - return 0; -} - -/** - * Close control endpoint - * - * @v endpoint Endpoint - */ -static void usbio_control_close ( struct usbio_endpoint *endpoint __unused ) { - - /* Nothing to do */ -} - -/** - * Poll control endpoint - * - * @v endpoint Endpoint - */ -static void usbio_control_poll ( struct usbio_endpoint *endpoint ) { - struct usbio_device *usbio = endpoint->usbio; - struct usb_endpoint *ep = endpoint->ep; - EFI_HANDLE handle = usbio->handle; - EFI_USB_IO_PROTOCOL *io; - union { - struct usb_setup_packet setup; - EFI_USB_DEVICE_REQUEST efi; - } *msg; - EFI_USB_DATA_DIRECTION direction; - struct io_buffer *iobuf; - unsigned int index; - unsigned int flags; - unsigned int recipient; - unsigned int interface; - uint16_t request; - void *data; - size_t len; - UINT32 status; - EFI_STATUS efirc; - int rc; - - /* Do nothing if ring is empty */ - if ( endpoint->cons == endpoint->prod ) - return; - - /* Consume next transfer */ - index = ( endpoint->cons++ % USBIO_RING_COUNT ); - iobuf = endpoint->iobuf[index]; - flags = endpoint->flags[index]; - - /* Sanity check */ - if ( ! ( flags & USBIO_MESSAGE ) ) { - DBGC ( usbio, "USBIO %s %s non-message transfer\n", - efi_handle_name ( handle ), usb_endpoint_name ( ep ) ); - rc = -ENOTSUP; - goto err_not_message; - } - - /* Construct transfer */ - assert ( iob_len ( iobuf ) >= sizeof ( *msg ) ); - msg = iobuf->data; - iob_pull ( iobuf, sizeof ( *msg ) ); - request = le16_to_cpu ( msg->setup.request ); - len = iob_len ( iobuf ); - if ( len ) { - data = iobuf->data; - direction = ( ( request & USB_DIR_IN ) ? - EfiUsbDataIn : EfiUsbDataOut ); - } else { - data = NULL; - direction = EfiUsbNoData; - } - - /* Determine interface for this transfer */ - recipient = ( request & USB_RECIP_MASK ); - if ( recipient == USB_RECIP_INTERFACE ) { - /* Recipient is an interface: use interface number directly */ - interface = le16_to_cpu ( msg->setup.index ); - } else { - /* Route all other requests through the first interface */ - interface = 0; - } - - /* Open interface */ - if ( ( rc = usbio_open ( usbio, interface ) ) != 0 ) - goto err_open; - io = usbio->interface[interface].io; - - /* Due to the design of EFI_USB_IO_PROTOCOL, attempting to set - * the configuration to a non-default value is basically a - * self-destruct button. - */ - if ( ( request == USB_SET_CONFIGURATION ) && - ( le16_to_cpu ( msg->setup.value ) != usbio->config->config ) ) { - rc = -ENOTSUP_MORONIC_SPECIFICATION; - DBGC ( usbio, "USBIO %s cannot change configuration: %s\n", - efi_handle_name ( handle ), strerror ( rc ) ); - goto err_moronic_specification; - } - - /* Submit transfer */ - if ( ( efirc = io->UsbControlTransfer ( io, &msg->efi, direction, 0, - data, len, &status ) ) != 0 ) { - rc = -EEFI ( efirc ); - DBGC ( usbio, "USBIO %s %s could not submit control transfer ", - efi_handle_name ( handle ), usb_endpoint_name ( ep ) ); - DBGC ( usbio, "via %s: %s (status %04x)\n", - efi_handle_name ( usbio->interface[interface].handle ), - strerror ( rc ), status ); - goto err_transfer; - } - - /* Close interface */ - usbio_close ( usbio, interface ); - - /* Complete transfer */ - usb_complete ( ep, iobuf ); - - return; - - err_transfer: - err_moronic_specification: - usbio_close ( usbio, interface ); - err_open: - err_not_message: - usb_complete_err ( ep, iobuf, rc ); -} - -/** Control endpoint operations */ -static struct usbio_operations usbio_control_operations = { - .open = usbio_control_open, - .close = usbio_control_close, - .poll = usbio_control_poll, -}; - -/****************************************************************************** - * - * Bulk IN endpoints - * - ****************************************************************************** - */ - -/** - * Open bulk IN endpoint - * - * @v endpoint Endpoint - * @ret rc Return status code - */ -static int usbio_bulk_in_open ( struct usbio_endpoint *endpoint __unused ) { - - /* Nothing to do */ - return 0; -} - -/** - * Close bulk IN endpoint - * - * @v endpoint Endpoint - */ -static void usbio_bulk_in_close ( struct usbio_endpoint *endpoint __unused ) { - - /* Nothing to do */ -} - -/** - * Poll bulk IN endpoint - * - * @v endpoint Endpoint - */ -static void usbio_bulk_in_poll ( struct usbio_endpoint *endpoint ) { - struct usbio_device *usbio = endpoint->usbio; - struct usb_endpoint *ep = endpoint->ep; - EFI_USB_IO_PROTOCOL *io = endpoint->io; - EFI_HANDLE handle = usbio->handle; - struct io_buffer *iobuf; - unsigned int index; - UINTN len; - UINT32 status; - EFI_STATUS efirc; - int rc; - - /* Do nothing if ring is empty */ - if ( endpoint->cons == endpoint->prod ) - return; - - /* Attempt (but do not yet consume) next transfer */ - index = ( endpoint->cons % USBIO_RING_COUNT ); - iobuf = endpoint->iobuf[index]; - - /* Construct transfer */ - len = iob_len ( iobuf ); - - /* Upon being turned on, the EFI_USB_IO_PROTOCOL did nothing - * for several minutes before firing a small ARP packet a few - * millimetres into the ether. - */ - efirc = io->UsbBulkTransfer ( io, ep->address, iobuf->data, - &len, 1, &status ); - if ( efirc == EFI_TIMEOUT ) - return; - - /* Consume transfer */ - endpoint->cons++; - - /* Check for failure */ - if ( efirc != 0 ) { - rc = -EEFI ( efirc ); - DBGC2 ( usbio, "USBIO %s %s could not submit bulk IN transfer: " - "%s (status %04x)\n", efi_handle_name ( handle ), - usb_endpoint_name ( ep ), strerror ( rc ), status ); - usb_complete_err ( ep, iobuf, rc ); - return; - } - - /* Update length */ - iob_put ( iobuf, ( len - iob_len ( iobuf ) ) ); - - /* Complete transfer */ - usb_complete ( ep, iobuf ); -} - -/** Bulk endpoint operations */ -static struct usbio_operations usbio_bulk_in_operations = { - .open = usbio_bulk_in_open, - .close = usbio_bulk_in_close, - .poll = usbio_bulk_in_poll, -}; - -/****************************************************************************** - * - * Bulk OUT endpoints - * - ****************************************************************************** - */ - -/** - * Open bulk OUT endpoint - * - * @v endpoint Endpoint - * @ret rc Return status code - */ -static int usbio_bulk_out_open ( struct usbio_endpoint *endpoint __unused ) { - - /* Nothing to do */ - return 0; -} - -/** - * Close bulk OUT endpoint - * - * @v endpoint Endpoint - */ -static void usbio_bulk_out_close ( struct usbio_endpoint *endpoint __unused ) { - - /* Nothing to do */ -} - -/** - * Poll bulk OUT endpoint - * - * @v endpoint Endpoint - */ -static void usbio_bulk_out_poll ( struct usbio_endpoint *endpoint ) { - struct usbio_device *usbio = endpoint->usbio; - struct usb_endpoint *ep = endpoint->ep; - EFI_USB_IO_PROTOCOL *io = endpoint->io; - EFI_HANDLE handle = usbio->handle; - struct io_buffer *iobuf; - unsigned int index; - unsigned int flags; - UINTN len; - UINT32 status; - EFI_STATUS efirc; - int rc; - - /* Do nothing if ring is empty */ - if ( endpoint->cons == endpoint->prod ) - return; - - /* Consume next transfer */ - index = ( endpoint->cons++ % USBIO_RING_COUNT ); - iobuf = endpoint->iobuf[index]; - flags = endpoint->flags[index]; - - /* Construct transfer */ - len = iob_len ( iobuf ); - - /* Submit transfer */ - if ( ( efirc = io->UsbBulkTransfer ( io, ep->address, iobuf->data, - &len, 0, &status ) ) != 0 ) { - rc = -EEFI ( efirc ); - DBGC ( usbio, "USBIO %s %s could not submit bulk OUT transfer: " - "%s (status %04x)\n", efi_handle_name ( handle ), - usb_endpoint_name ( ep ), strerror ( rc ), status ); - goto err; - } - - /* Update length */ - iob_put ( iobuf, ( len - iob_len ( iobuf ) ) ); - - /* Submit zero-length transfer if required */ - len = 0; - if ( ( flags & USBIO_ZLEN ) && - ( efirc = io->UsbBulkTransfer ( io, ep->address, NULL, &len, 0, - &status ) ) != 0 ) { - rc = -EEFI ( efirc ); - DBGC ( usbio, "USBIO %s %s could not submit zero-length " - "transfer: %s (status %04x)\n", - efi_handle_name ( handle ), usb_endpoint_name ( ep ), - strerror ( rc ), status ); - goto err; - } - - /* Complete transfer */ - usb_complete ( ep, iobuf ); - - return; - - err: - usb_complete_err ( ep, iobuf, rc ); -} - -/** Bulk endpoint operations */ -static struct usbio_operations usbio_bulk_out_operations = { - .open = usbio_bulk_out_open, - .close = usbio_bulk_out_close, - .poll = usbio_bulk_out_poll, -}; - -/****************************************************************************** - * - * Interrupt endpoints - * - ****************************************************************************** - * - * The EFI_USB_IO_PROTOCOL provides two ways to interact with - * interrupt endpoints, neither of which naturally model the hardware - * interaction. The UsbSyncInterruptTransfer() method allows imposes - * a 1ms overhead for every interrupt transfer (which could result in - * up to a 50% decrease in overall throughput for the device). The - * UsbAsyncInterruptTransfer() method provides no way for us to - * prevent transfers when no I/O buffers are available. - * - * We work around this design by utilising a small, fixed ring buffer - * into which the interrupt callback delivers the data. This aims to - * provide buffer space even if no I/O buffers have yet been enqueued. - * The scheme is not guaranteed since the fixed ring buffer may also - * become full. However: - * - * - devices which send a constant stream of interrupts (and which - * therefore might exhaust the fixed ring buffer) tend to be - * responding to every interrupt request, and can tolerate lost - * packets, and - * - * - devices which cannot tolerate lost interrupt packets tend to send - * only a few small messages. - * - * The scheme should therefore work in practice. - */ - -/** - * Interrupt endpoint callback - * - * @v data Received data - * @v len Length of received data - * @v context Callback context - * @v status Transfer status - * @ret efirc EFI status code - */ -static EFI_STATUS EFIAPI usbio_interrupt_callback ( VOID *data, UINTN len, - VOID *context, - UINT32 status ) { - struct usbio_interrupt_ring *intr = context; - struct usbio_endpoint *endpoint = intr->endpoint; - struct usbio_device *usbio = endpoint->usbio; - struct usb_endpoint *ep = endpoint->ep; - EFI_HANDLE handle = usbio->handle; - unsigned int fill; - unsigned int index; - - /* Sanity check */ - assert ( len <= ep->mtu ); - - /* Do nothing if ring is empty */ - fill = ( intr->prod - intr->cons ); - if ( fill >= USBIO_INTR_COUNT ) { - DBGC ( usbio, "USBIO %s %s dropped interrupt completion\n", - efi_handle_name ( handle ), usb_endpoint_name ( ep ) ); - return 0; - } - - /* Do nothing if transfer was unsuccessful */ - if ( status != 0 ) { - DBGC ( usbio, "USBIO %s %s interrupt completion status %04x\n", - efi_handle_name ( handle ), usb_endpoint_name ( ep ), - status ); - return 0; /* Unclear what failure actually means here */ - } - - /* Copy data to buffer and increment producer counter */ - index = ( intr->prod % USBIO_INTR_COUNT ); - memcpy ( intr->data[index], data, len ); - intr->len[index] = len; - intr->prod++; - - return 0; -} - -/** - * Open interrupt endpoint - * - * @v endpoint Endpoint - * @ret rc Return status code - */ -static int usbio_interrupt_open ( struct usbio_endpoint *endpoint ) { - struct usbio_device *usbio = endpoint->usbio; - struct usbio_interrupt_ring *intr; - struct usb_endpoint *ep = endpoint->ep; - EFI_USB_IO_PROTOCOL *io = endpoint->io; - EFI_HANDLE handle = usbio->handle; - unsigned int interval; - unsigned int i; - void *data; - EFI_STATUS efirc; - int rc; - - /* Allocate interrupt ring buffer */ - intr = zalloc ( sizeof ( *intr ) + ( USBIO_INTR_COUNT * ep->mtu ) ); - if ( ! intr ) { - rc = -ENOMEM; - goto err_alloc; - } - endpoint->intr = intr; - intr->endpoint = endpoint; - data = ( ( ( void * ) intr ) + sizeof ( *intr ) ); - for ( i = 0 ; i < USBIO_INTR_COUNT ; i++ ) { - intr->data[i] = data; - data += ep->mtu; - } - - /* Determine polling interval */ - interval = ( ep->interval >> 3 /* microframes -> milliseconds */ ); - if ( ! interval ) - interval = 1; /* May not be zero */ - - /* Add to periodic schedule */ - if ( ( efirc = io->UsbAsyncInterruptTransfer ( io, ep->address, TRUE, - interval, ep->mtu, - usbio_interrupt_callback, - intr ) ) != 0 ) { - rc = -EEFI ( efirc ); - DBGC ( usbio, "USBIO %s %s could not schedule interrupt " - "transfer: %s\n", efi_handle_name ( handle ), - usb_endpoint_name ( ep ), strerror ( rc ) ); - goto err_schedule; - } - - return 0; - - io->UsbAsyncInterruptTransfer ( io, ep->address, FALSE, 0, 0, - NULL, NULL ); - err_schedule: - free ( intr ); - err_alloc: - return rc; -} - -/** - * Close interrupt endpoint - * - * @v endpoint Endpoint - */ -static void usbio_interrupt_close ( struct usbio_endpoint *endpoint ) { - struct usb_endpoint *ep = endpoint->ep; - EFI_USB_IO_PROTOCOL *io = endpoint->io; - - /* Remove from periodic schedule */ - io->UsbAsyncInterruptTransfer ( io, ep->address, FALSE, 0, 0, - NULL, NULL ); - - /* Free interrupt ring buffer */ - free ( endpoint->intr ); -} - -/** - * Poll interrupt endpoint - * - * @v endpoint Endpoint - */ -static void usbio_interrupt_poll ( struct usbio_endpoint *endpoint ) { - struct usbio_interrupt_ring *intr = endpoint->intr; - struct usb_endpoint *ep = endpoint->ep; - struct io_buffer *iobuf; - unsigned int index; - unsigned int intr_index; - size_t len; - - /* Do nothing if ring is empty */ - if ( endpoint->cons == endpoint->prod ) - return; - - /* Do nothing if interrupt ring is empty */ - if ( intr->cons == intr->prod ) - return; - - /* Consume next transfer */ - index = ( endpoint->cons++ % USBIO_RING_COUNT ); - iobuf = endpoint->iobuf[index]; - - /* Populate I/O buffer */ - intr_index = ( intr->cons++ % USBIO_INTR_COUNT ); - len = intr->len[intr_index]; - assert ( len <= iob_len ( iobuf ) ); - iob_put ( iobuf, ( len - iob_len ( iobuf ) ) ); - memcpy ( iobuf->data, intr->data[intr_index], len ); - - /* Complete transfer */ - usb_complete ( ep, iobuf ); -} - -/** Interrupt endpoint operations */ -static struct usbio_operations usbio_interrupt_operations = { - .open = usbio_interrupt_open, - .close = usbio_interrupt_close, - .poll = usbio_interrupt_poll, -}; - -/****************************************************************************** - * - * Endpoint operations - * - ****************************************************************************** - */ - -/** - * Open endpoint - * - * @v ep USB endpoint - * @ret rc Return status code - */ -static int usbio_endpoint_open ( struct usb_endpoint *ep ) { - struct usb_bus *bus = ep->usb->port->hub->bus; - struct usbio_device *usbio = usb_bus_get_hostdata ( bus ); - struct usbio_endpoint *endpoint; - EFI_HANDLE handle = usbio->handle; - unsigned int attr = ( ep->attributes & USB_ENDPOINT_ATTR_TYPE_MASK ); - int interface; - int rc; - - /* Allocate and initialise structure */ - endpoint = zalloc ( sizeof ( *endpoint ) ); - if ( ! endpoint ) { - rc = -ENOMEM; - goto err_alloc; - } - usb_endpoint_set_hostdata ( ep, endpoint ); - endpoint->usbio = usbio; - endpoint->ep = ep; - - /* Identify endpoint operations */ - if ( attr == USB_ENDPOINT_ATTR_CONTROL ) { - endpoint->op = &usbio_control_operations; - } else if ( attr == USB_ENDPOINT_ATTR_BULK ) { - endpoint->op = ( ( ep->address & USB_DIR_IN ) ? - &usbio_bulk_in_operations : - &usbio_bulk_out_operations ); - } else if ( attr == USB_ENDPOINT_ATTR_INTERRUPT ) { - endpoint->op = &usbio_interrupt_operations; - } else { - rc = -ENOTSUP; - goto err_operations; - } - - /* Identify interface for this endpoint */ - interface = usbio_interface ( usbio, ep ); - if ( interface < 0 ) { - rc = interface; - goto err_interface; - } - endpoint->interface = interface; - - /* Open interface */ - if ( ( rc = usbio_open ( usbio, interface ) ) != 0 ) - goto err_open_interface; - endpoint->handle = usbio->interface[interface].handle; - endpoint->io = usbio->interface[interface].io; - DBGC ( usbio, "USBIO %s %s using ", - efi_handle_name ( handle ), usb_endpoint_name ( ep ) ); - DBGC ( usbio, "%s\n", efi_handle_name ( endpoint->handle ) ); - - /* Open endpoint */ - if ( ( rc = endpoint->op->open ( endpoint ) ) != 0 ) - goto err_open_endpoint; - - /* Add to list of endpoints */ - list_add_tail ( &endpoint->list, &usbio->endpoints ); - - return 0; - - list_del ( &endpoint->list ); - endpoint->op->close ( endpoint ); - err_open_endpoint: - usbio_close ( usbio, interface ); - err_open_interface: - err_interface: - err_operations: - free ( endpoint ); - err_alloc: - return rc; -} - -/** - * Close endpoint - * - * @v ep USB endpoint - */ -static void usbio_endpoint_close ( struct usb_endpoint *ep ) { - struct usbio_endpoint *endpoint = usb_endpoint_get_hostdata ( ep ); - struct usbio_device *usbio = endpoint->usbio; - struct io_buffer *iobuf; - unsigned int index; - - /* Remove from list of endpoints */ - list_del ( &endpoint->list ); - - /* Close endpoint */ - endpoint->op->close ( endpoint ); - - /* Close interface */ - usbio_close ( usbio, endpoint->interface ); - - /* Cancel any incomplete transfers */ - while ( endpoint->cons != endpoint->prod ) { - index = ( endpoint->cons++ % USBIO_RING_COUNT ); - iobuf = endpoint->iobuf[index]; - usb_complete_err ( ep, iobuf, -ECANCELED ); - } - - /* Free endpoint */ - free ( endpoint ); -} - -/** - * Reset endpoint - * - * @v ep USB endpoint - * @ret rc Return status code - */ -static int usbio_endpoint_reset ( struct usb_endpoint *ep __unused ) { - - /* Nothing to do */ - return 0; -} - -/** - * Update MTU - * - * @v ep USB endpoint - * @ret rc Return status code - */ -static int usbio_endpoint_mtu ( struct usb_endpoint *ep __unused ) { - - /* Nothing to do */ - return 0; -} - -/** - * Enqueue transfer - * - * @v ep USB endpoint - * @v iobuf I/O buffer - * @v flags Transfer flags - * @ret rc Return status code - */ -static int usbio_endpoint_enqueue ( struct usb_endpoint *ep, - struct io_buffer *iobuf, - unsigned int flags ) { - struct usbio_endpoint *endpoint = usb_endpoint_get_hostdata ( ep ); - unsigned int fill; - unsigned int index; - - /* Fail if transfer ring is full */ - fill = ( endpoint->prod - endpoint->cons ); - if ( fill >= USBIO_RING_COUNT ) - return -ENOBUFS; - - /* Add to ring */ - index = ( endpoint->prod++ % USBIO_RING_COUNT ); - endpoint->iobuf[index] = iobuf; - endpoint->flags[index] = flags; - - return 0; -} - -/** - * Enqueue message transfer - * - * @v ep USB endpoint - * @v iobuf I/O buffer - * @ret rc Return status code - */ -static int usbio_endpoint_message ( struct usb_endpoint *ep, - struct io_buffer *iobuf ) { - - /* Enqueue transfer */ - return usbio_endpoint_enqueue ( ep, iobuf, USBIO_MESSAGE ); -} - -/** - * Enqueue stream transfer - * - * @v ep USB endpoint - * @v iobuf I/O buffer - * @v zlp Append a zero-length packet - * @ret rc Return status code - */ -static int usbio_endpoint_stream ( struct usb_endpoint *ep, - struct io_buffer *iobuf, int zlp ) { - - /* Enqueue transfer */ - return usbio_endpoint_enqueue ( ep, iobuf, ( zlp ? USBIO_ZLEN : 0 ) ); -} - -/** - * Poll for completions - * - * @v endpoint Endpoint - */ -static void usbio_endpoint_poll ( struct usbio_endpoint *endpoint ) { - - /* Poll endpoint */ - endpoint->op->poll ( endpoint ); -} - -/****************************************************************************** - * - * Device operations - * - ****************************************************************************** - */ - -/** - * Open device - * - * @v usb USB device - * @ret rc Return status code - */ -static int usbio_device_open ( struct usb_device *usb ) { - struct usbio_device *usbio = - usb_bus_get_hostdata ( usb->port->hub->bus ); - - usb_set_hostdata ( usb, usbio ); - return 0; -} - -/** - * Close device - * - * @v usb USB device - */ -static void usbio_device_close ( struct usb_device *usb __unused ) { - - /* Nothing to do */ -} - -/** - * Assign device address - * - * @v usb USB device - * @ret rc Return status code - */ -static int usbio_device_address ( struct usb_device *usb __unused ) { - - /* Nothing to do */ - return 0; -} - -/****************************************************************************** - * - * Hub operations - * - ****************************************************************************** - */ - -/** - * Open hub - * - * @v hub USB hub - * @ret rc Return status code - */ -static int usbio_hub_open ( struct usb_hub *hub ) { - - /* Disallow non-root hubs */ - if ( hub->usb ) - return -ENOTSUP; - - /* Nothing to do */ - return 0; -} - -/** - * Close hub - * - * @v hub USB hub - */ -static void usbio_hub_close ( struct usb_hub *hub __unused ) { - - /* Nothing to do */ -} - -/****************************************************************************** - * - * Root hub operations - * - ****************************************************************************** - */ - -/** - * Open root hub - * - * @v hub USB hub - * @ret rc Return status code - */ -static int usbio_root_open ( struct usb_hub *hub __unused ) { - - /* Nothing to do */ - return 0; -} - -/** - * Close root hub - * - * @v hub USB hub - */ -static void usbio_root_close ( struct usb_hub *hub __unused ) { - - /* Nothing to do */ -} - -/** - * Enable port - * - * @v hub USB hub - * @v port USB port - * @ret rc Return status code - */ -static int usbio_root_enable ( struct usb_hub *hub __unused, - struct usb_port *port __unused ) { - - /* Nothing to do */ - return 0; -} - -/** - * Disable port - * - * @v hub USB hub - * @v port USB port - * @ret rc Return status code - */ -static int usbio_root_disable ( struct usb_hub *hub __unused, - struct usb_port *port __unused ) { - - /* Nothing to do */ - return 0; -} - -/** - * Update root hub port speed - * - * @v hub USB hub - * @v port USB port - * @ret rc Return status code - */ -static int usbio_root_speed ( struct usb_hub *hub __unused, - struct usb_port *port ) { - - /* Not actually exposed via EFI_USB_IO_PROTOCOL */ - port->speed = USB_SPEED_HIGH; - return 0; -} - -/** - * Clear transaction translator buffer - * - * @v hub USB hub - * @v port USB port - * @v ep USB endpoint - * @ret rc Return status code - */ -static int usbio_root_clear_tt ( struct usb_hub *hub __unused, - struct usb_port *port __unused, - struct usb_endpoint *ep __unused ) { - - /* Should never be called; this is a root hub */ - return -ENOTSUP; -} - -/****************************************************************************** - * - * Bus operations - * - ****************************************************************************** - */ - -/** - * Open USB bus - * - * @v bus USB bus - * @ret rc Return status code - */ -static int usbio_bus_open ( struct usb_bus *bus __unused ) { - - /* Nothing to do */ - return 0; -} - -/** - * Close USB bus - * - * @v bus USB bus - */ -static void usbio_bus_close ( struct usb_bus *bus __unused ) { - - /* Nothing to do */ -} - -/** - * Poll USB bus - * - * @v bus USB bus - */ -static void usbio_bus_poll ( struct usb_bus *bus ) { - struct usbio_device *usbio = usb_bus_get_hostdata ( bus ); - struct usbio_endpoint *endpoint; - - /* Poll all endpoints. We trust that completion handlers are - * minimal and will not do anything that could plausibly - * affect the endpoint list itself. - */ - list_for_each_entry ( endpoint, &usbio->endpoints, list ) - usbio_endpoint_poll ( endpoint ); -} - -/****************************************************************************** - * - * EFI driver interface - * - ****************************************************************************** - */ - -/** USB I/O host controller driver operations */ -static struct usb_host_operations usbio_operations = { - .endpoint = { - .open = usbio_endpoint_open, - .close = usbio_endpoint_close, - .reset = usbio_endpoint_reset, - .mtu = usbio_endpoint_mtu, - .message = usbio_endpoint_message, - .stream = usbio_endpoint_stream, - }, - .device = { - .open = usbio_device_open, - .close = usbio_device_close, - .address = usbio_device_address, - }, - .bus = { - .open = usbio_bus_open, - .close = usbio_bus_close, - .poll = usbio_bus_poll, - }, - .hub = { - .open = usbio_hub_open, - .close = usbio_hub_close, - }, - .root = { - .open = usbio_root_open, - .close = usbio_root_close, - .enable = usbio_root_enable, - .disable = usbio_root_disable, - .speed = usbio_root_speed, - .clear_tt = usbio_root_clear_tt, - }, -}; - -/** - * Check to see if driver supports a device - * - * @v handle EFI device handle - * @ret rc Return status code - */ -static int usbio_supported ( EFI_HANDLE handle ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - EFI_USB_DEVICE_DESCRIPTOR device; - EFI_USB_INTERFACE_DESCRIPTOR interface; - struct usb_function_descriptor desc; - struct usb_driver *driver; - struct usb_device_id *id; - union { - void *interface; - EFI_USB_IO_PROTOCOL *io; - } usb; - EFI_STATUS efirc; - int rc; - - /* Get protocol */ - if ( ( efirc = bs->OpenProtocol ( handle, &efi_usb_io_protocol_guid, - &usb.interface, efi_image_handle, - handle, - EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){ - rc = -EEFI ( efirc ); - DBGCP ( handle, "USB %s is not a USB device\n", - efi_handle_name ( handle ) ); - goto err_open_protocol; - } - - /* Get device descriptor */ - if ( ( efirc = usb.io->UsbGetDeviceDescriptor ( usb.io, - &device ) ) != 0 ) { - rc = -EEFI ( efirc ); - DBGC ( handle, "USB %s could not get device descriptor: " - "%s\n", efi_handle_name ( handle ), strerror ( rc ) ); - goto err_get_device_descriptor; - } - memset ( &desc, 0, sizeof ( desc ) ); - desc.vendor = device.IdVendor; - desc.product = device.IdProduct; - - /* Get interface descriptor */ - if ( ( efirc = usb.io->UsbGetInterfaceDescriptor ( usb.io, - &interface ) ) !=0){ - rc = -EEFI ( efirc ); - DBGC ( handle, "USB %s could not get interface descriptor: " - "%s\n", efi_handle_name ( handle ), strerror ( rc ) ); - goto err_get_interface_descriptor; - } - desc.class.class.class = interface.InterfaceClass; - desc.class.class.subclass = interface.InterfaceSubClass; - desc.class.class.protocol = interface.InterfaceProtocol; - - /* Look for a driver for this interface */ - driver = usb_find_driver ( &desc, &id ); - if ( ! driver ) { - rc = -ENOTSUP; - goto err_unsupported; - } - - /* Success */ - rc = 0; - - err_unsupported: - err_get_interface_descriptor: - err_get_device_descriptor: - bs->CloseProtocol ( handle, &efi_usb_io_protocol_guid, - efi_image_handle, handle ); - err_open_protocol: - return rc; -} - -/** - * Fetch configuration descriptor - * - * @v usbio USB I/O device - * @ret rc Return status code - */ -static int usbio_config ( struct usbio_device *usbio ) { - EFI_HANDLE handle = usbio->handle; - EFI_USB_IO_PROTOCOL *io = usbio->io; - EFI_USB_DEVICE_DESCRIPTOR device; - EFI_USB_CONFIG_DESCRIPTOR partial; - union { - struct usb_setup_packet setup; - EFI_USB_DEVICE_REQUEST efi; - } msg; - UINT32 status; - size_t len; - unsigned int count; - unsigned int value; - unsigned int i; - EFI_STATUS efirc; - int rc; - - /* Get device descriptor */ - if ( ( efirc = io->UsbGetDeviceDescriptor ( io, &device ) ) != 0 ) { - rc = -EEFI ( efirc ); - DBGC ( usbio, "USB %s could not get device descriptor: " - "%s\n", efi_handle_name ( handle ), strerror ( rc ) ); - goto err_get_device_descriptor; - } - count = device.NumConfigurations; - - /* Get current partial configuration descriptor */ - if ( ( efirc = io->UsbGetConfigDescriptor ( io, &partial ) ) != 0 ) { - rc = -EEFI ( efirc ); - DBGC ( usbio, "USB %s could not get partial configuration " - "descriptor: %s\n", efi_handle_name ( handle ), - strerror ( rc ) ); - goto err_get_configuration_descriptor; - } - len = le16_to_cpu ( partial.TotalLength ); - - /* Allocate configuration descriptor */ - usbio->config = malloc ( len ); - if ( ! usbio->config ) { - rc = -ENOMEM; - goto err_alloc; - } - - /* There is, naturally, no way to retrieve the entire device - * configuration descriptor via EFI_USB_IO_PROTOCOL. Worse, - * there is no way to even retrieve the index of the current - * configuration descriptor. We have to iterate over all - * possible configuration descriptors looking for the - * descriptor that matches the current configuration value. - */ - for ( i = 0 ; i < count ; i++ ) { - - /* Construct request */ - msg.setup.request = cpu_to_le16 ( USB_GET_DESCRIPTOR ); - value = ( ( USB_CONFIGURATION_DESCRIPTOR << 8 ) | i ); - msg.setup.value = cpu_to_le16 ( value ); - msg.setup.index = 0; - msg.setup.len = cpu_to_le16 ( len ); - - /* Get full configuration descriptor */ - if ( ( efirc = io->UsbControlTransfer ( io, &msg.efi, - EfiUsbDataIn, 0, - usbio->config, len, - &status ) ) != 0 ) { - rc = -EEFI ( efirc ); - DBGC ( usbio, "USB %s could not get configuration %d " - "descriptor: %s\n", efi_handle_name ( handle ), - i, strerror ( rc ) ); - goto err_control_transfer; - } - - /* Ignore unless this is the current configuration */ - if ( usbio->config->config != partial.ConfigurationValue ) - continue; - - /* Check length */ - if ( le16_to_cpu ( usbio->config->len ) != len ) { - DBGC ( usbio, "USB %s configuration descriptor length " - "mismatch\n", efi_handle_name ( handle ) ); - rc = -EINVAL; - goto err_len; - } - - return 0; - } - - /* No match found */ - DBGC ( usbio, "USB %s could not find current configuration " - "descriptor\n", efi_handle_name ( handle ) ); - rc = -ENOENT; - - err_len: - err_control_transfer: - free ( usbio->config ); - err_alloc: - err_get_configuration_descriptor: - err_get_device_descriptor: - return rc; -} - -/** - * Construct device path for opening other interfaces - * - * @v usbio USB I/O device - * @ret rc Return status code - */ -static int usbio_path ( struct usbio_device *usbio ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - EFI_HANDLE handle = usbio->handle; - EFI_DEVICE_PATH_PROTOCOL *path; - EFI_DEVICE_PATH_PROTOCOL *end; - USB_DEVICE_PATH *usbpath; - union { - void *interface; - EFI_DEVICE_PATH_PROTOCOL *path; - } u; - size_t len; - EFI_STATUS efirc; - int rc; - - /* Open device path protocol */ - if ( ( efirc = bs->OpenProtocol ( handle, - &efi_device_path_protocol_guid, - &u.interface, efi_image_handle, - handle, - EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){ - rc = -EEFI ( efirc ); - DBGC ( usbio, "USBIO %s cannot open device path protocol: " - "%s\n", efi_handle_name ( handle ), strerror ( rc ) ); - goto err_open_protocol; - } - path = u.interface; - - /* Locate end of device path and sanity check */ - len = efi_devpath_len ( path ); - if ( len < sizeof ( *usbpath ) ) { - DBGC ( usbio, "USBIO %s underlength device path\n", - efi_handle_name ( handle ) ); - rc = -EINVAL; - goto err_underlength; - } - usbpath = ( ( ( void * ) path ) + len - sizeof ( *usbpath ) ); - if ( ! ( ( usbpath->Header.Type == MESSAGING_DEVICE_PATH ) && - ( usbpath->Header.SubType == MSG_USB_DP ) ) ) { - DBGC ( usbio, "USBIO %s not a USB device path: ", - efi_handle_name ( handle ) ); - DBGC ( usbio, "%s\n", efi_devpath_text ( path ) ); - rc = -EINVAL; - goto err_non_usb; - } - - /* Allocate copy of device path */ - usbio->path = malloc ( len + sizeof ( *end ) ); - if ( ! usbio->path ) { - rc = -ENOMEM; - goto err_alloc; - } - memcpy ( usbio->path, path, ( len + sizeof ( *end ) ) ); - usbio->usbpath = ( ( ( void * ) usbio->path ) + len - - sizeof ( *usbpath ) ); - - /* Close protocol */ - bs->CloseProtocol ( handle, &efi_device_path_protocol_guid, - efi_image_handle, handle ); - - return 0; - - free ( usbio->path ); - err_alloc: - err_non_usb: - err_underlength: - bs->CloseProtocol ( handle, &efi_device_path_protocol_guid, - efi_image_handle, handle ); - err_open_protocol: - return rc; -} - -/** - * Construct interface list - * - * @v usbio USB I/O device - * @ret rc Return status code - */ -static int usbio_interfaces ( struct usbio_device *usbio ) { - EFI_HANDLE handle = usbio->handle; - EFI_USB_IO_PROTOCOL *io = usbio->io; - EFI_USB_INTERFACE_DESCRIPTOR interface; - unsigned int first; - unsigned int count; - EFI_STATUS efirc; - int rc; - - /* Get interface descriptor */ - if ( ( efirc = io->UsbGetInterfaceDescriptor ( io, &interface ) ) != 0){ - rc = -EEFI ( efirc ); - DBGC ( usbio, "USB %s could not get interface descriptor: " - "%s\n", efi_handle_name ( handle ), strerror ( rc ) ); - goto err_get_interface_descriptor; - } - - /* Record first interface number */ - first = interface.InterfaceNumber; - count = usbio->config->interfaces; - assert ( first < count ); - usbio->first = first; - - /* Allocate interface list */ - usbio->interface = zalloc ( count * sizeof ( usbio->interface[0] ) ); - if ( ! usbio->interface ) { - rc = -ENOMEM; - goto err_alloc; - } - - /* Use already-opened protocol for control transfers and for - * the first interface. - */ - usbio->interface[0].handle = handle; - usbio->interface[0].io = io; - usbio->interface[0].count = 1; - usbio->interface[first].handle = handle; - usbio->interface[first].io = io; - usbio->interface[first].count = 1; - - return 0; - - free ( usbio->interface ); - err_alloc: - err_get_interface_descriptor: - return rc; -} - -/** - * Attach driver to device - * - * @v efidev EFI device - * @ret rc Return status code - */ -static int usbio_start ( struct efi_device *efidev ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - EFI_HANDLE handle = efidev->device; - struct usbio_device *usbio; - struct usb_port *port; - union { - void *interface; - EFI_USB_IO_PROTOCOL *io; - } u; - EFI_STATUS efirc; - int rc; - - /* Allocate and initialise structure */ - usbio = zalloc ( sizeof ( *usbio ) ); - if ( ! usbio ) { - rc = -ENOMEM; - goto err_alloc; - } - efidev_set_drvdata ( efidev, usbio ); - usbio->handle = handle; - INIT_LIST_HEAD ( &usbio->endpoints ); - - /* Open USB I/O protocol */ - if ( ( efirc = bs->OpenProtocol ( handle, &efi_usb_io_protocol_guid, - &u.interface, efi_image_handle, - handle, - ( EFI_OPEN_PROTOCOL_BY_DRIVER | - EFI_OPEN_PROTOCOL_EXCLUSIVE )))!=0){ - rc = -EEFI ( efirc ); - DBGC ( usbio, "USBIO %s cannot open USB I/O protocol: %s\n", - efi_handle_name ( handle ), strerror ( rc ) ); - DBGC_EFI_OPENERS ( usbio, handle, &efi_usb_io_protocol_guid ); - goto err_open_usbio; - } - usbio->io = u.io; - - /* Describe generic device */ - efi_device_info ( handle, "USB", &usbio->dev ); - usbio->dev.parent = &efidev->dev; - list_add ( &usbio->dev.siblings, &efidev->dev.children ); - INIT_LIST_HEAD ( &usbio->dev.children ); - - /* Fetch configuration descriptor */ - if ( ( rc = usbio_config ( usbio ) ) != 0 ) - goto err_config; - - /* Construct device path */ - if ( ( rc = usbio_path ( usbio ) ) != 0 ) - goto err_path; - - /* Construct interface list */ - if ( ( rc = usbio_interfaces ( usbio ) ) != 0 ) - goto err_interfaces; - - /* Allocate USB bus */ - usbio->bus = alloc_usb_bus ( &usbio->dev, 1 /* single "port" */, - USBIO_MTU, &usbio_operations ); - if ( ! usbio->bus ) { - rc = -ENOMEM; - goto err_alloc_bus; - } - usb_bus_set_hostdata ( usbio->bus, usbio ); - usb_hub_set_drvdata ( usbio->bus->hub, usbio ); - - /* Set port protocol */ - port = usb_port ( usbio->bus->hub, 1 ); - port->protocol = USB_PROTO_2_0; - - /* Register USB bus */ - if ( ( rc = register_usb_bus ( usbio->bus ) ) != 0 ) - goto err_register; - - return 0; - - unregister_usb_bus ( usbio->bus ); - err_register: - free_usb_bus ( usbio->bus ); - err_alloc_bus: - free ( usbio->interface ); - err_interfaces: - free ( usbio->path ); - err_path: - free ( usbio->config ); - err_config: - list_del ( &usbio->dev.siblings ); - bs->CloseProtocol ( handle, &efi_usb_io_protocol_guid, - efi_image_handle, handle ); - err_open_usbio: - free ( usbio ); - err_alloc: - return rc; -} - -/** - * Detach driver from device - * - * @v efidev EFI device - */ -static void usbio_stop ( struct efi_device *efidev ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - EFI_HANDLE handle = efidev->device; - struct usbio_device *usbio = efidev_get_drvdata ( efidev ); - - unregister_usb_bus ( usbio->bus ); - free_usb_bus ( usbio->bus ); - free ( usbio->interface ); - free ( usbio->path ); - free ( usbio->config ); - list_del ( &usbio->dev.siblings ); - bs->CloseProtocol ( handle, &efi_usb_io_protocol_guid, - efi_image_handle, handle ); - free ( usbio ); -} - -/** EFI USB I/O driver */ -struct efi_driver usbio_driver __efi_driver ( EFI_DRIVER_NORMAL ) = { - .name = "USBIO", - .supported = usbio_supported, - .start = usbio_start, - .stop = usbio_stop, -}; diff --git a/roms/ipxe/src/drivers/usb/usbio.h b/roms/ipxe/src/drivers/usb/usbio.h deleted file mode 100644 index 1d02876f6..000000000 --- a/roms/ipxe/src/drivers/usb/usbio.h +++ /dev/null @@ -1,153 +0,0 @@ -#ifndef _USBIO_H -#define _USBIO_H - -/** @file - * - * EFI_USB_IO_PROTOCOL pseudo Host Controller Interface driver - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#include <ipxe/list.h> -#include <ipxe/device.h> -#include <ipxe/efi/efi.h> -#include <ipxe/efi/Protocol/UsbIo.h> -#include <ipxe/efi/Protocol/DevicePath.h> -#include <ipxe/usb.h> - -/** USB I/O maximum transfer size - * - * The API provides no way to discover the maximum transfer size. - * Assume the 16kB supported by EHCI. - */ -#define USBIO_MTU 16384 - -/** USB I/O interrupt ring buffer size - * - * This is a policy decision. - */ -#define USBIO_INTR_COUNT 4 - -/** A USB interrupt ring buffer */ -struct usbio_interrupt_ring { - /** USB I/O endpoint */ - struct usbio_endpoint *endpoint; - /** Producer counter */ - unsigned int prod; - /** Consumer counter */ - unsigned int cons; - /** Data buffers */ - void *data[USBIO_INTR_COUNT]; - /** Lengths */ - size_t len[USBIO_INTR_COUNT]; -}; - -/** USB I/O ring buffer size - * - * This is a policy decision. - */ -#define USBIO_RING_COUNT 64 - -/** A USB I/O endpoint */ -struct usbio_endpoint { - /** USB I/O device */ - struct usbio_device *usbio; - /** USB endpoint */ - struct usb_endpoint *ep; - /** List of endpoints */ - struct list_head list; - /** USB I/O endpoint operations */ - struct usbio_operations *op; - - /** Containing interface number */ - unsigned int interface; - /** EFI handle */ - EFI_HANDLE handle; - /** USB I/O protocol */ - EFI_USB_IO_PROTOCOL *io; - - /** Producer counter */ - unsigned int prod; - /** Consumer counter */ - unsigned int cons; - /** I/O buffers */ - struct io_buffer *iobuf[USBIO_RING_COUNT]; - /** Flags */ - uint8_t flags[USBIO_RING_COUNT]; - - /** Interrupt ring buffer (if applicable) */ - struct usbio_interrupt_ring *intr; -}; - -/** USB I/O transfer flags */ -enum usbio_flags { - /** This is a message transfer */ - USBIO_MESSAGE = 0x01, - /** This transfer requires zero-length packet termination */ - USBIO_ZLEN = 0x02, -}; - -/** USB I/O endpoint operations */ -struct usbio_operations { - /** Open endpoint - * - * @v endpoint Endpoint - * @ret rc Return status code - */ - int ( * open ) ( struct usbio_endpoint *endpoint ); - /** Close endpoint - * - * @v endpoint Endpoint - */ - void ( * close ) ( struct usbio_endpoint *endpoint ); - /** Poll endpoint - * - * @v endpoint Endpoint - */ - void ( * poll ) ( struct usbio_endpoint *endpoint ); -}; - -/** A USB I/O protocol interface */ -struct usbio_interface { - /** EFI device handle */ - EFI_HANDLE handle; - /** USB I/O protocol */ - EFI_USB_IO_PROTOCOL *io; - /** Usage count */ - unsigned int count; -}; - -/** A USB I/O protocol device - * - * We model each externally-provided USB I/O protocol device as a host - * controller containing a root hub with a single port. - */ -struct usbio_device { - /** EFI device handle */ - EFI_HANDLE handle; - /** USB I/O protocol */ - EFI_USB_IO_PROTOCOL *io; - /** Generic device */ - struct device dev; - - /** Configuration descriptor */ - struct usb_configuration_descriptor *config; - - /** Device path */ - EFI_DEVICE_PATH_PROTOCOL *path; - /** Final component of USB device path */ - USB_DEVICE_PATH *usbpath; - - /** First interface number */ - uint8_t first; - /** USB I/O protocol interfaces */ - struct usbio_interface *interface; - - /** USB bus */ - struct usb_bus *bus; - /** List of endpoints */ - struct list_head endpoints; -}; - -#endif /* _USBIO_H */ diff --git a/roms/ipxe/src/drivers/usb/usbkbd.c b/roms/ipxe/src/drivers/usb/usbkbd.c index a8ab6ab76..ea94f2e63 100644 --- a/roms/ipxe/src/drivers/usb/usbkbd.c +++ b/roms/ipxe/src/drivers/usb/usbkbd.c @@ -53,14 +53,13 @@ static LIST_HEAD ( usb_keyboards ); * * @v keycode Keycode * @v modifiers Modifiers - * @v leds LED state * @ret key iPXE key * * Key codes are defined in the USB HID Usage Tables Keyboard/Keypad * page. */ -static unsigned int usbkbd_map ( unsigned int keycode, unsigned int modifiers, - unsigned int leds ) { +static unsigned int usbkbd_map ( unsigned int keycode, + unsigned int modifiers ) { unsigned int key; if ( keycode < USBKBD_KEY_A ) { @@ -71,8 +70,7 @@ static unsigned int usbkbd_map ( unsigned int keycode, unsigned int modifiers, key = ( keycode - USBKBD_KEY_A + 'a' ); if ( modifiers & USBKBD_CTRL ) { key -= ( 'a' - CTRL_A ); - } else if ( ( modifiers & USBKBD_SHIFT ) || - ( leds & USBKBD_LED_CAPS_LOCK ) ) { + } else if ( modifiers & USBKBD_SHIFT ) { key -= ( 'a' - 'A' ); } } else if ( keycode <= USBKBD_KEY_0 ) { @@ -102,22 +100,7 @@ static unsigned int usbkbd_map ( unsigned int keycode, unsigned int modifiers, KEY_PPAGE, KEY_DC, KEY_END, KEY_NPAGE, KEY_RIGHT, KEY_LEFT, KEY_DOWN, KEY_UP }; - key = special[ keycode - USBKBD_KEY_CAPS_LOCK ]; - } else if ( keycode <= USBKBD_KEY_PAD_ENTER ) { - /* Keypad (unaffected by Num Lock) */ - key = "\0/*-+\n" [ keycode - USBKBD_KEY_NUM_LOCK ]; - } else if ( keycode <= USBKBD_KEY_PAD_DOT ) { - /* Keypad (affected by Num Lock) */ - if ( leds & USBKBD_LED_NUM_LOCK ) { - key = "1234567890." [ keycode - USBKBD_KEY_PAD_1 ]; - } else { - static const uint16_t keypad[] = { - KEY_END, KEY_DOWN, KEY_NPAGE, KEY_LEFT, 0, - KEY_RIGHT, KEY_HOME, KEY_UP, KEY_PPAGE, - KEY_IC, KEY_DC - }; - key = keypad[ keycode - USBKBD_KEY_PAD_1 ]; - }; + key = special[ keycode - USBKBD_KEY_CAPSLOCK ]; } else { key = 0; } @@ -141,25 +124,10 @@ static unsigned int usbkbd_map ( unsigned int keycode, unsigned int modifiers, */ static void usbkbd_produce ( struct usb_keyboard *kbd, unsigned int keycode, unsigned int modifiers ) { - unsigned int leds = 0; unsigned int key; - /* Check for LED-modifying keys */ - if ( keycode == USBKBD_KEY_CAPS_LOCK ) { - leds = USBKBD_LED_CAPS_LOCK; - } else if ( keycode == USBKBD_KEY_NUM_LOCK ) { - leds = USBKBD_LED_NUM_LOCK; - } - - /* Handle LED-modifying keys */ - if ( leds ) { - kbd->leds ^= leds; - kbd->leds_changed = 1; - return; - } - /* Map to iPXE key */ - key = usbkbd_map ( keycode, modifiers, kbd->leds ); + key = usbkbd_map ( keycode, modifiers ); /* Do nothing if this keycode has no corresponding iPXE key */ if ( ! key ) { @@ -367,37 +335,6 @@ static struct usb_endpoint_driver_operations usbkbd_operations = { /****************************************************************************** * - * Keyboard LEDs - * - ****************************************************************************** - */ - -/** - * Set keyboard LEDs - * - * @v kbd USB keyboard - * @ret rc Return status code - */ -static int usbkbd_set_leds ( struct usb_keyboard *kbd ) { - struct usb_function *func = kbd->hid.func; - int rc; - - DBGC2 ( kbd, "KBD %s setting LEDs to %#02x\n", kbd->name, kbd->leds ); - - /* Set keyboard LEDs */ - if ( ( rc = usbhid_set_report ( func->usb, func->interface[0], - USBHID_REPORT_OUTPUT, 0, &kbd->leds, - sizeof ( kbd->leds ) ) ) != 0 ) { - DBGC ( kbd, "KBD %s could not set LEDs to %#02x: %s\n", - kbd->name, kbd->leds, strerror ( rc ) ); - return rc; - } - - return 0; -} - -/****************************************************************************** - * * USB interface * ****************************************************************************** @@ -425,7 +362,7 @@ static int usbkbd_probe ( struct usb_function *func, kbd->name = func->name; kbd->bus = usb->port->hub->bus; usbhid_init ( &kbd->hid, func, &usbkbd_operations, NULL ); - usb_refill_init ( &kbd->hid.in, 0, sizeof ( kbd->report ), + usb_refill_init ( &kbd->hid.in, sizeof ( kbd->report ), USBKBD_INTR_MAX_FILL ); /* Describe USB human interface device */ @@ -463,9 +400,6 @@ static int usbkbd_probe ( struct usb_function *func, /* Add to list of USB keyboards */ list_add_tail ( &kbd->list, &usb_keyboards ); - /* Set initial LED state */ - usbkbd_set_leds ( kbd ); - usb_func_set_drvdata ( func, kbd ); return 0; @@ -503,6 +437,11 @@ static struct usb_device_id usbkbd_ids[] = { .name = "kbd", .vendor = USB_ANY_ID, .product = USB_ANY_ID, + .class = { + .class = USB_CLASS_HID, + .subclass = USB_SUBCLASS_HID_BOOT, + .protocol = USBKBD_PROTOCOL, + }, }, }; @@ -510,9 +449,6 @@ static struct usb_device_id usbkbd_ids[] = { struct usb_driver usbkbd_driver __usb_driver = { .ids = usbkbd_ids, .id_count = ( sizeof ( usbkbd_ids ) / sizeof ( usbkbd_ids[0] ) ), - .class = USB_CLASS_ID ( USB_CLASS_HID, USB_SUBCLASS_HID_BOOT, - USBKBD_PROTOCOL ), - .score = USB_SCORE_NORMAL, .probe = usbkbd_probe, .remove = usbkbd_remove, }; @@ -550,20 +486,10 @@ static int usbkbd_iskey ( void ) { struct usb_keyboard *kbd; unsigned int fill; - /* Poll USB keyboards, refill endpoints, and set LEDs if applicable */ + /* Poll all USB keyboards and refill endpoints */ list_for_each_entry ( kbd, &usb_keyboards, list ) { - - /* Poll keyboard */ usb_poll ( kbd->bus ); - - /* Refill endpoints */ usb_refill ( &kbd->hid.in ); - - /* Update keyboard LEDs, if applicable */ - if ( kbd->leds_changed ) { - usbkbd_set_leds ( kbd ); - kbd->leds_changed = 0; - } } /* Check for a non-empty keyboard buffer */ diff --git a/roms/ipxe/src/drivers/usb/usbkbd.h b/roms/ipxe/src/drivers/usb/usbkbd.h index cedebfe71..7eab24e46 100644 --- a/roms/ipxe/src/drivers/usb/usbkbd.h +++ b/roms/ipxe/src/drivers/usb/usbkbd.h @@ -68,20 +68,8 @@ enum usb_keycode { USBKBD_KEY_SPACE = 0x2c, USBKBD_KEY_MINUS = 0x2d, USBKBD_KEY_SLASH = 0x38, - USBKBD_KEY_CAPS_LOCK = 0x39, - USBKBD_KEY_F1 = 0x3a, + USBKBD_KEY_CAPSLOCK = 0x39, USBKBD_KEY_UP = 0x52, - USBKBD_KEY_NUM_LOCK = 0x53, - USBKBD_KEY_PAD_ENTER = 0x58, - USBKBD_KEY_PAD_1 = 0x59, - USBKBD_KEY_PAD_DOT = 0x63, -}; - -/** USB keyboard LEDs */ -enum usb_keyboard_led { - USBKBD_LED_NUM_LOCK = 0x01, - USBKBD_LED_CAPS_LOCK = 0x02, - USBKBD_LED_SCROLL_LOCK = 0x04, }; /** Keyboard idle duration (in 4ms units) @@ -132,11 +120,6 @@ struct usb_keyboard { /** Autorepeat hold-off time (in number of completions reported) */ unsigned int holdoff; - /** Keyboard LED state */ - uint8_t leds; - /** Keyboard LEDs changed */ - uint8_t leds_changed; - /** Keyboard buffer * * This stores iPXE key values. diff --git a/roms/ipxe/src/drivers/usb/usbnet.c b/roms/ipxe/src/drivers/usb/usbnet.c index d18d81772..b92336d05 100644 --- a/roms/ipxe/src/drivers/usb/usbnet.c +++ b/roms/ipxe/src/drivers/usb/usbnet.c @@ -173,7 +173,7 @@ static int usbnet_comms_describe ( struct usbnet_device *usbnet, int rc; /* Iterate over all available interfaces */ - for ( i = 0 ; i < usbnet->func->desc.count ; i++ ) { + for ( i = 0 ; i < usbnet->func->count ; i++ ) { /* Get interface number */ comms = usbnet->func->interface[i]; @@ -217,7 +217,7 @@ static int usbnet_data_describe ( struct usbnet_device *usbnet, int rc; /* Iterate over all available interfaces */ - for ( i = 0 ; i < usbnet->func->desc.count ; i++ ) { + for ( i = 0 ; i < usbnet->func->count ; i++ ) { /* Get interface number */ data = usbnet->func->interface[i]; diff --git a/roms/ipxe/src/drivers/usb/xhci.c b/roms/ipxe/src/drivers/usb/xhci.c index 48ac6a307..49e67316b 100644 --- a/roms/ipxe/src/drivers/usb/xhci.c +++ b/roms/ipxe/src/drivers/usb/xhci.c @@ -2542,44 +2542,20 @@ static int xhci_endpoint_message ( struct usb_endpoint *ep, } /** - * Calculate number of TRBs - * - * @v len Length of data - * @v zlp Append a zero-length packet - * @ret count Number of transfer descriptors - */ -static unsigned int xhci_endpoint_count ( size_t len, int zlp ) { - unsigned int count; - - /* Split into 64kB TRBs */ - count = ( ( len + XHCI_MTU - 1 ) / XHCI_MTU ); - - /* Append a zero-length TRB if applicable */ - if ( zlp || ( count == 0 ) ) - count++; - - return count; -} - -/** * Enqueue stream transfer * * @v ep USB endpoint * @v iobuf I/O buffer - * @v zlp Append a zero-length packet + * @v terminate Terminate using a short packet * @ret rc Return status code */ static int xhci_endpoint_stream ( struct usb_endpoint *ep, - struct io_buffer *iobuf, int zlp ) { + struct io_buffer *iobuf, int terminate ) { struct xhci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep ); - void *data = iobuf->data; - size_t len = iob_len ( iobuf ); - unsigned int count = xhci_endpoint_count ( len, zlp ); - union xhci_trb trbs[count]; + union xhci_trb trbs[ 1 /* Normal */ + 1 /* Possible zero-length */ ]; union xhci_trb *trb = trbs; struct xhci_trb_normal *normal; - unsigned int i; - size_t trb_len; + size_t len = iob_len ( iobuf ); int rc; /* Profile stream transfers */ @@ -2587,36 +2563,20 @@ static int xhci_endpoint_stream ( struct usb_endpoint *ep, /* Construct normal TRBs */ memset ( &trbs, 0, sizeof ( trbs ) ); - for ( i = 0 ; i < count ; i ++ ) { - - /* Calculate TRB length */ - trb_len = XHCI_MTU; - if ( trb_len > len ) - trb_len = len; - - /* Construct normal TRB */ - normal = &trb->normal; - normal->data = cpu_to_le64 ( virt_to_phys ( data ) ); - normal->len = cpu_to_le32 ( trb_len ); - normal->type = XHCI_TRB_NORMAL; + normal = &(trb++)->normal; + normal->data = cpu_to_le64 ( virt_to_phys ( iobuf->data ) ); + normal->len = cpu_to_le32 ( len ); + normal->type = XHCI_TRB_NORMAL; + if ( terminate && ( ( len & ( ep->mtu - 1 ) ) == 0 ) ) { normal->flags = XHCI_TRB_CH; - - /* Move to next TRB */ - data += trb_len; - len -= trb_len; - trb++; + normal = &(trb++)->normal; + normal->type = XHCI_TRB_NORMAL; } - - /* Mark zero-length packet (if present) as a separate transfer */ - if ( zlp && ( count > 1 ) ) - trb[-2].normal.flags = 0; - - /* Generate completion for final TRB */ - trb[-1].normal.flags = XHCI_TRB_IOC; + normal->flags = XHCI_TRB_IOC; /* Enqueue TRBs */ if ( ( rc = xhci_enqueue_multi ( &endpoint->ring, iobuf, trbs, - count ) ) != 0 ) + ( trb - trbs ) ) ) != 0 ) return rc; /* Ring the doorbell */ @@ -2759,6 +2719,7 @@ static void xhci_device_close ( struct usb_device *usb ) { static int xhci_device_address ( struct usb_device *usb ) { struct xhci_slot *slot = usb_get_hostdata ( usb ); struct xhci_device *xhci = slot->xhci; + struct usb_port *port = usb->port; struct usb_port *root_port; int psiv; int rc; @@ -2771,7 +2732,7 @@ static int xhci_device_address ( struct usb_device *usb ) { slot->port = root_port->address; /* Calculate protocol speed ID */ - psiv = xhci_port_psiv ( xhci, slot->port, usb->speed ); + psiv = xhci_port_psiv ( xhci, slot->port, port->speed ); if ( psiv < 0 ) { rc = psiv; return rc; diff --git a/roms/ipxe/src/hci/commands/ibmgmt_cmd.c b/roms/ipxe/src/hci/commands/ibmgmt_cmd.c deleted file mode 100644 index 1154d749e..000000000 --- a/roms/ipxe/src/hci/commands/ibmgmt_cmd.c +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2016 Michael Brown <mbrown@fensystems.co.uk>. - * - * 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 <stdio.h> -#include <errno.h> -#include <getopt.h> -#include <ipxe/command.h> -#include <ipxe/parseopt.h> -#include <ipxe/infiniband.h> -#include <usr/ibmgmt.h> - -/** @file - * - * Infiniband device management commands - * - */ - -/** "ibstat" options */ -struct ibstat_options {}; - -/** "ibstat" option list */ -static struct option_descriptor ibstat_opts[] = {}; - -/** "ibstat" command descriptor */ -static struct command_descriptor ibstat_cmd = - COMMAND_DESC ( struct ibstat_options, ibstat_opts, 0, 0, "" ); - -/** - * The "ibstat" command - * - * @v argc Argument count - * @v argv Argument list - * @ret rc Return status code - */ -static int ibstat_exec ( int argc, char **argv ) { - struct ibstat_options opts; - struct ib_device *ibdev; - int rc; - - /* Parse options */ - if ( ( rc = parse_options ( argc, argv, &ibstat_cmd, &opts ) ) != 0 ) - return rc; - - /* Show all Infiniband devices */ - for_each_ibdev ( ibdev ) - ibstat ( ibdev ); - - return 0; -} - -/** Infiniband commands */ -struct command ibmgmt_commands[] __command = { - { - .name = "ibstat", - .exec = ibstat_exec, - }, -}; diff --git a/roms/ipxe/src/hci/commands/lotest_cmd.c b/roms/ipxe/src/hci/commands/lotest_cmd.c index 393b3c36e..a989932d4 100644 --- a/roms/ipxe/src/hci/commands/lotest_cmd.c +++ b/roms/ipxe/src/hci/commands/lotest_cmd.c @@ -43,16 +43,12 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); struct lotest_options { /** MTU */ unsigned int mtu; - /** Broadcast */ - int broadcast; }; /** "lotest" option list */ static struct option_descriptor lotest_opts[] = { OPTION_DESC ( "mtu", 'm', required_argument, struct lotest_options, mtu, parse_integer ), - OPTION_DESC ( "broadcast", 'b', no_argument, - struct lotest_options, broadcast, parse_flag ), }; /** "lotest" command descriptor */ @@ -90,8 +86,7 @@ static int lotest_exec ( int argc, char **argv ) { opts.mtu = ETH_MAX_MTU; /* Perform loopback test */ - if ( ( rc = loopback_test ( sender, receiver, opts.mtu, - opts.broadcast ) ) != 0 ) { + if ( ( rc = loopback_test ( sender, receiver, opts.mtu ) ) != 0 ) { printf ( "Test failed: %s\n", strerror ( rc ) ); return rc; } diff --git a/roms/ipxe/src/hci/commands/ntp_cmd.c b/roms/ipxe/src/hci/commands/ntp_cmd.c deleted file mode 100644 index 8f741a512..000000000 --- a/roms/ipxe/src/hci/commands/ntp_cmd.c +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) 2016 Michael Brown <mbrown@fensystems.co.uk>. - * - * 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 <stdio.h> -#include <string.h> -#include <getopt.h> -#include <ipxe/command.h> -#include <ipxe/parseopt.h> -#include <usr/ntpmgmt.h> - -/** @file - * - * NTP commands - * - */ - -/** "ntp" options */ -struct ntp_options {}; - -/** "ntp" option list */ -static struct option_descriptor ntp_opts[] = {}; - -/** "ntp" command descriptor */ -static struct command_descriptor ntp_cmd = - COMMAND_DESC ( struct ntp_options, ntp_opts, 1, 1, "<server>" ); - -/** - * "ntp" command - * - * @v argc Argument count - * @v argv Argument list - * @ret rc Return status code - */ -static int ntp_exec ( int argc, char **argv ) { - struct ntp_options opts; - const char *hostname; - int rc; - - /* Parse options */ - if ( ( rc = parse_options ( argc, argv, &ntp_cmd, &opts ) ) != 0 ) - return rc; - - /* Parse hostname */ - hostname = argv[optind]; - - /* Get time and date via NTP */ - if ( ( rc = ntp ( hostname ) ) != 0 ) { - printf ( "Could not get time and date: %s\n", strerror ( rc ) ); - return rc; - } - - return 0; -} - -/** NTP command */ -struct command ntp_command __command = { - .name = "ntp", - .exec = ntp_exec, -}; diff --git a/roms/ipxe/src/hci/mucurses/windows.c b/roms/ipxe/src/hci/mucurses/windows.c index 5f5d1f4e2..7f39bdea2 100644 --- a/roms/ipxe/src/hci/mucurses/windows.c +++ b/roms/ipxe/src/hci/mucurses/windows.c @@ -18,6 +18,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); * @ret rc return status code */ int delwin ( WINDOW *win ) { + if ( win == NULL ) + return ERR; + /* I think we should blank the region covered by the window - ncurses doesn't do this, but they have a buffer, so they may just be deleting from an offscreen context whereas we @@ -48,6 +51,8 @@ int delwin ( WINDOW *win ) { WINDOW *derwin ( WINDOW *parent, int nlines, int ncols, int begin_y, int begin_x ) { WINDOW *child; + if ( parent == NULL ) + return NULL; if ( ( child = malloc( sizeof( WINDOW ) ) ) == NULL ) return NULL; if ( ( (unsigned)ncols > parent->width ) || @@ -70,6 +75,8 @@ WINDOW *derwin ( WINDOW *parent, int nlines, int ncols, */ WINDOW *dupwin ( WINDOW *orig ) { WINDOW *copy; + if ( orig == NULL ) + return NULL; if ( ( copy = malloc( sizeof( WINDOW ) ) ) == NULL ) return NULL; copy->scr = orig->scr; @@ -92,6 +99,8 @@ WINDOW *dupwin ( WINDOW *orig ) { * @ret rc return status code */ int mvwin ( WINDOW *win, int y, int x ) { + if ( win == NULL ) + return ERR; if ( ( ( (unsigned)y + win->height ) > LINES ) || ( ( (unsigned)x + win->width ) > COLS ) ) return ERR; @@ -140,6 +149,8 @@ WINDOW *newwin ( int nlines, int ncols, int begin_y, int begin_x ) { WINDOW *subwin ( WINDOW *parent, int nlines, int ncols, int begin_y, int begin_x ) { WINDOW *child; + if ( parent == NULL ) + return NULL; if ( ( child = malloc( sizeof( WINDOW ) ) ) == NULL ) return NULL; child = newwin( nlines, ncols, begin_y, begin_x ); diff --git a/roms/ipxe/src/image/efi_image.c b/roms/ipxe/src/image/efi_image.c index 47580c0db..b7d8f9c6e 100644 --- a/roms/ipxe/src/image/efi_image.c +++ b/roms/ipxe/src/image/efi_image.c @@ -29,12 +29,10 @@ FILE_LICENCE ( GPL2_OR_LATER ); #include <ipxe/efi/efi_utils.h> #include <ipxe/efi/efi_strings.h> #include <ipxe/efi/efi_wrap.h> -#include <ipxe/efi/efi_pxe.h> #include <ipxe/image.h> #include <ipxe/init.h> #include <ipxe/features.h> #include <ipxe/uri.h> -#include <ipxe/console.h> FEATURE ( FEATURE_IMAGE, "EFI", DHCP_EB_FEATURE_EFI, 1 ); @@ -74,7 +72,8 @@ efi_image_path ( struct image *image, EFI_DEVICE_PATH_PROTOCOL *parent ) { size_t len; /* Calculate device path lengths */ - prefix_len = efi_devpath_len ( parent ); + end = efi_devpath_end ( parent ); + prefix_len = ( ( void * ) end - ( void * ) parent ); name_len = strlen ( image->name ); filepath_len = ( SIZE_OF_FILEPATH_DEVICE_PATH + ( name_len + 1 /* NUL */ ) * sizeof ( wchar_t ) ); @@ -160,13 +159,6 @@ static int efi_image_exec ( struct image *image ) { goto err_file_install; } - /* Install PXE base code protocol */ - if ( ( rc = efi_pxe_install ( snpdev->handle, snpdev->netdev ) ) != 0 ){ - DBGC ( image, "EFIIMAGE %p could not install PXE protocol: " - "%s\n", image, strerror ( rc ) ); - goto err_pxe_install; - } - /* Install iPXE download protocol */ if ( ( rc = efi_download_install ( snpdev->handle ) ) != 0 ) { DBGC ( image, "EFIIMAGE %p could not install iPXE download " @@ -237,9 +229,6 @@ static int efi_image_exec ( struct image *image ) { /* Wrap calls made by the loaded image (for debugging) */ efi_wrap ( handle ); - /* Reset console since image will probably use it */ - console_reset(); - /* Start the image */ if ( ( efirc = bs->StartImage ( handle, NULL, NULL ) ) != 0 ) { rc = -EEFI_START ( efirc ); @@ -277,8 +266,6 @@ static int efi_image_exec ( struct image *image ) { err_image_path: efi_download_uninstall ( snpdev->handle ); err_download_install: - efi_pxe_uninstall ( snpdev->handle ); - err_pxe_install: efi_file_uninstall ( snpdev->handle ); err_file_install: err_no_snpdev: diff --git a/roms/ipxe/src/image/embedded.c b/roms/ipxe/src/image/embedded.c index 376e5d299..48dd86851 100644 --- a/roms/ipxe/src/image/embedded.c +++ b/roms/ipxe/src/image/embedded.c @@ -18,7 +18,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #define EMBED( _index, _path, _name ) \ extern char embedded_image_ ## _index ## _data[]; \ extern char embedded_image_ ## _index ## _len[]; \ - __asm__ ( ".section \".rodata\", \"a\", " PROGBITS "\n\t" \ + __asm__ ( ".section \".rodata\", \"a\", @progbits\n\t" \ "\nembedded_image_" #_index "_data:\n\t" \ ".incbin \"" _path "\"\n\t" \ "\nembedded_image_" #_index "_end:\n\t" \ diff --git a/roms/ipxe/src/include/compiler.h b/roms/ipxe/src/include/compiler.h index 32afb64cf..ca82f9523 100644 --- a/roms/ipxe/src/include/compiler.h +++ b/roms/ipxe/src/include/compiler.h @@ -52,17 +52,6 @@ /** Stringify expanded argument */ #define _S2( x ) _S1 ( x ) -/* Assembler section types */ -#ifdef ASSEMBLY -#define PROGBITS _C2 ( ASM_TCHAR, progbits ) -#define NOBITS _C2 ( ASM_TCHAR, nobits ) -#else -#define PROGBITS_OPS _S2 ( ASM_TCHAR_OPS ) "progbits" -#define PROGBITS _S2 ( ASM_TCHAR ) "progbits" -#define NOBITS_OPS _S2 ( ASM_TCHAR_OPS ) "nobits" -#define NOBITS _S2 ( ASM_TCHAR ) "nobits" -#endif - /** * @defgroup symmacros Macros to provide or require explicit symbols * @{ @@ -75,7 +64,7 @@ */ #ifdef ASSEMBLY #define PROVIDE_SYMBOL( symbol ) \ - .section ".provided", "a", NOBITS ; \ + .section ".provided", "a", @nobits ; \ .hidden symbol ; \ .globl symbol ; \ symbol: ; \ @@ -150,14 +139,14 @@ */ #ifdef ASSEMBLY #define PROVIDE_REQUIRING_SYMBOL() \ - .section ".tbl.requiring_symbols", "a", PROGBITS ; \ + .section ".tbl.requiring_symbols", "a", @progbits ; \ __requiring_symbol__: .byte 0 ; \ .size __requiring_symbol__, . - __requiring_symbol__ ; \ .previous #else #define PROVIDE_REQUIRING_SYMBOL() \ __asm__ ( ".section \".tbl.requiring_symbols\", " \ - " \"a\", " PROGBITS "\n" \ + " \"a\", @progbits\n" \ "__requiring_symbol__:\t.byte 0\n" \ ".size __requiring_symbol__, " \ " . - __requiring_symbol__\n" \ diff --git a/roms/ipxe/src/include/errno.h b/roms/ipxe/src/include/errno.h index 342384fa4..036479aff 100644 --- a/roms/ipxe/src/include/errno.h +++ b/roms/ipxe/src/include/errno.h @@ -258,7 +258,7 @@ static inline void eplatform_discard ( int dummy __unused, ... ) {} * @ret error Error */ #define __einfo_error( einfo ) ( { \ - __asm__ ( ".section \".einfo\", \"\", " PROGBITS_OPS "\n\t" \ + __asm__ ( ".section \".einfo\", \"\", @progbits\n\t" \ ".align 8\n\t" \ "\n1:\n\t" \ ".long ( 4f - 1b )\n\t" \ diff --git a/roms/ipxe/src/include/ipxe/asn1.h b/roms/ipxe/src/include/ipxe/asn1.h index 2e635b48a..5fbd58281 100644 --- a/roms/ipxe/src/include/ipxe/asn1.h +++ b/roms/ipxe/src/include/ipxe/asn1.h @@ -315,26 +315,14 @@ struct asn1_bit_string { } __attribute__ (( packed )); /** - * Invalidate ASN.1 object cursor - * - * @v cursor ASN.1 object cursor - */ -static inline __attribute__ (( always_inline )) void -asn1_invalidate_cursor ( struct asn1_cursor *cursor ) { - cursor->len = 0; -} - -/** * Extract ASN.1 type * * @v cursor ASN.1 object cursor - * @ret type Type, or ASN1_END if cursor is invalid + * @ret type Type */ static inline __attribute__ (( always_inline )) unsigned int asn1_type ( const struct asn1_cursor *cursor ) { - const uint8_t *type = cursor->data; - - return ( ( cursor->len >= sizeof ( *type ) ) ? *type : ASN1_END ); + return ( *( ( const uint8_t * ) cursor->data ) ); } extern void asn1_invalidate_cursor ( struct asn1_cursor *cursor ); diff --git a/roms/ipxe/src/include/ipxe/bitops.h b/roms/ipxe/src/include/ipxe/bitops.h index 7366cd9f1..220ab0fe7 100644 --- a/roms/ipxe/src/include/ipxe/bitops.h +++ b/roms/ipxe/src/include/ipxe/bitops.h @@ -1,19 +1,235 @@ #ifndef _IPXE_BITOPS_H #define _IPXE_BITOPS_H -/** @file +/* + * Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>. * - * Bit operations + * 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 <bits/bitops.h> +/** + * @file + * + * Bit operations + * + */ + +#include <stdint.h> +#include <byteswap.h> + +/* Endianness selection. + * + * This is a property of the NIC, not a property of the host CPU. + */ +#ifdef BITOPS_LITTLE_ENDIAN +#define cpu_to_BIT64 cpu_to_le64 +#define cpu_to_BIT32 cpu_to_le32 +#define BIT64_to_cpu le64_to_cpu +#define BIT32_to_cpu le32_to_cpu +#endif +#ifdef BITOPS_BIG_ENDIAN +#define cpu_to_BIT64 cpu_to_be64 +#define cpu_to_BIT32 cpu_to_be32 +#define BIT64_to_cpu be64_to_cpu +#define BIT32_to_cpu be32_to_cpu +#endif + +/** Datatype used to represent a bit in the pseudo-structures */ +typedef unsigned char pseudo_bit_t; + +/** + * Wrapper structure for pseudo_bit_t structures + * + * This structure provides a wrapper around pseudo_bit_t structures. + * It has the correct size, and also encapsulates type information + * about the underlying pseudo_bit_t-based structure, which allows the + * BIT_FILL() etc. macros to work without requiring explicit type + * information. + */ +#define PSEUDO_BIT_STRUCT( _structure ) \ + union { \ + uint8_t bytes[ sizeof ( _structure ) / 8 ]; \ + uint32_t dwords[ sizeof ( _structure ) / 32 ]; \ + uint64_t qwords[ sizeof ( _structure ) / 64 ]; \ + _structure *dummy[0]; \ + } __attribute__ (( packed )) u + +/** Get pseudo_bit_t structure type from wrapper structure pointer */ +#define PSEUDO_BIT_STRUCT_TYPE( _ptr ) \ + typeof ( *((_ptr)->u.dummy[0]) ) + +/** Bit offset of a field within a pseudo_bit_t structure */ +#define BIT_OFFSET( _ptr, _field ) \ + offsetof ( PSEUDO_BIT_STRUCT_TYPE ( _ptr ), _field ) + +/** Bit width of a field within a pseudo_bit_t structure */ +#define BIT_WIDTH( _ptr, _field ) \ + sizeof ( ( ( PSEUDO_BIT_STRUCT_TYPE ( _ptr ) * ) NULL )->_field ) + +/** Qword offset of a field within a pseudo_bit_t structure */ +#define QWORD_OFFSET( _ptr, _field ) \ + ( BIT_OFFSET ( _ptr, _field ) / 64 ) + +/** Qword bit offset of a field within a pseudo_bit_t structure */ +#define QWORD_BIT_OFFSET( _ptr, _index, _field ) \ + ( BIT_OFFSET ( _ptr, _field ) - ( 64 * (_index) ) ) + +/** Bit mask for a field within a pseudo_bit_t structure */ +#define BIT_MASK( _ptr, _field ) \ + ( ( ~( ( uint64_t ) 0 ) ) >> \ + ( 64 - BIT_WIDTH ( _ptr, _field ) ) ) + +/* + * Assemble native-endian qword from named fields and values + * + */ + +#define BIT_ASSEMBLE_1( _ptr, _index, _field, _value ) \ + ( ( ( uint64_t) (_value) ) << \ + QWORD_BIT_OFFSET ( _ptr, _index, _field ) ) + +#define BIT_ASSEMBLE_2( _ptr, _index, _field, _value, ... ) \ + ( BIT_ASSEMBLE_1 ( _ptr, _index, _field, _value ) | \ + BIT_ASSEMBLE_1 ( _ptr, _index, __VA_ARGS__ ) ) + +#define BIT_ASSEMBLE_3( _ptr, _index, _field, _value, ... ) \ + ( BIT_ASSEMBLE_1 ( _ptr, _index, _field, _value ) | \ + BIT_ASSEMBLE_2 ( _ptr, _index, __VA_ARGS__ ) ) + +#define BIT_ASSEMBLE_4( _ptr, _index, _field, _value, ... ) \ + ( BIT_ASSEMBLE_1 ( _ptr, _index, _field, _value ) | \ + BIT_ASSEMBLE_3 ( _ptr, _index, __VA_ARGS__ ) ) + +#define BIT_ASSEMBLE_5( _ptr, _index, _field, _value, ... ) \ + ( BIT_ASSEMBLE_1 ( _ptr, _index, _field, _value ) | \ + BIT_ASSEMBLE_4 ( _ptr, _index, __VA_ARGS__ ) ) + +#define BIT_ASSEMBLE_6( _ptr, _index, _field, _value, ... ) \ + ( BIT_ASSEMBLE_1 ( _ptr, _index, _field, _value ) | \ + BIT_ASSEMBLE_5 ( _ptr, _index, __VA_ARGS__ ) ) + +#define BIT_ASSEMBLE_7( _ptr, _index, _field, _value, ... ) \ + ( BIT_ASSEMBLE_1 ( _ptr, _index, _field, _value ) | \ + BIT_ASSEMBLE_6 ( _ptr, _index, __VA_ARGS__ ) ) + +/* + * Build native-endian (positive) qword bitmasks from named fields + * + */ + +#define BIT_MASK_1( _ptr, _index, _field ) \ + ( BIT_MASK ( _ptr, _field ) << \ + QWORD_BIT_OFFSET ( _ptr, _index, _field ) ) + +#define BIT_MASK_2( _ptr, _index, _field, ... ) \ + ( BIT_MASK_1 ( _ptr, _index, _field ) | \ + BIT_MASK_1 ( _ptr, _index, __VA_ARGS__ ) ) + +#define BIT_MASK_3( _ptr, _index, _field, ... ) \ + ( BIT_MASK_1 ( _ptr, _index, _field ) | \ + BIT_MASK_2 ( _ptr, _index, __VA_ARGS__ ) ) + +#define BIT_MASK_4( _ptr, _index, _field, ... ) \ + ( BIT_MASK_1 ( _ptr, _index, _field ) | \ + BIT_MASK_3 ( _ptr, _index, __VA_ARGS__ ) ) + +#define BIT_MASK_5( _ptr, _index, _field, ... ) \ + ( BIT_MASK_1 ( _ptr, _index, _field ) | \ + BIT_MASK_4 ( _ptr, _index, __VA_ARGS__ ) ) + +#define BIT_MASK_6( _ptr, _index, _field, ... ) \ + ( BIT_MASK_1 ( _ptr, _index, _field ) | \ + BIT_MASK_5 ( _ptr, _index, __VA_ARGS__ ) ) + +#define BIT_MASK_7( _ptr, _index, _field, ... ) \ + ( BIT_MASK_1 ( _ptr, _index, _field ) | \ + BIT_MASK_6 ( _ptr, _index, __VA_ARGS__ ) ) + +/* + * Populate little-endian qwords from named fields and values + * + */ + +#define BIT_FILL( _ptr, _index, _assembled ) do { \ + uint64_t *__ptr = &(_ptr)->u.qwords[(_index)]; \ + uint64_t __assembled = (_assembled); \ + *__ptr = cpu_to_BIT64 ( __assembled ); \ + } while ( 0 ) + +#define BIT_FILL_1( _ptr, _field1, ... ) \ + BIT_FILL ( _ptr, QWORD_OFFSET ( _ptr, _field1 ), \ + BIT_ASSEMBLE_1 ( _ptr, QWORD_OFFSET ( _ptr, _field1 ), \ + _field1, __VA_ARGS__ ) ) + +#define BIT_FILL_2( _ptr, _field1, ... ) \ + BIT_FILL ( _ptr, QWORD_OFFSET ( _ptr, _field1 ), \ + BIT_ASSEMBLE_2 ( _ptr, QWORD_OFFSET ( _ptr, _field1 ), \ + _field1, __VA_ARGS__ ) ) + +#define BIT_FILL_3( _ptr, _field1, ... ) \ + BIT_FILL ( _ptr, QWORD_OFFSET ( _ptr, _field1 ), \ + BIT_ASSEMBLE_3 ( _ptr, QWORD_OFFSET ( _ptr, _field1 ), \ + _field1, __VA_ARGS__ ) ) + +#define BIT_FILL_4( _ptr, _field1, ... ) \ + BIT_FILL ( _ptr, QWORD_OFFSET ( _ptr, _field1 ), \ + BIT_ASSEMBLE_4 ( _ptr, QWORD_OFFSET ( _ptr, _field1 ), \ + _field1, __VA_ARGS__ ) ) + +#define BIT_FILL_5( _ptr, _field1, ... ) \ + BIT_FILL ( _ptr, QWORD_OFFSET ( _ptr, _field1 ), \ + BIT_ASSEMBLE_5 ( _ptr, QWORD_OFFSET ( _ptr, _field1 ), \ + _field1, __VA_ARGS__ ) ) + +#define BIT_FILL_6( _ptr, _field1, ... ) \ + BIT_FILL ( _ptr, QWORD_OFFSET ( _ptr, _field1 ), \ + BIT_ASSEMBLE_6 ( _ptr, QWORD_OFFSET ( _ptr, _field1 ), \ + _field1, __VA_ARGS__ ) ) + +/** Extract value of named field */ +#define BIT_GET64( _ptr, _field ) \ + ( { \ + unsigned int __index = QWORD_OFFSET ( _ptr, _field ); \ + uint64_t *__ptr = &(_ptr)->u.qwords[__index]; \ + uint64_t __value = BIT64_to_cpu ( *__ptr ); \ + __value >>= \ + QWORD_BIT_OFFSET ( _ptr, __index, _field ); \ + __value &= BIT_MASK ( _ptr, _field ); \ + __value; \ + } ) + +/** Extract value of named field (for fields up to the size of a long) */ +#define BIT_GET( _ptr, _field ) \ + ( ( unsigned long ) BIT_GET64 ( _ptr, _field ) ) -void set_bit ( unsigned int bit, volatile void *bits ); -void clear_bit ( unsigned int bit, volatile void *bits ); -int test_and_set_bit ( unsigned int bit, volatile void *bits ); -int test_and_clear_bit ( unsigned int bit, volatile void *bits ); +#define BIT_SET( _ptr, _field, _value ) do { \ + unsigned int __index = QWORD_OFFSET ( _ptr, _field ); \ + uint64_t *__ptr = &(_ptr)->u.qwords[__index]; \ + unsigned int __shift = \ + QWORD_BIT_OFFSET ( _ptr, __index, _field ); \ + uint64_t __value = (_value); \ + *__ptr &= cpu_to_BIT64 ( ~( BIT_MASK ( _ptr, _field ) << \ + __shift ) ); \ + *__ptr |= cpu_to_BIT64 ( __value << __shift ); \ + } while ( 0 ) #endif /* _IPXE_BITOPS_H */ diff --git a/roms/ipxe/src/include/ipxe/cdc.h b/roms/ipxe/src/include/ipxe/cdc.h index b8b4a59d9..f1799cd9a 100644 --- a/roms/ipxe/src/include/ipxe/cdc.h +++ b/roms/ipxe/src/include/ipxe/cdc.h @@ -14,16 +14,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); /** Class code for communications devices */ #define USB_CLASS_CDC 2 -/** Send encapsulated command */ -#define CDC_SEND_ENCAPSULATED_COMMAND \ - ( USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE | \ - USB_REQUEST_TYPE ( 0x00 ) ) - -/** Get encapsulated response */ -#define CDC_GET_ENCAPSULATED_RESPONSE \ - ( USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE | \ - USB_REQUEST_TYPE ( 0x01 ) ) - /** Union functional descriptor */ struct cdc_union_descriptor { /** Descriptor header */ @@ -40,11 +30,6 @@ struct cdc_union_descriptor { /** Ethernet descriptor subtype */ #define CDC_SUBTYPE_ETHERNET 15 -/** Response available */ -#define CDC_RESPONSE_AVAILABLE \ - ( USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE | \ - USB_REQUEST_TYPE ( 0x01 ) ) - /** Network connection notification */ #define CDC_NETWORK_CONNECTION \ ( USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE | \ @@ -67,38 +52,4 @@ extern struct cdc_union_descriptor * cdc_union_descriptor ( struct usb_configuration_descriptor *config, struct usb_interface_descriptor *interface ); -/** - * Send encapsulated command - * - * @v usb USB device - * @v interface Interface number - * @v data Command - * @v len Length of command - * @ret rc Return status code - */ -static inline __attribute__ (( always_inline )) int -cdc_send_encapsulated_command ( struct usb_device *usb, unsigned int interface, - void *data, size_t len ) { - - return usb_control ( usb, CDC_SEND_ENCAPSULATED_COMMAND, 0, interface, - data, len ); -} - -/** -* Get encapsulated response -* -* @v usb USB device -* @v interface Interface number -* @v data Response buffer -* @v len Length of response buffer -* @ret rc Return status code -*/ -static inline __attribute__ (( always_inline )) int -cdc_get_encapsulated_response ( struct usb_device *usb, unsigned int interface, - void *data, size_t len ) { - - return usb_control ( usb, CDC_GET_ENCAPSULATED_RESPONSE, 0, interface, - data, len ); -} - #endif /* _IPXE_CDC_H */ diff --git a/roms/ipxe/src/include/ipxe/dhcp.h b/roms/ipxe/src/include/ipxe/dhcp.h index 693aa7e73..a11db3497 100644 --- a/roms/ipxe/src/include/ipxe/dhcp.h +++ b/roms/ipxe/src/include/ipxe/dhcp.h @@ -266,16 +266,12 @@ enum dhcp_client_architecture_values { DHCP_CLIENT_ARCHITECTURE_LC = 0x0005, /** EFI IA32 */ DHCP_CLIENT_ARCHITECTURE_IA32 = 0x0006, - /** EFI x86-64 */ - DHCP_CLIENT_ARCHITECTURE_X86_64 = 0x0007, + /** EFI BC */ + DHCP_CLIENT_ARCHITECTURE_EFI = 0x0007, /** EFI Xscale */ DHCP_CLIENT_ARCHITECTURE_XSCALE = 0x0008, - /** EFI BC */ - DHCP_CLIENT_ARCHITECTURE_EFI = 0x0009, - /** EFI 32-bit ARM */ - DHCP_CLIENT_ARCHITECTURE_ARM32 = 0x000a, - /** EFI 64-bit ARM */ - DHCP_CLIENT_ARCHITECTURE_ARM64 = 0x000b, + /** EFI x86-64 */ + DHCP_CLIENT_ARCHITECTURE_X86_64 = 0x0009, }; /** Client network device interface */ @@ -407,12 +403,12 @@ struct dhcp_netdev_desc { /** Use cached network settings (obsolete; do not reuse this value) */ #define DHCP_EB_USE_CACHED DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xb2 ) -/** SAN drive number +/** BIOS drive number * - * This is the drive number for a SAN-hooked drive. For BIOS, 0x80 is + * This is the drive number for a drive emulated via INT 13. 0x80 is * the first hard disk, 0x81 is the second hard disk, etc. */ -#define DHCP_EB_SAN_DRIVE DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xbd ) +#define DHCP_EB_BIOS_DRIVE DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xbd ) /** Username * diff --git a/roms/ipxe/src/include/ipxe/efi/AArch64/ProcessorBind.h b/roms/ipxe/src/include/ipxe/efi/AArch64/ProcessorBind.h deleted file mode 100644 index d4301726f..000000000 --- a/roms/ipxe/src/include/ipxe/efi/AArch64/ProcessorBind.h +++ /dev/null @@ -1,150 +0,0 @@ -/** @file - Processor or Compiler specific defines and types for AArch64. - - Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR> - Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR> - Portions copyright (c) 2011 - 2013, ARM Ltd. All rights reserved.<BR> - - This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#ifndef __PROCESSOR_BIND_H__ -#define __PROCESSOR_BIND_H__ - -FILE_LICENCE ( BSD3 ); - -/// -/// Define the processor type so other code can make processor based choices -/// -#define MDE_CPU_AARCH64 - -// -// Make sure we are using the correct packing rules per EFI specification -// -#ifndef __GNUC__ -#pragma pack() -#endif - -#if _MSC_EXTENSIONS - // - // use Microsoft* C complier dependent integer width types - // - typedef unsigned __int64 UINT64; - typedef __int64 INT64; - typedef unsigned __int32 UINT32; - typedef __int32 INT32; - typedef unsigned short UINT16; - typedef unsigned short CHAR16; - typedef short INT16; - typedef unsigned char BOOLEAN; - typedef unsigned char UINT8; - typedef char CHAR8; - typedef signed char INT8; -#else - // - // Assume standard AARCH64 alignment. - // - typedef unsigned long long UINT64; - typedef long long INT64; - typedef unsigned int UINT32; - typedef int INT32; - typedef unsigned short UINT16; - typedef unsigned short CHAR16; - typedef short INT16; - typedef unsigned char BOOLEAN; - typedef unsigned char UINT8; - typedef char CHAR8; - typedef signed char INT8; -#endif - -/// -/// Unsigned value of native width. (4 bytes on supported 32-bit processor instructions, -/// 8 bytes on supported 64-bit processor instructions) -/// -typedef UINT64 UINTN; - -/// -/// Signed value of native width. (4 bytes on supported 32-bit processor instructions, -/// 8 bytes on supported 64-bit processor instructions) -/// -typedef INT64 INTN; - -// -// Processor specific defines -// - -/// -/// A value of native width with the highest bit set. -/// -#define MAX_BIT 0x8000000000000000ULL - -/// -/// A value of native width with the two highest bits set. -/// -#define MAX_2_BITS 0xC000000000000000ULL - -/// -/// Maximum legal AARCH64 address -/// -#define MAX_ADDRESS 0xFFFFFFFFFFFFFFFFULL - -/// -/// Maximum legal AArch64 INTN and UINTN values. -/// -#define MAX_INTN ((INTN)0x7FFFFFFFFFFFFFFFULL) -#define MAX_UINTN ((UINTN)0xFFFFFFFFFFFFFFFFULL) - -/// -/// The stack alignment required for AARCH64 -/// -#define CPU_STACK_ALIGNMENT 16 - -// -// Modifier to ensure that all protocol member functions and EFI intrinsics -// use the correct C calling convention. All protocol member functions and -// EFI intrinsics are required to modify their member functions with EFIAPI. -// -#define EFIAPI - -// When compiling with Clang, we still use GNU as for the assembler, so we still -// need to define the GCC_ASM* macros. -#if defined(__GNUC__) || defined(__clang__) - /// - /// For GNU assembly code, .global or .globl can declare global symbols. - /// Define this macro to unify the usage. - /// - #define ASM_GLOBAL .globl - - #define GCC_ASM_EXPORT(func__) \ - .global _CONCATENATE (__USER_LABEL_PREFIX__, func__) ;\ - .type ASM_PFX(func__), %function - - #define GCC_ASM_IMPORT(func__) \ - .extern _CONCATENATE (__USER_LABEL_PREFIX__, func__) - -#endif - -/** - Return the pointer to the first instruction of a function given a function pointer. - On ARM CPU architectures, these two pointer values are the same, - so the implementation of this macro is very simple. - - @param FunctionPointer A pointer to a function. - - @return The pointer to the first instruction of a function given a function pointer. - -**/ -#define FUNCTION_ENTRY_POINT(FunctionPointer) (VOID *)(UINTN)(FunctionPointer) - -#ifndef __USER_LABEL_PREFIX__ -#define __USER_LABEL_PREFIX__ -#endif - -#endif diff --git a/roms/ipxe/src/include/ipxe/efi/Arm/ProcessorBind.h b/roms/ipxe/src/include/ipxe/efi/Arm/ProcessorBind.h deleted file mode 100644 index 51a727145..000000000 --- a/roms/ipxe/src/include/ipxe/efi/Arm/ProcessorBind.h +++ /dev/null @@ -1,171 +0,0 @@ -/** @file - Processor or Compiler specific defines and types for ARM. - - Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR> - Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR> - This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#ifndef __PROCESSOR_BIND_H__ -#define __PROCESSOR_BIND_H__ - -FILE_LICENCE ( BSD3 ); - -/// -/// Define the processor type so other code can make processor based choices -/// -#define MDE_CPU_ARM - -// -// Make sure we are using the correct packing rules per EFI specification -// -#ifndef __GNUC__ -#pragma pack() -#endif - -#if _MSC_EXTENSIONS - // - // use Microsoft* C complier dependent integer width types - // - typedef unsigned __int64 UINT64; - typedef __int64 INT64; - typedef unsigned __int32 UINT32; - typedef __int32 INT32; - typedef unsigned short UINT16; - typedef unsigned short CHAR16; - typedef short INT16; - typedef unsigned char BOOLEAN; - typedef unsigned char UINT8; - typedef char CHAR8; - typedef signed char INT8; -#else - // - // Assume standard ARM alignment. - // Need to check portability of long long - // - typedef unsigned long long UINT64; - typedef long long INT64; - typedef unsigned int UINT32; - typedef int INT32; - typedef unsigned short UINT16; - typedef unsigned short CHAR16; - typedef short INT16; - typedef unsigned char BOOLEAN; - typedef unsigned char UINT8; - typedef char CHAR8; - typedef signed char INT8; -#endif - -/// -/// Unsigned value of native width. (4 bytes on supported 32-bit processor instructions, -/// 8 bytes on supported 64-bit processor instructions) -/// -typedef UINT32 UINTN; - -/// -/// Signed value of native width. (4 bytes on supported 32-bit processor instructions, -/// 8 bytes on supported 64-bit processor instructions) -/// -typedef INT32 INTN; - -// -// Processor specific defines -// - -/// -/// A value of native width with the highest bit set. -/// -#define MAX_BIT 0x80000000 - -/// -/// A value of native width with the two highest bits set. -/// -#define MAX_2_BITS 0xC0000000 - -/// -/// Maximum legal ARM address -/// -#define MAX_ADDRESS 0xFFFFFFFF - -/// -/// Maximum legal ARM INTN and UINTN values. -/// -#define MAX_INTN ((INTN)0x7FFFFFFF) -#define MAX_UINTN ((UINTN)0xFFFFFFFF) - -/// -/// The stack alignment required for ARM -/// -#define CPU_STACK_ALIGNMENT sizeof(UINT64) - -// -// Modifier to ensure that all protocol member functions and EFI intrinsics -// use the correct C calling convention. All protocol member functions and -// EFI intrinsics are required to modify their member functions with EFIAPI. -// -#define EFIAPI - -// When compiling with Clang, we still use GNU as for the assembler, so we still -// need to define the GCC_ASM* macros. -#if defined(__GNUC__) || defined(__clang__) - /// - /// For GNU assembly code, .global or .globl can declare global symbols. - /// Define this macro to unify the usage. - /// - #define ASM_GLOBAL .globl - - #if !defined(__APPLE__) - /// - /// ARM EABI defines that the linker should not manipulate call relocations - /// (do bl/blx conversion) unless the target symbol has function type. - /// CodeSourcery 2010.09 started requiring the .type to function properly - /// - #define INTERWORK_FUNC(func__) .type ASM_PFX(func__), %function - - #define GCC_ASM_EXPORT(func__) \ - .global _CONCATENATE (__USER_LABEL_PREFIX__, func__) ;\ - .type ASM_PFX(func__), %function - - #define GCC_ASM_IMPORT(func__) \ - .extern _CONCATENATE (__USER_LABEL_PREFIX__, func__) - - #else - // - // .type not supported by Apple Xcode tools - // - #define INTERWORK_FUNC(func__) - - #define GCC_ASM_EXPORT(func__) \ - .globl _CONCATENATE (__USER_LABEL_PREFIX__, func__) \ - - #define GCC_ASM_IMPORT(name) - - #endif -#endif - -/** - Return the pointer to the first instruction of a function given a function pointer. - On ARM CPU architectures, these two pointer values are the same, - so the implementation of this macro is very simple. - - @param FunctionPointer A pointer to a function. - - @return The pointer to the first instruction of a function given a function pointer. - -**/ -#define FUNCTION_ENTRY_POINT(FunctionPointer) (VOID *)(UINTN)(FunctionPointer) - -#ifndef __USER_LABEL_PREFIX__ -#define __USER_LABEL_PREFIX__ -#endif - -#endif - - diff --git a/roms/ipxe/src/include/ipxe/efi/Base.h b/roms/ipxe/src/include/ipxe/efi/Base.h index 8a047aef0..844f428f1 100644 --- a/roms/ipxe/src/include/ipxe/efi/Base.h +++ b/roms/ipxe/src/include/ipxe/efi/Base.h @@ -6,7 +6,7 @@ environment. There are a set of base libraries in the Mde Package that can be used to implement base modules. -Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR> Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR> This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License @@ -29,12 +29,6 @@ FILE_LICENCE ( BSD3 ); // #include <ipxe/efi/ProcessorBind.h> -#if defined(_MSC_EXTENSIONS) -// -// Disable warning when last field of data structure is a zero sized array. -// -#pragma warning ( disable : 4200 ) -#endif /** Verifies the storage size of a given data type. @@ -943,11 +937,6 @@ typedef UINTN RETURN_STATUS; #define RETURN_COMPROMISED_DATA ENCODE_ERROR (33) /// -/// A HTTP error occurred during the network operation. -/// -#define RETURN_HTTP_ERROR ENCODE_ERROR (35) - -/// /// The string contained one or more characters that /// the device could not render and were skipped. /// @@ -976,12 +965,6 @@ typedef UINTN RETURN_STATUS; /// #define RETURN_WARN_STALE_DATA ENCODE_WARNING (5) -/// -/// The resulting buffer contains UEFI-compliant file system. -/// -#define RETURN_WARN_FILE_SYSTEM ENCODE_WARNING (6) - - /** Returns a 16-bit signature built from 2 ASCII characters. @@ -1035,46 +1018,5 @@ typedef UINTN RETURN_STATUS; #define SIGNATURE_64(A, B, C, D, E, F, G, H) \ (SIGNATURE_32 (A, B, C, D) | ((UINT64) (SIGNATURE_32 (E, F, G, H)) << 32)) -#if defined(_MSC_EXTENSIONS) && !defined (__INTEL_COMPILER) && !defined (MDE_CPU_EBC) - #pragma intrinsic(_ReturnAddress) - /** - Get the return address of the calling funcation. - - Based on intrinsic function _ReturnAddress that provides the address of - the instruction in the calling function that will be executed after - control returns to the caller. - - @param L Return Level. - - @return The return address of the calling funcation or 0 if L != 0. - - **/ - #define RETURN_ADDRESS(L) ((L == 0) ? _ReturnAddress() : (VOID *) 0) -#elif defined(__GNUC__) - void * __builtin_return_address (unsigned int level); - /** - Get the return address of the calling funcation. - - Based on built-in Function __builtin_return_address that returns - the return address of the current function, or of one of its callers. - - @param L Return Level. - - @return The return address of the calling funcation. - - **/ - #define RETURN_ADDRESS(L) __builtin_return_address (L) -#else - /** - Get the return address of the calling funcation. - - @param L Return Level. - - @return 0 as compilers don't support this feature. - - **/ - #define RETURN_ADDRESS(L) ((VOID *) 0) -#endif - #endif diff --git a/roms/ipxe/src/include/ipxe/efi/Guid/SmBios.h b/roms/ipxe/src/include/ipxe/efi/Guid/SmBios.h index 49142897a..cc4a1f946 100644 --- a/roms/ipxe/src/include/ipxe/efi/Guid/SmBios.h +++ b/roms/ipxe/src/include/ipxe/efi/Guid/SmBios.h @@ -1,11 +1,11 @@ /** @file - GUIDs used to locate the SMBIOS tables in the UEFI 2.5 system table. + GUIDs used to locate the SMBIOS tables in the UEFI 2.0 system table. - These GUIDs in the system table are the only legal ways to search for and + This GUID in the system table is the only legal way to search for and locate the SMBIOS tables. Do not search the 0xF0000 segment to find SMBIOS tables. - Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR> + Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR> This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -15,7 +15,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. @par Revision Reference: - GUIDs defined in UEFI 2.5 spec. + GUIDs defined in UEFI 2.0 spec. **/ @@ -29,12 +29,6 @@ FILE_LICENCE ( BSD3 ); 0xeb9d2d31, 0x2d88, 0x11d3, {0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \ } -#define SMBIOS3_TABLE_GUID \ - { \ - 0xf2fd1544, 0x9794, 0x4a2c, {0x99, 0x2e, 0xe5, 0xbb, 0xcf, 0x20, 0xe3, 0x94 } \ - } - extern EFI_GUID gEfiSmbiosTableGuid; -extern EFI_GUID gEfiSmbios3TableGuid; #endif diff --git a/roms/ipxe/src/include/ipxe/efi/Ia32/ProcessorBind.h b/roms/ipxe/src/include/ipxe/efi/Ia32/ProcessorBind.h index 375ff2d92..16e30b358 100644 --- a/roms/ipxe/src/include/ipxe/efi/Ia32/ProcessorBind.h +++ b/roms/ipxe/src/include/ipxe/efi/Ia32/ProcessorBind.h @@ -1,7 +1,7 @@ /** @file Processor or Compiler specific defines and types for IA-32 architecture. -Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR> This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License that accompanies this distribution. The full text of the license may be found at @@ -95,26 +95,6 @@ FILE_LICENCE ( BSD3 ); // #pragma warning ( disable : 4206 ) -#if _MSC_VER == 1800 || _MSC_VER == 1900 - -// -// Disable these warnings for VS2013. -// - -// -// This warning is for potentially uninitialized local variable, and it may cause false -// positive issues in VS2013 and VS2015 build -// -#pragma warning ( disable : 4701 ) - -// -// This warning is for potentially uninitialized local pointer variable, and it may cause -// false positive issues in VS2013 and VS2015 build -// -#pragma warning ( disable : 4703 ) - -#endif - #endif diff --git a/roms/ipxe/src/include/ipxe/efi/IndustryStandard/Acpi20.h b/roms/ipxe/src/include/ipxe/efi/IndustryStandard/Acpi20.h deleted file mode 100644 index f5ff44c9c..000000000 --- a/roms/ipxe/src/include/ipxe/efi/IndustryStandard/Acpi20.h +++ /dev/null @@ -1,547 +0,0 @@ -/** @file - ACPI 2.0 definitions from the ACPI Specification, revision 2.0 - - Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR> - This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -**/ - -#ifndef _ACPI_2_0_H_ -#define _ACPI_2_0_H_ - -FILE_LICENCE ( BSD3 ); - -#include <ipxe/efi/IndustryStandard/Acpi10.h> - -// -// Define for Desriptor -// -#define ACPI_LARGE_GENERIC_REGISTER_DESCRIPTOR_NAME 0x02 - -#define ACPI_GENERIC_REGISTER_DESCRIPTOR 0x82 - -// -// Ensure proper structure formats -// -#pragma pack(1) - -/// -/// Generic Register Descriptor -/// -typedef PACKED struct { - ACPI_LARGE_RESOURCE_HEADER Header; - UINT8 AddressSpaceId; - UINT8 RegisterBitWidth; - UINT8 RegisterBitOffset; - UINT8 AddressSize; - UINT64 RegisterAddress; -} EFI_ACPI_GENERIC_REGISTER_DESCRIPTOR; - -#pragma pack() - -// -// Ensure proper structure formats -// -#pragma pack(1) - -/// -/// ACPI 2.0 Generic Address Space definition -/// -typedef struct { - UINT8 AddressSpaceId; - UINT8 RegisterBitWidth; - UINT8 RegisterBitOffset; - UINT8 Reserved; - UINT64 Address; -} EFI_ACPI_2_0_GENERIC_ADDRESS_STRUCTURE; - -// -// Generic Address Space Address IDs -// -#define EFI_ACPI_2_0_SYSTEM_MEMORY 0 -#define EFI_ACPI_2_0_SYSTEM_IO 1 -#define EFI_ACPI_2_0_PCI_CONFIGURATION_SPACE 2 -#define EFI_ACPI_2_0_EMBEDDED_CONTROLLER 3 -#define EFI_ACPI_2_0_SMBUS 4 -#define EFI_ACPI_2_0_FUNCTIONAL_FIXED_HARDWARE 0x7F - -// -// ACPI 2.0 table structures -// - -/// -/// Root System Description Pointer Structure -/// -typedef struct { - UINT64 Signature; - UINT8 Checksum; - UINT8 OemId[6]; - UINT8 Revision; - UINT32 RsdtAddress; - UINT32 Length; - UINT64 XsdtAddress; - UINT8 ExtendedChecksum; - UINT8 Reserved[3]; -} EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER; - -/// -/// RSD_PTR Revision (as defined in ACPI 2.0 spec.) -/// -#define EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER_REVISION 0x02 - -/// -/// Common table header, this prefaces all ACPI tables, including FACS, but -/// excluding the RSD PTR structure -/// -typedef struct { - UINT32 Signature; - UINT32 Length; -} EFI_ACPI_2_0_COMMON_HEADER; - -// -// Root System Description Table -// No definition needed as it is a common description table header, the same with -// EFI_ACPI_DESCRIPTION_HEADER, followed by a variable number of UINT32 table pointers. -// - -/// -/// RSDT Revision (as defined in ACPI 2.0 spec.) -/// -#define EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION 0x01 - -// -// Extended System Description Table -// No definition needed as it is a common description table header, the same with -// EFI_ACPI_DESCRIPTION_HEADER, followed by a variable number of UINT64 table pointers. -// - -/// -/// XSDT Revision (as defined in ACPI 2.0 spec.) -/// -#define EFI_ACPI_2_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_REVISION 0x01 - -/// -/// Fixed ACPI Description Table Structure (FADT) -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 FirmwareCtrl; - UINT32 Dsdt; - UINT8 Reserved0; - UINT8 PreferredPmProfile; - UINT16 SciInt; - UINT32 SmiCmd; - UINT8 AcpiEnable; - UINT8 AcpiDisable; - UINT8 S4BiosReq; - UINT8 PstateCnt; - UINT32 Pm1aEvtBlk; - UINT32 Pm1bEvtBlk; - UINT32 Pm1aCntBlk; - UINT32 Pm1bCntBlk; - UINT32 Pm2CntBlk; - UINT32 PmTmrBlk; - UINT32 Gpe0Blk; - UINT32 Gpe1Blk; - UINT8 Pm1EvtLen; - UINT8 Pm1CntLen; - UINT8 Pm2CntLen; - UINT8 PmTmrLen; - UINT8 Gpe0BlkLen; - UINT8 Gpe1BlkLen; - UINT8 Gpe1Base; - UINT8 CstCnt; - UINT16 PLvl2Lat; - UINT16 PLvl3Lat; - UINT16 FlushSize; - UINT16 FlushStride; - UINT8 DutyOffset; - UINT8 DutyWidth; - UINT8 DayAlrm; - UINT8 MonAlrm; - UINT8 Century; - UINT16 IaPcBootArch; - UINT8 Reserved1; - UINT32 Flags; - EFI_ACPI_2_0_GENERIC_ADDRESS_STRUCTURE ResetReg; - UINT8 ResetValue; - UINT8 Reserved2[3]; - UINT64 XFirmwareCtrl; - UINT64 XDsdt; - EFI_ACPI_2_0_GENERIC_ADDRESS_STRUCTURE XPm1aEvtBlk; - EFI_ACPI_2_0_GENERIC_ADDRESS_STRUCTURE XPm1bEvtBlk; - EFI_ACPI_2_0_GENERIC_ADDRESS_STRUCTURE XPm1aCntBlk; - EFI_ACPI_2_0_GENERIC_ADDRESS_STRUCTURE XPm1bCntBlk; - EFI_ACPI_2_0_GENERIC_ADDRESS_STRUCTURE XPm2CntBlk; - EFI_ACPI_2_0_GENERIC_ADDRESS_STRUCTURE XPmTmrBlk; - EFI_ACPI_2_0_GENERIC_ADDRESS_STRUCTURE XGpe0Blk; - EFI_ACPI_2_0_GENERIC_ADDRESS_STRUCTURE XGpe1Blk; -} EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE; - -/// -/// FADT Version (as defined in ACPI 2.0 spec.) -/// -#define EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE_REVISION 0x03 - -// -// Fixed ACPI Description Table Preferred Power Management Profile -// -#define EFI_ACPI_2_0_PM_PROFILE_UNSPECIFIED 0 -#define EFI_ACPI_2_0_PM_PROFILE_DESKTOP 1 -#define EFI_ACPI_2_0_PM_PROFILE_MOBILE 2 -#define EFI_ACPI_2_0_PM_PROFILE_WORKSTATION 3 -#define EFI_ACPI_2_0_PM_PROFILE_ENTERPRISE_SERVER 4 -#define EFI_ACPI_2_0_PM_PROFILE_SOHO_SERVER 5 -#define EFI_ACPI_2_0_PM_PROFILE_APPLIANCE_PC 6 - -// -// Fixed ACPI Description Table Boot Architecture Flags -// All other bits are reserved and must be set to 0. -// -#define EFI_ACPI_2_0_LEGACY_DEVICES BIT0 -#define EFI_ACPI_2_0_8042 BIT1 - -// -// Fixed ACPI Description Table Fixed Feature Flags -// All other bits are reserved and must be set to 0. -// -#define EFI_ACPI_2_0_WBINVD BIT0 -#define EFI_ACPI_2_0_WBINVD_FLUSH BIT1 -#define EFI_ACPI_2_0_PROC_C1 BIT2 -#define EFI_ACPI_2_0_P_LVL2_UP BIT3 -#define EFI_ACPI_2_0_PWR_BUTTON BIT4 -#define EFI_ACPI_2_0_SLP_BUTTON BIT5 -#define EFI_ACPI_2_0_FIX_RTC BIT6 -#define EFI_ACPI_2_0_RTC_S4 BIT7 -#define EFI_ACPI_2_0_TMR_VAL_EXT BIT8 -#define EFI_ACPI_2_0_DCK_CAP BIT9 -#define EFI_ACPI_2_0_RESET_REG_SUP BIT10 -#define EFI_ACPI_2_0_SEALED_CASE BIT11 -#define EFI_ACPI_2_0_HEADLESS BIT12 -#define EFI_ACPI_2_0_CPU_SW_SLP BIT13 - -/// -/// Firmware ACPI Control Structure -/// -typedef struct { - UINT32 Signature; - UINT32 Length; - UINT32 HardwareSignature; - UINT32 FirmwareWakingVector; - UINT32 GlobalLock; - UINT32 Flags; - UINT64 XFirmwareWakingVector; - UINT8 Version; - UINT8 Reserved[31]; -} EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE; - -/// -/// FACS Version (as defined in ACPI 2.0 spec.) -/// -#define EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_VERSION 0x01 - -/// -/// Firmware Control Structure Feature Flags -/// All other bits are reserved and must be set to 0. -/// -#define EFI_ACPI_2_0_S4BIOS_F BIT0 - -/// -/// Multiple APIC Description Table header definition. The rest of the table -/// must be defined in a platform specific manner. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 LocalApicAddress; - UINT32 Flags; -} EFI_ACPI_2_0_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER; - -/// -/// MADT Revision (as defined in ACPI 2.0 spec.) -/// -#define EFI_ACPI_2_0_MULTIPLE_APIC_DESCRIPTION_TABLE_REVISION 0x01 - -/// -/// Multiple APIC Flags -/// All other bits are reserved and must be set to 0. -/// -#define EFI_ACPI_2_0_PCAT_COMPAT BIT0 - -// -// Multiple APIC Description Table APIC structure types -// All other values between 0x09 an 0xFF are reserved and -// will be ignored by OSPM. -// -#define EFI_ACPI_2_0_PROCESSOR_LOCAL_APIC 0x00 -#define EFI_ACPI_2_0_IO_APIC 0x01 -#define EFI_ACPI_2_0_INTERRUPT_SOURCE_OVERRIDE 0x02 -#define EFI_ACPI_2_0_NON_MASKABLE_INTERRUPT_SOURCE 0x03 -#define EFI_ACPI_2_0_LOCAL_APIC_NMI 0x04 -#define EFI_ACPI_2_0_LOCAL_APIC_ADDRESS_OVERRIDE 0x05 -#define EFI_ACPI_2_0_IO_SAPIC 0x06 -#define EFI_ACPI_2_0_PROCESSOR_LOCAL_SAPIC 0x07 -#define EFI_ACPI_2_0_PLATFORM_INTERRUPT_SOURCES 0x08 - -// -// APIC Structure Definitions -// - -/// -/// Processor Local APIC Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 AcpiProcessorId; - UINT8 ApicId; - UINT32 Flags; -} EFI_ACPI_2_0_PROCESSOR_LOCAL_APIC_STRUCTURE; - -/// -/// Local APIC Flags. All other bits are reserved and must be 0. -/// -#define EFI_ACPI_2_0_LOCAL_APIC_ENABLED BIT0 - -/// -/// IO APIC Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 IoApicId; - UINT8 Reserved; - UINT32 IoApicAddress; - UINT32 GlobalSystemInterruptBase; -} EFI_ACPI_2_0_IO_APIC_STRUCTURE; - -/// -/// Interrupt Source Override Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 Bus; - UINT8 Source; - UINT32 GlobalSystemInterrupt; - UINT16 Flags; -} EFI_ACPI_2_0_INTERRUPT_SOURCE_OVERRIDE_STRUCTURE; - -/// -/// Non-Maskable Interrupt Source Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT16 Flags; - UINT32 GlobalSystemInterrupt; -} EFI_ACPI_2_0_NON_MASKABLE_INTERRUPT_SOURCE_STRUCTURE; - -/// -/// Local APIC NMI Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 AcpiProcessorId; - UINT16 Flags; - UINT8 LocalApicLint; -} EFI_ACPI_2_0_LOCAL_APIC_NMI_STRUCTURE; - -/// -/// Local APIC Address Override Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT16 Reserved; - UINT64 LocalApicAddress; -} EFI_ACPI_2_0_LOCAL_APIC_ADDRESS_OVERRIDE_STRUCTURE; - -/// -/// IO SAPIC Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 IoApicId; - UINT8 Reserved; - UINT32 GlobalSystemInterruptBase; - UINT64 IoSapicAddress; -} EFI_ACPI_2_0_IO_SAPIC_STRUCTURE; - -/// -/// Local SAPIC Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 AcpiProcessorId; - UINT8 LocalSapicId; - UINT8 LocalSapicEid; - UINT8 Reserved[3]; - UINT32 Flags; -} EFI_ACPI_2_0_PROCESSOR_LOCAL_SAPIC_STRUCTURE; - -/// -/// Platform Interrupt Sources Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT16 Flags; - UINT8 InterruptType; - UINT8 ProcessorId; - UINT8 ProcessorEid; - UINT8 IoSapicVector; - UINT32 GlobalSystemInterrupt; - UINT32 Reserved; -} EFI_ACPI_2_0_PLATFORM_INTERRUPT_SOURCES_STRUCTURE; - -/// -/// Smart Battery Description Table (SBST) -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 WarningEnergyLevel; - UINT32 LowEnergyLevel; - UINT32 CriticalEnergyLevel; -} EFI_ACPI_2_0_SMART_BATTERY_DESCRIPTION_TABLE; - -/// -/// SBST Version (as defined in ACPI 2.0 spec.) -/// -#define EFI_ACPI_2_0_SMART_BATTERY_DESCRIPTION_TABLE_REVISION 0x01 - -/// -/// Embedded Controller Boot Resources Table (ECDT) -/// The table is followed by a null terminated ASCII string that contains -/// a fully qualified reference to the name space object. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - EFI_ACPI_2_0_GENERIC_ADDRESS_STRUCTURE EcControl; - EFI_ACPI_2_0_GENERIC_ADDRESS_STRUCTURE EcData; - UINT32 Uid; - UINT8 GpeBit; -} EFI_ACPI_2_0_EMBEDDED_CONTROLLER_BOOT_RESOURCES_TABLE; - -/// -/// ECDT Version (as defined in ACPI 2.0 spec.) -/// -#define EFI_ACPI_2_0_EMBEDDED_CONTROLLER_BOOT_RESOURCES_TABLE_REVISION 0x01 - -// -// Known table signatures -// - -/// -/// "RSD PTR " Root System Description Pointer -/// -#define EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE SIGNATURE_64('R', 'S', 'D', ' ', 'P', 'T', 'R', ' ') - -/// -/// "SPIC" Multiple SAPIC Description Table -/// -/// BUGBUG: Don't know where this came from except SR870BN4 uses it. -/// #define EFI_ACPI_2_0_MULTIPLE_SAPIC_DESCRIPTION_TABLE_SIGNATURE 0x43495053 -/// -#define EFI_ACPI_2_0_MULTIPLE_SAPIC_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('A', 'P', 'I', 'C') - -/// -/// "BOOT" MS Simple Boot Spec -/// -#define EFI_ACPI_2_0_SIMPLE_BOOT_FLAG_TABLE_SIGNATURE SIGNATURE_32('B', 'O', 'O', 'T') - -/// -/// "DBGP" MS Bebug Port Spec -/// -#define EFI_ACPI_2_0_DEBUG_PORT_TABLE_SIGNATURE SIGNATURE_32('D', 'B', 'G', 'P') - -/// -/// "DSDT" Differentiated System Description Table -/// -#define EFI_ACPI_2_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('D', 'S', 'D', 'T') - -/// -/// "ECDT" Embedded Controller Boot Resources Table -/// -#define EFI_ACPI_2_0_EMBEDDED_CONTROLLER_BOOT_RESOURCES_TABLE_SIGNATURE SIGNATURE_32('E', 'C', 'D', 'T') - -/// -/// "ETDT" Event Timer Description Table -/// -#define EFI_ACPI_2_0_EVENT_TIMER_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('E', 'T', 'D', 'T') - -/// -/// "FACS" Firmware ACPI Control Structure -/// -#define EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE SIGNATURE_32('F', 'A', 'C', 'S') - -/// -/// "FACP" Fixed ACPI Description Table -/// -#define EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('F', 'A', 'C', 'P') - -/// -/// "APIC" Multiple APIC Description Table -/// -#define EFI_ACPI_2_0_MULTIPLE_APIC_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('A', 'P', 'I', 'C') - -/// -/// "PSDT" Persistent System Description Table -/// -#define EFI_ACPI_2_0_PERSISTENT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('P', 'S', 'D', 'T') - -/// -/// "RSDT" Root System Description Table -/// -#define EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('R', 'S', 'D', 'T') - -/// -/// "SBST" Smart Battery Specification Table -/// -#define EFI_ACPI_2_0_SMART_BATTERY_SPECIFICATION_TABLE_SIGNATURE SIGNATURE_32('S', 'B', 'S', 'T') - -/// -/// "SLIT" System Locality Information Table -/// -#define EFI_ACPI_2_0_SYSTEM_LOCALITY_INFORMATION_TABLE_SIGNATURE SIGNATURE_32('S', 'L', 'I', 'T') - -/// -/// "SPCR" Serial Port Concole Redirection Table -/// -#define EFI_ACPI_2_0_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_SIGNATURE SIGNATURE_32('S', 'P', 'C', 'R') - -/// -/// "SRAT" Static Resource Affinity Table -/// -#define EFI_ACPI_2_0_STATIC_RESOURCE_AFFINITY_TABLE_SIGNATURE SIGNATURE_32('S', 'R', 'A', 'T') - -/// -/// "SSDT" Secondary System Description Table -/// -#define EFI_ACPI_2_0_SECONDARY_SYSTEM_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('S', 'S', 'D', 'T') - -/// -/// "SPMI" Server Platform Management Interface Table -/// -#define EFI_ACPI_2_0_SERVER_PLATFORM_MANAGEMENT_INTERFACE_SIGNATURE SIGNATURE_32('S', 'P', 'M', 'I') - -/// -/// "XSDT" Extended System Description Table -/// -#define EFI_ACPI_2_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('X', 'S', 'D', 'T') - -/// -/// "MCFG" PCI Express Memory Mapped Configuration Space Base Address Description Table -/// -#define EFI_ACPI_2_0_MEMORY_MAPPED_CONFIGURATION_BASE_ADDRESS_TABLE_SIGNATURE SIGNATURE_32('M', 'C', 'F', 'G') - -#pragma pack() - -#endif diff --git a/roms/ipxe/src/include/ipxe/efi/IndustryStandard/Acpi30.h b/roms/ipxe/src/include/ipxe/efi/IndustryStandard/Acpi30.h deleted file mode 100644 index abaa72128..000000000 --- a/roms/ipxe/src/include/ipxe/efi/IndustryStandard/Acpi30.h +++ /dev/null @@ -1,731 +0,0 @@ -/** @file - ACPI 3.0 definitions from the ACPI Specification Revision 3.0b October 10, 2006 - - Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR> - This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -**/ - -#ifndef _ACPI_3_0_H_ -#define _ACPI_3_0_H_ - -FILE_LICENCE ( BSD3 ); - -#include <ipxe/efi/IndustryStandard/Acpi20.h> - -// -// Define for Desriptor -// -#define ACPI_LARGE_EXTENDED_ADDRESS_SPACE_DESCRIPTOR_NAME 0x0B - -#define ACPI_EXTENDED_ADDRESS_SPACE_DESCRIPTOR 0x8B - -// -// Ensure proper structure formats -// -#pragma pack(1) - -/// -/// Extended Address Space Descriptor -/// -typedef PACKED struct { - ACPI_LARGE_RESOURCE_HEADER Header; - UINT8 ResType; - UINT8 GenFlag; - UINT8 SpecificFlag; - UINT8 RevisionId; - UINT8 Reserved; - UINT64 AddrSpaceGranularity; - UINT64 AddrRangeMin; - UINT64 AddrRangeMax; - UINT64 AddrTranslationOffset; - UINT64 AddrLen; - UINT64 TypeSpecificAttribute; -} EFI_ACPI_EXTENDED_ADDRESS_SPACE_DESCRIPTOR; - -#pragma pack() - -// -// Memory Type Specific Flags -// -#define EFI_ACPI_MEMORY_TYPE_SPECIFIC_ATTRIBUTES_UC 0x0000000000000001 -#define EFI_ACPI_MEMORY_TYPE_SPECIFIC_ATTRIBUTES_WC 0x0000000000000002 -#define EFI_ACPI_MEMORY_TYPE_SPECIFIC_ATTRIBUTES_WT 0x0000000000000004 -#define EFI_ACPI_MEMORY_TYPE_SPECIFIC_ATTRIBUTES_WB 0x0000000000000008 -#define EFI_ACPI_MEMORY_TYPE_SPECIFIC_ATTRIBUTES_UCE 0x0000000000000010 -#define EFI_ACPI_MEMORY_TYPE_SPECIFIC_ATTRIBUTES_NV 0x0000000000008000 - -// -// Ensure proper structure formats -// -#pragma pack(1) - -/// -/// ACPI 3.0 Generic Address Space definition -/// -typedef struct { - UINT8 AddressSpaceId; - UINT8 RegisterBitWidth; - UINT8 RegisterBitOffset; - UINT8 AccessSize; - UINT64 Address; -} EFI_ACPI_3_0_GENERIC_ADDRESS_STRUCTURE; - -// -// Generic Address Space Address IDs -// -#define EFI_ACPI_3_0_SYSTEM_MEMORY 0 -#define EFI_ACPI_3_0_SYSTEM_IO 1 -#define EFI_ACPI_3_0_PCI_CONFIGURATION_SPACE 2 -#define EFI_ACPI_3_0_EMBEDDED_CONTROLLER 3 -#define EFI_ACPI_3_0_SMBUS 4 -#define EFI_ACPI_3_0_FUNCTIONAL_FIXED_HARDWARE 0x7F - -// -// Generic Address Space Access Sizes -// -#define EFI_ACPI_3_0_UNDEFINED 0 -#define EFI_ACPI_3_0_BYTE 1 -#define EFI_ACPI_3_0_WORD 2 -#define EFI_ACPI_3_0_DWORD 3 -#define EFI_ACPI_3_0_QWORD 4 - -// -// ACPI 3.0 table structures -// - -/// -/// Root System Description Pointer Structure -/// -typedef struct { - UINT64 Signature; - UINT8 Checksum; - UINT8 OemId[6]; - UINT8 Revision; - UINT32 RsdtAddress; - UINT32 Length; - UINT64 XsdtAddress; - UINT8 ExtendedChecksum; - UINT8 Reserved[3]; -} EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER; - -/// -/// RSD_PTR Revision (as defined in ACPI 3.0b spec.) -/// -#define EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_REVISION 0x02 ///< ACPISpec (Revision 3.0b) says current value is 2 - -/// -/// Common table header, this prefaces all ACPI tables, including FACS, but -/// excluding the RSD PTR structure -/// -typedef struct { - UINT32 Signature; - UINT32 Length; -} EFI_ACPI_3_0_COMMON_HEADER; - -// -// Root System Description Table -// No definition needed as it is a common description table header, the same with -// EFI_ACPI_DESCRIPTION_HEADER, followed by a variable number of UINT32 table pointers. -// - -/// -/// RSDT Revision (as defined in ACPI 3.0 spec.) -/// -#define EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION 0x01 - -// -// Extended System Description Table -// No definition needed as it is a common description table header, the same with -// EFI_ACPI_DESCRIPTION_HEADER, followed by a variable number of UINT64 table pointers. -// - -/// -/// XSDT Revision (as defined in ACPI 3.0 spec.) -/// -#define EFI_ACPI_3_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_REVISION 0x01 - -/// -/// Fixed ACPI Description Table Structure (FADT) -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 FirmwareCtrl; - UINT32 Dsdt; - UINT8 Reserved0; - UINT8 PreferredPmProfile; - UINT16 SciInt; - UINT32 SmiCmd; - UINT8 AcpiEnable; - UINT8 AcpiDisable; - UINT8 S4BiosReq; - UINT8 PstateCnt; - UINT32 Pm1aEvtBlk; - UINT32 Pm1bEvtBlk; - UINT32 Pm1aCntBlk; - UINT32 Pm1bCntBlk; - UINT32 Pm2CntBlk; - UINT32 PmTmrBlk; - UINT32 Gpe0Blk; - UINT32 Gpe1Blk; - UINT8 Pm1EvtLen; - UINT8 Pm1CntLen; - UINT8 Pm2CntLen; - UINT8 PmTmrLen; - UINT8 Gpe0BlkLen; - UINT8 Gpe1BlkLen; - UINT8 Gpe1Base; - UINT8 CstCnt; - UINT16 PLvl2Lat; - UINT16 PLvl3Lat; - UINT16 FlushSize; - UINT16 FlushStride; - UINT8 DutyOffset; - UINT8 DutyWidth; - UINT8 DayAlrm; - UINT8 MonAlrm; - UINT8 Century; - UINT16 IaPcBootArch; - UINT8 Reserved1; - UINT32 Flags; - EFI_ACPI_3_0_GENERIC_ADDRESS_STRUCTURE ResetReg; - UINT8 ResetValue; - UINT8 Reserved2[3]; - UINT64 XFirmwareCtrl; - UINT64 XDsdt; - EFI_ACPI_3_0_GENERIC_ADDRESS_STRUCTURE XPm1aEvtBlk; - EFI_ACPI_3_0_GENERIC_ADDRESS_STRUCTURE XPm1bEvtBlk; - EFI_ACPI_3_0_GENERIC_ADDRESS_STRUCTURE XPm1aCntBlk; - EFI_ACPI_3_0_GENERIC_ADDRESS_STRUCTURE XPm1bCntBlk; - EFI_ACPI_3_0_GENERIC_ADDRESS_STRUCTURE XPm2CntBlk; - EFI_ACPI_3_0_GENERIC_ADDRESS_STRUCTURE XPmTmrBlk; - EFI_ACPI_3_0_GENERIC_ADDRESS_STRUCTURE XGpe0Blk; - EFI_ACPI_3_0_GENERIC_ADDRESS_STRUCTURE XGpe1Blk; -} EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE; - -/// -/// FADT Version (as defined in ACPI 3.0 spec.) -/// -#define EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_REVISION 0x04 - -// -// Fixed ACPI Description Table Preferred Power Management Profile -// -#define EFI_ACPI_3_0_PM_PROFILE_UNSPECIFIED 0 -#define EFI_ACPI_3_0_PM_PROFILE_DESKTOP 1 -#define EFI_ACPI_3_0_PM_PROFILE_MOBILE 2 -#define EFI_ACPI_3_0_PM_PROFILE_WORKSTATION 3 -#define EFI_ACPI_3_0_PM_PROFILE_ENTERPRISE_SERVER 4 -#define EFI_ACPI_3_0_PM_PROFILE_SOHO_SERVER 5 -#define EFI_ACPI_3_0_PM_PROFILE_APPLIANCE_PC 6 -#define EFI_ACPI_3_0_PM_PROFILE_PERFORMANCE_SERVER 7 - -// -// Fixed ACPI Description Table Boot Architecture Flags -// All other bits are reserved and must be set to 0. -// -#define EFI_ACPI_3_0_LEGACY_DEVICES BIT0 -#define EFI_ACPI_3_0_8042 BIT1 -#define EFI_ACPI_3_0_VGA_NOT_PRESENT BIT2 -#define EFI_ACPI_3_0_MSI_NOT_SUPPORTED BIT3 -#define EFI_ACPI_3_0_PCIE_ASPM_CONTROLS BIT4 - -// -// Fixed ACPI Description Table Fixed Feature Flags -// All other bits are reserved and must be set to 0. -// -#define EFI_ACPI_3_0_WBINVD BIT0 -#define EFI_ACPI_3_0_WBINVD_FLUSH BIT1 -#define EFI_ACPI_3_0_PROC_C1 BIT2 -#define EFI_ACPI_3_0_P_LVL2_UP BIT3 -#define EFI_ACPI_3_0_PWR_BUTTON BIT4 -#define EFI_ACPI_3_0_SLP_BUTTON BIT5 -#define EFI_ACPI_3_0_FIX_RTC BIT6 -#define EFI_ACPI_3_0_RTC_S4 BIT7 -#define EFI_ACPI_3_0_TMR_VAL_EXT BIT8 -#define EFI_ACPI_3_0_DCK_CAP BIT9 -#define EFI_ACPI_3_0_RESET_REG_SUP BIT10 -#define EFI_ACPI_3_0_SEALED_CASE BIT11 -#define EFI_ACPI_3_0_HEADLESS BIT12 -#define EFI_ACPI_3_0_CPU_SW_SLP BIT13 -#define EFI_ACPI_3_0_PCI_EXP_WAK BIT14 -#define EFI_ACPI_3_0_USE_PLATFORM_CLOCK BIT15 -#define EFI_ACPI_3_0_S4_RTC_STS_VALID BIT16 -#define EFI_ACPI_3_0_REMOTE_POWER_ON_CAPABLE BIT17 -#define EFI_ACPI_3_0_FORCE_APIC_CLUSTER_MODEL BIT18 -#define EFI_ACPI_3_0_FORCE_APIC_PHYSICAL_DESTINATION_MODE BIT19 - -/// -/// Firmware ACPI Control Structure -/// -typedef struct { - UINT32 Signature; - UINT32 Length; - UINT32 HardwareSignature; - UINT32 FirmwareWakingVector; - UINT32 GlobalLock; - UINT32 Flags; - UINT64 XFirmwareWakingVector; - UINT8 Version; - UINT8 Reserved[31]; -} EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE; - -/// -/// FACS Version (as defined in ACPI 3.0 spec.) -/// -#define EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_VERSION 0x01 - -/// -/// Firmware Control Structure Feature Flags -/// All other bits are reserved and must be set to 0. -/// -#define EFI_ACPI_3_0_S4BIOS_F BIT0 - -// -// Differentiated System Description Table, -// Secondary System Description Table -// and Persistent System Description Table, -// no definition needed as they are common description table header, the same with -// EFI_ACPI_DESCRIPTION_HEADER, followed by a definition block. -// -#define EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_REVISION 0x02 -#define EFI_ACPI_3_0_SECONDARY_SYSTEM_DESCRIPTION_TABLE_REVISION 0x02 - -/// -/// Multiple APIC Description Table header definition. The rest of the table -/// must be defined in a platform specific manner. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 LocalApicAddress; - UINT32 Flags; -} EFI_ACPI_3_0_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER; - -/// -/// MADT Revision (as defined in ACPI 3.0 spec.) -/// -#define EFI_ACPI_3_0_MULTIPLE_APIC_DESCRIPTION_TABLE_REVISION 0x02 - -/// -/// Multiple APIC Flags -/// All other bits are reserved and must be set to 0. -/// -#define EFI_ACPI_3_0_PCAT_COMPAT BIT0 - -// -// Multiple APIC Description Table APIC structure types -// All other values between 0x09 an 0xFF are reserved and -// will be ignored by OSPM. -// -#define EFI_ACPI_3_0_PROCESSOR_LOCAL_APIC 0x00 -#define EFI_ACPI_3_0_IO_APIC 0x01 -#define EFI_ACPI_3_0_INTERRUPT_SOURCE_OVERRIDE 0x02 -#define EFI_ACPI_3_0_NON_MASKABLE_INTERRUPT_SOURCE 0x03 -#define EFI_ACPI_3_0_LOCAL_APIC_NMI 0x04 -#define EFI_ACPI_3_0_LOCAL_APIC_ADDRESS_OVERRIDE 0x05 -#define EFI_ACPI_3_0_IO_SAPIC 0x06 -#define EFI_ACPI_3_0_LOCAL_SAPIC 0x07 -#define EFI_ACPI_3_0_PLATFORM_INTERRUPT_SOURCES 0x08 - -// -// APIC Structure Definitions -// - -/// -/// Processor Local APIC Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 AcpiProcessorId; - UINT8 ApicId; - UINT32 Flags; -} EFI_ACPI_3_0_PROCESSOR_LOCAL_APIC_STRUCTURE; - -/// -/// Local APIC Flags. All other bits are reserved and must be 0. -/// -#define EFI_ACPI_3_0_LOCAL_APIC_ENABLED BIT0 - -/// -/// IO APIC Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 IoApicId; - UINT8 Reserved; - UINT32 IoApicAddress; - UINT32 GlobalSystemInterruptBase; -} EFI_ACPI_3_0_IO_APIC_STRUCTURE; - -/// -/// Interrupt Source Override Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 Bus; - UINT8 Source; - UINT32 GlobalSystemInterrupt; - UINT16 Flags; -} EFI_ACPI_3_0_INTERRUPT_SOURCE_OVERRIDE_STRUCTURE; - -/// -/// Platform Interrupt Sources Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT16 Flags; - UINT8 InterruptType; - UINT8 ProcessorId; - UINT8 ProcessorEid; - UINT8 IoSapicVector; - UINT32 GlobalSystemInterrupt; - UINT32 PlatformInterruptSourceFlags; - UINT8 CpeiProcessorOverride; - UINT8 Reserved[31]; -} EFI_ACPI_3_0_PLATFORM_INTERRUPT_APIC_STRUCTURE; - -// -// MPS INTI flags. -// All other bits are reserved and must be set to 0. -// -#define EFI_ACPI_3_0_POLARITY (3 << 0) -#define EFI_ACPI_3_0_TRIGGER_MODE (3 << 2) - -/// -/// Non-Maskable Interrupt Source Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT16 Flags; - UINT32 GlobalSystemInterrupt; -} EFI_ACPI_3_0_NON_MASKABLE_INTERRUPT_SOURCE_STRUCTURE; - -/// -/// Local APIC NMI Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 AcpiProcessorId; - UINT16 Flags; - UINT8 LocalApicLint; -} EFI_ACPI_3_0_LOCAL_APIC_NMI_STRUCTURE; - -/// -/// Local APIC Address Override Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT16 Reserved; - UINT64 LocalApicAddress; -} EFI_ACPI_3_0_LOCAL_APIC_ADDRESS_OVERRIDE_STRUCTURE; - -/// -/// IO SAPIC Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 IoApicId; - UINT8 Reserved; - UINT32 GlobalSystemInterruptBase; - UINT64 IoSapicAddress; -} EFI_ACPI_3_0_IO_SAPIC_STRUCTURE; - -/// -/// Local SAPIC Structure -/// This struct followed by a null-terminated ASCII string - ACPI Processor UID String -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 AcpiProcessorId; - UINT8 LocalSapicId; - UINT8 LocalSapicEid; - UINT8 Reserved[3]; - UINT32 Flags; - UINT32 ACPIProcessorUIDValue; -} EFI_ACPI_3_0_PROCESSOR_LOCAL_SAPIC_STRUCTURE; - -/// -/// Platform Interrupt Sources Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT16 Flags; - UINT8 InterruptType; - UINT8 ProcessorId; - UINT8 ProcessorEid; - UINT8 IoSapicVector; - UINT32 GlobalSystemInterrupt; - UINT32 PlatformInterruptSourceFlags; -} EFI_ACPI_3_0_PLATFORM_INTERRUPT_SOURCES_STRUCTURE; - -/// -/// Platform Interrupt Source Flags. -/// All other bits are reserved and must be set to 0. -/// -#define EFI_ACPI_3_0_CPEI_PROCESSOR_OVERRIDE BIT0 - -/// -/// Smart Battery Description Table (SBST) -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 WarningEnergyLevel; - UINT32 LowEnergyLevel; - UINT32 CriticalEnergyLevel; -} EFI_ACPI_3_0_SMART_BATTERY_DESCRIPTION_TABLE; - -/// -/// SBST Version (as defined in ACPI 3.0 spec.) -/// -#define EFI_ACPI_3_0_SMART_BATTERY_DESCRIPTION_TABLE_REVISION 0x01 - -/// -/// Embedded Controller Boot Resources Table (ECDT) -/// The table is followed by a null terminated ASCII string that contains -/// a fully qualified reference to the name space object. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - EFI_ACPI_3_0_GENERIC_ADDRESS_STRUCTURE EcControl; - EFI_ACPI_3_0_GENERIC_ADDRESS_STRUCTURE EcData; - UINT32 Uid; - UINT8 GpeBit; -} EFI_ACPI_3_0_EMBEDDED_CONTROLLER_BOOT_RESOURCES_TABLE; - -/// -/// ECDT Version (as defined in ACPI 3.0 spec.) -/// -#define EFI_ACPI_3_0_EMBEDDED_CONTROLLER_BOOT_RESOURCES_TABLE_REVISION 0x01 - -/// -/// System Resource Affinity Table (SRAT. The rest of the table -/// must be defined in a platform specific manner. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 Reserved1; ///< Must be set to 1 - UINT64 Reserved2; -} EFI_ACPI_3_0_SYSTEM_RESOURCE_AFFINITY_TABLE_HEADER; - -/// -/// SRAT Version (as defined in ACPI 3.0 spec.) -/// -#define EFI_ACPI_3_0_SYSTEM_RESOURCE_AFFINITY_TABLE_REVISION 0x02 - -// -// SRAT structure types. -// All other values between 0x02 an 0xFF are reserved and -// will be ignored by OSPM. -// -#define EFI_ACPI_3_0_PROCESSOR_LOCAL_APIC_SAPIC_AFFINITY 0x00 -#define EFI_ACPI_3_0_MEMORY_AFFINITY 0x01 - -/// -/// Processor Local APIC/SAPIC Affinity Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 ProximityDomain7To0; - UINT8 ApicId; - UINT32 Flags; - UINT8 LocalSapicEid; - UINT8 ProximityDomain31To8[3]; - UINT8 Reserved[4]; -} EFI_ACPI_3_0_PROCESSOR_LOCAL_APIC_SAPIC_AFFINITY_STRUCTURE; - -/// -/// Local APIC/SAPIC Flags. All other bits are reserved and must be 0. -/// -#define EFI_ACPI_3_0_PROCESSOR_LOCAL_APIC_SAPIC_ENABLED (1 << 0) - -/// -/// Memory Affinity Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT32 ProximityDomain; - UINT16 Reserved1; - UINT32 AddressBaseLow; - UINT32 AddressBaseHigh; - UINT32 LengthLow; - UINT32 LengthHigh; - UINT32 Reserved2; - UINT32 Flags; - UINT64 Reserved3; -} EFI_ACPI_3_0_MEMORY_AFFINITY_STRUCTURE; - -// -// Memory Flags. All other bits are reserved and must be 0. -// -#define EFI_ACPI_3_0_MEMORY_ENABLED (1 << 0) -#define EFI_ACPI_3_0_MEMORY_HOT_PLUGGABLE (1 << 1) -#define EFI_ACPI_3_0_MEMORY_NONVOLATILE (1 << 2) - -/// -/// System Locality Distance Information Table (SLIT). -/// The rest of the table is a matrix. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT64 NumberOfSystemLocalities; -} EFI_ACPI_3_0_SYSTEM_LOCALITY_DISTANCE_INFORMATION_TABLE_HEADER; - -/// -/// SLIT Version (as defined in ACPI 3.0 spec.) -/// -#define EFI_ACPI_3_0_SYSTEM_LOCALITY_DISTANCE_INFORMATION_TABLE_REVISION 0x01 - -// -// Known table signatures -// - -/// -/// "RSD PTR " Root System Description Pointer -/// -#define EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE SIGNATURE_64('R', 'S', 'D', ' ', 'P', 'T', 'R', ' ') - -/// -/// "APIC" Multiple APIC Description Table -/// -#define EFI_ACPI_3_0_MULTIPLE_APIC_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('A', 'P', 'I', 'C') - -/// -/// "DSDT" Differentiated System Description Table -/// -#define EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('D', 'S', 'D', 'T') - -/// -/// "ECDT" Embedded Controller Boot Resources Table -/// -#define EFI_ACPI_3_0_EMBEDDED_CONTROLLER_BOOT_RESOURCES_TABLE_SIGNATURE SIGNATURE_32('E', 'C', 'D', 'T') - -/// -/// "FACP" Fixed ACPI Description Table -/// -#define EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('F', 'A', 'C', 'P') - -/// -/// "FACS" Firmware ACPI Control Structure -/// -#define EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE SIGNATURE_32('F', 'A', 'C', 'S') - -/// -/// "PSDT" Persistent System Description Table -/// -#define EFI_ACPI_3_0_PERSISTENT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('P', 'S', 'D', 'T') - -/// -/// "RSDT" Root System Description Table -/// -#define EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('R', 'S', 'D', 'T') - -/// -/// "SBST" Smart Battery Specification Table -/// -#define EFI_ACPI_3_0_SMART_BATTERY_SPECIFICATION_TABLE_SIGNATURE SIGNATURE_32('S', 'B', 'S', 'T') - -/// -/// "SLIT" System Locality Information Table -/// -#define EFI_ACPI_3_0_SYSTEM_LOCALITY_INFORMATION_TABLE_SIGNATURE SIGNATURE_32('S', 'L', 'I', 'T') - -/// -/// "SRAT" System Resource Affinity Table -/// -#define EFI_ACPI_3_0_SYSTEM_RESOURCE_AFFINITY_TABLE_SIGNATURE SIGNATURE_32('S', 'R', 'A', 'T') - -/// -/// "SSDT" Secondary System Description Table -/// -#define EFI_ACPI_3_0_SECONDARY_SYSTEM_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('S', 'S', 'D', 'T') - -/// -/// "XSDT" Extended System Description Table -/// -#define EFI_ACPI_3_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('X', 'S', 'D', 'T') - -/// -/// "BOOT" MS Simple Boot Spec -/// -#define EFI_ACPI_3_0_SIMPLE_BOOT_FLAG_TABLE_SIGNATURE SIGNATURE_32('B', 'O', 'O', 'T') - -/// -/// "CPEP" Corrected Platform Error Polling Table -/// -#define EFI_ACPI_3_0_CORRECTED_PLATFORM_ERROR_POLLING_TABLE_SIGNATURE SIGNATURE_32('C', 'P', 'E', 'P') - -/// -/// "DBGP" MS Debug Port Spec -/// -#define EFI_ACPI_3_0_DEBUG_PORT_TABLE_SIGNATURE SIGNATURE_32('D', 'B', 'G', 'P') - -/// -/// "ETDT" Event Timer Description Table -/// -#define EFI_ACPI_3_0_EVENT_TIMER_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('E', 'T', 'D', 'T') - -/// -/// "HPET" IA-PC High Precision Event Timer Table -/// -#define EFI_ACPI_3_0_HIGH_PRECISION_EVENT_TIMER_TABLE_SIGNATURE SIGNATURE_32('H', 'P', 'E', 'T') - -/// -/// "MCFG" PCI Express Memory Mapped Configuration Space Base Address Description Table -/// -#define EFI_ACPI_3_0_PCI_EXPRESS_MEMORY_MAPPED_CONFIGURATION_SPACE_BASE_ADDRESS_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('M', 'C', 'F', 'G') - -/// -/// "SPCR" Serial Port Concole Redirection Table -/// -#define EFI_ACPI_3_0_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_SIGNATURE SIGNATURE_32('S', 'P', 'C', 'R') - -/// -/// "SPMI" Server Platform Management Interface Table -/// -#define EFI_ACPI_3_0_SERVER_PLATFORM_MANAGEMENT_INTERFACE_TABLE_SIGNATURE SIGNATURE_32('S', 'P', 'M', 'I') - -/// -/// "TCPA" Trusted Computing Platform Alliance Capabilities Table -/// -#define EFI_ACPI_3_0_TRUSTED_COMPUTING_PLATFORM_ALLIANCE_CAPABILITIES_TABLE_SIGNATURE SIGNATURE_32('T', 'C', 'P', 'A') - -/// -/// "WDRT" Watchdog Resource Table -/// -#define EFI_ACPI_3_0_WATCHDOG_RESOURCE_TABLE_SIGNATURE SIGNATURE_32('W', 'D', 'R', 'T') - -/// -/// "WDAT" Watchdog Action Table -/// -#define EFI_ACPI_3_0_WATCHDOG_ACTION_TABLE_SIGNATURE SIGNATURE_32('W', 'D', 'A', 'T') - -/// -/// "WSPT" Windows Specific Properties Table -/// -#define EFI_ACPI_3_0_WINDOWS_SPECIFIC_PROPERTIES_TABLE_SIGNATURE SIGNATURE_32('W', 'S', 'P', 'T') - -/// -/// "iBFT" iSCSI Boot Firmware Table -/// -#define EFI_ACPI_3_0_ISCSI_BOOT_FIRMWARE_TABLE_SIGNATURE SIGNATURE_32('i', 'B', 'F', 'T') - -#pragma pack() - -#endif diff --git a/roms/ipxe/src/include/ipxe/efi/IndustryStandard/Acpi40.h b/roms/ipxe/src/include/ipxe/efi/IndustryStandard/Acpi40.h deleted file mode 100644 index 5fcad3e42..000000000 --- a/roms/ipxe/src/include/ipxe/efi/IndustryStandard/Acpi40.h +++ /dev/null @@ -1,1311 +0,0 @@ -/** @file - ACPI 4.0 definitions from the ACPI Specification Revision 4.0a April 5, 2010 - - Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR> - This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -**/ - -#ifndef _ACPI_4_0_H_ -#define _ACPI_4_0_H_ - -FILE_LICENCE ( BSD3 ); - -#include <ipxe/efi/IndustryStandard/Acpi30.h> - -// -// Ensure proper structure formats -// -#pragma pack(1) - -/// -/// ACPI 4.0 Generic Address Space definition -/// -typedef struct { - UINT8 AddressSpaceId; - UINT8 RegisterBitWidth; - UINT8 RegisterBitOffset; - UINT8 AccessSize; - UINT64 Address; -} EFI_ACPI_4_0_GENERIC_ADDRESS_STRUCTURE; - -// -// Generic Address Space Address IDs -// -#define EFI_ACPI_4_0_SYSTEM_MEMORY 0 -#define EFI_ACPI_4_0_SYSTEM_IO 1 -#define EFI_ACPI_4_0_PCI_CONFIGURATION_SPACE 2 -#define EFI_ACPI_4_0_EMBEDDED_CONTROLLER 3 -#define EFI_ACPI_4_0_SMBUS 4 -#define EFI_ACPI_4_0_FUNCTIONAL_FIXED_HARDWARE 0x7F - -// -// Generic Address Space Access Sizes -// -#define EFI_ACPI_4_0_UNDEFINED 0 -#define EFI_ACPI_4_0_BYTE 1 -#define EFI_ACPI_4_0_WORD 2 -#define EFI_ACPI_4_0_DWORD 3 -#define EFI_ACPI_4_0_QWORD 4 - -// -// ACPI 4.0 table structures -// - -/// -/// Root System Description Pointer Structure -/// -typedef struct { - UINT64 Signature; - UINT8 Checksum; - UINT8 OemId[6]; - UINT8 Revision; - UINT32 RsdtAddress; - UINT32 Length; - UINT64 XsdtAddress; - UINT8 ExtendedChecksum; - UINT8 Reserved[3]; -} EFI_ACPI_4_0_ROOT_SYSTEM_DESCRIPTION_POINTER; - -/// -/// RSD_PTR Revision (as defined in ACPI 4.0b spec.) -/// -#define EFI_ACPI_4_0_ROOT_SYSTEM_DESCRIPTION_POINTER_REVISION 0x02 ///< ACPISpec (Revision 4.0a) says current value is 2 - -/// -/// Common table header, this prefaces all ACPI tables, including FACS, but -/// excluding the RSD PTR structure -/// -typedef struct { - UINT32 Signature; - UINT32 Length; -} EFI_ACPI_4_0_COMMON_HEADER; - -// -// Root System Description Table -// No definition needed as it is a common description table header, the same with -// EFI_ACPI_DESCRIPTION_HEADER, followed by a variable number of UINT32 table pointers. -// - -/// -/// RSDT Revision (as defined in ACPI 4.0 spec.) -/// -#define EFI_ACPI_4_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION 0x01 - -// -// Extended System Description Table -// No definition needed as it is a common description table header, the same with -// EFI_ACPI_DESCRIPTION_HEADER, followed by a variable number of UINT64 table pointers. -// - -/// -/// XSDT Revision (as defined in ACPI 4.0 spec.) -/// -#define EFI_ACPI_4_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_REVISION 0x01 - -/// -/// Fixed ACPI Description Table Structure (FADT) -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 FirmwareCtrl; - UINT32 Dsdt; - UINT8 Reserved0; - UINT8 PreferredPmProfile; - UINT16 SciInt; - UINT32 SmiCmd; - UINT8 AcpiEnable; - UINT8 AcpiDisable; - UINT8 S4BiosReq; - UINT8 PstateCnt; - UINT32 Pm1aEvtBlk; - UINT32 Pm1bEvtBlk; - UINT32 Pm1aCntBlk; - UINT32 Pm1bCntBlk; - UINT32 Pm2CntBlk; - UINT32 PmTmrBlk; - UINT32 Gpe0Blk; - UINT32 Gpe1Blk; - UINT8 Pm1EvtLen; - UINT8 Pm1CntLen; - UINT8 Pm2CntLen; - UINT8 PmTmrLen; - UINT8 Gpe0BlkLen; - UINT8 Gpe1BlkLen; - UINT8 Gpe1Base; - UINT8 CstCnt; - UINT16 PLvl2Lat; - UINT16 PLvl3Lat; - UINT16 FlushSize; - UINT16 FlushStride; - UINT8 DutyOffset; - UINT8 DutyWidth; - UINT8 DayAlrm; - UINT8 MonAlrm; - UINT8 Century; - UINT16 IaPcBootArch; - UINT8 Reserved1; - UINT32 Flags; - EFI_ACPI_4_0_GENERIC_ADDRESS_STRUCTURE ResetReg; - UINT8 ResetValue; - UINT8 Reserved2[3]; - UINT64 XFirmwareCtrl; - UINT64 XDsdt; - EFI_ACPI_4_0_GENERIC_ADDRESS_STRUCTURE XPm1aEvtBlk; - EFI_ACPI_4_0_GENERIC_ADDRESS_STRUCTURE XPm1bEvtBlk; - EFI_ACPI_4_0_GENERIC_ADDRESS_STRUCTURE XPm1aCntBlk; - EFI_ACPI_4_0_GENERIC_ADDRESS_STRUCTURE XPm1bCntBlk; - EFI_ACPI_4_0_GENERIC_ADDRESS_STRUCTURE XPm2CntBlk; - EFI_ACPI_4_0_GENERIC_ADDRESS_STRUCTURE XPmTmrBlk; - EFI_ACPI_4_0_GENERIC_ADDRESS_STRUCTURE XGpe0Blk; - EFI_ACPI_4_0_GENERIC_ADDRESS_STRUCTURE XGpe1Blk; -} EFI_ACPI_4_0_FIXED_ACPI_DESCRIPTION_TABLE; - -/// -/// FADT Version (as defined in ACPI 4.0 spec.) -/// -#define EFI_ACPI_4_0_FIXED_ACPI_DESCRIPTION_TABLE_REVISION 0x04 - -// -// Fixed ACPI Description Table Preferred Power Management Profile -// -#define EFI_ACPI_4_0_PM_PROFILE_UNSPECIFIED 0 -#define EFI_ACPI_4_0_PM_PROFILE_DESKTOP 1 -#define EFI_ACPI_4_0_PM_PROFILE_MOBILE 2 -#define EFI_ACPI_4_0_PM_PROFILE_WORKSTATION 3 -#define EFI_ACPI_4_0_PM_PROFILE_ENTERPRISE_SERVER 4 -#define EFI_ACPI_4_0_PM_PROFILE_SOHO_SERVER 5 -#define EFI_ACPI_4_0_PM_PROFILE_APPLIANCE_PC 6 -#define EFI_ACPI_4_0_PM_PROFILE_PERFORMANCE_SERVER 7 - -// -// Fixed ACPI Description Table Boot Architecture Flags -// All other bits are reserved and must be set to 0. -// -#define EFI_ACPI_4_0_LEGACY_DEVICES BIT0 -#define EFI_ACPI_4_0_8042 BIT1 -#define EFI_ACPI_4_0_VGA_NOT_PRESENT BIT2 -#define EFI_ACPI_4_0_MSI_NOT_SUPPORTED BIT3 -#define EFI_ACPI_4_0_PCIE_ASPM_CONTROLS BIT4 - -// -// Fixed ACPI Description Table Fixed Feature Flags -// All other bits are reserved and must be set to 0. -// -#define EFI_ACPI_4_0_WBINVD BIT0 -#define EFI_ACPI_4_0_WBINVD_FLUSH BIT1 -#define EFI_ACPI_4_0_PROC_C1 BIT2 -#define EFI_ACPI_4_0_P_LVL2_UP BIT3 -#define EFI_ACPI_4_0_PWR_BUTTON BIT4 -#define EFI_ACPI_4_0_SLP_BUTTON BIT5 -#define EFI_ACPI_4_0_FIX_RTC BIT6 -#define EFI_ACPI_4_0_RTC_S4 BIT7 -#define EFI_ACPI_4_0_TMR_VAL_EXT BIT8 -#define EFI_ACPI_4_0_DCK_CAP BIT9 -#define EFI_ACPI_4_0_RESET_REG_SUP BIT10 -#define EFI_ACPI_4_0_SEALED_CASE BIT11 -#define EFI_ACPI_4_0_HEADLESS BIT12 -#define EFI_ACPI_4_0_CPU_SW_SLP BIT13 -#define EFI_ACPI_4_0_PCI_EXP_WAK BIT14 -#define EFI_ACPI_4_0_USE_PLATFORM_CLOCK BIT15 -#define EFI_ACPI_4_0_S4_RTC_STS_VALID BIT16 -#define EFI_ACPI_4_0_REMOTE_POWER_ON_CAPABLE BIT17 -#define EFI_ACPI_4_0_FORCE_APIC_CLUSTER_MODEL BIT18 -#define EFI_ACPI_4_0_FORCE_APIC_PHYSICAL_DESTINATION_MODE BIT19 - -/// -/// Firmware ACPI Control Structure -/// -typedef struct { - UINT32 Signature; - UINT32 Length; - UINT32 HardwareSignature; - UINT32 FirmwareWakingVector; - UINT32 GlobalLock; - UINT32 Flags; - UINT64 XFirmwareWakingVector; - UINT8 Version; - UINT8 Reserved0[3]; - UINT32 OspmFlags; - UINT8 Reserved1[24]; -} EFI_ACPI_4_0_FIRMWARE_ACPI_CONTROL_STRUCTURE; - -/// -/// FACS Version (as defined in ACPI 4.0 spec.) -/// -#define EFI_ACPI_4_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_VERSION 0x02 - -/// -/// Firmware Control Structure Feature Flags -/// All other bits are reserved and must be set to 0. -/// -#define EFI_ACPI_4_0_S4BIOS_F BIT0 -#define EFI_ACPI_4_0_64BIT_WAKE_SUPPORTED_F BIT1 - -/// -/// OSPM Enabled Firmware Control Structure Flags -/// All other bits are reserved and must be set to 0. -/// -#define EFI_ACPI_4_0_OSPM_64BIT_WAKE__F BIT0 - -// -// Differentiated System Description Table, -// Secondary System Description Table -// and Persistent System Description Table, -// no definition needed as they are common description table header, the same with -// EFI_ACPI_DESCRIPTION_HEADER, followed by a definition block. -// -#define EFI_ACPI_4_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_REVISION 0x02 -#define EFI_ACPI_4_0_SECONDARY_SYSTEM_DESCRIPTION_TABLE_REVISION 0x02 - -/// -/// Multiple APIC Description Table header definition. The rest of the table -/// must be defined in a platform specific manner. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 LocalApicAddress; - UINT32 Flags; -} EFI_ACPI_4_0_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER; - -/// -/// MADT Revision (as defined in ACPI 4.0 spec.) -/// -#define EFI_ACPI_4_0_MULTIPLE_APIC_DESCRIPTION_TABLE_REVISION 0x03 - -/// -/// Multiple APIC Flags -/// All other bits are reserved and must be set to 0. -/// -#define EFI_ACPI_4_0_PCAT_COMPAT BIT0 - -// -// Multiple APIC Description Table APIC structure types -// All other values between 0x0B an 0xFF are reserved and -// will be ignored by OSPM. -// -#define EFI_ACPI_4_0_PROCESSOR_LOCAL_APIC 0x00 -#define EFI_ACPI_4_0_IO_APIC 0x01 -#define EFI_ACPI_4_0_INTERRUPT_SOURCE_OVERRIDE 0x02 -#define EFI_ACPI_4_0_NON_MASKABLE_INTERRUPT_SOURCE 0x03 -#define EFI_ACPI_4_0_LOCAL_APIC_NMI 0x04 -#define EFI_ACPI_4_0_LOCAL_APIC_ADDRESS_OVERRIDE 0x05 -#define EFI_ACPI_4_0_IO_SAPIC 0x06 -#define EFI_ACPI_4_0_LOCAL_SAPIC 0x07 -#define EFI_ACPI_4_0_PLATFORM_INTERRUPT_SOURCES 0x08 -#define EFI_ACPI_4_0_PROCESSOR_LOCAL_X2APIC 0x09 -#define EFI_ACPI_4_0_LOCAL_X2APIC_NMI 0x0A - -// -// APIC Structure Definitions -// - -/// -/// Processor Local APIC Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 AcpiProcessorId; - UINT8 ApicId; - UINT32 Flags; -} EFI_ACPI_4_0_PROCESSOR_LOCAL_APIC_STRUCTURE; - -/// -/// Local APIC Flags. All other bits are reserved and must be 0. -/// -#define EFI_ACPI_4_0_LOCAL_APIC_ENABLED BIT0 - -/// -/// IO APIC Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 IoApicId; - UINT8 Reserved; - UINT32 IoApicAddress; - UINT32 GlobalSystemInterruptBase; -} EFI_ACPI_4_0_IO_APIC_STRUCTURE; - -/// -/// Interrupt Source Override Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 Bus; - UINT8 Source; - UINT32 GlobalSystemInterrupt; - UINT16 Flags; -} EFI_ACPI_4_0_INTERRUPT_SOURCE_OVERRIDE_STRUCTURE; - -/// -/// Platform Interrupt Sources Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT16 Flags; - UINT8 InterruptType; - UINT8 ProcessorId; - UINT8 ProcessorEid; - UINT8 IoSapicVector; - UINT32 GlobalSystemInterrupt; - UINT32 PlatformInterruptSourceFlags; - UINT8 CpeiProcessorOverride; - UINT8 Reserved[31]; -} EFI_ACPI_4_0_PLATFORM_INTERRUPT_APIC_STRUCTURE; - -// -// MPS INTI flags. -// All other bits are reserved and must be set to 0. -// -#define EFI_ACPI_4_0_POLARITY (3 << 0) -#define EFI_ACPI_4_0_TRIGGER_MODE (3 << 2) - -/// -/// Non-Maskable Interrupt Source Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT16 Flags; - UINT32 GlobalSystemInterrupt; -} EFI_ACPI_4_0_NON_MASKABLE_INTERRUPT_SOURCE_STRUCTURE; - -/// -/// Local APIC NMI Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 AcpiProcessorId; - UINT16 Flags; - UINT8 LocalApicLint; -} EFI_ACPI_4_0_LOCAL_APIC_NMI_STRUCTURE; - -/// -/// Local APIC Address Override Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT16 Reserved; - UINT64 LocalApicAddress; -} EFI_ACPI_4_0_LOCAL_APIC_ADDRESS_OVERRIDE_STRUCTURE; - -/// -/// IO SAPIC Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 IoApicId; - UINT8 Reserved; - UINT32 GlobalSystemInterruptBase; - UINT64 IoSapicAddress; -} EFI_ACPI_4_0_IO_SAPIC_STRUCTURE; - -/// -/// Local SAPIC Structure -/// This struct followed by a null-terminated ASCII string - ACPI Processor UID String -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 AcpiProcessorId; - UINT8 LocalSapicId; - UINT8 LocalSapicEid; - UINT8 Reserved[3]; - UINT32 Flags; - UINT32 ACPIProcessorUIDValue; -} EFI_ACPI_4_0_PROCESSOR_LOCAL_SAPIC_STRUCTURE; - -/// -/// Platform Interrupt Sources Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT16 Flags; - UINT8 InterruptType; - UINT8 ProcessorId; - UINT8 ProcessorEid; - UINT8 IoSapicVector; - UINT32 GlobalSystemInterrupt; - UINT32 PlatformInterruptSourceFlags; -} EFI_ACPI_4_0_PLATFORM_INTERRUPT_SOURCES_STRUCTURE; - -/// -/// Platform Interrupt Source Flags. -/// All other bits are reserved and must be set to 0. -/// -#define EFI_ACPI_4_0_CPEI_PROCESSOR_OVERRIDE BIT0 - -/// -/// Processor Local x2APIC Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 Reserved[2]; - UINT32 X2ApicId; - UINT32 Flags; - UINT32 AcpiProcessorUid; -} EFI_ACPI_4_0_PROCESSOR_LOCAL_X2APIC_STRUCTURE; - -/// -/// Local x2APIC NMI Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT16 Flags; - UINT32 AcpiProcessorUid; - UINT8 LocalX2ApicLint; - UINT8 Reserved[3]; -} EFI_ACPI_4_0_LOCAL_X2APIC_NMI_STRUCTURE; - -/// -/// Smart Battery Description Table (SBST) -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 WarningEnergyLevel; - UINT32 LowEnergyLevel; - UINT32 CriticalEnergyLevel; -} EFI_ACPI_4_0_SMART_BATTERY_DESCRIPTION_TABLE; - -/// -/// SBST Version (as defined in ACPI 4.0 spec.) -/// -#define EFI_ACPI_4_0_SMART_BATTERY_DESCRIPTION_TABLE_REVISION 0x01 - -/// -/// Embedded Controller Boot Resources Table (ECDT) -/// The table is followed by a null terminated ASCII string that contains -/// a fully qualified reference to the name space object. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - EFI_ACPI_4_0_GENERIC_ADDRESS_STRUCTURE EcControl; - EFI_ACPI_4_0_GENERIC_ADDRESS_STRUCTURE EcData; - UINT32 Uid; - UINT8 GpeBit; -} EFI_ACPI_4_0_EMBEDDED_CONTROLLER_BOOT_RESOURCES_TABLE; - -/// -/// ECDT Version (as defined in ACPI 4.0 spec.) -/// -#define EFI_ACPI_4_0_EMBEDDED_CONTROLLER_BOOT_RESOURCES_TABLE_REVISION 0x01 - -/// -/// System Resource Affinity Table (SRAT. The rest of the table -/// must be defined in a platform specific manner. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 Reserved1; ///< Must be set to 1 - UINT64 Reserved2; -} EFI_ACPI_4_0_SYSTEM_RESOURCE_AFFINITY_TABLE_HEADER; - -/// -/// SRAT Version (as defined in ACPI 4.0 spec.) -/// -#define EFI_ACPI_4_0_SYSTEM_RESOURCE_AFFINITY_TABLE_REVISION 0x03 - -// -// SRAT structure types. -// All other values between 0x03 an 0xFF are reserved and -// will be ignored by OSPM. -// -#define EFI_ACPI_4_0_PROCESSOR_LOCAL_APIC_SAPIC_AFFINITY 0x00 -#define EFI_ACPI_4_0_MEMORY_AFFINITY 0x01 -#define EFI_ACPI_4_0_PROCESSOR_LOCAL_X2APIC_AFFINITY 0x02 - -/// -/// Processor Local APIC/SAPIC Affinity Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 ProximityDomain7To0; - UINT8 ApicId; - UINT32 Flags; - UINT8 LocalSapicEid; - UINT8 ProximityDomain31To8[3]; - UINT32 ClockDomain; -} EFI_ACPI_4_0_PROCESSOR_LOCAL_APIC_SAPIC_AFFINITY_STRUCTURE; - -/// -/// Local APIC/SAPIC Flags. All other bits are reserved and must be 0. -/// -#define EFI_ACPI_4_0_PROCESSOR_LOCAL_APIC_SAPIC_ENABLED (1 << 0) - -/// -/// Memory Affinity Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT32 ProximityDomain; - UINT16 Reserved1; - UINT32 AddressBaseLow; - UINT32 AddressBaseHigh; - UINT32 LengthLow; - UINT32 LengthHigh; - UINT32 Reserved2; - UINT32 Flags; - UINT64 Reserved3; -} EFI_ACPI_4_0_MEMORY_AFFINITY_STRUCTURE; - -// -// Memory Flags. All other bits are reserved and must be 0. -// -#define EFI_ACPI_4_0_MEMORY_ENABLED (1 << 0) -#define EFI_ACPI_4_0_MEMORY_HOT_PLUGGABLE (1 << 1) -#define EFI_ACPI_4_0_MEMORY_NONVOLATILE (1 << 2) - -/// -/// Processor Local x2APIC Affinity Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 Reserved1[2]; - UINT32 ProximityDomain; - UINT32 X2ApicId; - UINT32 Flags; - UINT32 ClockDomain; - UINT8 Reserved2[4]; -} EFI_ACPI_4_0_PROCESSOR_LOCAL_X2APIC_AFFINITY_STRUCTURE; - -/// -/// System Locality Distance Information Table (SLIT). -/// The rest of the table is a matrix. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT64 NumberOfSystemLocalities; -} EFI_ACPI_4_0_SYSTEM_LOCALITY_DISTANCE_INFORMATION_TABLE_HEADER; - -/// -/// SLIT Version (as defined in ACPI 4.0 spec.) -/// -#define EFI_ACPI_4_0_SYSTEM_LOCALITY_DISTANCE_INFORMATION_TABLE_REVISION 0x01 - -/// -/// Corrected Platform Error Polling Table (CPEP) -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT8 Reserved[8]; -} EFI_ACPI_4_0_CORRECTED_PLATFORM_ERROR_POLLING_TABLE_HEADER; - -/// -/// CPEP Version (as defined in ACPI 4.0 spec.) -/// -#define EFI_ACPI_4_0_CORRECTED_PLATFORM_ERROR_POLLING_TABLE_REVISION 0x01 - -// -// CPEP processor structure types. -// -#define EFI_ACPI_4_0_CPEP_PROCESSOR_APIC_SAPIC 0x00 - -/// -/// Corrected Platform Error Polling Processor Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 ProcessorId; - UINT8 ProcessorEid; - UINT32 PollingInterval; -} EFI_ACPI_4_0_CPEP_PROCESSOR_APIC_SAPIC_STRUCTURE; - -/// -/// Maximum System Characteristics Table (MSCT) -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 OffsetProxDomInfo; - UINT32 MaximumNumberOfProximityDomains; - UINT32 MaximumNumberOfClockDomains; - UINT64 MaximumPhysicalAddress; -} EFI_ACPI_4_0_MAXIMUM_SYSTEM_CHARACTERISTICS_TABLE_HEADER; - -/// -/// MSCT Version (as defined in ACPI 4.0 spec.) -/// -#define EFI_ACPI_4_0_MAXIMUM_SYSTEM_CHARACTERISTICS_TABLE_REVISION 0x01 - -/// -/// Maximum Proximity Domain Information Structure Definition -/// -typedef struct { - UINT8 Revision; - UINT8 Length; - UINT32 ProximityDomainRangeLow; - UINT32 ProximityDomainRangeHigh; - UINT32 MaximumProcessorCapacity; - UINT64 MaximumMemoryCapacity; -} EFI_ACPI_4_0_MAXIMUM_PROXIMITY_DOMAIN_INFORMATION_STRUCTURE; - -/// -/// Boot Error Record Table (BERT) -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 BootErrorRegionLength; - UINT64 BootErrorRegion; -} EFI_ACPI_4_0_BOOT_ERROR_RECORD_TABLE_HEADER; - -/// -/// BERT Version (as defined in ACPI 4.0 spec.) -/// -#define EFI_ACPI_4_0_BOOT_ERROR_RECORD_TABLE_REVISION 0x01 - -/// -/// Boot Error Region Block Status Definition -/// -typedef struct { - UINT32 UncorrectableErrorValid:1; - UINT32 CorrectableErrorValid:1; - UINT32 MultipleUncorrectableErrors:1; - UINT32 MultipleCorrectableErrors:1; - UINT32 ErrorDataEntryCount:10; - UINT32 Reserved:18; -} EFI_ACPI_4_0_ERROR_BLOCK_STATUS; - -/// -/// Boot Error Region Definition -/// -typedef struct { - EFI_ACPI_4_0_ERROR_BLOCK_STATUS BlockStatus; - UINT32 RawDataOffset; - UINT32 RawDataLength; - UINT32 DataLength; - UINT32 ErrorSeverity; -} EFI_ACPI_4_0_BOOT_ERROR_REGION_STRUCTURE; - -// -// Boot Error Severity types -// -#define EFI_ACPI_4_0_ERROR_SEVERITY_CORRECTABLE 0x00 -#define EFI_ACPI_4_0_ERROR_SEVERITY_FATAL 0x01 -#define EFI_ACPI_4_0_ERROR_SEVERITY_CORRECTED 0x02 -#define EFI_ACPI_4_0_ERROR_SEVERITY_NONE 0x03 - -/// -/// Generic Error Data Entry Definition -/// -typedef struct { - UINT8 SectionType[16]; - UINT32 ErrorSeverity; - UINT16 Revision; - UINT8 ValidationBits; - UINT8 Flags; - UINT32 ErrorDataLength; - UINT8 FruId[16]; - UINT8 FruText[20]; -} EFI_ACPI_4_0_GENERIC_ERROR_DATA_ENTRY_STRUCTURE; - -/// -/// Generic Error Data Entry Version (as defined in ACPI 4.0 spec.) -/// -#define EFI_ACPI_4_0_GENERIC_ERROR_DATA_ENTRY_REVISION 0x0201 - -/// -/// HEST - Hardware Error Source Table -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 ErrorSourceCount; -} EFI_ACPI_4_0_HARDWARE_ERROR_SOURCE_TABLE_HEADER; - -/// -/// HEST Version (as defined in ACPI 4.0 spec.) -/// -#define EFI_ACPI_4_0_HARDWARE_ERROR_SOURCE_TABLE_REVISION 0x01 - -// -// Error Source structure types. -// -#define EFI_ACPI_4_0_IA32_ARCHITECTURE_MACHINE_CHECK_EXCEPTION 0x00 -#define EFI_ACPI_4_0_IA32_ARCHITECTURE_CORRECTED_MACHINE_CHECK 0x01 -#define EFI_ACPI_4_0_IA32_ARCHITECTURE_NMI_ERROR 0x02 -#define EFI_ACPI_4_0_PCI_EXPRESS_ROOT_PORT_AER 0x06 -#define EFI_ACPI_4_0_PCI_EXPRESS_DEVICE_AER 0x07 -#define EFI_ACPI_4_0_PCI_EXPRESS_BRIDGE_AER 0x08 -#define EFI_ACPI_4_0_GENERIC_HARDWARE_ERROR 0x09 - -// -// Error Source structure flags. -// -#define EFI_ACPI_4_0_ERROR_SOURCE_FLAG_FIRMWARE_FIRST (1 << 0) -#define EFI_ACPI_4_0_ERROR_SOURCE_FLAG_GLOBAL (1 << 1) - -/// -/// IA-32 Architecture Machine Check Exception Structure Definition -/// -typedef struct { - UINT16 Type; - UINT16 SourceId; - UINT8 Reserved0[2]; - UINT8 Flags; - UINT8 Enabled; - UINT32 NumberOfRecordsToPreAllocate; - UINT32 MaxSectionsPerRecord; - UINT64 GlobalCapabilityInitData; - UINT64 GlobalControlInitData; - UINT8 NumberOfHardwareBanks; - UINT8 Reserved1[7]; -} EFI_ACPI_4_0_IA32_ARCHITECTURE_MACHINE_CHECK_EXCEPTION_STRUCTURE; - -/// -/// IA-32 Architecture Machine Check Bank Structure Definition -/// -typedef struct { - UINT8 BankNumber; - UINT8 ClearStatusOnInitialization; - UINT8 StatusDataFormat; - UINT8 Reserved0; - UINT32 ControlRegisterMsrAddress; - UINT64 ControlInitData; - UINT32 StatusRegisterMsrAddress; - UINT32 AddressRegisterMsrAddress; - UINT32 MiscRegisterMsrAddress; -} EFI_ACPI_4_0_IA32_ARCHITECTURE_MACHINE_CHECK_ERROR_BANK_STRUCTURE; - -/// -/// IA-32 Architecture Machine Check Bank Structure MCA data format -/// -#define EFI_ACPI_4_0_IA32_ARCHITECTURE_MACHINE_CHECK_ERROR_DATA_FORMAT_IA32 0x00 -#define EFI_ACPI_4_0_IA32_ARCHITECTURE_MACHINE_CHECK_ERROR_DATA_FORMAT_INTEL64 0x01 -#define EFI_ACPI_4_0_IA32_ARCHITECTURE_MACHINE_CHECK_ERROR_DATA_FORMAT_AMD64 0x02 - -// -// Hardware Error Notification types. All other values are reserved -// -#define EFI_ACPI_4_0_HARDWARE_ERROR_NOTIFICATION_POLLED 0x00 -#define EFI_ACPI_4_0_HARDWARE_ERROR_NOTIFICATION_EXTERNAL_INTERRUPT 0x01 -#define EFI_ACPI_4_0_HARDWARE_ERROR_NOTIFICATION_LOCAL_INTERRUPT 0x02 -#define EFI_ACPI_4_0_HARDWARE_ERROR_NOTIFICATION_SCI 0x03 -#define EFI_ACPI_4_0_HARDWARE_ERROR_NOTIFICATION_NMI 0x04 - -/// -/// Hardware Error Notification Configuration Write Enable Structure Definition -/// -typedef struct { - UINT16 Type:1; - UINT16 PollInterval:1; - UINT16 SwitchToPollingThresholdValue:1; - UINT16 SwitchToPollingThresholdWindow:1; - UINT16 ErrorThresholdValue:1; - UINT16 ErrorThresholdWindow:1; - UINT16 Reserved:10; -} EFI_ACPI_4_0_HARDWARE_ERROR_NOTIFICATION_CONFIGURATION_WRITE_ENABLE_STRUCTURE; - -/// -/// Hardware Error Notification Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - EFI_ACPI_4_0_HARDWARE_ERROR_NOTIFICATION_CONFIGURATION_WRITE_ENABLE_STRUCTURE ConfigurationWriteEnable; - UINT32 PollInterval; - UINT32 Vector; - UINT32 SwitchToPollingThresholdValue; - UINT32 SwitchToPollingThresholdWindow; - UINT32 ErrorThresholdValue; - UINT32 ErrorThresholdWindow; -} EFI_ACPI_4_0_HARDWARE_ERROR_NOTIFICATION_STRUCTURE; - -/// -/// IA-32 Architecture Corrected Machine Check Structure Definition -/// -typedef struct { - UINT16 Type; - UINT16 SourceId; - UINT8 Reserved0[2]; - UINT8 Flags; - UINT8 Enabled; - UINT32 NumberOfRecordsToPreAllocate; - UINT32 MaxSectionsPerRecord; - EFI_ACPI_4_0_HARDWARE_ERROR_NOTIFICATION_STRUCTURE NotificationStructure; - UINT8 NumberOfHardwareBanks; - UINT8 Reserved1[3]; -} EFI_ACPI_4_0_IA32_ARCHITECTURE_CORRECTED_MACHINE_CHECK_STRUCTURE; - -/// -/// IA-32 Architecture NMI Error Structure Definition -/// -typedef struct { - UINT16 Type; - UINT16 SourceId; - UINT8 Reserved0[2]; - UINT32 NumberOfRecordsToPreAllocate; - UINT32 MaxSectionsPerRecord; - UINT32 MaxRawDataLength; -} EFI_ACPI_4_0_IA32_ARCHITECTURE_NMI_ERROR_STRUCTURE; - -/// -/// PCI Express Root Port AER Structure Definition -/// -typedef struct { - UINT16 Type; - UINT16 SourceId; - UINT8 Reserved0[2]; - UINT8 Flags; - UINT8 Enabled; - UINT32 NumberOfRecordsToPreAllocate; - UINT32 MaxSectionsPerRecord; - UINT32 Bus; - UINT16 Device; - UINT16 Function; - UINT16 DeviceControl; - UINT8 Reserved1[2]; - UINT32 UncorrectableErrorMask; - UINT32 UncorrectableErrorSeverity; - UINT32 CorrectableErrorMask; - UINT32 AdvancedErrorCapabilitiesAndControl; - UINT32 RootErrorCommand; -} EFI_ACPI_4_0_PCI_EXPRESS_ROOT_PORT_AER_STRUCTURE; - -/// -/// PCI Express Device AER Structure Definition -/// -typedef struct { - UINT16 Type; - UINT16 SourceId; - UINT8 Reserved0[2]; - UINT8 Flags; - UINT8 Enabled; - UINT32 NumberOfRecordsToPreAllocate; - UINT32 MaxSectionsPerRecord; - UINT32 Bus; - UINT16 Device; - UINT16 Function; - UINT16 DeviceControl; - UINT8 Reserved1[2]; - UINT32 UncorrectableErrorMask; - UINT32 UncorrectableErrorSeverity; - UINT32 CorrectableErrorMask; - UINT32 AdvancedErrorCapabilitiesAndControl; -} EFI_ACPI_4_0_PCI_EXPRESS_DEVICE_AER_STRUCTURE; - -/// -/// PCI Express Bridge AER Structure Definition -/// -typedef struct { - UINT16 Type; - UINT16 SourceId; - UINT8 Reserved0[2]; - UINT8 Flags; - UINT8 Enabled; - UINT32 NumberOfRecordsToPreAllocate; - UINT32 MaxSectionsPerRecord; - UINT32 Bus; - UINT16 Device; - UINT16 Function; - UINT16 DeviceControl; - UINT8 Reserved1[2]; - UINT32 UncorrectableErrorMask; - UINT32 UncorrectableErrorSeverity; - UINT32 CorrectableErrorMask; - UINT32 AdvancedErrorCapabilitiesAndControl; - UINT32 SecondaryUncorrectableErrorMask; - UINT32 SecondaryUncorrectableErrorSeverity; - UINT32 SecondaryAdvancedErrorCapabilitiesAndControl; -} EFI_ACPI_4_0_PCI_EXPRESS_BRIDGE_AER_STRUCTURE; - -/// -/// Generic Hardware Error Source Structure Definition -/// -typedef struct { - UINT16 Type; - UINT16 SourceId; - UINT16 RelatedSourceId; - UINT8 Flags; - UINT8 Enabled; - UINT32 NumberOfRecordsToPreAllocate; - UINT32 MaxSectionsPerRecord; - UINT32 MaxRawDataLength; - EFI_ACPI_4_0_GENERIC_ADDRESS_STRUCTURE ErrorStatusAddress; - EFI_ACPI_4_0_HARDWARE_ERROR_NOTIFICATION_STRUCTURE NotificationStructure; - UINT32 ErrorStatusBlockLength; -} EFI_ACPI_4_0_GENERIC_HARDWARE_ERROR_SOURCE_STRUCTURE; - -/// -/// Generic Error Status Definition -/// -typedef struct { - EFI_ACPI_4_0_ERROR_BLOCK_STATUS BlockStatus; - UINT32 RawDataOffset; - UINT32 RawDataLength; - UINT32 DataLength; - UINT32 ErrorSeverity; -} EFI_ACPI_4_0_GENERIC_ERROR_STATUS_STRUCTURE; - -/// -/// ERST - Error Record Serialization Table -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 SerializationHeaderSize; - UINT8 Reserved0[4]; - UINT32 InstructionEntryCount; -} EFI_ACPI_4_0_ERROR_RECORD_SERIALIZATION_TABLE_HEADER; - -/// -/// ERST Version (as defined in ACPI 4.0 spec.) -/// -#define EFI_ACPI_4_0_ERROR_RECORD_SERIALIZATION_TABLE_REVISION 0x01 - -/// -/// ERST Serialization Actions -/// -#define EFI_ACPI_4_0_ERST_BEGIN_WRITE_OPERATION 0x00 -#define EFI_ACPI_4_0_ERST_BEGIN_READ_OPERATION 0x01 -#define EFI_ACPI_4_0_ERST_BEGIN_CLEAR_OPERATION 0x02 -#define EFI_ACPI_4_0_ERST_END_OPERATION 0x03 -#define EFI_ACPI_4_0_ERST_SET_RECORD_OFFSET 0x04 -#define EFI_ACPI_4_0_ERST_EXECUTE_OPERATION 0x05 -#define EFI_ACPI_4_0_ERST_CHECK_BUSY_STATUS 0x06 -#define EFI_ACPI_4_0_ERST_GET_COMMAND_STATUS 0x07 -#define EFI_ACPI_4_0_ERST_GET_RECORD_IDENTIFIER 0x08 -#define EFI_ACPI_4_0_ERST_SET_RECORD_IDENTIFIER 0x09 -#define EFI_ACPI_4_0_ERST_GET_RECORD_COUNT 0x0A -#define EFI_ACPI_4_0_ERST_BEGIN_DUMMY_WRITE_OPERATION 0x0B -#define EFI_ACPI_4_0_ERST_GET_ERROR_LOG_ADDRESS_RANGE 0x0D -#define EFI_ACPI_4_0_ERST_GET_ERROR_LOG_ADDRESS_RANGE_LENGTH 0x0E -#define EFI_ACPI_4_0_ERST_GET_ERROR_LOG_ADDRESS_RANGE_ATTRIBUTES 0x0F - -/// -/// ERST Action Command Status -/// -#define EFI_ACPI_4_0_EINJ_STATUS_SUCCESS 0x00 -#define EFI_ACPI_4_0_EINJ_STATUS_NOT_ENOUGH_SPACE 0x01 -#define EFI_ACPI_4_0_EINJ_STATUS_HARDWARE_NOT_AVAILABLE 0x02 -#define EFI_ACPI_4_0_EINJ_STATUS_FAILED 0x03 -#define EFI_ACPI_4_0_EINJ_STATUS_RECORD_STORE_EMPTY 0x04 -#define EFI_ACPI_4_0_EINJ_STATUS_RECORD_NOT_FOUND 0x05 - -/// -/// ERST Serialization Instructions -/// -#define EFI_ACPI_4_0_ERST_READ_REGISTER 0x00 -#define EFI_ACPI_4_0_ERST_READ_REGISTER_VALUE 0x01 -#define EFI_ACPI_4_0_ERST_WRITE_REGISTER 0x02 -#define EFI_ACPI_4_0_ERST_WRITE_REGISTER_VALUE 0x03 -#define EFI_ACPI_4_0_ERST_NOOP 0x04 -#define EFI_ACPI_4_0_ERST_LOAD_VAR1 0x05 -#define EFI_ACPI_4_0_ERST_LOAD_VAR2 0x06 -#define EFI_ACPI_4_0_ERST_STORE_VAR1 0x07 -#define EFI_ACPI_4_0_ERST_ADD 0x08 -#define EFI_ACPI_4_0_ERST_SUBTRACT 0x09 -#define EFI_ACPI_4_0_ERST_ADD_VALUE 0x0A -#define EFI_ACPI_4_0_ERST_SUBTRACT_VALUE 0x0B -#define EFI_ACPI_4_0_ERST_STALL 0x0C -#define EFI_ACPI_4_0_ERST_STALL_WHILE_TRUE 0x0D -#define EFI_ACPI_4_0_ERST_SKIP_NEXT_INSTRUCTION_IF_TRUE 0x0E -#define EFI_ACPI_4_0_ERST_GOTO 0x0F -#define EFI_ACPI_4_0_ERST_SET_SRC_ADDRESS_BASE 0x10 -#define EFI_ACPI_4_0_ERST_SET_DST_ADDRESS_BASE 0x11 -#define EFI_ACPI_4_0_ERST_MOVE_DATA 0x12 - -/// -/// ERST Instruction Flags -/// -#define EFI_ACPI_4_0_ERST_PRESERVE_REGISTER 0x01 - -/// -/// ERST Serialization Instruction Entry -/// -typedef struct { - UINT8 SerializationAction; - UINT8 Instruction; - UINT8 Flags; - UINT8 Reserved0; - EFI_ACPI_4_0_GENERIC_ADDRESS_STRUCTURE RegisterRegion; - UINT64 Value; - UINT64 Mask; -} EFI_ACPI_4_0_ERST_SERIALIZATION_INSTRUCTION_ENTRY; - -/// -/// EINJ - Error Injection Table -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 InjectionHeaderSize; - UINT8 InjectionFlags; - UINT8 Reserved0[3]; - UINT32 InjectionEntryCount; -} EFI_ACPI_4_0_ERROR_INJECTION_TABLE_HEADER; - -/// -/// EINJ Version (as defined in ACPI 4.0 spec.) -/// -#define EFI_ACPI_4_0_ERROR_INJECTION_TABLE_REVISION 0x01 - -/// -/// EINJ Error Injection Actions -/// -#define EFI_ACPI_4_0_EINJ_BEGIN_INJECTION_OPERATION 0x00 -#define EFI_ACPI_4_0_EINJ_GET_TRIGGER_ERROR_ACTION_TABLE 0x01 -#define EFI_ACPI_4_0_EINJ_SET_ERROR_TYPE 0x02 -#define EFI_ACPI_4_0_EINJ_GET_ERROR_TYPE 0x03 -#define EFI_ACPI_4_0_EINJ_END_OPERATION 0x04 -#define EFI_ACPI_4_0_EINJ_EXECUTE_OPERATION 0x05 -#define EFI_ACPI_4_0_EINJ_CHECK_BUSY_STATUS 0x06 -#define EFI_ACPI_4_0_EINJ_GET_COMMAND_STATUS 0x07 -#define EFI_ACPI_4_0_EINJ_TRIGGER_ERROR 0xFF - -/// -/// EINJ Action Command Status -/// -#define EFI_ACPI_4_0_EINJ_STATUS_SUCCESS 0x00 -#define EFI_ACPI_4_0_EINJ_STATUS_UNKNOWN_FAILURE 0x01 -#define EFI_ACPI_4_0_EINJ_STATUS_INVALID_ACCESS 0x02 - -/// -/// EINJ Error Type Definition -/// -#define EFI_ACPI_4_0_EINJ_ERROR_PROCESSOR_CORRECTABLE (1 << 0) -#define EFI_ACPI_4_0_EINJ_ERROR_PROCESSOR_UNCORRECTABLE_NONFATAL (1 << 1) -#define EFI_ACPI_4_0_EINJ_ERROR_PROCESSOR_UNCORRECTABLE_FATAL (1 << 2) -#define EFI_ACPI_4_0_EINJ_ERROR_MEMORY_CORRECTABLE (1 << 3) -#define EFI_ACPI_4_0_EINJ_ERROR_MEMORY_UNCORRECTABLE_NONFATAL (1 << 4) -#define EFI_ACPI_4_0_EINJ_ERROR_MEMORY_UNCORRECTABLE_FATAL (1 << 5) -#define EFI_ACPI_4_0_EINJ_ERROR_PCI_EXPRESS_CORRECTABLE (1 << 6) -#define EFI_ACPI_4_0_EINJ_ERROR_PCI_EXPRESS_UNCORRECTABLE_NONFATAL (1 << 7) -#define EFI_ACPI_4_0_EINJ_ERROR_PCI_EXPRESS_UNCORRECTABLE_FATAL (1 << 8) -#define EFI_ACPI_4_0_EINJ_ERROR_PLATFORM_CORRECTABLE (1 << 9) -#define EFI_ACPI_4_0_EINJ_ERROR_PLATFORM_UNCORRECTABLE_NONFATAL (1 << 10) -#define EFI_ACPI_4_0_EINJ_ERROR_PLATFORM_UNCORRECTABLE_FATAL (1 << 11) - -/// -/// EINJ Injection Instructions -/// -#define EFI_ACPI_4_0_EINJ_READ_REGISTER 0x00 -#define EFI_ACPI_4_0_EINJ_READ_REGISTER_VALUE 0x01 -#define EFI_ACPI_4_0_EINJ_WRITE_REGISTER 0x02 -#define EFI_ACPI_4_0_EINJ_WRITE_REGISTER_VALUE 0x03 -#define EFI_ACPI_4_0_EINJ_NOOP 0x04 - -/// -/// EINJ Instruction Flags -/// -#define EFI_ACPI_4_0_EINJ_PRESERVE_REGISTER 0x01 - -/// -/// EINJ Injection Instruction Entry -/// -typedef struct { - UINT8 InjectionAction; - UINT8 Instruction; - UINT8 Flags; - UINT8 Reserved0; - EFI_ACPI_4_0_GENERIC_ADDRESS_STRUCTURE RegisterRegion; - UINT64 Value; - UINT64 Mask; -} EFI_ACPI_4_0_EINJ_INJECTION_INSTRUCTION_ENTRY; - -/// -/// EINJ Trigger Action Table -/// -typedef struct { - UINT32 HeaderSize; - UINT32 Revision; - UINT32 TableSize; - UINT32 EntryCount; -} EFI_ACPI_4_0_EINJ_TRIGGER_ACTION_TABLE; - -// -// Known table signatures -// - -/// -/// "RSD PTR " Root System Description Pointer -/// -#define EFI_ACPI_4_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE SIGNATURE_64('R', 'S', 'D', ' ', 'P', 'T', 'R', ' ') - -/// -/// "APIC" Multiple APIC Description Table -/// -#define EFI_ACPI_4_0_MULTIPLE_APIC_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('A', 'P', 'I', 'C') - -/// -/// "BERT" Boot Error Record Table -/// -#define EFI_ACPI_4_0_BOOT_ERROR_RECORD_TABLE_SIGNATURE SIGNATURE_32('B', 'E', 'R', 'T') - -/// -/// "CPEP" Corrected Platform Error Polling Table -/// -#define EFI_ACPI_4_0_CORRECTED_PLATFORM_ERROR_POLLING_TABLE_SIGNATURE SIGNATURE_32('C', 'P', 'E', 'P') - -/// -/// "DSDT" Differentiated System Description Table -/// -#define EFI_ACPI_4_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('D', 'S', 'D', 'T') - -/// -/// "ECDT" Embedded Controller Boot Resources Table -/// -#define EFI_ACPI_4_0_EMBEDDED_CONTROLLER_BOOT_RESOURCES_TABLE_SIGNATURE SIGNATURE_32('E', 'C', 'D', 'T') - -/// -/// "EINJ" Error Injection Table -/// -#define EFI_ACPI_4_0_ERROR_INJECTION_TABLE_SIGNATURE SIGNATURE_32('E', 'I', 'N', 'J') - -/// -/// "ERST" Error Record Serialization Table -/// -#define EFI_ACPI_4_0_ERROR_RECORD_SERIALIZATION_TABLE_SIGNATURE SIGNATURE_32('E', 'R', 'S', 'T') - -/// -/// "FACP" Fixed ACPI Description Table -/// -#define EFI_ACPI_4_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('F', 'A', 'C', 'P') - -/// -/// "FACS" Firmware ACPI Control Structure -/// -#define EFI_ACPI_4_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE SIGNATURE_32('F', 'A', 'C', 'S') - -/// -/// "HEST" Hardware Error Source Table -/// -#define EFI_ACPI_4_0_HARDWARE_ERROR_SOURCE_TABLE_SIGNATURE SIGNATURE_32('H', 'E', 'S', 'T') - -/// -/// "MSCT" Maximum System Characteristics Table -/// -#define EFI_ACPI_4_0_MAXIMUM_SYSTEM_CHARACTERISTICS_TABLE_SIGNATURE SIGNATURE_32('M', 'S', 'C', 'T') - -/// -/// "PSDT" Persistent System Description Table -/// -#define EFI_ACPI_4_0_PERSISTENT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('P', 'S', 'D', 'T') - -/// -/// "RSDT" Root System Description Table -/// -#define EFI_ACPI_4_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('R', 'S', 'D', 'T') - -/// -/// "SBST" Smart Battery Specification Table -/// -#define EFI_ACPI_4_0_SMART_BATTERY_SPECIFICATION_TABLE_SIGNATURE SIGNATURE_32('S', 'B', 'S', 'T') - -/// -/// "SLIT" System Locality Information Table -/// -#define EFI_ACPI_4_0_SYSTEM_LOCALITY_INFORMATION_TABLE_SIGNATURE SIGNATURE_32('S', 'L', 'I', 'T') - -/// -/// "SRAT" System Resource Affinity Table -/// -#define EFI_ACPI_4_0_SYSTEM_RESOURCE_AFFINITY_TABLE_SIGNATURE SIGNATURE_32('S', 'R', 'A', 'T') - -/// -/// "SSDT" Secondary System Description Table -/// -#define EFI_ACPI_4_0_SECONDARY_SYSTEM_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('S', 'S', 'D', 'T') - -/// -/// "XSDT" Extended System Description Table -/// -#define EFI_ACPI_4_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('X', 'S', 'D', 'T') - -/// -/// "BOOT" MS Simple Boot Spec -/// -#define EFI_ACPI_4_0_SIMPLE_BOOT_FLAG_TABLE_SIGNATURE SIGNATURE_32('B', 'O', 'O', 'T') - -/// -/// "DBGP" MS Debug Port Spec -/// -#define EFI_ACPI_4_0_DEBUG_PORT_TABLE_SIGNATURE SIGNATURE_32('D', 'B', 'G', 'P') - -/// -/// "DMAR" DMA Remapping Table -/// -#define EFI_ACPI_4_0_DMA_REMAPPING_TABLE_SIGNATURE SIGNATURE_32('D', 'M', 'A', 'R') - -/// -/// "ETDT" Event Timer Description Table -/// -#define EFI_ACPI_4_0_EVENT_TIMER_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('E', 'T', 'D', 'T') - -/// -/// "HPET" IA-PC High Precision Event Timer Table -/// -#define EFI_ACPI_4_0_HIGH_PRECISION_EVENT_TIMER_TABLE_SIGNATURE SIGNATURE_32('H', 'P', 'E', 'T') - -/// -/// "iBFT" iSCSI Boot Firmware Table -/// -#define EFI_ACPI_4_0_ISCSI_BOOT_FIRMWARE_TABLE_SIGNATURE SIGNATURE_32('i', 'B', 'F', 'T') - -/// -/// "IVRS" I/O Virtualization Reporting Structure -/// -#define EFI_ACPI_4_0_IO_VIRTUALIZATION_REPORTING_STRUCTURE_SIGNATURE SIGNATURE_32('I', 'V', 'R', 'S') - -/// -/// "MCFG" PCI Express Memory Mapped Configuration Space Base Address Description Table -/// -#define EFI_ACPI_4_0_PCI_EXPRESS_MEMORY_MAPPED_CONFIGURATION_SPACE_BASE_ADDRESS_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('M', 'C', 'F', 'G') - -/// -/// "MCHI" Management Controller Host Interface Table -/// -#define EFI_ACPI_4_0_MANAGEMENT_CONTROLLER_HOST_INTERFACE_TABLE_SIGNATURE SIGNATURE_32('M', 'C', 'H', 'I') - -/// -/// "SPCR" Serial Port Concole Redirection Table -/// -#define EFI_ACPI_4_0_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_SIGNATURE SIGNATURE_32('S', 'P', 'C', 'R') - -/// -/// "SPMI" Server Platform Management Interface Table -/// -#define EFI_ACPI_4_0_SERVER_PLATFORM_MANAGEMENT_INTERFACE_TABLE_SIGNATURE SIGNATURE_32('S', 'P', 'M', 'I') - -/// -/// "TCPA" Trusted Computing Platform Alliance Capabilities Table -/// -#define EFI_ACPI_4_0_TRUSTED_COMPUTING_PLATFORM_ALLIANCE_CAPABILITIES_TABLE_SIGNATURE SIGNATURE_32('T', 'C', 'P', 'A') - -/// -/// "UEFI" UEFI ACPI Data Table -/// -#define EFI_ACPI_4_0_UEFI_ACPI_DATA_TABLE_SIGNATURE SIGNATURE_32('U', 'E', 'F', 'I') - -/// -/// "WAET" Windows ACPI Enlightenment Table -/// -#define EFI_ACPI_4_0_WINDOWS_ACPI_ENLIGHTENMENT_TABLE_SIGNATURE SIGNATURE_32('W', 'A', 'E', 'T') - -/// -/// "WDAT" Watchdog Action Table -/// -#define EFI_ACPI_4_0_WATCHDOG_ACTION_TABLE_SIGNATURE SIGNATURE_32('W', 'D', 'A', 'T') - -/// -/// "WDRT" Watchdog Resource Table -/// -#define EFI_ACPI_4_0_WATCHDOG_RESOURCE_TABLE_SIGNATURE SIGNATURE_32('W', 'D', 'R', 'T') - -#pragma pack() - -#endif diff --git a/roms/ipxe/src/include/ipxe/efi/IndustryStandard/Acpi50.h b/roms/ipxe/src/include/ipxe/efi/IndustryStandard/Acpi50.h deleted file mode 100644 index df9e71531..000000000 --- a/roms/ipxe/src/include/ipxe/efi/IndustryStandard/Acpi50.h +++ /dev/null @@ -1,2121 +0,0 @@ -/** @file - ACPI 5.0 definitions from the ACPI Specification Revision 5.0a November 13, 2013. - - Copyright (c) 2014 Hewlett-Packard Development Company, L.P.<BR> - Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR> - This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -**/ - -#ifndef _ACPI_5_0_H_ -#define _ACPI_5_0_H_ - -FILE_LICENCE ( BSD3 ); - -#include <ipxe/efi/IndustryStandard/Acpi40.h> - -// -// Define for Desriptor -// -#define ACPI_SMALL_FIXED_DMA_DESCRIPTOR_NAME 0x0A -#define ACPI_LARGE_GPIO_CONNECTION_DESCRIPTOR_NAME 0x0C -#define ACPI_LARGE_GENERIC_SERIAL_BUS_CONNECTION_DESCRIPTOR_NAME 0x0E - -#define ACPI_FIXED_DMA_DESCRIPTOR 0x55 -#define ACPI_GPIO_CONNECTION_DESCRIPTOR 0x8C -#define ACPI_GENERIC_SERIAL_BUS_CONNECTION_DESCRIPTOR 0x8E - -#pragma pack(1) - -/// -/// Generic DMA Descriptor. -/// -typedef PACKED struct { - ACPI_SMALL_RESOURCE_HEADER Header; - UINT16 DmaRequestLine; - UINT16 DmaChannel; - UINT8 DmaTransferWidth; -} EFI_ACPI_FIXED_DMA_DESCRIPTOR; - -/// -/// GPIO Connection Descriptor -/// -typedef PACKED struct { - ACPI_LARGE_RESOURCE_HEADER Header; - UINT8 RevisionId; - UINT8 ConnectionType; - UINT16 GeneralFlags; - UINT16 InterruptFlags; - UINT8 PinConfiguration; - UINT16 OutputDriveStrength; - UINT16 DebounceTimeout; - UINT16 PinTableOffset; - UINT8 ResourceSourceIndex; - UINT16 ResourceSourceNameOffset; - UINT16 VendorDataOffset; - UINT16 VendorDataLength; -} EFI_ACPI_GPIO_CONNECTION_DESCRIPTOR; - -#define EFI_ACPI_GPIO_CONNECTION_TYPE_INTERRUPT 0x0 -#define EFI_ACPI_GPIO_CONNECTION_TYPE_IO 0x1 - -/// -/// Serial Bus Resource Descriptor (Generic) -/// -typedef PACKED struct { - ACPI_LARGE_RESOURCE_HEADER Header; - UINT8 RevisionId; - UINT8 ResourceSourceIndex; - UINT8 SerialBusType; - UINT8 GeneralFlags; - UINT16 TypeSpecificFlags; - UINT8 TypeSpecificRevisionId; - UINT16 TypeDataLength; -// Type specific data -} EFI_ACPI_SERIAL_BUS_RESOURCE_DESCRIPTOR; - -#define EFI_ACPI_SERIAL_BUS_RESOURCE_TYPE_I2C 0x1 -#define EFI_ACPI_SERIAL_BUS_RESOURCE_TYPE_SPI 0x2 -#define EFI_ACPI_SERIAL_BUS_RESOURCE_TYPE_UART 0x3 - -/// -/// Serial Bus Resource Descriptor (I2C) -/// -typedef PACKED struct { - ACPI_LARGE_RESOURCE_HEADER Header; - UINT8 RevisionId; - UINT8 ResourceSourceIndex; - UINT8 SerialBusType; - UINT8 GeneralFlags; - UINT16 TypeSpecificFlags; - UINT8 TypeSpecificRevisionId; - UINT16 TypeDataLength; - UINT32 ConnectionSpeed; - UINT16 SlaveAddress; -} EFI_ACPI_SERIAL_BUS_RESOURCE_I2C_DESCRIPTOR; - -/// -/// Serial Bus Resource Descriptor (SPI) -/// -typedef PACKED struct { - ACPI_LARGE_RESOURCE_HEADER Header; - UINT8 RevisionId; - UINT8 ResourceSourceIndex; - UINT8 SerialBusType; - UINT8 GeneralFlags; - UINT16 TypeSpecificFlags; - UINT8 TypeSpecificRevisionId; - UINT16 TypeDataLength; - UINT32 ConnectionSpeed; - UINT8 DataBitLength; - UINT8 Phase; - UINT8 Polarity; - UINT16 DeviceSelection; -} EFI_ACPI_SERIAL_BUS_RESOURCE_SPI_DESCRIPTOR; - -/// -/// Serial Bus Resource Descriptor (UART) -/// -typedef PACKED struct { - ACPI_LARGE_RESOURCE_HEADER Header; - UINT8 RevisionId; - UINT8 ResourceSourceIndex; - UINT8 SerialBusType; - UINT8 GeneralFlags; - UINT16 TypeSpecificFlags; - UINT8 TypeSpecificRevisionId; - UINT16 TypeDataLength; - UINT32 DefaultBaudRate; - UINT16 RxFIFO; - UINT16 TxFIFO; - UINT8 Parity; - UINT8 SerialLinesEnabled; -} EFI_ACPI_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR; - -#pragma pack() - -// -// Ensure proper structure formats -// -#pragma pack(1) - -/// -/// ACPI 5.0 Generic Address Space definition -/// -typedef struct { - UINT8 AddressSpaceId; - UINT8 RegisterBitWidth; - UINT8 RegisterBitOffset; - UINT8 AccessSize; - UINT64 Address; -} EFI_ACPI_5_0_GENERIC_ADDRESS_STRUCTURE; - -// -// Generic Address Space Address IDs -// -#define EFI_ACPI_5_0_SYSTEM_MEMORY 0 -#define EFI_ACPI_5_0_SYSTEM_IO 1 -#define EFI_ACPI_5_0_PCI_CONFIGURATION_SPACE 2 -#define EFI_ACPI_5_0_EMBEDDED_CONTROLLER 3 -#define EFI_ACPI_5_0_SMBUS 4 -#define EFI_ACPI_5_0_PLATFORM_COMMUNICATION_CHANNEL 0x0A -#define EFI_ACPI_5_0_FUNCTIONAL_FIXED_HARDWARE 0x7F - -// -// Generic Address Space Access Sizes -// -#define EFI_ACPI_5_0_UNDEFINED 0 -#define EFI_ACPI_5_0_BYTE 1 -#define EFI_ACPI_5_0_WORD 2 -#define EFI_ACPI_5_0_DWORD 3 -#define EFI_ACPI_5_0_QWORD 4 - -// -// ACPI 5.0 table structures -// - -/// -/// Root System Description Pointer Structure -/// -typedef struct { - UINT64 Signature; - UINT8 Checksum; - UINT8 OemId[6]; - UINT8 Revision; - UINT32 RsdtAddress; - UINT32 Length; - UINT64 XsdtAddress; - UINT8 ExtendedChecksum; - UINT8 Reserved[3]; -} EFI_ACPI_5_0_ROOT_SYSTEM_DESCRIPTION_POINTER; - -/// -/// RSD_PTR Revision (as defined in ACPI 5.0 spec.) -/// -#define EFI_ACPI_5_0_ROOT_SYSTEM_DESCRIPTION_POINTER_REVISION 0x02 ///< ACPISpec (Revision 5.0) says current value is 2 - -/// -/// Common table header, this prefaces all ACPI tables, including FACS, but -/// excluding the RSD PTR structure -/// -typedef struct { - UINT32 Signature; - UINT32 Length; -} EFI_ACPI_5_0_COMMON_HEADER; - -// -// Root System Description Table -// No definition needed as it is a common description table header, the same with -// EFI_ACPI_DESCRIPTION_HEADER, followed by a variable number of UINT32 table pointers. -// - -/// -/// RSDT Revision (as defined in ACPI 5.0 spec.) -/// -#define EFI_ACPI_5_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION 0x01 - -// -// Extended System Description Table -// No definition needed as it is a common description table header, the same with -// EFI_ACPI_DESCRIPTION_HEADER, followed by a variable number of UINT64 table pointers. -// - -/// -/// XSDT Revision (as defined in ACPI 5.0 spec.) -/// -#define EFI_ACPI_5_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_REVISION 0x01 - -/// -/// Fixed ACPI Description Table Structure (FADT) -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 FirmwareCtrl; - UINT32 Dsdt; - UINT8 Reserved0; - UINT8 PreferredPmProfile; - UINT16 SciInt; - UINT32 SmiCmd; - UINT8 AcpiEnable; - UINT8 AcpiDisable; - UINT8 S4BiosReq; - UINT8 PstateCnt; - UINT32 Pm1aEvtBlk; - UINT32 Pm1bEvtBlk; - UINT32 Pm1aCntBlk; - UINT32 Pm1bCntBlk; - UINT32 Pm2CntBlk; - UINT32 PmTmrBlk; - UINT32 Gpe0Blk; - UINT32 Gpe1Blk; - UINT8 Pm1EvtLen; - UINT8 Pm1CntLen; - UINT8 Pm2CntLen; - UINT8 PmTmrLen; - UINT8 Gpe0BlkLen; - UINT8 Gpe1BlkLen; - UINT8 Gpe1Base; - UINT8 CstCnt; - UINT16 PLvl2Lat; - UINT16 PLvl3Lat; - UINT16 FlushSize; - UINT16 FlushStride; - UINT8 DutyOffset; - UINT8 DutyWidth; - UINT8 DayAlrm; - UINT8 MonAlrm; - UINT8 Century; - UINT16 IaPcBootArch; - UINT8 Reserved1; - UINT32 Flags; - EFI_ACPI_5_0_GENERIC_ADDRESS_STRUCTURE ResetReg; - UINT8 ResetValue; - UINT8 Reserved2[3]; - UINT64 XFirmwareCtrl; - UINT64 XDsdt; - EFI_ACPI_5_0_GENERIC_ADDRESS_STRUCTURE XPm1aEvtBlk; - EFI_ACPI_5_0_GENERIC_ADDRESS_STRUCTURE XPm1bEvtBlk; - EFI_ACPI_5_0_GENERIC_ADDRESS_STRUCTURE XPm1aCntBlk; - EFI_ACPI_5_0_GENERIC_ADDRESS_STRUCTURE XPm1bCntBlk; - EFI_ACPI_5_0_GENERIC_ADDRESS_STRUCTURE XPm2CntBlk; - EFI_ACPI_5_0_GENERIC_ADDRESS_STRUCTURE XPmTmrBlk; - EFI_ACPI_5_0_GENERIC_ADDRESS_STRUCTURE XGpe0Blk; - EFI_ACPI_5_0_GENERIC_ADDRESS_STRUCTURE XGpe1Blk; - EFI_ACPI_5_0_GENERIC_ADDRESS_STRUCTURE SleepControlReg; - EFI_ACPI_5_0_GENERIC_ADDRESS_STRUCTURE SleepStatusReg; -} EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE; - -/// -/// FADT Version (as defined in ACPI 5.0 spec.) -/// -#define EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE_REVISION 0x05 - -// -// Fixed ACPI Description Table Preferred Power Management Profile -// -#define EFI_ACPI_5_0_PM_PROFILE_UNSPECIFIED 0 -#define EFI_ACPI_5_0_PM_PROFILE_DESKTOP 1 -#define EFI_ACPI_5_0_PM_PROFILE_MOBILE 2 -#define EFI_ACPI_5_0_PM_PROFILE_WORKSTATION 3 -#define EFI_ACPI_5_0_PM_PROFILE_ENTERPRISE_SERVER 4 -#define EFI_ACPI_5_0_PM_PROFILE_SOHO_SERVER 5 -#define EFI_ACPI_5_0_PM_PROFILE_APPLIANCE_PC 6 -#define EFI_ACPI_5_0_PM_PROFILE_PERFORMANCE_SERVER 7 -#define EFI_ACPI_5_0_PM_PROFILE_TABLET 8 - -// -// Fixed ACPI Description Table Boot Architecture Flags -// All other bits are reserved and must be set to 0. -// -#define EFI_ACPI_5_0_LEGACY_DEVICES BIT0 -#define EFI_ACPI_5_0_8042 BIT1 -#define EFI_ACPI_5_0_VGA_NOT_PRESENT BIT2 -#define EFI_ACPI_5_0_MSI_NOT_SUPPORTED BIT3 -#define EFI_ACPI_5_0_PCIE_ASPM_CONTROLS BIT4 -#define EFI_ACPI_5_0_CMOS_RTC_NOT_PRESENT BIT5 - -// -// Fixed ACPI Description Table Fixed Feature Flags -// All other bits are reserved and must be set to 0. -// -#define EFI_ACPI_5_0_WBINVD BIT0 -#define EFI_ACPI_5_0_WBINVD_FLUSH BIT1 -#define EFI_ACPI_5_0_PROC_C1 BIT2 -#define EFI_ACPI_5_0_P_LVL2_UP BIT3 -#define EFI_ACPI_5_0_PWR_BUTTON BIT4 -#define EFI_ACPI_5_0_SLP_BUTTON BIT5 -#define EFI_ACPI_5_0_FIX_RTC BIT6 -#define EFI_ACPI_5_0_RTC_S4 BIT7 -#define EFI_ACPI_5_0_TMR_VAL_EXT BIT8 -#define EFI_ACPI_5_0_DCK_CAP BIT9 -#define EFI_ACPI_5_0_RESET_REG_SUP BIT10 -#define EFI_ACPI_5_0_SEALED_CASE BIT11 -#define EFI_ACPI_5_0_HEADLESS BIT12 -#define EFI_ACPI_5_0_CPU_SW_SLP BIT13 -#define EFI_ACPI_5_0_PCI_EXP_WAK BIT14 -#define EFI_ACPI_5_0_USE_PLATFORM_CLOCK BIT15 -#define EFI_ACPI_5_0_S4_RTC_STS_VALID BIT16 -#define EFI_ACPI_5_0_REMOTE_POWER_ON_CAPABLE BIT17 -#define EFI_ACPI_5_0_FORCE_APIC_CLUSTER_MODEL BIT18 -#define EFI_ACPI_5_0_FORCE_APIC_PHYSICAL_DESTINATION_MODE BIT19 -#define EFI_ACPI_5_0_HW_REDUCED_ACPI BIT20 -#define EFI_ACPI_5_0_LOW_POWER_S0_IDLE_CAPABLE BIT21 - -/// -/// Firmware ACPI Control Structure -/// -typedef struct { - UINT32 Signature; - UINT32 Length; - UINT32 HardwareSignature; - UINT32 FirmwareWakingVector; - UINT32 GlobalLock; - UINT32 Flags; - UINT64 XFirmwareWakingVector; - UINT8 Version; - UINT8 Reserved0[3]; - UINT32 OspmFlags; - UINT8 Reserved1[24]; -} EFI_ACPI_5_0_FIRMWARE_ACPI_CONTROL_STRUCTURE; - -/// -/// FACS Version (as defined in ACPI 5.0 spec.) -/// -#define EFI_ACPI_5_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_VERSION 0x02 - -/// -/// Firmware Control Structure Feature Flags -/// All other bits are reserved and must be set to 0. -/// -#define EFI_ACPI_5_0_S4BIOS_F BIT0 -#define EFI_ACPI_5_0_64BIT_WAKE_SUPPORTED_F BIT1 - -/// -/// OSPM Enabled Firmware Control Structure Flags -/// All other bits are reserved and must be set to 0. -/// -#define EFI_ACPI_5_0_OSPM_64BIT_WAKE_F BIT0 - -// -// Differentiated System Description Table, -// Secondary System Description Table -// and Persistent System Description Table, -// no definition needed as they are common description table header, the same with -// EFI_ACPI_DESCRIPTION_HEADER, followed by a definition block. -// -#define EFI_ACPI_5_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_REVISION 0x02 -#define EFI_ACPI_5_0_SECONDARY_SYSTEM_DESCRIPTION_TABLE_REVISION 0x02 - -/// -/// Multiple APIC Description Table header definition. The rest of the table -/// must be defined in a platform specific manner. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 LocalApicAddress; - UINT32 Flags; -} EFI_ACPI_5_0_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER; - -/// -/// MADT Revision (as defined in ACPI 5.0 spec.) -/// -#define EFI_ACPI_5_0_MULTIPLE_APIC_DESCRIPTION_TABLE_REVISION 0x03 - -/// -/// Multiple APIC Flags -/// All other bits are reserved and must be set to 0. -/// -#define EFI_ACPI_5_0_PCAT_COMPAT BIT0 - -// -// Multiple APIC Description Table APIC structure types -// All other values between 0x0D and 0x7F are reserved and -// will be ignored by OSPM. 0x80 ~ 0xFF are reserved for OEM. -// -#define EFI_ACPI_5_0_PROCESSOR_LOCAL_APIC 0x00 -#define EFI_ACPI_5_0_IO_APIC 0x01 -#define EFI_ACPI_5_0_INTERRUPT_SOURCE_OVERRIDE 0x02 -#define EFI_ACPI_5_0_NON_MASKABLE_INTERRUPT_SOURCE 0x03 -#define EFI_ACPI_5_0_LOCAL_APIC_NMI 0x04 -#define EFI_ACPI_5_0_LOCAL_APIC_ADDRESS_OVERRIDE 0x05 -#define EFI_ACPI_5_0_IO_SAPIC 0x06 -#define EFI_ACPI_5_0_LOCAL_SAPIC 0x07 -#define EFI_ACPI_5_0_PLATFORM_INTERRUPT_SOURCES 0x08 -#define EFI_ACPI_5_0_PROCESSOR_LOCAL_X2APIC 0x09 -#define EFI_ACPI_5_0_LOCAL_X2APIC_NMI 0x0A -#define EFI_ACPI_5_0_GIC 0x0B -#define EFI_ACPI_5_0_GICD 0x0C - -// -// APIC Structure Definitions -// - -/// -/// Processor Local APIC Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 AcpiProcessorId; - UINT8 ApicId; - UINT32 Flags; -} EFI_ACPI_5_0_PROCESSOR_LOCAL_APIC_STRUCTURE; - -/// -/// Local APIC Flags. All other bits are reserved and must be 0. -/// -#define EFI_ACPI_5_0_LOCAL_APIC_ENABLED BIT0 - -/// -/// IO APIC Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 IoApicId; - UINT8 Reserved; - UINT32 IoApicAddress; - UINT32 GlobalSystemInterruptBase; -} EFI_ACPI_5_0_IO_APIC_STRUCTURE; - -/// -/// Interrupt Source Override Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 Bus; - UINT8 Source; - UINT32 GlobalSystemInterrupt; - UINT16 Flags; -} EFI_ACPI_5_0_INTERRUPT_SOURCE_OVERRIDE_STRUCTURE; - -/// -/// Platform Interrupt Sources Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT16 Flags; - UINT8 InterruptType; - UINT8 ProcessorId; - UINT8 ProcessorEid; - UINT8 IoSapicVector; - UINT32 GlobalSystemInterrupt; - UINT32 PlatformInterruptSourceFlags; - UINT8 CpeiProcessorOverride; - UINT8 Reserved[31]; -} EFI_ACPI_5_0_PLATFORM_INTERRUPT_APIC_STRUCTURE; - -// -// MPS INTI flags. -// All other bits are reserved and must be set to 0. -// -#define EFI_ACPI_5_0_POLARITY (3 << 0) -#define EFI_ACPI_5_0_TRIGGER_MODE (3 << 2) - -/// -/// Non-Maskable Interrupt Source Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT16 Flags; - UINT32 GlobalSystemInterrupt; -} EFI_ACPI_5_0_NON_MASKABLE_INTERRUPT_SOURCE_STRUCTURE; - -/// -/// Local APIC NMI Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 AcpiProcessorId; - UINT16 Flags; - UINT8 LocalApicLint; -} EFI_ACPI_5_0_LOCAL_APIC_NMI_STRUCTURE; - -/// -/// Local APIC Address Override Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT16 Reserved; - UINT64 LocalApicAddress; -} EFI_ACPI_5_0_LOCAL_APIC_ADDRESS_OVERRIDE_STRUCTURE; - -/// -/// IO SAPIC Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 IoApicId; - UINT8 Reserved; - UINT32 GlobalSystemInterruptBase; - UINT64 IoSapicAddress; -} EFI_ACPI_5_0_IO_SAPIC_STRUCTURE; - -/// -/// Local SAPIC Structure -/// This struct followed by a null-terminated ASCII string - ACPI Processor UID String -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 AcpiProcessorId; - UINT8 LocalSapicId; - UINT8 LocalSapicEid; - UINT8 Reserved[3]; - UINT32 Flags; - UINT32 ACPIProcessorUIDValue; -} EFI_ACPI_5_0_PROCESSOR_LOCAL_SAPIC_STRUCTURE; - -/// -/// Platform Interrupt Sources Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT16 Flags; - UINT8 InterruptType; - UINT8 ProcessorId; - UINT8 ProcessorEid; - UINT8 IoSapicVector; - UINT32 GlobalSystemInterrupt; - UINT32 PlatformInterruptSourceFlags; -} EFI_ACPI_5_0_PLATFORM_INTERRUPT_SOURCES_STRUCTURE; - -/// -/// Platform Interrupt Source Flags. -/// All other bits are reserved and must be set to 0. -/// -#define EFI_ACPI_5_0_CPEI_PROCESSOR_OVERRIDE BIT0 - -/// -/// Processor Local x2APIC Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 Reserved[2]; - UINT32 X2ApicId; - UINT32 Flags; - UINT32 AcpiProcessorUid; -} EFI_ACPI_5_0_PROCESSOR_LOCAL_X2APIC_STRUCTURE; - -/// -/// Local x2APIC NMI Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT16 Flags; - UINT32 AcpiProcessorUid; - UINT8 LocalX2ApicLint; - UINT8 Reserved[3]; -} EFI_ACPI_5_0_LOCAL_X2APIC_NMI_STRUCTURE; - -/// -/// GIC Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT16 Reserved; - UINT32 GicId; - UINT32 AcpiProcessorUid; - UINT32 Flags; - UINT32 ParkingProtocolVersion; - UINT32 PerformanceInterruptGsiv; - UINT64 ParkedAddress; - UINT64 PhysicalBaseAddress; -} EFI_ACPI_5_0_GIC_STRUCTURE; - -/// -/// GIC Flags. All other bits are reserved and must be 0. -/// -#define EFI_ACPI_5_0_GIC_ENABLED BIT0 -#define EFI_ACPI_5_0_PERFORMANCE_INTERRUPT_MODEL BIT1 - -/// -/// GIC Distributor Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT16 Reserved1; - UINT32 GicId; - UINT64 PhysicalBaseAddress; - UINT32 SystemVectorBase; - UINT32 Reserved2; -} EFI_ACPI_5_0_GIC_DISTRIBUTOR_STRUCTURE; - -/// -/// Smart Battery Description Table (SBST) -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 WarningEnergyLevel; - UINT32 LowEnergyLevel; - UINT32 CriticalEnergyLevel; -} EFI_ACPI_5_0_SMART_BATTERY_DESCRIPTION_TABLE; - -/// -/// SBST Version (as defined in ACPI 5.0 spec.) -/// -#define EFI_ACPI_5_0_SMART_BATTERY_DESCRIPTION_TABLE_REVISION 0x01 - -/// -/// Embedded Controller Boot Resources Table (ECDT) -/// The table is followed by a null terminated ASCII string that contains -/// a fully qualified reference to the name space object. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - EFI_ACPI_5_0_GENERIC_ADDRESS_STRUCTURE EcControl; - EFI_ACPI_5_0_GENERIC_ADDRESS_STRUCTURE EcData; - UINT32 Uid; - UINT8 GpeBit; -} EFI_ACPI_5_0_EMBEDDED_CONTROLLER_BOOT_RESOURCES_TABLE; - -/// -/// ECDT Version (as defined in ACPI 5.0 spec.) -/// -#define EFI_ACPI_5_0_EMBEDDED_CONTROLLER_BOOT_RESOURCES_TABLE_REVISION 0x01 - -/// -/// System Resource Affinity Table (SRAT). The rest of the table -/// must be defined in a platform specific manner. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 Reserved1; ///< Must be set to 1 - UINT64 Reserved2; -} EFI_ACPI_5_0_SYSTEM_RESOURCE_AFFINITY_TABLE_HEADER; - -/// -/// SRAT Version (as defined in ACPI 5.0 spec.) -/// -#define EFI_ACPI_5_0_SYSTEM_RESOURCE_AFFINITY_TABLE_REVISION 0x03 - -// -// SRAT structure types. -// All other values between 0x03 an 0xFF are reserved and -// will be ignored by OSPM. -// -#define EFI_ACPI_5_0_PROCESSOR_LOCAL_APIC_SAPIC_AFFINITY 0x00 -#define EFI_ACPI_5_0_MEMORY_AFFINITY 0x01 -#define EFI_ACPI_5_0_PROCESSOR_LOCAL_X2APIC_AFFINITY 0x02 - -/// -/// Processor Local APIC/SAPIC Affinity Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 ProximityDomain7To0; - UINT8 ApicId; - UINT32 Flags; - UINT8 LocalSapicEid; - UINT8 ProximityDomain31To8[3]; - UINT32 ClockDomain; -} EFI_ACPI_5_0_PROCESSOR_LOCAL_APIC_SAPIC_AFFINITY_STRUCTURE; - -/// -/// Local APIC/SAPIC Flags. All other bits are reserved and must be 0. -/// -#define EFI_ACPI_5_0_PROCESSOR_LOCAL_APIC_SAPIC_ENABLED (1 << 0) - -/// -/// Memory Affinity Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT32 ProximityDomain; - UINT16 Reserved1; - UINT32 AddressBaseLow; - UINT32 AddressBaseHigh; - UINT32 LengthLow; - UINT32 LengthHigh; - UINT32 Reserved2; - UINT32 Flags; - UINT64 Reserved3; -} EFI_ACPI_5_0_MEMORY_AFFINITY_STRUCTURE; - -// -// Memory Flags. All other bits are reserved and must be 0. -// -#define EFI_ACPI_5_0_MEMORY_ENABLED (1 << 0) -#define EFI_ACPI_5_0_MEMORY_HOT_PLUGGABLE (1 << 1) -#define EFI_ACPI_5_0_MEMORY_NONVOLATILE (1 << 2) - -/// -/// Processor Local x2APIC Affinity Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 Reserved1[2]; - UINT32 ProximityDomain; - UINT32 X2ApicId; - UINT32 Flags; - UINT32 ClockDomain; - UINT8 Reserved2[4]; -} EFI_ACPI_5_0_PROCESSOR_LOCAL_X2APIC_AFFINITY_STRUCTURE; - -/// -/// System Locality Distance Information Table (SLIT). -/// The rest of the table is a matrix. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT64 NumberOfSystemLocalities; -} EFI_ACPI_5_0_SYSTEM_LOCALITY_DISTANCE_INFORMATION_TABLE_HEADER; - -/// -/// SLIT Version (as defined in ACPI 5.0 spec.) -/// -#define EFI_ACPI_5_0_SYSTEM_LOCALITY_DISTANCE_INFORMATION_TABLE_REVISION 0x01 - -/// -/// Corrected Platform Error Polling Table (CPEP) -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT8 Reserved[8]; -} EFI_ACPI_5_0_CORRECTED_PLATFORM_ERROR_POLLING_TABLE_HEADER; - -/// -/// CPEP Version (as defined in ACPI 5.0 spec.) -/// -#define EFI_ACPI_5_0_CORRECTED_PLATFORM_ERROR_POLLING_TABLE_REVISION 0x01 - -// -// CPEP processor structure types. -// -#define EFI_ACPI_5_0_CPEP_PROCESSOR_APIC_SAPIC 0x00 - -/// -/// Corrected Platform Error Polling Processor Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 ProcessorId; - UINT8 ProcessorEid; - UINT32 PollingInterval; -} EFI_ACPI_5_0_CPEP_PROCESSOR_APIC_SAPIC_STRUCTURE; - -/// -/// Maximum System Characteristics Table (MSCT) -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 OffsetProxDomInfo; - UINT32 MaximumNumberOfProximityDomains; - UINT32 MaximumNumberOfClockDomains; - UINT64 MaximumPhysicalAddress; -} EFI_ACPI_5_0_MAXIMUM_SYSTEM_CHARACTERISTICS_TABLE_HEADER; - -/// -/// MSCT Version (as defined in ACPI 5.0 spec.) -/// -#define EFI_ACPI_5_0_MAXIMUM_SYSTEM_CHARACTERISTICS_TABLE_REVISION 0x01 - -/// -/// Maximum Proximity Domain Information Structure Definition -/// -typedef struct { - UINT8 Revision; - UINT8 Length; - UINT32 ProximityDomainRangeLow; - UINT32 ProximityDomainRangeHigh; - UINT32 MaximumProcessorCapacity; - UINT64 MaximumMemoryCapacity; -} EFI_ACPI_5_0_MAXIMUM_PROXIMITY_DOMAIN_INFORMATION_STRUCTURE; - -/// -/// ACPI RAS Feature Table definition. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT8 PlatformCommunicationChannelIdentifier[12]; -} EFI_ACPI_5_0_RAS_FEATURE_TABLE; - -/// -/// RASF Version (as defined in ACPI 5.0 spec.) -/// -#define EFI_ACPI_5_0_RAS_FEATURE_TABLE_REVISION 0x01 - -/// -/// ACPI RASF Platform Communication Channel Shared Memory Region definition. -/// -typedef struct { - UINT32 Signature; - UINT16 Command; - UINT16 Status; - UINT16 Version; - UINT8 RASCapabilities[16]; - UINT8 SetRASCapabilities[16]; - UINT16 NumberOfRASFParameterBlocks; - UINT32 SetRASCapabilitiesStatus; -} EFI_ACPI_5_0_RASF_PLATFORM_COMMUNICATION_CHANNEL_SHARED_MEMORY_REGION; - -/// -/// ACPI RASF PCC command code -/// -#define EFI_ACPI_5_0_RASF_PCC_COMMAND_CODE_EXECUTE_RASF_COMMAND 0x01 - -/// -/// ACPI RASF Platform RAS Capabilities -/// -#define EFI_ACPI_5_0_RASF_PLATFORM_RAS_CAPABILITY_HARDWARE_BASED_PATROL_SCRUB_SUPPOTED 0x01 -#define EFI_ACPI_5_0_RASF_PLATFORM_RAS_CAPABILITY_HARDWARE_BASED_PATROL_SCRUB_SUPPOTED_AND_EXPOSED_TO_SOFTWARE 0x02 - -/// -/// ACPI RASF Parameter Block structure for PATROL_SCRUB -/// -typedef struct { - UINT16 Type; - UINT16 Version; - UINT16 Length; - UINT16 PatrolScrubCommand; - UINT64 RequestedAddressRange[2]; - UINT64 ActualAddressRange[2]; - UINT16 Flags; - UINT8 RequestedSpeed; -} EFI_ACPI_5_0_RASF_PATROL_SCRUB_PLATFORM_BLOCK_STRUCTURE; - -/// -/// ACPI RASF Patrol Scrub command -/// -#define EFI_ACPI_5_0_RASF_PATROL_SCRUB_COMMAND_GET_PATROL_PARAMETERS 0x01 -#define EFI_ACPI_5_0_RASF_PATROL_SCRUB_COMMAND_START_PATROL_SCRUBBER 0x02 -#define EFI_ACPI_5_0_RASF_PATROL_SCRUB_COMMAND_STOP_PATROL_SCRUBBER 0x03 - -/// -/// Memory Power State Table definition. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT8 PlatformCommunicationChannelIdentifier; - UINT8 Reserved[3]; -// Memory Power Node Structure -// Memory Power State Characteristics -} EFI_ACPI_5_0_MEMORY_POWER_STATUS_TABLE; - -/// -/// MPST Version (as defined in ACPI 5.0 spec.) -/// -#define EFI_ACPI_5_0_MEMORY_POWER_STATE_TABLE_REVISION 0x01 - -/// -/// MPST Platform Communication Channel Shared Memory Region definition. -/// -typedef struct { - UINT32 Signature; - UINT16 Command; - UINT16 Status; - UINT32 MemoryPowerCommandRegister; - UINT32 MemoryPowerStatusRegister; - UINT32 PowerStateId; - UINT32 MemoryPowerNodeId; - UINT64 MemoryEnergyConsumed; - UINT64 ExpectedAveragePowerComsuned; -} EFI_ACPI_5_0_MPST_PLATFORM_COMMUNICATION_CHANNEL_SHARED_MEMORY_REGION; - -/// -/// ACPI MPST PCC command code -/// -#define EFI_ACPI_5_0_MPST_PCC_COMMAND_CODE_EXECUTE_MPST_COMMAND 0x03 - -/// -/// ACPI MPST Memory Power command -/// -#define EFI_ACPI_5_0_MPST_MEMORY_POWER_COMMAND_GET_MEMORY_POWER_STATE 0x01 -#define EFI_ACPI_5_0_MPST_MEMORY_POWER_COMMAND_SET_MEMORY_POWER_STATE 0x02 -#define EFI_ACPI_5_0_MPST_MEMORY_POWER_COMMAND_GET_AVERAGE_POWER_CONSUMED 0x03 -#define EFI_ACPI_5_0_MPST_MEMORY_POWER_COMMAND_GET_MEMORY_ENERGY_CONSUMED 0x04 - -/// -/// MPST Memory Power Node Table -/// -typedef struct { - UINT8 PowerStateValue; - UINT8 PowerStateInformationIndex; -} EFI_ACPI_5_0_MPST_MEMORY_POWER_STATE; - -typedef struct { - UINT8 Flag; - UINT8 Reserved; - UINT16 MemoryPowerNodeId; - UINT32 Length; - UINT64 AddressBase; - UINT64 AddressLength; - UINT32 NumberOfPowerStates; - UINT32 NumberOfPhysicalComponents; -//EFI_ACPI_5_0_MPST_MEMORY_POWER_STATE MemoryPowerState[NumberOfPowerStates]; -//UINT16 PhysicalComponentIdentifier[NumberOfPhysicalComponents]; -} EFI_ACPI_5_0_MPST_MEMORY_POWER_STRUCTURE; - -#define EFI_ACPI_5_0_MPST_MEMORY_POWER_STRUCTURE_FLAG_ENABLE 0x01 -#define EFI_ACPI_5_0_MPST_MEMORY_POWER_STRUCTURE_FLAG_POWER_MANAGED 0x02 -#define EFI_ACPI_5_0_MPST_MEMORY_POWER_STRUCTURE_FLAG_HOT_PLUGGABLE 0x04 - -typedef struct { - UINT16 MemoryPowerNodeCount; - UINT8 Reserved[2]; -} EFI_ACPI_5_0_MPST_MEMORY_POWER_NODE_TABLE; - -/// -/// MPST Memory Power State Characteristics Table -/// -typedef struct { - UINT8 PowerStateStructureID; - UINT8 Flag; - UINT16 Reserved; - UINT32 AveragePowerConsumedInMPS0; - UINT32 RelativePowerSavingToMPS0; - UINT64 ExitLatencyToMPS0; -} EFI_ACPI_5_0_MPST_MEMORY_POWER_STATE_CHARACTERISTICS_STRUCTURE; - -#define EFI_ACPI_5_0_MPST_MEMORY_POWER_STATE_CHARACTERISTICS_STRUCTURE_FLAG_MEMORY_CONTENT_PRESERVED 0x01 -#define EFI_ACPI_5_0_MPST_MEMORY_POWER_STATE_CHARACTERISTICS_STRUCTURE_FLAG_AUTONOMOUS_MEMORY_POWER_STATE_ENTRY 0x02 -#define EFI_ACPI_5_0_MPST_MEMORY_POWER_STATE_CHARACTERISTICS_STRUCTURE_FLAG_AUTONOMOUS_MEMORY_POWER_STATE_EXIT 0x04 - -typedef struct { - UINT16 MemoryPowerStateCharacteristicsCount; - UINT8 Reserved[2]; -} EFI_ACPI_5_0_MPST_MEMORY_POWER_STATE_CHARACTERISTICS_TABLE; - -/// -/// Memory Topology Table definition. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 Reserved; -} EFI_ACPI_5_0_MEMORY_TOPOLOGY_TABLE; - -/// -/// PMTT Version (as defined in ACPI 5.0 spec.) -/// -#define EFI_ACPI_5_0_MEMORY_TOPOLOGY_TABLE_REVISION 0x01 - -/// -/// Common Memory Aggregator Device Structure. -/// -typedef struct { - UINT8 Type; - UINT8 Reserved; - UINT16 Length; - UINT16 Flags; - UINT16 Reserved1; -} EFI_ACPI_5_0_PMMT_COMMON_MEMORY_AGGREGATOR_DEVICE_STRUCTURE; - -/// -/// Memory Aggregator Device Type -/// -#define EFI_ACPI_5_0_PMMT_MEMORY_AGGREGATOR_DEVICE_TYPE_SOCKET 0x1 -#define EFI_ACPI_5_0_PMMT_MEMORY_AGGREGATOR_DEVICE_TYPE_MEMORY_CONTROLLER 0x2 -#define EFI_ACPI_5_0_PMMT_MEMORY_AGGREGATOR_DEVICE_TYPE_DIMM 0x3 - -/// -/// Socket Memory Aggregator Device Structure. -/// -typedef struct { - EFI_ACPI_5_0_PMMT_COMMON_MEMORY_AGGREGATOR_DEVICE_STRUCTURE Header; - UINT16 SocketIdentifier; - UINT16 Reserved; -//EFI_ACPI_5_0_PMMT_MEMORY_CONTROLLER_MEMORY_AGGREGATOR_DEVICE_STRUCTURE MemoryController[]; -} EFI_ACPI_5_0_PMMT_SOCKET_MEMORY_AGGREGATOR_DEVICE_STRUCTURE; - -/// -/// MemoryController Memory Aggregator Device Structure. -/// -typedef struct { - EFI_ACPI_5_0_PMMT_COMMON_MEMORY_AGGREGATOR_DEVICE_STRUCTURE Header; - UINT32 ReadLatency; - UINT32 WriteLatency; - UINT32 ReadBandwidth; - UINT32 WriteBandwidth; - UINT16 OptimalAccessUnit; - UINT16 OptimalAccessAlignment; - UINT16 Reserved; - UINT16 NumberOfProximityDomains; -//UINT32 ProximityDomain[NumberOfProximityDomains]; -//EFI_ACPI_5_0_PMMT_DIMM_MEMORY_AGGREGATOR_DEVICE_STRUCTURE PhysicalComponent[]; -} EFI_ACPI_5_0_PMMT_MEMORY_CONTROLLER_MEMORY_AGGREGATOR_DEVICE_STRUCTURE; - -/// -/// DIMM Memory Aggregator Device Structure. -/// -typedef struct { - EFI_ACPI_5_0_PMMT_COMMON_MEMORY_AGGREGATOR_DEVICE_STRUCTURE Header; - UINT16 PhysicalComponentIdentifier; - UINT16 Reserved; - UINT32 SizeOfDimm; - UINT32 SmbiosHandle; -} EFI_ACPI_5_0_PMMT_DIMM_MEMORY_AGGREGATOR_DEVICE_STRUCTURE; - -/// -/// Boot Graphics Resource Table definition. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - /// - /// 2-bytes (16 bit) version ID. This value must be 1. - /// - UINT16 Version; - /// - /// 1-byte status field indicating current status about the table. - /// Bits[7:1] = Reserved (must be zero) - /// Bit [0] = Valid. A one indicates the boot image graphic is valid. - /// - UINT8 Status; - /// - /// 1-byte enumerated type field indicating format of the image. - /// 0 = Bitmap - /// 1 - 255 Reserved (for future use) - /// - UINT8 ImageType; - /// - /// 8-byte (64 bit) physical address pointing to the firmware's in-memory copy - /// of the image bitmap. - /// - UINT64 ImageAddress; - /// - /// A 4-byte (32-bit) unsigned long describing the display X-offset of the boot image. - /// (X, Y) display offset of the top left corner of the boot image. - /// The top left corner of the display is at offset (0, 0). - /// - UINT32 ImageOffsetX; - /// - /// A 4-byte (32-bit) unsigned long describing the display Y-offset of the boot image. - /// (X, Y) display offset of the top left corner of the boot image. - /// The top left corner of the display is at offset (0, 0). - /// - UINT32 ImageOffsetY; -} EFI_ACPI_5_0_BOOT_GRAPHICS_RESOURCE_TABLE; - -/// -/// BGRT Revision -/// -#define EFI_ACPI_5_0_BOOT_GRAPHICS_RESOURCE_TABLE_REVISION 1 - -/// -/// BGRT Version -/// -#define EFI_ACPI_5_0_BGRT_VERSION 0x01 - -/// -/// BGRT Status -/// -#define EFI_ACPI_5_0_BGRT_STATUS_NOT_DISPLAYED 0x00 -#define EFI_ACPI_5_0_BGRT_STATUS_DISPLAYED 0x01 -#define EFI_ACPI_5_0_BGRT_STATUS_INVALID EFI_ACPI_5_0_BGRT_STATUS_NOT_DISPLAYED -#define EFI_ACPI_5_0_BGRT_STATUS_VALID EFI_ACPI_5_0_BGRT_STATUS_DISPLAYED - -/// -/// BGRT Image Type -/// -#define EFI_ACPI_5_0_BGRT_IMAGE_TYPE_BMP 0x00 - -/// -/// FPDT Version (as defined in ACPI 5.0 spec.) -/// -#define EFI_ACPI_5_0_FIRMWARE_PERFORMANCE_DATA_TABLE_REVISION 0x01 - -/// -/// FPDT Performance Record Types -/// -#define EFI_ACPI_5_0_FPDT_RECORD_TYPE_FIRMWARE_BASIC_BOOT_POINTER 0x0000 -#define EFI_ACPI_5_0_FPDT_RECORD_TYPE_S3_PERFORMANCE_TABLE_POINTER 0x0001 - -/// -/// FPDT Performance Record Revision -/// -#define EFI_ACPI_5_0_FPDT_RECORD_REVISION_FIRMWARE_BASIC_BOOT_POINTER 0x01 -#define EFI_ACPI_5_0_FPDT_RECORD_REVISION_S3_PERFORMANCE_TABLE_POINTER 0x01 - -/// -/// FPDT Runtime Performance Record Types -/// -#define EFI_ACPI_5_0_FPDT_RUNTIME_RECORD_TYPE_S3_RESUME 0x0000 -#define EFI_ACPI_5_0_FPDT_RUNTIME_RECORD_TYPE_S3_SUSPEND 0x0001 -#define EFI_ACPI_5_0_FPDT_RUNTIME_RECORD_TYPE_FIRMWARE_BASIC_BOOT 0x0002 - -/// -/// FPDT Runtime Performance Record Revision -/// -#define EFI_ACPI_5_0_FPDT_RUNTIME_RECORD_REVISION_S3_RESUME 0x01 -#define EFI_ACPI_5_0_FPDT_RUNTIME_RECORD_REVISION_S3_SUSPEND 0x01 -#define EFI_ACPI_5_0_FPDT_RUNTIME_RECORD_REVISION_FIRMWARE_BASIC_BOOT 0x02 - -/// -/// FPDT Performance Record header -/// -typedef struct { - UINT16 Type; - UINT8 Length; - UINT8 Revision; -} EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER; - -/// -/// FPDT Performance Table header -/// -typedef struct { - UINT32 Signature; - UINT32 Length; -} EFI_ACPI_5_0_FPDT_PERFORMANCE_TABLE_HEADER; - -/// -/// FPDT Firmware Basic Boot Performance Pointer Record Structure -/// -typedef struct { - EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER Header; - UINT32 Reserved; - /// - /// 64-bit processor-relative physical address of the Basic Boot Performance Table. - /// - UINT64 BootPerformanceTablePointer; -} EFI_ACPI_5_0_FPDT_BOOT_PERFORMANCE_TABLE_POINTER_RECORD; - -/// -/// FPDT S3 Performance Table Pointer Record Structure -/// -typedef struct { - EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER Header; - UINT32 Reserved; - /// - /// 64-bit processor-relative physical address of the S3 Performance Table. - /// - UINT64 S3PerformanceTablePointer; -} EFI_ACPI_5_0_FPDT_S3_PERFORMANCE_TABLE_POINTER_RECORD; - -/// -/// FPDT Firmware Basic Boot Performance Record Structure -/// -typedef struct { - EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER Header; - UINT32 Reserved; - /// - /// Timer value logged at the beginning of firmware image execution. - /// This may not always be zero or near zero. - /// - UINT64 ResetEnd; - /// - /// Timer value logged just prior to loading the OS boot loader into memory. - /// For non-UEFI compatible boots, this field must be zero. - /// - UINT64 OsLoaderLoadImageStart; - /// - /// Timer value logged just prior to launching the previously loaded OS boot loader image. - /// For non-UEFI compatible boots, the timer value logged will be just prior - /// to the INT 19h handler invocation. - /// - UINT64 OsLoaderStartImageStart; - /// - /// Timer value logged at the point when the OS loader calls the - /// ExitBootServices function for UEFI compatible firmware. - /// For non-UEFI compatible boots, this field must be zero. - /// - UINT64 ExitBootServicesEntry; - /// - /// Timer value logged at the point just prior towhen the OS loader gaining - /// control back from calls the ExitBootServices function for UEFI compatible firmware. - /// For non-UEFI compatible boots, this field must be zero. - /// - UINT64 ExitBootServicesExit; -} EFI_ACPI_5_0_FPDT_FIRMWARE_BASIC_BOOT_RECORD; - -/// -/// FPDT Firmware Basic Boot Performance Table signature -/// -#define EFI_ACPI_5_0_FPDT_BOOT_PERFORMANCE_TABLE_SIGNATURE SIGNATURE_32('F', 'B', 'P', 'T') - -// -// FPDT Firmware Basic Boot Performance Table -// -typedef struct { - EFI_ACPI_5_0_FPDT_PERFORMANCE_TABLE_HEADER Header; - // - // one or more Performance Records. - // -} EFI_ACPI_5_0_FPDT_FIRMWARE_BASIC_BOOT_TABLE; - -/// -/// FPDT "S3PT" S3 Performance Table -/// -#define EFI_ACPI_5_0_FPDT_S3_PERFORMANCE_TABLE_SIGNATURE SIGNATURE_32('S', '3', 'P', 'T') - -// -// FPDT Firmware S3 Boot Performance Table -// -typedef struct { - EFI_ACPI_5_0_FPDT_PERFORMANCE_TABLE_HEADER Header; - // - // one or more Performance Records. - // -} EFI_ACPI_5_0_FPDT_FIRMWARE_S3_BOOT_TABLE; - -/// -/// FPDT Basic S3 Resume Performance Record -/// -typedef struct { - EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER Header; - /// - /// A count of the number of S3 resume cycles since the last full boot sequence. - /// - UINT32 ResumeCount; - /// - /// Timer recorded at the end of BIOS S3 resume, just prior to handoff to the - /// OS waking vector. Only the most recent resume cycle's time is retained. - /// - UINT64 FullResume; - /// - /// Average timer value of all resume cycles logged since the last full boot - /// sequence, including the most recent resume. Note that the entire log of - /// timer values does not need to be retained in order to calculate this average. - /// - UINT64 AverageResume; -} EFI_ACPI_5_0_FPDT_S3_RESUME_RECORD; - -/// -/// FPDT Basic S3 Suspend Performance Record -/// -typedef struct { - EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER Header; - /// - /// Timer value recorded at the OS write to SLP_TYP upon entry to S3. - /// Only the most recent suspend cycle's timer value is retained. - /// - UINT64 SuspendStart; - /// - /// Timer value recorded at the final firmware write to SLP_TYP (or other - /// mechanism) used to trigger hardware entry to S3. - /// Only the most recent suspend cycle's timer value is retained. - /// - UINT64 SuspendEnd; -} EFI_ACPI_5_0_FPDT_S3_SUSPEND_RECORD; - -/// -/// Firmware Performance Record Table definition. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; -} EFI_ACPI_5_0_FIRMWARE_PERFORMANCE_RECORD_TABLE; - -/// -/// Generic Timer Description Table definition. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT64 PhysicalAddress; - UINT32 GlobalFlags; - UINT32 SecurePL1TimerGSIV; - UINT32 SecurePL1TimerFlags; - UINT32 NonSecurePL1TimerGSIV; - UINT32 NonSecurePL1TimerFlags; - UINT32 VirtualTimerGSIV; - UINT32 VirtualTimerFlags; - UINT32 NonSecurePL2TimerGSIV; - UINT32 NonSecurePL2TimerFlags; -} EFI_ACPI_5_0_GENERIC_TIMER_DESCRIPTION_TABLE; - -/// -/// GTDT Version (as defined in ACPI 5.0 spec.) -/// -#define EFI_ACPI_5_0_GENERIC_TIMER_DESCRIPTION_TABLE_REVISION 0x01 - -/// -/// Global Flags. All other bits are reserved and must be 0. -/// -#define EFI_ACPI_5_0_GTDT_GLOBAL_FLAG_MEMORY_MAPPED_BLOCK_PRESENT BIT0 -#define EFI_ACPI_5_0_GTDT_GLOBAL_FLAG_INTERRUPT_MODE BIT1 - -/// -/// Timer Flags. All other bits are reserved and must be 0. -/// -#define EFI_ACPI_5_0_GTDT_TIMER_FLAG_TIMER_INTERRUPT_MODE BIT0 -#define EFI_ACPI_5_0_GTDT_TIMER_FLAG_TIMER_INTERRUPT_POLARITY BIT1 - -/// -/// Boot Error Record Table (BERT) -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 BootErrorRegionLength; - UINT64 BootErrorRegion; -} EFI_ACPI_5_0_BOOT_ERROR_RECORD_TABLE_HEADER; - -/// -/// BERT Version (as defined in ACPI 5.0 spec.) -/// -#define EFI_ACPI_5_0_BOOT_ERROR_RECORD_TABLE_REVISION 0x01 - -/// -/// Boot Error Region Block Status Definition -/// -typedef struct { - UINT32 UncorrectableErrorValid:1; - UINT32 CorrectableErrorValid:1; - UINT32 MultipleUncorrectableErrors:1; - UINT32 MultipleCorrectableErrors:1; - UINT32 ErrorDataEntryCount:10; - UINT32 Reserved:18; -} EFI_ACPI_5_0_ERROR_BLOCK_STATUS; - -/// -/// Boot Error Region Definition -/// -typedef struct { - EFI_ACPI_5_0_ERROR_BLOCK_STATUS BlockStatus; - UINT32 RawDataOffset; - UINT32 RawDataLength; - UINT32 DataLength; - UINT32 ErrorSeverity; -} EFI_ACPI_5_0_BOOT_ERROR_REGION_STRUCTURE; - -// -// Boot Error Severity types -// -#define EFI_ACPI_5_0_ERROR_SEVERITY_CORRECTABLE 0x00 -#define EFI_ACPI_5_0_ERROR_SEVERITY_FATAL 0x01 -#define EFI_ACPI_5_0_ERROR_SEVERITY_CORRECTED 0x02 -#define EFI_ACPI_5_0_ERROR_SEVERITY_NONE 0x03 - -/// -/// Generic Error Data Entry Definition -/// -typedef struct { - UINT8 SectionType[16]; - UINT32 ErrorSeverity; - UINT16 Revision; - UINT8 ValidationBits; - UINT8 Flags; - UINT32 ErrorDataLength; - UINT8 FruId[16]; - UINT8 FruText[20]; -} EFI_ACPI_5_0_GENERIC_ERROR_DATA_ENTRY_STRUCTURE; - -/// -/// Generic Error Data Entry Version (as defined in ACPI 5.0 spec.) -/// -#define EFI_ACPI_5_0_GENERIC_ERROR_DATA_ENTRY_REVISION 0x0201 - -/// -/// HEST - Hardware Error Source Table -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 ErrorSourceCount; -} EFI_ACPI_5_0_HARDWARE_ERROR_SOURCE_TABLE_HEADER; - -/// -/// HEST Version (as defined in ACPI 5.0 spec.) -/// -#define EFI_ACPI_5_0_HARDWARE_ERROR_SOURCE_TABLE_REVISION 0x01 - -// -// Error Source structure types. -// -#define EFI_ACPI_5_0_IA32_ARCHITECTURE_MACHINE_CHECK_EXCEPTION 0x00 -#define EFI_ACPI_5_0_IA32_ARCHITECTURE_CORRECTED_MACHINE_CHECK 0x01 -#define EFI_ACPI_5_0_IA32_ARCHITECTURE_NMI_ERROR 0x02 -#define EFI_ACPI_5_0_PCI_EXPRESS_ROOT_PORT_AER 0x06 -#define EFI_ACPI_5_0_PCI_EXPRESS_DEVICE_AER 0x07 -#define EFI_ACPI_5_0_PCI_EXPRESS_BRIDGE_AER 0x08 -#define EFI_ACPI_5_0_GENERIC_HARDWARE_ERROR 0x09 - -// -// Error Source structure flags. -// -#define EFI_ACPI_5_0_ERROR_SOURCE_FLAG_FIRMWARE_FIRST (1 << 0) -#define EFI_ACPI_5_0_ERROR_SOURCE_FLAG_GLOBAL (1 << 1) - -/// -/// IA-32 Architecture Machine Check Exception Structure Definition -/// -typedef struct { - UINT16 Type; - UINT16 SourceId; - UINT8 Reserved0[2]; - UINT8 Flags; - UINT8 Enabled; - UINT32 NumberOfRecordsToPreAllocate; - UINT32 MaxSectionsPerRecord; - UINT64 GlobalCapabilityInitData; - UINT64 GlobalControlInitData; - UINT8 NumberOfHardwareBanks; - UINT8 Reserved1[7]; -} EFI_ACPI_5_0_IA32_ARCHITECTURE_MACHINE_CHECK_EXCEPTION_STRUCTURE; - -/// -/// IA-32 Architecture Machine Check Bank Structure Definition -/// -typedef struct { - UINT8 BankNumber; - UINT8 ClearStatusOnInitialization; - UINT8 StatusDataFormat; - UINT8 Reserved0; - UINT32 ControlRegisterMsrAddress; - UINT64 ControlInitData; - UINT32 StatusRegisterMsrAddress; - UINT32 AddressRegisterMsrAddress; - UINT32 MiscRegisterMsrAddress; -} EFI_ACPI_5_0_IA32_ARCHITECTURE_MACHINE_CHECK_ERROR_BANK_STRUCTURE; - -/// -/// IA-32 Architecture Machine Check Bank Structure MCA data format -/// -#define EFI_ACPI_5_0_IA32_ARCHITECTURE_MACHINE_CHECK_ERROR_DATA_FORMAT_IA32 0x00 -#define EFI_ACPI_5_0_IA32_ARCHITECTURE_MACHINE_CHECK_ERROR_DATA_FORMAT_INTEL64 0x01 -#define EFI_ACPI_5_0_IA32_ARCHITECTURE_MACHINE_CHECK_ERROR_DATA_FORMAT_AMD64 0x02 - -// -// Hardware Error Notification types. All other values are reserved -// -#define EFI_ACPI_5_0_HARDWARE_ERROR_NOTIFICATION_POLLED 0x00 -#define EFI_ACPI_5_0_HARDWARE_ERROR_NOTIFICATION_EXTERNAL_INTERRUPT 0x01 -#define EFI_ACPI_5_0_HARDWARE_ERROR_NOTIFICATION_LOCAL_INTERRUPT 0x02 -#define EFI_ACPI_5_0_HARDWARE_ERROR_NOTIFICATION_SCI 0x03 -#define EFI_ACPI_5_0_HARDWARE_ERROR_NOTIFICATION_NMI 0x04 - -/// -/// Hardware Error Notification Configuration Write Enable Structure Definition -/// -typedef struct { - UINT16 Type:1; - UINT16 PollInterval:1; - UINT16 SwitchToPollingThresholdValue:1; - UINT16 SwitchToPollingThresholdWindow:1; - UINT16 ErrorThresholdValue:1; - UINT16 ErrorThresholdWindow:1; - UINT16 Reserved:10; -} EFI_ACPI_5_0_HARDWARE_ERROR_NOTIFICATION_CONFIGURATION_WRITE_ENABLE_STRUCTURE; - -/// -/// Hardware Error Notification Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - EFI_ACPI_5_0_HARDWARE_ERROR_NOTIFICATION_CONFIGURATION_WRITE_ENABLE_STRUCTURE ConfigurationWriteEnable; - UINT32 PollInterval; - UINT32 Vector; - UINT32 SwitchToPollingThresholdValue; - UINT32 SwitchToPollingThresholdWindow; - UINT32 ErrorThresholdValue; - UINT32 ErrorThresholdWindow; -} EFI_ACPI_5_0_HARDWARE_ERROR_NOTIFICATION_STRUCTURE; - -/// -/// IA-32 Architecture Corrected Machine Check Structure Definition -/// -typedef struct { - UINT16 Type; - UINT16 SourceId; - UINT8 Reserved0[2]; - UINT8 Flags; - UINT8 Enabled; - UINT32 NumberOfRecordsToPreAllocate; - UINT32 MaxSectionsPerRecord; - EFI_ACPI_5_0_HARDWARE_ERROR_NOTIFICATION_STRUCTURE NotificationStructure; - UINT8 NumberOfHardwareBanks; - UINT8 Reserved1[3]; -} EFI_ACPI_5_0_IA32_ARCHITECTURE_CORRECTED_MACHINE_CHECK_STRUCTURE; - -/// -/// IA-32 Architecture NMI Error Structure Definition -/// -typedef struct { - UINT16 Type; - UINT16 SourceId; - UINT8 Reserved0[2]; - UINT32 NumberOfRecordsToPreAllocate; - UINT32 MaxSectionsPerRecord; - UINT32 MaxRawDataLength; -} EFI_ACPI_5_0_IA32_ARCHITECTURE_NMI_ERROR_STRUCTURE; - -/// -/// PCI Express Root Port AER Structure Definition -/// -typedef struct { - UINT16 Type; - UINT16 SourceId; - UINT8 Reserved0[2]; - UINT8 Flags; - UINT8 Enabled; - UINT32 NumberOfRecordsToPreAllocate; - UINT32 MaxSectionsPerRecord; - UINT32 Bus; - UINT16 Device; - UINT16 Function; - UINT16 DeviceControl; - UINT8 Reserved1[2]; - UINT32 UncorrectableErrorMask; - UINT32 UncorrectableErrorSeverity; - UINT32 CorrectableErrorMask; - UINT32 AdvancedErrorCapabilitiesAndControl; - UINT32 RootErrorCommand; -} EFI_ACPI_5_0_PCI_EXPRESS_ROOT_PORT_AER_STRUCTURE; - -/// -/// PCI Express Device AER Structure Definition -/// -typedef struct { - UINT16 Type; - UINT16 SourceId; - UINT8 Reserved0[2]; - UINT8 Flags; - UINT8 Enabled; - UINT32 NumberOfRecordsToPreAllocate; - UINT32 MaxSectionsPerRecord; - UINT32 Bus; - UINT16 Device; - UINT16 Function; - UINT16 DeviceControl; - UINT8 Reserved1[2]; - UINT32 UncorrectableErrorMask; - UINT32 UncorrectableErrorSeverity; - UINT32 CorrectableErrorMask; - UINT32 AdvancedErrorCapabilitiesAndControl; -} EFI_ACPI_5_0_PCI_EXPRESS_DEVICE_AER_STRUCTURE; - -/// -/// PCI Express Bridge AER Structure Definition -/// -typedef struct { - UINT16 Type; - UINT16 SourceId; - UINT8 Reserved0[2]; - UINT8 Flags; - UINT8 Enabled; - UINT32 NumberOfRecordsToPreAllocate; - UINT32 MaxSectionsPerRecord; - UINT32 Bus; - UINT16 Device; - UINT16 Function; - UINT16 DeviceControl; - UINT8 Reserved1[2]; - UINT32 UncorrectableErrorMask; - UINT32 UncorrectableErrorSeverity; - UINT32 CorrectableErrorMask; - UINT32 AdvancedErrorCapabilitiesAndControl; - UINT32 SecondaryUncorrectableErrorMask; - UINT32 SecondaryUncorrectableErrorSeverity; - UINT32 SecondaryAdvancedErrorCapabilitiesAndControl; -} EFI_ACPI_5_0_PCI_EXPRESS_BRIDGE_AER_STRUCTURE; - -/// -/// Generic Hardware Error Source Structure Definition -/// -typedef struct { - UINT16 Type; - UINT16 SourceId; - UINT16 RelatedSourceId; - UINT8 Flags; - UINT8 Enabled; - UINT32 NumberOfRecordsToPreAllocate; - UINT32 MaxSectionsPerRecord; - UINT32 MaxRawDataLength; - EFI_ACPI_5_0_GENERIC_ADDRESS_STRUCTURE ErrorStatusAddress; - EFI_ACPI_5_0_HARDWARE_ERROR_NOTIFICATION_STRUCTURE NotificationStructure; - UINT32 ErrorStatusBlockLength; -} EFI_ACPI_5_0_GENERIC_HARDWARE_ERROR_SOURCE_STRUCTURE; - -/// -/// Generic Error Status Definition -/// -typedef struct { - EFI_ACPI_5_0_ERROR_BLOCK_STATUS BlockStatus; - UINT32 RawDataOffset; - UINT32 RawDataLength; - UINT32 DataLength; - UINT32 ErrorSeverity; -} EFI_ACPI_5_0_GENERIC_ERROR_STATUS_STRUCTURE; - -/// -/// ERST - Error Record Serialization Table -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 SerializationHeaderSize; - UINT8 Reserved0[4]; - UINT32 InstructionEntryCount; -} EFI_ACPI_5_0_ERROR_RECORD_SERIALIZATION_TABLE_HEADER; - -/// -/// ERST Version (as defined in ACPI 5.0 spec.) -/// -#define EFI_ACPI_5_0_ERROR_RECORD_SERIALIZATION_TABLE_REVISION 0x01 - -/// -/// ERST Serialization Actions -/// -#define EFI_ACPI_5_0_ERST_BEGIN_WRITE_OPERATION 0x00 -#define EFI_ACPI_5_0_ERST_BEGIN_READ_OPERATION 0x01 -#define EFI_ACPI_5_0_ERST_BEGIN_CLEAR_OPERATION 0x02 -#define EFI_ACPI_5_0_ERST_END_OPERATION 0x03 -#define EFI_ACPI_5_0_ERST_SET_RECORD_OFFSET 0x04 -#define EFI_ACPI_5_0_ERST_EXECUTE_OPERATION 0x05 -#define EFI_ACPI_5_0_ERST_CHECK_BUSY_STATUS 0x06 -#define EFI_ACPI_5_0_ERST_GET_COMMAND_STATUS 0x07 -#define EFI_ACPI_5_0_ERST_GET_RECORD_IDENTIFIER 0x08 -#define EFI_ACPI_5_0_ERST_SET_RECORD_IDENTIFIER 0x09 -#define EFI_ACPI_5_0_ERST_GET_RECORD_COUNT 0x0A -#define EFI_ACPI_5_0_ERST_BEGIN_DUMMY_WRITE_OPERATION 0x0B -#define EFI_ACPI_5_0_ERST_GET_ERROR_LOG_ADDRESS_RANGE 0x0D -#define EFI_ACPI_5_0_ERST_GET_ERROR_LOG_ADDRESS_RANGE_LENGTH 0x0E -#define EFI_ACPI_5_0_ERST_GET_ERROR_LOG_ADDRESS_RANGE_ATTRIBUTES 0x0F - -/// -/// ERST Action Command Status -/// -#define EFI_ACPI_5_0_ERST_STATUS_SUCCESS 0x00 -#define EFI_ACPI_5_0_ERST_STATUS_NOT_ENOUGH_SPACE 0x01 -#define EFI_ACPI_5_0_ERST_STATUS_HARDWARE_NOT_AVAILABLE 0x02 -#define EFI_ACPI_5_0_ERST_STATUS_FAILED 0x03 -#define EFI_ACPI_5_0_ERST_STATUS_RECORD_STORE_EMPTY 0x04 -#define EFI_ACPI_5_0_ERST_STATUS_RECORD_NOT_FOUND 0x05 - -/// -/// ERST Serialization Instructions -/// -#define EFI_ACPI_5_0_ERST_READ_REGISTER 0x00 -#define EFI_ACPI_5_0_ERST_READ_REGISTER_VALUE 0x01 -#define EFI_ACPI_5_0_ERST_WRITE_REGISTER 0x02 -#define EFI_ACPI_5_0_ERST_WRITE_REGISTER_VALUE 0x03 -#define EFI_ACPI_5_0_ERST_NOOP 0x04 -#define EFI_ACPI_5_0_ERST_LOAD_VAR1 0x05 -#define EFI_ACPI_5_0_ERST_LOAD_VAR2 0x06 -#define EFI_ACPI_5_0_ERST_STORE_VAR1 0x07 -#define EFI_ACPI_5_0_ERST_ADD 0x08 -#define EFI_ACPI_5_0_ERST_SUBTRACT 0x09 -#define EFI_ACPI_5_0_ERST_ADD_VALUE 0x0A -#define EFI_ACPI_5_0_ERST_SUBTRACT_VALUE 0x0B -#define EFI_ACPI_5_0_ERST_STALL 0x0C -#define EFI_ACPI_5_0_ERST_STALL_WHILE_TRUE 0x0D -#define EFI_ACPI_5_0_ERST_SKIP_NEXT_INSTRUCTION_IF_TRUE 0x0E -#define EFI_ACPI_5_0_ERST_GOTO 0x0F -#define EFI_ACPI_5_0_ERST_SET_SRC_ADDRESS_BASE 0x10 -#define EFI_ACPI_5_0_ERST_SET_DST_ADDRESS_BASE 0x11 -#define EFI_ACPI_5_0_ERST_MOVE_DATA 0x12 - -/// -/// ERST Instruction Flags -/// -#define EFI_ACPI_5_0_ERST_PRESERVE_REGISTER 0x01 - -/// -/// ERST Serialization Instruction Entry -/// -typedef struct { - UINT8 SerializationAction; - UINT8 Instruction; - UINT8 Flags; - UINT8 Reserved0; - EFI_ACPI_5_0_GENERIC_ADDRESS_STRUCTURE RegisterRegion; - UINT64 Value; - UINT64 Mask; -} EFI_ACPI_5_0_ERST_SERIALIZATION_INSTRUCTION_ENTRY; - -/// -/// EINJ - Error Injection Table -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 InjectionHeaderSize; - UINT8 InjectionFlags; - UINT8 Reserved0[3]; - UINT32 InjectionEntryCount; -} EFI_ACPI_5_0_ERROR_INJECTION_TABLE_HEADER; - -/// -/// EINJ Version (as defined in ACPI 5.0 spec.) -/// -#define EFI_ACPI_5_0_ERROR_INJECTION_TABLE_REVISION 0x01 - -/// -/// EINJ Error Injection Actions -/// -#define EFI_ACPI_5_0_EINJ_BEGIN_INJECTION_OPERATION 0x00 -#define EFI_ACPI_5_0_EINJ_GET_TRIGGER_ERROR_ACTION_TABLE 0x01 -#define EFI_ACPI_5_0_EINJ_SET_ERROR_TYPE 0x02 -#define EFI_ACPI_5_0_EINJ_GET_ERROR_TYPE 0x03 -#define EFI_ACPI_5_0_EINJ_END_OPERATION 0x04 -#define EFI_ACPI_5_0_EINJ_EXECUTE_OPERATION 0x05 -#define EFI_ACPI_5_0_EINJ_CHECK_BUSY_STATUS 0x06 -#define EFI_ACPI_5_0_EINJ_GET_COMMAND_STATUS 0x07 -#define EFI_ACPI_5_0_EINJ_TRIGGER_ERROR 0xFF - -/// -/// EINJ Action Command Status -/// -#define EFI_ACPI_5_0_EINJ_STATUS_SUCCESS 0x00 -#define EFI_ACPI_5_0_EINJ_STATUS_UNKNOWN_FAILURE 0x01 -#define EFI_ACPI_5_0_EINJ_STATUS_INVALID_ACCESS 0x02 - -/// -/// EINJ Error Type Definition -/// -#define EFI_ACPI_5_0_EINJ_ERROR_PROCESSOR_CORRECTABLE (1 << 0) -#define EFI_ACPI_5_0_EINJ_ERROR_PROCESSOR_UNCORRECTABLE_NONFATAL (1 << 1) -#define EFI_ACPI_5_0_EINJ_ERROR_PROCESSOR_UNCORRECTABLE_FATAL (1 << 2) -#define EFI_ACPI_5_0_EINJ_ERROR_MEMORY_CORRECTABLE (1 << 3) -#define EFI_ACPI_5_0_EINJ_ERROR_MEMORY_UNCORRECTABLE_NONFATAL (1 << 4) -#define EFI_ACPI_5_0_EINJ_ERROR_MEMORY_UNCORRECTABLE_FATAL (1 << 5) -#define EFI_ACPI_5_0_EINJ_ERROR_PCI_EXPRESS_CORRECTABLE (1 << 6) -#define EFI_ACPI_5_0_EINJ_ERROR_PCI_EXPRESS_UNCORRECTABLE_NONFATAL (1 << 7) -#define EFI_ACPI_5_0_EINJ_ERROR_PCI_EXPRESS_UNCORRECTABLE_FATAL (1 << 8) -#define EFI_ACPI_5_0_EINJ_ERROR_PLATFORM_CORRECTABLE (1 << 9) -#define EFI_ACPI_5_0_EINJ_ERROR_PLATFORM_UNCORRECTABLE_NONFATAL (1 << 10) -#define EFI_ACPI_5_0_EINJ_ERROR_PLATFORM_UNCORRECTABLE_FATAL (1 << 11) - -/// -/// EINJ Injection Instructions -/// -#define EFI_ACPI_5_0_EINJ_READ_REGISTER 0x00 -#define EFI_ACPI_5_0_EINJ_READ_REGISTER_VALUE 0x01 -#define EFI_ACPI_5_0_EINJ_WRITE_REGISTER 0x02 -#define EFI_ACPI_5_0_EINJ_WRITE_REGISTER_VALUE 0x03 -#define EFI_ACPI_5_0_EINJ_NOOP 0x04 - -/// -/// EINJ Instruction Flags -/// -#define EFI_ACPI_5_0_EINJ_PRESERVE_REGISTER 0x01 - -/// -/// EINJ Injection Instruction Entry -/// -typedef struct { - UINT8 InjectionAction; - UINT8 Instruction; - UINT8 Flags; - UINT8 Reserved0; - EFI_ACPI_5_0_GENERIC_ADDRESS_STRUCTURE RegisterRegion; - UINT64 Value; - UINT64 Mask; -} EFI_ACPI_5_0_EINJ_INJECTION_INSTRUCTION_ENTRY; - -/// -/// EINJ Trigger Action Table -/// -typedef struct { - UINT32 HeaderSize; - UINT32 Revision; - UINT32 TableSize; - UINT32 EntryCount; -} EFI_ACPI_5_0_EINJ_TRIGGER_ACTION_TABLE; - -/// -/// Platform Communications Channel Table (PCCT) -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 Flags; - UINT64 Reserved; -} EFI_ACPI_5_0_PLATFORM_COMMUNICATION_CHANNEL_TABLE_HEADER; - -/// -/// PCCT Version (as defined in ACPI 5.0 spec.) -/// -#define EFI_ACPI_5_0_PLATFORM_COMMUNICATION_CHANNEL_TABLE_REVISION 0x01 - -/// -/// PCCT Global Flags -/// -#define EFI_ACPI_5_0_PCCT_FLAGS_SCI_DOORBELL BIT0 - -// -// PCCT Subspace type -// -#define EFI_ACPI_5_0_PCCT_SUBSPACE_TYPE_GENERIC 0x00 - -/// -/// PCC Subspace Structure Header -/// -typedef struct { - UINT8 Type; - UINT8 Length; -} EFI_ACPI_5_0_PCCT_SUBSPACE_HEADER; - -/// -/// Generic Communications Subspace Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 Reserved[6]; - UINT64 BaseAddress; - UINT64 AddressLength; - EFI_ACPI_5_0_GENERIC_ADDRESS_STRUCTURE DoorbellRegister; - UINT64 DoorbellPreserve; - UINT64 DoorbellWrite; - UINT32 NominalLatency; - UINT32 MaximumPeriodicAccessRate; - UINT16 MinimumRequestTurnaroundTime; -} EFI_ACPI_5_0_PCCT_SUBSPACE_GENERIC; - -/// -/// Generic Communications Channel Shared Memory Region -/// - -typedef struct { - UINT8 Command; - UINT8 Reserved:7; - UINT8 GenerateSci:1; -} EFI_ACPI_5_0_PCCT_GENERIC_SHARED_MEMORY_REGION_COMMAND; - -typedef struct { - UINT8 CommandComplete:1; - UINT8 SciDoorbell:1; - UINT8 Error:1; - UINT8 PlatformNotification:1; - UINT8 Reserved:4; - UINT8 Reserved1; -} EFI_ACPI_5_0_PCCT_GENERIC_SHARED_MEMORY_REGION_STATUS; - -typedef struct { - UINT32 Signature; - EFI_ACPI_5_0_PCCT_GENERIC_SHARED_MEMORY_REGION_COMMAND Command; - EFI_ACPI_5_0_PCCT_GENERIC_SHARED_MEMORY_REGION_STATUS Status; -} EFI_ACPI_5_0_PCCT_GENERIC_SHARED_MEMORY_REGION_HEADER; - -// -// Known table signatures -// - -/// -/// "RSD PTR " Root System Description Pointer -/// -#define EFI_ACPI_5_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE SIGNATURE_64('R', 'S', 'D', ' ', 'P', 'T', 'R', ' ') - -/// -/// "APIC" Multiple APIC Description Table -/// -#define EFI_ACPI_5_0_MULTIPLE_APIC_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('A', 'P', 'I', 'C') - -/// -/// "BERT" Boot Error Record Table -/// -#define EFI_ACPI_5_0_BOOT_ERROR_RECORD_TABLE_SIGNATURE SIGNATURE_32('B', 'E', 'R', 'T') - -/// -/// "BGRT" Boot Graphics Resource Table -/// -#define EFI_ACPI_5_0_BOOT_GRAPHICS_RESOURCE_TABLE_SIGNATURE SIGNATURE_32('B', 'G', 'R', 'T') - -/// -/// "CPEP" Corrected Platform Error Polling Table -/// -#define EFI_ACPI_5_0_CORRECTED_PLATFORM_ERROR_POLLING_TABLE_SIGNATURE SIGNATURE_32('C', 'P', 'E', 'P') - -/// -/// "DSDT" Differentiated System Description Table -/// -#define EFI_ACPI_5_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('D', 'S', 'D', 'T') - -/// -/// "ECDT" Embedded Controller Boot Resources Table -/// -#define EFI_ACPI_5_0_EMBEDDED_CONTROLLER_BOOT_RESOURCES_TABLE_SIGNATURE SIGNATURE_32('E', 'C', 'D', 'T') - -/// -/// "EINJ" Error Injection Table -/// -#define EFI_ACPI_5_0_ERROR_INJECTION_TABLE_SIGNATURE SIGNATURE_32('E', 'I', 'N', 'J') - -/// -/// "ERST" Error Record Serialization Table -/// -#define EFI_ACPI_5_0_ERROR_RECORD_SERIALIZATION_TABLE_SIGNATURE SIGNATURE_32('E', 'R', 'S', 'T') - -/// -/// "FACP" Fixed ACPI Description Table -/// -#define EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('F', 'A', 'C', 'P') - -/// -/// "FACS" Firmware ACPI Control Structure -/// -#define EFI_ACPI_5_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE SIGNATURE_32('F', 'A', 'C', 'S') - -/// -/// "FPDT" Firmware Performance Data Table -/// -#define EFI_ACPI_5_0_FIRMWARE_PERFORMANCE_DATA_TABLE_SIGNATURE SIGNATURE_32('F', 'P', 'D', 'T') - -/// -/// "GTDT" Generic Timer Description Table -/// -#define EFI_ACPI_5_0_GENERIC_TIMER_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('G', 'T', 'D', 'T') - -/// -/// "HEST" Hardware Error Source Table -/// -#define EFI_ACPI_5_0_HARDWARE_ERROR_SOURCE_TABLE_SIGNATURE SIGNATURE_32('H', 'E', 'S', 'T') - -/// -/// "MPST" Memory Power State Table -/// -#define EFI_ACPI_5_0_MEMORY_POWER_STATE_TABLE_SIGNATURE SIGNATURE_32('M', 'P', 'S', 'T') - -/// -/// "MSCT" Maximum System Characteristics Table -/// -#define EFI_ACPI_5_0_MAXIMUM_SYSTEM_CHARACTERISTICS_TABLE_SIGNATURE SIGNATURE_32('M', 'S', 'C', 'T') - -/// -/// "PMTT" Platform Memory Topology Table -/// -#define EFI_ACPI_5_0_PLATFORM_MEMORY_TOPOLOGY_TABLE_SIGNATURE SIGNATURE_32('P', 'M', 'T', 'T') - -/// -/// "PSDT" Persistent System Description Table -/// -#define EFI_ACPI_5_0_PERSISTENT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('P', 'S', 'D', 'T') - -/// -/// "RASF" ACPI RAS Feature Table -/// -#define EFI_ACPI_5_0_ACPI_RAS_FEATURE_TABLE_SIGNATURE SIGNATURE_32('R', 'A', 'S', 'F') - -/// -/// "RSDT" Root System Description Table -/// -#define EFI_ACPI_5_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('R', 'S', 'D', 'T') - -/// -/// "SBST" Smart Battery Specification Table -/// -#define EFI_ACPI_5_0_SMART_BATTERY_SPECIFICATION_TABLE_SIGNATURE SIGNATURE_32('S', 'B', 'S', 'T') - -/// -/// "SLIT" System Locality Information Table -/// -#define EFI_ACPI_5_0_SYSTEM_LOCALITY_INFORMATION_TABLE_SIGNATURE SIGNATURE_32('S', 'L', 'I', 'T') - -/// -/// "SRAT" System Resource Affinity Table -/// -#define EFI_ACPI_5_0_SYSTEM_RESOURCE_AFFINITY_TABLE_SIGNATURE SIGNATURE_32('S', 'R', 'A', 'T') - -/// -/// "SSDT" Secondary System Description Table -/// -#define EFI_ACPI_5_0_SECONDARY_SYSTEM_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('S', 'S', 'D', 'T') - -/// -/// "XSDT" Extended System Description Table -/// -#define EFI_ACPI_5_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('X', 'S', 'D', 'T') - -/// -/// "BOOT" MS Simple Boot Spec -/// -#define EFI_ACPI_5_0_SIMPLE_BOOT_FLAG_TABLE_SIGNATURE SIGNATURE_32('B', 'O', 'O', 'T') - -/// -/// "CSRT" MS Core System Resource Table -/// -#define EFI_ACPI_5_0_CORE_SYSTEM_RESOURCE_TABLE_SIGNATURE SIGNATURE_32('C', 'S', 'R', 'T') - -/// -/// "DBG2" MS Debug Port 2 Spec -/// -#define EFI_ACPI_5_0_DEBUG_PORT_2_TABLE_SIGNATURE SIGNATURE_32('D', 'B', 'G', '2') - -/// -/// "DBGP" MS Debug Port Spec -/// -#define EFI_ACPI_5_0_DEBUG_PORT_TABLE_SIGNATURE SIGNATURE_32('D', 'B', 'G', 'P') - -/// -/// "DMAR" DMA Remapping Table -/// -#define EFI_ACPI_5_0_DMA_REMAPPING_TABLE_SIGNATURE SIGNATURE_32('D', 'M', 'A', 'R') - -/// -/// "DRTM" Dynamic Root of Trust for Measurement Table -/// -#define EFI_ACPI_5_0_DYNAMIC_ROOT_OF_TRUST_FOR_MEASUREMENT_TABLE_SIGNATURE SIGNATURE_32('D', 'R', 'T', 'M') - -/// -/// "ETDT" Event Timer Description Table -/// -#define EFI_ACPI_5_0_EVENT_TIMER_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('E', 'T', 'D', 'T') - -/// -/// "HPET" IA-PC High Precision Event Timer Table -/// -#define EFI_ACPI_5_0_HIGH_PRECISION_EVENT_TIMER_TABLE_SIGNATURE SIGNATURE_32('H', 'P', 'E', 'T') - -/// -/// "iBFT" iSCSI Boot Firmware Table -/// -#define EFI_ACPI_5_0_ISCSI_BOOT_FIRMWARE_TABLE_SIGNATURE SIGNATURE_32('i', 'B', 'F', 'T') - -/// -/// "IVRS" I/O Virtualization Reporting Structure -/// -#define EFI_ACPI_5_0_IO_VIRTUALIZATION_REPORTING_STRUCTURE_SIGNATURE SIGNATURE_32('I', 'V', 'R', 'S') - -/// -/// "MCFG" PCI Express Memory Mapped Configuration Space Base Address Description Table -/// -#define EFI_ACPI_5_0_PCI_EXPRESS_MEMORY_MAPPED_CONFIGURATION_SPACE_BASE_ADDRESS_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('M', 'C', 'F', 'G') - -/// -/// "MCHI" Management Controller Host Interface Table -/// -#define EFI_ACPI_5_0_MANAGEMENT_CONTROLLER_HOST_INTERFACE_TABLE_SIGNATURE SIGNATURE_32('M', 'C', 'H', 'I') - -/// -/// "MSDM" MS Data Management Table -/// -#define EFI_ACPI_5_0_DATA_MANAGEMENT_TABLE_SIGNATURE SIGNATURE_32('M', 'S', 'D', 'M') - -/// -/// "SLIC" MS Software Licensing Table Specification -/// -#define EFI_ACPI_5_0_SOFTWARE_LICENSING_TABLE_SIGNATURE SIGNATURE_32('S', 'L', 'I', 'C') - -/// -/// "SPCR" Serial Port Concole Redirection Table -/// -#define EFI_ACPI_5_0_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_SIGNATURE SIGNATURE_32('S', 'P', 'C', 'R') - -/// -/// "SPMI" Server Platform Management Interface Table -/// -#define EFI_ACPI_5_0_SERVER_PLATFORM_MANAGEMENT_INTERFACE_TABLE_SIGNATURE SIGNATURE_32('S', 'P', 'M', 'I') - -/// -/// "TCPA" Trusted Computing Platform Alliance Capabilities Table -/// -#define EFI_ACPI_5_0_TRUSTED_COMPUTING_PLATFORM_ALLIANCE_CAPABILITIES_TABLE_SIGNATURE SIGNATURE_32('T', 'C', 'P', 'A') - -/// -/// "TPM2" Trusted Computing Platform 1 Table -/// -#define EFI_ACPI_5_0_TRUSTED_COMPUTING_PLATFORM_2_TABLE_SIGNATURE SIGNATURE_32('T', 'P', 'M', '2') - -/// -/// "UEFI" UEFI ACPI Data Table -/// -#define EFI_ACPI_5_0_UEFI_ACPI_DATA_TABLE_SIGNATURE SIGNATURE_32('U', 'E', 'F', 'I') - -/// -/// "WAET" Windows ACPI Emulated Devices Table -/// -#define EFI_ACPI_5_0_WINDOWS_ACPI_EMULATED_DEVICES_TABLE_SIGNATURE SIGNATURE_32('W', 'A', 'E', 'T') -#define EFI_ACPI_5_0_WINDOWS_ACPI_ENLIGHTENMENT_TABLE_SIGNATURE EFI_ACPI_5_0_WINDOWS_ACPI_EMULATED_DEVICES_TABLE_SIGNATURE - -/// -/// "WDAT" Watchdog Action Table -/// -#define EFI_ACPI_5_0_WATCHDOG_ACTION_TABLE_SIGNATURE SIGNATURE_32('W', 'D', 'A', 'T') - -/// -/// "WDRT" Watchdog Resource Table -/// -#define EFI_ACPI_5_0_WATCHDOG_RESOURCE_TABLE_SIGNATURE SIGNATURE_32('W', 'D', 'R', 'T') - -/// -/// "WPBT" MS Platform Binary Table -/// -#define EFI_ACPI_5_0_PLATFORM_BINARY_TABLE_SIGNATURE SIGNATURE_32('W', 'P', 'B', 'T') - -#pragma pack() - -#endif diff --git a/roms/ipxe/src/include/ipxe/efi/IndustryStandard/Acpi51.h b/roms/ipxe/src/include/ipxe/efi/IndustryStandard/Acpi51.h deleted file mode 100644 index b00613942..000000000 --- a/roms/ipxe/src/include/ipxe/efi/IndustryStandard/Acpi51.h +++ /dev/null @@ -1,2141 +0,0 @@ -/** @file - ACPI 5.1 definitions from the ACPI Specification Revision 5.1 July, 2014. - - Copyright (c) 2014 Hewlett-Packard Development Company, L.P.<BR> - Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR> - (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR> - This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -**/ - -#ifndef _ACPI_5_1_H_ -#define _ACPI_5_1_H_ - -FILE_LICENCE ( BSD3 ); - -#include <ipxe/efi/IndustryStandard/Acpi50.h> - -// -// Ensure proper structure formats -// -#pragma pack(1) - -/// -/// ACPI 5.1 Generic Address Space definition -/// -typedef struct { - UINT8 AddressSpaceId; - UINT8 RegisterBitWidth; - UINT8 RegisterBitOffset; - UINT8 AccessSize; - UINT64 Address; -} EFI_ACPI_5_1_GENERIC_ADDRESS_STRUCTURE; - -// -// Generic Address Space Address IDs -// -#define EFI_ACPI_5_1_SYSTEM_MEMORY 0 -#define EFI_ACPI_5_1_SYSTEM_IO 1 -#define EFI_ACPI_5_1_PCI_CONFIGURATION_SPACE 2 -#define EFI_ACPI_5_1_EMBEDDED_CONTROLLER 3 -#define EFI_ACPI_5_1_SMBUS 4 -#define EFI_ACPI_5_1_PLATFORM_COMMUNICATION_CHANNEL 0x0A -#define EFI_ACPI_5_1_FUNCTIONAL_FIXED_HARDWARE 0x7F - -// -// Generic Address Space Access Sizes -// -#define EFI_ACPI_5_1_UNDEFINED 0 -#define EFI_ACPI_5_1_BYTE 1 -#define EFI_ACPI_5_1_WORD 2 -#define EFI_ACPI_5_1_DWORD 3 -#define EFI_ACPI_5_1_QWORD 4 - -// -// ACPI 5.1 table structures -// - -/// -/// Root System Description Pointer Structure -/// -typedef struct { - UINT64 Signature; - UINT8 Checksum; - UINT8 OemId[6]; - UINT8 Revision; - UINT32 RsdtAddress; - UINT32 Length; - UINT64 XsdtAddress; - UINT8 ExtendedChecksum; - UINT8 Reserved[3]; -} EFI_ACPI_5_1_ROOT_SYSTEM_DESCRIPTION_POINTER; - -/// -/// RSD_PTR Revision (as defined in ACPI 5.1 spec.) -/// -#define EFI_ACPI_5_1_ROOT_SYSTEM_DESCRIPTION_POINTER_REVISION 0x02 ///< ACPISpec (Revision 5.1) says current value is 2 - -/// -/// Common table header, this prefaces all ACPI tables, including FACS, but -/// excluding the RSD PTR structure -/// -typedef struct { - UINT32 Signature; - UINT32 Length; -} EFI_ACPI_5_1_COMMON_HEADER; - -// -// Root System Description Table -// No definition needed as it is a common description table header, the same with -// EFI_ACPI_DESCRIPTION_HEADER, followed by a variable number of UINT32 table pointers. -// - -/// -/// RSDT Revision (as defined in ACPI 5.1 spec.) -/// -#define EFI_ACPI_5_1_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION 0x01 - -// -// Extended System Description Table -// No definition needed as it is a common description table header, the same with -// EFI_ACPI_DESCRIPTION_HEADER, followed by a variable number of UINT64 table pointers. -// - -/// -/// XSDT Revision (as defined in ACPI 5.1 spec.) -/// -#define EFI_ACPI_5_1_EXTENDED_SYSTEM_DESCRIPTION_TABLE_REVISION 0x01 - -/// -/// Fixed ACPI Description Table Structure (FADT) -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 FirmwareCtrl; - UINT32 Dsdt; - UINT8 Reserved0; - UINT8 PreferredPmProfile; - UINT16 SciInt; - UINT32 SmiCmd; - UINT8 AcpiEnable; - UINT8 AcpiDisable; - UINT8 S4BiosReq; - UINT8 PstateCnt; - UINT32 Pm1aEvtBlk; - UINT32 Pm1bEvtBlk; - UINT32 Pm1aCntBlk; - UINT32 Pm1bCntBlk; - UINT32 Pm2CntBlk; - UINT32 PmTmrBlk; - UINT32 Gpe0Blk; - UINT32 Gpe1Blk; - UINT8 Pm1EvtLen; - UINT8 Pm1CntLen; - UINT8 Pm2CntLen; - UINT8 PmTmrLen; - UINT8 Gpe0BlkLen; - UINT8 Gpe1BlkLen; - UINT8 Gpe1Base; - UINT8 CstCnt; - UINT16 PLvl2Lat; - UINT16 PLvl3Lat; - UINT16 FlushSize; - UINT16 FlushStride; - UINT8 DutyOffset; - UINT8 DutyWidth; - UINT8 DayAlrm; - UINT8 MonAlrm; - UINT8 Century; - UINT16 IaPcBootArch; - UINT8 Reserved1; - UINT32 Flags; - EFI_ACPI_5_1_GENERIC_ADDRESS_STRUCTURE ResetReg; - UINT8 ResetValue; - UINT16 ArmBootArch; - UINT8 MinorVersion; - UINT64 XFirmwareCtrl; - UINT64 XDsdt; - EFI_ACPI_5_1_GENERIC_ADDRESS_STRUCTURE XPm1aEvtBlk; - EFI_ACPI_5_1_GENERIC_ADDRESS_STRUCTURE XPm1bEvtBlk; - EFI_ACPI_5_1_GENERIC_ADDRESS_STRUCTURE XPm1aCntBlk; - EFI_ACPI_5_1_GENERIC_ADDRESS_STRUCTURE XPm1bCntBlk; - EFI_ACPI_5_1_GENERIC_ADDRESS_STRUCTURE XPm2CntBlk; - EFI_ACPI_5_1_GENERIC_ADDRESS_STRUCTURE XPmTmrBlk; - EFI_ACPI_5_1_GENERIC_ADDRESS_STRUCTURE XGpe0Blk; - EFI_ACPI_5_1_GENERIC_ADDRESS_STRUCTURE XGpe1Blk; - EFI_ACPI_5_1_GENERIC_ADDRESS_STRUCTURE SleepControlReg; - EFI_ACPI_5_1_GENERIC_ADDRESS_STRUCTURE SleepStatusReg; -} EFI_ACPI_5_1_FIXED_ACPI_DESCRIPTION_TABLE; - -/// -/// FADT Version (as defined in ACPI 5.1 spec.) -/// -#define EFI_ACPI_5_1_FIXED_ACPI_DESCRIPTION_TABLE_REVISION 0x05 -#define EFI_ACPI_5_1_FIXED_ACPI_DESCRIPTION_TABLE_MINOR_REVISION 0x01 - -// -// Fixed ACPI Description Table Preferred Power Management Profile -// -#define EFI_ACPI_5_1_PM_PROFILE_UNSPECIFIED 0 -#define EFI_ACPI_5_1_PM_PROFILE_DESKTOP 1 -#define EFI_ACPI_5_1_PM_PROFILE_MOBILE 2 -#define EFI_ACPI_5_1_PM_PROFILE_WORKSTATION 3 -#define EFI_ACPI_5_1_PM_PROFILE_ENTERPRISE_SERVER 4 -#define EFI_ACPI_5_1_PM_PROFILE_SOHO_SERVER 5 -#define EFI_ACPI_5_1_PM_PROFILE_APPLIANCE_PC 6 -#define EFI_ACPI_5_1_PM_PROFILE_PERFORMANCE_SERVER 7 -#define EFI_ACPI_5_1_PM_PROFILE_TABLET 8 - -// -// Fixed ACPI Description Table Boot Architecture Flags -// All other bits are reserved and must be set to 0. -// -#define EFI_ACPI_5_1_LEGACY_DEVICES BIT0 -#define EFI_ACPI_5_1_8042 BIT1 -#define EFI_ACPI_5_1_VGA_NOT_PRESENT BIT2 -#define EFI_ACPI_5_1_MSI_NOT_SUPPORTED BIT3 -#define EFI_ACPI_5_1_PCIE_ASPM_CONTROLS BIT4 -#define EFI_ACPI_5_1_CMOS_RTC_NOT_PRESENT BIT5 - -// -// Fixed ACPI Description Table Arm Boot Architecture Flags -// All other bits are reserved and must be set to 0. -// -#define EFI_ACPI_5_1_ARM_PSCI_COMPLIANT BIT0 -#define EFI_ACPI_5_1_ARM_PSCI_USE_HVC BIT1 - -// -// Fixed ACPI Description Table Fixed Feature Flags -// All other bits are reserved and must be set to 0. -// -#define EFI_ACPI_5_1_WBINVD BIT0 -#define EFI_ACPI_5_1_WBINVD_FLUSH BIT1 -#define EFI_ACPI_5_1_PROC_C1 BIT2 -#define EFI_ACPI_5_1_P_LVL2_UP BIT3 -#define EFI_ACPI_5_1_PWR_BUTTON BIT4 -#define EFI_ACPI_5_1_SLP_BUTTON BIT5 -#define EFI_ACPI_5_1_FIX_RTC BIT6 -#define EFI_ACPI_5_1_RTC_S4 BIT7 -#define EFI_ACPI_5_1_TMR_VAL_EXT BIT8 -#define EFI_ACPI_5_1_DCK_CAP BIT9 -#define EFI_ACPI_5_1_RESET_REG_SUP BIT10 -#define EFI_ACPI_5_1_SEALED_CASE BIT11 -#define EFI_ACPI_5_1_HEADLESS BIT12 -#define EFI_ACPI_5_1_CPU_SW_SLP BIT13 -#define EFI_ACPI_5_1_PCI_EXP_WAK BIT14 -#define EFI_ACPI_5_1_USE_PLATFORM_CLOCK BIT15 -#define EFI_ACPI_5_1_S4_RTC_STS_VALID BIT16 -#define EFI_ACPI_5_1_REMOTE_POWER_ON_CAPABLE BIT17 -#define EFI_ACPI_5_1_FORCE_APIC_CLUSTER_MODEL BIT18 -#define EFI_ACPI_5_1_FORCE_APIC_PHYSICAL_DESTINATION_MODE BIT19 -#define EFI_ACPI_5_1_HW_REDUCED_ACPI BIT20 -#define EFI_ACPI_5_1_LOW_POWER_S0_IDLE_CAPABLE BIT21 - -/// -/// Firmware ACPI Control Structure -/// -typedef struct { - UINT32 Signature; - UINT32 Length; - UINT32 HardwareSignature; - UINT32 FirmwareWakingVector; - UINT32 GlobalLock; - UINT32 Flags; - UINT64 XFirmwareWakingVector; - UINT8 Version; - UINT8 Reserved0[3]; - UINT32 OspmFlags; - UINT8 Reserved1[24]; -} EFI_ACPI_5_1_FIRMWARE_ACPI_CONTROL_STRUCTURE; - -/// -/// FACS Version (as defined in ACPI 5.1 spec.) -/// -#define EFI_ACPI_5_1_FIRMWARE_ACPI_CONTROL_STRUCTURE_VERSION 0x02 - -/// -/// Firmware Control Structure Feature Flags -/// All other bits are reserved and must be set to 0. -/// -#define EFI_ACPI_5_1_S4BIOS_F BIT0 -#define EFI_ACPI_5_1_64BIT_WAKE_SUPPORTED_F BIT1 - -/// -/// OSPM Enabled Firmware Control Structure Flags -/// All other bits are reserved and must be set to 0. -/// -#define EFI_ACPI_5_1_OSPM_64BIT_WAKE_F BIT0 - -// -// Differentiated System Description Table, -// Secondary System Description Table -// and Persistent System Description Table, -// no definition needed as they are common description table header, the same with -// EFI_ACPI_DESCRIPTION_HEADER, followed by a definition block. -// -#define EFI_ACPI_5_1_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_REVISION 0x02 -#define EFI_ACPI_5_1_SECONDARY_SYSTEM_DESCRIPTION_TABLE_REVISION 0x02 - -/// -/// Multiple APIC Description Table header definition. The rest of the table -/// must be defined in a platform specific manner. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 LocalApicAddress; - UINT32 Flags; -} EFI_ACPI_5_1_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER; - -/// -/// MADT Revision (as defined in ACPI 5.1 spec.) -/// -#define EFI_ACPI_5_1_MULTIPLE_APIC_DESCRIPTION_TABLE_REVISION 0x03 - -/// -/// Multiple APIC Flags -/// All other bits are reserved and must be set to 0. -/// -#define EFI_ACPI_5_1_PCAT_COMPAT BIT0 - -// -// Multiple APIC Description Table APIC structure types -// All other values between 0x0D and 0x7F are reserved and -// will be ignored by OSPM. 0x80 ~ 0xFF are reserved for OEM. -// -#define EFI_ACPI_5_1_PROCESSOR_LOCAL_APIC 0x00 -#define EFI_ACPI_5_1_IO_APIC 0x01 -#define EFI_ACPI_5_1_INTERRUPT_SOURCE_OVERRIDE 0x02 -#define EFI_ACPI_5_1_NON_MASKABLE_INTERRUPT_SOURCE 0x03 -#define EFI_ACPI_5_1_LOCAL_APIC_NMI 0x04 -#define EFI_ACPI_5_1_LOCAL_APIC_ADDRESS_OVERRIDE 0x05 -#define EFI_ACPI_5_1_IO_SAPIC 0x06 -#define EFI_ACPI_5_1_LOCAL_SAPIC 0x07 -#define EFI_ACPI_5_1_PLATFORM_INTERRUPT_SOURCES 0x08 -#define EFI_ACPI_5_1_PROCESSOR_LOCAL_X2APIC 0x09 -#define EFI_ACPI_5_1_LOCAL_X2APIC_NMI 0x0A -#define EFI_ACPI_5_1_GIC 0x0B -#define EFI_ACPI_5_1_GICD 0x0C -#define EFI_ACPI_5_1_GIC_MSI_FRAME 0x0D -#define EFI_ACPI_5_1_GICR 0x0E - -// -// APIC Structure Definitions -// - -/// -/// Processor Local APIC Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 AcpiProcessorId; - UINT8 ApicId; - UINT32 Flags; -} EFI_ACPI_5_1_PROCESSOR_LOCAL_APIC_STRUCTURE; - -/// -/// Local APIC Flags. All other bits are reserved and must be 0. -/// -#define EFI_ACPI_5_1_LOCAL_APIC_ENABLED BIT0 - -/// -/// IO APIC Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 IoApicId; - UINT8 Reserved; - UINT32 IoApicAddress; - UINT32 GlobalSystemInterruptBase; -} EFI_ACPI_5_1_IO_APIC_STRUCTURE; - -/// -/// Interrupt Source Override Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 Bus; - UINT8 Source; - UINT32 GlobalSystemInterrupt; - UINT16 Flags; -} EFI_ACPI_5_1_INTERRUPT_SOURCE_OVERRIDE_STRUCTURE; - -/// -/// Platform Interrupt Sources Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT16 Flags; - UINT8 InterruptType; - UINT8 ProcessorId; - UINT8 ProcessorEid; - UINT8 IoSapicVector; - UINT32 GlobalSystemInterrupt; - UINT32 PlatformInterruptSourceFlags; - UINT8 CpeiProcessorOverride; - UINT8 Reserved[31]; -} EFI_ACPI_5_1_PLATFORM_INTERRUPT_APIC_STRUCTURE; - -// -// MPS INTI flags. -// All other bits are reserved and must be set to 0. -// -#define EFI_ACPI_5_1_POLARITY (3 << 0) -#define EFI_ACPI_5_1_TRIGGER_MODE (3 << 2) - -/// -/// Non-Maskable Interrupt Source Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT16 Flags; - UINT32 GlobalSystemInterrupt; -} EFI_ACPI_5_1_NON_MASKABLE_INTERRUPT_SOURCE_STRUCTURE; - -/// -/// Local APIC NMI Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 AcpiProcessorId; - UINT16 Flags; - UINT8 LocalApicLint; -} EFI_ACPI_5_1_LOCAL_APIC_NMI_STRUCTURE; - -/// -/// Local APIC Address Override Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT16 Reserved; - UINT64 LocalApicAddress; -} EFI_ACPI_5_1_LOCAL_APIC_ADDRESS_OVERRIDE_STRUCTURE; - -/// -/// IO SAPIC Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 IoApicId; - UINT8 Reserved; - UINT32 GlobalSystemInterruptBase; - UINT64 IoSapicAddress; -} EFI_ACPI_5_1_IO_SAPIC_STRUCTURE; - -/// -/// Local SAPIC Structure -/// This struct followed by a null-terminated ASCII string - ACPI Processor UID String -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 AcpiProcessorId; - UINT8 LocalSapicId; - UINT8 LocalSapicEid; - UINT8 Reserved[3]; - UINT32 Flags; - UINT32 ACPIProcessorUIDValue; -} EFI_ACPI_5_1_PROCESSOR_LOCAL_SAPIC_STRUCTURE; - -/// -/// Platform Interrupt Sources Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT16 Flags; - UINT8 InterruptType; - UINT8 ProcessorId; - UINT8 ProcessorEid; - UINT8 IoSapicVector; - UINT32 GlobalSystemInterrupt; - UINT32 PlatformInterruptSourceFlags; -} EFI_ACPI_5_1_PLATFORM_INTERRUPT_SOURCES_STRUCTURE; - -/// -/// Platform Interrupt Source Flags. -/// All other bits are reserved and must be set to 0. -/// -#define EFI_ACPI_5_1_CPEI_PROCESSOR_OVERRIDE BIT0 - -/// -/// Processor Local x2APIC Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 Reserved[2]; - UINT32 X2ApicId; - UINT32 Flags; - UINT32 AcpiProcessorUid; -} EFI_ACPI_5_1_PROCESSOR_LOCAL_X2APIC_STRUCTURE; - -/// -/// Local x2APIC NMI Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT16 Flags; - UINT32 AcpiProcessorUid; - UINT8 LocalX2ApicLint; - UINT8 Reserved[3]; -} EFI_ACPI_5_1_LOCAL_X2APIC_NMI_STRUCTURE; - -/// -/// GIC Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT16 Reserved; - UINT32 CPUInterfaceNumber; - UINT32 AcpiProcessorUid; - UINT32 Flags; - UINT32 ParkingProtocolVersion; - UINT32 PerformanceInterruptGsiv; - UINT64 ParkedAddress; - UINT64 PhysicalBaseAddress; - UINT64 GICV; - UINT64 GICH; - UINT32 VGICMaintenanceInterrupt; - UINT64 GICRBaseAddress; - UINT64 MPIDR; -} EFI_ACPI_5_1_GIC_STRUCTURE; - -/// -/// GIC Flags. All other bits are reserved and must be 0. -/// -#define EFI_ACPI_5_1_GIC_ENABLED BIT0 -#define EFI_ACPI_5_1_PERFORMANCE_INTERRUPT_MODEL BIT1 -#define EFI_ACPI_5_1_VGIC_MAINTENANCE_INTERRUPT_MODE_FLAGS BIT2 - -/// -/// GIC Distributor Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT16 Reserved1; - UINT32 GicId; - UINT64 PhysicalBaseAddress; - UINT32 SystemVectorBase; - UINT8 GicVersion; - UINT8 Reserved2[3]; -} EFI_ACPI_5_1_GIC_DISTRIBUTOR_STRUCTURE; - -/// -/// GIC Version -/// -#define EFI_ACPI_5_1_GIC_V2 0x01 -#define EFI_ACPI_5_1_GIC_V2m 0x02 -#define EFI_ACPI_5_1_GIC_V3 0x03 -#define EFI_ACPI_5_1_GIC_V4 0x04 - -/// -/// GIC MSI Frame Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT16 Reserved1; - UINT32 GicMsiFrameId; - UINT64 PhysicalBaseAddress; - UINT32 Flags; - UINT16 SPICount; - UINT16 SPIBase; -} EFI_ACPI_5_1_GIC_MSI_FRAME_STRUCTURE; - -/// -/// GIC MSI Frame Flags. All other bits are reserved and must be 0. -/// -#define EFI_ACPI_5_1_SPI_COUNT_BASE_SELECT BIT0 - -/// -/// GICR Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT16 Reserved; - UINT64 DiscoveryRangeBaseAddress; - UINT32 DiscoveryRangeLength; -} EFI_ACPI_5_1_GICR_STRUCTURE; - -/// -/// Smart Battery Description Table (SBST) -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 WarningEnergyLevel; - UINT32 LowEnergyLevel; - UINT32 CriticalEnergyLevel; -} EFI_ACPI_5_1_SMART_BATTERY_DESCRIPTION_TABLE; - -/// -/// SBST Version (as defined in ACPI 5.1 spec.) -/// -#define EFI_ACPI_5_1_SMART_BATTERY_DESCRIPTION_TABLE_REVISION 0x01 - -/// -/// Embedded Controller Boot Resources Table (ECDT) -/// The table is followed by a null terminated ASCII string that contains -/// a fully qualified reference to the name space object. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - EFI_ACPI_5_1_GENERIC_ADDRESS_STRUCTURE EcControl; - EFI_ACPI_5_1_GENERIC_ADDRESS_STRUCTURE EcData; - UINT32 Uid; - UINT8 GpeBit; -} EFI_ACPI_5_1_EMBEDDED_CONTROLLER_BOOT_RESOURCES_TABLE; - -/// -/// ECDT Version (as defined in ACPI 5.1 spec.) -/// -#define EFI_ACPI_5_1_EMBEDDED_CONTROLLER_BOOT_RESOURCES_TABLE_REVISION 0x01 - -/// -/// System Resource Affinity Table (SRAT). The rest of the table -/// must be defined in a platform specific manner. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 Reserved1; ///< Must be set to 1 - UINT64 Reserved2; -} EFI_ACPI_5_1_SYSTEM_RESOURCE_AFFINITY_TABLE_HEADER; - -/// -/// SRAT Version (as defined in ACPI 5.1 spec.) -/// -#define EFI_ACPI_5_1_SYSTEM_RESOURCE_AFFINITY_TABLE_REVISION 0x03 - -// -// SRAT structure types. -// All other values between 0x04 an 0xFF are reserved and -// will be ignored by OSPM. -// -#define EFI_ACPI_5_1_PROCESSOR_LOCAL_APIC_SAPIC_AFFINITY 0x00 -#define EFI_ACPI_5_1_MEMORY_AFFINITY 0x01 -#define EFI_ACPI_5_1_PROCESSOR_LOCAL_X2APIC_AFFINITY 0x02 -#define EFI_ACPI_5_1_GICC_AFFINITY 0x03 - -/// -/// Processor Local APIC/SAPIC Affinity Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 ProximityDomain7To0; - UINT8 ApicId; - UINT32 Flags; - UINT8 LocalSapicEid; - UINT8 ProximityDomain31To8[3]; - UINT32 ClockDomain; -} EFI_ACPI_5_1_PROCESSOR_LOCAL_APIC_SAPIC_AFFINITY_STRUCTURE; - -/// -/// Local APIC/SAPIC Flags. All other bits are reserved and must be 0. -/// -#define EFI_ACPI_5_1_PROCESSOR_LOCAL_APIC_SAPIC_ENABLED (1 << 0) - -/// -/// Memory Affinity Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT32 ProximityDomain; - UINT16 Reserved1; - UINT32 AddressBaseLow; - UINT32 AddressBaseHigh; - UINT32 LengthLow; - UINT32 LengthHigh; - UINT32 Reserved2; - UINT32 Flags; - UINT64 Reserved3; -} EFI_ACPI_5_1_MEMORY_AFFINITY_STRUCTURE; - -// -// Memory Flags. All other bits are reserved and must be 0. -// -#define EFI_ACPI_5_1_MEMORY_ENABLED (1 << 0) -#define EFI_ACPI_5_1_MEMORY_HOT_PLUGGABLE (1 << 1) -#define EFI_ACPI_5_1_MEMORY_NONVOLATILE (1 << 2) - -/// -/// Processor Local x2APIC Affinity Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 Reserved1[2]; - UINT32 ProximityDomain; - UINT32 X2ApicId; - UINT32 Flags; - UINT32 ClockDomain; - UINT8 Reserved2[4]; -} EFI_ACPI_5_1_PROCESSOR_LOCAL_X2APIC_AFFINITY_STRUCTURE; - -/// -/// GICC Affinity Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT32 ProximityDomain; - UINT32 AcpiProcessorUid; - UINT32 Flags; - UINT32 ClockDomain; -} EFI_ACPI_5_1_GICC_AFFINITY_STRUCTURE; - -/// -/// GICC Flags. All other bits are reserved and must be 0. -/// -#define EFI_ACPI_5_1_GICC_ENABLED (1 << 0) - -/// -/// System Locality Distance Information Table (SLIT). -/// The rest of the table is a matrix. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT64 NumberOfSystemLocalities; -} EFI_ACPI_5_1_SYSTEM_LOCALITY_DISTANCE_INFORMATION_TABLE_HEADER; - -/// -/// SLIT Version (as defined in ACPI 5.1 spec.) -/// -#define EFI_ACPI_5_1_SYSTEM_LOCALITY_DISTANCE_INFORMATION_TABLE_REVISION 0x01 - -/// -/// Corrected Platform Error Polling Table (CPEP) -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT8 Reserved[8]; -} EFI_ACPI_5_1_CORRECTED_PLATFORM_ERROR_POLLING_TABLE_HEADER; - -/// -/// CPEP Version (as defined in ACPI 5.1 spec.) -/// -#define EFI_ACPI_5_1_CORRECTED_PLATFORM_ERROR_POLLING_TABLE_REVISION 0x01 - -// -// CPEP processor structure types. -// -#define EFI_ACPI_5_1_CPEP_PROCESSOR_APIC_SAPIC 0x00 - -/// -/// Corrected Platform Error Polling Processor Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 ProcessorId; - UINT8 ProcessorEid; - UINT32 PollingInterval; -} EFI_ACPI_5_1_CPEP_PROCESSOR_APIC_SAPIC_STRUCTURE; - -/// -/// Maximum System Characteristics Table (MSCT) -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 OffsetProxDomInfo; - UINT32 MaximumNumberOfProximityDomains; - UINT32 MaximumNumberOfClockDomains; - UINT64 MaximumPhysicalAddress; -} EFI_ACPI_5_1_MAXIMUM_SYSTEM_CHARACTERISTICS_TABLE_HEADER; - -/// -/// MSCT Version (as defined in ACPI 5.1 spec.) -/// -#define EFI_ACPI_5_1_MAXIMUM_SYSTEM_CHARACTERISTICS_TABLE_REVISION 0x01 - -/// -/// Maximum Proximity Domain Information Structure Definition -/// -typedef struct { - UINT8 Revision; - UINT8 Length; - UINT32 ProximityDomainRangeLow; - UINT32 ProximityDomainRangeHigh; - UINT32 MaximumProcessorCapacity; - UINT64 MaximumMemoryCapacity; -} EFI_ACPI_5_1_MAXIMUM_PROXIMITY_DOMAIN_INFORMATION_STRUCTURE; - -/// -/// ACPI RAS Feature Table definition. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT8 PlatformCommunicationChannelIdentifier[12]; -} EFI_ACPI_5_1_RAS_FEATURE_TABLE; - -/// -/// RASF Version (as defined in ACPI 5.1 spec.) -/// -#define EFI_ACPI_5_1_RAS_FEATURE_TABLE_REVISION 0x01 - -/// -/// ACPI RASF Platform Communication Channel Shared Memory Region definition. -/// -typedef struct { - UINT32 Signature; - UINT16 Command; - UINT16 Status; - UINT16 Version; - UINT8 RASCapabilities[16]; - UINT8 SetRASCapabilities[16]; - UINT16 NumberOfRASFParameterBlocks; - UINT32 SetRASCapabilitiesStatus; -} EFI_ACPI_5_1_RASF_PLATFORM_COMMUNICATION_CHANNEL_SHARED_MEMORY_REGION; - -/// -/// ACPI RASF PCC command code -/// -#define EFI_ACPI_5_1_RASF_PCC_COMMAND_CODE_EXECUTE_RASF_COMMAND 0x01 - -/// -/// ACPI RASF Platform RAS Capabilities -/// -#define EFI_ACPI_5_1_RASF_PLATFORM_RAS_CAPABILITY_HARDWARE_BASED_PATROL_SCRUB_SUPPOTED 0x01 -#define EFI_ACPI_5_1_RASF_PLATFORM_RAS_CAPABILITY_HARDWARE_BASED_PATROL_SCRUB_SUPPOTED_AND_EXPOSED_TO_SOFTWARE 0x02 - -/// -/// ACPI RASF Parameter Block structure for PATROL_SCRUB -/// -typedef struct { - UINT16 Type; - UINT16 Version; - UINT16 Length; - UINT16 PatrolScrubCommand; - UINT64 RequestedAddressRange[2]; - UINT64 ActualAddressRange[2]; - UINT16 Flags; - UINT8 RequestedSpeed; -} EFI_ACPI_5_1_RASF_PATROL_SCRUB_PLATFORM_BLOCK_STRUCTURE; - -/// -/// ACPI RASF Patrol Scrub command -/// -#define EFI_ACPI_5_1_RASF_PATROL_SCRUB_COMMAND_GET_PATROL_PARAMETERS 0x01 -#define EFI_ACPI_5_1_RASF_PATROL_SCRUB_COMMAND_START_PATROL_SCRUBBER 0x02 -#define EFI_ACPI_5_1_RASF_PATROL_SCRUB_COMMAND_STOP_PATROL_SCRUBBER 0x03 - -/// -/// Memory Power State Table definition. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT8 PlatformCommunicationChannelIdentifier; - UINT8 Reserved[3]; -// Memory Power Node Structure -// Memory Power State Characteristics -} EFI_ACPI_5_1_MEMORY_POWER_STATUS_TABLE; - -/// -/// MPST Version (as defined in ACPI 5.1 spec.) -/// -#define EFI_ACPI_5_1_MEMORY_POWER_STATE_TABLE_REVISION 0x01 - -/// -/// MPST Platform Communication Channel Shared Memory Region definition. -/// -typedef struct { - UINT32 Signature; - UINT16 Command; - UINT16 Status; - UINT32 MemoryPowerCommandRegister; - UINT32 MemoryPowerStatusRegister; - UINT32 PowerStateId; - UINT32 MemoryPowerNodeId; - UINT64 MemoryEnergyConsumed; - UINT64 ExpectedAveragePowerComsuned; -} EFI_ACPI_5_1_MPST_PLATFORM_COMMUNICATION_CHANNEL_SHARED_MEMORY_REGION; - -/// -/// ACPI MPST PCC command code -/// -#define EFI_ACPI_5_1_MPST_PCC_COMMAND_CODE_EXECUTE_MPST_COMMAND 0x03 - -/// -/// ACPI MPST Memory Power command -/// -#define EFI_ACPI_5_1_MPST_MEMORY_POWER_COMMAND_GET_MEMORY_POWER_STATE 0x01 -#define EFI_ACPI_5_1_MPST_MEMORY_POWER_COMMAND_SET_MEMORY_POWER_STATE 0x02 -#define EFI_ACPI_5_1_MPST_MEMORY_POWER_COMMAND_GET_AVERAGE_POWER_CONSUMED 0x03 -#define EFI_ACPI_5_1_MPST_MEMORY_POWER_COMMAND_GET_MEMORY_ENERGY_CONSUMED 0x04 - -/// -/// MPST Memory Power Node Table -/// -typedef struct { - UINT8 PowerStateValue; - UINT8 PowerStateInformationIndex; -} EFI_ACPI_5_1_MPST_MEMORY_POWER_STATE; - -typedef struct { - UINT8 Flag; - UINT8 Reserved; - UINT16 MemoryPowerNodeId; - UINT32 Length; - UINT64 AddressBase; - UINT64 AddressLength; - UINT32 NumberOfPowerStates; - UINT32 NumberOfPhysicalComponents; -//EFI_ACPI_5_1_MPST_MEMORY_POWER_STATE MemoryPowerState[NumberOfPowerStates]; -//UINT16 PhysicalComponentIdentifier[NumberOfPhysicalComponents]; -} EFI_ACPI_5_1_MPST_MEMORY_POWER_STRUCTURE; - -#define EFI_ACPI_5_1_MPST_MEMORY_POWER_STRUCTURE_FLAG_ENABLE 0x01 -#define EFI_ACPI_5_1_MPST_MEMORY_POWER_STRUCTURE_FLAG_POWER_MANAGED 0x02 -#define EFI_ACPI_5_1_MPST_MEMORY_POWER_STRUCTURE_FLAG_HOT_PLUGGABLE 0x04 - -typedef struct { - UINT16 MemoryPowerNodeCount; - UINT8 Reserved[2]; -} EFI_ACPI_5_1_MPST_MEMORY_POWER_NODE_TABLE; - -/// -/// MPST Memory Power State Characteristics Table -/// -typedef struct { - UINT8 PowerStateStructureID; - UINT8 Flag; - UINT16 Reserved; - UINT32 AveragePowerConsumedInMPS0; - UINT32 RelativePowerSavingToMPS0; - UINT64 ExitLatencyToMPS0; -} EFI_ACPI_5_1_MPST_MEMORY_POWER_STATE_CHARACTERISTICS_STRUCTURE; - -#define EFI_ACPI_5_1_MPST_MEMORY_POWER_STATE_CHARACTERISTICS_STRUCTURE_FLAG_MEMORY_CONTENT_PRESERVED 0x01 -#define EFI_ACPI_5_1_MPST_MEMORY_POWER_STATE_CHARACTERISTICS_STRUCTURE_FLAG_AUTONOMOUS_MEMORY_POWER_STATE_ENTRY 0x02 -#define EFI_ACPI_5_1_MPST_MEMORY_POWER_STATE_CHARACTERISTICS_STRUCTURE_FLAG_AUTONOMOUS_MEMORY_POWER_STATE_EXIT 0x04 - -typedef struct { - UINT16 MemoryPowerStateCharacteristicsCount; - UINT8 Reserved[2]; -} EFI_ACPI_5_1_MPST_MEMORY_POWER_STATE_CHARACTERISTICS_TABLE; - -/// -/// Memory Topology Table definition. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 Reserved; -} EFI_ACPI_5_1_MEMORY_TOPOLOGY_TABLE; - -/// -/// PMTT Version (as defined in ACPI 5.1 spec.) -/// -#define EFI_ACPI_5_1_MEMORY_TOPOLOGY_TABLE_REVISION 0x01 - -/// -/// Common Memory Aggregator Device Structure. -/// -typedef struct { - UINT8 Type; - UINT8 Reserved; - UINT16 Length; - UINT16 Flags; - UINT16 Reserved1; -} EFI_ACPI_5_1_PMMT_COMMON_MEMORY_AGGREGATOR_DEVICE_STRUCTURE; - -/// -/// Memory Aggregator Device Type -/// -#define EFI_ACPI_5_1_PMMT_MEMORY_AGGREGATOR_DEVICE_TYPE_SOCKET 0x1 -#define EFI_ACPI_5_1_PMMT_MEMORY_AGGREGATOR_DEVICE_TYPE_MEMORY_CONTROLLER 0x2 -#define EFI_ACPI_5_1_PMMT_MEMORY_AGGREGATOR_DEVICE_TYPE_DIMM 0x3 - -/// -/// Socket Memory Aggregator Device Structure. -/// -typedef struct { - EFI_ACPI_5_1_PMMT_COMMON_MEMORY_AGGREGATOR_DEVICE_STRUCTURE Header; - UINT16 SocketIdentifier; - UINT16 Reserved; -//EFI_ACPI_5_1_PMMT_MEMORY_CONTROLLER_MEMORY_AGGREGATOR_DEVICE_STRUCTURE MemoryController[]; -} EFI_ACPI_5_1_PMMT_SOCKET_MEMORY_AGGREGATOR_DEVICE_STRUCTURE; - -/// -/// MemoryController Memory Aggregator Device Structure. -/// -typedef struct { - EFI_ACPI_5_1_PMMT_COMMON_MEMORY_AGGREGATOR_DEVICE_STRUCTURE Header; - UINT32 ReadLatency; - UINT32 WriteLatency; - UINT32 ReadBandwidth; - UINT32 WriteBandwidth; - UINT16 OptimalAccessUnit; - UINT16 OptimalAccessAlignment; - UINT16 Reserved; - UINT16 NumberOfProximityDomains; -//UINT32 ProximityDomain[NumberOfProximityDomains]; -//EFI_ACPI_5_1_PMMT_DIMM_MEMORY_AGGREGATOR_DEVICE_STRUCTURE PhysicalComponent[]; -} EFI_ACPI_5_1_PMMT_MEMORY_CONTROLLER_MEMORY_AGGREGATOR_DEVICE_STRUCTURE; - -/// -/// DIMM Memory Aggregator Device Structure. -/// -typedef struct { - EFI_ACPI_5_1_PMMT_COMMON_MEMORY_AGGREGATOR_DEVICE_STRUCTURE Header; - UINT16 PhysicalComponentIdentifier; - UINT16 Reserved; - UINT32 SizeOfDimm; - UINT32 SmbiosHandle; -} EFI_ACPI_5_1_PMMT_DIMM_MEMORY_AGGREGATOR_DEVICE_STRUCTURE; - -/// -/// Boot Graphics Resource Table definition. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - /// - /// 2-bytes (16 bit) version ID. This value must be 1. - /// - UINT16 Version; - /// - /// 1-byte status field indicating current status about the table. - /// Bits[7:1] = Reserved (must be zero) - /// Bit [0] = Valid. A one indicates the boot image graphic is valid. - /// - UINT8 Status; - /// - /// 1-byte enumerated type field indicating format of the image. - /// 0 = Bitmap - /// 1 - 255 Reserved (for future use) - /// - UINT8 ImageType; - /// - /// 8-byte (64 bit) physical address pointing to the firmware's in-memory copy - /// of the image bitmap. - /// - UINT64 ImageAddress; - /// - /// A 4-byte (32-bit) unsigned long describing the display X-offset of the boot image. - /// (X, Y) display offset of the top left corner of the boot image. - /// The top left corner of the display is at offset (0, 0). - /// - UINT32 ImageOffsetX; - /// - /// A 4-byte (32-bit) unsigned long describing the display Y-offset of the boot image. - /// (X, Y) display offset of the top left corner of the boot image. - /// The top left corner of the display is at offset (0, 0). - /// - UINT32 ImageOffsetY; -} EFI_ACPI_5_1_BOOT_GRAPHICS_RESOURCE_TABLE; - -/// -/// BGRT Revision -/// -#define EFI_ACPI_5_1_BOOT_GRAPHICS_RESOURCE_TABLE_REVISION 1 - -/// -/// BGRT Version -/// -#define EFI_ACPI_5_1_BGRT_VERSION 0x01 - -/// -/// BGRT Status -/// -#define EFI_ACPI_5_1_BGRT_STATUS_NOT_DISPLAYED 0x00 -#define EFI_ACPI_5_1_BGRT_STATUS_DISPLAYED 0x01 - -/// -/// BGRT Image Type -/// -#define EFI_ACPI_5_1_BGRT_IMAGE_TYPE_BMP 0x00 - -/// -/// FPDT Version (as defined in ACPI 5.1 spec.) -/// -#define EFI_ACPI_5_1_FIRMWARE_PERFORMANCE_DATA_TABLE_REVISION 0x01 - -/// -/// FPDT Performance Record Types -/// -#define EFI_ACPI_5_1_FPDT_RECORD_TYPE_FIRMWARE_BASIC_BOOT_POINTER 0x0000 -#define EFI_ACPI_5_1_FPDT_RECORD_TYPE_S3_PERFORMANCE_TABLE_POINTER 0x0001 - -/// -/// FPDT Performance Record Revision -/// -#define EFI_ACPI_5_1_FPDT_RECORD_REVISION_FIRMWARE_BASIC_BOOT_POINTER 0x01 -#define EFI_ACPI_5_1_FPDT_RECORD_REVISION_S3_PERFORMANCE_TABLE_POINTER 0x01 - -/// -/// FPDT Runtime Performance Record Types -/// -#define EFI_ACPI_5_1_FPDT_RUNTIME_RECORD_TYPE_S3_RESUME 0x0000 -#define EFI_ACPI_5_1_FPDT_RUNTIME_RECORD_TYPE_S3_SUSPEND 0x0001 -#define EFI_ACPI_5_1_FPDT_RUNTIME_RECORD_TYPE_FIRMWARE_BASIC_BOOT 0x0002 - -/// -/// FPDT Runtime Performance Record Revision -/// -#define EFI_ACPI_5_1_FPDT_RUNTIME_RECORD_REVISION_S3_RESUME 0x01 -#define EFI_ACPI_5_1_FPDT_RUNTIME_RECORD_REVISION_S3_SUSPEND 0x01 -#define EFI_ACPI_5_1_FPDT_RUNTIME_RECORD_REVISION_FIRMWARE_BASIC_BOOT 0x02 - -/// -/// FPDT Performance Record header -/// -typedef struct { - UINT16 Type; - UINT8 Length; - UINT8 Revision; -} EFI_ACPI_5_1_FPDT_PERFORMANCE_RECORD_HEADER; - -/// -/// FPDT Performance Table header -/// -typedef struct { - UINT32 Signature; - UINT32 Length; -} EFI_ACPI_5_1_FPDT_PERFORMANCE_TABLE_HEADER; - -/// -/// FPDT Firmware Basic Boot Performance Pointer Record Structure -/// -typedef struct { - EFI_ACPI_5_1_FPDT_PERFORMANCE_RECORD_HEADER Header; - UINT32 Reserved; - /// - /// 64-bit processor-relative physical address of the Basic Boot Performance Table. - /// - UINT64 BootPerformanceTablePointer; -} EFI_ACPI_5_1_FPDT_BOOT_PERFORMANCE_TABLE_POINTER_RECORD; - -/// -/// FPDT S3 Performance Table Pointer Record Structure -/// -typedef struct { - EFI_ACPI_5_1_FPDT_PERFORMANCE_RECORD_HEADER Header; - UINT32 Reserved; - /// - /// 64-bit processor-relative physical address of the S3 Performance Table. - /// - UINT64 S3PerformanceTablePointer; -} EFI_ACPI_5_1_FPDT_S3_PERFORMANCE_TABLE_POINTER_RECORD; - -/// -/// FPDT Firmware Basic Boot Performance Record Structure -/// -typedef struct { - EFI_ACPI_5_1_FPDT_PERFORMANCE_RECORD_HEADER Header; - UINT32 Reserved; - /// - /// Timer value logged at the beginning of firmware image execution. - /// This may not always be zero or near zero. - /// - UINT64 ResetEnd; - /// - /// Timer value logged just prior to loading the OS boot loader into memory. - /// For non-UEFI compatible boots, this field must be zero. - /// - UINT64 OsLoaderLoadImageStart; - /// - /// Timer value logged just prior to launching the previously loaded OS boot loader image. - /// For non-UEFI compatible boots, the timer value logged will be just prior - /// to the INT 19h handler invocation. - /// - UINT64 OsLoaderStartImageStart; - /// - /// Timer value logged at the point when the OS loader calls the - /// ExitBootServices function for UEFI compatible firmware. - /// For non-UEFI compatible boots, this field must be zero. - /// - UINT64 ExitBootServicesEntry; - /// - /// Timer value logged at the point just prior towhen the OS loader gaining - /// control back from calls the ExitBootServices function for UEFI compatible firmware. - /// For non-UEFI compatible boots, this field must be zero. - /// - UINT64 ExitBootServicesExit; -} EFI_ACPI_5_1_FPDT_FIRMWARE_BASIC_BOOT_RECORD; - -/// -/// FPDT Firmware Basic Boot Performance Table signature -/// -#define EFI_ACPI_5_1_FPDT_BOOT_PERFORMANCE_TABLE_SIGNATURE SIGNATURE_32('F', 'B', 'P', 'T') - -// -// FPDT Firmware Basic Boot Performance Table -// -typedef struct { - EFI_ACPI_5_1_FPDT_PERFORMANCE_TABLE_HEADER Header; - // - // one or more Performance Records. - // -} EFI_ACPI_5_1_FPDT_FIRMWARE_BASIC_BOOT_TABLE; - -/// -/// FPDT "S3PT" S3 Performance Table -/// -#define EFI_ACPI_5_1_FPDT_S3_PERFORMANCE_TABLE_SIGNATURE SIGNATURE_32('S', '3', 'P', 'T') - -// -// FPDT Firmware S3 Boot Performance Table -// -typedef struct { - EFI_ACPI_5_1_FPDT_PERFORMANCE_TABLE_HEADER Header; - // - // one or more Performance Records. - // -} EFI_ACPI_5_1_FPDT_FIRMWARE_S3_BOOT_TABLE; - -/// -/// FPDT Basic S3 Resume Performance Record -/// -typedef struct { - EFI_ACPI_5_1_FPDT_PERFORMANCE_RECORD_HEADER Header; - /// - /// A count of the number of S3 resume cycles since the last full boot sequence. - /// - UINT32 ResumeCount; - /// - /// Timer recorded at the end of BIOS S3 resume, just prior to handoff to the - /// OS waking vector. Only the most recent resume cycle's time is retained. - /// - UINT64 FullResume; - /// - /// Average timer value of all resume cycles logged since the last full boot - /// sequence, including the most recent resume. Note that the entire log of - /// timer values does not need to be retained in order to calculate this average. - /// - UINT64 AverageResume; -} EFI_ACPI_5_1_FPDT_S3_RESUME_RECORD; - -/// -/// FPDT Basic S3 Suspend Performance Record -/// -typedef struct { - EFI_ACPI_5_1_FPDT_PERFORMANCE_RECORD_HEADER Header; - /// - /// Timer value recorded at the OS write to SLP_TYP upon entry to S3. - /// Only the most recent suspend cycle's timer value is retained. - /// - UINT64 SuspendStart; - /// - /// Timer value recorded at the final firmware write to SLP_TYP (or other - /// mechanism) used to trigger hardware entry to S3. - /// Only the most recent suspend cycle's timer value is retained. - /// - UINT64 SuspendEnd; -} EFI_ACPI_5_1_FPDT_S3_SUSPEND_RECORD; - -/// -/// Firmware Performance Record Table definition. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; -} EFI_ACPI_5_1_FIRMWARE_PERFORMANCE_RECORD_TABLE; - -/// -/// Generic Timer Description Table definition. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT64 CntControlBasePhysicalAddress; - UINT32 Reserved; - UINT32 SecurePL1TimerGSIV; - UINT32 SecurePL1TimerFlags; - UINT32 NonSecurePL1TimerGSIV; - UINT32 NonSecurePL1TimerFlags; - UINT32 VirtualTimerGSIV; - UINT32 VirtualTimerFlags; - UINT32 NonSecurePL2TimerGSIV; - UINT32 NonSecurePL2TimerFlags; - UINT64 CntReadBasePhysicalAddress; - UINT32 PlatformTimerCount; - UINT32 PlatformTimerOffset; -} EFI_ACPI_5_1_GENERIC_TIMER_DESCRIPTION_TABLE; - -/// -/// GTDT Version (as defined in ACPI 5.1 spec.) -/// -#define EFI_ACPI_5_1_GENERIC_TIMER_DESCRIPTION_TABLE_REVISION 0x02 - -/// -/// Timer Flags. All other bits are reserved and must be 0. -/// -#define EFI_ACPI_5_1_GTDT_TIMER_FLAG_TIMER_INTERRUPT_MODE BIT0 -#define EFI_ACPI_5_1_GTDT_TIMER_FLAG_TIMER_INTERRUPT_POLARITY BIT1 -#define EFI_ACPI_5_1_GTDT_TIMER_FLAG_ALWAYS_ON_CAPABILITY BIT2 - -/// -/// Platform Timer Type -/// -#define EFI_ACPI_5_1_GTDT_GT_BLOCK 0 -#define EFI_ACPI_5_1_GTDT_SBSA_GENERIC_WATCHDOG 1 - -/// -/// GT Block Structure -/// -typedef struct { - UINT8 Type; - UINT16 Length; - UINT8 Reserved; - UINT64 CntCtlBase; - UINT32 GTBlockTimerCount; - UINT32 GTBlockTimerOffset; -} EFI_ACPI_5_1_GTDT_GT_BLOCK_STRUCTURE; - -/// -/// GT Block Timer Structure -/// -typedef struct { - UINT8 GTFrameNumber; - UINT8 Reserved[3]; - UINT64 CntBaseX; - UINT64 CntEL0BaseX; - UINT32 GTxPhysicalTimerGSIV; - UINT32 GTxPhysicalTimerFlags; - UINT32 GTxVirtualTimerGSIV; - UINT32 GTxVirtualTimerFlags; - UINT32 GTxCommonFlags; -} EFI_ACPI_5_1_GTDT_GT_BLOCK_TIMER_STRUCTURE; - -/// -/// GT Block Physical Timers and Virtual Timers Flags. All other bits are reserved and must be 0. -/// -#define EFI_ACPI_5_1_GTDT_GT_BLOCK_TIMER_FLAG_TIMER_INTERRUPT_MODE BIT0 -#define EFI_ACPI_5_1_GTDT_GT_BLOCK_TIMER_FLAG_TIMER_INTERRUPT_POLARITY BIT1 - -/// -/// Common Flags Flags. All other bits are reserved and must be 0. -/// -#define EFI_ACPI_5_1_GTDT_GT_BLOCK_COMMON_FLAG_SECURE_TIMER BIT0 -#define EFI_ACPI_5_1_GTDT_GT_BLOCK_COMMON_FLAG_ALWAYS_ON_CAPABILITY BIT1 - -/// -/// SBSA Generic Watchdog Structure -/// -typedef struct { - UINT8 Type; - UINT16 Length; - UINT8 Reserved; - UINT64 RefreshFramePhysicalAddress; - UINT64 WatchdogControlFramePhysicalAddress; - UINT32 WatchdogTimerGSIV; - UINT32 WatchdogTimerFlags; -} EFI_ACPI_5_1_GTDT_SBSA_GENERIC_WATCHDOG_STRUCTURE; - -/// -/// SBSA Generic Watchdog Timer Flags. All other bits are reserved and must be 0. -/// -#define EFI_ACPI_5_1_GTDT_SBSA_GENERIC_WATCHDOG_FLAG_TIMER_INTERRUPT_MODE BIT0 -#define EFI_ACPI_5_1_GTDT_SBSA_GENERIC_WATCHDOG_FLAG_TIMER_INTERRUPT_POLARITY BIT1 -#define EFI_ACPI_5_1_GTDT_SBSA_GENERIC_WATCHDOG_FLAG_SECURE_TIMER BIT2 - -/// -/// Boot Error Record Table (BERT) -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 BootErrorRegionLength; - UINT64 BootErrorRegion; -} EFI_ACPI_5_1_BOOT_ERROR_RECORD_TABLE_HEADER; - -/// -/// BERT Version (as defined in ACPI 5.1 spec.) -/// -#define EFI_ACPI_5_1_BOOT_ERROR_RECORD_TABLE_REVISION 0x01 - -/// -/// Boot Error Region Block Status Definition -/// -typedef struct { - UINT32 UncorrectableErrorValid:1; - UINT32 CorrectableErrorValid:1; - UINT32 MultipleUncorrectableErrors:1; - UINT32 MultipleCorrectableErrors:1; - UINT32 ErrorDataEntryCount:10; - UINT32 Reserved:18; -} EFI_ACPI_5_1_ERROR_BLOCK_STATUS; - -/// -/// Boot Error Region Definition -/// -typedef struct { - EFI_ACPI_5_1_ERROR_BLOCK_STATUS BlockStatus; - UINT32 RawDataOffset; - UINT32 RawDataLength; - UINT32 DataLength; - UINT32 ErrorSeverity; -} EFI_ACPI_5_1_BOOT_ERROR_REGION_STRUCTURE; - -// -// Boot Error Severity types -// -#define EFI_ACPI_5_1_ERROR_SEVERITY_CORRECTABLE 0x00 -#define EFI_ACPI_5_1_ERROR_SEVERITY_FATAL 0x01 -#define EFI_ACPI_5_1_ERROR_SEVERITY_CORRECTED 0x02 -#define EFI_ACPI_5_1_ERROR_SEVERITY_NONE 0x03 - -/// -/// Generic Error Data Entry Definition -/// -typedef struct { - UINT8 SectionType[16]; - UINT32 ErrorSeverity; - UINT16 Revision; - UINT8 ValidationBits; - UINT8 Flags; - UINT32 ErrorDataLength; - UINT8 FruId[16]; - UINT8 FruText[20]; -} EFI_ACPI_5_1_GENERIC_ERROR_DATA_ENTRY_STRUCTURE; - -/// -/// Generic Error Data Entry Version (as defined in ACPI 5.1 spec.) -/// -#define EFI_ACPI_5_1_GENERIC_ERROR_DATA_ENTRY_REVISION 0x0201 - -/// -/// HEST - Hardware Error Source Table -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 ErrorSourceCount; -} EFI_ACPI_5_1_HARDWARE_ERROR_SOURCE_TABLE_HEADER; - -/// -/// HEST Version (as defined in ACPI 5.1 spec.) -/// -#define EFI_ACPI_5_1_HARDWARE_ERROR_SOURCE_TABLE_REVISION 0x01 - -// -// Error Source structure types. -// -#define EFI_ACPI_5_1_IA32_ARCHITECTURE_MACHINE_CHECK_EXCEPTION 0x00 -#define EFI_ACPI_5_1_IA32_ARCHITECTURE_CORRECTED_MACHINE_CHECK 0x01 -#define EFI_ACPI_5_1_IA32_ARCHITECTURE_NMI_ERROR 0x02 -#define EFI_ACPI_5_1_PCI_EXPRESS_ROOT_PORT_AER 0x06 -#define EFI_ACPI_5_1_PCI_EXPRESS_DEVICE_AER 0x07 -#define EFI_ACPI_5_1_PCI_EXPRESS_BRIDGE_AER 0x08 -#define EFI_ACPI_5_1_GENERIC_HARDWARE_ERROR 0x09 - -// -// Error Source structure flags. -// -#define EFI_ACPI_5_1_ERROR_SOURCE_FLAG_FIRMWARE_FIRST (1 << 0) -#define EFI_ACPI_5_1_ERROR_SOURCE_FLAG_GLOBAL (1 << 1) - -/// -/// IA-32 Architecture Machine Check Exception Structure Definition -/// -typedef struct { - UINT16 Type; - UINT16 SourceId; - UINT8 Reserved0[2]; - UINT8 Flags; - UINT8 Enabled; - UINT32 NumberOfRecordsToPreAllocate; - UINT32 MaxSectionsPerRecord; - UINT64 GlobalCapabilityInitData; - UINT64 GlobalControlInitData; - UINT8 NumberOfHardwareBanks; - UINT8 Reserved1[7]; -} EFI_ACPI_5_1_IA32_ARCHITECTURE_MACHINE_CHECK_EXCEPTION_STRUCTURE; - -/// -/// IA-32 Architecture Machine Check Bank Structure Definition -/// -typedef struct { - UINT8 BankNumber; - UINT8 ClearStatusOnInitialization; - UINT8 StatusDataFormat; - UINT8 Reserved0; - UINT32 ControlRegisterMsrAddress; - UINT64 ControlInitData; - UINT32 StatusRegisterMsrAddress; - UINT32 AddressRegisterMsrAddress; - UINT32 MiscRegisterMsrAddress; -} EFI_ACPI_5_1_IA32_ARCHITECTURE_MACHINE_CHECK_ERROR_BANK_STRUCTURE; - -/// -/// IA-32 Architecture Machine Check Bank Structure MCA data format -/// -#define EFI_ACPI_5_1_IA32_ARCHITECTURE_MACHINE_CHECK_ERROR_DATA_FORMAT_IA32 0x00 -#define EFI_ACPI_5_1_IA32_ARCHITECTURE_MACHINE_CHECK_ERROR_DATA_FORMAT_INTEL64 0x01 -#define EFI_ACPI_5_1_IA32_ARCHITECTURE_MACHINE_CHECK_ERROR_DATA_FORMAT_AMD64 0x02 - -// -// Hardware Error Notification types. All other values are reserved -// -#define EFI_ACPI_5_1_HARDWARE_ERROR_NOTIFICATION_POLLED 0x00 -#define EFI_ACPI_5_1_HARDWARE_ERROR_NOTIFICATION_EXTERNAL_INTERRUPT 0x01 -#define EFI_ACPI_5_1_HARDWARE_ERROR_NOTIFICATION_LOCAL_INTERRUPT 0x02 -#define EFI_ACPI_5_1_HARDWARE_ERROR_NOTIFICATION_SCI 0x03 -#define EFI_ACPI_5_1_HARDWARE_ERROR_NOTIFICATION_NMI 0x04 - -/// -/// Hardware Error Notification Configuration Write Enable Structure Definition -/// -typedef struct { - UINT16 Type:1; - UINT16 PollInterval:1; - UINT16 SwitchToPollingThresholdValue:1; - UINT16 SwitchToPollingThresholdWindow:1; - UINT16 ErrorThresholdValue:1; - UINT16 ErrorThresholdWindow:1; - UINT16 Reserved:10; -} EFI_ACPI_5_1_HARDWARE_ERROR_NOTIFICATION_CONFIGURATION_WRITE_ENABLE_STRUCTURE; - -/// -/// Hardware Error Notification Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - EFI_ACPI_5_1_HARDWARE_ERROR_NOTIFICATION_CONFIGURATION_WRITE_ENABLE_STRUCTURE ConfigurationWriteEnable; - UINT32 PollInterval; - UINT32 Vector; - UINT32 SwitchToPollingThresholdValue; - UINT32 SwitchToPollingThresholdWindow; - UINT32 ErrorThresholdValue; - UINT32 ErrorThresholdWindow; -} EFI_ACPI_5_1_HARDWARE_ERROR_NOTIFICATION_STRUCTURE; - -/// -/// IA-32 Architecture Corrected Machine Check Structure Definition -/// -typedef struct { - UINT16 Type; - UINT16 SourceId; - UINT8 Reserved0[2]; - UINT8 Flags; - UINT8 Enabled; - UINT32 NumberOfRecordsToPreAllocate; - UINT32 MaxSectionsPerRecord; - EFI_ACPI_5_1_HARDWARE_ERROR_NOTIFICATION_STRUCTURE NotificationStructure; - UINT8 NumberOfHardwareBanks; - UINT8 Reserved1[3]; -} EFI_ACPI_5_1_IA32_ARCHITECTURE_CORRECTED_MACHINE_CHECK_STRUCTURE; - -/// -/// IA-32 Architecture NMI Error Structure Definition -/// -typedef struct { - UINT16 Type; - UINT16 SourceId; - UINT8 Reserved0[2]; - UINT32 NumberOfRecordsToPreAllocate; - UINT32 MaxSectionsPerRecord; - UINT32 MaxRawDataLength; -} EFI_ACPI_5_1_IA32_ARCHITECTURE_NMI_ERROR_STRUCTURE; - -/// -/// PCI Express Root Port AER Structure Definition -/// -typedef struct { - UINT16 Type; - UINT16 SourceId; - UINT8 Reserved0[2]; - UINT8 Flags; - UINT8 Enabled; - UINT32 NumberOfRecordsToPreAllocate; - UINT32 MaxSectionsPerRecord; - UINT32 Bus; - UINT16 Device; - UINT16 Function; - UINT16 DeviceControl; - UINT8 Reserved1[2]; - UINT32 UncorrectableErrorMask; - UINT32 UncorrectableErrorSeverity; - UINT32 CorrectableErrorMask; - UINT32 AdvancedErrorCapabilitiesAndControl; - UINT32 RootErrorCommand; -} EFI_ACPI_5_1_PCI_EXPRESS_ROOT_PORT_AER_STRUCTURE; - -/// -/// PCI Express Device AER Structure Definition -/// -typedef struct { - UINT16 Type; - UINT16 SourceId; - UINT8 Reserved0[2]; - UINT8 Flags; - UINT8 Enabled; - UINT32 NumberOfRecordsToPreAllocate; - UINT32 MaxSectionsPerRecord; - UINT32 Bus; - UINT16 Device; - UINT16 Function; - UINT16 DeviceControl; - UINT8 Reserved1[2]; - UINT32 UncorrectableErrorMask; - UINT32 UncorrectableErrorSeverity; - UINT32 CorrectableErrorMask; - UINT32 AdvancedErrorCapabilitiesAndControl; -} EFI_ACPI_5_1_PCI_EXPRESS_DEVICE_AER_STRUCTURE; - -/// -/// PCI Express Bridge AER Structure Definition -/// -typedef struct { - UINT16 Type; - UINT16 SourceId; - UINT8 Reserved0[2]; - UINT8 Flags; - UINT8 Enabled; - UINT32 NumberOfRecordsToPreAllocate; - UINT32 MaxSectionsPerRecord; - UINT32 Bus; - UINT16 Device; - UINT16 Function; - UINT16 DeviceControl; - UINT8 Reserved1[2]; - UINT32 UncorrectableErrorMask; - UINT32 UncorrectableErrorSeverity; - UINT32 CorrectableErrorMask; - UINT32 AdvancedErrorCapabilitiesAndControl; - UINT32 SecondaryUncorrectableErrorMask; - UINT32 SecondaryUncorrectableErrorSeverity; - UINT32 SecondaryAdvancedErrorCapabilitiesAndControl; -} EFI_ACPI_5_1_PCI_EXPRESS_BRIDGE_AER_STRUCTURE; - -/// -/// Generic Hardware Error Source Structure Definition -/// -typedef struct { - UINT16 Type; - UINT16 SourceId; - UINT16 RelatedSourceId; - UINT8 Flags; - UINT8 Enabled; - UINT32 NumberOfRecordsToPreAllocate; - UINT32 MaxSectionsPerRecord; - UINT32 MaxRawDataLength; - EFI_ACPI_5_1_GENERIC_ADDRESS_STRUCTURE ErrorStatusAddress; - EFI_ACPI_5_1_HARDWARE_ERROR_NOTIFICATION_STRUCTURE NotificationStructure; - UINT32 ErrorStatusBlockLength; -} EFI_ACPI_5_1_GENERIC_HARDWARE_ERROR_SOURCE_STRUCTURE; - -/// -/// Generic Error Status Definition -/// -typedef struct { - EFI_ACPI_5_1_ERROR_BLOCK_STATUS BlockStatus; - UINT32 RawDataOffset; - UINT32 RawDataLength; - UINT32 DataLength; - UINT32 ErrorSeverity; -} EFI_ACPI_5_1_GENERIC_ERROR_STATUS_STRUCTURE; - -/// -/// ERST - Error Record Serialization Table -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 SerializationHeaderSize; - UINT8 Reserved0[4]; - UINT32 InstructionEntryCount; -} EFI_ACPI_5_1_ERROR_RECORD_SERIALIZATION_TABLE_HEADER; - -/// -/// ERST Version (as defined in ACPI 5.1 spec.) -/// -#define EFI_ACPI_5_1_ERROR_RECORD_SERIALIZATION_TABLE_REVISION 0x01 - -/// -/// ERST Serialization Actions -/// -#define EFI_ACPI_5_1_ERST_BEGIN_WRITE_OPERATION 0x00 -#define EFI_ACPI_5_1_ERST_BEGIN_READ_OPERATION 0x01 -#define EFI_ACPI_5_1_ERST_BEGIN_CLEAR_OPERATION 0x02 -#define EFI_ACPI_5_1_ERST_END_OPERATION 0x03 -#define EFI_ACPI_5_1_ERST_SET_RECORD_OFFSET 0x04 -#define EFI_ACPI_5_1_ERST_EXECUTE_OPERATION 0x05 -#define EFI_ACPI_5_1_ERST_CHECK_BUSY_STATUS 0x06 -#define EFI_ACPI_5_1_ERST_GET_COMMAND_STATUS 0x07 -#define EFI_ACPI_5_1_ERST_GET_RECORD_IDENTIFIER 0x08 -#define EFI_ACPI_5_1_ERST_SET_RECORD_IDENTIFIER 0x09 -#define EFI_ACPI_5_1_ERST_GET_RECORD_COUNT 0x0A -#define EFI_ACPI_5_1_ERST_BEGIN_DUMMY_WRITE_OPERATION 0x0B -#define EFI_ACPI_5_1_ERST_GET_ERROR_LOG_ADDRESS_RANGE 0x0D -#define EFI_ACPI_5_1_ERST_GET_ERROR_LOG_ADDRESS_RANGE_LENGTH 0x0E -#define EFI_ACPI_5_1_ERST_GET_ERROR_LOG_ADDRESS_RANGE_ATTRIBUTES 0x0F - -/// -/// ERST Action Command Status -/// -#define EFI_ACPI_5_1_ERST_STATUS_SUCCESS 0x00 -#define EFI_ACPI_5_1_ERST_STATUS_NOT_ENOUGH_SPACE 0x01 -#define EFI_ACPI_5_1_ERST_STATUS_HARDWARE_NOT_AVAILABLE 0x02 -#define EFI_ACPI_5_1_ERST_STATUS_FAILED 0x03 -#define EFI_ACPI_5_1_ERST_STATUS_RECORD_STORE_EMPTY 0x04 -#define EFI_ACPI_5_1_ERST_STATUS_RECORD_NOT_FOUND 0x05 - -/// -/// ERST Serialization Instructions -/// -#define EFI_ACPI_5_1_ERST_READ_REGISTER 0x00 -#define EFI_ACPI_5_1_ERST_READ_REGISTER_VALUE 0x01 -#define EFI_ACPI_5_1_ERST_WRITE_REGISTER 0x02 -#define EFI_ACPI_5_1_ERST_WRITE_REGISTER_VALUE 0x03 -#define EFI_ACPI_5_1_ERST_NOOP 0x04 -#define EFI_ACPI_5_1_ERST_LOAD_VAR1 0x05 -#define EFI_ACPI_5_1_ERST_LOAD_VAR2 0x06 -#define EFI_ACPI_5_1_ERST_STORE_VAR1 0x07 -#define EFI_ACPI_5_1_ERST_ADD 0x08 -#define EFI_ACPI_5_1_ERST_SUBTRACT 0x09 -#define EFI_ACPI_5_1_ERST_ADD_VALUE 0x0A -#define EFI_ACPI_5_1_ERST_SUBTRACT_VALUE 0x0B -#define EFI_ACPI_5_1_ERST_STALL 0x0C -#define EFI_ACPI_5_1_ERST_STALL_WHILE_TRUE 0x0D -#define EFI_ACPI_5_1_ERST_SKIP_NEXT_INSTRUCTION_IF_TRUE 0x0E -#define EFI_ACPI_5_1_ERST_GOTO 0x0F -#define EFI_ACPI_5_1_ERST_SET_SRC_ADDRESS_BASE 0x10 -#define EFI_ACPI_5_1_ERST_SET_DST_ADDRESS_BASE 0x11 -#define EFI_ACPI_5_1_ERST_MOVE_DATA 0x12 - -/// -/// ERST Instruction Flags -/// -#define EFI_ACPI_5_1_ERST_PRESERVE_REGISTER 0x01 - -/// -/// ERST Serialization Instruction Entry -/// -typedef struct { - UINT8 SerializationAction; - UINT8 Instruction; - UINT8 Flags; - UINT8 Reserved0; - EFI_ACPI_5_1_GENERIC_ADDRESS_STRUCTURE RegisterRegion; - UINT64 Value; - UINT64 Mask; -} EFI_ACPI_5_1_ERST_SERIALIZATION_INSTRUCTION_ENTRY; - -/// -/// EINJ - Error Injection Table -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 InjectionHeaderSize; - UINT8 InjectionFlags; - UINT8 Reserved0[3]; - UINT32 InjectionEntryCount; -} EFI_ACPI_5_1_ERROR_INJECTION_TABLE_HEADER; - -/// -/// EINJ Version (as defined in ACPI 5.1 spec.) -/// -#define EFI_ACPI_5_1_ERROR_INJECTION_TABLE_REVISION 0x01 - -/// -/// EINJ Error Injection Actions -/// -#define EFI_ACPI_5_1_EINJ_BEGIN_INJECTION_OPERATION 0x00 -#define EFI_ACPI_5_1_EINJ_GET_TRIGGER_ERROR_ACTION_TABLE 0x01 -#define EFI_ACPI_5_1_EINJ_SET_ERROR_TYPE 0x02 -#define EFI_ACPI_5_1_EINJ_GET_ERROR_TYPE 0x03 -#define EFI_ACPI_5_1_EINJ_END_OPERATION 0x04 -#define EFI_ACPI_5_1_EINJ_EXECUTE_OPERATION 0x05 -#define EFI_ACPI_5_1_EINJ_CHECK_BUSY_STATUS 0x06 -#define EFI_ACPI_5_1_EINJ_GET_COMMAND_STATUS 0x07 -#define EFI_ACPI_5_1_EINJ_TRIGGER_ERROR 0xFF - -/// -/// EINJ Action Command Status -/// -#define EFI_ACPI_5_1_EINJ_STATUS_SUCCESS 0x00 -#define EFI_ACPI_5_1_EINJ_STATUS_UNKNOWN_FAILURE 0x01 -#define EFI_ACPI_5_1_EINJ_STATUS_INVALID_ACCESS 0x02 - -/// -/// EINJ Error Type Definition -/// -#define EFI_ACPI_5_1_EINJ_ERROR_PROCESSOR_CORRECTABLE (1 << 0) -#define EFI_ACPI_5_1_EINJ_ERROR_PROCESSOR_UNCORRECTABLE_NONFATAL (1 << 1) -#define EFI_ACPI_5_1_EINJ_ERROR_PROCESSOR_UNCORRECTABLE_FATAL (1 << 2) -#define EFI_ACPI_5_1_EINJ_ERROR_MEMORY_CORRECTABLE (1 << 3) -#define EFI_ACPI_5_1_EINJ_ERROR_MEMORY_UNCORRECTABLE_NONFATAL (1 << 4) -#define EFI_ACPI_5_1_EINJ_ERROR_MEMORY_UNCORRECTABLE_FATAL (1 << 5) -#define EFI_ACPI_5_1_EINJ_ERROR_PCI_EXPRESS_CORRECTABLE (1 << 6) -#define EFI_ACPI_5_1_EINJ_ERROR_PCI_EXPRESS_UNCORRECTABLE_NONFATAL (1 << 7) -#define EFI_ACPI_5_1_EINJ_ERROR_PCI_EXPRESS_UNCORRECTABLE_FATAL (1 << 8) -#define EFI_ACPI_5_1_EINJ_ERROR_PLATFORM_CORRECTABLE (1 << 9) -#define EFI_ACPI_5_1_EINJ_ERROR_PLATFORM_UNCORRECTABLE_NONFATAL (1 << 10) -#define EFI_ACPI_5_1_EINJ_ERROR_PLATFORM_UNCORRECTABLE_FATAL (1 << 11) - -/// -/// EINJ Injection Instructions -/// -#define EFI_ACPI_5_1_EINJ_READ_REGISTER 0x00 -#define EFI_ACPI_5_1_EINJ_READ_REGISTER_VALUE 0x01 -#define EFI_ACPI_5_1_EINJ_WRITE_REGISTER 0x02 -#define EFI_ACPI_5_1_EINJ_WRITE_REGISTER_VALUE 0x03 -#define EFI_ACPI_5_1_EINJ_NOOP 0x04 - -/// -/// EINJ Instruction Flags -/// -#define EFI_ACPI_5_1_EINJ_PRESERVE_REGISTER 0x01 - -/// -/// EINJ Injection Instruction Entry -/// -typedef struct { - UINT8 InjectionAction; - UINT8 Instruction; - UINT8 Flags; - UINT8 Reserved0; - EFI_ACPI_5_1_GENERIC_ADDRESS_STRUCTURE RegisterRegion; - UINT64 Value; - UINT64 Mask; -} EFI_ACPI_5_1_EINJ_INJECTION_INSTRUCTION_ENTRY; - -/// -/// EINJ Trigger Action Table -/// -typedef struct { - UINT32 HeaderSize; - UINT32 Revision; - UINT32 TableSize; - UINT32 EntryCount; -} EFI_ACPI_5_1_EINJ_TRIGGER_ACTION_TABLE; - -/// -/// Platform Communications Channel Table (PCCT) -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 Flags; - UINT64 Reserved; -} EFI_ACPI_5_1_PLATFORM_COMMUNICATION_CHANNEL_TABLE_HEADER; - -/// -/// PCCT Version (as defined in ACPI 5.1 spec.) -/// -#define EFI_ACPI_5_1_PLATFORM_COMMUNICATION_CHANNEL_TABLE_REVISION 0x01 - -/// -/// PCCT Global Flags -/// -#define EFI_ACPI_5_1_PCCT_FLAGS_SCI_DOORBELL BIT0 - -// -// PCCT Subspace type -// -#define EFI_ACPI_5_1_PCCT_SUBSPACE_TYPE_GENERIC 0x00 - -/// -/// PCC Subspace Structure Header -/// -typedef struct { - UINT8 Type; - UINT8 Length; -} EFI_ACPI_5_1_PCCT_SUBSPACE_HEADER; - -/// -/// Generic Communications Subspace Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 Reserved[6]; - UINT64 BaseAddress; - UINT64 AddressLength; - EFI_ACPI_5_1_GENERIC_ADDRESS_STRUCTURE DoorbellRegister; - UINT64 DoorbellPreserve; - UINT64 DoorbellWrite; - UINT32 NominalLatency; - UINT32 MaximumPeriodicAccessRate; - UINT16 MinimumRequestTurnaroundTime; -} EFI_ACPI_5_1_PCCT_SUBSPACE_GENERIC; - -/// -/// Generic Communications Channel Shared Memory Region -/// - -typedef struct { - UINT8 Command; - UINT8 Reserved:7; - UINT8 GenerateSci:1; -} EFI_ACPI_5_1_PCCT_GENERIC_SHARED_MEMORY_REGION_COMMAND; - -typedef struct { - UINT8 CommandComplete:1; - UINT8 SciDoorbell:1; - UINT8 Error:1; - UINT8 PlatformNotification:1; - UINT8 Reserved:4; - UINT8 Reserved1; -} EFI_ACPI_5_1_PCCT_GENERIC_SHARED_MEMORY_REGION_STATUS; - -typedef struct { - UINT32 Signature; - EFI_ACPI_5_1_PCCT_GENERIC_SHARED_MEMORY_REGION_COMMAND Command; - EFI_ACPI_5_1_PCCT_GENERIC_SHARED_MEMORY_REGION_STATUS Status; -} EFI_ACPI_5_1_PCCT_GENERIC_SHARED_MEMORY_REGION_HEADER; - -// -// Known table signatures -// - -/// -/// "RSD PTR " Root System Description Pointer -/// -#define EFI_ACPI_5_1_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE SIGNATURE_64('R', 'S', 'D', ' ', 'P', 'T', 'R', ' ') - -/// -/// "APIC" Multiple APIC Description Table -/// -#define EFI_ACPI_5_1_MULTIPLE_APIC_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('A', 'P', 'I', 'C') - -/// -/// "BERT" Boot Error Record Table -/// -#define EFI_ACPI_5_1_BOOT_ERROR_RECORD_TABLE_SIGNATURE SIGNATURE_32('B', 'E', 'R', 'T') - -/// -/// "BGRT" Boot Graphics Resource Table -/// -#define EFI_ACPI_5_1_BOOT_GRAPHICS_RESOURCE_TABLE_SIGNATURE SIGNATURE_32('B', 'G', 'R', 'T') - -/// -/// "CPEP" Corrected Platform Error Polling Table -/// -#define EFI_ACPI_5_1_CORRECTED_PLATFORM_ERROR_POLLING_TABLE_SIGNATURE SIGNATURE_32('C', 'P', 'E', 'P') - -/// -/// "DSDT" Differentiated System Description Table -/// -#define EFI_ACPI_5_1_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('D', 'S', 'D', 'T') - -/// -/// "ECDT" Embedded Controller Boot Resources Table -/// -#define EFI_ACPI_5_1_EMBEDDED_CONTROLLER_BOOT_RESOURCES_TABLE_SIGNATURE SIGNATURE_32('E', 'C', 'D', 'T') - -/// -/// "EINJ" Error Injection Table -/// -#define EFI_ACPI_5_1_ERROR_INJECTION_TABLE_SIGNATURE SIGNATURE_32('E', 'I', 'N', 'J') - -/// -/// "ERST" Error Record Serialization Table -/// -#define EFI_ACPI_5_1_ERROR_RECORD_SERIALIZATION_TABLE_SIGNATURE SIGNATURE_32('E', 'R', 'S', 'T') - -/// -/// "FACP" Fixed ACPI Description Table -/// -#define EFI_ACPI_5_1_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('F', 'A', 'C', 'P') - -/// -/// "FACS" Firmware ACPI Control Structure -/// -#define EFI_ACPI_5_1_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE SIGNATURE_32('F', 'A', 'C', 'S') - -/// -/// "FPDT" Firmware Performance Data Table -/// -#define EFI_ACPI_5_1_FIRMWARE_PERFORMANCE_DATA_TABLE_SIGNATURE SIGNATURE_32('F', 'P', 'D', 'T') - -/// -/// "GTDT" Generic Timer Description Table -/// -#define EFI_ACPI_5_1_GENERIC_TIMER_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('G', 'T', 'D', 'T') - -/// -/// "HEST" Hardware Error Source Table -/// -#define EFI_ACPI_5_1_HARDWARE_ERROR_SOURCE_TABLE_SIGNATURE SIGNATURE_32('H', 'E', 'S', 'T') - -/// -/// "MPST" Memory Power State Table -/// -#define EFI_ACPI_5_1_MEMORY_POWER_STATE_TABLE_SIGNATURE SIGNATURE_32('M', 'P', 'S', 'T') - -/// -/// "MSCT" Maximum System Characteristics Table -/// -#define EFI_ACPI_5_1_MAXIMUM_SYSTEM_CHARACTERISTICS_TABLE_SIGNATURE SIGNATURE_32('M', 'S', 'C', 'T') - -/// -/// "PMTT" Platform Memory Topology Table -/// -#define EFI_ACPI_5_1_PLATFORM_MEMORY_TOPOLOGY_TABLE_SIGNATURE SIGNATURE_32('P', 'M', 'T', 'T') - -/// -/// "PSDT" Persistent System Description Table -/// -#define EFI_ACPI_5_1_PERSISTENT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('P', 'S', 'D', 'T') - -/// -/// "RASF" ACPI RAS Feature Table -/// -#define EFI_ACPI_5_1_ACPI_RAS_FEATURE_TABLE_SIGNATURE SIGNATURE_32('R', 'A', 'S', 'F') - -/// -/// "RSDT" Root System Description Table -/// -#define EFI_ACPI_5_1_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('R', 'S', 'D', 'T') - -/// -/// "SBST" Smart Battery Specification Table -/// -#define EFI_ACPI_5_1_SMART_BATTERY_SPECIFICATION_TABLE_SIGNATURE SIGNATURE_32('S', 'B', 'S', 'T') - -/// -/// "SLIT" System Locality Information Table -/// -#define EFI_ACPI_5_1_SYSTEM_LOCALITY_INFORMATION_TABLE_SIGNATURE SIGNATURE_32('S', 'L', 'I', 'T') - -/// -/// "SRAT" System Resource Affinity Table -/// -#define EFI_ACPI_5_1_SYSTEM_RESOURCE_AFFINITY_TABLE_SIGNATURE SIGNATURE_32('S', 'R', 'A', 'T') - -/// -/// "SSDT" Secondary System Description Table -/// -#define EFI_ACPI_5_1_SECONDARY_SYSTEM_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('S', 'S', 'D', 'T') - -/// -/// "XSDT" Extended System Description Table -/// -#define EFI_ACPI_5_1_EXTENDED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('X', 'S', 'D', 'T') - -/// -/// "BOOT" MS Simple Boot Spec -/// -#define EFI_ACPI_5_1_SIMPLE_BOOT_FLAG_TABLE_SIGNATURE SIGNATURE_32('B', 'O', 'O', 'T') - -/// -/// "CSRT" MS Core System Resource Table -/// -#define EFI_ACPI_5_1_CORE_SYSTEM_RESOURCE_TABLE_SIGNATURE SIGNATURE_32('C', 'S', 'R', 'T') - -/// -/// "DBG2" MS Debug Port 2 Spec -/// -#define EFI_ACPI_5_1_DEBUG_PORT_2_TABLE_SIGNATURE SIGNATURE_32('D', 'B', 'G', '2') - -/// -/// "DBGP" MS Debug Port Spec -/// -#define EFI_ACPI_5_1_DEBUG_PORT_TABLE_SIGNATURE SIGNATURE_32('D', 'B', 'G', 'P') - -/// -/// "DMAR" DMA Remapping Table -/// -#define EFI_ACPI_5_1_DMA_REMAPPING_TABLE_SIGNATURE SIGNATURE_32('D', 'M', 'A', 'R') - -/// -/// "DRTM" Dynamic Root of Trust for Measurement Table -/// -#define EFI_ACPI_5_1_DYNAMIC_ROOT_OF_TRUST_FOR_MEASUREMENT_TABLE_SIGNATURE SIGNATURE_32('D', 'R', 'T', 'M') - -/// -/// "ETDT" Event Timer Description Table -/// -#define EFI_ACPI_5_1_EVENT_TIMER_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('E', 'T', 'D', 'T') - -/// -/// "HPET" IA-PC High Precision Event Timer Table -/// -#define EFI_ACPI_5_1_HIGH_PRECISION_EVENT_TIMER_TABLE_SIGNATURE SIGNATURE_32('H', 'P', 'E', 'T') - -/// -/// "iBFT" iSCSI Boot Firmware Table -/// -#define EFI_ACPI_5_1_ISCSI_BOOT_FIRMWARE_TABLE_SIGNATURE SIGNATURE_32('i', 'B', 'F', 'T') - -/// -/// "IVRS" I/O Virtualization Reporting Structure -/// -#define EFI_ACPI_5_1_IO_VIRTUALIZATION_REPORTING_STRUCTURE_SIGNATURE SIGNATURE_32('I', 'V', 'R', 'S') - -/// -/// "LPIT" Low Power Idle Table -/// -#define EFI_ACPI_5_1_IO_LOW_POWER_IDLE_TABLE_STRUCTURE_SIGNATURE SIGNATURE_32('L', 'P', 'I', 'T') - -/// -/// "MCFG" PCI Express Memory Mapped Configuration Space Base Address Description Table -/// -#define EFI_ACPI_5_1_PCI_EXPRESS_MEMORY_MAPPED_CONFIGURATION_SPACE_BASE_ADDRESS_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('M', 'C', 'F', 'G') - -/// -/// "MCHI" Management Controller Host Interface Table -/// -#define EFI_ACPI_5_1_MANAGEMENT_CONTROLLER_HOST_INTERFACE_TABLE_SIGNATURE SIGNATURE_32('M', 'C', 'H', 'I') - -/// -/// "MSDM" MS Data Management Table -/// -#define EFI_ACPI_5_1_DATA_MANAGEMENT_TABLE_SIGNATURE SIGNATURE_32('M', 'S', 'D', 'M') - -/// -/// "SLIC" MS Software Licensing Table Specification -/// -#define EFI_ACPI_5_1_SOFTWARE_LICENSING_TABLE_SIGNATURE SIGNATURE_32('S', 'L', 'I', 'C') - -/// -/// "SPCR" Serial Port Concole Redirection Table -/// -#define EFI_ACPI_5_1_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_SIGNATURE SIGNATURE_32('S', 'P', 'C', 'R') - -/// -/// "SPMI" Server Platform Management Interface Table -/// -#define EFI_ACPI_5_1_SERVER_PLATFORM_MANAGEMENT_INTERFACE_TABLE_SIGNATURE SIGNATURE_32('S', 'P', 'M', 'I') - -/// -/// "TCPA" Trusted Computing Platform Alliance Capabilities Table -/// -#define EFI_ACPI_5_1_TRUSTED_COMPUTING_PLATFORM_ALLIANCE_CAPABILITIES_TABLE_SIGNATURE SIGNATURE_32('T', 'C', 'P', 'A') - -/// -/// "TPM2" Trusted Computing Platform 1 Table -/// -#define EFI_ACPI_5_1_TRUSTED_COMPUTING_PLATFORM_2_TABLE_SIGNATURE SIGNATURE_32('T', 'P', 'M', '2') - -/// -/// "UEFI" UEFI ACPI Data Table -/// -#define EFI_ACPI_5_1_UEFI_ACPI_DATA_TABLE_SIGNATURE SIGNATURE_32('U', 'E', 'F', 'I') - -/// -/// "WAET" Windows ACPI Emulated Devices Table -/// -#define EFI_ACPI_5_1_WINDOWS_ACPI_EMULATED_DEVICES_TABLE_SIGNATURE SIGNATURE_32('W', 'A', 'E', 'T') - -/// -/// "WDAT" Watchdog Action Table -/// -#define EFI_ACPI_5_1_WATCHDOG_ACTION_TABLE_SIGNATURE SIGNATURE_32('W', 'D', 'A', 'T') - -/// -/// "WDRT" Watchdog Resource Table -/// -#define EFI_ACPI_5_1_WATCHDOG_RESOURCE_TABLE_SIGNATURE SIGNATURE_32('W', 'D', 'R', 'T') - -/// -/// "WPBT" MS Platform Binary Table -/// -#define EFI_ACPI_5_1_PLATFORM_BINARY_TABLE_SIGNATURE SIGNATURE_32('W', 'P', 'B', 'T') - -#pragma pack() - -#endif diff --git a/roms/ipxe/src/include/ipxe/efi/IndustryStandard/Acpi60.h b/roms/ipxe/src/include/ipxe/efi/IndustryStandard/Acpi60.h deleted file mode 100644 index 18eb5f7d9..000000000 --- a/roms/ipxe/src/include/ipxe/efi/IndustryStandard/Acpi60.h +++ /dev/null @@ -1,2348 +0,0 @@ -/** @file - ACPI 6.0 definitions from the ACPI Specification Revision 6.0 April, 2015. - - Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR> - (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR> - This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -**/ - -#ifndef _ACPI_6_0_H_ -#define _ACPI_6_0_H_ - -FILE_LICENCE ( BSD3 ); - -#include <ipxe/efi/IndustryStandard/Acpi51.h> - -// -// Ensure proper structure formats -// -#pragma pack(1) - -/// -/// ACPI 6.0 Generic Address Space definition -/// -typedef struct { - UINT8 AddressSpaceId; - UINT8 RegisterBitWidth; - UINT8 RegisterBitOffset; - UINT8 AccessSize; - UINT64 Address; -} EFI_ACPI_6_0_GENERIC_ADDRESS_STRUCTURE; - -// -// Generic Address Space Address IDs -// -#define EFI_ACPI_6_0_SYSTEM_MEMORY 0 -#define EFI_ACPI_6_0_SYSTEM_IO 1 -#define EFI_ACPI_6_0_PCI_CONFIGURATION_SPACE 2 -#define EFI_ACPI_6_0_EMBEDDED_CONTROLLER 3 -#define EFI_ACPI_6_0_SMBUS 4 -#define EFI_ACPI_6_0_PLATFORM_COMMUNICATION_CHANNEL 0x0A -#define EFI_ACPI_6_0_FUNCTIONAL_FIXED_HARDWARE 0x7F - -// -// Generic Address Space Access Sizes -// -#define EFI_ACPI_6_0_UNDEFINED 0 -#define EFI_ACPI_6_0_BYTE 1 -#define EFI_ACPI_6_0_WORD 2 -#define EFI_ACPI_6_0_DWORD 3 -#define EFI_ACPI_6_0_QWORD 4 - -// -// ACPI 6.0 table structures -// - -/// -/// Root System Description Pointer Structure -/// -typedef struct { - UINT64 Signature; - UINT8 Checksum; - UINT8 OemId[6]; - UINT8 Revision; - UINT32 RsdtAddress; - UINT32 Length; - UINT64 XsdtAddress; - UINT8 ExtendedChecksum; - UINT8 Reserved[3]; -} EFI_ACPI_6_0_ROOT_SYSTEM_DESCRIPTION_POINTER; - -/// -/// RSD_PTR Revision (as defined in ACPI 6.0 spec.) -/// -#define EFI_ACPI_6_0_ROOT_SYSTEM_DESCRIPTION_POINTER_REVISION 0x02 ///< ACPISpec (Revision 6.0) says current value is 2 - -/// -/// Common table header, this prefaces all ACPI tables, including FACS, but -/// excluding the RSD PTR structure -/// -typedef struct { - UINT32 Signature; - UINT32 Length; -} EFI_ACPI_6_0_COMMON_HEADER; - -// -// Root System Description Table -// No definition needed as it is a common description table header, the same with -// EFI_ACPI_DESCRIPTION_HEADER, followed by a variable number of UINT32 table pointers. -// - -/// -/// RSDT Revision (as defined in ACPI 6.0 spec.) -/// -#define EFI_ACPI_6_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION 0x01 - -// -// Extended System Description Table -// No definition needed as it is a common description table header, the same with -// EFI_ACPI_DESCRIPTION_HEADER, followed by a variable number of UINT64 table pointers. -// - -/// -/// XSDT Revision (as defined in ACPI 6.0 spec.) -/// -#define EFI_ACPI_6_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_REVISION 0x01 - -/// -/// Fixed ACPI Description Table Structure (FADT) -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 FirmwareCtrl; - UINT32 Dsdt; - UINT8 Reserved0; - UINT8 PreferredPmProfile; - UINT16 SciInt; - UINT32 SmiCmd; - UINT8 AcpiEnable; - UINT8 AcpiDisable; - UINT8 S4BiosReq; - UINT8 PstateCnt; - UINT32 Pm1aEvtBlk; - UINT32 Pm1bEvtBlk; - UINT32 Pm1aCntBlk; - UINT32 Pm1bCntBlk; - UINT32 Pm2CntBlk; - UINT32 PmTmrBlk; - UINT32 Gpe0Blk; - UINT32 Gpe1Blk; - UINT8 Pm1EvtLen; - UINT8 Pm1CntLen; - UINT8 Pm2CntLen; - UINT8 PmTmrLen; - UINT8 Gpe0BlkLen; - UINT8 Gpe1BlkLen; - UINT8 Gpe1Base; - UINT8 CstCnt; - UINT16 PLvl2Lat; - UINT16 PLvl3Lat; - UINT16 FlushSize; - UINT16 FlushStride; - UINT8 DutyOffset; - UINT8 DutyWidth; - UINT8 DayAlrm; - UINT8 MonAlrm; - UINT8 Century; - UINT16 IaPcBootArch; - UINT8 Reserved1; - UINT32 Flags; - EFI_ACPI_6_0_GENERIC_ADDRESS_STRUCTURE ResetReg; - UINT8 ResetValue; - UINT16 ArmBootArch; - UINT8 MinorVersion; - UINT64 XFirmwareCtrl; - UINT64 XDsdt; - EFI_ACPI_6_0_GENERIC_ADDRESS_STRUCTURE XPm1aEvtBlk; - EFI_ACPI_6_0_GENERIC_ADDRESS_STRUCTURE XPm1bEvtBlk; - EFI_ACPI_6_0_GENERIC_ADDRESS_STRUCTURE XPm1aCntBlk; - EFI_ACPI_6_0_GENERIC_ADDRESS_STRUCTURE XPm1bCntBlk; - EFI_ACPI_6_0_GENERIC_ADDRESS_STRUCTURE XPm2CntBlk; - EFI_ACPI_6_0_GENERIC_ADDRESS_STRUCTURE XPmTmrBlk; - EFI_ACPI_6_0_GENERIC_ADDRESS_STRUCTURE XGpe0Blk; - EFI_ACPI_6_0_GENERIC_ADDRESS_STRUCTURE XGpe1Blk; - EFI_ACPI_6_0_GENERIC_ADDRESS_STRUCTURE SleepControlReg; - EFI_ACPI_6_0_GENERIC_ADDRESS_STRUCTURE SleepStatusReg; - UINT64 HypervisorVendorIdentity; -} EFI_ACPI_6_0_FIXED_ACPI_DESCRIPTION_TABLE; - -/// -/// FADT Version (as defined in ACPI 6.0 spec.) -/// -#define EFI_ACPI_6_0_FIXED_ACPI_DESCRIPTION_TABLE_REVISION 0x06 -#define EFI_ACPI_6_0_FIXED_ACPI_DESCRIPTION_TABLE_MINOR_REVISION 0x00 - -// -// Fixed ACPI Description Table Preferred Power Management Profile -// -#define EFI_ACPI_6_0_PM_PROFILE_UNSPECIFIED 0 -#define EFI_ACPI_6_0_PM_PROFILE_DESKTOP 1 -#define EFI_ACPI_6_0_PM_PROFILE_MOBILE 2 -#define EFI_ACPI_6_0_PM_PROFILE_WORKSTATION 3 -#define EFI_ACPI_6_0_PM_PROFILE_ENTERPRISE_SERVER 4 -#define EFI_ACPI_6_0_PM_PROFILE_SOHO_SERVER 5 -#define EFI_ACPI_6_0_PM_PROFILE_APPLIANCE_PC 6 -#define EFI_ACPI_6_0_PM_PROFILE_PERFORMANCE_SERVER 7 -#define EFI_ACPI_6_0_PM_PROFILE_TABLET 8 - -// -// Fixed ACPI Description Table Boot Architecture Flags -// All other bits are reserved and must be set to 0. -// -#define EFI_ACPI_6_0_LEGACY_DEVICES BIT0 -#define EFI_ACPI_6_0_8042 BIT1 -#define EFI_ACPI_6_0_VGA_NOT_PRESENT BIT2 -#define EFI_ACPI_6_0_MSI_NOT_SUPPORTED BIT3 -#define EFI_ACPI_6_0_PCIE_ASPM_CONTROLS BIT4 -#define EFI_ACPI_6_0_CMOS_RTC_NOT_PRESENT BIT5 - -// -// Fixed ACPI Description Table Arm Boot Architecture Flags -// All other bits are reserved and must be set to 0. -// -#define EFI_ACPI_6_0_ARM_PSCI_COMPLIANT BIT0 -#define EFI_ACPI_6_0_ARM_PSCI_USE_HVC BIT1 - -// -// Fixed ACPI Description Table Fixed Feature Flags -// All other bits are reserved and must be set to 0. -// -#define EFI_ACPI_6_0_WBINVD BIT0 -#define EFI_ACPI_6_0_WBINVD_FLUSH BIT1 -#define EFI_ACPI_6_0_PROC_C1 BIT2 -#define EFI_ACPI_6_0_P_LVL2_UP BIT3 -#define EFI_ACPI_6_0_PWR_BUTTON BIT4 -#define EFI_ACPI_6_0_SLP_BUTTON BIT5 -#define EFI_ACPI_6_0_FIX_RTC BIT6 -#define EFI_ACPI_6_0_RTC_S4 BIT7 -#define EFI_ACPI_6_0_TMR_VAL_EXT BIT8 -#define EFI_ACPI_6_0_DCK_CAP BIT9 -#define EFI_ACPI_6_0_RESET_REG_SUP BIT10 -#define EFI_ACPI_6_0_SEALED_CASE BIT11 -#define EFI_ACPI_6_0_HEADLESS BIT12 -#define EFI_ACPI_6_0_CPU_SW_SLP BIT13 -#define EFI_ACPI_6_0_PCI_EXP_WAK BIT14 -#define EFI_ACPI_6_0_USE_PLATFORM_CLOCK BIT15 -#define EFI_ACPI_6_0_S4_RTC_STS_VALID BIT16 -#define EFI_ACPI_6_0_REMOTE_POWER_ON_CAPABLE BIT17 -#define EFI_ACPI_6_0_FORCE_APIC_CLUSTER_MODEL BIT18 -#define EFI_ACPI_6_0_FORCE_APIC_PHYSICAL_DESTINATION_MODE BIT19 -#define EFI_ACPI_6_0_HW_REDUCED_ACPI BIT20 -#define EFI_ACPI_6_0_LOW_POWER_S0_IDLE_CAPABLE BIT21 - -/// -/// Firmware ACPI Control Structure -/// -typedef struct { - UINT32 Signature; - UINT32 Length; - UINT32 HardwareSignature; - UINT32 FirmwareWakingVector; - UINT32 GlobalLock; - UINT32 Flags; - UINT64 XFirmwareWakingVector; - UINT8 Version; - UINT8 Reserved0[3]; - UINT32 OspmFlags; - UINT8 Reserved1[24]; -} EFI_ACPI_6_0_FIRMWARE_ACPI_CONTROL_STRUCTURE; - -/// -/// FACS Version (as defined in ACPI 6.0 spec.) -/// -#define EFI_ACPI_6_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_VERSION 0x02 - -/// -/// Firmware Control Structure Feature Flags -/// All other bits are reserved and must be set to 0. -/// -#define EFI_ACPI_6_0_S4BIOS_F BIT0 -#define EFI_ACPI_6_0_64BIT_WAKE_SUPPORTED_F BIT1 - -/// -/// OSPM Enabled Firmware Control Structure Flags -/// All other bits are reserved and must be set to 0. -/// -#define EFI_ACPI_6_0_OSPM_64BIT_WAKE_F BIT0 - -// -// Differentiated System Description Table, -// Secondary System Description Table -// and Persistent System Description Table, -// no definition needed as they are common description table header, the same with -// EFI_ACPI_DESCRIPTION_HEADER, followed by a definition block. -// -#define EFI_ACPI_6_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_REVISION 0x02 -#define EFI_ACPI_6_0_SECONDARY_SYSTEM_DESCRIPTION_TABLE_REVISION 0x02 - -/// -/// Multiple APIC Description Table header definition. The rest of the table -/// must be defined in a platform specific manner. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 LocalApicAddress; - UINT32 Flags; -} EFI_ACPI_6_0_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER; - -/// -/// MADT Revision (as defined in ACPI 6.0 spec.) -/// -#define EFI_ACPI_6_0_MULTIPLE_APIC_DESCRIPTION_TABLE_REVISION 0x03 - -/// -/// Multiple APIC Flags -/// All other bits are reserved and must be set to 0. -/// -#define EFI_ACPI_6_0_PCAT_COMPAT BIT0 - -// -// Multiple APIC Description Table APIC structure types -// All other values between 0x0D and 0x7F are reserved and -// will be ignored by OSPM. 0x80 ~ 0xFF are reserved for OEM. -// -#define EFI_ACPI_6_0_PROCESSOR_LOCAL_APIC 0x00 -#define EFI_ACPI_6_0_IO_APIC 0x01 -#define EFI_ACPI_6_0_INTERRUPT_SOURCE_OVERRIDE 0x02 -#define EFI_ACPI_6_0_NON_MASKABLE_INTERRUPT_SOURCE 0x03 -#define EFI_ACPI_6_0_LOCAL_APIC_NMI 0x04 -#define EFI_ACPI_6_0_LOCAL_APIC_ADDRESS_OVERRIDE 0x05 -#define EFI_ACPI_6_0_IO_SAPIC 0x06 -#define EFI_ACPI_6_0_LOCAL_SAPIC 0x07 -#define EFI_ACPI_6_0_PLATFORM_INTERRUPT_SOURCES 0x08 -#define EFI_ACPI_6_0_PROCESSOR_LOCAL_X2APIC 0x09 -#define EFI_ACPI_6_0_LOCAL_X2APIC_NMI 0x0A -#define EFI_ACPI_6_0_GIC 0x0B -#define EFI_ACPI_6_0_GICD 0x0C -#define EFI_ACPI_6_0_GIC_MSI_FRAME 0x0D -#define EFI_ACPI_6_0_GICR 0x0E -#define EFI_ACPI_6_0_GIC_ITS 0x0F - -// -// APIC Structure Definitions -// - -/// -/// Processor Local APIC Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 AcpiProcessorUid; - UINT8 ApicId; - UINT32 Flags; -} EFI_ACPI_6_0_PROCESSOR_LOCAL_APIC_STRUCTURE; - -/// -/// Local APIC Flags. All other bits are reserved and must be 0. -/// -#define EFI_ACPI_6_0_LOCAL_APIC_ENABLED BIT0 - -/// -/// IO APIC Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 IoApicId; - UINT8 Reserved; - UINT32 IoApicAddress; - UINT32 GlobalSystemInterruptBase; -} EFI_ACPI_6_0_IO_APIC_STRUCTURE; - -/// -/// Interrupt Source Override Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 Bus; - UINT8 Source; - UINT32 GlobalSystemInterrupt; - UINT16 Flags; -} EFI_ACPI_6_0_INTERRUPT_SOURCE_OVERRIDE_STRUCTURE; - -/// -/// Platform Interrupt Sources Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT16 Flags; - UINT8 InterruptType; - UINT8 ProcessorId; - UINT8 ProcessorEid; - UINT8 IoSapicVector; - UINT32 GlobalSystemInterrupt; - UINT32 PlatformInterruptSourceFlags; - UINT8 CpeiProcessorOverride; - UINT8 Reserved[31]; -} EFI_ACPI_6_0_PLATFORM_INTERRUPT_APIC_STRUCTURE; - -// -// MPS INTI flags. -// All other bits are reserved and must be set to 0. -// -#define EFI_ACPI_6_0_POLARITY (3 << 0) -#define EFI_ACPI_6_0_TRIGGER_MODE (3 << 2) - -/// -/// Non-Maskable Interrupt Source Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT16 Flags; - UINT32 GlobalSystemInterrupt; -} EFI_ACPI_6_0_NON_MASKABLE_INTERRUPT_SOURCE_STRUCTURE; - -/// -/// Local APIC NMI Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 AcpiProcessorUid; - UINT16 Flags; - UINT8 LocalApicLint; -} EFI_ACPI_6_0_LOCAL_APIC_NMI_STRUCTURE; - -/// -/// Local APIC Address Override Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT16 Reserved; - UINT64 LocalApicAddress; -} EFI_ACPI_6_0_LOCAL_APIC_ADDRESS_OVERRIDE_STRUCTURE; - -/// -/// IO SAPIC Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 IoApicId; - UINT8 Reserved; - UINT32 GlobalSystemInterruptBase; - UINT64 IoSapicAddress; -} EFI_ACPI_6_0_IO_SAPIC_STRUCTURE; - -/// -/// Local SAPIC Structure -/// This struct followed by a null-terminated ASCII string - ACPI Processor UID String -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 AcpiProcessorId; - UINT8 LocalSapicId; - UINT8 LocalSapicEid; - UINT8 Reserved[3]; - UINT32 Flags; - UINT32 ACPIProcessorUIDValue; -} EFI_ACPI_6_0_PROCESSOR_LOCAL_SAPIC_STRUCTURE; - -/// -/// Platform Interrupt Sources Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT16 Flags; - UINT8 InterruptType; - UINT8 ProcessorId; - UINT8 ProcessorEid; - UINT8 IoSapicVector; - UINT32 GlobalSystemInterrupt; - UINT32 PlatformInterruptSourceFlags; -} EFI_ACPI_6_0_PLATFORM_INTERRUPT_SOURCES_STRUCTURE; - -/// -/// Platform Interrupt Source Flags. -/// All other bits are reserved and must be set to 0. -/// -#define EFI_ACPI_6_0_CPEI_PROCESSOR_OVERRIDE BIT0 - -/// -/// Processor Local x2APIC Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 Reserved[2]; - UINT32 X2ApicId; - UINT32 Flags; - UINT32 AcpiProcessorUid; -} EFI_ACPI_6_0_PROCESSOR_LOCAL_X2APIC_STRUCTURE; - -/// -/// Local x2APIC NMI Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT16 Flags; - UINT32 AcpiProcessorUid; - UINT8 LocalX2ApicLint; - UINT8 Reserved[3]; -} EFI_ACPI_6_0_LOCAL_X2APIC_NMI_STRUCTURE; - -/// -/// GIC Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT16 Reserved; - UINT32 CPUInterfaceNumber; - UINT32 AcpiProcessorUid; - UINT32 Flags; - UINT32 ParkingProtocolVersion; - UINT32 PerformanceInterruptGsiv; - UINT64 ParkedAddress; - UINT64 PhysicalBaseAddress; - UINT64 GICV; - UINT64 GICH; - UINT32 VGICMaintenanceInterrupt; - UINT64 GICRBaseAddress; - UINT64 MPIDR; - UINT8 ProcessorPowerEfficiencyClass; - UINT8 Reserved2[3]; -} EFI_ACPI_6_0_GIC_STRUCTURE; - -/// -/// GIC Flags. All other bits are reserved and must be 0. -/// -#define EFI_ACPI_6_0_GIC_ENABLED BIT0 -#define EFI_ACPI_6_0_PERFORMANCE_INTERRUPT_MODEL BIT1 -#define EFI_ACPI_6_0_VGIC_MAINTENANCE_INTERRUPT_MODE_FLAGS BIT2 - -/// -/// GIC Distributor Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT16 Reserved1; - UINT32 GicId; - UINT64 PhysicalBaseAddress; - UINT32 SystemVectorBase; - UINT8 GicVersion; - UINT8 Reserved2[3]; -} EFI_ACPI_6_0_GIC_DISTRIBUTOR_STRUCTURE; - -/// -/// GIC Version -/// -#define EFI_ACPI_6_0_GIC_V1 0x01 -#define EFI_ACPI_6_0_GIC_V2 0x02 -#define EFI_ACPI_6_0_GIC_V3 0x03 -#define EFI_ACPI_6_0_GIC_V4 0x04 - -/// -/// GIC MSI Frame Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT16 Reserved1; - UINT32 GicMsiFrameId; - UINT64 PhysicalBaseAddress; - UINT32 Flags; - UINT16 SPICount; - UINT16 SPIBase; -} EFI_ACPI_6_0_GIC_MSI_FRAME_STRUCTURE; - -/// -/// GIC MSI Frame Flags. All other bits are reserved and must be 0. -/// -#define EFI_ACPI_6_0_SPI_COUNT_BASE_SELECT BIT0 - -/// -/// GICR Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT16 Reserved; - UINT64 DiscoveryRangeBaseAddress; - UINT32 DiscoveryRangeLength; -} EFI_ACPI_6_0_GICR_STRUCTURE; - -/// -/// GIC Interrupt Translation Service Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT16 Reserved; - UINT32 GicItsId; - UINT64 PhysicalBaseAddress; - UINT32 Reserved2; -} EFI_ACPI_6_0_GIC_ITS_STRUCTURE; - -/// -/// Smart Battery Description Table (SBST) -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 WarningEnergyLevel; - UINT32 LowEnergyLevel; - UINT32 CriticalEnergyLevel; -} EFI_ACPI_6_0_SMART_BATTERY_DESCRIPTION_TABLE; - -/// -/// SBST Version (as defined in ACPI 6.0 spec.) -/// -#define EFI_ACPI_6_0_SMART_BATTERY_DESCRIPTION_TABLE_REVISION 0x01 - -/// -/// Embedded Controller Boot Resources Table (ECDT) -/// The table is followed by a null terminated ASCII string that contains -/// a fully qualified reference to the name space object. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - EFI_ACPI_6_0_GENERIC_ADDRESS_STRUCTURE EcControl; - EFI_ACPI_6_0_GENERIC_ADDRESS_STRUCTURE EcData; - UINT32 Uid; - UINT8 GpeBit; -} EFI_ACPI_6_0_EMBEDDED_CONTROLLER_BOOT_RESOURCES_TABLE; - -/// -/// ECDT Version (as defined in ACPI 6.0 spec.) -/// -#define EFI_ACPI_6_0_EMBEDDED_CONTROLLER_BOOT_RESOURCES_TABLE_REVISION 0x01 - -/// -/// System Resource Affinity Table (SRAT). The rest of the table -/// must be defined in a platform specific manner. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 Reserved1; ///< Must be set to 1 - UINT64 Reserved2; -} EFI_ACPI_6_0_SYSTEM_RESOURCE_AFFINITY_TABLE_HEADER; - -/// -/// SRAT Version (as defined in ACPI 6.0 spec.) -/// -#define EFI_ACPI_6_0_SYSTEM_RESOURCE_AFFINITY_TABLE_REVISION 0x03 - -// -// SRAT structure types. -// All other values between 0x04 an 0xFF are reserved and -// will be ignored by OSPM. -// -#define EFI_ACPI_6_0_PROCESSOR_LOCAL_APIC_SAPIC_AFFINITY 0x00 -#define EFI_ACPI_6_0_MEMORY_AFFINITY 0x01 -#define EFI_ACPI_6_0_PROCESSOR_LOCAL_X2APIC_AFFINITY 0x02 -#define EFI_ACPI_6_0_GICC_AFFINITY 0x03 - -/// -/// Processor Local APIC/SAPIC Affinity Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 ProximityDomain7To0; - UINT8 ApicId; - UINT32 Flags; - UINT8 LocalSapicEid; - UINT8 ProximityDomain31To8[3]; - UINT32 ClockDomain; -} EFI_ACPI_6_0_PROCESSOR_LOCAL_APIC_SAPIC_AFFINITY_STRUCTURE; - -/// -/// Local APIC/SAPIC Flags. All other bits are reserved and must be 0. -/// -#define EFI_ACPI_6_0_PROCESSOR_LOCAL_APIC_SAPIC_ENABLED (1 << 0) - -/// -/// Memory Affinity Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT32 ProximityDomain; - UINT16 Reserved1; - UINT32 AddressBaseLow; - UINT32 AddressBaseHigh; - UINT32 LengthLow; - UINT32 LengthHigh; - UINT32 Reserved2; - UINT32 Flags; - UINT64 Reserved3; -} EFI_ACPI_6_0_MEMORY_AFFINITY_STRUCTURE; - -// -// Memory Flags. All other bits are reserved and must be 0. -// -#define EFI_ACPI_6_0_MEMORY_ENABLED (1 << 0) -#define EFI_ACPI_6_0_MEMORY_HOT_PLUGGABLE (1 << 1) -#define EFI_ACPI_6_0_MEMORY_NONVOLATILE (1 << 2) - -/// -/// Processor Local x2APIC Affinity Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 Reserved1[2]; - UINT32 ProximityDomain; - UINT32 X2ApicId; - UINT32 Flags; - UINT32 ClockDomain; - UINT8 Reserved2[4]; -} EFI_ACPI_6_0_PROCESSOR_LOCAL_X2APIC_AFFINITY_STRUCTURE; - -/// -/// GICC Affinity Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT32 ProximityDomain; - UINT32 AcpiProcessorUid; - UINT32 Flags; - UINT32 ClockDomain; -} EFI_ACPI_6_0_GICC_AFFINITY_STRUCTURE; - -/// -/// GICC Flags. All other bits are reserved and must be 0. -/// -#define EFI_ACPI_6_0_GICC_ENABLED (1 << 0) - -/// -/// System Locality Distance Information Table (SLIT). -/// The rest of the table is a matrix. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT64 NumberOfSystemLocalities; -} EFI_ACPI_6_0_SYSTEM_LOCALITY_DISTANCE_INFORMATION_TABLE_HEADER; - -/// -/// SLIT Version (as defined in ACPI 6.0 spec.) -/// -#define EFI_ACPI_6_0_SYSTEM_LOCALITY_DISTANCE_INFORMATION_TABLE_REVISION 0x01 - -/// -/// Corrected Platform Error Polling Table (CPEP) -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT8 Reserved[8]; -} EFI_ACPI_6_0_CORRECTED_PLATFORM_ERROR_POLLING_TABLE_HEADER; - -/// -/// CPEP Version (as defined in ACPI 6.0 spec.) -/// -#define EFI_ACPI_6_0_CORRECTED_PLATFORM_ERROR_POLLING_TABLE_REVISION 0x01 - -// -// CPEP processor structure types. -// -#define EFI_ACPI_6_0_CPEP_PROCESSOR_APIC_SAPIC 0x00 - -/// -/// Corrected Platform Error Polling Processor Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 ProcessorId; - UINT8 ProcessorEid; - UINT32 PollingInterval; -} EFI_ACPI_6_0_CPEP_PROCESSOR_APIC_SAPIC_STRUCTURE; - -/// -/// Maximum System Characteristics Table (MSCT) -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 OffsetProxDomInfo; - UINT32 MaximumNumberOfProximityDomains; - UINT32 MaximumNumberOfClockDomains; - UINT64 MaximumPhysicalAddress; -} EFI_ACPI_6_0_MAXIMUM_SYSTEM_CHARACTERISTICS_TABLE_HEADER; - -/// -/// MSCT Version (as defined in ACPI 6.0 spec.) -/// -#define EFI_ACPI_6_0_MAXIMUM_SYSTEM_CHARACTERISTICS_TABLE_REVISION 0x01 - -/// -/// Maximum Proximity Domain Information Structure Definition -/// -typedef struct { - UINT8 Revision; - UINT8 Length; - UINT32 ProximityDomainRangeLow; - UINT32 ProximityDomainRangeHigh; - UINT32 MaximumProcessorCapacity; - UINT64 MaximumMemoryCapacity; -} EFI_ACPI_6_0_MAXIMUM_PROXIMITY_DOMAIN_INFORMATION_STRUCTURE; - -/// -/// ACPI RAS Feature Table definition. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT8 PlatformCommunicationChannelIdentifier[12]; -} EFI_ACPI_6_0_RAS_FEATURE_TABLE; - -/// -/// RASF Version (as defined in ACPI 6.0 spec.) -/// -#define EFI_ACPI_6_0_RAS_FEATURE_TABLE_REVISION 0x01 - -/// -/// ACPI RASF Platform Communication Channel Shared Memory Region definition. -/// -typedef struct { - UINT32 Signature; - UINT16 Command; - UINT16 Status; - UINT16 Version; - UINT8 RASCapabilities[16]; - UINT8 SetRASCapabilities[16]; - UINT16 NumberOfRASFParameterBlocks; - UINT32 SetRASCapabilitiesStatus; -} EFI_ACPI_6_0_RASF_PLATFORM_COMMUNICATION_CHANNEL_SHARED_MEMORY_REGION; - -/// -/// ACPI RASF PCC command code -/// -#define EFI_ACPI_6_0_RASF_PCC_COMMAND_CODE_EXECUTE_RASF_COMMAND 0x01 - -/// -/// ACPI RASF Platform RAS Capabilities -/// -#define EFI_ACPI_6_0_RASF_PLATFORM_RAS_CAPABILITY_HARDWARE_BASED_PATROL_SCRUB_SUPPOTED 0x01 -#define EFI_ACPI_6_0_RASF_PLATFORM_RAS_CAPABILITY_HARDWARE_BASED_PATROL_SCRUB_SUPPOTED_AND_EXPOSED_TO_SOFTWARE 0x02 - -/// -/// ACPI RASF Parameter Block structure for PATROL_SCRUB -/// -typedef struct { - UINT16 Type; - UINT16 Version; - UINT16 Length; - UINT16 PatrolScrubCommand; - UINT64 RequestedAddressRange[2]; - UINT64 ActualAddressRange[2]; - UINT16 Flags; - UINT8 RequestedSpeed; -} EFI_ACPI_6_0_RASF_PATROL_SCRUB_PLATFORM_BLOCK_STRUCTURE; - -/// -/// ACPI RASF Patrol Scrub command -/// -#define EFI_ACPI_6_0_RASF_PATROL_SCRUB_COMMAND_GET_PATROL_PARAMETERS 0x01 -#define EFI_ACPI_6_0_RASF_PATROL_SCRUB_COMMAND_START_PATROL_SCRUBBER 0x02 -#define EFI_ACPI_6_0_RASF_PATROL_SCRUB_COMMAND_STOP_PATROL_SCRUBBER 0x03 - -/// -/// Memory Power State Table definition. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT8 PlatformCommunicationChannelIdentifier; - UINT8 Reserved[3]; -// Memory Power Node Structure -// Memory Power State Characteristics -} EFI_ACPI_6_0_MEMORY_POWER_STATUS_TABLE; - -/// -/// MPST Version (as defined in ACPI 6.0 spec.) -/// -#define EFI_ACPI_6_0_MEMORY_POWER_STATE_TABLE_REVISION 0x01 - -/// -/// MPST Platform Communication Channel Shared Memory Region definition. -/// -typedef struct { - UINT32 Signature; - UINT16 Command; - UINT16 Status; - UINT32 MemoryPowerCommandRegister; - UINT32 MemoryPowerStatusRegister; - UINT32 PowerStateId; - UINT32 MemoryPowerNodeId; - UINT64 MemoryEnergyConsumed; - UINT64 ExpectedAveragePowerComsuned; -} EFI_ACPI_6_0_MPST_PLATFORM_COMMUNICATION_CHANNEL_SHARED_MEMORY_REGION; - -/// -/// ACPI MPST PCC command code -/// -#define EFI_ACPI_6_0_MPST_PCC_COMMAND_CODE_EXECUTE_MPST_COMMAND 0x03 - -/// -/// ACPI MPST Memory Power command -/// -#define EFI_ACPI_6_0_MPST_MEMORY_POWER_COMMAND_GET_MEMORY_POWER_STATE 0x01 -#define EFI_ACPI_6_0_MPST_MEMORY_POWER_COMMAND_SET_MEMORY_POWER_STATE 0x02 -#define EFI_ACPI_6_0_MPST_MEMORY_POWER_COMMAND_GET_AVERAGE_POWER_CONSUMED 0x03 -#define EFI_ACPI_6_0_MPST_MEMORY_POWER_COMMAND_GET_MEMORY_ENERGY_CONSUMED 0x04 - -/// -/// MPST Memory Power Node Table -/// -typedef struct { - UINT8 PowerStateValue; - UINT8 PowerStateInformationIndex; -} EFI_ACPI_6_0_MPST_MEMORY_POWER_STATE; - -typedef struct { - UINT8 Flag; - UINT8 Reserved; - UINT16 MemoryPowerNodeId; - UINT32 Length; - UINT64 AddressBase; - UINT64 AddressLength; - UINT32 NumberOfPowerStates; - UINT32 NumberOfPhysicalComponents; -//EFI_ACPI_6_0_MPST_MEMORY_POWER_STATE MemoryPowerState[NumberOfPowerStates]; -//UINT16 PhysicalComponentIdentifier[NumberOfPhysicalComponents]; -} EFI_ACPI_6_0_MPST_MEMORY_POWER_STRUCTURE; - -#define EFI_ACPI_6_0_MPST_MEMORY_POWER_STRUCTURE_FLAG_ENABLE 0x01 -#define EFI_ACPI_6_0_MPST_MEMORY_POWER_STRUCTURE_FLAG_POWER_MANAGED 0x02 -#define EFI_ACPI_6_0_MPST_MEMORY_POWER_STRUCTURE_FLAG_HOT_PLUGGABLE 0x04 - -typedef struct { - UINT16 MemoryPowerNodeCount; - UINT8 Reserved[2]; -} EFI_ACPI_6_0_MPST_MEMORY_POWER_NODE_TABLE; - -/// -/// MPST Memory Power State Characteristics Table -/// -typedef struct { - UINT8 PowerStateStructureID; - UINT8 Flag; - UINT16 Reserved; - UINT32 AveragePowerConsumedInMPS0; - UINT32 RelativePowerSavingToMPS0; - UINT64 ExitLatencyToMPS0; -} EFI_ACPI_6_0_MPST_MEMORY_POWER_STATE_CHARACTERISTICS_STRUCTURE; - -#define EFI_ACPI_6_0_MPST_MEMORY_POWER_STATE_CHARACTERISTICS_STRUCTURE_FLAG_MEMORY_CONTENT_PRESERVED 0x01 -#define EFI_ACPI_6_0_MPST_MEMORY_POWER_STATE_CHARACTERISTICS_STRUCTURE_FLAG_AUTONOMOUS_MEMORY_POWER_STATE_ENTRY 0x02 -#define EFI_ACPI_6_0_MPST_MEMORY_POWER_STATE_CHARACTERISTICS_STRUCTURE_FLAG_AUTONOMOUS_MEMORY_POWER_STATE_EXIT 0x04 - -typedef struct { - UINT16 MemoryPowerStateCharacteristicsCount; - UINT8 Reserved[2]; -} EFI_ACPI_6_0_MPST_MEMORY_POWER_STATE_CHARACTERISTICS_TABLE; - -/// -/// Memory Topology Table definition. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 Reserved; -} EFI_ACPI_6_0_MEMORY_TOPOLOGY_TABLE; - -/// -/// PMTT Version (as defined in ACPI 6.0 spec.) -/// -#define EFI_ACPI_6_0_MEMORY_TOPOLOGY_TABLE_REVISION 0x01 - -/// -/// Common Memory Aggregator Device Structure. -/// -typedef struct { - UINT8 Type; - UINT8 Reserved; - UINT16 Length; - UINT16 Flags; - UINT16 Reserved1; -} EFI_ACPI_6_0_PMMT_COMMON_MEMORY_AGGREGATOR_DEVICE_STRUCTURE; - -/// -/// Memory Aggregator Device Type -/// -#define EFI_ACPI_6_0_PMMT_MEMORY_AGGREGATOR_DEVICE_TYPE_SOCKET 0x1 -#define EFI_ACPI_6_0_PMMT_MEMORY_AGGREGATOR_DEVICE_TYPE_MEMORY_CONTROLLER 0x2 -#define EFI_ACPI_6_0_PMMT_MEMORY_AGGREGATOR_DEVICE_TYPE_DIMM 0x3 - -/// -/// Socket Memory Aggregator Device Structure. -/// -typedef struct { - EFI_ACPI_6_0_PMMT_COMMON_MEMORY_AGGREGATOR_DEVICE_STRUCTURE Header; - UINT16 SocketIdentifier; - UINT16 Reserved; -//EFI_ACPI_6_0_PMMT_MEMORY_CONTROLLER_MEMORY_AGGREGATOR_DEVICE_STRUCTURE MemoryController[]; -} EFI_ACPI_6_0_PMMT_SOCKET_MEMORY_AGGREGATOR_DEVICE_STRUCTURE; - -/// -/// MemoryController Memory Aggregator Device Structure. -/// -typedef struct { - EFI_ACPI_6_0_PMMT_COMMON_MEMORY_AGGREGATOR_DEVICE_STRUCTURE Header; - UINT32 ReadLatency; - UINT32 WriteLatency; - UINT32 ReadBandwidth; - UINT32 WriteBandwidth; - UINT16 OptimalAccessUnit; - UINT16 OptimalAccessAlignment; - UINT16 Reserved; - UINT16 NumberOfProximityDomains; -//UINT32 ProximityDomain[NumberOfProximityDomains]; -//EFI_ACPI_6_0_PMMT_DIMM_MEMORY_AGGREGATOR_DEVICE_STRUCTURE PhysicalComponent[]; -} EFI_ACPI_6_0_PMMT_MEMORY_CONTROLLER_MEMORY_AGGREGATOR_DEVICE_STRUCTURE; - -/// -/// DIMM Memory Aggregator Device Structure. -/// -typedef struct { - EFI_ACPI_6_0_PMMT_COMMON_MEMORY_AGGREGATOR_DEVICE_STRUCTURE Header; - UINT16 PhysicalComponentIdentifier; - UINT16 Reserved; - UINT32 SizeOfDimm; - UINT32 SmbiosHandle; -} EFI_ACPI_6_0_PMMT_DIMM_MEMORY_AGGREGATOR_DEVICE_STRUCTURE; - -/// -/// Boot Graphics Resource Table definition. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - /// - /// 2-bytes (16 bit) version ID. This value must be 1. - /// - UINT16 Version; - /// - /// 1-byte status field indicating current status about the table. - /// Bits[7:1] = Reserved (must be zero) - /// Bit [0] = Valid. A one indicates the boot image graphic is valid. - /// - UINT8 Status; - /// - /// 1-byte enumerated type field indicating format of the image. - /// 0 = Bitmap - /// 1 - 255 Reserved (for future use) - /// - UINT8 ImageType; - /// - /// 8-byte (64 bit) physical address pointing to the firmware's in-memory copy - /// of the image bitmap. - /// - UINT64 ImageAddress; - /// - /// A 4-byte (32-bit) unsigned long describing the display X-offset of the boot image. - /// (X, Y) display offset of the top left corner of the boot image. - /// The top left corner of the display is at offset (0, 0). - /// - UINT32 ImageOffsetX; - /// - /// A 4-byte (32-bit) unsigned long describing the display Y-offset of the boot image. - /// (X, Y) display offset of the top left corner of the boot image. - /// The top left corner of the display is at offset (0, 0). - /// - UINT32 ImageOffsetY; -} EFI_ACPI_6_0_BOOT_GRAPHICS_RESOURCE_TABLE; - -/// -/// BGRT Revision -/// -#define EFI_ACPI_6_0_BOOT_GRAPHICS_RESOURCE_TABLE_REVISION 1 - -/// -/// BGRT Version -/// -#define EFI_ACPI_6_0_BGRT_VERSION 0x01 - -/// -/// BGRT Status -/// -#define EFI_ACPI_6_0_BGRT_STATUS_NOT_DISPLAYED 0x00 -#define EFI_ACPI_6_0_BGRT_STATUS_DISPLAYED 0x01 - -/// -/// BGRT Image Type -/// -#define EFI_ACPI_6_0_BGRT_IMAGE_TYPE_BMP 0x00 - -/// -/// FPDT Version (as defined in ACPI 6.0 spec.) -/// -#define EFI_ACPI_6_0_FIRMWARE_PERFORMANCE_DATA_TABLE_REVISION 0x01 - -/// -/// FPDT Performance Record Types -/// -#define EFI_ACPI_6_0_FPDT_RECORD_TYPE_FIRMWARE_BASIC_BOOT_POINTER 0x0000 -#define EFI_ACPI_6_0_FPDT_RECORD_TYPE_S3_PERFORMANCE_TABLE_POINTER 0x0001 - -/// -/// FPDT Performance Record Revision -/// -#define EFI_ACPI_6_0_FPDT_RECORD_REVISION_FIRMWARE_BASIC_BOOT_POINTER 0x01 -#define EFI_ACPI_6_0_FPDT_RECORD_REVISION_S3_PERFORMANCE_TABLE_POINTER 0x01 - -/// -/// FPDT Runtime Performance Record Types -/// -#define EFI_ACPI_6_0_FPDT_RUNTIME_RECORD_TYPE_S3_RESUME 0x0000 -#define EFI_ACPI_6_0_FPDT_RUNTIME_RECORD_TYPE_S3_SUSPEND 0x0001 -#define EFI_ACPI_6_0_FPDT_RUNTIME_RECORD_TYPE_FIRMWARE_BASIC_BOOT 0x0002 - -/// -/// FPDT Runtime Performance Record Revision -/// -#define EFI_ACPI_6_0_FPDT_RUNTIME_RECORD_REVISION_S3_RESUME 0x01 -#define EFI_ACPI_6_0_FPDT_RUNTIME_RECORD_REVISION_S3_SUSPEND 0x01 -#define EFI_ACPI_6_0_FPDT_RUNTIME_RECORD_REVISION_FIRMWARE_BASIC_BOOT 0x02 - -/// -/// FPDT Performance Record header -/// -typedef struct { - UINT16 Type; - UINT8 Length; - UINT8 Revision; -} EFI_ACPI_6_0_FPDT_PERFORMANCE_RECORD_HEADER; - -/// -/// FPDT Performance Table header -/// -typedef struct { - UINT32 Signature; - UINT32 Length; -} EFI_ACPI_6_0_FPDT_PERFORMANCE_TABLE_HEADER; - -/// -/// FPDT Firmware Basic Boot Performance Pointer Record Structure -/// -typedef struct { - EFI_ACPI_6_0_FPDT_PERFORMANCE_RECORD_HEADER Header; - UINT32 Reserved; - /// - /// 64-bit processor-relative physical address of the Basic Boot Performance Table. - /// - UINT64 BootPerformanceTablePointer; -} EFI_ACPI_6_0_FPDT_BOOT_PERFORMANCE_TABLE_POINTER_RECORD; - -/// -/// FPDT S3 Performance Table Pointer Record Structure -/// -typedef struct { - EFI_ACPI_6_0_FPDT_PERFORMANCE_RECORD_HEADER Header; - UINT32 Reserved; - /// - /// 64-bit processor-relative physical address of the S3 Performance Table. - /// - UINT64 S3PerformanceTablePointer; -} EFI_ACPI_6_0_FPDT_S3_PERFORMANCE_TABLE_POINTER_RECORD; - -/// -/// FPDT Firmware Basic Boot Performance Record Structure -/// -typedef struct { - EFI_ACPI_6_0_FPDT_PERFORMANCE_RECORD_HEADER Header; - UINT32 Reserved; - /// - /// Timer value logged at the beginning of firmware image execution. - /// This may not always be zero or near zero. - /// - UINT64 ResetEnd; - /// - /// Timer value logged just prior to loading the OS boot loader into memory. - /// For non-UEFI compatible boots, this field must be zero. - /// - UINT64 OsLoaderLoadImageStart; - /// - /// Timer value logged just prior to launching the previously loaded OS boot loader image. - /// For non-UEFI compatible boots, the timer value logged will be just prior - /// to the INT 19h handler invocation. - /// - UINT64 OsLoaderStartImageStart; - /// - /// Timer value logged at the point when the OS loader calls the - /// ExitBootServices function for UEFI compatible firmware. - /// For non-UEFI compatible boots, this field must be zero. - /// - UINT64 ExitBootServicesEntry; - /// - /// Timer value logged at the point just prior towhen the OS loader gaining - /// control back from calls the ExitBootServices function for UEFI compatible firmware. - /// For non-UEFI compatible boots, this field must be zero. - /// - UINT64 ExitBootServicesExit; -} EFI_ACPI_6_0_FPDT_FIRMWARE_BASIC_BOOT_RECORD; - -/// -/// FPDT Firmware Basic Boot Performance Table signature -/// -#define EFI_ACPI_6_0_FPDT_BOOT_PERFORMANCE_TABLE_SIGNATURE SIGNATURE_32('F', 'B', 'P', 'T') - -// -// FPDT Firmware Basic Boot Performance Table -// -typedef struct { - EFI_ACPI_6_0_FPDT_PERFORMANCE_TABLE_HEADER Header; - // - // one or more Performance Records. - // -} EFI_ACPI_6_0_FPDT_FIRMWARE_BASIC_BOOT_TABLE; - -/// -/// FPDT "S3PT" S3 Performance Table -/// -#define EFI_ACPI_6_0_FPDT_S3_PERFORMANCE_TABLE_SIGNATURE SIGNATURE_32('S', '3', 'P', 'T') - -// -// FPDT Firmware S3 Boot Performance Table -// -typedef struct { - EFI_ACPI_6_0_FPDT_PERFORMANCE_TABLE_HEADER Header; - // - // one or more Performance Records. - // -} EFI_ACPI_6_0_FPDT_FIRMWARE_S3_BOOT_TABLE; - -/// -/// FPDT Basic S3 Resume Performance Record -/// -typedef struct { - EFI_ACPI_6_0_FPDT_PERFORMANCE_RECORD_HEADER Header; - /// - /// A count of the number of S3 resume cycles since the last full boot sequence. - /// - UINT32 ResumeCount; - /// - /// Timer recorded at the end of BIOS S3 resume, just prior to handoff to the - /// OS waking vector. Only the most recent resume cycle's time is retained. - /// - UINT64 FullResume; - /// - /// Average timer value of all resume cycles logged since the last full boot - /// sequence, including the most recent resume. Note that the entire log of - /// timer values does not need to be retained in order to calculate this average. - /// - UINT64 AverageResume; -} EFI_ACPI_6_0_FPDT_S3_RESUME_RECORD; - -/// -/// FPDT Basic S3 Suspend Performance Record -/// -typedef struct { - EFI_ACPI_6_0_FPDT_PERFORMANCE_RECORD_HEADER Header; - /// - /// Timer value recorded at the OS write to SLP_TYP upon entry to S3. - /// Only the most recent suspend cycle's timer value is retained. - /// - UINT64 SuspendStart; - /// - /// Timer value recorded at the final firmware write to SLP_TYP (or other - /// mechanism) used to trigger hardware entry to S3. - /// Only the most recent suspend cycle's timer value is retained. - /// - UINT64 SuspendEnd; -} EFI_ACPI_6_0_FPDT_S3_SUSPEND_RECORD; - -/// -/// Firmware Performance Record Table definition. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; -} EFI_ACPI_6_0_FIRMWARE_PERFORMANCE_RECORD_TABLE; - -/// -/// Generic Timer Description Table definition. -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT64 CntControlBasePhysicalAddress; - UINT32 Reserved; - UINT32 SecurePL1TimerGSIV; - UINT32 SecurePL1TimerFlags; - UINT32 NonSecurePL1TimerGSIV; - UINT32 NonSecurePL1TimerFlags; - UINT32 VirtualTimerGSIV; - UINT32 VirtualTimerFlags; - UINT32 NonSecurePL2TimerGSIV; - UINT32 NonSecurePL2TimerFlags; - UINT64 CntReadBasePhysicalAddress; - UINT32 PlatformTimerCount; - UINT32 PlatformTimerOffset; -} EFI_ACPI_6_0_GENERIC_TIMER_DESCRIPTION_TABLE; - -/// -/// GTDT Version (as defined in ACPI 6.0 spec.) -/// -#define EFI_ACPI_6_0_GENERIC_TIMER_DESCRIPTION_TABLE_REVISION 0x02 - -/// -/// Timer Flags. All other bits are reserved and must be 0. -/// -#define EFI_ACPI_6_0_GTDT_TIMER_FLAG_TIMER_INTERRUPT_MODE BIT0 -#define EFI_ACPI_6_0_GTDT_TIMER_FLAG_TIMER_INTERRUPT_POLARITY BIT1 -#define EFI_ACPI_6_0_GTDT_TIMER_FLAG_ALWAYS_ON_CAPABILITY BIT2 - -/// -/// Platform Timer Type -/// -#define EFI_ACPI_6_0_GTDT_GT_BLOCK 0 -#define EFI_ACPI_6_0_GTDT_SBSA_GENERIC_WATCHDOG 1 - -/// -/// GT Block Structure -/// -typedef struct { - UINT8 Type; - UINT16 Length; - UINT8 Reserved; - UINT64 CntCtlBase; - UINT32 GTBlockTimerCount; - UINT32 GTBlockTimerOffset; -} EFI_ACPI_6_0_GTDT_GT_BLOCK_STRUCTURE; - -/// -/// GT Block Timer Structure -/// -typedef struct { - UINT8 GTFrameNumber; - UINT8 Reserved[3]; - UINT64 CntBaseX; - UINT64 CntEL0BaseX; - UINT32 GTxPhysicalTimerGSIV; - UINT32 GTxPhysicalTimerFlags; - UINT32 GTxVirtualTimerGSIV; - UINT32 GTxVirtualTimerFlags; - UINT32 GTxCommonFlags; -} EFI_ACPI_6_0_GTDT_GT_BLOCK_TIMER_STRUCTURE; - -/// -/// GT Block Physical Timers and Virtual Timers Flags. All other bits are reserved and must be 0. -/// -#define EFI_ACPI_6_0_GTDT_GT_BLOCK_TIMER_FLAG_TIMER_INTERRUPT_MODE BIT0 -#define EFI_ACPI_6_0_GTDT_GT_BLOCK_TIMER_FLAG_TIMER_INTERRUPT_POLARITY BIT1 - -/// -/// Common Flags Flags. All other bits are reserved and must be 0. -/// -#define EFI_ACPI_6_0_GTDT_GT_BLOCK_COMMON_FLAG_SECURE_TIMER BIT0 -#define EFI_ACPI_6_0_GTDT_GT_BLOCK_COMMON_FLAG_ALWAYS_ON_CAPABILITY BIT1 - -/// -/// SBSA Generic Watchdog Structure -/// -typedef struct { - UINT8 Type; - UINT16 Length; - UINT8 Reserved; - UINT64 RefreshFramePhysicalAddress; - UINT64 WatchdogControlFramePhysicalAddress; - UINT32 WatchdogTimerGSIV; - UINT32 WatchdogTimerFlags; -} EFI_ACPI_6_0_GTDT_SBSA_GENERIC_WATCHDOG_STRUCTURE; - -/// -/// SBSA Generic Watchdog Timer Flags. All other bits are reserved and must be 0. -/// -#define EFI_ACPI_6_0_GTDT_SBSA_GENERIC_WATCHDOG_FLAG_TIMER_INTERRUPT_MODE BIT0 -#define EFI_ACPI_6_0_GTDT_SBSA_GENERIC_WATCHDOG_FLAG_TIMER_INTERRUPT_POLARITY BIT1 -#define EFI_ACPI_6_0_GTDT_SBSA_GENERIC_WATCHDOG_FLAG_SECURE_TIMER BIT2 - -// -// NVDIMM Firmware Interface Table definition. -// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 Reserved; -} EFI_ACPI_6_0_NVDIMM_FIRMWARE_INTERFACE_TABLE; - -// -// NFIT Version (as defined in ACPI 6.0 spec.) -// -#define EFI_ACPI_6_0_NVDIMM_FIRMWARE_INTERFACE_TABLE_REVISION 0x1 - -// -// Definition for NFIT Table Structure Types -// -#define EFI_ACPI_6_0_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE_TYPE 0 -#define EFI_ACPI_6_0_NFIT_MEMORY_DEVICE_TO_SYSTEM_ADDRESS_RANGE_MAP_STRUCTURE_TYPE 1 -#define EFI_ACPI_6_0_NFIT_INTERLEAVE_STRUCTURE_TYPE 2 -#define EFI_ACPI_6_0_NFIT_SMBIOS_MANAGEMENT_INFORMATION_STRUCTURE_TYPE 3 -#define EFI_ACPI_6_0_NFIT_NVDIMM_CONTROL_REGION_STRUCTURE_TYPE 4 -#define EFI_ACPI_6_0_NFIT_NVDIMM_BLOCK_DATA_WINDOW_REGION_STRUCTURE_TYPE 5 -#define EFI_ACPI_6_0_NFIT_FLUSH_HINT_ADDRESS_STRUCTURE_TYPE 6 - -// -// Definition for NFIT Structure Header -// -typedef struct { - UINT16 Type; - UINT16 Length; -} EFI_ACPI_6_0_NFIT_STRUCTURE_HEADER; - -// -// Definition for System Physical Address Range Structure -// -#define EFI_ACPI_6_0_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_FLAGS_CONTROL_REGION_FOR_MANAGEMENT BIT0 -#define EFI_ACPI_6_0_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_FLAGS_PROXIMITY_DOMAIN_VALID BIT1 -#define EFI_ACPI_6_0_NFIT_GUID_VOLATILE_MEMORY_REGION { 0x7305944F, 0xFDDA, 0x44E3, { 0xB1, 0x6C, 0x3F, 0x22, 0xD2, 0x52, 0xE5, 0xD0 }} -#define EFI_ACPI_6_0_NFIT_GUID_BYTE_ADDRESSABLE_PERSISTENT_MEMORY_REGION { 0x66F0D379, 0xB4F3, 0x4074, { 0xAC, 0x43, 0x0D, 0x33, 0x18, 0xB7, 0x8C, 0xDB }} -#define EFI_ACPI_6_0_NFIT_GUID_NVDIMM_CONTROL_REGION { 0x92F701F6, 0x13B4, 0x405D, { 0x91, 0x0B, 0x29, 0x93, 0x67, 0xE8, 0x23, 0x4C }} -#define EFI_ACPI_6_0_NFIT_GUID_NVDIMM_BLOCK_DATA_WINDOW_REGION { 0x91AF0530, 0x5D86, 0x470E, { 0xA6, 0xB0, 0x0A, 0x2D, 0xB9, 0x40, 0x82, 0x49 }} -#define EFI_ACPI_6_0_NFIT_GUID_RAM_DISK_SUPPORTING_VIRTUAL_DISK_REGION_VOLATILE { 0x77AB535A, 0x45FC, 0x624B, { 0x55, 0x60, 0xF7, 0xB2, 0x81, 0xD1, 0xF9, 0x6E }} -#define EFI_ACPI_6_0_NFIT_GUID_RAM_DISK_SUPPORTING_VIRTUAL_CD_REGION_VOLATILE { 0x3D5ABD30, 0x4175, 0x87CE, { 0x6D, 0x64, 0xD2, 0xAD, 0xE5, 0x23, 0xC4, 0xBB }} -#define EFI_ACPI_6_0_NFIT_GUID_RAM_DISK_SUPPORTING_VIRTUAL_DISK_REGION_PERSISTENT { 0x5CEA02C9, 0x4D07, 0x69D3, { 0x26, 0x9F ,0x44, 0x96, 0xFB, 0xE0, 0x96, 0xF9 }} -#define EFI_ACPI_6_0_NFIT_GUID_RAM_DISK_SUPPORTING_VIRTUAL_CD_REGION_PERSISTENT { 0x08018188, 0x42CD, 0xBB48, { 0x10, 0x0F, 0x53, 0x87, 0xD5, 0x3D, 0xED, 0x3D }} -typedef struct { - UINT16 Type; - UINT16 Length; - UINT16 SPARangeStructureIndex; - UINT16 Flags; - UINT32 Reserved_8; - UINT32 ProximityDomain; - GUID AddressRangeTypeGUID; - UINT64 SystemPhysicalAddressRangeBase; - UINT64 SystemPhysicalAddressRangeLength; - UINT64 AddressRangeMemoryMappingAttribute; -} EFI_ACPI_6_0_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE; - -// -// Definition for Memory Device to System Physical Address Range Mapping Structure -// -typedef struct { - UINT32 DIMMNumber:4; - UINT32 MemoryChannelNumber:4; - UINT32 MemoryControllerID:4; - UINT32 SocketID:4; - UINT32 NodeControllerID:12; - UINT32 Reserved_28:4; -} EFI_ACPI_6_0_NFIT_DEVICE_HANDLE; - -#define EFI_ACPI_6_0_NFIT_MEMORY_DEVICE_STATE_FLAGS_PREVIOUS_SAVE_FAIL BIT0 -#define EFI_ACPI_6_0_NFIT_MEMORY_DEVICE_STATE_FLAGS_LAST_RESTORE_FAIL BIT1 -#define EFI_ACPI_6_0_NFIT_MEMORY_DEVICE_STATE_FLAGS_PLATFORM_FLUSH_FAIL BIT2 -#define EFI_ACPI_6_0_NFIT_MEMORY_DEVICE_STATE_FLAGS_NOT_ARMED_PRIOR_TO_OSPM_HAND_OFF BIT3 -#define EFI_ACPI_6_0_NFIT_MEMORY_DEVICE_STATE_FLAGS_SMART_HEALTH_EVENTS_PRIOR_OSPM_HAND_OFF BIT4 -#define EFI_ACPI_6_0_NFIT_MEMORY_DEVICE_STATE_FLAGS_FIRMWARE_ENABLED_TO_NOTIFY_OSPM_ON_SMART_HEALTH_EVENTS BIT5 -typedef struct { - UINT16 Type; - UINT16 Length; - EFI_ACPI_6_0_NFIT_DEVICE_HANDLE NFITDeviceHandle; - UINT16 MemoryDevicePhysicalID; - UINT16 MemoryDeviceRegionID; - UINT16 SPARangeStructureIndex ; - UINT16 NVDIMMControlRegionStructureIndex; - UINT64 MemoryDeviceRegionSize; - UINT64 RegionOffset; - UINT64 MemoryDevicePhysicalAddressRegionBase; - UINT16 InterleaveStructureIndex; - UINT16 InterleaveWays; - UINT16 MemoryDeviceStateFlags; - UINT16 Reserved_46; -} EFI_ACPI_6_0_NFIT_MEMORY_DEVICE_TO_SYSTEM_ADDRESS_RANGE_MAP_STRUCTURE; - -// -// Definition for Interleave Structure -// -typedef struct { - UINT16 Type; - UINT16 Length; - UINT16 InterleaveStructureIndex; - UINT16 Reserved_6; - UINT32 NumberOfLines; - UINT32 LineSize; -//UINT32 LineOffset[NumberOfLines]; -} EFI_ACPI_6_0_NFIT_INTERLEAVE_STRUCTURE; - -// -// Definition for SMBIOS Management Information Structure -// -typedef struct { - UINT16 Type; - UINT16 Length; - UINT32 Reserved_4; -//UINT8 Data[]; -} EFI_ACPI_6_0_NFIT_SMBIOS_MANAGEMENT_INFORMATION_STRUCTURE; - -// -// Definition for NVDIMM Control Region Structure -// -#define EFI_ACPI_6_0_NFIT_NVDIMM_CONTROL_REGION_FLAGS_BLOCK_DATA_WINDOWS_BUFFERED BIT0 -typedef struct { - UINT16 Type; - UINT16 Length; - UINT16 NVDIMMControlRegionStructureIndex; - UINT16 VendorID; - UINT16 DeviceID; - UINT16 RevisionID; - UINT16 SubsystemVendorID; - UINT16 SubsystemDeviceID; - UINT16 SubsystemRevisionID; - UINT8 Reserved_18[6]; - UINT32 SerialNumber; - UINT16 RegionFormatInterfaceCode; - UINT16 NumberOfBlockControlWindows; - UINT64 SizeOfBlockControlWindow; - UINT64 CommandRegisterOffsetInBlockControlWindow; - UINT64 SizeOfCommandRegisterInBlockControlWindows; - UINT64 StatusRegisterOffsetInBlockControlWindow; - UINT64 SizeOfStatusRegisterInBlockControlWindows; - UINT16 NVDIMMControlRegionFlag; - UINT8 Reserved_74[6]; -} EFI_ACPI_6_0_NFIT_NVDIMM_CONTROL_REGION_STRUCTURE; - -// -// Definition for NVDIMM Block Data Window Region Structure -// -typedef struct { - UINT16 Type; - UINT16 Length; - UINT16 NVDIMMControlRegionStructureIndex; - UINT16 NumberOfBlockDataWindows; - UINT64 BlockDataWindowStartOffset; - UINT64 SizeOfBlockDataWindow; - UINT64 BlockAccessibleMemoryCapacity; - UINT64 BeginningAddressOfFirstBlockInBlockAccessibleMemory; -} EFI_ACPI_6_0_NFIT_NVDIMM_BLOCK_DATA_WINDOW_REGION_STRUCTURE; - -// -// Definition for Flush Hint Address Structure -// -typedef struct { - UINT16 Type; - UINT16 Length; - EFI_ACPI_6_0_NFIT_DEVICE_HANDLE NFITDeviceHandle; - UINT16 NumberOfFlushHintAddresses; - UINT8 Reserved_10[6]; -//UINT64 FlushHintAddress[NumberOfFlushHintAddresses]; -} EFI_ACPI_6_0_NFIT_FLUSH_HINT_ADDRESS_STRUCTURE; - -/// -/// Boot Error Record Table (BERT) -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 BootErrorRegionLength; - UINT64 BootErrorRegion; -} EFI_ACPI_6_0_BOOT_ERROR_RECORD_TABLE_HEADER; - -/// -/// BERT Version (as defined in ACPI 6.0 spec.) -/// -#define EFI_ACPI_6_0_BOOT_ERROR_RECORD_TABLE_REVISION 0x01 - -/// -/// Boot Error Region Block Status Definition -/// -typedef struct { - UINT32 UncorrectableErrorValid:1; - UINT32 CorrectableErrorValid:1; - UINT32 MultipleUncorrectableErrors:1; - UINT32 MultipleCorrectableErrors:1; - UINT32 ErrorDataEntryCount:10; - UINT32 Reserved:18; -} EFI_ACPI_6_0_ERROR_BLOCK_STATUS; - -/// -/// Boot Error Region Definition -/// -typedef struct { - EFI_ACPI_6_0_ERROR_BLOCK_STATUS BlockStatus; - UINT32 RawDataOffset; - UINT32 RawDataLength; - UINT32 DataLength; - UINT32 ErrorSeverity; -} EFI_ACPI_6_0_BOOT_ERROR_REGION_STRUCTURE; - -// -// Boot Error Severity types -// -#define EFI_ACPI_6_0_ERROR_SEVERITY_CORRECTABLE 0x00 -#define EFI_ACPI_6_0_ERROR_SEVERITY_FATAL 0x01 -#define EFI_ACPI_6_0_ERROR_SEVERITY_CORRECTED 0x02 -#define EFI_ACPI_6_0_ERROR_SEVERITY_NONE 0x03 - -/// -/// Generic Error Data Entry Definition -/// -typedef struct { - UINT8 SectionType[16]; - UINT32 ErrorSeverity; - UINT16 Revision; - UINT8 ValidationBits; - UINT8 Flags; - UINT32 ErrorDataLength; - UINT8 FruId[16]; - UINT8 FruText[20]; -} EFI_ACPI_6_0_GENERIC_ERROR_DATA_ENTRY_STRUCTURE; - -/// -/// Generic Error Data Entry Version (as defined in ACPI 6.0 spec.) -/// -#define EFI_ACPI_6_0_GENERIC_ERROR_DATA_ENTRY_REVISION 0x0201 - -/// -/// HEST - Hardware Error Source Table -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 ErrorSourceCount; -} EFI_ACPI_6_0_HARDWARE_ERROR_SOURCE_TABLE_HEADER; - -/// -/// HEST Version (as defined in ACPI 6.0 spec.) -/// -#define EFI_ACPI_6_0_HARDWARE_ERROR_SOURCE_TABLE_REVISION 0x01 - -// -// Error Source structure types. -// -#define EFI_ACPI_6_0_IA32_ARCHITECTURE_MACHINE_CHECK_EXCEPTION 0x00 -#define EFI_ACPI_6_0_IA32_ARCHITECTURE_CORRECTED_MACHINE_CHECK 0x01 -#define EFI_ACPI_6_0_IA32_ARCHITECTURE_NMI_ERROR 0x02 -#define EFI_ACPI_6_0_PCI_EXPRESS_ROOT_PORT_AER 0x06 -#define EFI_ACPI_6_0_PCI_EXPRESS_DEVICE_AER 0x07 -#define EFI_ACPI_6_0_PCI_EXPRESS_BRIDGE_AER 0x08 -#define EFI_ACPI_6_0_GENERIC_HARDWARE_ERROR 0x09 - -// -// Error Source structure flags. -// -#define EFI_ACPI_6_0_ERROR_SOURCE_FLAG_FIRMWARE_FIRST (1 << 0) -#define EFI_ACPI_6_0_ERROR_SOURCE_FLAG_GLOBAL (1 << 1) - -/// -/// IA-32 Architecture Machine Check Exception Structure Definition -/// -typedef struct { - UINT16 Type; - UINT16 SourceId; - UINT8 Reserved0[2]; - UINT8 Flags; - UINT8 Enabled; - UINT32 NumberOfRecordsToPreAllocate; - UINT32 MaxSectionsPerRecord; - UINT64 GlobalCapabilityInitData; - UINT64 GlobalControlInitData; - UINT8 NumberOfHardwareBanks; - UINT8 Reserved1[7]; -} EFI_ACPI_6_0_IA32_ARCHITECTURE_MACHINE_CHECK_EXCEPTION_STRUCTURE; - -/// -/// IA-32 Architecture Machine Check Bank Structure Definition -/// -typedef struct { - UINT8 BankNumber; - UINT8 ClearStatusOnInitialization; - UINT8 StatusDataFormat; - UINT8 Reserved0; - UINT32 ControlRegisterMsrAddress; - UINT64 ControlInitData; - UINT32 StatusRegisterMsrAddress; - UINT32 AddressRegisterMsrAddress; - UINT32 MiscRegisterMsrAddress; -} EFI_ACPI_6_0_IA32_ARCHITECTURE_MACHINE_CHECK_ERROR_BANK_STRUCTURE; - -/// -/// IA-32 Architecture Machine Check Bank Structure MCA data format -/// -#define EFI_ACPI_6_0_IA32_ARCHITECTURE_MACHINE_CHECK_ERROR_DATA_FORMAT_IA32 0x00 -#define EFI_ACPI_6_0_IA32_ARCHITECTURE_MACHINE_CHECK_ERROR_DATA_FORMAT_INTEL64 0x01 -#define EFI_ACPI_6_0_IA32_ARCHITECTURE_MACHINE_CHECK_ERROR_DATA_FORMAT_AMD64 0x02 - -// -// Hardware Error Notification types. All other values are reserved -// -#define EFI_ACPI_6_0_HARDWARE_ERROR_NOTIFICATION_POLLED 0x00 -#define EFI_ACPI_6_0_HARDWARE_ERROR_NOTIFICATION_EXTERNAL_INTERRUPT 0x01 -#define EFI_ACPI_6_0_HARDWARE_ERROR_NOTIFICATION_LOCAL_INTERRUPT 0x02 -#define EFI_ACPI_6_0_HARDWARE_ERROR_NOTIFICATION_SCI 0x03 -#define EFI_ACPI_6_0_HARDWARE_ERROR_NOTIFICATION_NMI 0x04 -#define EFI_ACPI_6_0_HARDWARE_ERROR_NOTIFICATION_CMCI 0x05 -#define EFI_ACPI_6_0_HARDWARE_ERROR_NOTIFICATION_MCE 0x06 -#define EFI_ACPI_6_0_HARDWARE_ERROR_NOTIFICATION_GPIO_SIGNAL 0x07 - -/// -/// Hardware Error Notification Configuration Write Enable Structure Definition -/// -typedef struct { - UINT16 Type:1; - UINT16 PollInterval:1; - UINT16 SwitchToPollingThresholdValue:1; - UINT16 SwitchToPollingThresholdWindow:1; - UINT16 ErrorThresholdValue:1; - UINT16 ErrorThresholdWindow:1; - UINT16 Reserved:10; -} EFI_ACPI_6_0_HARDWARE_ERROR_NOTIFICATION_CONFIGURATION_WRITE_ENABLE_STRUCTURE; - -/// -/// Hardware Error Notification Structure Definition -/// -typedef struct { - UINT8 Type; - UINT8 Length; - EFI_ACPI_6_0_HARDWARE_ERROR_NOTIFICATION_CONFIGURATION_WRITE_ENABLE_STRUCTURE ConfigurationWriteEnable; - UINT32 PollInterval; - UINT32 Vector; - UINT32 SwitchToPollingThresholdValue; - UINT32 SwitchToPollingThresholdWindow; - UINT32 ErrorThresholdValue; - UINT32 ErrorThresholdWindow; -} EFI_ACPI_6_0_HARDWARE_ERROR_NOTIFICATION_STRUCTURE; - -/// -/// IA-32 Architecture Corrected Machine Check Structure Definition -/// -typedef struct { - UINT16 Type; - UINT16 SourceId; - UINT8 Reserved0[2]; - UINT8 Flags; - UINT8 Enabled; - UINT32 NumberOfRecordsToPreAllocate; - UINT32 MaxSectionsPerRecord; - EFI_ACPI_6_0_HARDWARE_ERROR_NOTIFICATION_STRUCTURE NotificationStructure; - UINT8 NumberOfHardwareBanks; - UINT8 Reserved1[3]; -} EFI_ACPI_6_0_IA32_ARCHITECTURE_CORRECTED_MACHINE_CHECK_STRUCTURE; - -/// -/// IA-32 Architecture NMI Error Structure Definition -/// -typedef struct { - UINT16 Type; - UINT16 SourceId; - UINT8 Reserved0[2]; - UINT32 NumberOfRecordsToPreAllocate; - UINT32 MaxSectionsPerRecord; - UINT32 MaxRawDataLength; -} EFI_ACPI_6_0_IA32_ARCHITECTURE_NMI_ERROR_STRUCTURE; - -/// -/// PCI Express Root Port AER Structure Definition -/// -typedef struct { - UINT16 Type; - UINT16 SourceId; - UINT8 Reserved0[2]; - UINT8 Flags; - UINT8 Enabled; - UINT32 NumberOfRecordsToPreAllocate; - UINT32 MaxSectionsPerRecord; - UINT32 Bus; - UINT16 Device; - UINT16 Function; - UINT16 DeviceControl; - UINT8 Reserved1[2]; - UINT32 UncorrectableErrorMask; - UINT32 UncorrectableErrorSeverity; - UINT32 CorrectableErrorMask; - UINT32 AdvancedErrorCapabilitiesAndControl; - UINT32 RootErrorCommand; -} EFI_ACPI_6_0_PCI_EXPRESS_ROOT_PORT_AER_STRUCTURE; - -/// -/// PCI Express Device AER Structure Definition -/// -typedef struct { - UINT16 Type; - UINT16 SourceId; - UINT8 Reserved0[2]; - UINT8 Flags; - UINT8 Enabled; - UINT32 NumberOfRecordsToPreAllocate; - UINT32 MaxSectionsPerRecord; - UINT32 Bus; - UINT16 Device; - UINT16 Function; - UINT16 DeviceControl; - UINT8 Reserved1[2]; - UINT32 UncorrectableErrorMask; - UINT32 UncorrectableErrorSeverity; - UINT32 CorrectableErrorMask; - UINT32 AdvancedErrorCapabilitiesAndControl; -} EFI_ACPI_6_0_PCI_EXPRESS_DEVICE_AER_STRUCTURE; - -/// -/// PCI Express Bridge AER Structure Definition -/// -typedef struct { - UINT16 Type; - UINT16 SourceId; - UINT8 Reserved0[2]; - UINT8 Flags; - UINT8 Enabled; - UINT32 NumberOfRecordsToPreAllocate; - UINT32 MaxSectionsPerRecord; - UINT32 Bus; - UINT16 Device; - UINT16 Function; - UINT16 DeviceControl; - UINT8 Reserved1[2]; - UINT32 UncorrectableErrorMask; - UINT32 UncorrectableErrorSeverity; - UINT32 CorrectableErrorMask; - UINT32 AdvancedErrorCapabilitiesAndControl; - UINT32 SecondaryUncorrectableErrorMask; - UINT32 SecondaryUncorrectableErrorSeverity; - UINT32 SecondaryAdvancedErrorCapabilitiesAndControl; -} EFI_ACPI_6_0_PCI_EXPRESS_BRIDGE_AER_STRUCTURE; - -/// -/// Generic Hardware Error Source Structure Definition -/// -typedef struct { - UINT16 Type; - UINT16 SourceId; - UINT16 RelatedSourceId; - UINT8 Flags; - UINT8 Enabled; - UINT32 NumberOfRecordsToPreAllocate; - UINT32 MaxSectionsPerRecord; - UINT32 MaxRawDataLength; - EFI_ACPI_6_0_GENERIC_ADDRESS_STRUCTURE ErrorStatusAddress; - EFI_ACPI_6_0_HARDWARE_ERROR_NOTIFICATION_STRUCTURE NotificationStructure; - UINT32 ErrorStatusBlockLength; -} EFI_ACPI_6_0_GENERIC_HARDWARE_ERROR_SOURCE_STRUCTURE; - -/// -/// Generic Error Status Definition -/// -typedef struct { - EFI_ACPI_6_0_ERROR_BLOCK_STATUS BlockStatus; - UINT32 RawDataOffset; - UINT32 RawDataLength; - UINT32 DataLength; - UINT32 ErrorSeverity; -} EFI_ACPI_6_0_GENERIC_ERROR_STATUS_STRUCTURE; - -/// -/// ERST - Error Record Serialization Table -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 SerializationHeaderSize; - UINT8 Reserved0[4]; - UINT32 InstructionEntryCount; -} EFI_ACPI_6_0_ERROR_RECORD_SERIALIZATION_TABLE_HEADER; - -/// -/// ERST Version (as defined in ACPI 6.0 spec.) -/// -#define EFI_ACPI_6_0_ERROR_RECORD_SERIALIZATION_TABLE_REVISION 0x01 - -/// -/// ERST Serialization Actions -/// -#define EFI_ACPI_6_0_ERST_BEGIN_WRITE_OPERATION 0x00 -#define EFI_ACPI_6_0_ERST_BEGIN_READ_OPERATION 0x01 -#define EFI_ACPI_6_0_ERST_BEGIN_CLEAR_OPERATION 0x02 -#define EFI_ACPI_6_0_ERST_END_OPERATION 0x03 -#define EFI_ACPI_6_0_ERST_SET_RECORD_OFFSET 0x04 -#define EFI_ACPI_6_0_ERST_EXECUTE_OPERATION 0x05 -#define EFI_ACPI_6_0_ERST_CHECK_BUSY_STATUS 0x06 -#define EFI_ACPI_6_0_ERST_GET_COMMAND_STATUS 0x07 -#define EFI_ACPI_6_0_ERST_GET_RECORD_IDENTIFIER 0x08 -#define EFI_ACPI_6_0_ERST_SET_RECORD_IDENTIFIER 0x09 -#define EFI_ACPI_6_0_ERST_GET_RECORD_COUNT 0x0A -#define EFI_ACPI_6_0_ERST_BEGIN_DUMMY_WRITE_OPERATION 0x0B -#define EFI_ACPI_6_0_ERST_GET_ERROR_LOG_ADDRESS_RANGE 0x0D -#define EFI_ACPI_6_0_ERST_GET_ERROR_LOG_ADDRESS_RANGE_LENGTH 0x0E -#define EFI_ACPI_6_0_ERST_GET_ERROR_LOG_ADDRESS_RANGE_ATTRIBUTES 0x0F - -/// -/// ERST Action Command Status -/// -#define EFI_ACPI_6_0_ERST_STATUS_SUCCESS 0x00 -#define EFI_ACPI_6_0_ERST_STATUS_NOT_ENOUGH_SPACE 0x01 -#define EFI_ACPI_6_0_ERST_STATUS_HARDWARE_NOT_AVAILABLE 0x02 -#define EFI_ACPI_6_0_ERST_STATUS_FAILED 0x03 -#define EFI_ACPI_6_0_ERST_STATUS_RECORD_STORE_EMPTY 0x04 -#define EFI_ACPI_6_0_ERST_STATUS_RECORD_NOT_FOUND 0x05 - -/// -/// ERST Serialization Instructions -/// -#define EFI_ACPI_6_0_ERST_READ_REGISTER 0x00 -#define EFI_ACPI_6_0_ERST_READ_REGISTER_VALUE 0x01 -#define EFI_ACPI_6_0_ERST_WRITE_REGISTER 0x02 -#define EFI_ACPI_6_0_ERST_WRITE_REGISTER_VALUE 0x03 -#define EFI_ACPI_6_0_ERST_NOOP 0x04 -#define EFI_ACPI_6_0_ERST_LOAD_VAR1 0x05 -#define EFI_ACPI_6_0_ERST_LOAD_VAR2 0x06 -#define EFI_ACPI_6_0_ERST_STORE_VAR1 0x07 -#define EFI_ACPI_6_0_ERST_ADD 0x08 -#define EFI_ACPI_6_0_ERST_SUBTRACT 0x09 -#define EFI_ACPI_6_0_ERST_ADD_VALUE 0x0A -#define EFI_ACPI_6_0_ERST_SUBTRACT_VALUE 0x0B -#define EFI_ACPI_6_0_ERST_STALL 0x0C -#define EFI_ACPI_6_0_ERST_STALL_WHILE_TRUE 0x0D -#define EFI_ACPI_6_0_ERST_SKIP_NEXT_INSTRUCTION_IF_TRUE 0x0E -#define EFI_ACPI_6_0_ERST_GOTO 0x0F -#define EFI_ACPI_6_0_ERST_SET_SRC_ADDRESS_BASE 0x10 -#define EFI_ACPI_6_0_ERST_SET_DST_ADDRESS_BASE 0x11 -#define EFI_ACPI_6_0_ERST_MOVE_DATA 0x12 - -/// -/// ERST Instruction Flags -/// -#define EFI_ACPI_6_0_ERST_PRESERVE_REGISTER 0x01 - -/// -/// ERST Serialization Instruction Entry -/// -typedef struct { - UINT8 SerializationAction; - UINT8 Instruction; - UINT8 Flags; - UINT8 Reserved0; - EFI_ACPI_6_0_GENERIC_ADDRESS_STRUCTURE RegisterRegion; - UINT64 Value; - UINT64 Mask; -} EFI_ACPI_6_0_ERST_SERIALIZATION_INSTRUCTION_ENTRY; - -/// -/// EINJ - Error Injection Table -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 InjectionHeaderSize; - UINT8 InjectionFlags; - UINT8 Reserved0[3]; - UINT32 InjectionEntryCount; -} EFI_ACPI_6_0_ERROR_INJECTION_TABLE_HEADER; - -/// -/// EINJ Version (as defined in ACPI 6.0 spec.) -/// -#define EFI_ACPI_6_0_ERROR_INJECTION_TABLE_REVISION 0x01 - -/// -/// EINJ Error Injection Actions -/// -#define EFI_ACPI_6_0_EINJ_BEGIN_INJECTION_OPERATION 0x00 -#define EFI_ACPI_6_0_EINJ_GET_TRIGGER_ERROR_ACTION_TABLE 0x01 -#define EFI_ACPI_6_0_EINJ_SET_ERROR_TYPE 0x02 -#define EFI_ACPI_6_0_EINJ_GET_ERROR_TYPE 0x03 -#define EFI_ACPI_6_0_EINJ_END_OPERATION 0x04 -#define EFI_ACPI_6_0_EINJ_EXECUTE_OPERATION 0x05 -#define EFI_ACPI_6_0_EINJ_CHECK_BUSY_STATUS 0x06 -#define EFI_ACPI_6_0_EINJ_GET_COMMAND_STATUS 0x07 -#define EFI_ACPI_6_0_EINJ_TRIGGER_ERROR 0xFF - -/// -/// EINJ Action Command Status -/// -#define EFI_ACPI_6_0_EINJ_STATUS_SUCCESS 0x00 -#define EFI_ACPI_6_0_EINJ_STATUS_UNKNOWN_FAILURE 0x01 -#define EFI_ACPI_6_0_EINJ_STATUS_INVALID_ACCESS 0x02 - -/// -/// EINJ Error Type Definition -/// -#define EFI_ACPI_6_0_EINJ_ERROR_PROCESSOR_CORRECTABLE (1 << 0) -#define EFI_ACPI_6_0_EINJ_ERROR_PROCESSOR_UNCORRECTABLE_NONFATAL (1 << 1) -#define EFI_ACPI_6_0_EINJ_ERROR_PROCESSOR_UNCORRECTABLE_FATAL (1 << 2) -#define EFI_ACPI_6_0_EINJ_ERROR_MEMORY_CORRECTABLE (1 << 3) -#define EFI_ACPI_6_0_EINJ_ERROR_MEMORY_UNCORRECTABLE_NONFATAL (1 << 4) -#define EFI_ACPI_6_0_EINJ_ERROR_MEMORY_UNCORRECTABLE_FATAL (1 << 5) -#define EFI_ACPI_6_0_EINJ_ERROR_PCI_EXPRESS_CORRECTABLE (1 << 6) -#define EFI_ACPI_6_0_EINJ_ERROR_PCI_EXPRESS_UNCORRECTABLE_NONFATAL (1 << 7) -#define EFI_ACPI_6_0_EINJ_ERROR_PCI_EXPRESS_UNCORRECTABLE_FATAL (1 << 8) -#define EFI_ACPI_6_0_EINJ_ERROR_PLATFORM_CORRECTABLE (1 << 9) -#define EFI_ACPI_6_0_EINJ_ERROR_PLATFORM_UNCORRECTABLE_NONFATAL (1 << 10) -#define EFI_ACPI_6_0_EINJ_ERROR_PLATFORM_UNCORRECTABLE_FATAL (1 << 11) - -/// -/// EINJ Injection Instructions -/// -#define EFI_ACPI_6_0_EINJ_READ_REGISTER 0x00 -#define EFI_ACPI_6_0_EINJ_READ_REGISTER_VALUE 0x01 -#define EFI_ACPI_6_0_EINJ_WRITE_REGISTER 0x02 -#define EFI_ACPI_6_0_EINJ_WRITE_REGISTER_VALUE 0x03 -#define EFI_ACPI_6_0_EINJ_NOOP 0x04 - -/// -/// EINJ Instruction Flags -/// -#define EFI_ACPI_6_0_EINJ_PRESERVE_REGISTER 0x01 - -/// -/// EINJ Injection Instruction Entry -/// -typedef struct { - UINT8 InjectionAction; - UINT8 Instruction; - UINT8 Flags; - UINT8 Reserved0; - EFI_ACPI_6_0_GENERIC_ADDRESS_STRUCTURE RegisterRegion; - UINT64 Value; - UINT64 Mask; -} EFI_ACPI_6_0_EINJ_INJECTION_INSTRUCTION_ENTRY; - -/// -/// EINJ Trigger Action Table -/// -typedef struct { - UINT32 HeaderSize; - UINT32 Revision; - UINT32 TableSize; - UINT32 EntryCount; -} EFI_ACPI_6_0_EINJ_TRIGGER_ACTION_TABLE; - -/// -/// Platform Communications Channel Table (PCCT) -/// -typedef struct { - EFI_ACPI_DESCRIPTION_HEADER Header; - UINT32 Flags; - UINT64 Reserved; -} EFI_ACPI_6_0_PLATFORM_COMMUNICATION_CHANNEL_TABLE_HEADER; - -/// -/// PCCT Version (as defined in ACPI 6.0 spec.) -/// -#define EFI_ACPI_6_0_PLATFORM_COMMUNICATION_CHANNEL_TABLE_REVISION 0x01 - -/// -/// PCCT Global Flags -/// -#define EFI_ACPI_6_0_PCCT_FLAGS_SCI_DOORBELL BIT0 - -// -// PCCT Subspace type -// -#define EFI_ACPI_6_0_PCCT_SUBSPACE_TYPE_GENERIC 0x00 - -/// -/// PCC Subspace Structure Header -/// -typedef struct { - UINT8 Type; - UINT8 Length; -} EFI_ACPI_6_0_PCCT_SUBSPACE_HEADER; - -/// -/// Generic Communications Subspace Structure -/// -typedef struct { - UINT8 Type; - UINT8 Length; - UINT8 Reserved[6]; - UINT64 BaseAddress; - UINT64 AddressLength; - EFI_ACPI_6_0_GENERIC_ADDRESS_STRUCTURE DoorbellRegister; - UINT64 DoorbellPreserve; - UINT64 DoorbellWrite; - UINT32 NominalLatency; - UINT32 MaximumPeriodicAccessRate; - UINT16 MinimumRequestTurnaroundTime; -} EFI_ACPI_6_0_PCCT_SUBSPACE_GENERIC; - -/// -/// Generic Communications Channel Shared Memory Region -/// - -typedef struct { - UINT8 Command; - UINT8 Reserved:7; - UINT8 GenerateSci:1; -} EFI_ACPI_6_0_PCCT_GENERIC_SHARED_MEMORY_REGION_COMMAND; - -typedef struct { - UINT8 CommandComplete:1; - UINT8 SciDoorbell:1; - UINT8 Error:1; - UINT8 PlatformNotification:1; - UINT8 Reserved:4; - UINT8 Reserved1; -} EFI_ACPI_6_0_PCCT_GENERIC_SHARED_MEMORY_REGION_STATUS; - -typedef struct { - UINT32 Signature; - EFI_ACPI_6_0_PCCT_GENERIC_SHARED_MEMORY_REGION_COMMAND Command; - EFI_ACPI_6_0_PCCT_GENERIC_SHARED_MEMORY_REGION_STATUS Status; -} EFI_ACPI_6_0_PCCT_GENERIC_SHARED_MEMORY_REGION_HEADER; - -// -// Known table signatures -// - -/// -/// "RSD PTR " Root System Description Pointer -/// -#define EFI_ACPI_6_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE SIGNATURE_64('R', 'S', 'D', ' ', 'P', 'T', 'R', ' ') - -/// -/// "APIC" Multiple APIC Description Table -/// -#define EFI_ACPI_6_0_MULTIPLE_APIC_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('A', 'P', 'I', 'C') - -/// -/// "BERT" Boot Error Record Table -/// -#define EFI_ACPI_6_0_BOOT_ERROR_RECORD_TABLE_SIGNATURE SIGNATURE_32('B', 'E', 'R', 'T') - -/// -/// "BGRT" Boot Graphics Resource Table -/// -#define EFI_ACPI_6_0_BOOT_GRAPHICS_RESOURCE_TABLE_SIGNATURE SIGNATURE_32('B', 'G', 'R', 'T') - -/// -/// "CPEP" Corrected Platform Error Polling Table -/// -#define EFI_ACPI_6_0_CORRECTED_PLATFORM_ERROR_POLLING_TABLE_SIGNATURE SIGNATURE_32('C', 'P', 'E', 'P') - -/// -/// "DSDT" Differentiated System Description Table -/// -#define EFI_ACPI_6_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('D', 'S', 'D', 'T') - -/// -/// "ECDT" Embedded Controller Boot Resources Table -/// -#define EFI_ACPI_6_0_EMBEDDED_CONTROLLER_BOOT_RESOURCES_TABLE_SIGNATURE SIGNATURE_32('E', 'C', 'D', 'T') - -/// -/// "EINJ" Error Injection Table -/// -#define EFI_ACPI_6_0_ERROR_INJECTION_TABLE_SIGNATURE SIGNATURE_32('E', 'I', 'N', 'J') - -/// -/// "ERST" Error Record Serialization Table -/// -#define EFI_ACPI_6_0_ERROR_RECORD_SERIALIZATION_TABLE_SIGNATURE SIGNATURE_32('E', 'R', 'S', 'T') - -/// -/// "FACP" Fixed ACPI Description Table -/// -#define EFI_ACPI_6_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('F', 'A', 'C', 'P') - -/// -/// "FACS" Firmware ACPI Control Structure -/// -#define EFI_ACPI_6_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE SIGNATURE_32('F', 'A', 'C', 'S') - -/// -/// "FPDT" Firmware Performance Data Table -/// -#define EFI_ACPI_6_0_FIRMWARE_PERFORMANCE_DATA_TABLE_SIGNATURE SIGNATURE_32('F', 'P', 'D', 'T') - -/// -/// "GTDT" Generic Timer Description Table -/// -#define EFI_ACPI_6_0_GENERIC_TIMER_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('G', 'T', 'D', 'T') - -/// -/// "HEST" Hardware Error Source Table -/// -#define EFI_ACPI_6_0_HARDWARE_ERROR_SOURCE_TABLE_SIGNATURE SIGNATURE_32('H', 'E', 'S', 'T') - -/// -/// "MPST" Memory Power State Table -/// -#define EFI_ACPI_6_0_MEMORY_POWER_STATE_TABLE_SIGNATURE SIGNATURE_32('M', 'P', 'S', 'T') - -/// -/// "MSCT" Maximum System Characteristics Table -/// -#define EFI_ACPI_6_0_MAXIMUM_SYSTEM_CHARACTERISTICS_TABLE_SIGNATURE SIGNATURE_32('M', 'S', 'C', 'T') - -/// -/// "NFIT" NVDIMM Firmware Interface Table -/// -#define EFI_ACPI_6_0_NVDIMM_FIRMWARE_INTERFACE_TABLE_STRUCTURE_SIGNATURE SIGNATURE_32('N', 'F', 'I', 'T') - -/// -/// "PMTT" Platform Memory Topology Table -/// -#define EFI_ACPI_6_0_PLATFORM_MEMORY_TOPOLOGY_TABLE_SIGNATURE SIGNATURE_32('P', 'M', 'T', 'T') - -/// -/// "PSDT" Persistent System Description Table -/// -#define EFI_ACPI_6_0_PERSISTENT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('P', 'S', 'D', 'T') - -/// -/// "RASF" ACPI RAS Feature Table -/// -#define EFI_ACPI_6_0_ACPI_RAS_FEATURE_TABLE_SIGNATURE SIGNATURE_32('R', 'A', 'S', 'F') - -/// -/// "RSDT" Root System Description Table -/// -#define EFI_ACPI_6_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('R', 'S', 'D', 'T') - -/// -/// "SBST" Smart Battery Specification Table -/// -#define EFI_ACPI_6_0_SMART_BATTERY_SPECIFICATION_TABLE_SIGNATURE SIGNATURE_32('S', 'B', 'S', 'T') - -/// -/// "SLIT" System Locality Information Table -/// -#define EFI_ACPI_6_0_SYSTEM_LOCALITY_INFORMATION_TABLE_SIGNATURE SIGNATURE_32('S', 'L', 'I', 'T') - -/// -/// "SRAT" System Resource Affinity Table -/// -#define EFI_ACPI_6_0_SYSTEM_RESOURCE_AFFINITY_TABLE_SIGNATURE SIGNATURE_32('S', 'R', 'A', 'T') - -/// -/// "SSDT" Secondary System Description Table -/// -#define EFI_ACPI_6_0_SECONDARY_SYSTEM_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('S', 'S', 'D', 'T') - -/// -/// "XSDT" Extended System Description Table -/// -#define EFI_ACPI_6_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('X', 'S', 'D', 'T') - -/// -/// "BOOT" MS Simple Boot Spec -/// -#define EFI_ACPI_6_0_SIMPLE_BOOT_FLAG_TABLE_SIGNATURE SIGNATURE_32('B', 'O', 'O', 'T') - -/// -/// "CSRT" MS Core System Resource Table -/// -#define EFI_ACPI_6_0_CORE_SYSTEM_RESOURCE_TABLE_SIGNATURE SIGNATURE_32('C', 'S', 'R', 'T') - -/// -/// "DBG2" MS Debug Port 2 Spec -/// -#define EFI_ACPI_6_0_DEBUG_PORT_2_TABLE_SIGNATURE SIGNATURE_32('D', 'B', 'G', '2') - -/// -/// "DBGP" MS Debug Port Spec -/// -#define EFI_ACPI_6_0_DEBUG_PORT_TABLE_SIGNATURE SIGNATURE_32('D', 'B', 'G', 'P') - -/// -/// "DMAR" DMA Remapping Table -/// -#define EFI_ACPI_6_0_DMA_REMAPPING_TABLE_SIGNATURE SIGNATURE_32('D', 'M', 'A', 'R') - -/// -/// "DRTM" Dynamic Root of Trust for Measurement Table -/// -#define EFI_ACPI_6_0_DYNAMIC_ROOT_OF_TRUST_FOR_MEASUREMENT_TABLE_SIGNATURE SIGNATURE_32('D', 'R', 'T', 'M') - -/// -/// "ETDT" Event Timer Description Table -/// -#define EFI_ACPI_6_0_EVENT_TIMER_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('E', 'T', 'D', 'T') - -/// -/// "HPET" IA-PC High Precision Event Timer Table -/// -#define EFI_ACPI_6_0_HIGH_PRECISION_EVENT_TIMER_TABLE_SIGNATURE SIGNATURE_32('H', 'P', 'E', 'T') - -/// -/// "iBFT" iSCSI Boot Firmware Table -/// -#define EFI_ACPI_6_0_ISCSI_BOOT_FIRMWARE_TABLE_SIGNATURE SIGNATURE_32('i', 'B', 'F', 'T') - -/// -/// "IORT" Interrupt Source Override -/// -#define EFI_ACPI_6_0_INTERRUPT_SOURCE_OVERRIDE_SIGNATURE SIGNATURE_32('I', 'O', 'R', 'T') - -/// -/// "IVRS" I/O Virtualization Reporting Structure -/// -#define EFI_ACPI_6_0_IO_VIRTUALIZATION_REPORTING_STRUCTURE_SIGNATURE SIGNATURE_32('I', 'V', 'R', 'S') - -/// -/// "LPIT" Low Power Idle Table -/// -#define EFI_ACPI_6_0_LOW_POWER_IDLE_TABLE_STRUCTURE_SIGNATURE SIGNATURE_32('L', 'P', 'I', 'T') - -/// -/// "MCFG" PCI Express Memory Mapped Configuration Space Base Address Description Table -/// -#define EFI_ACPI_6_0_PCI_EXPRESS_MEMORY_MAPPED_CONFIGURATION_SPACE_BASE_ADDRESS_DESCRIPTION_TABLE_SIGNATURE SIGNATURE_32('M', 'C', 'F', 'G') - -/// -/// "MCHI" Management Controller Host Interface Table -/// -#define EFI_ACPI_6_0_MANAGEMENT_CONTROLLER_HOST_INTERFACE_TABLE_SIGNATURE SIGNATURE_32('M', 'C', 'H', 'I') - -/// -/// "MSDM" MS Data Management Table -/// -#define EFI_ACPI_6_0_DATA_MANAGEMENT_TABLE_SIGNATURE SIGNATURE_32('M', 'S', 'D', 'M') - -/// -/// "SLIC" MS Software Licensing Table Specification -/// -#define EFI_ACPI_6_0_SOFTWARE_LICENSING_TABLE_SIGNATURE SIGNATURE_32('S', 'L', 'I', 'C') - -/// -/// "SPCR" Serial Port Concole Redirection Table -/// -#define EFI_ACPI_6_0_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_SIGNATURE SIGNATURE_32('S', 'P', 'C', 'R') - -/// -/// "SPMI" Server Platform Management Interface Table -/// -#define EFI_ACPI_6_0_SERVER_PLATFORM_MANAGEMENT_INTERFACE_TABLE_SIGNATURE SIGNATURE_32('S', 'P', 'M', 'I') - -/// -/// "STAO" _STA Override Table -/// -#define EFI_ACPI_6_0_STA_OVERRIDE_TABLE_SIGNATURE SIGNATURE_32('S', 'T', 'A', 'O') - -/// -/// "TCPA" Trusted Computing Platform Alliance Capabilities Table -/// -#define EFI_ACPI_6_0_TRUSTED_COMPUTING_PLATFORM_ALLIANCE_CAPABILITIES_TABLE_SIGNATURE SIGNATURE_32('T', 'C', 'P', 'A') - -/// -/// "TPM2" Trusted Computing Platform 1 Table -/// -#define EFI_ACPI_6_0_TRUSTED_COMPUTING_PLATFORM_2_TABLE_SIGNATURE SIGNATURE_32('T', 'P', 'M', '2') - -/// -/// "UEFI" UEFI ACPI Data Table -/// -#define EFI_ACPI_6_0_UEFI_ACPI_DATA_TABLE_SIGNATURE SIGNATURE_32('U', 'E', 'F', 'I') - -/// -/// "WAET" Windows ACPI Emulated Devices Table -/// -#define EFI_ACPI_6_0_WINDOWS_ACPI_EMULATED_DEVICES_TABLE_SIGNATURE SIGNATURE_32('W', 'A', 'E', 'T') - -/// -/// "WDAT" Watchdog Action Table -/// -#define EFI_ACPI_6_0_WATCHDOG_ACTION_TABLE_SIGNATURE SIGNATURE_32('W', 'D', 'A', 'T') - -/// -/// "WDRT" Watchdog Resource Table -/// -#define EFI_ACPI_6_0_WATCHDOG_RESOURCE_TABLE_SIGNATURE SIGNATURE_32('W', 'D', 'R', 'T') - -/// -/// "WPBT" MS Platform Binary Table -/// -#define EFI_ACPI_6_0_PLATFORM_BINARY_TABLE_SIGNATURE SIGNATURE_32('W', 'P', 'B', 'T') - -/// -/// "XENV" Xen Project Table -/// -#define EFI_ACPI_6_0_XEN_PROJECT_TABLE_SIGNATURE SIGNATURE_32('X', 'E', 'N', 'V') - -#pragma pack() - -#endif diff --git a/roms/ipxe/src/include/ipxe/efi/IndustryStandard/Bluetooth.h b/roms/ipxe/src/include/ipxe/efi/IndustryStandard/Bluetooth.h deleted file mode 100644 index f63ab8901..000000000 --- a/roms/ipxe/src/include/ipxe/efi/IndustryStandard/Bluetooth.h +++ /dev/null @@ -1,49 +0,0 @@ -/** @file - This file contains the Bluetooth definitions that are consumed by drivers. - These definitions are from Bluetooth Core Specification Version 4.0 June, 2010 - - Copyright (c) 2015, Intel Corporation. All rights reserved.<BR> - This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#ifndef _BLUETOOTH_H_ -#define _BLUETOOTH_H_ - -FILE_LICENCE ( BSD3 ); - -#pragma pack(1) - -/// -/// BLUETOOTH_ADDRESS -/// -typedef struct { - /// - /// 48bit Bluetooth device address. - /// - UINT8 Address[6]; -} BLUETOOTH_ADDRESS; - -/// -/// BLUETOOTH_CLASS_OF_DEVICE. See Bluetooth specification for detail. -/// -typedef struct { - UINT8 FormatType:2; - UINT8 MinorDeviceClass: 6; - UINT16 MajorDeviceClass: 5; - UINT16 MajorServiceClass:11; -} BLUETOOTH_CLASS_OF_DEVICE; - -#pragma pack() - -#define BLUETOOTH_HCI_COMMAND_LOCAL_READABLE_NAME_MAX_SIZE 248 - -#define BLUETOOTH_HCI_LINK_KEY_SIZE 16 - -#endif diff --git a/roms/ipxe/src/include/ipxe/efi/IndustryStandard/Pci22.h b/roms/ipxe/src/include/ipxe/efi/IndustryStandard/Pci22.h index f0f2ae922..a73820f69 100644 --- a/roms/ipxe/src/include/ipxe/efi/IndustryStandard/Pci22.h +++ b/roms/ipxe/src/include/ipxe/efi/IndustryStandard/Pci22.h @@ -9,7 +9,7 @@ Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR> - Copyright (c) 2014 - 2105, Hewlett-Packard Development Company, L.P.<BR> + Copyright (c) 2014, Hewlett-Packard Development Company, L.P.<BR> This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -554,7 +554,6 @@ typedef struct { #define PCI_BRIDGE_PRIMARY_BUS_REGISTER_OFFSET 0x18 #define PCI_BRIDGE_SECONDARY_BUS_REGISTER_OFFSET 0x19 #define PCI_BRIDGE_SUBORDINATE_BUS_REGISTER_OFFSET 0x1a -#define PCI_BRIDGE_SECONDARY_LATENCY_TIMER_OFFSET 0x1b #define PCI_BRIDGE_STATUS_REGISTER_OFFSET 0x1E #define PCI_BRIDGE_CONTROL_REGISTER_OFFSET 0x3E diff --git a/roms/ipxe/src/include/ipxe/efi/IndustryStandard/Tpm20.h b/roms/ipxe/src/include/ipxe/efi/IndustryStandard/Tpm20.h deleted file mode 100644 index 656bf21eb..000000000 --- a/roms/ipxe/src/include/ipxe/efi/IndustryStandard/Tpm20.h +++ /dev/null @@ -1,1822 +0,0 @@ -/** @file - TPM2.0 Specification data structures - (Trusted Platform Module Library Specification, Family "2.0", Level 00, Revision 00.96, - @http://www.trustedcomputinggroup.org/resources/tpm_library_specification) - - Check http://trustedcomputinggroup.org for latest specification updates. - -Copyright (c) 2013 - 2015, Intel Corporation. All rights reserved. <BR> -This program and the accompanying materials -are licensed and made available under the terms and conditions of the BSD License -which accompanies this distribution. The full text of the license may be found at -http://opensource.org/licenses/bsd-license.php - -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - - -#ifndef _TPM20_H_ -#define _TPM20_H_ - -FILE_LICENCE ( BSD3 ); - -#include <ipxe/efi/IndustryStandard/Tpm12.h> - -#pragma pack (1) - -// Annex A Algorithm Constants - -// Table 205 - Defines for SHA1 Hash Values -#define SHA1_DIGEST_SIZE 20 -#define SHA1_BLOCK_SIZE 64 - -// Table 206 - Defines for SHA256 Hash Values -#define SHA256_DIGEST_SIZE 32 -#define SHA256_BLOCK_SIZE 64 - -// Table 207 - Defines for SHA384 Hash Values -#define SHA384_DIGEST_SIZE 48 -#define SHA384_BLOCK_SIZE 128 - -// Table 208 - Defines for SHA512 Hash Values -#define SHA512_DIGEST_SIZE 64 -#define SHA512_BLOCK_SIZE 128 - -// Table 209 - Defines for SM3_256 Hash Values -#define SM3_256_DIGEST_SIZE 32 -#define SM3_256_BLOCK_SIZE 64 - -// Table 210 - Defines for Architectural Limits Values -#define MAX_SESSION_NUMBER 3 - -// Annex B Implementation Definitions - -// Table 211 - Defines for Logic Values -#define YES 1 -#define NO 0 -#define SET 1 -#define CLEAR 0 - -// Table 215 - Defines for RSA Algorithm Constants -#define MAX_RSA_KEY_BITS 2048 -#define MAX_RSA_KEY_BYTES ((MAX_RSA_KEY_BITS + 7) / 8) - -// Table 216 - Defines for ECC Algorithm Constants -#define MAX_ECC_KEY_BITS 256 -#define MAX_ECC_KEY_BYTES ((MAX_ECC_KEY_BITS + 7) / 8) - -// Table 217 - Defines for AES Algorithm Constants -#define MAX_AES_KEY_BITS 128 -#define MAX_AES_BLOCK_SIZE_BYTES 16 -#define MAX_AES_KEY_BYTES ((MAX_AES_KEY_BITS + 7) / 8) - -// Table 218 - Defines for SM4 Algorithm Constants -#define MAX_SM4_KEY_BITS 128 -#define MAX_SM4_BLOCK_SIZE_BYTES 16 -#define MAX_SM4_KEY_BYTES ((MAX_SM4_KEY_BITS + 7) / 8) - -// Table 219 - Defines for Symmetric Algorithm Constants -#define MAX_SYM_KEY_BITS MAX_AES_KEY_BITS -#define MAX_SYM_KEY_BYTES MAX_AES_KEY_BYTES -#define MAX_SYM_BLOCK_SIZE MAX_AES_BLOCK_SIZE_BYTES - -// Table 220 - Defines for Implementation Values -typedef UINT16 BSIZE; -#define BUFFER_ALIGNMENT 4 -#define IMPLEMENTATION_PCR 24 -#define PLATFORM_PCR 24 -#define DRTM_PCR 17 -#define NUM_LOCALITIES 5 -#define MAX_HANDLE_NUM 3 -#define MAX_ACTIVE_SESSIONS 64 -typedef UINT16 CONTEXT_SLOT; -typedef UINT64 CONTEXT_COUNTER; -#define MAX_LOADED_SESSIONS 3 -#define MAX_SESSION_NUM 3 -#define MAX_LOADED_OBJECTS 3 -#define MIN_EVICT_OBJECTS 2 -#define PCR_SELECT_MIN ((PLATFORM_PCR + 7) / 8) -#define PCR_SELECT_MAX ((IMPLEMENTATION_PCR + 7) / 8) -#define NUM_POLICY_PCR_GROUP 1 -#define NUM_AUTHVALUE_PCR_GROUP 1 -#define MAX_CONTEXT_SIZE 4000 -#define MAX_DIGEST_BUFFER 1024 -#define MAX_NV_INDEX_SIZE 1024 -#define MAX_CAP_BUFFER 1024 -#define NV_MEMORY_SIZE 16384 -#define NUM_STATIC_PCR 16 -#define MAX_ALG_LIST_SIZE 64 -#define TIMER_PRESCALE 100000 -#define PRIMARY_SEED_SIZE 32 -#define CONTEXT_ENCRYPT_ALG TPM_ALG_AES -#define CONTEXT_ENCRYPT_KEY_BITS MAX_SYM_KEY_BITS -#define CONTEXT_ENCRYPT_KEY_BYTES ((CONTEXT_ENCRYPT_KEY_BITS + 7) / 8) -#define CONTEXT_INTEGRITY_HASH_ALG TPM_ALG_SHA256 -#define CONTEXT_INTEGRITY_HASH_SIZE SHA256_DIGEST_SIZE -#define PROOF_SIZE CONTEXT_INTEGRITY_HASH_SIZE -#define NV_CLOCK_UPDATE_INTERVAL 12 -#define NUM_POLICY_PCR 1 -#define MAX_COMMAND_SIZE 4096 -#define MAX_RESPONSE_SIZE 4096 -#define ORDERLY_BITS 8 -#define MAX_ORDERLY_COUNT ((1 << ORDERLY_BITS) - 1) -#define ALG_ID_FIRST TPM_ALG_FIRST -#define ALG_ID_LAST TPM_ALG_LAST -#define MAX_SYM_DATA 128 -#define MAX_RNG_ENTROPY_SIZE 64 -#define RAM_INDEX_SPACE 512 -#define RSA_DEFAULT_PUBLIC_EXPONENT 0x00010001 -#define CRT_FORMAT_RSA YES -#define PRIVATE_VENDOR_SPECIFIC_BYTES ((MAX_RSA_KEY_BYTES / 2) * ( 3 + CRT_FORMAT_RSA * 2)) - -// Capability related MAX_ value -#define MAX_CAP_DATA (MAX_CAP_BUFFER - sizeof(TPM_CAP) - sizeof(UINT32)) -#define MAX_CAP_ALGS (MAX_CAP_DATA / sizeof(TPMS_ALG_PROPERTY)) -#define MAX_CAP_HANDLES (MAX_CAP_DATA / sizeof(TPM_HANDLE)) -#define MAX_CAP_CC (MAX_CAP_DATA / sizeof(TPM_CC)) -#define MAX_TPM_PROPERTIES (MAX_CAP_DATA / sizeof(TPMS_TAGGED_PROPERTY)) -#define MAX_PCR_PROPERTIES (MAX_CAP_DATA / sizeof(TPMS_TAGGED_PCR_SELECT)) -#define MAX_ECC_CURVES (MAX_CAP_DATA / sizeof(TPM_ECC_CURVE)) - -// -// Always set 5 here, because we want to support all hash algo in BIOS. -// -#define HASH_COUNT 5 - -// 5 Base Types - -// Table 3 - Definition of Base Types -typedef UINT8 BYTE; - -// Table 4 - Definition of Types for Documentation Clarity -// -// NOTE: Comment because it has same name as TPM1.2 (value is same, so not runtime issue) -// -//typedef UINT32 TPM_ALGORITHM_ID; -//typedef UINT32 TPM_MODIFIER_INDICATOR; -typedef UINT32 TPM_AUTHORIZATION_SIZE; -typedef UINT32 TPM_PARAMETER_SIZE; -typedef UINT16 TPM_KEY_SIZE; -typedef UINT16 TPM_KEY_BITS; - -// 6 Constants - -// Table 6 - TPM_GENERATED Constants -typedef UINT32 TPM_GENERATED; -#define TPM_GENERATED_VALUE (TPM_GENERATED)(0xff544347) - -// Table 7 - TPM_ALG_ID Constants -typedef UINT16 TPM_ALG_ID; -// -// NOTE: Comment some algo which has same name as TPM1.2 (value is same, so not runtime issue) -// -#define TPM_ALG_ERROR (TPM_ALG_ID)(0x0000) -#define TPM_ALG_FIRST (TPM_ALG_ID)(0x0001) -//#define TPM_ALG_RSA (TPM_ALG_ID)(0x0001) -//#define TPM_ALG_SHA (TPM_ALG_ID)(0x0004) -#define TPM_ALG_SHA1 (TPM_ALG_ID)(0x0004) -//#define TPM_ALG_HMAC (TPM_ALG_ID)(0x0005) -#define TPM_ALG_AES (TPM_ALG_ID)(0x0006) -//#define TPM_ALG_MGF1 (TPM_ALG_ID)(0x0007) -#define TPM_ALG_KEYEDHASH (TPM_ALG_ID)(0x0008) -//#define TPM_ALG_XOR (TPM_ALG_ID)(0x000A) -#define TPM_ALG_SHA256 (TPM_ALG_ID)(0x000B) -#define TPM_ALG_SHA384 (TPM_ALG_ID)(0x000C) -#define TPM_ALG_SHA512 (TPM_ALG_ID)(0x000D) -#define TPM_ALG_NULL (TPM_ALG_ID)(0x0010) -#define TPM_ALG_SM3_256 (TPM_ALG_ID)(0x0012) -#define TPM_ALG_SM4 (TPM_ALG_ID)(0x0013) -#define TPM_ALG_RSASSA (TPM_ALG_ID)(0x0014) -#define TPM_ALG_RSAES (TPM_ALG_ID)(0x0015) -#define TPM_ALG_RSAPSS (TPM_ALG_ID)(0x0016) -#define TPM_ALG_OAEP (TPM_ALG_ID)(0x0017) -#define TPM_ALG_ECDSA (TPM_ALG_ID)(0x0018) -#define TPM_ALG_ECDH (TPM_ALG_ID)(0x0019) -#define TPM_ALG_ECDAA (TPM_ALG_ID)(0x001A) -#define TPM_ALG_SM2 (TPM_ALG_ID)(0x001B) -#define TPM_ALG_ECSCHNORR (TPM_ALG_ID)(0x001C) -#define TPM_ALG_ECMQV (TPM_ALG_ID)(0x001D) -#define TPM_ALG_KDF1_SP800_56a (TPM_ALG_ID)(0x0020) -#define TPM_ALG_KDF2 (TPM_ALG_ID)(0x0021) -#define TPM_ALG_KDF1_SP800_108 (TPM_ALG_ID)(0x0022) -#define TPM_ALG_ECC (TPM_ALG_ID)(0x0023) -#define TPM_ALG_SYMCIPHER (TPM_ALG_ID)(0x0025) -#define TPM_ALG_CTR (TPM_ALG_ID)(0x0040) -#define TPM_ALG_OFB (TPM_ALG_ID)(0x0041) -#define TPM_ALG_CBC (TPM_ALG_ID)(0x0042) -#define TPM_ALG_CFB (TPM_ALG_ID)(0x0043) -#define TPM_ALG_ECB (TPM_ALG_ID)(0x0044) -#define TPM_ALG_LAST (TPM_ALG_ID)(0x0044) - -// Table 8 - TPM_ECC_CURVE Constants -typedef UINT16 TPM_ECC_CURVE; -#define TPM_ECC_NONE (TPM_ECC_CURVE)(0x0000) -#define TPM_ECC_NIST_P192 (TPM_ECC_CURVE)(0x0001) -#define TPM_ECC_NIST_P224 (TPM_ECC_CURVE)(0x0002) -#define TPM_ECC_NIST_P256 (TPM_ECC_CURVE)(0x0003) -#define TPM_ECC_NIST_P384 (TPM_ECC_CURVE)(0x0004) -#define TPM_ECC_NIST_P521 (TPM_ECC_CURVE)(0x0005) -#define TPM_ECC_BN_P256 (TPM_ECC_CURVE)(0x0010) -#define TPM_ECC_BN_P638 (TPM_ECC_CURVE)(0x0011) -#define TPM_ECC_SM2_P256 (TPM_ECC_CURVE)(0x0020) - -// Table 11 - TPM_CC Constants (Numeric Order) -typedef UINT32 TPM_CC; -#define TPM_CC_FIRST (TPM_CC)(0x0000011F) -#define TPM_CC_PP_FIRST (TPM_CC)(0x0000011F) -#define TPM_CC_NV_UndefineSpaceSpecial (TPM_CC)(0x0000011F) -#define TPM_CC_EvictControl (TPM_CC)(0x00000120) -#define TPM_CC_HierarchyControl (TPM_CC)(0x00000121) -#define TPM_CC_NV_UndefineSpace (TPM_CC)(0x00000122) -#define TPM_CC_ChangeEPS (TPM_CC)(0x00000124) -#define TPM_CC_ChangePPS (TPM_CC)(0x00000125) -#define TPM_CC_Clear (TPM_CC)(0x00000126) -#define TPM_CC_ClearControl (TPM_CC)(0x00000127) -#define TPM_CC_ClockSet (TPM_CC)(0x00000128) -#define TPM_CC_HierarchyChangeAuth (TPM_CC)(0x00000129) -#define TPM_CC_NV_DefineSpace (TPM_CC)(0x0000012A) -#define TPM_CC_PCR_Allocate (TPM_CC)(0x0000012B) -#define TPM_CC_PCR_SetAuthPolicy (TPM_CC)(0x0000012C) -#define TPM_CC_PP_Commands (TPM_CC)(0x0000012D) -#define TPM_CC_SetPrimaryPolicy (TPM_CC)(0x0000012E) -#define TPM_CC_FieldUpgradeStart (TPM_CC)(0x0000012F) -#define TPM_CC_ClockRateAdjust (TPM_CC)(0x00000130) -#define TPM_CC_CreatePrimary (TPM_CC)(0x00000131) -#define TPM_CC_NV_GlobalWriteLock (TPM_CC)(0x00000132) -#define TPM_CC_PP_LAST (TPM_CC)(0x00000132) -#define TPM_CC_GetCommandAuditDigest (TPM_CC)(0x00000133) -#define TPM_CC_NV_Increment (TPM_CC)(0x00000134) -#define TPM_CC_NV_SetBits (TPM_CC)(0x00000135) -#define TPM_CC_NV_Extend (TPM_CC)(0x00000136) -#define TPM_CC_NV_Write (TPM_CC)(0x00000137) -#define TPM_CC_NV_WriteLock (TPM_CC)(0x00000138) -#define TPM_CC_DictionaryAttackLockReset (TPM_CC)(0x00000139) -#define TPM_CC_DictionaryAttackParameters (TPM_CC)(0x0000013A) -#define TPM_CC_NV_ChangeAuth (TPM_CC)(0x0000013B) -#define TPM_CC_PCR_Event (TPM_CC)(0x0000013C) -#define TPM_CC_PCR_Reset (TPM_CC)(0x0000013D) -#define TPM_CC_SequenceComplete (TPM_CC)(0x0000013E) -#define TPM_CC_SetAlgorithmSet (TPM_CC)(0x0000013F) -#define TPM_CC_SetCommandCodeAuditStatus (TPM_CC)(0x00000140) -#define TPM_CC_FieldUpgradeData (TPM_CC)(0x00000141) -#define TPM_CC_IncrementalSelfTest (TPM_CC)(0x00000142) -#define TPM_CC_SelfTest (TPM_CC)(0x00000143) -#define TPM_CC_Startup (TPM_CC)(0x00000144) -#define TPM_CC_Shutdown (TPM_CC)(0x00000145) -#define TPM_CC_StirRandom (TPM_CC)(0x00000146) -#define TPM_CC_ActivateCredential (TPM_CC)(0x00000147) -#define TPM_CC_Certify (TPM_CC)(0x00000148) -#define TPM_CC_PolicyNV (TPM_CC)(0x00000149) -#define TPM_CC_CertifyCreation (TPM_CC)(0x0000014A) -#define TPM_CC_Duplicate (TPM_CC)(0x0000014B) -#define TPM_CC_GetTime (TPM_CC)(0x0000014C) -#define TPM_CC_GetSessionAuditDigest (TPM_CC)(0x0000014D) -#define TPM_CC_NV_Read (TPM_CC)(0x0000014E) -#define TPM_CC_NV_ReadLock (TPM_CC)(0x0000014F) -#define TPM_CC_ObjectChangeAuth (TPM_CC)(0x00000150) -#define TPM_CC_PolicySecret (TPM_CC)(0x00000151) -#define TPM_CC_Rewrap (TPM_CC)(0x00000152) -#define TPM_CC_Create (TPM_CC)(0x00000153) -#define TPM_CC_ECDH_ZGen (TPM_CC)(0x00000154) -#define TPM_CC_HMAC (TPM_CC)(0x00000155) -#define TPM_CC_Import (TPM_CC)(0x00000156) -#define TPM_CC_Load (TPM_CC)(0x00000157) -#define TPM_CC_Quote (TPM_CC)(0x00000158) -#define TPM_CC_RSA_Decrypt (TPM_CC)(0x00000159) -#define TPM_CC_HMAC_Start (TPM_CC)(0x0000015B) -#define TPM_CC_SequenceUpdate (TPM_CC)(0x0000015C) -#define TPM_CC_Sign (TPM_CC)(0x0000015D) -#define TPM_CC_Unseal (TPM_CC)(0x0000015E) -#define TPM_CC_PolicySigned (TPM_CC)(0x00000160) -#define TPM_CC_ContextLoad (TPM_CC)(0x00000161) -#define TPM_CC_ContextSave (TPM_CC)(0x00000162) -#define TPM_CC_ECDH_KeyGen (TPM_CC)(0x00000163) -#define TPM_CC_EncryptDecrypt (TPM_CC)(0x00000164) -#define TPM_CC_FlushContext (TPM_CC)(0x00000165) -#define TPM_CC_LoadExternal (TPM_CC)(0x00000167) -#define TPM_CC_MakeCredential (TPM_CC)(0x00000168) -#define TPM_CC_NV_ReadPublic (TPM_CC)(0x00000169) -#define TPM_CC_PolicyAuthorize (TPM_CC)(0x0000016A) -#define TPM_CC_PolicyAuthValue (TPM_CC)(0x0000016B) -#define TPM_CC_PolicyCommandCode (TPM_CC)(0x0000016C) -#define TPM_CC_PolicyCounterTimer (TPM_CC)(0x0000016D) -#define TPM_CC_PolicyCpHash (TPM_CC)(0x0000016E) -#define TPM_CC_PolicyLocality (TPM_CC)(0x0000016F) -#define TPM_CC_PolicyNameHash (TPM_CC)(0x00000170) -#define TPM_CC_PolicyOR (TPM_CC)(0x00000171) -#define TPM_CC_PolicyTicket (TPM_CC)(0x00000172) -#define TPM_CC_ReadPublic (TPM_CC)(0x00000173) -#define TPM_CC_RSA_Encrypt (TPM_CC)(0x00000174) -#define TPM_CC_StartAuthSession (TPM_CC)(0x00000176) -#define TPM_CC_VerifySignature (TPM_CC)(0x00000177) -#define TPM_CC_ECC_Parameters (TPM_CC)(0x00000178) -#define TPM_CC_FirmwareRead (TPM_CC)(0x00000179) -#define TPM_CC_GetCapability (TPM_CC)(0x0000017A) -#define TPM_CC_GetRandom (TPM_CC)(0x0000017B) -#define TPM_CC_GetTestResult (TPM_CC)(0x0000017C) -#define TPM_CC_Hash (TPM_CC)(0x0000017D) -#define TPM_CC_PCR_Read (TPM_CC)(0x0000017E) -#define TPM_CC_PolicyPCR (TPM_CC)(0x0000017F) -#define TPM_CC_PolicyRestart (TPM_CC)(0x00000180) -#define TPM_CC_ReadClock (TPM_CC)(0x00000181) -#define TPM_CC_PCR_Extend (TPM_CC)(0x00000182) -#define TPM_CC_PCR_SetAuthValue (TPM_CC)(0x00000183) -#define TPM_CC_NV_Certify (TPM_CC)(0x00000184) -#define TPM_CC_EventSequenceComplete (TPM_CC)(0x00000185) -#define TPM_CC_HashSequenceStart (TPM_CC)(0x00000186) -#define TPM_CC_PolicyPhysicalPresence (TPM_CC)(0x00000187) -#define TPM_CC_PolicyDuplicationSelect (TPM_CC)(0x00000188) -#define TPM_CC_PolicyGetDigest (TPM_CC)(0x00000189) -#define TPM_CC_TestParms (TPM_CC)(0x0000018A) -#define TPM_CC_Commit (TPM_CC)(0x0000018B) -#define TPM_CC_PolicyPassword (TPM_CC)(0x0000018C) -#define TPM_CC_ZGen_2Phase (TPM_CC)(0x0000018D) -#define TPM_CC_EC_Ephemeral (TPM_CC)(0x0000018E) -#define TPM_CC_LAST (TPM_CC)(0x0000018E) - -// Table 15 - TPM_RC Constants (Actions) -typedef UINT32 TPM_RC; -#define TPM_RC_SUCCESS (TPM_RC)(0x000) -#define TPM_RC_BAD_TAG (TPM_RC)(0x030) -#define RC_VER1 (TPM_RC)(0x100) -#define TPM_RC_INITIALIZE (TPM_RC)(RC_VER1 + 0x000) -#define TPM_RC_FAILURE (TPM_RC)(RC_VER1 + 0x001) -#define TPM_RC_SEQUENCE (TPM_RC)(RC_VER1 + 0x003) -#define TPM_RC_PRIVATE (TPM_RC)(RC_VER1 + 0x00B) -#define TPM_RC_HMAC (TPM_RC)(RC_VER1 + 0x019) -#define TPM_RC_DISABLED (TPM_RC)(RC_VER1 + 0x020) -#define TPM_RC_EXCLUSIVE (TPM_RC)(RC_VER1 + 0x021) -#define TPM_RC_AUTH_TYPE (TPM_RC)(RC_VER1 + 0x024) -#define TPM_RC_AUTH_MISSING (TPM_RC)(RC_VER1 + 0x025) -#define TPM_RC_POLICY (TPM_RC)(RC_VER1 + 0x026) -#define TPM_RC_PCR (TPM_RC)(RC_VER1 + 0x027) -#define TPM_RC_PCR_CHANGED (TPM_RC)(RC_VER1 + 0x028) -#define TPM_RC_UPGRADE (TPM_RC)(RC_VER1 + 0x02D) -#define TPM_RC_TOO_MANY_CONTEXTS (TPM_RC)(RC_VER1 + 0x02E) -#define TPM_RC_AUTH_UNAVAILABLE (TPM_RC)(RC_VER1 + 0x02F) -#define TPM_RC_REBOOT (TPM_RC)(RC_VER1 + 0x030) -#define TPM_RC_UNBALANCED (TPM_RC)(RC_VER1 + 0x031) -#define TPM_RC_COMMAND_SIZE (TPM_RC)(RC_VER1 + 0x042) -#define TPM_RC_COMMAND_CODE (TPM_RC)(RC_VER1 + 0x043) -#define TPM_RC_AUTHSIZE (TPM_RC)(RC_VER1 + 0x044) -#define TPM_RC_AUTH_CONTEXT (TPM_RC)(RC_VER1 + 0x045) -#define TPM_RC_NV_RANGE (TPM_RC)(RC_VER1 + 0x046) -#define TPM_RC_NV_SIZE (TPM_RC)(RC_VER1 + 0x047) -#define TPM_RC_NV_LOCKED (TPM_RC)(RC_VER1 + 0x048) -#define TPM_RC_NV_AUTHORIZATION (TPM_RC)(RC_VER1 + 0x049) -#define TPM_RC_NV_UNINITIALIZED (TPM_RC)(RC_VER1 + 0x04A) -#define TPM_RC_NV_SPACE (TPM_RC)(RC_VER1 + 0x04B) -#define TPM_RC_NV_DEFINED (TPM_RC)(RC_VER1 + 0x04C) -#define TPM_RC_BAD_CONTEXT (TPM_RC)(RC_VER1 + 0x050) -#define TPM_RC_CPHASH (TPM_RC)(RC_VER1 + 0x051) -#define TPM_RC_PARENT (TPM_RC)(RC_VER1 + 0x052) -#define TPM_RC_NEEDS_TEST (TPM_RC)(RC_VER1 + 0x053) -#define TPM_RC_NO_RESULT (TPM_RC)(RC_VER1 + 0x054) -#define TPM_RC_SENSITIVE (TPM_RC)(RC_VER1 + 0x055) -#define RC_MAX_FM0 (TPM_RC)(RC_VER1 + 0x07F) -#define RC_FMT1 (TPM_RC)(0x080) -#define TPM_RC_ASYMMETRIC (TPM_RC)(RC_FMT1 + 0x001) -#define TPM_RC_ATTRIBUTES (TPM_RC)(RC_FMT1 + 0x002) -#define TPM_RC_HASH (TPM_RC)(RC_FMT1 + 0x003) -#define TPM_RC_VALUE (TPM_RC)(RC_FMT1 + 0x004) -#define TPM_RC_HIERARCHY (TPM_RC)(RC_FMT1 + 0x005) -#define TPM_RC_KEY_SIZE (TPM_RC)(RC_FMT1 + 0x007) -#define TPM_RC_MGF (TPM_RC)(RC_FMT1 + 0x008) -#define TPM_RC_MODE (TPM_RC)(RC_FMT1 + 0x009) -#define TPM_RC_TYPE (TPM_RC)(RC_FMT1 + 0x00A) -#define TPM_RC_HANDLE (TPM_RC)(RC_FMT1 + 0x00B) -#define TPM_RC_KDF (TPM_RC)(RC_FMT1 + 0x00C) -#define TPM_RC_RANGE (TPM_RC)(RC_FMT1 + 0x00D) -#define TPM_RC_AUTH_FAIL (TPM_RC)(RC_FMT1 + 0x00E) -#define TPM_RC_NONCE (TPM_RC)(RC_FMT1 + 0x00F) -#define TPM_RC_PP (TPM_RC)(RC_FMT1 + 0x010) -#define TPM_RC_SCHEME (TPM_RC)(RC_FMT1 + 0x012) -#define TPM_RC_SIZE (TPM_RC)(RC_FMT1 + 0x015) -#define TPM_RC_SYMMETRIC (TPM_RC)(RC_FMT1 + 0x016) -#define TPM_RC_TAG (TPM_RC)(RC_FMT1 + 0x017) -#define TPM_RC_SELECTOR (TPM_RC)(RC_FMT1 + 0x018) -#define TPM_RC_INSUFFICIENT (TPM_RC)(RC_FMT1 + 0x01A) -#define TPM_RC_SIGNATURE (TPM_RC)(RC_FMT1 + 0x01B) -#define TPM_RC_KEY (TPM_RC)(RC_FMT1 + 0x01C) -#define TPM_RC_POLICY_FAIL (TPM_RC)(RC_FMT1 + 0x01D) -#define TPM_RC_INTEGRITY (TPM_RC)(RC_FMT1 + 0x01F) -#define TPM_RC_TICKET (TPM_RC)(RC_FMT1 + 0x020) -#define TPM_RC_RESERVED_BITS (TPM_RC)(RC_FMT1 + 0x021) -#define TPM_RC_BAD_AUTH (TPM_RC)(RC_FMT1 + 0x022) -#define TPM_RC_EXPIRED (TPM_RC)(RC_FMT1 + 0x023) -#define TPM_RC_POLICY_CC (TPM_RC)(RC_FMT1 + 0x024 ) -#define TPM_RC_BINDING (TPM_RC)(RC_FMT1 + 0x025) -#define TPM_RC_CURVE (TPM_RC)(RC_FMT1 + 0x026) -#define TPM_RC_ECC_POINT (TPM_RC)(RC_FMT1 + 0x027) -#define RC_WARN (TPM_RC)(0x900) -#define TPM_RC_CONTEXT_GAP (TPM_RC)(RC_WARN + 0x001) -#define TPM_RC_OBJECT_MEMORY (TPM_RC)(RC_WARN + 0x002) -#define TPM_RC_SESSION_MEMORY (TPM_RC)(RC_WARN + 0x003) -#define TPM_RC_MEMORY (TPM_RC)(RC_WARN + 0x004) -#define TPM_RC_SESSION_HANDLES (TPM_RC)(RC_WARN + 0x005) -#define TPM_RC_OBJECT_HANDLES (TPM_RC)(RC_WARN + 0x006) -#define TPM_RC_LOCALITY (TPM_RC)(RC_WARN + 0x007) -#define TPM_RC_YIELDED (TPM_RC)(RC_WARN + 0x008) -#define TPM_RC_CANCELED (TPM_RC)(RC_WARN + 0x009) -#define TPM_RC_TESTING (TPM_RC)(RC_WARN + 0x00A) -#define TPM_RC_REFERENCE_H0 (TPM_RC)(RC_WARN + 0x010) -#define TPM_RC_REFERENCE_H1 (TPM_RC)(RC_WARN + 0x011) -#define TPM_RC_REFERENCE_H2 (TPM_RC)(RC_WARN + 0x012) -#define TPM_RC_REFERENCE_H3 (TPM_RC)(RC_WARN + 0x013) -#define TPM_RC_REFERENCE_H4 (TPM_RC)(RC_WARN + 0x014) -#define TPM_RC_REFERENCE_H5 (TPM_RC)(RC_WARN + 0x015) -#define TPM_RC_REFERENCE_H6 (TPM_RC)(RC_WARN + 0x016) -#define TPM_RC_REFERENCE_S0 (TPM_RC)(RC_WARN + 0x018) -#define TPM_RC_REFERENCE_S1 (TPM_RC)(RC_WARN + 0x019) -#define TPM_RC_REFERENCE_S2 (TPM_RC)(RC_WARN + 0x01A) -#define TPM_RC_REFERENCE_S3 (TPM_RC)(RC_WARN + 0x01B) -#define TPM_RC_REFERENCE_S4 (TPM_RC)(RC_WARN + 0x01C) -#define TPM_RC_REFERENCE_S5 (TPM_RC)(RC_WARN + 0x01D) -#define TPM_RC_REFERENCE_S6 (TPM_RC)(RC_WARN + 0x01E) -#define TPM_RC_NV_RATE (TPM_RC)(RC_WARN + 0x020) -#define TPM_RC_LOCKOUT (TPM_RC)(RC_WARN + 0x021) -#define TPM_RC_RETRY (TPM_RC)(RC_WARN + 0x022) -#define TPM_RC_NV_UNAVAILABLE (TPM_RC)(RC_WARN + 0x023) -#define TPM_RC_NOT_USED (TPM_RC)(RC_WARN + 0x7F) -#define TPM_RC_H (TPM_RC)(0x000) -#define TPM_RC_P (TPM_RC)(0x040) -#define TPM_RC_S (TPM_RC)(0x800) -#define TPM_RC_1 (TPM_RC)(0x100) -#define TPM_RC_2 (TPM_RC)(0x200) -#define TPM_RC_3 (TPM_RC)(0x300) -#define TPM_RC_4 (TPM_RC)(0x400) -#define TPM_RC_5 (TPM_RC)(0x500) -#define TPM_RC_6 (TPM_RC)(0x600) -#define TPM_RC_7 (TPM_RC)(0x700) -#define TPM_RC_8 (TPM_RC)(0x800) -#define TPM_RC_9 (TPM_RC)(0x900) -#define TPM_RC_A (TPM_RC)(0xA00) -#define TPM_RC_B (TPM_RC)(0xB00) -#define TPM_RC_C (TPM_RC)(0xC00) -#define TPM_RC_D (TPM_RC)(0xD00) -#define TPM_RC_E (TPM_RC)(0xE00) -#define TPM_RC_F (TPM_RC)(0xF00) -#define TPM_RC_N_MASK (TPM_RC)(0xF00) - -// Table 16 - TPM_CLOCK_ADJUST Constants -typedef INT8 TPM_CLOCK_ADJUST; -#define TPM_CLOCK_COARSE_SLOWER (TPM_CLOCK_ADJUST)(-3) -#define TPM_CLOCK_MEDIUM_SLOWER (TPM_CLOCK_ADJUST)(-2) -#define TPM_CLOCK_FINE_SLOWER (TPM_CLOCK_ADJUST)(-1) -#define TPM_CLOCK_NO_CHANGE (TPM_CLOCK_ADJUST)(0) -#define TPM_CLOCK_FINE_FASTER (TPM_CLOCK_ADJUST)(1) -#define TPM_CLOCK_MEDIUM_FASTER (TPM_CLOCK_ADJUST)(2) -#define TPM_CLOCK_COARSE_FASTER (TPM_CLOCK_ADJUST)(3) - -// Table 17 - TPM_EO Constants -typedef UINT16 TPM_EO; -#define TPM_EO_EQ (TPM_EO)(0x0000) -#define TPM_EO_NEQ (TPM_EO)(0x0001) -#define TPM_EO_SIGNED_GT (TPM_EO)(0x0002) -#define TPM_EO_UNSIGNED_GT (TPM_EO)(0x0003) -#define TPM_EO_SIGNED_LT (TPM_EO)(0x0004) -#define TPM_EO_UNSIGNED_LT (TPM_EO)(0x0005) -#define TPM_EO_SIGNED_GE (TPM_EO)(0x0006) -#define TPM_EO_UNSIGNED_GE (TPM_EO)(0x0007) -#define TPM_EO_SIGNED_LE (TPM_EO)(0x0008) -#define TPM_EO_UNSIGNED_LE (TPM_EO)(0x0009) -#define TPM_EO_BITSET (TPM_EO)(0x000A) -#define TPM_EO_BITCLEAR (TPM_EO)(0x000B) - -// Table 18 - TPM_ST Constants -typedef UINT16 TPM_ST; -#define TPM_ST_RSP_COMMAND (TPM_ST)(0x00C4) -#define TPM_ST_NULL (TPM_ST)(0X8000) -#define TPM_ST_NO_SESSIONS (TPM_ST)(0x8001) -#define TPM_ST_SESSIONS (TPM_ST)(0x8002) -#define TPM_ST_ATTEST_NV (TPM_ST)(0x8014) -#define TPM_ST_ATTEST_COMMAND_AUDIT (TPM_ST)(0x8015) -#define TPM_ST_ATTEST_SESSION_AUDIT (TPM_ST)(0x8016) -#define TPM_ST_ATTEST_CERTIFY (TPM_ST)(0x8017) -#define TPM_ST_ATTEST_QUOTE (TPM_ST)(0x8018) -#define TPM_ST_ATTEST_TIME (TPM_ST)(0x8019) -#define TPM_ST_ATTEST_CREATION (TPM_ST)(0x801A) -#define TPM_ST_CREATION (TPM_ST)(0x8021) -#define TPM_ST_VERIFIED (TPM_ST)(0x8022) -#define TPM_ST_AUTH_SECRET (TPM_ST)(0x8023) -#define TPM_ST_HASHCHECK (TPM_ST)(0x8024) -#define TPM_ST_AUTH_SIGNED (TPM_ST)(0x8025) -#define TPM_ST_FU_MANIFEST (TPM_ST)(0x8029) - -// Table 19 - TPM_SU Constants -typedef UINT16 TPM_SU; -#define TPM_SU_CLEAR (TPM_SU)(0x0000) -#define TPM_SU_STATE (TPM_SU)(0x0001) - -// Table 20 - TPM_SE Constants -typedef UINT8 TPM_SE; -#define TPM_SE_HMAC (TPM_SE)(0x00) -#define TPM_SE_POLICY (TPM_SE)(0x01) -#define TPM_SE_TRIAL (TPM_SE)(0x03) - -// Table 21 - TPM_CAP Constants -typedef UINT32 TPM_CAP; -#define TPM_CAP_FIRST (TPM_CAP)(0x00000000) -#define TPM_CAP_ALGS (TPM_CAP)(0x00000000) -#define TPM_CAP_HANDLES (TPM_CAP)(0x00000001) -#define TPM_CAP_COMMANDS (TPM_CAP)(0x00000002) -#define TPM_CAP_PP_COMMANDS (TPM_CAP)(0x00000003) -#define TPM_CAP_AUDIT_COMMANDS (TPM_CAP)(0x00000004) -#define TPM_CAP_PCRS (TPM_CAP)(0x00000005) -#define TPM_CAP_TPM_PROPERTIES (TPM_CAP)(0x00000006) -#define TPM_CAP_PCR_PROPERTIES (TPM_CAP)(0x00000007) -#define TPM_CAP_ECC_CURVES (TPM_CAP)(0x00000008) -#define TPM_CAP_LAST (TPM_CAP)(0x00000008) -#define TPM_CAP_VENDOR_PROPERTY (TPM_CAP)(0x00000100) - -// Table 22 - TPM_PT Constants -typedef UINT32 TPM_PT; -#define TPM_PT_NONE (TPM_PT)(0x00000000) -#define PT_GROUP (TPM_PT)(0x00000100) -#define PT_FIXED (TPM_PT)(PT_GROUP * 1) -#define TPM_PT_FAMILY_INDICATOR (TPM_PT)(PT_FIXED + 0) -#define TPM_PT_LEVEL (TPM_PT)(PT_FIXED + 1) -#define TPM_PT_REVISION (TPM_PT)(PT_FIXED + 2) -#define TPM_PT_DAY_OF_YEAR (TPM_PT)(PT_FIXED + 3) -#define TPM_PT_YEAR (TPM_PT)(PT_FIXED + 4) -#define TPM_PT_MANUFACTURER (TPM_PT)(PT_FIXED + 5) -#define TPM_PT_VENDOR_STRING_1 (TPM_PT)(PT_FIXED + 6) -#define TPM_PT_VENDOR_STRING_2 (TPM_PT)(PT_FIXED + 7) -#define TPM_PT_VENDOR_STRING_3 (TPM_PT)(PT_FIXED + 8) -#define TPM_PT_VENDOR_STRING_4 (TPM_PT)(PT_FIXED + 9) -#define TPM_PT_VENDOR_TPM_TYPE (TPM_PT)(PT_FIXED + 10) -#define TPM_PT_FIRMWARE_VERSION_1 (TPM_PT)(PT_FIXED + 11) -#define TPM_PT_FIRMWARE_VERSION_2 (TPM_PT)(PT_FIXED + 12) -#define TPM_PT_INPUT_BUFFER (TPM_PT)(PT_FIXED + 13) -#define TPM_PT_HR_TRANSIENT_MIN (TPM_PT)(PT_FIXED + 14) -#define TPM_PT_HR_PERSISTENT_MIN (TPM_PT)(PT_FIXED + 15) -#define TPM_PT_HR_LOADED_MIN (TPM_PT)(PT_FIXED + 16) -#define TPM_PT_ACTIVE_SESSIONS_MAX (TPM_PT)(PT_FIXED + 17) -#define TPM_PT_PCR_COUNT (TPM_PT)(PT_FIXED + 18) -#define TPM_PT_PCR_SELECT_MIN (TPM_PT)(PT_FIXED + 19) -#define TPM_PT_CONTEXT_GAP_MAX (TPM_PT)(PT_FIXED + 20) -#define TPM_PT_NV_COUNTERS_MAX (TPM_PT)(PT_FIXED + 22) -#define TPM_PT_NV_INDEX_MAX (TPM_PT)(PT_FIXED + 23) -#define TPM_PT_MEMORY (TPM_PT)(PT_FIXED + 24) -#define TPM_PT_CLOCK_UPDATE (TPM_PT)(PT_FIXED + 25) -#define TPM_PT_CONTEXT_HASH (TPM_PT)(PT_FIXED + 26) -#define TPM_PT_CONTEXT_SYM (TPM_PT)(PT_FIXED + 27) -#define TPM_PT_CONTEXT_SYM_SIZE (TPM_PT)(PT_FIXED + 28) -#define TPM_PT_ORDERLY_COUNT (TPM_PT)(PT_FIXED + 29) -#define TPM_PT_MAX_COMMAND_SIZE (TPM_PT)(PT_FIXED + 30) -#define TPM_PT_MAX_RESPONSE_SIZE (TPM_PT)(PT_FIXED + 31) -#define TPM_PT_MAX_DIGEST (TPM_PT)(PT_FIXED + 32) -#define TPM_PT_MAX_OBJECT_CONTEXT (TPM_PT)(PT_FIXED + 33) -#define TPM_PT_MAX_SESSION_CONTEXT (TPM_PT)(PT_FIXED + 34) -#define TPM_PT_PS_FAMILY_INDICATOR (TPM_PT)(PT_FIXED + 35) -#define TPM_PT_PS_LEVEL (TPM_PT)(PT_FIXED + 36) -#define TPM_PT_PS_REVISION (TPM_PT)(PT_FIXED + 37) -#define TPM_PT_PS_DAY_OF_YEAR (TPM_PT)(PT_FIXED + 38) -#define TPM_PT_PS_YEAR (TPM_PT)(PT_FIXED + 39) -#define TPM_PT_SPLIT_MAX (TPM_PT)(PT_FIXED + 40) -#define TPM_PT_TOTAL_COMMANDS (TPM_PT)(PT_FIXED + 41) -#define TPM_PT_LIBRARY_COMMANDS (TPM_PT)(PT_FIXED + 42) -#define TPM_PT_VENDOR_COMMANDS (TPM_PT)(PT_FIXED + 43) -#define PT_VAR (TPM_PT)(PT_GROUP * 2) -#define TPM_PT_PERMANENT (TPM_PT)(PT_VAR + 0) -#define TPM_PT_STARTUP_CLEAR (TPM_PT)(PT_VAR + 1) -#define TPM_PT_HR_NV_INDEX (TPM_PT)(PT_VAR + 2) -#define TPM_PT_HR_LOADED (TPM_PT)(PT_VAR + 3) -#define TPM_PT_HR_LOADED_AVAIL (TPM_PT)(PT_VAR + 4) -#define TPM_PT_HR_ACTIVE (TPM_PT)(PT_VAR + 5) -#define TPM_PT_HR_ACTIVE_AVAIL (TPM_PT)(PT_VAR + 6) -#define TPM_PT_HR_TRANSIENT_AVAIL (TPM_PT)(PT_VAR + 7) -#define TPM_PT_HR_PERSISTENT (TPM_PT)(PT_VAR + 8) -#define TPM_PT_HR_PERSISTENT_AVAIL (TPM_PT)(PT_VAR + 9) -#define TPM_PT_NV_COUNTERS (TPM_PT)(PT_VAR + 10) -#define TPM_PT_NV_COUNTERS_AVAIL (TPM_PT)(PT_VAR + 11) -#define TPM_PT_ALGORITHM_SET (TPM_PT)(PT_VAR + 12) -#define TPM_PT_LOADED_CURVES (TPM_PT)(PT_VAR + 13) -#define TPM_PT_LOCKOUT_COUNTER (TPM_PT)(PT_VAR + 14) -#define TPM_PT_MAX_AUTH_FAIL (TPM_PT)(PT_VAR + 15) -#define TPM_PT_LOCKOUT_INTERVAL (TPM_PT)(PT_VAR + 16) -#define TPM_PT_LOCKOUT_RECOVERY (TPM_PT)(PT_VAR + 17) -#define TPM_PT_NV_WRITE_RECOVERY (TPM_PT)(PT_VAR + 18) -#define TPM_PT_AUDIT_COUNTER_0 (TPM_PT)(PT_VAR + 19) -#define TPM_PT_AUDIT_COUNTER_1 (TPM_PT)(PT_VAR + 20) - -// Table 23 - TPM_PT_PCR Constants -typedef UINT32 TPM_PT_PCR; -#define TPM_PT_PCR_FIRST (TPM_PT_PCR)(0x00000000) -#define TPM_PT_PCR_SAVE (TPM_PT_PCR)(0x00000000) -#define TPM_PT_PCR_EXTEND_L0 (TPM_PT_PCR)(0x00000001) -#define TPM_PT_PCR_RESET_L0 (TPM_PT_PCR)(0x00000002) -#define TPM_PT_PCR_EXTEND_L1 (TPM_PT_PCR)(0x00000003) -#define TPM_PT_PCR_RESET_L1 (TPM_PT_PCR)(0x00000004) -#define TPM_PT_PCR_EXTEND_L2 (TPM_PT_PCR)(0x00000005) -#define TPM_PT_PCR_RESET_L2 (TPM_PT_PCR)(0x00000006) -#define TPM_PT_PCR_EXTEND_L3 (TPM_PT_PCR)(0x00000007) -#define TPM_PT_PCR_RESET_L3 (TPM_PT_PCR)(0x00000008) -#define TPM_PT_PCR_EXTEND_L4 (TPM_PT_PCR)(0x00000009) -#define TPM_PT_PCR_RESET_L4 (TPM_PT_PCR)(0x0000000A) -#define TPM_PT_PCR_NO_INCREMENT (TPM_PT_PCR)(0x00000011) -#define TPM_PT_PCR_DRTM_RESET (TPM_PT_PCR)(0x00000012) -#define TPM_PT_PCR_POLICY (TPM_PT_PCR)(0x00000013) -#define TPM_PT_PCR_AUTH (TPM_PT_PCR)(0x00000014) -#define TPM_PT_PCR_LAST (TPM_PT_PCR)(0x00000014) - -// Table 24 - TPM_PS Constants -typedef UINT32 TPM_PS; -#define TPM_PS_MAIN (TPM_PS)(0x00000000) -#define TPM_PS_PC (TPM_PS)(0x00000001) -#define TPM_PS_PDA (TPM_PS)(0x00000002) -#define TPM_PS_CELL_PHONE (TPM_PS)(0x00000003) -#define TPM_PS_SERVER (TPM_PS)(0x00000004) -#define TPM_PS_PERIPHERAL (TPM_PS)(0x00000005) -#define TPM_PS_TSS (TPM_PS)(0x00000006) -#define TPM_PS_STORAGE (TPM_PS)(0x00000007) -#define TPM_PS_AUTHENTICATION (TPM_PS)(0x00000008) -#define TPM_PS_EMBEDDED (TPM_PS)(0x00000009) -#define TPM_PS_HARDCOPY (TPM_PS)(0x0000000A) -#define TPM_PS_INFRASTRUCTURE (TPM_PS)(0x0000000B) -#define TPM_PS_VIRTUALIZATION (TPM_PS)(0x0000000C) -#define TPM_PS_TNC (TPM_PS)(0x0000000D) -#define TPM_PS_MULTI_TENANT (TPM_PS)(0x0000000E) -#define TPM_PS_TC (TPM_PS)(0x0000000F) - -// 7 Handles - -// Table 25 - Handles Types -// -// NOTE: Comment because it has same name as TPM1.2 (value is same, so not runtime issue) -// -//typedef UINT32 TPM_HANDLE; - -// Table 26 - TPM_HT Constants -typedef UINT8 TPM_HT; -#define TPM_HT_PCR (TPM_HT)(0x00) -#define TPM_HT_NV_INDEX (TPM_HT)(0x01) -#define TPM_HT_HMAC_SESSION (TPM_HT)(0x02) -#define TPM_HT_LOADED_SESSION (TPM_HT)(0x02) -#define TPM_HT_POLICY_SESSION (TPM_HT)(0x03) -#define TPM_HT_ACTIVE_SESSION (TPM_HT)(0x03) -#define TPM_HT_PERMANENT (TPM_HT)(0x40) -#define TPM_HT_TRANSIENT (TPM_HT)(0x80) -#define TPM_HT_PERSISTENT (TPM_HT)(0x81) - -// Table 27 - TPM_RH Constants -typedef UINT32 TPM_RH; -#define TPM_RH_FIRST (TPM_RH)(0x40000000) -#define TPM_RH_SRK (TPM_RH)(0x40000000) -#define TPM_RH_OWNER (TPM_RH)(0x40000001) -#define TPM_RH_REVOKE (TPM_RH)(0x40000002) -#define TPM_RH_TRANSPORT (TPM_RH)(0x40000003) -#define TPM_RH_OPERATOR (TPM_RH)(0x40000004) -#define TPM_RH_ADMIN (TPM_RH)(0x40000005) -#define TPM_RH_EK (TPM_RH)(0x40000006) -#define TPM_RH_NULL (TPM_RH)(0x40000007) -#define TPM_RH_UNASSIGNED (TPM_RH)(0x40000008) -#define TPM_RS_PW (TPM_RH)(0x40000009) -#define TPM_RH_LOCKOUT (TPM_RH)(0x4000000A) -#define TPM_RH_ENDORSEMENT (TPM_RH)(0x4000000B) -#define TPM_RH_PLATFORM (TPM_RH)(0x4000000C) -#define TPM_RH_PLATFORM_NV (TPM_RH)(0x4000000D) -#define TPM_RH_AUTH_00 (TPM_RH)(0x40000010) -#define TPM_RH_AUTH_FF (TPM_RH)(0x4000010F) -#define TPM_RH_LAST (TPM_RH)(0x4000010F) - -// Table 28 - TPM_HC Constants -typedef TPM_HANDLE TPM_HC; -#define HR_HANDLE_MASK (TPM_HC)(0x00FFFFFF) -#define HR_RANGE_MASK (TPM_HC)(0xFF000000) -#define HR_SHIFT (TPM_HC)(24) -#define HR_PCR (TPM_HC)((TPM_HC)TPM_HT_PCR << HR_SHIFT) -#define HR_HMAC_SESSION (TPM_HC)((TPM_HC)TPM_HT_HMAC_SESSION << HR_SHIFT) -#define HR_POLICY_SESSION (TPM_HC)((TPM_HC)TPM_HT_POLICY_SESSION << HR_SHIFT) -#define HR_TRANSIENT (TPM_HC)((TPM_HC)TPM_HT_TRANSIENT << HR_SHIFT) -#define HR_PERSISTENT (TPM_HC)((TPM_HC)TPM_HT_PERSISTENT << HR_SHIFT) -#define HR_NV_INDEX (TPM_HC)((TPM_HC)TPM_HT_NV_INDEX << HR_SHIFT) -#define HR_PERMANENT (TPM_HC)((TPM_HC)TPM_HT_PERMANENT << HR_SHIFT) -#define PCR_FIRST (TPM_HC)(HR_PCR + 0) -#define PCR_LAST (TPM_HC)(PCR_FIRST + IMPLEMENTATION_PCR - 1) -#define HMAC_SESSION_FIRST (TPM_HC)(HR_HMAC_SESSION + 0) -#define HMAC_SESSION_LAST (TPM_HC)(HMAC_SESSION_FIRST + MAX_ACTIVE_SESSIONS - 1) -#define LOADED_SESSION_FIRST (TPM_HC)(HMAC_SESSION_FIRST) -#define LOADED_SESSION_LAST (TPM_HC)(HMAC_SESSION_LAST) -#define POLICY_SESSION_FIRST (TPM_HC)(HR_POLICY_SESSION + 0) -#define POLICY_SESSION_LAST (TPM_HC)(POLICY_SESSION_FIRST + MAX_ACTIVE_SESSIONS - 1) -#define TRANSIENT_FIRST (TPM_HC)(HR_TRANSIENT + 0) -#define ACTIVE_SESSION_FIRST (TPM_HC)(POLICY_SESSION_FIRST) -#define ACTIVE_SESSION_LAST (TPM_HC)(POLICY_SESSION_LAST) -#define TRANSIENT_LAST (TPM_HC)(TRANSIENT_FIRST+MAX_LOADED_OBJECTS - 1) -#define PERSISTENT_FIRST (TPM_HC)(HR_PERSISTENT + 0) -#define PERSISTENT_LAST (TPM_HC)(PERSISTENT_FIRST + 0x00FFFFFF) -#define PLATFORM_PERSISTENT (TPM_HC)(PERSISTENT_FIRST + 0x00800000) -#define NV_INDEX_FIRST (TPM_HC)(HR_NV_INDEX + 0) -#define NV_INDEX_LAST (TPM_HC)(NV_INDEX_FIRST + 0x00FFFFFF) -#define PERMANENT_FIRST (TPM_HC)(TPM_RH_FIRST) -#define PERMANENT_LAST (TPM_HC)(TPM_RH_LAST) - -// 8 Attribute Structures - -// Table 29 - TPMA_ALGORITHM Bits -typedef struct { - UINT32 asymmetric : 1; - UINT32 symmetric : 1; - UINT32 hash : 1; - UINT32 object : 1; - UINT32 reserved4_7 : 4; - UINT32 signing : 1; - UINT32 encrypting : 1; - UINT32 method : 1; - UINT32 reserved11_31 : 21; -} TPMA_ALGORITHM; - -// Table 30 - TPMA_OBJECT Bits -typedef struct { - UINT32 reserved1 : 1; - UINT32 fixedTPM : 1; - UINT32 stClear : 1; - UINT32 reserved4 : 1; - UINT32 fixedParent : 1; - UINT32 sensitiveDataOrigin : 1; - UINT32 userWithAuth : 1; - UINT32 adminWithPolicy : 1; - UINT32 reserved8_9 : 2; - UINT32 noDA : 1; - UINT32 encryptedDuplication : 1; - UINT32 reserved12_15 : 4; - UINT32 restricted : 1; - UINT32 decrypt : 1; - UINT32 sign : 1; - UINT32 reserved19_31 : 13; -} TPMA_OBJECT; - -// Table 31 - TPMA_SESSION Bits -typedef struct { - UINT8 continueSession : 1; - UINT8 auditExclusive : 1; - UINT8 auditReset : 1; - UINT8 reserved3_4 : 2; - UINT8 decrypt : 1; - UINT8 encrypt : 1; - UINT8 audit : 1; -} TPMA_SESSION; - -// Table 32 - TPMA_LOCALITY Bits -// -// NOTE: Use low case here to resolve conflict -// -typedef struct { - UINT8 locZero : 1; - UINT8 locOne : 1; - UINT8 locTwo : 1; - UINT8 locThree : 1; - UINT8 locFour : 1; - UINT8 Extended : 3; -} TPMA_LOCALITY; - -// Table 33 - TPMA_PERMANENT Bits -typedef struct { - UINT32 ownerAuthSet : 1; - UINT32 endorsementAuthSet : 1; - UINT32 lockoutAuthSet : 1; - UINT32 reserved3_7 : 5; - UINT32 disableClear : 1; - UINT32 inLockout : 1; - UINT32 tpmGeneratedEPS : 1; - UINT32 reserved11_31 : 21; -} TPMA_PERMANENT; - -// Table 34 - TPMA_STARTUP_CLEAR Bits -typedef struct { - UINT32 phEnable : 1; - UINT32 shEnable : 1; - UINT32 ehEnable : 1; - UINT32 reserved3_30 : 28; - UINT32 orderly : 1; -} TPMA_STARTUP_CLEAR; - -// Table 35 - TPMA_MEMORY Bits -typedef struct { - UINT32 sharedRAM : 1; - UINT32 sharedNV : 1; - UINT32 objectCopiedToRam : 1; - UINT32 reserved3_31 : 29; -} TPMA_MEMORY; - -// Table 36 - TPMA_CC Bits -typedef struct { - UINT32 commandIndex : 16; - UINT32 reserved16_21 : 6; - UINT32 nv : 1; - UINT32 extensive : 1; - UINT32 flushed : 1; - UINT32 cHandles : 3; - UINT32 rHandle : 1; - UINT32 V : 1; - UINT32 Res : 2; -} TPMA_CC; - -// 9 Interface Types - -// Table 37 - TPMI_YES_NO Type -typedef BYTE TPMI_YES_NO; - -// Table 38 - TPMI_DH_OBJECT Type -typedef TPM_HANDLE TPMI_DH_OBJECT; - -// Table 39 - TPMI_DH_PERSISTENT Type -typedef TPM_HANDLE TPMI_DH_PERSISTENT; - -// Table 40 - TPMI_DH_ENTITY Type -typedef TPM_HANDLE TPMI_DH_ENTITY; - -// Table 41 - TPMI_DH_PCR Type -typedef TPM_HANDLE TPMI_DH_PCR; - -// Table 42 - TPMI_SH_AUTH_SESSION Type -typedef TPM_HANDLE TPMI_SH_AUTH_SESSION; - -// Table 43 - TPMI_SH_HMAC Type -typedef TPM_HANDLE TPMI_SH_HMAC; - -// Table 44 - TPMI_SH_POLICY Type -typedef TPM_HANDLE TPMI_SH_POLICY; - -// Table 45 - TPMI_DH_CONTEXT Type -typedef TPM_HANDLE TPMI_DH_CONTEXT; - -// Table 46 - TPMI_RH_HIERARCHY Type -typedef TPM_HANDLE TPMI_RH_HIERARCHY; - -// Table 47 - TPMI_RH_HIERARCHY_AUTH Type -typedef TPM_HANDLE TPMI_RH_HIERARCHY_AUTH; - -// Table 48 - TPMI_RH_PLATFORM Type -typedef TPM_HANDLE TPMI_RH_PLATFORM; - -// Table 49 - TPMI_RH_OWNER Type -typedef TPM_HANDLE TPMI_RH_OWNER; - -// Table 50 - TPMI_RH_ENDORSEMENT Type -typedef TPM_HANDLE TPMI_RH_ENDORSEMENT; - -// Table 51 - TPMI_RH_PROVISION Type -typedef TPM_HANDLE TPMI_RH_PROVISION; - -// Table 52 - TPMI_RH_CLEAR Type -typedef TPM_HANDLE TPMI_RH_CLEAR; - -// Table 53 - TPMI_RH_NV_AUTH Type -typedef TPM_HANDLE TPMI_RH_NV_AUTH; - -// Table 54 - TPMI_RH_LOCKOUT Type -typedef TPM_HANDLE TPMI_RH_LOCKOUT; - -// Table 55 - TPMI_RH_NV_INDEX Type -typedef TPM_HANDLE TPMI_RH_NV_INDEX; - -// Table 56 - TPMI_ALG_HASH Type -typedef TPM_ALG_ID TPMI_ALG_HASH; - -// Table 57 - TPMI_ALG_ASYM Type -typedef TPM_ALG_ID TPMI_ALG_ASYM; - -// Table 58 - TPMI_ALG_SYM Type -typedef TPM_ALG_ID TPMI_ALG_SYM; - -// Table 59 - TPMI_ALG_SYM_OBJECT Type -typedef TPM_ALG_ID TPMI_ALG_SYM_OBJECT; - -// Table 60 - TPMI_ALG_SYM_MODE Type -typedef TPM_ALG_ID TPMI_ALG_SYM_MODE; - -// Table 61 - TPMI_ALG_KDF Type -typedef TPM_ALG_ID TPMI_ALG_KDF; - -// Table 62 - TPMI_ALG_SIG_SCHEME Type -typedef TPM_ALG_ID TPMI_ALG_SIG_SCHEME; - -// Table 63 - TPMI_ECC_KEY_EXCHANGE Type -typedef TPM_ALG_ID TPMI_ECC_KEY_EXCHANGE; - -// Table 64 - TPMI_ST_COMMAND_TAG Type -typedef TPM_ST TPMI_ST_COMMAND_TAG; - -// 10 Structure Definitions - -// Table 65 - TPMS_ALGORITHM_DESCRIPTION Structure -typedef struct { - TPM_ALG_ID alg; - TPMA_ALGORITHM attributes; -} TPMS_ALGORITHM_DESCRIPTION; - -// Table 66 - TPMU_HA Union -typedef union { - BYTE sha1[SHA1_DIGEST_SIZE]; - BYTE sha256[SHA256_DIGEST_SIZE]; - BYTE sm3_256[SM3_256_DIGEST_SIZE]; - BYTE sha384[SHA384_DIGEST_SIZE]; - BYTE sha512[SHA512_DIGEST_SIZE]; -} TPMU_HA; - -// Table 67 - TPMT_HA Structure -typedef struct { - TPMI_ALG_HASH hashAlg; - TPMU_HA digest; -} TPMT_HA; - -// Table 68 - TPM2B_DIGEST Structure -typedef struct { - UINT16 size; - BYTE buffer[sizeof(TPMU_HA)]; -} TPM2B_DIGEST; - -// Table 69 - TPM2B_DATA Structure -typedef struct { - UINT16 size; - BYTE buffer[sizeof(TPMT_HA)]; -} TPM2B_DATA; - -// Table 70 - TPM2B_NONCE Types -typedef TPM2B_DIGEST TPM2B_NONCE; - -// Table 71 - TPM2B_AUTH Types -typedef TPM2B_DIGEST TPM2B_AUTH; - -// Table 72 - TPM2B_OPERAND Types -typedef TPM2B_DIGEST TPM2B_OPERAND; - -// Table 73 - TPM2B_EVENT Structure -typedef struct { - UINT16 size; - BYTE buffer[1024]; -} TPM2B_EVENT; - -// Table 74 - TPM2B_MAX_BUFFER Structure -typedef struct { - UINT16 size; - BYTE buffer[MAX_DIGEST_BUFFER]; -} TPM2B_MAX_BUFFER; - -// Table 75 - TPM2B_MAX_NV_BUFFER Structure -typedef struct { - UINT16 size; - BYTE buffer[MAX_NV_INDEX_SIZE]; -} TPM2B_MAX_NV_BUFFER; - -// Table 76 - TPM2B_TIMEOUT Structure -typedef struct { - UINT16 size; - BYTE buffer[sizeof(UINT64)]; -} TPM2B_TIMEOUT; - -// Table 77 -- TPM2B_IV Structure <I/O> -typedef struct { - UINT16 size; - BYTE buffer[MAX_SYM_BLOCK_SIZE]; -} TPM2B_IV; - -// Table 78 - TPMU_NAME Union -typedef union { - TPMT_HA digest; - TPM_HANDLE handle; -} TPMU_NAME; - -// Table 79 - TPM2B_NAME Structure -typedef struct { - UINT16 size; - BYTE name[sizeof(TPMU_NAME)]; -} TPM2B_NAME; - -// Table 80 - TPMS_PCR_SELECT Structure -typedef struct { - UINT8 sizeofSelect; - BYTE pcrSelect[PCR_SELECT_MAX]; -} TPMS_PCR_SELECT; - -// Table 81 - TPMS_PCR_SELECTION Structure -typedef struct { - TPMI_ALG_HASH hash; - UINT8 sizeofSelect; - BYTE pcrSelect[PCR_SELECT_MAX]; -} TPMS_PCR_SELECTION; - -// Table 84 - TPMT_TK_CREATION Structure -typedef struct { - TPM_ST tag; - TPMI_RH_HIERARCHY hierarchy; - TPM2B_DIGEST digest; -} TPMT_TK_CREATION; - -// Table 85 - TPMT_TK_VERIFIED Structure -typedef struct { - TPM_ST tag; - TPMI_RH_HIERARCHY hierarchy; - TPM2B_DIGEST digest; -} TPMT_TK_VERIFIED; - -// Table 86 - TPMT_TK_AUTH Structure -typedef struct { - TPM_ST tag; - TPMI_RH_HIERARCHY hierarchy; - TPM2B_DIGEST digest; -} TPMT_TK_AUTH; - -// Table 87 - TPMT_TK_HASHCHECK Structure -typedef struct { - TPM_ST tag; - TPMI_RH_HIERARCHY hierarchy; - TPM2B_DIGEST digest; -} TPMT_TK_HASHCHECK; - -// Table 88 - TPMS_ALG_PROPERTY Structure -typedef struct { - TPM_ALG_ID alg; - TPMA_ALGORITHM algProperties; -} TPMS_ALG_PROPERTY; - -// Table 89 - TPMS_TAGGED_PROPERTY Structure -typedef struct { - TPM_PT property; - UINT32 value; -} TPMS_TAGGED_PROPERTY; - -// Table 90 - TPMS_TAGGED_PCR_SELECT Structure -typedef struct { - TPM_PT tag; - UINT8 sizeofSelect; - BYTE pcrSelect[PCR_SELECT_MAX]; -} TPMS_TAGGED_PCR_SELECT; - -// Table 91 - TPML_CC Structure -typedef struct { - UINT32 count; - TPM_CC commandCodes[MAX_CAP_CC]; -} TPML_CC; - -// Table 92 - TPML_CCA Structure -typedef struct { - UINT32 count; - TPMA_CC commandAttributes[MAX_CAP_CC]; -} TPML_CCA; - -// Table 93 - TPML_ALG Structure -typedef struct { - UINT32 count; - TPM_ALG_ID algorithms[MAX_ALG_LIST_SIZE]; -} TPML_ALG; - -// Table 94 - TPML_HANDLE Structure -typedef struct { - UINT32 count; - TPM_HANDLE handle[MAX_CAP_HANDLES]; -} TPML_HANDLE; - -// Table 95 - TPML_DIGEST Structure -typedef struct { - UINT32 count; - TPM2B_DIGEST digests[8]; -} TPML_DIGEST; - -// Table 96 -- TPML_DIGEST_VALUES Structure <I/O> -typedef struct { - UINT32 count; - TPMT_HA digests[HASH_COUNT]; -} TPML_DIGEST_VALUES; - -// Table 97 - TPM2B_DIGEST_VALUES Structure -typedef struct { - UINT16 size; - BYTE buffer[sizeof(TPML_DIGEST_VALUES)]; -} TPM2B_DIGEST_VALUES; - -// Table 98 - TPML_PCR_SELECTION Structure -typedef struct { - UINT32 count; - TPMS_PCR_SELECTION pcrSelections[HASH_COUNT]; -} TPML_PCR_SELECTION; - -// Table 99 - TPML_ALG_PROPERTY Structure -typedef struct { - UINT32 count; - TPMS_ALG_PROPERTY algProperties[MAX_CAP_ALGS]; -} TPML_ALG_PROPERTY; - -// Table 100 - TPML_TAGGED_TPM_PROPERTY Structure -typedef struct { - UINT32 count; - TPMS_TAGGED_PROPERTY tpmProperty[MAX_TPM_PROPERTIES]; -} TPML_TAGGED_TPM_PROPERTY; - -// Table 101 - TPML_TAGGED_PCR_PROPERTY Structure -typedef struct { - UINT32 count; - TPMS_TAGGED_PCR_SELECT pcrProperty[MAX_PCR_PROPERTIES]; -} TPML_TAGGED_PCR_PROPERTY; - -// Table 102 - TPML_ECC_CURVE Structure -typedef struct { - UINT32 count; - TPM_ECC_CURVE eccCurves[MAX_ECC_CURVES]; -} TPML_ECC_CURVE; - -// Table 103 - TPMU_CAPABILITIES Union -typedef union { - TPML_ALG_PROPERTY algorithms; - TPML_HANDLE handles; - TPML_CCA command; - TPML_CC ppCommands; - TPML_CC auditCommands; - TPML_PCR_SELECTION assignedPCR; - TPML_TAGGED_TPM_PROPERTY tpmProperties; - TPML_TAGGED_PCR_PROPERTY pcrProperties; - TPML_ECC_CURVE eccCurves; -} TPMU_CAPABILITIES; - -// Table 104 - TPMS_CAPABILITY_DATA Structure -typedef struct { - TPM_CAP capability; - TPMU_CAPABILITIES data; -} TPMS_CAPABILITY_DATA; - -// Table 105 - TPMS_CLOCK_INFO Structure -typedef struct { - UINT64 clock; - UINT32 resetCount; - UINT32 restartCount; - TPMI_YES_NO safe; -} TPMS_CLOCK_INFO; - -// Table 106 - TPMS_TIME_INFO Structure -typedef struct { - UINT64 time; - TPMS_CLOCK_INFO clockInfo; -} TPMS_TIME_INFO; - -// Table 107 - TPMS_TIME_ATTEST_INFO Structure -typedef struct { - TPMS_TIME_INFO time; - UINT64 firmwareVersion; -} TPMS_TIME_ATTEST_INFO; - -// Table 108 - TPMS_CERTIFY_INFO Structure -typedef struct { - TPM2B_NAME name; - TPM2B_NAME qualifiedName; -} TPMS_CERTIFY_INFO; - -// Table 109 - TPMS_QUOTE_INFO Structure -typedef struct { - TPML_PCR_SELECTION pcrSelect; - TPM2B_DIGEST pcrDigest; -} TPMS_QUOTE_INFO; - -// Table 110 - TPMS_COMMAND_AUDIT_INFO Structure -typedef struct { - UINT64 auditCounter; - TPM_ALG_ID digestAlg; - TPM2B_DIGEST auditDigest; - TPM2B_DIGEST commandDigest; -} TPMS_COMMAND_AUDIT_INFO; - -// Table 111 - TPMS_SESSION_AUDIT_INFO Structure -typedef struct { - TPMI_YES_NO exclusiveSession; - TPM2B_DIGEST sessionDigest; -} TPMS_SESSION_AUDIT_INFO; - -// Table 112 - TPMS_CREATION_INFO Structure -typedef struct { - TPM2B_NAME objectName; - TPM2B_DIGEST creationHash; -} TPMS_CREATION_INFO; - -// Table 113 - TPMS_NV_CERTIFY_INFO Structure -typedef struct { - TPM2B_NAME indexName; - UINT16 offset; - TPM2B_MAX_NV_BUFFER nvContents; -} TPMS_NV_CERTIFY_INFO; - -// Table 114 - TPMI_ST_ATTEST Type -typedef TPM_ST TPMI_ST_ATTEST; - -// Table 115 - TPMU_ATTEST Union -typedef union { - TPMS_CERTIFY_INFO certify; - TPMS_CREATION_INFO creation; - TPMS_QUOTE_INFO quote; - TPMS_COMMAND_AUDIT_INFO commandAudit; - TPMS_SESSION_AUDIT_INFO sessionAudit; - TPMS_TIME_ATTEST_INFO time; - TPMS_NV_CERTIFY_INFO nv; -} TPMU_ATTEST; - -// Table 116 - TPMS_ATTEST Structure -typedef struct { - TPM_GENERATED magic; - TPMI_ST_ATTEST type; - TPM2B_NAME qualifiedSigner; - TPM2B_DATA extraData; - TPMS_CLOCK_INFO clockInfo; - UINT64 firmwareVersion; - TPMU_ATTEST attested; -} TPMS_ATTEST; - -// Table 117 - TPM2B_ATTEST Structure -typedef struct { - UINT16 size; - BYTE attestationData[sizeof(TPMS_ATTEST)]; -} TPM2B_ATTEST; - -// Table 118 - TPMS_AUTH_COMMAND Structure -typedef struct { - TPMI_SH_AUTH_SESSION sessionHandle; - TPM2B_NONCE nonce; - TPMA_SESSION sessionAttributes; - TPM2B_AUTH hmac; -} TPMS_AUTH_COMMAND; - -// Table 119 - TPMS_AUTH_RESPONSE Structure -typedef struct { - TPM2B_NONCE nonce; - TPMA_SESSION sessionAttributes; - TPM2B_AUTH hmac; -} TPMS_AUTH_RESPONSE; - -// 11 Algorithm Parameters and Structures - -// Table 120 - TPMI_AES_KEY_BITS Type -typedef TPM_KEY_BITS TPMI_AES_KEY_BITS; - -// Table 121 - TPMI_SM4_KEY_BITS Type -typedef TPM_KEY_BITS TPMI_SM4_KEY_BITS; - -// Table 122 - TPMU_SYM_KEY_BITS Union -typedef union { - TPMI_AES_KEY_BITS aes; - TPMI_SM4_KEY_BITS SM4; - TPM_KEY_BITS sym; - TPMI_ALG_HASH xor; -} TPMU_SYM_KEY_BITS; - -// Table 123 - TPMU_SYM_MODE Union -typedef union { - TPMI_ALG_SYM_MODE aes; - TPMI_ALG_SYM_MODE SM4; - TPMI_ALG_SYM_MODE sym; -} TPMU_SYM_MODE; - -// Table 125 - TPMT_SYM_DEF Structure -typedef struct { - TPMI_ALG_SYM algorithm; - TPMU_SYM_KEY_BITS keyBits; - TPMU_SYM_MODE mode; -} TPMT_SYM_DEF; - -// Table 126 - TPMT_SYM_DEF_OBJECT Structure -typedef struct { - TPMI_ALG_SYM_OBJECT algorithm; - TPMU_SYM_KEY_BITS keyBits; - TPMU_SYM_MODE mode; -} TPMT_SYM_DEF_OBJECT; - -// Table 127 - TPM2B_SYM_KEY Structure -typedef struct { - UINT16 size; - BYTE buffer[MAX_SYM_KEY_BYTES]; -} TPM2B_SYM_KEY; - -// Table 128 - TPMS_SYMCIPHER_PARMS Structure -typedef struct { - TPMT_SYM_DEF_OBJECT sym; -} TPMS_SYMCIPHER_PARMS; - -// Table 129 - TPM2B_SENSITIVE_DATA Structure -typedef struct { - UINT16 size; - BYTE buffer[MAX_SYM_DATA]; -} TPM2B_SENSITIVE_DATA; - -// Table 130 - TPMS_SENSITIVE_CREATE Structure -typedef struct { - TPM2B_AUTH userAuth; - TPM2B_SENSITIVE_DATA data; -} TPMS_SENSITIVE_CREATE; - -// Table 131 - TPM2B_SENSITIVE_CREATE Structure -typedef struct { - UINT16 size; - TPMS_SENSITIVE_CREATE sensitive; -} TPM2B_SENSITIVE_CREATE; - -// Table 132 - TPMS_SCHEME_SIGHASH Structure -typedef struct { - TPMI_ALG_HASH hashAlg; -} TPMS_SCHEME_SIGHASH; - -// Table 133 - TPMI_ALG_KEYEDHASH_SCHEME Type -typedef TPM_ALG_ID TPMI_ALG_KEYEDHASH_SCHEME; - -// Table 134 - HMAC_SIG_SCHEME Types -typedef TPMS_SCHEME_SIGHASH TPMS_SCHEME_HMAC; - -// Table 135 - TPMS_SCHEME_XOR Structure -typedef struct { - TPMI_ALG_HASH hashAlg; - TPMI_ALG_KDF kdf; -} TPMS_SCHEME_XOR; - -// Table 136 - TPMU_SCHEME_KEYEDHASH Union -typedef union { - TPMS_SCHEME_HMAC hmac; - TPMS_SCHEME_XOR xor; -} TPMU_SCHEME_KEYEDHASH; - -// Table 137 - TPMT_KEYEDHASH_SCHEME Structure -typedef struct { - TPMI_ALG_KEYEDHASH_SCHEME scheme; - TPMU_SCHEME_KEYEDHASH details; -} TPMT_KEYEDHASH_SCHEME; - -// Table 138 - RSA_SIG_SCHEMES Types -typedef TPMS_SCHEME_SIGHASH TPMS_SCHEME_RSASSA; -typedef TPMS_SCHEME_SIGHASH TPMS_SCHEME_RSAPSS; - -// Table 139 - ECC_SIG_SCHEMES Types -typedef TPMS_SCHEME_SIGHASH TPMS_SCHEME_ECDSA; -typedef TPMS_SCHEME_SIGHASH TPMS_SCHEME_SM2; -typedef TPMS_SCHEME_SIGHASH TPMS_SCHEME_ECSCHNORR; - -// Table 140 - TPMS_SCHEME_ECDAA Structure -typedef struct { - TPMI_ALG_HASH hashAlg; - UINT16 count; -} TPMS_SCHEME_ECDAA; - -// Table 141 - TPMU_SIG_SCHEME Union -typedef union { - TPMS_SCHEME_RSASSA rsassa; - TPMS_SCHEME_RSAPSS rsapss; - TPMS_SCHEME_ECDSA ecdsa; - TPMS_SCHEME_ECDAA ecdaa; - TPMS_SCHEME_ECSCHNORR ecSchnorr; - TPMS_SCHEME_HMAC hmac; - TPMS_SCHEME_SIGHASH any; -} TPMU_SIG_SCHEME; - -// Table 142 - TPMT_SIG_SCHEME Structure -typedef struct { - TPMI_ALG_SIG_SCHEME scheme; - TPMU_SIG_SCHEME details; -} TPMT_SIG_SCHEME; - -// Table 143 - TPMS_SCHEME_OAEP Structure -typedef struct { - TPMI_ALG_HASH hashAlg; -} TPMS_SCHEME_OAEP; - -// Table 144 - TPMS_SCHEME_ECDH Structure -typedef struct { - TPMI_ALG_HASH hashAlg; -} TPMS_SCHEME_ECDH; - -// Table 145 - TPMS_SCHEME_MGF1 Structure -typedef struct { - TPMI_ALG_HASH hashAlg; -} TPMS_SCHEME_MGF1; - -// Table 146 - TPMS_SCHEME_KDF1_SP800_56a Structure -typedef struct { - TPMI_ALG_HASH hashAlg; -} TPMS_SCHEME_KDF1_SP800_56a; - -// Table 147 - TPMS_SCHEME_KDF2 Structure -typedef struct { - TPMI_ALG_HASH hashAlg; -} TPMS_SCHEME_KDF2; - -// Table 148 - TPMS_SCHEME_KDF1_SP800_108 Structure -typedef struct { - TPMI_ALG_HASH hashAlg; -} TPMS_SCHEME_KDF1_SP800_108; - -// Table 149 - TPMU_KDF_SCHEME Union -typedef union { - TPMS_SCHEME_MGF1 mgf1; - TPMS_SCHEME_KDF1_SP800_56a kdf1_SP800_56a; - TPMS_SCHEME_KDF2 kdf2; - TPMS_SCHEME_KDF1_SP800_108 kdf1_sp800_108; -} TPMU_KDF_SCHEME; - -// Table 150 - TPMT_KDF_SCHEME Structure -typedef struct { - TPMI_ALG_KDF scheme; - TPMU_KDF_SCHEME details; -} TPMT_KDF_SCHEME; - -// Table 151 - TPMI_ALG_ASYM_SCHEME Type -typedef TPM_ALG_ID TPMI_ALG_ASYM_SCHEME; - -// Table 152 - TPMU_ASYM_SCHEME Union -typedef union { - TPMS_SCHEME_RSASSA rsassa; - TPMS_SCHEME_RSAPSS rsapss; - TPMS_SCHEME_OAEP oaep; - TPMS_SCHEME_ECDSA ecdsa; - TPMS_SCHEME_ECDAA ecdaa; - TPMS_SCHEME_ECSCHNORR ecSchnorr; - TPMS_SCHEME_SIGHASH anySig; -} TPMU_ASYM_SCHEME; - -// Table 153 - TPMT_ASYM_SCHEME Structure -typedef struct { - TPMI_ALG_ASYM_SCHEME scheme; - TPMU_ASYM_SCHEME details; -} TPMT_ASYM_SCHEME; - -// Table 154 - TPMI_ALG_RSA_SCHEME Type -typedef TPM_ALG_ID TPMI_ALG_RSA_SCHEME; - -// Table 155 - TPMT_RSA_SCHEME Structure -typedef struct { - TPMI_ALG_RSA_SCHEME scheme; - TPMU_ASYM_SCHEME details; -} TPMT_RSA_SCHEME; - -// Table 156 - TPMI_ALG_RSA_DECRYPT Type -typedef TPM_ALG_ID TPMI_ALG_RSA_DECRYPT; - -// Table 157 - TPMT_RSA_DECRYPT Structure -typedef struct { - TPMI_ALG_RSA_DECRYPT scheme; - TPMU_ASYM_SCHEME details; -} TPMT_RSA_DECRYPT; - -// Table 158 - TPM2B_PUBLIC_KEY_RSA Structure -typedef struct { - UINT16 size; - BYTE buffer[MAX_RSA_KEY_BYTES]; -} TPM2B_PUBLIC_KEY_RSA; - -// Table 159 - TPMI_RSA_KEY_BITS Type -typedef TPM_KEY_BITS TPMI_RSA_KEY_BITS; - -// Table 160 - TPM2B_PRIVATE_KEY_RSA Structure -typedef struct { - UINT16 size; - BYTE buffer[MAX_RSA_KEY_BYTES/2]; -} TPM2B_PRIVATE_KEY_RSA; - -// Table 161 - TPM2B_ECC_PARAMETER Structure -typedef struct { - UINT16 size; - BYTE buffer[MAX_ECC_KEY_BYTES]; -} TPM2B_ECC_PARAMETER; - -// Table 162 - TPMS_ECC_POINT Structure -typedef struct { - TPM2B_ECC_PARAMETER x; - TPM2B_ECC_PARAMETER y; -} TPMS_ECC_POINT; - -// Table 163 -- TPM2B_ECC_POINT Structure <I/O> -typedef struct { - UINT16 size; - TPMS_ECC_POINT point; -} TPM2B_ECC_POINT; - -// Table 164 - TPMI_ALG_ECC_SCHEME Type -typedef TPM_ALG_ID TPMI_ALG_ECC_SCHEME; - -// Table 165 - TPMI_ECC_CURVE Type -typedef TPM_ECC_CURVE TPMI_ECC_CURVE; - -// Table 166 - TPMT_ECC_SCHEME Structure -typedef struct { - TPMI_ALG_ECC_SCHEME scheme; - TPMU_SIG_SCHEME details; -} TPMT_ECC_SCHEME; - -// Table 167 - TPMS_ALGORITHM_DETAIL_ECC Structure -typedef struct { - TPM_ECC_CURVE curveID; - UINT16 keySize; - TPMT_KDF_SCHEME kdf; - TPMT_ECC_SCHEME sign; - TPM2B_ECC_PARAMETER p; - TPM2B_ECC_PARAMETER a; - TPM2B_ECC_PARAMETER b; - TPM2B_ECC_PARAMETER gX; - TPM2B_ECC_PARAMETER gY; - TPM2B_ECC_PARAMETER n; - TPM2B_ECC_PARAMETER h; -} TPMS_ALGORITHM_DETAIL_ECC; - -// Table 168 - TPMS_SIGNATURE_RSASSA Structure -typedef struct { - TPMI_ALG_HASH hash; - TPM2B_PUBLIC_KEY_RSA sig; -} TPMS_SIGNATURE_RSASSA; - -// Table 169 - TPMS_SIGNATURE_RSAPSS Structure -typedef struct { - TPMI_ALG_HASH hash; - TPM2B_PUBLIC_KEY_RSA sig; -} TPMS_SIGNATURE_RSAPSS; - -// Table 170 - TPMS_SIGNATURE_ECDSA Structure -typedef struct { - TPMI_ALG_HASH hash; - TPM2B_ECC_PARAMETER signatureR; - TPM2B_ECC_PARAMETER signatureS; -} TPMS_SIGNATURE_ECDSA; - -// Table 171 - TPMU_SIGNATURE Union -typedef union { - TPMS_SIGNATURE_RSASSA rsassa; - TPMS_SIGNATURE_RSAPSS rsapss; - TPMS_SIGNATURE_ECDSA ecdsa; - TPMS_SIGNATURE_ECDSA sm2; - TPMS_SIGNATURE_ECDSA ecdaa; - TPMS_SIGNATURE_ECDSA ecschnorr; - TPMT_HA hmac; - TPMS_SCHEME_SIGHASH any; -} TPMU_SIGNATURE; - -// Table 172 - TPMT_SIGNATURE Structure -typedef struct { - TPMI_ALG_SIG_SCHEME sigAlg; - TPMU_SIGNATURE signature; -} TPMT_SIGNATURE; - -// Table 173 - TPMU_ENCRYPTED_SECRET Union -typedef union { - BYTE ecc[sizeof(TPMS_ECC_POINT)]; - BYTE rsa[MAX_RSA_KEY_BYTES]; - BYTE symmetric[sizeof(TPM2B_DIGEST)]; - BYTE keyedHash[sizeof(TPM2B_DIGEST)]; -} TPMU_ENCRYPTED_SECRET; - -// Table 174 - TPM2B_ENCRYPTED_SECRET Structure -typedef struct { - UINT16 size; - BYTE secret[sizeof(TPMU_ENCRYPTED_SECRET)]; -} TPM2B_ENCRYPTED_SECRET; - -// 12 Key/Object Complex - -// Table 175 - TPMI_ALG_PUBLIC Type -typedef TPM_ALG_ID TPMI_ALG_PUBLIC; - -// Table 176 - TPMU_PUBLIC_ID Union -typedef union { - TPM2B_DIGEST keyedHash; - TPM2B_DIGEST sym; - TPM2B_PUBLIC_KEY_RSA rsa; - TPMS_ECC_POINT ecc; -} TPMU_PUBLIC_ID; - -// Table 177 - TPMS_KEYEDHASH_PARMS Structure -typedef struct { - TPMT_KEYEDHASH_SCHEME scheme; -} TPMS_KEYEDHASH_PARMS; - -// Table 178 - TPMS_ASYM_PARMS Structure -typedef struct { - TPMT_SYM_DEF_OBJECT symmetric; - TPMT_ASYM_SCHEME scheme; -} TPMS_ASYM_PARMS; - -// Table 179 - TPMS_RSA_PARMS Structure -typedef struct { - TPMT_SYM_DEF_OBJECT symmetric; - TPMT_RSA_SCHEME scheme; - TPMI_RSA_KEY_BITS keyBits; - UINT32 exponent; -} TPMS_RSA_PARMS; - -// Table 180 - TPMS_ECC_PARMS Structure -typedef struct { - TPMT_SYM_DEF_OBJECT symmetric; - TPMT_ECC_SCHEME scheme; - TPMI_ECC_CURVE curveID; - TPMT_KDF_SCHEME kdf; -} TPMS_ECC_PARMS; - -// Table 181 - TPMU_PUBLIC_PARMS Union -typedef union { - TPMS_KEYEDHASH_PARMS keyedHashDetail; - TPMT_SYM_DEF_OBJECT symDetail; - TPMS_RSA_PARMS rsaDetail; - TPMS_ECC_PARMS eccDetail; - TPMS_ASYM_PARMS asymDetail; -} TPMU_PUBLIC_PARMS; - -// Table 182 - TPMT_PUBLIC_PARMS Structure -typedef struct { - TPMI_ALG_PUBLIC type; - TPMU_PUBLIC_PARMS parameters; -} TPMT_PUBLIC_PARMS; - -// Table 183 - TPMT_PUBLIC Structure -typedef struct { - TPMI_ALG_PUBLIC type; - TPMI_ALG_HASH nameAlg; - TPMA_OBJECT objectAttributes; - TPM2B_DIGEST authPolicy; - TPMU_PUBLIC_PARMS parameters; - TPMU_PUBLIC_ID unique; -} TPMT_PUBLIC; - -// Table 184 - TPM2B_PUBLIC Structure -typedef struct { - UINT16 size; - TPMT_PUBLIC publicArea; -} TPM2B_PUBLIC; - -// Table 185 - TPM2B_PRIVATE_VENDOR_SPECIFIC Structure -typedef struct { - UINT16 size; - BYTE buffer[PRIVATE_VENDOR_SPECIFIC_BYTES]; -} TPM2B_PRIVATE_VENDOR_SPECIFIC; - -// Table 186 - TPMU_SENSITIVE_COMPOSITE Union -typedef union { - TPM2B_PRIVATE_KEY_RSA rsa; - TPM2B_ECC_PARAMETER ecc; - TPM2B_SENSITIVE_DATA bits; - TPM2B_SYM_KEY sym; - TPM2B_PRIVATE_VENDOR_SPECIFIC any; -} TPMU_SENSITIVE_COMPOSITE; - -// Table 187 - TPMT_SENSITIVE Structure -typedef struct { - TPMI_ALG_PUBLIC sensitiveType; - TPM2B_AUTH authValue; - TPM2B_DIGEST seedValue; - TPMU_SENSITIVE_COMPOSITE sensitive; -} TPMT_SENSITIVE; - -// Table 188 - TPM2B_SENSITIVE Structure -typedef struct { - UINT16 size; - TPMT_SENSITIVE sensitiveArea; -} TPM2B_SENSITIVE; - -// Table 189 - _PRIVATE Structure -typedef struct { - TPM2B_DIGEST integrityOuter; - TPM2B_DIGEST integrityInner; - TPMT_SENSITIVE sensitive; -} _PRIVATE; - -// Table 190 - TPM2B_PRIVATE Structure -typedef struct { - UINT16 size; - BYTE buffer[sizeof(_PRIVATE)]; -} TPM2B_PRIVATE; - -// Table 191 - _ID_OBJECT Structure -typedef struct { - TPM2B_DIGEST integrityHMAC; - TPM2B_DIGEST encIdentity; -} _ID_OBJECT; - -// Table 192 - TPM2B_ID_OBJECT Structure -typedef struct { - UINT16 size; - BYTE credential[sizeof(_ID_OBJECT)]; -} TPM2B_ID_OBJECT; - -// 13 NV Storage Structures - -// Table 193 - TPM_NV_INDEX Bits -// -// NOTE: Comment here to resolve conflict -// -//typedef struct { -// UINT32 index : 22; -// UINT32 space : 2; -// UINT32 RH_NV : 8; -//} TPM_NV_INDEX; - -// Table 195 - TPMA_NV Bits -typedef struct { - UINT32 TPMA_NV_PPWRITE : 1; - UINT32 TPMA_NV_OWNERWRITE : 1; - UINT32 TPMA_NV_AUTHWRITE : 1; - UINT32 TPMA_NV_POLICYWRITE : 1; - UINT32 TPMA_NV_COUNTER : 1; - UINT32 TPMA_NV_BITS : 1; - UINT32 TPMA_NV_EXTEND : 1; - UINT32 reserved7_9 : 3; - UINT32 TPMA_NV_POLICY_DELETE : 1; - UINT32 TPMA_NV_WRITELOCKED : 1; - UINT32 TPMA_NV_WRITEALL : 1; - UINT32 TPMA_NV_WRITEDEFINE : 1; - UINT32 TPMA_NV_WRITE_STCLEAR : 1; - UINT32 TPMA_NV_GLOBALLOCK : 1; - UINT32 TPMA_NV_PPREAD : 1; - UINT32 TPMA_NV_OWNERREAD : 1; - UINT32 TPMA_NV_AUTHREAD : 1; - UINT32 TPMA_NV_POLICYREAD : 1; - UINT32 reserved20_24 : 5; - UINT32 TPMA_NV_NO_DA : 1; - UINT32 TPMA_NV_ORDERLY : 1; - UINT32 TPMA_NV_CLEAR_STCLEAR : 1; - UINT32 TPMA_NV_READLOCKED : 1; - UINT32 TPMA_NV_WRITTEN : 1; - UINT32 TPMA_NV_PLATFORMCREATE : 1; - UINT32 TPMA_NV_READ_STCLEAR : 1; -} TPMA_NV; - -// Table 196 - TPMS_NV_PUBLIC Structure -typedef struct { - TPMI_RH_NV_INDEX nvIndex; - TPMI_ALG_HASH nameAlg; - TPMA_NV attributes; - TPM2B_DIGEST authPolicy; - UINT16 dataSize; -} TPMS_NV_PUBLIC; - -// Table 197 - TPM2B_NV_PUBLIC Structure -typedef struct { - UINT16 size; - TPMS_NV_PUBLIC nvPublic; -} TPM2B_NV_PUBLIC; - -// 14 Context Data - -// Table 198 - TPM2B_CONTEXT_SENSITIVE Structure -typedef struct { - UINT16 size; - BYTE buffer[MAX_CONTEXT_SIZE]; -} TPM2B_CONTEXT_SENSITIVE; - -// Table 199 - TPMS_CONTEXT_DATA Structure -typedef struct { - TPM2B_DIGEST integrity; - TPM2B_CONTEXT_SENSITIVE encrypted; -} TPMS_CONTEXT_DATA; - -// Table 200 - TPM2B_CONTEXT_DATA Structure -typedef struct { - UINT16 size; - BYTE buffer[sizeof(TPMS_CONTEXT_DATA)]; -} TPM2B_CONTEXT_DATA; - -// Table 201 - TPMS_CONTEXT Structure -typedef struct { - UINT64 sequence; - TPMI_DH_CONTEXT savedHandle; - TPMI_RH_HIERARCHY hierarchy; - TPM2B_CONTEXT_DATA contextBlob; -} TPMS_CONTEXT; - -// 15 Creation Data - -// Table 203 - TPMS_CREATION_DATA Structure -typedef struct { - TPML_PCR_SELECTION pcrSelect; - TPM2B_DIGEST pcrDigest; - TPMA_LOCALITY locality; - TPM_ALG_ID parentNameAlg; - TPM2B_NAME parentName; - TPM2B_NAME parentQualifiedName; - TPM2B_DATA outsideInfo; -} TPMS_CREATION_DATA; - -// Table 204 - TPM2B_CREATION_DATA Structure -typedef struct { - UINT16 size; - TPMS_CREATION_DATA creationData; -} TPM2B_CREATION_DATA; - - -// -// Command Header -// -typedef struct { - TPM_ST tag; - UINT32 paramSize; - TPM_CC commandCode; -} TPM2_COMMAND_HEADER; - -typedef struct { - TPM_ST tag; - UINT32 paramSize; - TPM_RC responseCode; -} TPM2_RESPONSE_HEADER; - -#pragma pack () - -// -// TCG Algorithm Registry -// -#define HASH_ALG_SHA1 0x00000001 -#define HASH_ALG_SHA256 0x00000002 -#define HASH_ALG_SHA384 0x00000004 -#define HASH_ALG_SHA512 0x00000008 -#define HASH_ALG_SM3_256 0x00000010 - -#endif diff --git a/roms/ipxe/src/include/ipxe/efi/IndustryStandard/UefiTcgPlatform.h b/roms/ipxe/src/include/ipxe/efi/IndustryStandard/UefiTcgPlatform.h index df65be914..8bb7ea389 100644 --- a/roms/ipxe/src/include/ipxe/efi/IndustryStandard/UefiTcgPlatform.h +++ b/roms/ipxe/src/include/ipxe/efi/IndustryStandard/UefiTcgPlatform.h @@ -1,7 +1,7 @@ /** @file TCG EFI Platform Definition in TCG_EFI_Platform_1_20_Final - Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR> + Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR> This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -18,14 +18,12 @@ FILE_LICENCE ( BSD3 ); #include <ipxe/efi/IndustryStandard/Tpm12.h> -#include <ipxe/efi/IndustryStandard/Tpm20.h> #include <ipxe/efi/Uefi.h> // // Standard event types // #define EV_POST_CODE ((TCG_EVENTTYPE) 0x00000001) -#define EV_NO_ACTION ((TCG_EVENTTYPE) 0x00000003) #define EV_SEPARATOR ((TCG_EVENTTYPE) 0x00000004) #define EV_S_CRTM_CONTENTS ((TCG_EVENTTYPE) 0x00000007) #define EV_S_CRTM_VERSION ((TCG_EVENTTYPE) 0x00000008) @@ -45,7 +43,6 @@ FILE_LICENCE ( BSD3 ); #define EV_EFI_ACTION (EV_EFI_EVENT_BASE + 7) #define EV_EFI_PLATFORM_FIRMWARE_BLOB (EV_EFI_EVENT_BASE + 8) #define EV_EFI_HANDOFF_TABLES (EV_EFI_EVENT_BASE + 9) -#define EV_EFI_VARIABLE_AUTHORITY (EV_EFI_EVENT_BASE + 0xE0) #define EFI_CALLING_EFI_APPLICATION \ "Calling EFI Application from Boot Option" @@ -77,9 +74,6 @@ FILE_LICENCE ( BSD3 ); #define EV_POSTCODE_INFO_OPROM "Embedded Option ROM" #define OPROM_LEN (sizeof(EV_POSTCODE_INFO_OPROM) - 1) -#define FIRMWARE_DEBUGGER_EVENT_STRING "UEFI Debug Mode" -#define FIRMWARE_DEBUGGER_EVENT_STRING_LEN (sizeof(FIRMWARE_DEBUGGER_EVENT_STRING) - 1) - // // Set structure alignment to 1-byte // @@ -162,17 +156,6 @@ typedef struct tdEFI_VARIABLE_DATA { INT8 VariableData[1]; ///< Driver or platform-specific data } EFI_VARIABLE_DATA; -// -// For TrEE1.0 compatibility -// -typedef struct { - EFI_GUID VariableName; - UINT64 UnicodeNameLength; // The TCG Definition used UINTN - UINT64 VariableDataLength; // The TCG Definition used UINTN - CHAR16 UnicodeName[1]; - INT8 VariableData[1]; -} EFI_VARIABLE_DATA_TREE; - typedef struct tdEFI_GPT_DATA { EFI_PARTITION_TABLE_HEADER EfiPartitionHeader; UINTN NumberOfPartitions; @@ -180,97 +163,6 @@ typedef struct tdEFI_GPT_DATA { } EFI_GPT_DATA; // -// Crypto Agile Log Entry Format -// -typedef struct tdTCG_PCR_EVENT2 { - TCG_PCRINDEX PCRIndex; - TCG_EVENTTYPE EventType; - TPML_DIGEST_VALUES Digest; - UINT32 EventSize; - UINT8 Event[1]; -} TCG_PCR_EVENT2; - -// -// Log Header Entry Data -// -typedef struct { - // - // TCG defined hashing algorithm ID. - // - UINT16 algorithmId; - // - // The size of the digest for the respective hashing algorithm. - // - UINT16 digestSize; -} TCG_EfiSpecIdEventAlgorithmSize; - -#define TCG_EfiSpecIDEventStruct_SIGNATURE_02 "Spec ID Event02" -#define TCG_EfiSpecIDEventStruct_SIGNATURE_03 "Spec ID Event03" - -#define TCG_EfiSpecIDEventStruct_SPEC_VERSION_MAJOR_TPM12 1 -#define TCG_EfiSpecIDEventStruct_SPEC_VERSION_MINOR_TPM12 2 -#define TCG_EfiSpecIDEventStruct_SPEC_ERRATA_TPM12 2 - -#define TCG_EfiSpecIDEventStruct_SPEC_VERSION_MAJOR_TPM2 2 -#define TCG_EfiSpecIDEventStruct_SPEC_VERSION_MINOR_TPM2 0 -#define TCG_EfiSpecIDEventStruct_SPEC_ERRATA_TPM2 0 - -typedef struct { - UINT8 signature[16]; - // - // The value for the Platform Class. - // The enumeration is defined in the TCG ACPI Specification Client Common Header. - // - UINT32 platformClass; - // - // The TCG EFI Platform Specification minor version number this BIOS supports. - // Any BIOS supporting version (1.22) MUST set this value to 02h. - // Any BIOS supporting version (2.0) SHALL set this value to 0x00. - // - UINT8 specVersionMinor; - // - // The TCG EFI Platform Specification major version number this BIOS supports. - // Any BIOS supporting version (1.22) MUST set this value to 01h. - // Any BIOS supporting version (2.0) SHALL set this value to 0x02. - // - UINT8 specVersionMajor; - // - // The TCG EFI Platform Specification errata for this specification this BIOS supports. - // Any BIOS supporting version and errata (1.22) MUST set this value to 02h. - // Any BIOS supporting version and errata (2.0) SHALL set this value to 0x00. - // - UINT8 specErrata; - // - // Specifies the size of the UINTN fields used in various data structures used in this specification. - // 0x01 indicates UINT32 and 0x02 indicates UINT64. - // - UINT8 uintnSize; - // - // This field is added in "Spec ID Event03". - // The number of hashing algorithms used in this event log (except the first event). - // All events in this event log use all hashing algorithms defined here. - // -//UINT32 numberOfAlgorithms; - // - // This field is added in "Spec ID Event03". - // An array of size numberOfAlgorithms of value pairs. - // -//TCG_EfiSpecIdEventAlgorithmSize digestSize[numberOfAlgorithms]; - // - // Size in bytes of the VendorInfo field. - // Maximum value SHALL be FFh bytes. - // -//UINT8 vendorInfoSize; - // - // Provided for use by the BIOS implementer. - // The value might be used, for example, to provide more detailed information about the specific BIOS such as BIOS revision numbers, etc. - // The values within this field are not standardized and are implementer-specific. - // Platform-specific or -unique information SHALL NOT be provided in this field. - // -//UINT8 vendorInfo[vendorInfoSize]; -} TCG_EfiSpecIDEventStruct; - -// // Restore original structure alignment // #pragma pack () diff --git a/roms/ipxe/src/include/ipxe/efi/IndustryStandard/Usb.h b/roms/ipxe/src/include/ipxe/efi/IndustryStandard/Usb.h deleted file mode 100644 index 7eb1a8d95..000000000 --- a/roms/ipxe/src/include/ipxe/efi/IndustryStandard/Usb.h +++ /dev/null @@ -1,388 +0,0 @@ -/** @file - Support for USB 2.0 standard. - - Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR> - This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#ifndef __USB_H__ -#define __USB_H__ - -FILE_LICENCE ( BSD3 ); - -// -// Subset of Class and Subclass definitions from USB Specs -// - -// -// Usb mass storage class code -// -#define USB_MASS_STORE_CLASS 0x08 - -// -// Usb mass storage subclass code, specify the command set used. -// -#define USB_MASS_STORE_RBC 0x01 ///< Reduced Block Commands -#define USB_MASS_STORE_8020I 0x02 ///< SFF-8020i, typically a CD/DVD device -#define USB_MASS_STORE_QIC 0x03 ///< Typically a tape device -#define USB_MASS_STORE_UFI 0x04 ///< Typically a floppy disk driver device -#define USB_MASS_STORE_8070I 0x05 ///< SFF-8070i, typically a floppy disk driver device. -#define USB_MASS_STORE_SCSI 0x06 ///< SCSI transparent command set - -// -// Usb mass storage protocol code, specify the transport protocol -// -#define USB_MASS_STORE_CBI0 0x00 ///< CBI protocol with command completion interrupt -#define USB_MASS_STORE_CBI1 0x01 ///< CBI protocol without command completion interrupt -#define USB_MASS_STORE_BOT 0x50 ///< Bulk-Only Transport - -// -// Standard device request and request type -// USB 2.0 spec, Section 9.4 -// -#define USB_DEV_GET_STATUS 0x00 -#define USB_DEV_GET_STATUS_REQ_TYPE_D 0x80 // Receiver : Device -#define USB_DEV_GET_STATUS_REQ_TYPE_I 0x81 // Receiver : Interface -#define USB_DEV_GET_STATUS_REQ_TYPE_E 0x82 // Receiver : Endpoint - -#define USB_DEV_CLEAR_FEATURE 0x01 -#define USB_DEV_CLEAR_FEATURE_REQ_TYPE_D 0x00 // Receiver : Device -#define USB_DEV_CLEAR_FEATURE_REQ_TYPE_I 0x01 // Receiver : Interface -#define USB_DEV_CLEAR_FEATURE_REQ_TYPE_E 0x02 // Receiver : Endpoint - -#define USB_DEV_SET_FEATURE 0x03 -#define USB_DEV_SET_FEATURE_REQ_TYPE_D 0x00 // Receiver : Device -#define USB_DEV_SET_FEATURE_REQ_TYPE_I 0x01 // Receiver : Interface -#define USB_DEV_SET_FEATURE_REQ_TYPE_E 0x02 // Receiver : Endpoint - -#define USB_DEV_SET_ADDRESS 0x05 -#define USB_DEV_SET_ADDRESS_REQ_TYPE 0x00 - -#define USB_DEV_GET_DESCRIPTOR 0x06 -#define USB_DEV_GET_DESCRIPTOR_REQ_TYPE 0x80 - -#define USB_DEV_SET_DESCRIPTOR 0x07 -#define USB_DEV_SET_DESCRIPTOR_REQ_TYPE 0x00 - -#define USB_DEV_GET_CONFIGURATION 0x08 -#define USB_DEV_GET_CONFIGURATION_REQ_TYPE 0x80 - -#define USB_DEV_SET_CONFIGURATION 0x09 -#define USB_DEV_SET_CONFIGURATION_REQ_TYPE 0x00 - -#define USB_DEV_GET_INTERFACE 0x0A -#define USB_DEV_GET_INTERFACE_REQ_TYPE 0x81 - -#define USB_DEV_SET_INTERFACE 0x0B -#define USB_DEV_SET_INTERFACE_REQ_TYPE 0x01 - -#define USB_DEV_SYNCH_FRAME 0x0C -#define USB_DEV_SYNCH_FRAME_REQ_TYPE 0x82 - - -// -// USB standard descriptors and reqeust -// -#pragma pack(1) - -/// -/// Format of Setup Data for USB Device Requests -/// USB 2.0 spec, Section 9.3 -/// -typedef struct { - UINT8 RequestType; - UINT8 Request; - UINT16 Value; - UINT16 Index; - UINT16 Length; -} USB_DEVICE_REQUEST; - -/// -/// Standard Device Descriptor -/// USB 2.0 spec, Section 9.6.1 -/// -typedef struct { - UINT8 Length; - UINT8 DescriptorType; - UINT16 BcdUSB; - UINT8 DeviceClass; - UINT8 DeviceSubClass; - UINT8 DeviceProtocol; - UINT8 MaxPacketSize0; - UINT16 IdVendor; - UINT16 IdProduct; - UINT16 BcdDevice; - UINT8 StrManufacturer; - UINT8 StrProduct; - UINT8 StrSerialNumber; - UINT8 NumConfigurations; -} USB_DEVICE_DESCRIPTOR; - -/// -/// Standard Configuration Descriptor -/// USB 2.0 spec, Section 9.6.3 -/// -typedef struct { - UINT8 Length; - UINT8 DescriptorType; - UINT16 TotalLength; - UINT8 NumInterfaces; - UINT8 ConfigurationValue; - UINT8 Configuration; - UINT8 Attributes; - UINT8 MaxPower; -} USB_CONFIG_DESCRIPTOR; - -/// -/// Standard Interface Descriptor -/// USB 2.0 spec, Section 9.6.5 -/// -typedef struct { - UINT8 Length; - UINT8 DescriptorType; - UINT8 InterfaceNumber; - UINT8 AlternateSetting; - UINT8 NumEndpoints; - UINT8 InterfaceClass; - UINT8 InterfaceSubClass; - UINT8 InterfaceProtocol; - UINT8 Interface; -} USB_INTERFACE_DESCRIPTOR; - -/// -/// Standard Endpoint Descriptor -/// USB 2.0 spec, Section 9.6.6 -/// -typedef struct { - UINT8 Length; - UINT8 DescriptorType; - UINT8 EndpointAddress; - UINT8 Attributes; - UINT16 MaxPacketSize; - UINT8 Interval; -} USB_ENDPOINT_DESCRIPTOR; - -/// -/// UNICODE String Descriptor -/// USB 2.0 spec, Section 9.6.7 -/// -typedef struct { - UINT8 Length; - UINT8 DescriptorType; - CHAR16 String[1]; -} EFI_USB_STRING_DESCRIPTOR; - -#pragma pack() - - -typedef enum { - // - // USB request type - // - USB_REQ_TYPE_STANDARD = (0x00 << 5), - USB_REQ_TYPE_CLASS = (0x01 << 5), - USB_REQ_TYPE_VENDOR = (0x02 << 5), - - // - // Standard control transfer request type, or the value - // to fill in EFI_USB_DEVICE_REQUEST.Request - // - USB_REQ_GET_STATUS = 0x00, - USB_REQ_CLEAR_FEATURE = 0x01, - USB_REQ_SET_FEATURE = 0x03, - USB_REQ_SET_ADDRESS = 0x05, - USB_REQ_GET_DESCRIPTOR = 0x06, - USB_REQ_SET_DESCRIPTOR = 0x07, - USB_REQ_GET_CONFIG = 0x08, - USB_REQ_SET_CONFIG = 0x09, - USB_REQ_GET_INTERFACE = 0x0A, - USB_REQ_SET_INTERFACE = 0x0B, - USB_REQ_SYNCH_FRAME = 0x0C, - - // - // Usb control transfer target - // - USB_TARGET_DEVICE = 0, - USB_TARGET_INTERFACE = 0x01, - USB_TARGET_ENDPOINT = 0x02, - USB_TARGET_OTHER = 0x03, - - // - // USB Descriptor types - // - USB_DESC_TYPE_DEVICE = 0x01, - USB_DESC_TYPE_CONFIG = 0x02, - USB_DESC_TYPE_STRING = 0x03, - USB_DESC_TYPE_INTERFACE = 0x04, - USB_DESC_TYPE_ENDPOINT = 0x05, - USB_DESC_TYPE_HID = 0x21, - USB_DESC_TYPE_REPORT = 0x22, - - // - // Features to be cleared by CLEAR_FEATURE requests - // - USB_FEATURE_ENDPOINT_HALT = 0, - - // - // USB endpoint types: 00: control, 01: isochronous, 10: bulk, 11: interrupt - // - USB_ENDPOINT_CONTROL = 0x00, - USB_ENDPOINT_ISO = 0x01, - USB_ENDPOINT_BULK = 0x02, - USB_ENDPOINT_INTERRUPT = 0x03, - - USB_ENDPOINT_TYPE_MASK = 0x03, - USB_ENDPOINT_DIR_IN = 0x80, - - // - //Use 200 ms to increase the error handling response time - // - EFI_USB_INTERRUPT_DELAY = 2000000 -} USB_TYPES_DEFINITION; - - -// -// HID constants definition, see Device Class Definition -// for Human Interface Devices (HID) rev1.11 -// - -// -// HID standard GET_DESCRIPTOR request. -// -#define USB_HID_GET_DESCRIPTOR_REQ_TYPE 0x81 - -// -// HID specific requests. -// -#define USB_HID_CLASS_GET_REQ_TYPE 0xa1 -#define USB_HID_CLASS_SET_REQ_TYPE 0x21 - -// -// HID report item format -// -#define HID_ITEM_FORMAT_SHORT 0 -#define HID_ITEM_FORMAT_LONG 1 - -// -// Special tag indicating long items -// -#define HID_ITEM_TAG_LONG 15 - -// -// HID report descriptor item type (prefix bit 2,3) -// -#define HID_ITEM_TYPE_MAIN 0 -#define HID_ITEM_TYPE_GLOBAL 1 -#define HID_ITEM_TYPE_LOCAL 2 -#define HID_ITEM_TYPE_RESERVED 3 - -// -// HID report descriptor main item tags -// -#define HID_MAIN_ITEM_TAG_INPUT 8 -#define HID_MAIN_ITEM_TAG_OUTPUT 9 -#define HID_MAIN_ITEM_TAG_FEATURE 11 -#define HID_MAIN_ITEM_TAG_BEGIN_COLLECTION 10 -#define HID_MAIN_ITEM_TAG_END_COLLECTION 12 - -// -// HID report descriptor main item contents -// -#define HID_MAIN_ITEM_CONSTANT 0x001 -#define HID_MAIN_ITEM_VARIABLE 0x002 -#define HID_MAIN_ITEM_RELATIVE 0x004 -#define HID_MAIN_ITEM_WRAP 0x008 -#define HID_MAIN_ITEM_NONLINEAR 0x010 -#define HID_MAIN_ITEM_NO_PREFERRED 0x020 -#define HID_MAIN_ITEM_NULL_STATE 0x040 -#define HID_MAIN_ITEM_VOLATILE 0x080 -#define HID_MAIN_ITEM_BUFFERED_BYTE 0x100 - -// -// HID report descriptor collection item types -// -#define HID_COLLECTION_PHYSICAL 0 -#define HID_COLLECTION_APPLICATION 1 -#define HID_COLLECTION_LOGICAL 2 - -// -// HID report descriptor global item tags -// -#define HID_GLOBAL_ITEM_TAG_USAGE_PAGE 0 -#define HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM 1 -#define HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM 2 -#define HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM 3 -#define HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM 4 -#define HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT 5 -#define HID_GLOBAL_ITEM_TAG_UNIT 6 -#define HID_GLOBAL_ITEM_TAG_REPORT_SIZE 7 -#define HID_GLOBAL_ITEM_TAG_REPORT_ID 8 -#define HID_GLOBAL_ITEM_TAG_REPORT_COUNT 9 -#define HID_GLOBAL_ITEM_TAG_PUSH 10 -#define HID_GLOBAL_ITEM_TAG_POP 11 - -// -// HID report descriptor local item tags -// -#define HID_LOCAL_ITEM_TAG_USAGE 0 -#define HID_LOCAL_ITEM_TAG_USAGE_MINIMUM 1 -#define HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM 2 -#define HID_LOCAL_ITEM_TAG_DESIGNATOR_INDEX 3 -#define HID_LOCAL_ITEM_TAG_DESIGNATOR_MINIMUM 4 -#define HID_LOCAL_ITEM_TAG_DESIGNATOR_MAXIMUM 5 -#define HID_LOCAL_ITEM_TAG_STRING_INDEX 7 -#define HID_LOCAL_ITEM_TAG_STRING_MINIMUM 8 -#define HID_LOCAL_ITEM_TAG_STRING_MAXIMUM 9 -#define HID_LOCAL_ITEM_TAG_DELIMITER 10 - -// -// HID report types -// -#define HID_INPUT_REPORT 1 -#define HID_OUTPUT_REPORT 2 -#define HID_FEATURE_REPORT 3 - -// -// HID class protocol request -// -#define EFI_USB_GET_REPORT_REQUEST 0x01 -#define EFI_USB_GET_IDLE_REQUEST 0x02 -#define EFI_USB_GET_PROTOCOL_REQUEST 0x03 -#define EFI_USB_SET_REPORT_REQUEST 0x09 -#define EFI_USB_SET_IDLE_REQUEST 0x0a -#define EFI_USB_SET_PROTOCOL_REQUEST 0x0b - -#pragma pack(1) -/// -/// Descriptor header for Report/Physical Descriptors -/// HID 1.1, section 6.2.1 -/// -typedef struct hid_class_descriptor { - UINT8 DescriptorType; - UINT16 DescriptorLength; -} EFI_USB_HID_CLASS_DESCRIPTOR; - -/// -/// The HID descriptor identifies the length and type -/// of subordinate descriptors for a device. -/// HID 1.1, section 6.2.1 -/// -typedef struct hid_descriptor { - UINT8 Length; - UINT8 DescriptorType; - UINT16 BcdHID; - UINT8 CountryCode; - UINT8 NumDescriptors; - EFI_USB_HID_CLASS_DESCRIPTOR HidClassDesc[1]; -} EFI_USB_HID_DESCRIPTOR; - -#pragma pack() - -#endif diff --git a/roms/ipxe/src/include/ipxe/efi/Library/BaseLib.h b/roms/ipxe/src/include/ipxe/efi/Library/BaseLib.h index a45a20d70..e9c31d130 100644 --- a/roms/ipxe/src/include/ipxe/efi/Library/BaseLib.h +++ b/roms/ipxe/src/include/ipxe/efi/Library/BaseLib.h @@ -1,8 +1,8 @@ /** @file Provides string functions, linked list functions, math functions, synchronization - functions, file path functions, and CPU architecture-specific functions. + functions, and CPU architecture-specific functions. -Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR> Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR> This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License @@ -185,321 +185,7 @@ typedef struct { // String Services // - /** - Returns the length of a Null-terminated Unicode string. - - If String is not aligned on a 16-bit boundary, then ASSERT(). - - @param String A pointer to a Null-terminated Unicode string. - @param MaxSize The maximum number of Destination Unicode - char, including terminating null char. - - @retval 0 If String is NULL. - @retval MaxSize If there is no null character in the first MaxSize characters of String. - @return The number of characters that percede the terminating null character. - -**/ -UINTN -EFIAPI -StrnLenS ( - IN CONST CHAR16 *String, - IN UINTN MaxSize - ); - -/** - Copies the string pointed to by Source (including the terminating null char) - to the array pointed to by Destination. - - If Destination is not aligned on a 16-bit boundary, then ASSERT(). - If Source is not aligned on a 16-bit boundary, then ASSERT(). - If an error would be returned, then the function will also ASSERT(). - - @param Destination A pointer to a Null-terminated Unicode string. - @param DestMax The maximum number of Destination Unicode - char, including terminating null char. - @param Source A pointer to a Null-terminated Unicode string. - - @retval RETURN_SUCCESS String is copied. - @retval RETURN_BUFFER_TOO_SMALL If DestMax is NOT greater than StrLen(Source). - @retval RETURN_INVALID_PARAMETER If Destination is NULL. - If Source is NULL. - If PcdMaximumUnicodeStringLength is not zero, - and DestMax is greater than - PcdMaximumUnicodeStringLength. - If DestMax is 0. - @retval RETURN_ACCESS_DENIED If Source and Destination overlap. -**/ -RETURN_STATUS -EFIAPI -StrCpyS ( - OUT CHAR16 *Destination, - IN UINTN DestMax, - IN CONST CHAR16 *Source - ); - -/** - Copies not more than Length successive char from the string pointed to by - Source to the array pointed to by Destination. If no null char is copied from - Source, then Destination[Length] is always set to null. - - If Length > 0 and Destination is not aligned on a 16-bit boundary, then ASSERT(). - If Length > 0 and Source is not aligned on a 16-bit boundary, then ASSERT(). - If an error would be returned, then the function will also ASSERT(). - - @param Destination A pointer to a Null-terminated Unicode string. - @param DestMax The maximum number of Destination Unicode - char, including terminating null char. - @param Source A pointer to a Null-terminated Unicode string. - @param Length The maximum number of Unicode characters to copy. - - @retval RETURN_SUCCESS String is copied. - @retval RETURN_BUFFER_TOO_SMALL If DestMax is NOT greater than - MIN(StrLen(Source), Length). - @retval RETURN_INVALID_PARAMETER If Destination is NULL. - If Source is NULL. - If PcdMaximumUnicodeStringLength is not zero, - and DestMax is greater than - PcdMaximumUnicodeStringLength. - If DestMax is 0. - @retval RETURN_ACCESS_DENIED If Source and Destination overlap. -**/ -RETURN_STATUS -EFIAPI -StrnCpyS ( - OUT CHAR16 *Destination, - IN UINTN DestMax, - IN CONST CHAR16 *Source, - IN UINTN Length - ); - -/** - Appends a copy of the string pointed to by Source (including the terminating - null char) to the end of the string pointed to by Destination. - - If Destination is not aligned on a 16-bit boundary, then ASSERT(). - If Source is not aligned on a 16-bit boundary, then ASSERT(). - If an error would be returned, then the function will also ASSERT(). - - @param Destination A pointer to a Null-terminated Unicode string. - @param DestMax The maximum number of Destination Unicode - char, including terminating null char. - @param Source A pointer to a Null-terminated Unicode string. - - @retval RETURN_SUCCESS String is appended. - @retval RETURN_BAD_BUFFER_SIZE If DestMax is NOT greater than - StrLen(Destination). - @retval RETURN_BUFFER_TOO_SMALL If (DestMax - StrLen(Destination)) is NOT - greater than StrLen(Source). - @retval RETURN_INVALID_PARAMETER If Destination is NULL. - If Source is NULL. - If PcdMaximumUnicodeStringLength is not zero, - and DestMax is greater than - PcdMaximumUnicodeStringLength. - If DestMax is 0. - @retval RETURN_ACCESS_DENIED If Source and Destination overlap. -**/ -RETURN_STATUS -EFIAPI -StrCatS ( - IN OUT CHAR16 *Destination, - IN UINTN DestMax, - IN CONST CHAR16 *Source - ); - -/** - Appends not more than Length successive char from the string pointed to by - Source to the end of the string pointed to by Destination. If no null char is - copied from Source, then Destination[StrLen(Destination) + Length] is always - set to null. - - If Destination is not aligned on a 16-bit boundary, then ASSERT(). - If Source is not aligned on a 16-bit boundary, then ASSERT(). - If an error would be returned, then the function will also ASSERT(). - - @param Destination A pointer to a Null-terminated Unicode string. - @param DestMax The maximum number of Destination Unicode - char, including terminating null char. - @param Source A pointer to a Null-terminated Unicode string. - @param Length The maximum number of Unicode characters to copy. - - @retval RETURN_SUCCESS String is appended. - @retval RETURN_BAD_BUFFER_SIZE If DestMax is NOT greater than - StrLen(Destination). - @retval RETURN_BUFFER_TOO_SMALL If (DestMax - StrLen(Destination)) is NOT - greater than MIN(StrLen(Source), Length). - @retval RETURN_INVALID_PARAMETER If Destination is NULL. - If Source is NULL. - If PcdMaximumUnicodeStringLength is not zero, - and DestMax is greater than - PcdMaximumUnicodeStringLength. - If DestMax is 0. - @retval RETURN_ACCESS_DENIED If Source and Destination overlap. -**/ -RETURN_STATUS -EFIAPI -StrnCatS ( - IN OUT CHAR16 *Destination, - IN UINTN DestMax, - IN CONST CHAR16 *Source, - IN UINTN Length - ); - -/** - Returns the length of a Null-terminated Ascii string. - - @param String A pointer to a Null-terminated Ascii string. - @param MaxSize The maximum number of Destination Ascii - char, including terminating null char. - - @retval 0 If String is NULL. - @retval MaxSize If there is no null character in the first MaxSize characters of String. - @return The number of characters that percede the terminating null character. - -**/ -UINTN -EFIAPI -AsciiStrnLenS ( - IN CONST CHAR8 *String, - IN UINTN MaxSize - ); - -/** - Copies the string pointed to by Source (including the terminating null char) - to the array pointed to by Destination. - - If an error would be returned, then the function will also ASSERT(). - - @param Destination A pointer to a Null-terminated Ascii string. - @param DestMax The maximum number of Destination Ascii - char, including terminating null char. - @param Source A pointer to a Null-terminated Ascii string. - - @retval RETURN_SUCCESS String is copied. - @retval RETURN_BUFFER_TOO_SMALL If DestMax is NOT greater than StrLen(Source). - @retval RETURN_INVALID_PARAMETER If Destination is NULL. - If Source is NULL. - If PcdMaximumAsciiStringLength is not zero, - and DestMax is greater than - PcdMaximumAsciiStringLength. - If DestMax is 0. - @retval RETURN_ACCESS_DENIED If Source and Destination overlap. -**/ -RETURN_STATUS -EFIAPI -AsciiStrCpyS ( - OUT CHAR8 *Destination, - IN UINTN DestMax, - IN CONST CHAR8 *Source - ); - -/** - Copies not more than Length successive char from the string pointed to by - Source to the array pointed to by Destination. If no null char is copied from - Source, then Destination[Length] is always set to null. - - If an error would be returned, then the function will also ASSERT(). - - @param Destination A pointer to a Null-terminated Ascii string. - @param DestMax The maximum number of Destination Ascii - char, including terminating null char. - @param Source A pointer to a Null-terminated Ascii string. - @param Length The maximum number of Ascii characters to copy. - - @retval RETURN_SUCCESS String is copied. - @retval RETURN_BUFFER_TOO_SMALL If DestMax is NOT greater than - MIN(StrLen(Source), Length). - @retval RETURN_INVALID_PARAMETER If Destination is NULL. - If Source is NULL. - If PcdMaximumAsciiStringLength is not zero, - and DestMax is greater than - PcdMaximumAsciiStringLength. - If DestMax is 0. - @retval RETURN_ACCESS_DENIED If Source and Destination overlap. -**/ -RETURN_STATUS -EFIAPI -AsciiStrnCpyS ( - OUT CHAR8 *Destination, - IN UINTN DestMax, - IN CONST CHAR8 *Source, - IN UINTN Length - ); - -/** - Appends a copy of the string pointed to by Source (including the terminating - null char) to the end of the string pointed to by Destination. - - If an error would be returned, then the function will also ASSERT(). - - @param Destination A pointer to a Null-terminated Ascii string. - @param DestMax The maximum number of Destination Ascii - char, including terminating null char. - @param Source A pointer to a Null-terminated Ascii string. - - @retval RETURN_SUCCESS String is appended. - @retval RETURN_BAD_BUFFER_SIZE If DestMax is NOT greater than - StrLen(Destination). - @retval RETURN_BUFFER_TOO_SMALL If (DestMax - StrLen(Destination)) is NOT - greater than StrLen(Source). - @retval RETURN_INVALID_PARAMETER If Destination is NULL. - If Source is NULL. - If PcdMaximumAsciiStringLength is not zero, - and DestMax is greater than - PcdMaximumAsciiStringLength. - If DestMax is 0. - @retval RETURN_ACCESS_DENIED If Source and Destination overlap. -**/ -RETURN_STATUS -EFIAPI -AsciiStrCatS ( - IN OUT CHAR8 *Destination, - IN UINTN DestMax, - IN CONST CHAR8 *Source - ); - -/** - Appends not more than Length successive char from the string pointed to by - Source to the end of the string pointed to by Destination. If no null char is - copied from Source, then Destination[StrLen(Destination) + Length] is always - set to null. - - If an error would be returned, then the function will also ASSERT(). - - @param Destination A pointer to a Null-terminated Ascii string. - @param DestMax The maximum number of Destination Ascii - char, including terminating null char. - @param Source A pointer to a Null-terminated Ascii string. - @param Length The maximum number of Ascii characters to copy. - - @retval RETURN_SUCCESS String is appended. - @retval RETURN_BAD_BUFFER_SIZE If DestMax is NOT greater than - StrLen(Destination). - @retval RETURN_BUFFER_TOO_SMALL If (DestMax - StrLen(Destination)) is NOT - greater than MIN(StrLen(Source), Length). - @retval RETURN_INVALID_PARAMETER If Destination is NULL. - If Source is NULL. - If PcdMaximumAsciiStringLength is not zero, - and DestMax is greater than - PcdMaximumAsciiStringLength. - If DestMax is 0. - @retval RETURN_ACCESS_DENIED If Source and Destination overlap. -**/ -RETURN_STATUS -EFIAPI -AsciiStrnCatS ( - IN OUT CHAR8 *Destination, - IN UINTN DestMax, - IN CONST CHAR8 *Source, - IN UINTN Length - ); - - -#ifndef DISABLE_NEW_DEPRECATED_INTERFACES - -/** - [ATTENTION] This function is deprecated for security reason. - Copies one Null-terminated Unicode string to another Null-terminated Unicode string and returns the new Unicode string. @@ -531,8 +217,6 @@ StrCpy ( /** - [ATTENTION] This function is deprecated for security reason. - Copies up to a specified length from one Null-terminated Unicode string to another Null-terminated Unicode string and returns the new Unicode string. @@ -569,7 +253,7 @@ StrnCpy ( IN CONST CHAR16 *Source, IN UINTN Length ); -#endif + /** Returns the length of a Null-terminated Unicode string. @@ -697,11 +381,7 @@ StrnCmp ( ); -#ifndef DISABLE_NEW_DEPRECATED_INTERFACES - /** - [ATTENTION] This function is deprecated for security reason. - Concatenates one Null-terminated Unicode string to another Null-terminated Unicode string, and returns the concatenated Unicode string. @@ -742,8 +422,6 @@ StrCat ( /** - [ATTENTION] This function is deprecated for security reason. - Concatenates up to a specified length one Null-terminated Unicode to the end of another Null-terminated Unicode string, and returns the concatenated Unicode string. @@ -788,7 +466,6 @@ StrnCat ( IN CONST CHAR16 *Source, IN UINTN Length ); -#endif /** Returns the first occurrence of a Null-terminated Unicode sub-string @@ -1027,11 +704,7 @@ UnicodeStrToAsciiStr ( ); -#ifndef DISABLE_NEW_DEPRECATED_INTERFACES - /** - [ATTENTION] This function is deprecated for security reason. - Copies one Null-terminated ASCII string to another Null-terminated ASCII string and returns the new ASCII string. @@ -1061,8 +734,6 @@ AsciiStrCpy ( /** - [ATTENTION] This function is deprecated for security reason. - Copies up to a specified length one Null-terminated ASCII string to another Null-terminated ASCII string and returns the new ASCII string. @@ -1096,7 +767,7 @@ AsciiStrnCpy ( IN CONST CHAR8 *Source, IN UINTN Length ); -#endif + /** Returns the length of a Null-terminated ASCII string. @@ -1256,11 +927,7 @@ AsciiStrnCmp ( ); -#ifndef DISABLE_NEW_DEPRECATED_INTERFACES - /** - [ATTENTION] This function is deprecated for security reason. - Concatenates one Null-terminated ASCII string to another Null-terminated ASCII string, and returns the concatenated ASCII string. @@ -1296,8 +963,6 @@ AsciiStrCat ( /** - [ATTENTION] This function is deprecated for security reason. - Concatenates up to a specified length one Null-terminated ASCII string to the end of another Null-terminated ASCII string, and returns the concatenated ASCII string. @@ -1340,7 +1005,7 @@ AsciiStrnCat ( IN CONST CHAR8 *Source, IN UINTN Length ); -#endif + /** Returns the first occurrence of a Null-terminated ASCII sub-string @@ -1605,43 +1270,6 @@ BcdToDecimal8 ( IN UINT8 Value ); -// -// File Path Manipulation Functions -// - -/** - Removes the last directory or file entry in a path by changing the last - L'\' to a CHAR_NULL. - - @param[in, out] Path The pointer to the path to modify. - - @retval FALSE Nothing was found to remove. - @retval TRUE A directory or file was removed. -**/ -BOOLEAN -EFIAPI -PathRemoveLastItem( - IN OUT CHAR16 *Path - ); - -/** - Function to clean up paths. - - Single periods in the path are removed. - - Double periods in the path are removed along with a single parent directory. - - Forward slashes L'/' are converted to backward slashes L'\'. - - This will be done inline and the existing buffer may be larger than required - upon completion. - - @param[in] Path The pointer to the string containing the path. - - @return Returns Path, otherwise returns NULL to indicate that an error has occured. -**/ -CHAR16* -EFIAPI -PathCleanUpDirectories( - IN CHAR16 *Path - ); // // Linked List Functions and Macros @@ -7649,57 +7277,6 @@ AsmPrepareAndThunk16 ( IN OUT THUNK_CONTEXT *ThunkContext ); -/** - Generates a 16-bit random number through RDRAND instruction. - - if Rand is NULL, then ASSERT(). - - @param[out] Rand Buffer pointer to store the random result. - - @retval TRUE RDRAND call was successful. - @retval FALSE Failed attempts to call RDRAND. - - **/ -BOOLEAN -EFIAPI -AsmRdRand16 ( - OUT UINT16 *Rand - ); - -/** - Generates a 32-bit random number through RDRAND instruction. - - if Rand is NULL, then ASSERT(). - - @param[out] Rand Buffer pointer to store the random result. - - @retval TRUE RDRAND call was successful. - @retval FALSE Failed attempts to call RDRAND. - -**/ -BOOLEAN -EFIAPI -AsmRdRand32 ( - OUT UINT32 *Rand - ); - -/** - Generates a 64-bit random number through RDRAND instruction. - - if Rand is NULL, then ASSERT(). - - @param[out] Rand Buffer pointer to store the random result. - - @retval TRUE RDRAND call was successful. - @retval FALSE Failed attempts to call RDRAND. - -**/ -BOOLEAN -EFIAPI -AsmRdRand64 ( - OUT UINT64 *Rand - ); - #endif #endif diff --git a/roms/ipxe/src/include/ipxe/efi/Pi/PiDxeCis.h b/roms/ipxe/src/include/ipxe/efi/Pi/PiDxeCis.h index 047c077c4..50d25f23f 100644 --- a/roms/ipxe/src/include/ipxe/efi/Pi/PiDxeCis.h +++ b/roms/ipxe/src/include/ipxe/efi/Pi/PiDxeCis.h @@ -1,7 +1,7 @@ /** @file Include file matches things in PI. -Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR> This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License that accompanies this distribution. The full text of the license may be found at @@ -11,7 +11,7 @@ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. @par Revision Reference: - PI Version 1.4 + PI Version 1.2 **/ @@ -50,16 +50,6 @@ typedef enum { /// access I/O devices in the platform. /// EfiGcdMemoryTypeMemoryMappedIo, - /// - /// A memory region that is visible to the boot processor. - /// This memory supports byte-addressable non-volatility. - /// - EfiGcdMemoryTypePersistentMemory, - /// - /// A memory region that provides higher reliability relative to other memory in the - /// system. If all memory has the same reliability, then this bit is not used. - /// - EfiGcdMemoryTypeMoreReliable, EfiGcdMemoryTypeMaximum } EFI_GCD_MEMORY_TYPE; @@ -377,7 +367,7 @@ EFI_STATUS resource range specified by BaseAddress and Length. @retval EFI_UNSUPPORTED The bit mask of attributes is not support for the memory resource range specified by BaseAddress and Length. - @retval EFI_ACCESS_DENIED The attributes for the memory resource range specified by + @retval EFI_ACCESS_DEFINED The attributes for the memory resource range specified by BaseAddress and Length cannot be modified. @retval EFI_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of the memory resource range. @@ -393,31 +383,6 @@ EFI_STATUS ); /** - Modifies the capabilities for a memory region in the global coherency domain of the - processor. - - @param BaseAddress The physical address that is the start address of a memory region. - @param Length The size in bytes of the memory region. - @param Capabilities The bit mask of capabilities that the memory region supports. - - @retval EFI_SUCCESS The capabilities were set for the memory region. - @retval EFI_INVALID_PARAMETER Length is zero. - @retval EFI_UNSUPPORTED The capabilities specified by Capabilities do not include the - memory region attributes currently in use. - @retval EFI_ACCESS_DENIED The capabilities for the memory resource range specified by - BaseAddress and Length cannot be modified. - @retval EFI_OUT_OF_RESOURCES There are not enough system resources to modify the capabilities - of the memory resource range. -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_SET_MEMORY_SPACE_CAPABILITIES) ( - IN EFI_PHYSICAL_ADDRESS BaseAddress, - IN UINT64 Length, - IN UINT64 Capabilities - ); - -/** Returns a map of the memory resources in the global coherency domain of the processor. @@ -694,7 +659,7 @@ EFI_STATUS // #define DXE_SERVICES_SIGNATURE 0x565245535f455844ULL #define DXE_SPECIFICATION_MAJOR_REVISION 1 -#define DXE_SPECIFICATION_MINOR_REVISION 40 +#define DXE_SPECIFICATION_MINOR_REVISION 30 #define DXE_SERVICES_REVISION ((DXE_SPECIFICATION_MAJOR_REVISION<<16) | (DXE_SPECIFICATION_MINOR_REVISION)) typedef struct { @@ -731,12 +696,23 @@ typedef struct { // Service to process a single firmware volume found in a capsule // EFI_PROCESS_FIRMWARE_VOLUME ProcessFirmwareVolume; - // - // Extensions to Global Coherency Domain Services - // - EFI_SET_MEMORY_SPACE_CAPABILITIES SetMemorySpaceCapabilities; } DXE_SERVICES; typedef DXE_SERVICES EFI_DXE_SERVICES; + +/** + The function prototype for invoking a function on an Application Processor. + + This definition is used by the UEFI MP Serices Protocol, and the + PI SMM System Table. + + @param[in,out] Buffer The pointer to private data buffer. +**/ +typedef +VOID +(EFIAPI *EFI_AP_PROCEDURE)( + IN OUT VOID *Buffer + ); + #endif diff --git a/roms/ipxe/src/include/ipxe/efi/Pi/PiFirmwareFile.h b/roms/ipxe/src/include/ipxe/efi/Pi/PiFirmwareFile.h index 9bd22a544..f6cf9574d 100644 --- a/roms/ipxe/src/include/ipxe/efi/Pi/PiFirmwareFile.h +++ b/roms/ipxe/src/include/ipxe/efi/Pi/PiFirmwareFile.h @@ -1,7 +1,7 @@ /** @file The firmware file related definitions in PI. -Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR> This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License that accompanies this distribution. The full text of the license may be found at @@ -11,7 +11,7 @@ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. @par Revision Reference: - PI Version 1.4. + PI Version 1.2. **/ @@ -175,7 +175,7 @@ typedef struct { /// If FFS_ATTRIB_LARGE_FILE is set in Attributes, then ExtendedSize exists and Size must be set to zero. /// If FFS_ATTRIB_LARGE_FILE is not set then EFI_FFS_FILE_HEADER is used. /// - UINT64 ExtendedSize; + UINT32 ExtendedSize; } EFI_FFS_FILE_HEADER2; #define IS_FFS_FILE2(FfsFileHeaderPtr) \ @@ -185,7 +185,7 @@ typedef struct { ((UINT32) (*((UINT32 *) ((EFI_FFS_FILE_HEADER *) (UINTN) FfsFileHeaderPtr)->Size) & 0x00ffffff)) #define FFS_FILE2_SIZE(FfsFileHeaderPtr) \ - ((UINT32) (((EFI_FFS_FILE_HEADER2 *) (UINTN) FfsFileHeaderPtr)->ExtendedSize)) + (((EFI_FFS_FILE_HEADER2 *) (UINTN) FfsFileHeaderPtr)->ExtendedSize) typedef UINT8 EFI_SECTION_TYPE; diff --git a/roms/ipxe/src/include/ipxe/efi/Pi/PiHob.h b/roms/ipxe/src/include/ipxe/efi/Pi/PiHob.h index 121748dec..c68ea3002 100644 --- a/roms/ipxe/src/include/ipxe/efi/Pi/PiHob.h +++ b/roms/ipxe/src/include/ipxe/efi/Pi/PiHob.h @@ -1,7 +1,7 @@ /** @file HOB related definitions in PI. -Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR> This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License that accompanies this distribution. The full text of the license may be found at @@ -11,7 +11,7 @@ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. @par Revision Reference: - PI Version 1.4 + PI Version 1.0 **/ @@ -257,16 +257,8 @@ typedef UINT32 EFI_RESOURCE_ATTRIBUTE_TYPE; #define EFI_RESOURCE_ATTRIBUTE_INITIALIZED 0x00000002 #define EFI_RESOURCE_ATTRIBUTE_TESTED 0x00000004 #define EFI_RESOURCE_ATTRIBUTE_READ_PROTECTED 0x00000080 -// -// This is typically used as memory cacheability attribute today. -// NOTE: Since PI spec 1.4, please use EFI_RESOURCE_ATTRIBUTE_READ_ONLY_PROTECTED -// as Physical write protected attribute, and EFI_RESOURCE_ATTRIBUTE_WRITE_PROTECTED -// means Memory cacheability attribute: The memory supports being programmed with -// a writeprotected cacheable attribute. -// #define EFI_RESOURCE_ATTRIBUTE_WRITE_PROTECTED 0x00000100 #define EFI_RESOURCE_ATTRIBUTE_EXECUTION_PROTECTED 0x00000200 -#define EFI_RESOURCE_ATTRIBUTE_PERSISTENT 0x00800000 // // The rest of the attributes are used to describe capabilities // @@ -283,27 +275,8 @@ typedef UINT32 EFI_RESOURCE_ATTRIBUTE_TYPE; #define EFI_RESOURCE_ATTRIBUTE_64_BIT_IO 0x00010000 #define EFI_RESOURCE_ATTRIBUTE_UNCACHED_EXPORTED 0x00020000 #define EFI_RESOURCE_ATTRIBUTE_READ_PROTECTABLE 0x00100000 -// -// This is typically used as memory cacheability attribute today. -// NOTE: Since PI spec 1.4, please use EFI_RESOURCE_ATTRIBUTE_READ_ONLY_PROTECTABLE -// as Memory capability attribute: The memory supports being protected from processor -// writes, and EFI_RESOURCE_ATTRIBUTE_WRITE_PROTEC TABLE means Memory cacheability attribute: -// The memory supports being programmed with a writeprotected cacheable attribute. -// #define EFI_RESOURCE_ATTRIBUTE_WRITE_PROTECTABLE 0x00200000 #define EFI_RESOURCE_ATTRIBUTE_EXECUTION_PROTECTABLE 0x00400000 -#define EFI_RESOURCE_ATTRIBUTE_PERSISTABLE 0x01000000 - -#define EFI_RESOURCE_ATTRIBUTE_READ_ONLY_PROTECTED 0x00040000 -#define EFI_RESOURCE_ATTRIBUTE_READ_ONLY_PROTECTABLE 0x00800000 - -// -// Physical memory relative reliability attribute. This -// memory provides higher reliability relative to other -// memory in the system. If all memory has the same -// reliability, then this bit is not used. -// -#define EFI_RESOURCE_ATTRIBUTE_MORE_RELIABLE 0x02000000 /// /// Describes the resource properties of all fixed, diff --git a/roms/ipxe/src/include/ipxe/efi/Pi/PiMultiPhase.h b/roms/ipxe/src/include/ipxe/efi/Pi/PiMultiPhase.h index f35bb14cf..daf6591f5 100644 --- a/roms/ipxe/src/include/ipxe/efi/Pi/PiMultiPhase.h +++ b/roms/ipxe/src/include/ipxe/efi/Pi/PiMultiPhase.h @@ -1,7 +1,7 @@ /** @file Include file matches things in PI for multiple module types. -Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR> This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License that accompanies this distribution. The full text of the license may be found at @@ -164,18 +164,4 @@ typedef struct { CHAR8 *PcdName; } EFI_PCD_INFO; -/** - The function prototype for invoking a function on an Application Processor. - - This definition is used by the UEFI MP Serices Protocol, and the - PI SMM System Table. - - @param[in,out] Buffer The pointer to private data buffer. -**/ -typedef -VOID -(EFIAPI *EFI_AP_PROCEDURE)( - IN OUT VOID *Buffer - ); - #endif diff --git a/roms/ipxe/src/include/ipxe/efi/ProcessorBind.h b/roms/ipxe/src/include/ipxe/efi/ProcessorBind.h index ff1517f33..7466814fa 100644 --- a/roms/ipxe/src/include/ipxe/efi/ProcessorBind.h +++ b/roms/ipxe/src/include/ipxe/efi/ProcessorBind.h @@ -18,12 +18,4 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <ipxe/efi/X64/ProcessorBind.h> #endif -#if __arm__ -#include <ipxe/efi/Arm/ProcessorBind.h> -#endif - -#if __aarch64__ -#include <ipxe/efi/AArch64/ProcessorBind.h> -#endif - #endif /* _IPXE_EFI_PROCESSOR_BIND_H */ diff --git a/roms/ipxe/src/include/ipxe/efi/Protocol/AbsolutePointer.h b/roms/ipxe/src/include/ipxe/efi/Protocol/AbsolutePointer.h deleted file mode 100644 index b20ca0574..000000000 --- a/roms/ipxe/src/include/ipxe/efi/Protocol/AbsolutePointer.h +++ /dev/null @@ -1,207 +0,0 @@ -/** @file - The file provides services that allow information about an - absolute pointer device to be retrieved. - - Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR> - This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#ifndef __ABSOLUTE_POINTER_H__ -#define __ABSOLUTE_POINTER_H__ - -FILE_LICENCE ( BSD3 ); - - -#define EFI_ABSOLUTE_POINTER_PROTOCOL_GUID \ - { 0x8D59D32B, 0xC655, 0x4AE9, { 0x9B, 0x15, 0xF2, 0x59, 0x04, 0x99, 0x2A, 0x43 } } - - -typedef struct _EFI_ABSOLUTE_POINTER_PROTOCOL EFI_ABSOLUTE_POINTER_PROTOCOL; - - -//******************************************************* -// EFI_ABSOLUTE_POINTER_MODE -//******************************************************* - - -/** - The following data values in the EFI_ABSOLUTE_POINTER_MODE - interface are read-only and are changed by using the appropriate - interface functions. -**/ -typedef struct { - UINT64 AbsoluteMinX; ///< The Absolute Minimum of the device on the x-axis - UINT64 AbsoluteMinY; ///< The Absolute Minimum of the device on the y axis. - UINT64 AbsoluteMinZ; ///< The Absolute Minimum of the device on the z-axis - UINT64 AbsoluteMaxX; ///< The Absolute Maximum of the device on the x-axis. If 0, and the - ///< AbsoluteMinX is 0, then the pointer device does not support a xaxis - UINT64 AbsoluteMaxY; ///< The Absolute Maximum of the device on the y -axis. If 0, and the - ///< AbsoluteMinX is 0, then the pointer device does not support a yaxis. - UINT64 AbsoluteMaxZ; ///< The Absolute Maximum of the device on the z-axis. If 0 , and the - ///< AbsoluteMinX is 0, then the pointer device does not support a zaxis - UINT32 Attributes; ///< The following bits are set as needed (or'd together) to indicate the - ///< capabilities of the device supported. The remaining bits are undefined - ///< and should be 0 -} EFI_ABSOLUTE_POINTER_MODE; - -/// -/// If set, indicates this device supports an alternate button input. -/// -#define EFI_ABSP_SupportsAltActive 0x00000001 - -/// -/// If set, indicates this device returns pressure data in parameter CurrentZ. -/// -#define EFI_ABSP_SupportsPressureAsZ 0x00000002 - - -/** - This function resets the pointer device hardware. As part of - initialization process, the firmware/device will make a quick - but reasonable attempt to verify that the device is - functioning. If the ExtendedVerification flag is TRUE the - firmware may take an extended amount of time to verify the - device is operating on reset. Otherwise the reset operation is - to occur as quickly as possible. The hardware verification - process is not defined by this specification and is left up to - the platform firmware or driver to implement. - - @param This A pointer to the EFI_ABSOLUTE_POINTER_PROTOCOL - instance. - - @param ExtendedVerification Indicates that the driver may - perform a more exhaustive - verification operation of the - device during reset. - - @retval EFI_SUCCESS The device was reset. - - @retval EFI_DEVICE_ERROR The device is not functioning - correctly and could not be reset. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_ABSOLUTE_POINTER_RESET)( - IN EFI_ABSOLUTE_POINTER_PROTOCOL *This, - IN BOOLEAN ExtendedVerification -); - -/// -/// This bit is set if the touch sensor is active. -/// -#define EFI_ABSP_TouchActive 0x00000001 - -/// -/// This bit is set if the alt sensor, such as pen-side button, is active -/// -#define EFI_ABS_AltActive 0x00000002 - - -/** - Definition of EFI_ABSOLUTE_POINTER_STATE. -**/ -typedef struct { - /// - /// The unsigned position of the activation on the x axis. If the AboluteMinX - /// and the AboluteMaxX fields of the EFI_ABSOLUTE_POINTER_MODE structure are - /// both 0, then this pointer device does not support an x-axis, and this field - /// must be ignored. - /// - UINT64 CurrentX; - - /// - /// The unsigned position of the activation on the y axis. If the AboluteMinY - /// and the AboluteMaxY fields of the EFI_ABSOLUTE_POINTER_MODE structure are - /// both 0, then this pointer device does not support an y-axis, and this field - /// must be ignored. - /// - UINT64 CurrentY; - - /// - /// The unsigned position of the activation on the z axis, or the pressure - /// measurement. If the AboluteMinZ and the AboluteMaxZ fields of the - /// EFI_ABSOLUTE_POINTER_MODE structure are both 0, then this pointer device - /// does not support an z-axis, and this field must be ignored. - /// - UINT64 CurrentZ; - - /// - /// Bits are set to 1 in this structure item to indicate that device buttons are - /// active. - /// - UINT32 ActiveButtons; -} EFI_ABSOLUTE_POINTER_STATE; - -/** - The GetState() function retrieves the current state of a pointer - device. This includes information on the active state associated - with the pointer device and the current position of the axes - associated with the pointer device. If the state of the pointer - device has not changed since the last call to GetState(), then - EFI_NOT_READY is returned. If the state of the pointer device - has changed since the last call to GetState(), then the state - information is placed in State, and EFI_SUCCESS is returned. If - a device error occurs while attempting to retrieve the state - information, then EFI_DEVICE_ERROR is returned. - - - @param This A pointer to the EFI_ABSOLUTE_POINTER_PROTOCOL - instance. - - @param State A pointer to the state information on the - pointer device. - - @retval EFI_SUCCESS The state of the pointer device was - returned in State. - - @retval EFI_NOT_READY The state of the pointer device has not - changed since the last call to GetState(). - - @retval EFI_DEVICE_ERROR A device error occurred while - attempting to retrieve the pointer - device's current state. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_ABSOLUTE_POINTER_GET_STATE)( - IN EFI_ABSOLUTE_POINTER_PROTOCOL *This, - IN OUT EFI_ABSOLUTE_POINTER_STATE *State -); - - -/// -/// The EFI_ABSOLUTE_POINTER_PROTOCOL provides a set of services -/// for a pointer device that can be used as an input device from an -/// application written to this specification. The services include -/// the ability to: reset the pointer device, retrieve the state of -/// the pointer device, and retrieve the capabilities of the pointer -/// device. The service also provides certain data items describing the device. -/// -struct _EFI_ABSOLUTE_POINTER_PROTOCOL { - EFI_ABSOLUTE_POINTER_RESET Reset; - EFI_ABSOLUTE_POINTER_GET_STATE GetState; - /// - /// Event to use with WaitForEvent() to wait for input from the pointer device. - /// - EFI_EVENT WaitForInput; - /// - /// Pointer to EFI_ABSOLUTE_POINTER_MODE data. - /// - EFI_ABSOLUTE_POINTER_MODE *Mode; -}; - - -extern EFI_GUID gEfiAbsolutePointerProtocolGuid; - - -#endif - diff --git a/roms/ipxe/src/include/ipxe/efi/Protocol/AppleNetBoot.h b/roms/ipxe/src/include/ipxe/efi/Protocol/AppleNetBoot.h deleted file mode 100644 index 144beff1c..000000000 --- a/roms/ipxe/src/include/ipxe/efi/Protocol/AppleNetBoot.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef __EFI_APPLE_NET_BOOT_PROTOCOL_H__ -#define __EFI_APPLE_NET_BOOT_PROTOCOL_H__ - -/** @file - * - * Apple Net Boot Protocol - * - */ - -FILE_LICENCE ( BSD3 ); - -#define EFI_APPLE_NET_BOOT_PROTOCOL_GUID \ - { 0x78ee99fb, 0x6a5e, 0x4186, \ - { 0x97, 0xde, 0xcd, 0x0a, 0xba, 0x34, 0x5a, 0x74 } } - -typedef struct _EFI_APPLE_NET_BOOT_PROTOCOL EFI_APPLE_NET_BOOT_PROTOCOL; - -/** - Get a DHCP packet obtained by the firmware during NetBoot. - - @param This A pointer to the APPLE_NET_BOOT_PROTOCOL instance. - @param BufferSize A pointer to the size of the buffer in bytes. - @param DataBuffer The memory buffer to copy the packet to. If it is - NULL, then the size of the packet is returned - in BufferSize. - @retval EFI_SUCCESS The packet was copied. - @retval EFI_BUFFER_TOO_SMALL The BufferSize is too small to read the - current packet. BufferSize has been - updated with the size needed to - complete the request. -**/ -typedef -EFI_STATUS -(EFIAPI *GET_DHCP_RESPONSE) ( - IN EFI_APPLE_NET_BOOT_PROTOCOL *This, - IN OUT UINTN *BufferSize, - OUT VOID *DataBuffer - ); - -struct _EFI_APPLE_NET_BOOT_PROTOCOL -{ - GET_DHCP_RESPONSE GetDhcpResponse; - GET_DHCP_RESPONSE GetBsdpResponse; -}; - -#endif /*__EFI_APPLE_NET_BOOT_PROTOCOL_H__ */ diff --git a/roms/ipxe/src/include/ipxe/efi/Protocol/Cpu.h b/roms/ipxe/src/include/ipxe/efi/Protocol/Cpu.h new file mode 100644 index 000000000..665924e88 --- /dev/null +++ b/roms/ipxe/src/include/ipxe/efi/Protocol/Cpu.h @@ -0,0 +1,302 @@ +/** @file + CPU Architectural Protocol as defined in PI spec Volume 2 DXE + + This code abstracts the DXE core from processor implementation details. + + Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR> + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#ifndef __ARCH_PROTOCOL_CPU_H__ +#define __ARCH_PROTOCOL_CPU_H__ + +FILE_LICENCE ( BSD3 ); + +#include <ipxe/efi/Protocol/DebugSupport.h> + +#define EFI_CPU_ARCH_PROTOCOL_GUID \ + { 0x26baccb1, 0x6f42, 0x11d4, {0xbc, 0xe7, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } } + +typedef struct _EFI_CPU_ARCH_PROTOCOL EFI_CPU_ARCH_PROTOCOL; + +/// +/// The type of flush operation +/// +typedef enum { + EfiCpuFlushTypeWriteBackInvalidate, + EfiCpuFlushTypeWriteBack, + EfiCpuFlushTypeInvalidate, + EfiCpuMaxFlushType +} EFI_CPU_FLUSH_TYPE; + +/// +/// The type of processor INIT. +/// +typedef enum { + EfiCpuInit, + EfiCpuMaxInitType +} EFI_CPU_INIT_TYPE; + +/** + EFI_CPU_INTERRUPT_HANDLER that is called when a processor interrupt occurs. + + @param InterruptType Defines the type of interrupt or exception that + occurred on the processor.This parameter is processor architecture specific. + @param SystemContext A pointer to the processor context when + the interrupt occurred on the processor. + + @return None + +**/ +typedef +VOID +(EFIAPI *EFI_CPU_INTERRUPT_HANDLER)( + IN CONST EFI_EXCEPTION_TYPE InterruptType, + IN CONST EFI_SYSTEM_CONTEXT SystemContext + ); + +/** + This function flushes the range of addresses from Start to Start+Length + from the processor's data cache. If Start is not aligned to a cache line + boundary, then the bytes before Start to the preceding cache line boundary + are also flushed. If Start+Length is not aligned to a cache line boundary, + then the bytes past Start+Length to the end of the next cache line boundary + are also flushed. The FlushType of EfiCpuFlushTypeWriteBackInvalidate must be + supported. If the data cache is fully coherent with all DMA operations, then + this function can just return EFI_SUCCESS. If the processor does not support + flushing a range of the data cache, then the entire data cache can be flushed. + + @param This The EFI_CPU_ARCH_PROTOCOL instance. + @param Start The beginning physical address to flush from the processor's data + cache. + @param Length The number of bytes to flush from the processor's data cache. This + function may flush more bytes than Length specifies depending upon + the granularity of the flush operation that the processor supports. + @param FlushType Specifies the type of flush operation to perform. + + @retval EFI_SUCCESS The address range from Start to Start+Length was flushed from + the processor's data cache. + @retval EFI_UNSUPPORTEDT The processor does not support the cache flush type specified + by FlushType. + @retval EFI_DEVICE_ERROR The address range from Start to Start+Length could not be flushed + from the processor's data cache. + +**/ +typedef +EFI_STATUS +(EFIAPI *EFI_CPU_FLUSH_DATA_CACHE)( + IN EFI_CPU_ARCH_PROTOCOL *This, + IN EFI_PHYSICAL_ADDRESS Start, + IN UINT64 Length, + IN EFI_CPU_FLUSH_TYPE FlushType + ); + + +/** + This function enables interrupt processing by the processor. + + @param This The EFI_CPU_ARCH_PROTOCOL instance. + + @retval EFI_SUCCESS Interrupts are enabled on the processor. + @retval EFI_DEVICE_ERROR Interrupts could not be enabled on the processor. + +**/ +typedef +EFI_STATUS +(EFIAPI *EFI_CPU_ENABLE_INTERRUPT)( + IN EFI_CPU_ARCH_PROTOCOL *This + ); + + +/** + This function disables interrupt processing by the processor. + + @param This The EFI_CPU_ARCH_PROTOCOL instance. + + @retval EFI_SUCCESS Interrupts are disabled on the processor. + @retval EFI_DEVICE_ERROR Interrupts could not be disabled on the processor. + +**/ +typedef +EFI_STATUS +(EFIAPI *EFI_CPU_DISABLE_INTERRUPT)( + IN EFI_CPU_ARCH_PROTOCOL *This + ); + + +/** + This function retrieves the processor's current interrupt state a returns it in + State. If interrupts are currently enabled, then TRUE is returned. If interrupts + are currently disabled, then FALSE is returned. + + @param This The EFI_CPU_ARCH_PROTOCOL instance. + @param State A pointer to the processor's current interrupt state. Set to TRUE if + interrupts are enabled and FALSE if interrupts are disabled. + + @retval EFI_SUCCESS The processor's current interrupt state was returned in State. + @retval EFI_INVALID_PARAMETER State is NULL. + +**/ +typedef +EFI_STATUS +(EFIAPI *EFI_CPU_GET_INTERRUPT_STATE)( + IN EFI_CPU_ARCH_PROTOCOL *This, + OUT BOOLEAN *State + ); + + +/** + This function generates an INIT on the processor. If this function succeeds, then the + processor will be reset, and control will not be returned to the caller. If InitType is + not supported by this processor, or the processor cannot programmatically generate an + INIT without help from external hardware, then EFI_UNSUPPORTED is returned. If an error + occurs attempting to generate an INIT, then EFI_DEVICE_ERROR is returned. + + @param This The EFI_CPU_ARCH_PROTOCOL instance. + @param InitType The type of processor INIT to perform. + + @retval EFI_SUCCESS The processor INIT was performed. This return code should never be seen. + @retval EFI_UNSUPPORTED The processor INIT operation specified by InitType is not supported + by this processor. + @retval EFI_DEVICE_ERROR The processor INIT failed. + +**/ +typedef +EFI_STATUS +(EFIAPI *EFI_CPU_INIT)( + IN EFI_CPU_ARCH_PROTOCOL *This, + IN EFI_CPU_INIT_TYPE InitType + ); + + +/** + This function registers and enables the handler specified by InterruptHandler for a processor + interrupt or exception type specified by InterruptType. If InterruptHandler is NULL, then the + handler for the processor interrupt or exception type specified by InterruptType is uninstalled. + The installed handler is called once for each processor interrupt or exception. + + @param This The EFI_CPU_ARCH_PROTOCOL instance. + @param InterruptType A pointer to the processor's current interrupt state. Set to TRUE if interrupts + are enabled and FALSE if interrupts are disabled. + @param InterruptHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called + when a processor interrupt occurs. If this parameter is NULL, then the handler + will be uninstalled. + + @retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled. + @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InterruptType was + previously installed. + @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not + previously installed. + @retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not supported. + +**/ +typedef +EFI_STATUS +(EFIAPI *EFI_CPU_REGISTER_INTERRUPT_HANDLER)( + IN EFI_CPU_ARCH_PROTOCOL *This, + IN EFI_EXCEPTION_TYPE InterruptType, + IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler + ); + + +/** + This function reads the processor timer specified by TimerIndex and returns it in TimerValue. + + @param This The EFI_CPU_ARCH_PROTOCOL instance. + @param TimerIndex Specifies which processor timer is to be returned in TimerValue. This parameter + must be between 0 and NumberOfTimers-1. + @param TimerValue Pointer to the returned timer value. + @param TimerPeriod A pointer to the amount of time that passes in femtoseconds for each increment + of TimerValue. If TimerValue does not increment at a predictable rate, then 0 is + returned. This parameter is optional and may be NULL. + + @retval EFI_SUCCESS The processor timer value specified by TimerIndex was returned in TimerValue. + @retval EFI_DEVICE_ERROR An error occurred attempting to read one of the processor's timers. + @retval EFI_INVALID_PARAMETER TimerValue is NULL or TimerIndex is not valid. + @retval EFI_UNSUPPORTED The processor does not have any readable timers. + +**/ +typedef +EFI_STATUS +(EFIAPI *EFI_CPU_GET_TIMER_VALUE)( + IN EFI_CPU_ARCH_PROTOCOL *This, + IN UINT32 TimerIndex, + OUT UINT64 *TimerValue, + OUT UINT64 *TimerPeriod OPTIONAL + ); + + +/** + This function modifies the attributes for the memory region specified by BaseAddress and + Length from their current attributes to the attributes specified by Attributes. + + @param This The EFI_CPU_ARCH_PROTOCOL instance. + @param BaseAddress The physical address that is the start address of a memory region. + @param Length The size in bytes of the memory region. + @param Attributes The bit mask of attributes to set for the memory region. + + @retval EFI_SUCCESS The attributes were set for the memory region. + @retval EFI_ACCESS_DENIED The attributes for the memory resource range specified by + BaseAddress and Length cannot be modified. + @retval EFI_INVALID_PARAMETER Length is zero. + Attributes specified an illegal combination of attributes that + cannot be set together. + @retval EFI_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of + the memory resource range. + @retval EFI_UNSUPPORTED The processor does not support one or more bytes of the memory + resource range specified by BaseAddress and Length. + The bit mask of attributes is not support for the memory resource + range specified by BaseAddress and Length. + +**/ +typedef +EFI_STATUS +(EFIAPI *EFI_CPU_SET_MEMORY_ATTRIBUTES)( + IN EFI_CPU_ARCH_PROTOCOL *This, + IN EFI_PHYSICAL_ADDRESS BaseAddress, + IN UINT64 Length, + IN UINT64 Attributes + ); + + +/// +/// The EFI_CPU_ARCH_PROTOCOL is used to abstract processor-specific functions from the DXE +/// Foundation. This includes flushing caches, enabling and disabling interrupts, hooking interrupt +/// vectors and exception vectors, reading internal processor timers, resetting the processor, and +/// determining the processor frequency. +/// +struct _EFI_CPU_ARCH_PROTOCOL { + EFI_CPU_FLUSH_DATA_CACHE FlushDataCache; + EFI_CPU_ENABLE_INTERRUPT EnableInterrupt; + EFI_CPU_DISABLE_INTERRUPT DisableInterrupt; + EFI_CPU_GET_INTERRUPT_STATE GetInterruptState; + EFI_CPU_INIT Init; + EFI_CPU_REGISTER_INTERRUPT_HANDLER RegisterInterruptHandler; + EFI_CPU_GET_TIMER_VALUE GetTimerValue; + EFI_CPU_SET_MEMORY_ATTRIBUTES SetMemoryAttributes; + /// + /// The number of timers that are available in a processor. The value in this + /// field is a constant that must not be modified after the CPU Architectural + /// Protocol is installed. All consumers must treat this as a read-only field. + /// + UINT32 NumberOfTimers; + /// + /// The size, in bytes, of the alignment required for DMA buffer allocations. + /// This is typically the size of the largest data cache line in the platform. + /// The value in this field is a constant that must not be modified after the + /// CPU Architectural Protocol is installed. All consumers must treat this as + /// a read-only field. + /// + UINT32 DmaBufferAlignment; +}; + +extern EFI_GUID gEfiCpuArchProtocolGuid; + +#endif diff --git a/roms/ipxe/src/include/ipxe/efi/Protocol/DevicePath.h b/roms/ipxe/src/include/ipxe/efi/Protocol/DevicePath.h index d35b65fa9..a305df575 100644 --- a/roms/ipxe/src/include/ipxe/efi/Protocol/DevicePath.h +++ b/roms/ipxe/src/include/ipxe/efi/Protocol/DevicePath.h @@ -5,7 +5,7 @@ from a software point of view. The path must persist from boot to boot, so it can not contain things like PCI bus numbers that change from boot to boot. -Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR> This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License that accompanies this distribution. The full text of the license may be found at @@ -22,8 +22,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. FILE_LICENCE ( BSD3 ); #include <ipxe/efi/Guid/PcAnsi.h> -#include <ipxe/efi/IndustryStandard/Bluetooth.h> -#include <ipxe/efi/IndustryStandard/Acpi60.h> /// /// Device Path protocol. @@ -174,26 +172,6 @@ typedef struct { } CONTROLLER_DEVICE_PATH; /// -/// BMC Device Path SubType. -/// -#define HW_BMC_DP 0x06 - -/// -/// BMC Device Path. -/// -typedef struct { - EFI_DEVICE_PATH_PROTOCOL Header; - /// - /// Interface Type. - /// - UINT8 InterfaceType; - /// - /// Base Address. - /// - UINT8 BaseAddress[8]; -} BMC_DEVICE_PATH; - -/// /// ACPI Device Paths. /// #define ACPI_DEVICE_PATH 0x02 @@ -297,14 +275,14 @@ typedef struct { #define ACPI_ADR_DISPLAY_TYPE_INTERNAL_DIGITAL 4 #define ACPI_DISPLAY_ADR(_DeviceIdScheme, _HeadId, _NonVgaOutput, _BiosCanDetect, _VendorInfo, _Type, _Port, _Index) \ - ((UINT32)( ((UINT32)((_DeviceIdScheme) & 0x1) << 31) | \ - (((_HeadId) & 0x7) << 18) | \ - (((_NonVgaOutput) & 0x1) << 17) | \ - (((_BiosCanDetect) & 0x1) << 16) | \ - (((_VendorInfo) & 0xf) << 12) | \ - (((_Type) & 0xf) << 8) | \ - (((_Port) & 0xf) << 4) | \ - ((_Index) & 0xf) )) + ((UINT32)( (((_DeviceIdScheme) & 0x1) << 31) | \ + (((_HeadId) & 0x7) << 18) | \ + (((_NonVgaOutput) & 0x1) << 17) | \ + (((_BiosCanDetect) & 0x1) << 16) | \ + (((_VendorInfo) & 0xf) << 12) | \ + (((_Type) & 0xf) << 8) | \ + (((_Port) & 0xf) << 4) | \ + ((_Index) & 0xf) )) /// /// Messaging Device Paths. @@ -820,43 +798,6 @@ typedef struct { } NVME_NAMESPACE_DEVICE_PATH; /// -/// Uniform Resource Identifiers (URI) Device Path SubType -/// -#define MSG_URI_DP 0x18 -typedef struct { - EFI_DEVICE_PATH_PROTOCOL Header; - /// - /// Instance of the URI pursuant to RFC 3986. - /// - CHAR8 Uri[]; -} URI_DEVICE_PATH; - -/// -/// Universal Flash Storage (UFS) Device Path SubType. -/// -#define MSG_UFS_DP 0x19 -typedef struct { - EFI_DEVICE_PATH_PROTOCOL Header; - /// - /// Target ID on the UFS bus (PUN). - /// - UINT8 Pun; - /// - /// Logical Unit Number (LUN). - /// - UINT8 Lun; -} UFS_DEVICE_PATH; - -/// -/// SD (Secure Digital) Device Path SubType. -/// -#define MSG_SD_DP 0x1A -typedef struct { - EFI_DEVICE_PATH_PROTOCOL Header; - UINT8 SlotNumber; -} SD_DEVICE_PATH; - -/// /// iSCSI Device Path SubType /// #define MSG_ISCSI_DP 0x13 @@ -907,30 +848,6 @@ typedef struct { UINT16 VlanId; } VLAN_DEVICE_PATH; -/// -/// Bluetooth Device Path SubType. -/// -#define MSG_BLUETOOTH_DP 0x1b -typedef struct { - EFI_DEVICE_PATH_PROTOCOL Header; - /// - /// 48bit Bluetooth device address. - /// - BLUETOOTH_ADDRESS BD_ADDR; -} BLUETOOTH_DEVICE_PATH; - -/// -/// Wi-Fi Device Path SubType. -/// -#define MSG_WIFI_DP 0x1C -typedef struct { - EFI_DEVICE_PATH_PROTOCOL Header; - /// - /// Service set identifier. A 32-byte octets string. - /// - UINT8 SSId[32]; -} WIFI_DEVICE_PATH; - // // Media Device Path // @@ -1100,62 +1017,6 @@ typedef struct { } MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH; /// -/// This GUID defines a RAM Disk supporting a raw disk format in volatile memory. -/// -#define EFI_VIRTUAL_DISK_GUID EFI_ACPI_6_0_NFIT_GUID_RAM_DISK_SUPPORTING_VIRTUAL_DISK_REGION_VOLATILE - -extern EFI_GUID gEfiVirtualDiskGuid; - -/// -/// This GUID defines a RAM Disk supporting an ISO image in volatile memory. -/// -#define EFI_VIRTUAL_CD_GUID EFI_ACPI_6_0_NFIT_GUID_RAM_DISK_SUPPORTING_VIRTUAL_CD_REGION_VOLATILE - -extern EFI_GUID gEfiVirtualCdGuid; - -/// -/// This GUID defines a RAM Disk supporting a raw disk format in persistent memory. -/// -#define EFI_PERSISTENT_VIRTUAL_DISK_GUID EFI_ACPI_6_0_NFIT_GUID_RAM_DISK_SUPPORTING_VIRTUAL_DISK_REGION_PERSISTENT - -extern EFI_GUID gEfiPersistentVirtualDiskGuid; - -/// -/// This GUID defines a RAM Disk supporting an ISO image in persistent memory. -/// -#define EFI_PERSISTENT_VIRTUAL_CD_GUID EFI_ACPI_6_0_NFIT_GUID_RAM_DISK_SUPPORTING_VIRTUAL_CD_REGION_PERSISTENT - -extern EFI_GUID gEfiPersistentVirtualCdGuid; - -/// -/// Media ram disk device path. -/// -#define MEDIA_RAM_DISK_DP 0x09 - -/// -/// Used to describe the ram disk device path. -/// -typedef struct { - EFI_DEVICE_PATH_PROTOCOL Header; - /// - /// Starting Memory Address. - /// - UINT32 StartingAddr[2]; - /// - /// Ending Memory Address. - /// - UINT32 EndingAddr[2]; - /// - /// GUID that defines the type of the RAM Disk. - /// - EFI_GUID TypeGuid; - /// - /// RAM Diskinstance number, if supported. The default value is zero. - /// - UINT16 Instance; -} MEDIA_RAM_DISK_DEVICE_PATH; - -/// /// BIOS Boot Specification Device Path. /// #define BBS_DEVICE_PATH 0x05 @@ -1208,7 +1069,6 @@ typedef union { VENDOR_DEVICE_PATH Vendor; CONTROLLER_DEVICE_PATH Controller; - BMC_DEVICE_PATH Bmc; ACPI_HID_DEVICE_PATH Acpi; ACPI_EXTENDED_HID_DEVICE_PATH ExtendedAcpi; ACPI_ADR_DEVICE_PATH AcpiAdr; @@ -1236,11 +1096,6 @@ typedef union { SAS_DEVICE_PATH Sas; SASEX_DEVICE_PATH SasEx; NVME_NAMESPACE_DEVICE_PATH NvmeNamespace; - URI_DEVICE_PATH Uri; - BLUETOOTH_DEVICE_PATH Bluetooth; - WIFI_DEVICE_PATH WiFi; - UFS_DEVICE_PATH Ufs; - SD_DEVICE_PATH Sd; HARDDRIVE_DEVICE_PATH HardDrive; CDROM_DEVICE_PATH CD; @@ -1250,7 +1105,7 @@ typedef union { MEDIA_FW_VOL_DEVICE_PATH FirmwareVolume; MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FirmwareFile; MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH Offset; - MEDIA_RAM_DISK_DEVICE_PATH RamDisk; + BBS_BBS_DEVICE_PATH Bbs; } EFI_DEV_PATH; @@ -1264,7 +1119,6 @@ typedef union { VENDOR_DEVICE_PATH *Vendor; CONTROLLER_DEVICE_PATH *Controller; - BMC_DEVICE_PATH *Bmc; ACPI_HID_DEVICE_PATH *Acpi; ACPI_EXTENDED_HID_DEVICE_PATH *ExtendedAcpi; ACPI_ADR_DEVICE_PATH *AcpiAdr; @@ -1292,11 +1146,6 @@ typedef union { SAS_DEVICE_PATH *Sas; SASEX_DEVICE_PATH *SasEx; NVME_NAMESPACE_DEVICE_PATH *NvmeNamespace; - URI_DEVICE_PATH *Uri; - BLUETOOTH_DEVICE_PATH *Bluetooth; - WIFI_DEVICE_PATH *WiFi; - UFS_DEVICE_PATH *Ufs; - SD_DEVICE_PATH *Sd; HARDDRIVE_DEVICE_PATH *HardDrive; CDROM_DEVICE_PATH *CD; @@ -1306,7 +1155,7 @@ typedef union { MEDIA_FW_VOL_DEVICE_PATH *FirmwareVolume; MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FirmwareFile; MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH *Offset; - MEDIA_RAM_DISK_DEVICE_PATH *RamDisk; + BBS_BBS_DEVICE_PATH *Bbs; UINT8 *Raw; } EFI_DEV_PATH_PTR; diff --git a/roms/ipxe/src/include/ipxe/efi/Protocol/FormBrowser2.h b/roms/ipxe/src/include/ipxe/efi/Protocol/FormBrowser2.h index 8033a11d3..0c0f56d73 100644 --- a/roms/ipxe/src/include/ipxe/efi/Protocol/FormBrowser2.h +++ b/roms/ipxe/src/include/ipxe/efi/Protocol/FormBrowser2.h @@ -4,7 +4,7 @@ The EFI_FORM_BROWSER2_PROTOCOL is the interface to call for drivers to leverage the EFI configuration driver interface. -Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR> This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License that accompanies this distribution. The full text of the license may be found at @@ -65,7 +65,6 @@ typedef UINTN EFI_BROWSER_ACTION_REQUEST; #define EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT 5 #define EFI_BROWSER_ACTION_REQUEST_FORM_APPLY 6 #define EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD 7 -#define EFI_BROWSER_ACTION_REQUEST_RECONNECT 8 /** diff --git a/roms/ipxe/src/include/ipxe/efi/Protocol/HiiConfigAccess.h b/roms/ipxe/src/include/ipxe/efi/Protocol/HiiConfigAccess.h index df9080591..17ce3fdcc 100644 --- a/roms/ipxe/src/include/ipxe/efi/Protocol/HiiConfigAccess.h +++ b/roms/ipxe/src/include/ipxe/efi/Protocol/HiiConfigAccess.h @@ -5,7 +5,7 @@ This protocol is published by drivers providing and requesting configuration data from HII. It may only be invoked by HII. -Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR> This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License that accompanies this distribution. The full text of the license may be found at @@ -36,7 +36,6 @@ typedef UINTN EFI_BROWSER_ACTION; #define EFI_BROWSER_ACTION_RETRIEVE 2 #define EFI_BROWSER_ACTION_FORM_OPEN 3 #define EFI_BROWSER_ACTION_FORM_CLOSE 4 -#define EFI_BROWSER_ACTION_SUBMITTED 5 #define EFI_BROWSER_ACTION_DEFAULT_STANDARD 0x1000 #define EFI_BROWSER_ACTION_DEFAULT_MANUFACTURING 0x1001 #define EFI_BROWSER_ACTION_DEFAULT_SAFE 0x1002 diff --git a/roms/ipxe/src/include/ipxe/efi/Protocol/HiiFont.h b/roms/ipxe/src/include/ipxe/efi/Protocol/HiiFont.h deleted file mode 100644 index f2b72dc11..000000000 --- a/roms/ipxe/src/include/ipxe/efi/Protocol/HiiFont.h +++ /dev/null @@ -1,474 +0,0 @@ -/** @file - The file provides services to retrieve font information. - -Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR> -This program and the accompanying materials are licensed and made available under -the terms and conditions of the BSD License that accompanies this distribution. -The full text of the license may be found at -http://opensource.org/licenses/bsd-license.php. - -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#ifndef __HII_FONT_H__ -#define __HII_FONT_H__ - -FILE_LICENCE ( BSD3 ); - -#include <ipxe/efi/Protocol/GraphicsOutput.h> -#include <ipxe/efi/Protocol/HiiImage.h> - -#define EFI_HII_FONT_PROTOCOL_GUID \ -{ 0xe9ca4775, 0x8657, 0x47fc, { 0x97, 0xe7, 0x7e, 0xd6, 0x5a, 0x8, 0x43, 0x24 } } - -typedef struct _EFI_HII_FONT_PROTOCOL EFI_HII_FONT_PROTOCOL; - -typedef VOID *EFI_FONT_HANDLE; - -/// -/// EFI_HII_OUT_FLAGS. -/// -typedef UINT32 EFI_HII_OUT_FLAGS; - -#define EFI_HII_OUT_FLAG_CLIP 0x00000001 -#define EFI_HII_OUT_FLAG_WRAP 0x00000002 -#define EFI_HII_OUT_FLAG_CLIP_CLEAN_Y 0x00000004 -#define EFI_HII_OUT_FLAG_CLIP_CLEAN_X 0x00000008 -#define EFI_HII_OUT_FLAG_TRANSPARENT 0x00000010 -#define EFI_HII_IGNORE_IF_NO_GLYPH 0x00000020 -#define EFI_HII_IGNORE_LINE_BREAK 0x00000040 -#define EFI_HII_DIRECT_TO_SCREEN 0x00000080 - -/** - Definition of EFI_HII_ROW_INFO. -**/ -typedef struct _EFI_HII_ROW_INFO { - /// - /// The index of the first character in the string which is displayed on the line. - /// - UINTN StartIndex; - /// - /// The index of the last character in the string which is displayed on the line. - /// If this is the same as StartIndex, then no characters are displayed. - /// - UINTN EndIndex; - UINTN LineHeight; ///< The height of the line, in pixels. - UINTN LineWidth; ///< The width of the text on the line, in pixels. - - /// - /// The font baseline offset in pixels from the bottom of the row, or 0 if none. - /// - UINTN BaselineOffset; -} EFI_HII_ROW_INFO; - -/// -/// Font info flag. All flags (FONT, SIZE, STYLE, and COLOR) are defined. -/// They are defined as EFI_FONT_INFO_*** -/// -typedef UINT32 EFI_FONT_INFO_MASK; - -#define EFI_FONT_INFO_SYS_FONT 0x00000001 -#define EFI_FONT_INFO_SYS_SIZE 0x00000002 -#define EFI_FONT_INFO_SYS_STYLE 0x00000004 -#define EFI_FONT_INFO_SYS_FORE_COLOR 0x00000010 -#define EFI_FONT_INFO_SYS_BACK_COLOR 0x00000020 -#define EFI_FONT_INFO_RESIZE 0x00001000 -#define EFI_FONT_INFO_RESTYLE 0x00002000 -#define EFI_FONT_INFO_ANY_FONT 0x00010000 -#define EFI_FONT_INFO_ANY_SIZE 0x00020000 -#define EFI_FONT_INFO_ANY_STYLE 0x00040000 - -// -// EFI_FONT_INFO -// -typedef struct { - EFI_HII_FONT_STYLE FontStyle; - UINT16 FontSize; ///< character cell height in pixels - CHAR16 FontName[1]; -} EFI_FONT_INFO; - -/** - Describes font output-related information. - - This structure is used for describing the way in which a string - should be rendered in a particular font. FontInfo specifies the - basic font information and ForegroundColor and BackgroundColor - specify the color in which they should be displayed. The flags - in FontInfoMask describe where the system default should be - supplied instead of the specified information. The flags also - describe what options can be used to make a match between the - font requested and the font available. -**/ -typedef struct _EFI_FONT_DISPLAY_INFO { - EFI_GRAPHICS_OUTPUT_BLT_PIXEL ForegroundColor; - EFI_GRAPHICS_OUTPUT_BLT_PIXEL BackgroundColor; - EFI_FONT_INFO_MASK FontInfoMask; - EFI_FONT_INFO FontInfo; -} EFI_FONT_DISPLAY_INFO; - -/** - - This function renders a string to a bitmap or the screen using - the specified font, color and options. It either draws the - string and glyphs on an existing bitmap, allocates a new bitmap, - or uses the screen. The strings can be clipped or wrapped. - Optionally, the function also returns the information about each - row and the character position on that row. If - EFI_HII_OUT_FLAG_CLIP is set, then text will be formatted only - based on explicit line breaks and all pixels which would lie - outside the bounding box specified by Width and Height are - ignored. The information in the RowInfoArray only describes - characters which are at least partially displayed. For the final - row, the LineHeight and BaseLine may describe pixels that are - outside the limit specified by Height (unless - EFI_HII_OUT_FLAG_CLIP_CLEAN_Y is specified) even though those - pixels were not drawn. The LineWidth may describe pixels which - are outside the limit specified by Width (unless - EFI_HII_OUT_FLAG_CLIP_CLEAN_X is specified) even though those - pixels were not drawn. If EFI_HII_OUT_FLAG_CLIP_CLEAN_X is set, - then it modifies the behavior of EFI_HII_OUT_FLAG_CLIP so that - if a character's right-most on pixel cannot fit, then it will - not be drawn at all. This flag requires that - EFI_HII_OUT_FLAG_CLIP be set. If EFI_HII_OUT_FLAG_CLIP_CLEAN_Y - is set, then it modifies the behavior of EFI_HII_OUT_FLAG_CLIP - so that if a row's bottom-most pixel cannot fit, then it will - not be drawn at all. This flag requires that - EFI_HII_OUT_FLAG_CLIP be set. If EFI_HII_OUT_FLAG_WRAP is set, - then text will be wrapped at the right-most line-break - opportunity prior to a character whose right-most extent would - exceed Width. If no line-break opportunity can be found, then - the text will behave as if EFI_HII_OUT_FLAG_CLIP_CLEAN_X is set. - This flag cannot be used with EFI_HII_OUT_FLAG_CLIP_CLEAN_X. If - EFI_HII_OUT_FLAG_TRANSPARENT is set, then BackgroundColor is - ignored and all 'off' pixels in the character's drawn - will use the pixel value from Blt. This flag cannot be used if - Blt is NULL upon entry. If EFI_HII_IGNORE_IF_NO_GLYPH is set, - then characters which have no glyphs are not drawn. Otherwise, - they are replaced with Unicode character code 0xFFFD (REPLACEMENT - CHARACTER). If EFI_HII_IGNORE_LINE_BREAK is set, then explicit - line break characters will be ignored. If - EFI_HII_DIRECT_TO_SCREEN is set, then the string will be written - directly to the output device specified by Screen. Otherwise the - string will be rendered to the bitmap specified by Bitmap. - - @param This A pointer to the EFI_HII_FONT_PROTOCOL instance. - - @param Flags Describes how the string is to be drawn. - - @param String Points to the null-terminated string to be - - @param StringInfo Points to the string output information, - including the color and font. If NULL, then - the string will be output in the default - system font and color. - - @param Blt If this points to a non-NULL on entry, this points - to the image, which is Width pixels wide and - Height pixels high. The string will be drawn onto - this image and EFI_HII_OUT_FLAG_CLIP is implied. - If this points to a NULL on entry, then a buffer - will be allocated to hold the generated image and - the pointer updated on exit. It is the caller's - responsibility to free this buffer. - - @param BltX, BltY Specifies the offset from the left and top - edge of the image of the first character - cell in the image. - - @param RowInfoArray If this is non-NULL on entry, then on - exit, this will point to an allocated buffer - containing row information and - RowInfoArraySize will be updated to contain - the number of elements. This array describes - the characters that were at least partially - drawn and the heights of the rows. It is the - caller's responsibility to free this buffer. - - @param RowInfoArraySize If this is non-NULL on entry, then on - exit it contains the number of - elements in RowInfoArray. - - @param ColumnInfoArray If this is non-NULL, then on return it - will be filled with the horizontal - offset for each character in the - string on the row where it is - displayed. Non-printing characters - will have the offset ~0. The caller is - responsible for allocating a buffer large - enough so that there is one entry for - each character in the string, not - including the null-terminator. It is - possible when character display is - normalized that some character cells - overlap. - - @retval EFI_SUCCESS The string was successfully updated. - - @retval EFI_OUT_OF_RESOURCES Unable to allocate an output buffer for RowInfoArray or Blt. - - @retval EFI_INVALID_PARAMETER The String or Blt was NULL. - - @retval EFI_INVALID_PARAMETER Flags were invalid combination. -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_HII_STRING_TO_IMAGE)( - IN CONST EFI_HII_FONT_PROTOCOL *This, - IN EFI_HII_OUT_FLAGS Flags, - IN CONST EFI_STRING String, - IN CONST EFI_FONT_DISPLAY_INFO *StringInfo, - IN OUT EFI_IMAGE_OUTPUT **Blt, - IN UINTN BltX, - IN UINTN BltY, - OUT EFI_HII_ROW_INFO **RowInfoArray OPTIONAL, - OUT UINTN *RowInfoArraySize OPTIONAL, - OUT UINTN *ColumnInfoArray OPTIONAL -); - - - -/** - - This function renders a string as a bitmap or to the screen - and can clip or wrap the string. The bitmap is either supplied - by the caller or allocated by the function. The - strings are drawn with the font, size and style specified and - can be drawn transparently or opaquely. The function can also - return information about each row and each character's - position on the row. If EFI_HII_OUT_FLAG_CLIP is set, then - text will be formatted based only on explicit line breaks, and - all pixels that would lie outside the bounding box specified - by Width and Height are ignored. The information in the - RowInfoArray only describes characters which are at least - partially displayed. For the final row, the LineHeight and - BaseLine may describe pixels which are outside the limit - specified by Height (unless EFI_HII_OUT_FLAG_CLIP_CLEAN_Y is - specified) even though those pixels were not drawn. If - EFI_HII_OUT_FLAG_CLIP_CLEAN_X is set, then it modifies the - behavior of EFI_HII_OUT_FLAG_CLIP so that if a character's - right-most on pixel cannot fit, then it will not be drawn at - all. This flag requires that EFI_HII_OUT_FLAG_CLIP be set. If - EFI_HII_OUT_FLAG_CLIP_CLEAN_Y is set, then it modifies the - behavior of EFI_HII_OUT_FLAG_CLIP so that if a row's bottom - most pixel cannot fit, then it will not be drawn at all. This - flag requires that EFI_HII_OUT_FLAG_CLIP be set. If - EFI_HII_OUT_FLAG_WRAP is set, then text will be wrapped at the - right-most line-break opportunity prior to a character whose - right-most extent would exceed Width. If no line-break - opportunity can be found, then the text will behave as if - EFI_HII_OUT_FLAG_CLIP_CLEAN_X is set. This flag cannot be used - with EFI_HII_OUT_FLAG_CLIP_CLEAN_X. If - EFI_HII_OUT_FLAG_TRANSPARENT is set, then BackgroundColor is - ignored and all off" pixels in the character's glyph will - use the pixel value from Blt. This flag cannot be used if Blt - is NULL upon entry. If EFI_HII_IGNORE_IF_NO_GLYPH is set, then - characters which have no glyphs are not drawn. Otherwise, they - are replaced with Unicode character code 0xFFFD (REPLACEMENT - CHARACTER). If EFI_HII_IGNORE_LINE_BREAK is set, then explicit - line break characters will be ignored. If - EFI_HII_DIRECT_TO_SCREEN is set, then the string will be - written directly to the output device specified by Screen. - Otherwise the string will be rendered to the bitmap specified - by Bitmap. - - - @param This A pointer to the EFI_HII_FONT_PROTOCOL instance. - - @param Flags Describes how the string is to be drawn. - - @param PackageList - The package list in the HII database to - search for the specified string. - - @param StringId The string's id, which is unique within - PackageList. - - @param Language Points to the language for the retrieved - string. If NULL, then the current system - language is used. - - @param StringInfo Points to the string output information, - including the color and font. If NULL, then - the string will be output in the default - system font and color. - - @param Blt If this points to a non-NULL on entry, this points - to the image, which is Width pixels wide and - Height pixels high. The string will be drawn onto - this image and EFI_HII_OUT_FLAG_CLIP is implied. - If this points to a NULL on entry, then a buffer - will be allocated to hold the generated image and - the pointer updated on exit. It is the caller's - responsibility to free this buffer. - - @param BltX, BltY Specifies the offset from the left and top - edge of the output image of the first - character cell in the image. - - @param RowInfoArray If this is non-NULL on entry, then on - exit, this will point to an allocated - buffer containing row information and - RowInfoArraySize will be updated to - contain the number of elements. This array - describes the characters which were at - least partially drawn and the heights of - the rows. It is the caller's - responsibility to free this buffer. - - @param RowInfoArraySize If this is non-NULL on entry, then on - exit it contains the number of - elements in RowInfoArray. - - @param ColumnInfoArray If non-NULL, on return it is filled - with the horizontal offset for each - character in the string on the row - where it is displayed. Non-printing - characters will have the offset ~0. - The caller is responsible to allocate - a buffer large enough so that there is - one entry for each character in the - string, not including the - null-terminator. It is possible when - character display is normalized that - some character cells overlap. - - - @retval EFI_SUCCESS The string was successfully updated. - - @retval EFI_OUT_OF_RESOURCES Unable to allocate an output - buffer for RowInfoArray or Blt. - - @retval EFI_INVALID_PARAMETER The String, or Blt, or Height, or - Width was NULL. - @retval EFI_INVALID_PARAMETER The Blt or PackageList was NULL. - @retval EFI_INVALID_PARAMETER Flags were invalid combination. - @retval EFI_NOT_FOUND The specified PackageList is not in the Database, - or the stringid is not in the specified PackageList. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_HII_STRING_ID_TO_IMAGE)( - IN CONST EFI_HII_FONT_PROTOCOL *This, - IN EFI_HII_OUT_FLAGS Flags, - IN EFI_HII_HANDLE PackageList, - IN EFI_STRING_ID StringId, - IN CONST CHAR8 *Language, - IN CONST EFI_FONT_DISPLAY_INFO *StringInfo OPTIONAL, - IN OUT EFI_IMAGE_OUTPUT **Blt, - IN UINTN BltX, - IN UINTN BltY, - OUT EFI_HII_ROW_INFO **RowInfoArray OPTIONAL, - OUT UINTN *RowInfoArraySize OPTIONAL, - OUT UINTN *ColumnInfoArray OPTIONAL -); - - -/** - - Convert the glyph for a single character into a bitmap. - - @param This A pointer to the EFI_HII_FONT_PROTOCOL instance. - - @param Char The character to retrieve. - - @param StringInfo Points to the string font and color - information or NULL if the string should use - the default system font and color. - - @param Blt This must point to a NULL on entry. A buffer will - be allocated to hold the output and the pointer - updated on exit. It is the caller's responsibility - to free this buffer. - - @param Baseline The number of pixels from the bottom of the bitmap - to the baseline. - - - @retval EFI_SUCCESS The glyph bitmap created. - - @retval EFI_OUT_OF_RESOURCES Unable to allocate the output buffer Blt. - - @retval EFI_WARN_UNKNOWN_GLYPH The glyph was unknown and was - replaced with the glyph for - Unicode character code 0xFFFD. - - @retval EFI_INVALID_PARAMETER Blt is NULL, or Width is NULL, or - Height is NULL - - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_HII_GET_GLYPH)( - IN CONST EFI_HII_FONT_PROTOCOL *This, - IN CONST CHAR16 Char, - IN CONST EFI_FONT_DISPLAY_INFO *StringInfo, - OUT EFI_IMAGE_OUTPUT **Blt, - OUT UINTN *Baseline OPTIONAL -); - -/** - - This function iterates through fonts which match the specified - font, using the specified criteria. If String is non-NULL, then - all of the characters in the string must exist in order for a - candidate font to be returned. - - @param This A pointer to the EFI_HII_FONT_PROTOCOL instance. - - @param FontHandle On entry, points to the font handle returned - by a previous call to GetFontInfo() or NULL - to start with the first font. On return, - points to the returned font handle or points - to NULL if there are no more matching fonts. - - @param StringInfoIn Upon entry, points to the font to return - information about. If NULL, then the information - about the system default font will be returned. - - @param StringInfoOut Upon return, contains the matching font's information. - If NULL, then no information is returned. This buffer - is allocated with a call to the Boot Service AllocatePool(). - It is the caller's responsibility to call the Boot - Service FreePool() when the caller no longer requires - the contents of StringInfoOut. - - @param String Points to the string which will be tested to - determine if all characters are available. If - NULL, then any font is acceptable. - - @retval EFI_SUCCESS Matching font returned successfully. - - @retval EFI_NOT_FOUND No matching font was found. - - @retval EFI_OUT_OF_RESOURCES There were insufficient resources to complete the request. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_HII_GET_FONT_INFO)( - IN CONST EFI_HII_FONT_PROTOCOL *This, - IN OUT EFI_FONT_HANDLE *FontHandle, - IN CONST EFI_FONT_DISPLAY_INFO *StringInfoIn, OPTIONAL - OUT EFI_FONT_DISPLAY_INFO **StringInfoOut, - IN CONST EFI_STRING String OPTIONAL -); - -/// -/// The protocol provides the service to retrieve the font informations. -/// -struct _EFI_HII_FONT_PROTOCOL { - EFI_HII_STRING_TO_IMAGE StringToImage; - EFI_HII_STRING_ID_TO_IMAGE StringIdToImage; - EFI_HII_GET_GLYPH GetGlyph; - EFI_HII_GET_FONT_INFO GetFontInfo; -}; - -extern EFI_GUID gEfiHiiFontProtocolGuid; - - -#endif - diff --git a/roms/ipxe/src/include/ipxe/efi/Protocol/HiiImage.h b/roms/ipxe/src/include/ipxe/efi/Protocol/HiiImage.h deleted file mode 100644 index b18d51a61..000000000 --- a/roms/ipxe/src/include/ipxe/efi/Protocol/HiiImage.h +++ /dev/null @@ -1,356 +0,0 @@ -/** @file - The file provides services to access to images in the images database. - - Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR> - This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#ifndef __HII_IMAGE_H__ -#define __HII_IMAGE_H__ - -FILE_LICENCE ( BSD3 ); - -#define EFI_HII_IMAGE_PROTOCOL_GUID \ - { 0x31a6406a, 0x6bdf, 0x4e46, { 0xb2, 0xa2, 0xeb, 0xaa, 0x89, 0xc4, 0x9, 0x20 } } - -typedef struct _EFI_HII_IMAGE_PROTOCOL EFI_HII_IMAGE_PROTOCOL; - - -/// -/// Flags in EFI_IMAGE_INPUT -/// -#define EFI_IMAGE_TRANSPARENT 0x00000001 - -/** - - Definition of EFI_IMAGE_INPUT. - - @param Flags Describe image characteristics. If - EFI_IMAGE_TRANSPARENT is set, then the image was - designed for transparent display. - - @param Width Image width, in pixels. - - @param Height Image height, in pixels. - - @param Bitmap A pointer to the actual bitmap, organized left-to-right, - top-to-bottom. The size of the bitmap is - Width*Height*sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL). - - -**/ -typedef struct _EFI_IMAGE_INPUT { - UINT32 Flags; - UINT16 Width; - UINT16 Height; - EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Bitmap; -} EFI_IMAGE_INPUT; - - -/** - - This function adds the image Image to the group of images - owned by PackageList, and returns a new image identifier - (ImageId). - - @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance. - - @param PackageList Handle of the package list where this image will be added. - - @param ImageId On return, contains the new image id, which is - unique within PackageList. - - @param Image Points to the image. - - @retval EFI_SUCCESS The new image was added - successfully - - @retval EFI_OUT_OF_RESOURCES Could not add the image. - - @retval EFI_INVALID_PARAMETER Image is NULL or ImageId is - NULL. - - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_HII_NEW_IMAGE)( - IN CONST EFI_HII_IMAGE_PROTOCOL *This, - IN EFI_HII_HANDLE PackageList, - OUT EFI_IMAGE_ID *ImageId, - IN CONST EFI_IMAGE_INPUT *Image -); - -/** - - This function retrieves the image specified by ImageId which - is associated with the specified PackageList and copies it - into the buffer specified by Image. If the image specified by - ImageId is not present in the specified PackageList, then - EFI_NOT_FOUND is returned. If the buffer specified by - ImageSize is too small to hold the image, then - EFI_BUFFER_TOO_SMALL will be returned. ImageSize will be - updated to the size of buffer actually required to hold the - image. - - @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance. - - @param PackageList The package list in the HII database to - search for the specified image. - - @param ImageId The image's id, which is unique within - PackageList. - - @param Image Points to the new image. - - @retval EFI_SUCCESS The image was returned successfully. - - @retval EFI_NOT_FOUND The image specified by ImageId is not - available. Or The specified PackageList is not in the database. - - @retval EFI_INVALID_PARAMETER The Image or Langugae was NULL. - @retval EFI_OUT_OF_RESOURCES The bitmap could not be retrieved because there was not - enough memory. - - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_HII_GET_IMAGE)( - IN CONST EFI_HII_IMAGE_PROTOCOL *This, - IN EFI_HII_HANDLE PackageList, - IN EFI_IMAGE_ID ImageId, - OUT EFI_IMAGE_INPUT *Image -); - -/** - - This function updates the image specified by ImageId in the - specified PackageListHandle to the image specified by Image. - - - @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance. - - @param PackageList The package list containing the images. - - @param ImageId The image id, which is unique within PackageList. - - @param Image Points to the image. - - @retval EFI_SUCCESS The image was successfully updated. - - @retval EFI_NOT_FOUND The image specified by ImageId is not in the database. - The specified PackageList is not in the database. - - @retval EFI_INVALID_PARAMETER The Image or Language was NULL. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_HII_SET_IMAGE)( - IN CONST EFI_HII_IMAGE_PROTOCOL *This, - IN EFI_HII_HANDLE PackageList, - IN EFI_IMAGE_ID ImageId, - IN CONST EFI_IMAGE_INPUT *Image -); - - -/// -/// EFI_HII_DRAW_FLAGS describes how the image is to be drawn. -/// These flags are defined as EFI_HII_DRAW_FLAG_*** -/// -typedef UINT32 EFI_HII_DRAW_FLAGS; - -#define EFI_HII_DRAW_FLAG_CLIP 0x00000001 -#define EFI_HII_DRAW_FLAG_TRANSPARENT 0x00000030 -#define EFI_HII_DRAW_FLAG_DEFAULT 0x00000000 -#define EFI_HII_DRAW_FLAG_FORCE_TRANS 0x00000010 -#define EFI_HII_DRAW_FLAG_FORCE_OPAQUE 0x00000020 -#define EFI_HII_DIRECT_TO_SCREEN 0x00000080 - -/** - - Definition of EFI_IMAGE_OUTPUT. - - @param Width Width of the output image. - - @param Height Height of the output image. - - @param Bitmap Points to the output bitmap. - - @param Screen Points to the EFI_GRAPHICS_OUTPUT_PROTOCOL which - describes the screen on which to draw the - specified image. - -**/ -typedef struct _EFI_IMAGE_OUTPUT { - UINT16 Width; - UINT16 Height; - union { - EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Bitmap; - EFI_GRAPHICS_OUTPUT_PROTOCOL *Screen; - } Image; -} EFI_IMAGE_OUTPUT; - - -/** - - This function renders an image to a bitmap or the screen using - the specified color and options. It draws the image on an - existing bitmap, allocates a new bitmap or uses the screen. The - images can be clipped. If EFI_HII_DRAW_FLAG_CLIP is set, then - all pixels drawn outside the bounding box specified by Width and - Height are ignored. If EFI_HII_DRAW_FLAG_TRANSPARENT is set, - then all 'off' pixels in the images drawn will use the - pixel value from Blt. This flag cannot be used if Blt is NULL - upon entry. If EFI_HII_DIRECT_TO_SCREEN is set, then the image - will be written directly to the output device specified by - Screen. Otherwise the image will be rendered to the bitmap - specified by Bitmap. - - - @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance. - - @param Flags Describes how the image is to be drawn. - EFI_HII_DRAW_FLAGS is defined in Related - Definitions, below. - - @param Image Points to the image to be displayed. - - @param Blt If this points to a non-NULL on entry, this points - to the image, which is Width pixels wide and - Height pixels high. The image will be drawn onto - this image and EFI_HII_DRAW_FLAG_CLIP is implied. - If this points to a NULL on entry, then a buffer - will be allocated to hold the generated image and - the pointer updated on exit. It is the caller's - responsibility to free this buffer. - - @param BltX, BltY Specifies the offset from the left and top - edge of the image of the first pixel in - the image. - - @retval EFI_SUCCESS The image was successfully updated. - - @retval EFI_OUT_OF_RESOURCES Unable to allocate an output - buffer for RowInfoArray or Blt. - - @retval EFI_INVALID_PARAMETER The Image or Blt or Height or - Width was NULL. - - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_HII_DRAW_IMAGE)( - IN CONST EFI_HII_IMAGE_PROTOCOL *This, - IN EFI_HII_DRAW_FLAGS Flags, - IN CONST EFI_IMAGE_INPUT *Image, - IN OUT EFI_IMAGE_OUTPUT **Blt, - IN UINTN BltX, - IN UINTN BltY -); - -/** - - This function renders an image as a bitmap or to the screen and - can clip the image. The bitmap is either supplied by the caller - or else is allocated by the function. The images can be drawn - transparently or opaquely. If EFI_HII_DRAW_FLAG_CLIP is set, - then all pixels drawn outside the bounding box specified by - Width and Height are ignored. If EFI_HII_DRAW_FLAG_TRANSPARENT - is set, then all "off" pixels in the character's glyph will - use the pixel value from Blt. This flag cannot be used if Blt - is NULL upon entry. If EFI_HII_DIRECT_TO_SCREEN is set, then - the image will be written directly to the output device - specified by Screen. Otherwise the image will be rendered to - the bitmap specified by Bitmap. - This function renders an image to a bitmap or the screen using - the specified color and options. It draws the image on an - existing bitmap, allocates a new bitmap or uses the screen. The - images can be clipped. If EFI_HII_DRAW_FLAG_CLIP is set, then - all pixels drawn outside the bounding box specified by Width and - Height are ignored. The EFI_HII_DRAW_FLAG_TRANSPARENT flag - determines whether the image will be drawn transparent or - opaque. If EFI_HII_DRAW_FLAG_FORCE_TRANS is set, then the image - will be drawn so that all 'off' pixels in the image will - be drawn using the pixel value from Blt and all other pixels - will be copied. If EFI_HII_DRAW_FLAG_FORCE_OPAQUE is set, then - the image's pixels will be copied directly to the - destination. If EFI_HII_DRAW_FLAG_DEFAULT is set, then the image - will be drawn transparently or opaque, depending on the - image's transparency setting (see EFI_IMAGE_TRANSPARENT). - Images cannot be drawn transparently if Blt is NULL. If - EFI_HII_DIRECT_TO_SCREEN is set, then the image will be written - directly to the output device specified by Screen. Otherwise the - image will be rendered to the bitmap specified by Bitmap. - - @param This A pointer to the EFI_HII_IMAGE_PROTOCOL instance. - - @param Flags Describes how the image is to be drawn. - - @param PackageList The package list in the HII database to - search for the specified image. - - @param ImageId The image's id, which is unique within PackageList. - - @param Blt If this points to a non-NULL on entry, this points - to the image, which is Width pixels wide and - Height pixels high. The image will be drawn onto - this image and EFI_HII_DRAW_FLAG_CLIP is implied. - If this points to a NULL on entry, then a buffer - will be allocated to hold the generated image and - the pointer updated on exit. It is the caller's - responsibility to free this buffer. - - @param BltX, BltY Specifies the offset from the left and top - edge of the output image of the first - pixel in the image. - - @retval EFI_SUCCESS The image was successfully updated. - - @retval EFI_OUT_OF_RESOURCES Unable to allocate an output - buffer for RowInfoArray or Blt. - - @retval EFI_NOT_FOUND The image specified by ImageId is not in the database. - Or The specified PackageList is not in the database. - - @retval EFI_INVALID_PARAMETER The Blt was NULL. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_HII_DRAW_IMAGE_ID)( -IN CONST EFI_HII_IMAGE_PROTOCOL *This, -IN EFI_HII_DRAW_FLAGS Flags, -IN EFI_HII_HANDLE PackageList, -IN EFI_IMAGE_ID ImageId, -IN OUT EFI_IMAGE_OUTPUT **Blt, -IN UINTN BltX, -IN UINTN BltY -); - - -/// -/// Services to access to images in the images database. -/// -struct _EFI_HII_IMAGE_PROTOCOL { - EFI_HII_NEW_IMAGE NewImage; - EFI_HII_GET_IMAGE GetImage; - EFI_HII_SET_IMAGE SetImage; - EFI_HII_DRAW_IMAGE DrawImage; - EFI_HII_DRAW_IMAGE_ID DrawImageId; -}; - -extern EFI_GUID gEfiHiiImageProtocolGuid; - -#endif - - diff --git a/roms/ipxe/src/include/ipxe/efi/Protocol/LoadFile.h b/roms/ipxe/src/include/ipxe/efi/Protocol/LoadFile.h index ba80fdc16..99387e89f 100644 --- a/roms/ipxe/src/include/ipxe/efi/Protocol/LoadFile.h +++ b/roms/ipxe/src/include/ipxe/efi/Protocol/LoadFile.h @@ -7,7 +7,7 @@ UEFI 2.0 can boot from any device that produces a LoadFile protocol. -Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR> This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License that accompanies this distribution. The full text of the license may be found at @@ -66,7 +66,7 @@ typedef EFI_LOAD_FILE_PROTOCOL EFI_LOAD_FILE_INTERFACE; @retval EFI_NO_RESPONSE The remote system did not respond. @retval EFI_NOT_FOUND The file was not found. @retval EFI_ABORTED The file load process was manually cancelled. - @retval EFI_WARN_FILE_SYSTEM The resulting Buffer contains UEFI-compliant file system. + **/ typedef EFI_STATUS diff --git a/roms/ipxe/src/include/ipxe/efi/Protocol/SerialIo.h b/roms/ipxe/src/include/ipxe/efi/Protocol/SerialIo.h deleted file mode 100644 index 130a6ecdc..000000000 --- a/roms/ipxe/src/include/ipxe/efi/Protocol/SerialIo.h +++ /dev/null @@ -1,301 +0,0 @@ -/** @file - Serial IO protocol as defined in the UEFI 2.0 specification. - - Abstraction of a basic serial device. Targeted at 16550 UART, but - could be much more generic. - - Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR> - This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#ifndef __SERIAL_IO_PROTOCOL_H__ -#define __SERIAL_IO_PROTOCOL_H__ - -FILE_LICENCE ( BSD3 ); - -#define EFI_SERIAL_IO_PROTOCOL_GUID \ - { \ - 0xBB25CF6F, 0xF1D4, 0x11D2, {0x9A, 0x0C, 0x00, 0x90, 0x27, 0x3F, 0xC1, 0xFD } \ - } - -/// -/// Protocol GUID defined in EFI1.1. -/// -#define SERIAL_IO_PROTOCOL EFI_SERIAL_IO_PROTOCOL_GUID - -typedef struct _EFI_SERIAL_IO_PROTOCOL EFI_SERIAL_IO_PROTOCOL; - - -/// -/// Backward-compatible with EFI1.1. -/// -typedef EFI_SERIAL_IO_PROTOCOL SERIAL_IO_INTERFACE; - -/// -/// Parity type that is computed or checked as each character is transmitted or received. If the -/// device does not support parity, the value is the default parity value. -/// -typedef enum { - DefaultParity, - NoParity, - EvenParity, - OddParity, - MarkParity, - SpaceParity -} EFI_PARITY_TYPE; - -/// -/// Stop bits type -/// -typedef enum { - DefaultStopBits, - OneStopBit, - OneFiveStopBits, - TwoStopBits -} EFI_STOP_BITS_TYPE; - -// -// define for Control bits, grouped by read only, write only, and read write -// -// -// Read Only -// -#define EFI_SERIAL_CLEAR_TO_SEND 0x00000010 -#define EFI_SERIAL_DATA_SET_READY 0x00000020 -#define EFI_SERIAL_RING_INDICATE 0x00000040 -#define EFI_SERIAL_CARRIER_DETECT 0x00000080 -#define EFI_SERIAL_INPUT_BUFFER_EMPTY 0x00000100 -#define EFI_SERIAL_OUTPUT_BUFFER_EMPTY 0x00000200 - -// -// Write Only -// -#define EFI_SERIAL_REQUEST_TO_SEND 0x00000002 -#define EFI_SERIAL_DATA_TERMINAL_READY 0x00000001 - -// -// Read Write -// -#define EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE 0x00001000 -#define EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE 0x00002000 -#define EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE 0x00004000 - -// -// Serial IO Member Functions -// -/** - Reset the serial device. - - @param This Protocol instance pointer. - - @retval EFI_SUCCESS The device was reset. - @retval EFI_DEVICE_ERROR The serial device could not be reset. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_SERIAL_RESET)( - IN EFI_SERIAL_IO_PROTOCOL *This - ); - -/** - Sets the baud rate, receive FIFO depth, transmit/receice time out, parity, - data bits, and stop bits on a serial device. - - @param This Protocol instance pointer. - @param BaudRate The requested baud rate. A BaudRate value of 0 will use the - device's default interface speed. - @param ReveiveFifoDepth The requested depth of the FIFO on the receive side of the - serial interface. A ReceiveFifoDepth value of 0 will use - the device's default FIFO depth. - @param Timeout The requested time out for a single character in microseconds. - This timeout applies to both the transmit and receive side of the - interface. A Timeout value of 0 will use the device's default time - out value. - @param Parity The type of parity to use on this serial device. A Parity value of - DefaultParity will use the device's default parity value. - @param DataBits The number of data bits to use on the serial device. A DataBits - vaule of 0 will use the device's default data bit setting. - @param StopBits The number of stop bits to use on this serial device. A StopBits - value of DefaultStopBits will use the device's default number of - stop bits. - - @retval EFI_SUCCESS The device was reset. - @retval EFI_DEVICE_ERROR The serial device could not be reset. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_SERIAL_SET_ATTRIBUTES)( - IN EFI_SERIAL_IO_PROTOCOL *This, - IN UINT64 BaudRate, - IN UINT32 ReceiveFifoDepth, - IN UINT32 Timeout, - IN EFI_PARITY_TYPE Parity, - IN UINT8 DataBits, - IN EFI_STOP_BITS_TYPE StopBits - ); - -/** - Set the control bits on a serial device - - @param This Protocol instance pointer. - @param Control Set the bits of Control that are settable. - - @retval EFI_SUCCESS The new control bits were set on the serial device. - @retval EFI_UNSUPPORTED The serial device does not support this operation. - @retval EFI_DEVICE_ERROR The serial device is not functioning correctly. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_SERIAL_SET_CONTROL_BITS)( - IN EFI_SERIAL_IO_PROTOCOL *This, - IN UINT32 Control - ); - -/** - Retrieves the status of thecontrol bits on a serial device - - @param This Protocol instance pointer. - @param Control A pointer to return the current Control signals from the serial device. - - @retval EFI_SUCCESS The control bits were read from the serial device. - @retval EFI_DEVICE_ERROR The serial device is not functioning correctly. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_SERIAL_GET_CONTROL_BITS)( - IN EFI_SERIAL_IO_PROTOCOL *This, - OUT UINT32 *Control - ); - -/** - Writes data to a serial device. - - @param This Protocol instance pointer. - @param BufferSize On input, the size of the Buffer. On output, the amount of - data actually written. - @param Buffer The buffer of data to write - - @retval EFI_SUCCESS The data was written. - @retval EFI_DEVICE_ERROR The device reported an error. - @retval EFI_TIMEOUT The data write was stopped due to a timeout. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_SERIAL_WRITE)( - IN EFI_SERIAL_IO_PROTOCOL *This, - IN OUT UINTN *BufferSize, - IN VOID *Buffer - ); - -/** - Writes data to a serial device. - - @param This Protocol instance pointer. - @param BufferSize On input, the size of the Buffer. On output, the amount of - data returned in Buffer. - @param Buffer The buffer to return the data into. - - @retval EFI_SUCCESS The data was read. - @retval EFI_DEVICE_ERROR The device reported an error. - @retval EFI_TIMEOUT The data write was stopped due to a timeout. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_SERIAL_READ)( - IN EFI_SERIAL_IO_PROTOCOL *This, - IN OUT UINTN *BufferSize, - OUT VOID *Buffer - ); - -/** - @par Data Structure Description: - The data values in SERIAL_IO_MODE are read-only and are updated by the code - that produces the SERIAL_IO_PROTOCOL member functions. - - @param ControlMask - A mask for the Control bits that the device supports. The device - must always support the Input Buffer Empty control bit. - - @param TimeOut - If applicable, the number of microseconds to wait before timing out - a Read or Write operation. - - @param BaudRate - If applicable, the current baud rate setting of the device; otherwise, - baud rate has the value of zero to indicate that device runs at the - device's designed speed. - - @param ReceiveFifoDepth - The number of characters the device will buffer on input - - @param DataBits - The number of characters the device will buffer on input - - @param Parity - If applicable, this is the EFI_PARITY_TYPE that is computed or - checked as each character is transmitted or reveived. If the device - does not support parity the value is the default parity value. - - @param StopBits - If applicable, the EFI_STOP_BITS_TYPE number of stop bits per - character. If the device does not support stop bits the value is - the default stop bit values. - -**/ -typedef struct { - UINT32 ControlMask; - - // - // current Attributes - // - UINT32 Timeout; - UINT64 BaudRate; - UINT32 ReceiveFifoDepth; - UINT32 DataBits; - UINT32 Parity; - UINT32 StopBits; -} EFI_SERIAL_IO_MODE; - -#define EFI_SERIAL_IO_PROTOCOL_REVISION 0x00010000 -#define SERIAL_IO_INTERFACE_REVISION EFI_SERIAL_IO_PROTOCOL_REVISION - -/// -/// The Serial I/O protocol is used to communicate with UART-style serial devices. -/// These can be standard UART serial ports in PC-AT systems, serial ports attached -/// to a USB interface, or potentially any character-based I/O device. -/// -struct _EFI_SERIAL_IO_PROTOCOL { - /// - /// The revision to which the EFI_SERIAL_IO_PROTOCOL adheres. All future revisions - /// must be backwards compatible. If a future version is not backwards compatible, - /// it is not the same GUID. - /// - UINT32 Revision; - EFI_SERIAL_RESET Reset; - EFI_SERIAL_SET_ATTRIBUTES SetAttributes; - EFI_SERIAL_SET_CONTROL_BITS SetControl; - EFI_SERIAL_GET_CONTROL_BITS GetControl; - EFI_SERIAL_WRITE Write; - EFI_SERIAL_READ Read; - /// - /// Pointer to SERIAL_IO_MODE data. - /// - EFI_SERIAL_IO_MODE *Mode; -}; - -extern EFI_GUID gEfiSerialIoProtocolGuid; - -#endif diff --git a/roms/ipxe/src/include/ipxe/efi/Protocol/SimpleNetwork.h b/roms/ipxe/src/include/ipxe/efi/Protocol/SimpleNetwork.h index 2faa668f3..2b521a9de 100644 --- a/roms/ipxe/src/include/ipxe/efi/Protocol/SimpleNetwork.h +++ b/roms/ipxe/src/include/ipxe/efi/Protocol/SimpleNetwork.h @@ -9,7 +9,7 @@ MCast - MultiCast ... -Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR> This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License that accompanies this distribution. The full text of the license may be found at @@ -123,25 +123,6 @@ typedef struct { /// UINT64 UnsupportedProtocol; - /// - /// Number of valid frames received that were duplicated. - /// - UINT64 RxDuplicatedFrames; - - /// - /// Number of encrypted frames received that failed to decrypt. - /// - UINT64 RxDecryptErrorFrames; - - /// - /// Number of frames that failed to transmit after exceeding the retry limit. - /// - UINT64 TxErrorFrames; - - /// - /// Number of frames transmitted successfully after more than one attempt. - /// - UINT64 TxRetryFrames; } EFI_NETWORK_STATISTICS; /// diff --git a/roms/ipxe/src/include/ipxe/efi/Protocol/SimplePointer.h b/roms/ipxe/src/include/ipxe/efi/Protocol/SimplePointer.h deleted file mode 100644 index 3b1e3057b..000000000 --- a/roms/ipxe/src/include/ipxe/efi/Protocol/SimplePointer.h +++ /dev/null @@ -1,145 +0,0 @@ -/** @file - Simple Pointer protocol from the UEFI 2.0 specification. - - Abstraction of a very simple pointer device like a mouse or trackball. - - Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR> - This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#ifndef __SIMPLE_POINTER_H__ -#define __SIMPLE_POINTER_H__ - -FILE_LICENCE ( BSD3 ); - -#define EFI_SIMPLE_POINTER_PROTOCOL_GUID \ - { \ - 0x31878c87, 0xb75, 0x11d5, {0x9a, 0x4f, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \ - } - -typedef struct _EFI_SIMPLE_POINTER_PROTOCOL EFI_SIMPLE_POINTER_PROTOCOL; - -// -// Data structures -// -typedef struct { - /// - /// The signed distance in counts that the pointer device has been moved along the x-axis. - /// - INT32 RelativeMovementX; - /// - /// The signed distance in counts that the pointer device has been moved along the y-axis. - /// - INT32 RelativeMovementY; - /// - /// The signed distance in counts that the pointer device has been moved along the z-axis. - /// - INT32 RelativeMovementZ; - /// - /// If TRUE, then the left button of the pointer device is being - /// pressed. If FALSE, then the left button of the pointer device is not being pressed. - /// - BOOLEAN LeftButton; - /// - /// If TRUE, then the right button of the pointer device is being - /// pressed. If FALSE, then the right button of the pointer device is not being pressed. - /// - BOOLEAN RightButton; -} EFI_SIMPLE_POINTER_STATE; - -typedef struct { - /// - /// The resolution of the pointer device on the x-axis in counts/mm. - /// If 0, then the pointer device does not support an x-axis. - /// - UINT64 ResolutionX; - /// - /// The resolution of the pointer device on the y-axis in counts/mm. - /// If 0, then the pointer device does not support an x-axis. - /// - UINT64 ResolutionY; - /// - /// The resolution of the pointer device on the z-axis in counts/mm. - /// If 0, then the pointer device does not support an x-axis. - /// - UINT64 ResolutionZ; - /// - /// TRUE if a left button is present on the pointer device. Otherwise FALSE. - /// - BOOLEAN LeftButton; - /// - /// TRUE if a right button is present on the pointer device. Otherwise FALSE. - /// - BOOLEAN RightButton; -} EFI_SIMPLE_POINTER_MODE; - -/** - Resets the pointer device hardware. - - @param This A pointer to the EFI_SIMPLE_POINTER_PROTOCOL - instance. - @param ExtendedVerification Indicates that the driver may perform a more exhaustive - verification operation of the device during reset. - - @retval EFI_SUCCESS The device was reset. - @retval EFI_DEVICE_ERROR The device is not functioning correctly and could not be reset. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_SIMPLE_POINTER_RESET)( - IN EFI_SIMPLE_POINTER_PROTOCOL *This, - IN BOOLEAN ExtendedVerification - ); - -/** - Retrieves the current state of a pointer device. - - @param This A pointer to the EFI_SIMPLE_POINTER_PROTOCOL - instance. - @param State A pointer to the state information on the pointer device. - - @retval EFI_SUCCESS The state of the pointer device was returned in State. - @retval EFI_NOT_READY The state of the pointer device has not changed since the last call to - GetState(). - @retval EFI_DEVICE_ERROR A device error occurred while attempting to retrieve the pointer device's - current state. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_SIMPLE_POINTER_GET_STATE)( - IN EFI_SIMPLE_POINTER_PROTOCOL *This, - IN OUT EFI_SIMPLE_POINTER_STATE *State - ); - -/// -/// The EFI_SIMPLE_POINTER_PROTOCOL provides a set of services for a pointer -/// device that can use used as an input device from an application written -/// to this specification. The services include the ability to reset the -/// pointer device, retrieve get the state of the pointer device, and -/// retrieve the capabilities of the pointer device. -/// -struct _EFI_SIMPLE_POINTER_PROTOCOL { - EFI_SIMPLE_POINTER_RESET Reset; - EFI_SIMPLE_POINTER_GET_STATE GetState; - /// - /// Event to use with WaitForEvent() to wait for input from the pointer device. - /// - EFI_EVENT WaitForInput; - /// - /// Pointer to EFI_SIMPLE_POINTER_MODE data. - /// - EFI_SIMPLE_POINTER_MODE *Mode; -}; - -extern EFI_GUID gEfiSimplePointerProtocolGuid; - -#endif diff --git a/roms/ipxe/src/include/ipxe/efi/Protocol/SimpleTextOut.h b/roms/ipxe/src/include/ipxe/efi/Protocol/SimpleTextOut.h index 8aa36c35a..a79cf431c 100644 --- a/roms/ipxe/src/include/ipxe/efi/Protocol/SimpleTextOut.h +++ b/roms/ipxe/src/include/ipxe/efi/Protocol/SimpleTextOut.h @@ -6,7 +6,7 @@ a single hardware device or a virtual device that is an aggregation of multiple physical devices. -Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR> This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License that accompanies this distribution. The full text of the license may be found at @@ -117,7 +117,7 @@ typedef EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL SIMPLE_TEXT_OUTPUT_INTERFACE; #define EFI_BROWN (EFI_GREEN | EFI_RED) #define EFI_LIGHTGRAY (EFI_BLUE | EFI_GREEN | EFI_RED) #define EFI_BRIGHT 0x08 -#define EFI_DARKGRAY (EFI_BLACK | EFI_BRIGHT) +#define EFI_DARKGRAY (EFI_BRIGHT) #define EFI_LIGHTBLUE (EFI_BLUE | EFI_BRIGHT) #define EFI_LIGHTGREEN (EFI_GREEN | EFI_BRIGHT) #define EFI_LIGHTCYAN (EFI_CYAN | EFI_BRIGHT) @@ -126,18 +126,7 @@ typedef EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL SIMPLE_TEXT_OUTPUT_INTERFACE; #define EFI_YELLOW (EFI_BROWN | EFI_BRIGHT) #define EFI_WHITE (EFI_BLUE | EFI_GREEN | EFI_RED | EFI_BRIGHT) -// -// Macro to accept color values in their raw form to create -// a value that represents both a foreground and background -// color in a single byte. -// For Foreground, and EFI_* value is valid from EFI_BLACK(0x00) to -// EFI_WHITE (0x0F). -// For Background, only EFI_BLACK, EFI_BLUE, EFI_GREEN, EFI_CYAN, -// EFI_RED, EFI_MAGENTA, EFI_BROWN, and EFI_LIGHTGRAY are acceptable -// -// Do not use EFI_BACKGROUND_xxx values with this macro. -// -#define EFI_TEXT_ATTR(Foreground,Background) ((Foreground) | ((Background) << 4)) +#define EFI_TEXT_ATTR(f, b) ((f) | ((b) << 4)) #define EFI_BACKGROUND_BLACK 0x00 #define EFI_BACKGROUND_BLUE 0x10 diff --git a/roms/ipxe/src/include/ipxe/efi/Protocol/TcgService.h b/roms/ipxe/src/include/ipxe/efi/Protocol/TcgService.h index 86c69a84e..1068448f0 100644 --- a/roms/ipxe/src/include/ipxe/efi/Protocol/TcgService.h +++ b/roms/ipxe/src/include/ipxe/efi/Protocol/TcgService.h @@ -1,8 +1,8 @@ /** @file - TCG Service Protocol as defined in TCG_EFI_Protocol_1_22_Final + TCG Service Protocol as defined in TCG_EFI_Protocol_1_20_Final See http://trustedcomputinggroup.org for the latest specification -Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR> This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License that accompanies this distribution. The full text of the license may be found at @@ -44,6 +44,12 @@ typedef struct _TCG_EFI_BOOT_SERVICE_CAPABILITY { typedef UINT32 TCG_ALGORITHM_ID; +/// +/// Note: +/// Status codes returned for functions of EFI_TCG_PROTOCOL do not exactly match +/// those defined in the TCG EFI Protocol 1.20 Final Specification. +/// + /** This service provides EFI protocol capability information, state information about the TPM, and Event Log state information. diff --git a/roms/ipxe/src/include/ipxe/efi/Protocol/UgaDraw.h b/roms/ipxe/src/include/ipxe/efi/Protocol/UgaDraw.h deleted file mode 100644 index 565020688..000000000 --- a/roms/ipxe/src/include/ipxe/efi/Protocol/UgaDraw.h +++ /dev/null @@ -1,168 +0,0 @@ -/** @file - UGA Draw protocol from the EFI 1.10 specification. - - Abstraction of a very simple graphics device. - - Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR> - This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#ifndef __UGA_DRAW_H__ -#define __UGA_DRAW_H__ - -FILE_LICENCE ( BSD3 ); - - -#define EFI_UGA_DRAW_PROTOCOL_GUID \ - { \ - 0x982c298b, 0xf4fa, 0x41cb, {0xb8, 0x38, 0x77, 0xaa, 0x68, 0x8f, 0xb8, 0x39 } \ - } - -typedef struct _EFI_UGA_DRAW_PROTOCOL EFI_UGA_DRAW_PROTOCOL; - -/** - Return the current video mode information. - - @param This The EFI_UGA_DRAW_PROTOCOL instance. - @param HorizontalResolution The size of video screen in pixels in the X dimension. - @param VerticalResolution The size of video screen in pixels in the Y dimension. - @param ColorDepth Number of bits per pixel, currently defined to be 32. - @param RefreshRate The refresh rate of the monitor in Hertz. - - @retval EFI_SUCCESS Mode information returned. - @retval EFI_NOT_STARTED Video display is not initialized. Call SetMode () - @retval EFI_INVALID_PARAMETER One of the input args was NULL. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_UGA_DRAW_PROTOCOL_GET_MODE)( - IN EFI_UGA_DRAW_PROTOCOL *This, - OUT UINT32 *HorizontalResolution, - OUT UINT32 *VerticalResolution, - OUT UINT32 *ColorDepth, - OUT UINT32 *RefreshRate - ); - -/** - Set the current video mode information. - - @param This The EFI_UGA_DRAW_PROTOCOL instance. - @param HorizontalResolution The size of video screen in pixels in the X dimension. - @param VerticalResolution The size of video screen in pixels in the Y dimension. - @param ColorDepth Number of bits per pixel, currently defined to be 32. - @param RefreshRate The refresh rate of the monitor in Hertz. - - @retval EFI_SUCCESS Mode information returned. - @retval EFI_NOT_STARTED Video display is not initialized. Call SetMode () - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_UGA_DRAW_PROTOCOL_SET_MODE)( - IN EFI_UGA_DRAW_PROTOCOL *This, - IN UINT32 HorizontalResolution, - IN UINT32 VerticalResolution, - IN UINT32 ColorDepth, - IN UINT32 RefreshRate - ); - -typedef struct { - UINT8 Blue; - UINT8 Green; - UINT8 Red; - UINT8 Reserved; -} EFI_UGA_PIXEL; - -typedef union { - EFI_UGA_PIXEL Pixel; - UINT32 Raw; -} EFI_UGA_PIXEL_UNION; - -/// -/// Enumration value for actions of Blt operations. -/// -typedef enum { - EfiUgaVideoFill, ///< Write data from the BltBuffer pixel (SourceX, SourceY) - ///< directly to every pixel of the video display rectangle - ///< (DestinationX, DestinationY) (DestinationX + Width, DestinationY + Height). - ///< Only one pixel will be used from the BltBuffer. Delta is NOT used. - - EfiUgaVideoToBltBuffer, ///< Read data from the video display rectangle - ///< (SourceX, SourceY) (SourceX + Width, SourceY + Height) and place it in - ///< the BltBuffer rectangle (DestinationX, DestinationY ) - ///< (DestinationX + Width, DestinationY + Height). If DestinationX or - ///< DestinationY is not zero then Delta must be set to the length in bytes - ///< of a row in the BltBuffer. - - EfiUgaBltBufferToVideo, ///< Write data from the BltBuffer rectangle - ///< (SourceX, SourceY) (SourceX + Width, SourceY + Height) directly to the - ///< video display rectangle (DestinationX, DestinationY) - ///< (DestinationX + Width, DestinationY + Height). If SourceX or SourceY is - ///< not zero then Delta must be set to the length in bytes of a row in the - ///< BltBuffer. - - EfiUgaVideoToVideo, ///< Copy from the video display rectangle (SourceX, SourceY) - ///< (SourceX + Width, SourceY + Height) .to the video display rectangle - ///< (DestinationX, DestinationY) (DestinationX + Width, DestinationY + Height). - ///< The BltBuffer and Delta are not used in this mode. - - EfiUgaBltMax ///< Maxmimum value for enumration value of Blt operation. If a Blt operation - ///< larger or equal to this enumration value, it is invalid. -} EFI_UGA_BLT_OPERATION; - -/** - Blt a rectangle of pixels on the graphics screen. - - @param[in] This - Protocol instance pointer. - @param[in] BltBuffer - Buffer containing data to blit into video buffer. This - buffer has a size of Width*Height*sizeof(EFI_UGA_PIXEL) - @param[in] BltOperation - Operation to perform on BlitBuffer and video memory - @param[in] SourceX - X coordinate of source for the BltBuffer. - @param[in] SourceY - Y coordinate of source for the BltBuffer. - @param[in] DestinationX - X coordinate of destination for the BltBuffer. - @param[in] DestinationY - Y coordinate of destination for the BltBuffer. - @param[in] Width - Width of rectangle in BltBuffer in pixels. - @param[in] Height - Hight of rectangle in BltBuffer in pixels. - @param[in] Delta - OPTIONAL - - @retval EFI_SUCCESS - The Blt operation completed. - @retval EFI_INVALID_PARAMETER - BltOperation is not valid. - @retval EFI_DEVICE_ERROR - A hardware error occured writting to the video buffer. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_UGA_DRAW_PROTOCOL_BLT)( - IN EFI_UGA_DRAW_PROTOCOL * This, - IN EFI_UGA_PIXEL * BltBuffer, OPTIONAL - IN EFI_UGA_BLT_OPERATION BltOperation, - IN UINTN SourceX, - IN UINTN SourceY, - IN UINTN DestinationX, - IN UINTN DestinationY, - IN UINTN Width, - IN UINTN Height, - IN UINTN Delta OPTIONAL - ); - -/// -/// This protocol provides a basic abstraction to set video modes and -/// copy pixels to and from the graphics controller's frame buffer. -/// -struct _EFI_UGA_DRAW_PROTOCOL { - EFI_UGA_DRAW_PROTOCOL_GET_MODE GetMode; - EFI_UGA_DRAW_PROTOCOL_SET_MODE SetMode; - EFI_UGA_DRAW_PROTOCOL_BLT Blt; -}; - -extern EFI_GUID gEfiUgaDrawProtocolGuid; - -#endif diff --git a/roms/ipxe/src/include/ipxe/efi/Protocol/UnicodeCollation.h b/roms/ipxe/src/include/ipxe/efi/Protocol/UnicodeCollation.h deleted file mode 100644 index 870428c2b..000000000 --- a/roms/ipxe/src/include/ipxe/efi/Protocol/UnicodeCollation.h +++ /dev/null @@ -1,194 +0,0 @@ -/** @file - Unicode Collation protocol that follows the UEFI 2.0 specification. - This protocol is used to allow code running in the boot services environment - to perform lexical comparison functions on Unicode strings for given languages. - -Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR> -This program and the accompanying materials are licensed and made available under -the terms and conditions of the BSD License that accompanies this distribution. -The full text of the license may be found at -http://opensource.org/licenses/bsd-license.php. - -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#ifndef __UNICODE_COLLATION_H__ -#define __UNICODE_COLLATION_H__ - -FILE_LICENCE ( BSD3 ); - -#define EFI_UNICODE_COLLATION_PROTOCOL_GUID \ - { \ - 0x1d85cd7f, 0xf43d, 0x11d2, {0x9a, 0xc, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \ - } - -#define EFI_UNICODE_COLLATION_PROTOCOL2_GUID \ - { \ - 0xa4c751fc, 0x23ae, 0x4c3e, {0x92, 0xe9, 0x49, 0x64, 0xcf, 0x63, 0xf3, 0x49 } \ - } - -typedef struct _EFI_UNICODE_COLLATION_PROTOCOL EFI_UNICODE_COLLATION_PROTOCOL; - - -/// -/// Protocol GUID name defined in EFI1.1. -/// -#define UNICODE_COLLATION_PROTOCOL EFI_UNICODE_COLLATION_PROTOCOL_GUID - -/// -/// Protocol defined in EFI1.1. -/// -typedef EFI_UNICODE_COLLATION_PROTOCOL UNICODE_COLLATION_INTERFACE; - -/// -/// Protocol data structures and defines -/// -#define EFI_UNICODE_BYTE_ORDER_MARK (CHAR16) (0xfeff) - -// -// Protocol member functions -// -/** - Performs a case-insensitive comparison of two Null-terminated strings. - - @param This A pointer to the EFI_UNICODE_COLLATION_PROTOCOL instance. - @param Str1 A pointer to a Null-terminated string. - @param Str2 A pointer to a Null-terminated string. - - @retval 0 Str1 is equivalent to Str2. - @retval >0 Str1 is lexically greater than Str2. - @retval <0 Str1 is lexically less than Str2. - -**/ -typedef -INTN -(EFIAPI *EFI_UNICODE_COLLATION_STRICOLL)( - IN EFI_UNICODE_COLLATION_PROTOCOL *This, - IN CHAR16 *Str1, - IN CHAR16 *Str2 - ); - -/** - Performs a case-insensitive comparison of a Null-terminated - pattern string and a Null-terminated string. - - @param This A pointer to the EFI_UNICODE_COLLATION_PROTOCOL instance. - @param String A pointer to a Null-terminated string. - @param Pattern A pointer to a Null-terminated pattern string. - - @retval TRUE Pattern was found in String. - @retval FALSE Pattern was not found in String. - -**/ -typedef -BOOLEAN -(EFIAPI *EFI_UNICODE_COLLATION_METAIMATCH)( - IN EFI_UNICODE_COLLATION_PROTOCOL *This, - IN CHAR16 *String, - IN CHAR16 *Pattern - ); - -/** - Converts all the characters in a Null-terminated string to - lower case characters. - - @param This A pointer to the EFI_UNICODE_COLLATION_PROTOCOL instance. - @param String A pointer to a Null-terminated string. - -**/ -typedef -VOID -(EFIAPI *EFI_UNICODE_COLLATION_STRLWR)( - IN EFI_UNICODE_COLLATION_PROTOCOL *This, - IN OUT CHAR16 *Str - ); - -/** - Converts all the characters in a Null-terminated string to upper - case characters. - - @param This A pointer to the EFI_UNICODE_COLLATION_PROTOCOL instance. - @param String A pointer to a Null-terminated string. - -**/ -typedef -VOID -(EFIAPI *EFI_UNICODE_COLLATION_STRUPR)( - IN EFI_UNICODE_COLLATION_PROTOCOL *This, - IN OUT CHAR16 *Str - ); - -/** - Converts an 8.3 FAT file name in an OEM character set to a Null-terminated - string. - - @param This A pointer to the EFI_UNICODE_COLLATION_PROTOCOL instance. - @param FatSize The size of the string Fat in bytes. - @param Fat A pointer to a Null-terminated string that contains an 8.3 file - name using an 8-bit OEM character set. - @param String A pointer to a Null-terminated string. The string must - be allocated in advance to hold FatSize characters. - -**/ -typedef -VOID -(EFIAPI *EFI_UNICODE_COLLATION_FATTOSTR)( - IN EFI_UNICODE_COLLATION_PROTOCOL *This, - IN UINTN FatSize, - IN CHAR8 *Fat, - OUT CHAR16 *String - ); - -/** - Converts a Null-terminated string to legal characters in a FAT - filename using an OEM character set. - - @param This A pointer to the EFI_UNICODE_COLLATION_PROTOCOL instance. - @param String A pointer to a Null-terminated string. - @param FatSize The size of the string Fat in bytes. - @param Fat A pointer to a string that contains the converted version of - String using legal FAT characters from an OEM character set. - - @retval TRUE One or more conversions failed and were substituted with '_' - @retval FALSE None of the conversions failed. - -**/ -typedef -BOOLEAN -(EFIAPI *EFI_UNICODE_COLLATION_STRTOFAT)( - IN EFI_UNICODE_COLLATION_PROTOCOL *This, - IN CHAR16 *String, - IN UINTN FatSize, - OUT CHAR8 *Fat - ); - -/// -/// The EFI_UNICODE_COLLATION_PROTOCOL is used to perform case-insensitive -/// comparisons of strings. -/// -struct _EFI_UNICODE_COLLATION_PROTOCOL { - EFI_UNICODE_COLLATION_STRICOLL StriColl; - EFI_UNICODE_COLLATION_METAIMATCH MetaiMatch; - EFI_UNICODE_COLLATION_STRLWR StrLwr; - EFI_UNICODE_COLLATION_STRUPR StrUpr; - - // - // for supporting fat volumes - // - EFI_UNICODE_COLLATION_FATTOSTR FatToStr; - EFI_UNICODE_COLLATION_STRTOFAT StrToFat; - - /// - /// A Null-terminated ASCII string array that contains one or more language codes. - /// When this field is used for UnicodeCollation2, it is specified in RFC 4646 format. - /// When it is used for UnicodeCollation, it is specified in ISO 639-2 format. - /// - CHAR8 *SupportedLanguages; -}; - -extern EFI_GUID gEfiUnicodeCollationProtocolGuid; -extern EFI_GUID gEfiUnicodeCollation2ProtocolGuid; - -#endif diff --git a/roms/ipxe/src/include/ipxe/efi/Protocol/Usb2HostController.h b/roms/ipxe/src/include/ipxe/efi/Protocol/Usb2HostController.h deleted file mode 100644 index 8308e8f1b..000000000 --- a/roms/ipxe/src/include/ipxe/efi/Protocol/Usb2HostController.h +++ /dev/null @@ -1,666 +0,0 @@ -/** @file - EFI_USB2_HC_PROTOCOL as defined in UEFI 2.0. - The USB Host Controller Protocol is used by code, typically USB bus drivers, - running in the EFI boot services environment, to perform data transactions over - a USB bus. In addition, it provides an abstraction for the root hub of the USB bus. - - Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR> - This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#ifndef _USB2_HOSTCONTROLLER_H_ -#define _USB2_HOSTCONTROLLER_H_ - -FILE_LICENCE ( BSD3 ); - -#include <ipxe/efi/Protocol/UsbIo.h> - -#define EFI_USB2_HC_PROTOCOL_GUID \ - { \ - 0x3e745226, 0x9818, 0x45b6, {0xa2, 0xac, 0xd7, 0xcd, 0xe, 0x8b, 0xa2, 0xbc } \ - } - -/// -/// Forward reference for pure ANSI compatability -/// -typedef struct _EFI_USB2_HC_PROTOCOL EFI_USB2_HC_PROTOCOL; - - -typedef struct { - UINT16 PortStatus; ///< Contains current port status bitmap. - UINT16 PortChangeStatus; ///< Contains current port status change bitmap. -} EFI_USB_PORT_STATUS; - -/// -/// EFI_USB_PORT_STATUS.PortStatus bit definition -/// -#define USB_PORT_STAT_CONNECTION 0x0001 -#define USB_PORT_STAT_ENABLE 0x0002 -#define USB_PORT_STAT_SUSPEND 0x0004 -#define USB_PORT_STAT_OVERCURRENT 0x0008 -#define USB_PORT_STAT_RESET 0x0010 -#define USB_PORT_STAT_POWER 0x0100 -#define USB_PORT_STAT_LOW_SPEED 0x0200 -#define USB_PORT_STAT_HIGH_SPEED 0x0400 -#define USB_PORT_STAT_SUPER_SPEED 0x0800 -#define USB_PORT_STAT_OWNER 0x2000 - -/// -/// EFI_USB_PORT_STATUS.PortChangeStatus bit definition -/// -#define USB_PORT_STAT_C_CONNECTION 0x0001 -#define USB_PORT_STAT_C_ENABLE 0x0002 -#define USB_PORT_STAT_C_SUSPEND 0x0004 -#define USB_PORT_STAT_C_OVERCURRENT 0x0008 -#define USB_PORT_STAT_C_RESET 0x0010 - - -/// -/// Usb port features value -/// Each value indicates its bit index in the port status and status change bitmaps, -/// if combines these two bitmaps into a 32-bit bitmap. -/// -typedef enum { - EfiUsbPortEnable = 1, - EfiUsbPortSuspend = 2, - EfiUsbPortReset = 4, - EfiUsbPortPower = 8, - EfiUsbPortOwner = 13, - EfiUsbPortConnectChange = 16, - EfiUsbPortEnableChange = 17, - EfiUsbPortSuspendChange = 18, - EfiUsbPortOverCurrentChange = 19, - EfiUsbPortResetChange = 20 -} EFI_USB_PORT_FEATURE; - -#define EFI_USB_SPEED_FULL 0x0000 ///< 12 Mb/s, USB 1.1 OHCI and UHCI HC. -#define EFI_USB_SPEED_LOW 0x0001 ///< 1 Mb/s, USB 1.1 OHCI and UHCI HC. -#define EFI_USB_SPEED_HIGH 0x0002 ///< 480 Mb/s, USB 2.0 EHCI HC. -#define EFI_USB_SPEED_SUPER 0x0003 ///< 4.8 Gb/s, USB 3.0 XHCI HC. - -typedef struct { - UINT8 TranslatorHubAddress; ///< device address - UINT8 TranslatorPortNumber; ///< the port number of the hub that device is connected to. -} EFI_USB2_HC_TRANSACTION_TRANSLATOR; - -// -// Protocol definitions -// - -/** - Retrieves the Host Controller capabilities. - - @param This A pointer to the EFI_USB2_HC_PROTOCOL instance. - @param MaxSpeed Host controller data transfer speed. - @param PortNumber Number of the root hub ports. - @param Is64BitCapable TRUE if controller supports 64-bit memory addressing, - FALSE otherwise. - - @retval EFI_SUCCESS The host controller capabilities were retrieved successfully. - @retval EFI_INVALID_PARAMETER One of the input args was NULL. - @retval EFI_DEVICE_ERROR An error was encountered while attempting to - retrieve the capabilities. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB2_HC_PROTOCOL_GET_CAPABILITY)( - IN EFI_USB2_HC_PROTOCOL *This, - OUT UINT8 *MaxSpeed, - OUT UINT8 *PortNumber, - OUT UINT8 *Is64BitCapable - ); - -#define EFI_USB_HC_RESET_GLOBAL 0x0001 -#define EFI_USB_HC_RESET_HOST_CONTROLLER 0x0002 -#define EFI_USB_HC_RESET_GLOBAL_WITH_DEBUG 0x0004 -#define EFI_USB_HC_RESET_HOST_WITH_DEBUG 0x0008 -/** - Provides software reset for the USB host controller. - - @param This A pointer to the EFI_USB2_HC_PROTOCOL instance. - @param Attributes A bit mask of the reset operation to perform. - - @retval EFI_SUCCESS The reset operation succeeded. - @retval EFI_INVALID_PARAMETER Attributes is not valid. - @retval EFI_UNSUPPORTED The type of reset specified by Attributes is not currently - supported by the host controller hardware. - @retval EFI_ACCESS_DENIED Reset operation is rejected due to the debug port being configured - and active; only EFI_USB_HC_RESET_GLOBAL_WITH_DEBUG or - EFI_USB_HC_RESET_HOST_WITH_DEBUG reset Attributes can be used to - perform reset operation for this host controller. - @retval EFI_DEVICE_ERROR An error was encountered while attempting to - retrieve the capabilities. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB2_HC_PROTOCOL_RESET)( - IN EFI_USB2_HC_PROTOCOL *This, - IN UINT16 Attributes - ); - -/** - Enumration value for status of USB HC. -**/ -typedef enum { - EfiUsbHcStateHalt, ///< The host controller is in halt - ///< state. No USB transactions can occur - ///< while in this state. The host - ///< controller can enter this state for - ///< three reasons: 1) After host - ///< controller hardware reset. 2) - ///< Explicitly set by software. 3) - ///< Triggered by a fatal error such as - ///< consistency check failure. - - EfiUsbHcStateOperational, ///< The host controller is in an - ///< operational state. When in - ///< this state, the host - ///< controller can execute bus - ///< traffic. This state must be - ///< explicitly set to enable the - ///< USB bus traffic. - - EfiUsbHcStateSuspend, ///< The host controller is in the - ///< suspend state. No USB - ///< transactions can occur while in - ///< this state. The host controller - ///< enters this state for the - ///< following reasons: 1) Explicitly - ///< set by software. 2) Triggered - ///< when there is no bus traffic for - ///< 3 microseconds. - - EfiUsbHcStateMaximum ///< Maximum value for enumration value of HC status. -} EFI_USB_HC_STATE; - -/** - Retrieves current state of the USB host controller. - - @param This A pointer to the EFI_USB2_HC_PROTOCOL instance. - @param State A pointer to the EFI_USB_HC_STATE data structure that - indicates current state of the USB host controller. - - @retval EFI_SUCCESS The state information of the host controller was returned in State. - @retval EFI_INVALID_PARAMETER State is NULL. - @retval EFI_DEVICE_ERROR An error was encountered while attempting to retrieve the - host controller's current state. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB2_HC_PROTOCOL_GET_STATE)( - IN EFI_USB2_HC_PROTOCOL *This, - OUT EFI_USB_HC_STATE *State -); - -/** - Sets the USB host controller to a specific state. - - @param This A pointer to the EFI_USB2_HC_PROTOCOL instance. - @param State Indicates the state of the host controller that will be set. - - @retval EFI_SUCCESS The USB host controller was successfully placed in the state - specified by State. - @retval EFI_INVALID_PARAMETER State is not valid. - @retval EFI_DEVICE_ERROR Failed to set the state specified by State due to device error. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB2_HC_PROTOCOL_SET_STATE)( - IN EFI_USB2_HC_PROTOCOL *This, - IN EFI_USB_HC_STATE State - ); - -/** - Submits control transfer to a target USB device. - - @param This A pointer to the EFI_USB2_HC_PROTOCOL instance. - @param DeviceAddress Represents the address of the target device on the USB. - @param DeviceSpeed Indicates device speed. - @param MaximumPacketLength Indicates the maximum packet size that the default control transfer - endpoint is capable of sending or receiving. - @param Request A pointer to the USB device request that will be sent to the USB device. - @param TransferDirection Specifies the data direction for the transfer. There are three values - available, EfiUsbDataIn, EfiUsbDataOut and EfiUsbNoData. - @param Data A pointer to the buffer of data that will be transmitted to USB device or - received from USB device. - @param DataLength On input, indicates the size, in bytes, of the data buffer specified by Data. - On output, indicates the amount of data actually transferred. - @param TimeOut Indicates the maximum time, in milliseconds, which the transfer is - allowed to complete. - @param Translator A pointer to the transaction translator data. - @param TransferResult A pointer to the detailed result information generated by this control - transfer. - - @retval EFI_SUCCESS The control transfer was completed successfully. - @retval EFI_INVALID_PARAMETER Some parameters are invalid. - @retval EFI_OUT_OF_RESOURCES The control transfer could not be completed due to a lack of resources. - @retval EFI_TIMEOUT The control transfer failed due to timeout. - @retval EFI_DEVICE_ERROR The control transfer failed due to host controller or device error. - Caller should check TransferResult for detailed error information. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB2_HC_PROTOCOL_CONTROL_TRANSFER)( - IN EFI_USB2_HC_PROTOCOL *This, - IN UINT8 DeviceAddress, - IN UINT8 DeviceSpeed, - IN UINTN MaximumPacketLength, - IN EFI_USB_DEVICE_REQUEST *Request, - IN EFI_USB_DATA_DIRECTION TransferDirection, - IN OUT VOID *Data OPTIONAL, - IN OUT UINTN *DataLength OPTIONAL, - IN UINTN TimeOut, - IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator, - OUT UINT32 *TransferResult - ); - -#define EFI_USB_MAX_BULK_BUFFER_NUM 10 - -/** - Submits bulk transfer to a bulk endpoint of a USB device. - - @param This A pointer to the EFI_USB2_HC_PROTOCOL instance. - @param DeviceAddress Represents the address of the target device on the USB. - @param EndPointAddress The combination of an endpoint number and an endpoint direction of the - target USB device. - @param DeviceSpeed Indicates device speed. - @param MaximumPacketLength Indicates the maximum packet size the target endpoint is capable of - sending or receiving. - @param DataBuffersNumber Number of data buffers prepared for the transfer. - @param Data Array of pointers to the buffers of data that will be transmitted to USB - device or received from USB device. - @param DataLength When input, indicates the size, in bytes, of the data buffers specified by - Data. When output, indicates the actually transferred data size. - @param DataToggle A pointer to the data toggle value. - @param TimeOut Indicates the maximum time, in milliseconds, which the transfer is - allowed to complete. - @param Translator A pointer to the transaction translator data. - @param TransferResult A pointer to the detailed result information of the bulk transfer. - - @retval EFI_SUCCESS The bulk transfer was completed successfully. - @retval EFI_INVALID_PARAMETER Some parameters are invalid. - @retval EFI_OUT_OF_RESOURCES The bulk transfer could not be submitted due to a lack of resources. - @retval EFI_TIMEOUT The bulk transfer failed due to timeout. - @retval EFI_DEVICE_ERROR The bulk transfer failed due to host controller or device error. - Caller should check TransferResult for detailed error information. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB2_HC_PROTOCOL_BULK_TRANSFER)( - IN EFI_USB2_HC_PROTOCOL *This, - IN UINT8 DeviceAddress, - IN UINT8 EndPointAddress, - IN UINT8 DeviceSpeed, - IN UINTN MaximumPacketLength, - IN UINT8 DataBuffersNumber, - IN OUT VOID *Data[EFI_USB_MAX_BULK_BUFFER_NUM], - IN OUT UINTN *DataLength, - IN OUT UINT8 *DataToggle, - IN UINTN TimeOut, - IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator, - OUT UINT32 *TransferResult - ); - -/** - Submits an asynchronous interrupt transfer to an interrupt endpoint of a USB device. - Translator parameter doesn't exist in UEFI2.0 spec, but it will be updated in the following specification version. - - @param This A pointer to the EFI_USB2_HC_PROTOCOL instance. - @param DeviceAddress Represents the address of the target device on the USB. - @param EndPointAddress The combination of an endpoint number and an endpoint direction of the - target USB device. - @param DeviceSpeed Indicates device speed. - @param MaximumPacketLength Indicates the maximum packet size the target endpoint is capable of - sending or receiving. - @param IsNewTransfer If TRUE, an asynchronous interrupt pipe is built between the host and the - target interrupt endpoint. If FALSE, the specified asynchronous interrupt - pipe is canceled. If TRUE, and an interrupt transfer exists for the target - end point, then EFI_INVALID_PARAMETER is returned. - @param DataToggle A pointer to the data toggle value. - @param PollingInterval Indicates the interval, in milliseconds, that the asynchronous interrupt - transfer is polled. - @param DataLength Indicates the length of data to be received at the rate specified by - PollingInterval from the target asynchronous interrupt endpoint. - @param Translator A pointr to the transaction translator data. - @param CallBackFunction The Callback function. This function is called at the rate specified by - PollingInterval. - @param Context The context that is passed to the CallBackFunction. This is an - optional parameter and may be NULL. - - @retval EFI_SUCCESS The asynchronous interrupt transfer request has been successfully - submitted or canceled. - @retval EFI_INVALID_PARAMETER Some parameters are invalid. - @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB2_HC_PROTOCOL_ASYNC_INTERRUPT_TRANSFER)( - IN EFI_USB2_HC_PROTOCOL *This, - IN UINT8 DeviceAddress, - IN UINT8 EndPointAddress, - IN UINT8 DeviceSpeed, - IN UINTN MaxiumPacketLength, - IN BOOLEAN IsNewTransfer, - IN OUT UINT8 *DataToggle, - IN UINTN PollingInterval OPTIONAL, - IN UINTN DataLength OPTIONAL, - IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator OPTIONAL, - IN EFI_ASYNC_USB_TRANSFER_CALLBACK CallBackFunction OPTIONAL, - IN VOID *Context OPTIONAL - ); - -/** - Submits synchronous interrupt transfer to an interrupt endpoint of a USB device. - Translator parameter doesn't exist in UEFI2.0 spec, but it will be updated in the following specification version. - - @param This A pointer to the EFI_USB2_HC_PROTOCOL instance. - @param DeviceAddress Represents the address of the target device on the USB. - @param EndPointAddress The combination of an endpoint number and an endpoint direction of the - target USB device. - @param DeviceSpeed Indicates device speed. - @param MaximumPacketLength Indicates the maximum packet size the target endpoint is capable of - sending or receiving. - @param Data A pointer to the buffer of data that will be transmitted to USB device or - received from USB device. - @param DataLength On input, the size, in bytes, of the data buffer specified by Data. On - output, the number of bytes transferred. - @param DataToggle A pointer to the data toggle value. - @param TimeOut Indicates the maximum time, in milliseconds, which the transfer is - allowed to complete. - @param Translator A pointr to the transaction translator data. - @param TransferResult A pointer to the detailed result information from the synchronous - interrupt transfer. - - @retval EFI_SUCCESS The synchronous interrupt transfer was completed successfully. - @retval EFI_INVALID_PARAMETER Some parameters are invalid. - @retval EFI_OUT_OF_RESOURCES The synchronous interrupt transfer could not be submitted due to a lack of resources. - @retval EFI_TIMEOUT The synchronous interrupt transfer failed due to timeout. - @retval EFI_DEVICE_ERROR The synchronous interrupt transfer failed due to host controller or device error. - Caller should check TransferResult for detailed error information. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB2_HC_PROTOCOL_SYNC_INTERRUPT_TRANSFER)( - IN EFI_USB2_HC_PROTOCOL *This, - IN UINT8 DeviceAddress, - IN UINT8 EndPointAddress, - IN UINT8 DeviceSpeed, - IN UINTN MaximumPacketLength, - IN OUT VOID *Data, - IN OUT UINTN *DataLength, - IN OUT UINT8 *DataToggle, - IN UINTN TimeOut, - IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator, - OUT UINT32 *TransferResult - ); - -#define EFI_USB_MAX_ISO_BUFFER_NUM 7 -#define EFI_USB_MAX_ISO_BUFFER_NUM1 2 - -/** - Submits isochronous transfer to an isochronous endpoint of a USB device. - - This function is used to submit isochronous transfer to a target endpoint of a USB device. - The target endpoint is specified by DeviceAddressand EndpointAddress. Isochronous transfers are - used when working with isochronous date. It provides periodic, continuous communication between - the host and a device. Isochronous transfers can beused only by full-speed, high-speed, and - super-speed devices. - - High-speed isochronous transfers can be performed using multiple data buffers. The number of - buffers that are actually prepared for the transfer is specified by DataBuffersNumber. For - full-speed isochronous transfers this value is ignored. - - Data represents a list of pointers to the data buffers. For full-speed isochronous transfers - only the data pointed by Data[0]shall be used. For high-speed isochronous transfers and for - the split transactions depending on DataLengththere several data buffers canbe used. For the - high-speed isochronous transfers the total number of buffers must not exceed EFI_USB_MAX_ISO_BUFFER_NUM. - - For split transactions performed on full-speed device by high-speed host controller the total - number of buffers is limited to EFI_USB_MAX_ISO_BUFFER_NUM1. - If the isochronous transfer is successful, then EFI_SUCCESSis returned. The isochronous transfer - is designed to be completed within one USB frame time, if it cannot be completed, EFI_TIMEOUT - is returned. If an error other than timeout occurs during the USB transfer, then EFI_DEVICE_ERROR - is returned and the detailed status code will be returned in TransferResult. - - EFI_INVALID_PARAMETERis returned if one of the following conditionsis satisfied: - - Data is NULL. - - DataLength is 0. - - DeviceSpeed is not one of the supported values listed above. - - MaximumPacketLength is invalid. MaximumPacketLength must be 1023 or less for full-speed devices, - and 1024 or less for high-speed and super-speed devices. - - TransferResult is NULL. - - @param This A pointer to the EFI_USB2_HC_PROTOCOL instance. - @param DeviceAddress Represents the address of the target device on the USB. - @param EndPointAddress The combination of an endpoint number and an endpoint direction of the - target USB device. - @param DeviceSpeed Indicates device speed. The supported values are EFI_USB_SPEED_FULL, - EFI_USB_SPEED_HIGH, or EFI_USB_SPEED_SUPER. - @param MaximumPacketLength Indicates the maximum packet size the target endpoint is capable of - sending or receiving. - @param DataBuffersNumber Number of data buffers prepared for the transfer. - @param Data Array of pointers to the buffers of data that will be transmitted to USB - device or received from USB device. - @param DataLength Specifies the length, in bytes, of the data to be sent to or received from - the USB device. - @param Translator A pointer to the transaction translator data. - @param TransferResult A pointer to the detailed result information of the isochronous transfer. - - @retval EFI_SUCCESS The isochronous transfer was completed successfully. - @retval EFI_INVALID_PARAMETER Some parameters are invalid. - @retval EFI_OUT_OF_RESOURCES The isochronous transfer could not be submitted due to a lack of resources. - @retval EFI_TIMEOUT The isochronous transfer cannot be completed within the one USB frame time. - @retval EFI_DEVICE_ERROR The isochronous transfer failed due to host controller or device error. - Caller should check TransferResult for detailed error information. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB2_HC_PROTOCOL_ISOCHRONOUS_TRANSFER)( - IN EFI_USB2_HC_PROTOCOL *This, - IN UINT8 DeviceAddress, - IN UINT8 EndPointAddress, - IN UINT8 DeviceSpeed, - IN UINTN MaximumPacketLength, - IN UINT8 DataBuffersNumber, - IN OUT VOID *Data[EFI_USB_MAX_ISO_BUFFER_NUM], - IN UINTN DataLength, - IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator, - OUT UINT32 *TransferResult - ); - -/** - Submits nonblocking isochronous transfer to an isochronous endpoint of a USB device. - - This is an asynchronous type of USB isochronous transfer. If the caller submits a USB - isochronous transfer request through this function, this function will return immediately. - - When the isochronous transfer completes, the IsochronousCallbackfunction will be triggered, - the caller can know the transfer results. If the transfer is successful, the caller can get - the data received or sent in this callback function. - - The target endpoint is specified by DeviceAddressand EndpointAddress. Isochronous transfers - are used when working with isochronous date. It provides periodic, continuous communication - between the host and a device. Isochronous transfers can be used only by full-speed, high-speed, - and super-speed devices. - - High-speed isochronous transfers can be performed using multiple data buffers. The number of - buffers that are actually prepared for the transfer is specified by DataBuffersNumber. For - full-speed isochronous transfers this value is ignored. - - Data represents a list of pointers to the data buffers. For full-speed isochronous transfers - only the data pointed by Data[0] shall be used. For high-speed isochronous transfers and for - the split transactions depending on DataLength there several data buffers can be used. For - the high-speed isochronous transfers the total number of buffers must not exceed EFI_USB_MAX_ISO_BUFFER_NUM. - - For split transactions performed on full-speed device by high-speed host controller the total - number of buffers is limited to EFI_USB_MAX_ISO_BUFFER_NUM1. - - EFI_INVALID_PARAMETER is returned if one of the following conditionsis satisfied: - - Data is NULL. - - DataLength is 0. - - DeviceSpeed is not one of the supported values listed above. - - MaximumPacketLength is invalid. MaximumPacketLength must be 1023 or less for full-speed - devices and 1024 or less for high-speed and super-speed devices. - - @param This A pointer to the EFI_USB2_HC_PROTOCOL instance. - @param DeviceAddress Represents the address of the target device on the USB. - @param EndPointAddress The combination of an endpoint number and an endpoint direction of the - target USB device. - @param DeviceSpeed Indicates device speed. The supported values are EFI_USB_SPEED_FULL, - EFI_USB_SPEED_HIGH, or EFI_USB_SPEED_SUPER. - @param MaximumPacketLength Indicates the maximum packet size the target endpoint is capable of - sending or receiving. - @param DataBuffersNumber Number of data buffers prepared for the transfer. - @param Data Array of pointers to the buffers of data that will be transmitted to USB - device or received from USB device. - @param DataLength Specifies the length, in bytes, of the data to be sent to or received from - the USB device. - @param Translator A pointer to the transaction translator data. - @param IsochronousCallback The Callback function. This function is called if the requested - isochronous transfer is completed. - @param Context Data passed to the IsochronousCallback function. This is an - optional parameter and may be NULL. - - @retval EFI_SUCCESS The asynchronous isochronous transfer request has been successfully - submitted or canceled. - @retval EFI_INVALID_PARAMETER Some parameters are invalid. - @retval EFI_OUT_OF_RESOURCES The asynchronous isochronous transfer could not be submitted due to - a lack of resources. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB2_HC_PROTOCOL_ASYNC_ISOCHRONOUS_TRANSFER)( - IN EFI_USB2_HC_PROTOCOL *This, - IN UINT8 DeviceAddress, - IN UINT8 EndPointAddress, - IN UINT8 DeviceSpeed, - IN UINTN MaximumPacketLength, - IN UINT8 DataBuffersNumber, - IN OUT VOID *Data[EFI_USB_MAX_ISO_BUFFER_NUM], - IN UINTN DataLength, - IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator, - IN EFI_ASYNC_USB_TRANSFER_CALLBACK IsochronousCallBack, - IN VOID *Context OPTIONAL - ); - -/** - Retrieves the current status of a USB root hub port. - - @param This A pointer to the EFI_USB2_HC_PROTOCOL instance. - @param PortNumber Specifies the root hub port from which the status is to be retrieved. - This value is zero based. - @param PortStatus A pointer to the current port status bits and port status change bits. - - @retval EFI_SUCCESS The status of the USB root hub port specified by PortNumber - was returned in PortStatus. - @retval EFI_INVALID_PARAMETER PortNumber is invalid. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB2_HC_PROTOCOL_GET_ROOTHUB_PORT_STATUS)( - IN EFI_USB2_HC_PROTOCOL *This, - IN UINT8 PortNumber, - OUT EFI_USB_PORT_STATUS *PortStatus - ); - -/** - Sets a feature for the specified root hub port. - - @param This A pointer to the EFI_USB2_HC_PROTOCOL instance. - @param PortNumber Specifies the root hub port whose feature is requested to be set. This - value is zero based. - @param PortFeature Indicates the feature selector associated with the feature set request. - - @retval EFI_SUCCESS The feature specified by PortFeature was set for the USB - root hub port specified by PortNumber. - @retval EFI_INVALID_PARAMETER PortNumber is invalid or PortFeature is invalid for this function. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB2_HC_PROTOCOL_SET_ROOTHUB_PORT_FEATURE)( - IN EFI_USB2_HC_PROTOCOL *This, - IN UINT8 PortNumber, - IN EFI_USB_PORT_FEATURE PortFeature - ); - -/** - Clears a feature for the specified root hub port. - - @param This A pointer to the EFI_USB2_HC_PROTOCOL instance. - @param PortNumber Specifies the root hub port whose feature is requested to be cleared. This - value is zero based. - @param PortFeature Indicates the feature selector associated with the feature clear request. - - @retval EFI_SUCCESS The feature specified by PortFeature was cleared for the USB - root hub port specified by PortNumber. - @retval EFI_INVALID_PARAMETER PortNumber is invalid or PortFeature is invalid for this function. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB2_HC_PROTOCOL_CLEAR_ROOTHUB_PORT_FEATURE)( - IN EFI_USB2_HC_PROTOCOL *This, - IN UINT8 PortNumber, - IN EFI_USB_PORT_FEATURE PortFeature - ); - -/// -/// The EFI_USB2_HC_PROTOCOL provides USB host controller management, basic -/// data transactions over a USB bus, and USB root hub access. A device driver -/// that wishes to manage a USB bus in a system retrieves the EFI_USB2_HC_PROTOCOL -/// instance that is associated with the USB bus to be managed. A device handle -/// for a USB host controller will minimally contain an EFI_DEVICE_PATH_PROTOCOL -/// instance, and an EFI_USB2_HC_PROTOCOL instance. -/// -struct _EFI_USB2_HC_PROTOCOL { - EFI_USB2_HC_PROTOCOL_GET_CAPABILITY GetCapability; - EFI_USB2_HC_PROTOCOL_RESET Reset; - EFI_USB2_HC_PROTOCOL_GET_STATE GetState; - EFI_USB2_HC_PROTOCOL_SET_STATE SetState; - EFI_USB2_HC_PROTOCOL_CONTROL_TRANSFER ControlTransfer; - EFI_USB2_HC_PROTOCOL_BULK_TRANSFER BulkTransfer; - EFI_USB2_HC_PROTOCOL_ASYNC_INTERRUPT_TRANSFER AsyncInterruptTransfer; - EFI_USB2_HC_PROTOCOL_SYNC_INTERRUPT_TRANSFER SyncInterruptTransfer; - EFI_USB2_HC_PROTOCOL_ISOCHRONOUS_TRANSFER IsochronousTransfer; - EFI_USB2_HC_PROTOCOL_ASYNC_ISOCHRONOUS_TRANSFER AsyncIsochronousTransfer; - EFI_USB2_HC_PROTOCOL_GET_ROOTHUB_PORT_STATUS GetRootHubPortStatus; - EFI_USB2_HC_PROTOCOL_SET_ROOTHUB_PORT_FEATURE SetRootHubPortFeature; - EFI_USB2_HC_PROTOCOL_CLEAR_ROOTHUB_PORT_FEATURE ClearRootHubPortFeature; - - /// - /// The major revision number of the USB host controller. The revision information - /// indicates the release of the Universal Serial Bus Specification with which the - /// host controller is compliant. - /// - UINT16 MajorRevision; - - /// - /// The minor revision number of the USB host controller. The revision information - /// indicates the release of the Universal Serial Bus Specification with which the - /// host controller is compliant. - /// - UINT16 MinorRevision; -}; - -extern EFI_GUID gEfiUsb2HcProtocolGuid; - -#endif diff --git a/roms/ipxe/src/include/ipxe/efi/Protocol/UsbHostController.h b/roms/ipxe/src/include/ipxe/efi/Protocol/UsbHostController.h deleted file mode 100644 index a29088c6f..000000000 --- a/roms/ipxe/src/include/ipxe/efi/Protocol/UsbHostController.h +++ /dev/null @@ -1,510 +0,0 @@ -/** @file - EFI_USB_HC_PROTOCOL as defined in EFI 1.10. - - The USB Host Controller Protocol is used by code, typically USB bus drivers, - running in the EFI boot services environment, to perform data transactions - over a USB bus. In addition, it provides an abstraction for the root hub of the USB bus. - - Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR> - This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#ifndef _USB_HOSTCONTROLLER_H_ -#define _USB_HOSTCONTROLLER_H_ - -FILE_LICENCE ( BSD3 ); - -#include <ipxe/efi/Protocol/Usb2HostController.h> - -#define EFI_USB_HC_PROTOCOL_GUID \ - { \ - 0xf5089266, 0x1aa0, 0x4953, {0x97, 0xd8, 0x56, 0x2f, 0x8a, 0x73, 0xb5, 0x19 } \ - } - -/// -/// Forward reference for pure ANSI compatability -/// -typedef struct _EFI_USB_HC_PROTOCOL EFI_USB_HC_PROTOCOL; - -// -// Protocol definitions -// - -/** - Provides software reset for the USB host controller. - - @param This A pointer to the EFI_USB_HC_PROTOCOL instance. - @param Attributes A bit mask of the reset operation to perform. - - @retval EFI_SUCCESS The reset operation succeeded. - @retval EFI_UNSUPPORTED The type of reset specified by Attributes is not currently supported - by the host controller hardware. - @retval EFI_INVALID_PARAMETER Attributes is not valid. - @retval EFI_DEVICE_ERROR An error was encountered while attempting to perform the reset operation. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB_HC_PROTOCOL_RESET)( - IN EFI_USB_HC_PROTOCOL *This, - IN UINT16 Attributes - ); - -/** - Retrieves current state of the USB host controller. - - @param This A pointer to the EFI_USB_HC_PROTOCOL instance. - @param State A pointer to the EFI_USB_HC_STATE data structure that - indicates current state of the USB host controller. - - @retval EFI_SUCCESS The state information of the host controller was returned in State. - @retval EFI_INVALID_PARAMETER State is NULL. - @retval EFI_DEVICE_ERROR An error was encountered while attempting to retrieve the host controller's - current state. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB_HC_PROTOCOL_GET_STATE)( - IN EFI_USB_HC_PROTOCOL *This, - OUT EFI_USB_HC_STATE *State - ); - -/** - Sets the USB host controller to a specific state. - - @param This A pointer to the EFI_USB_HC_PROTOCOL instance. - @param State Indicates the state of the host controller that will be set. - - @retval EFI_SUCCESS The USB host controller was successfully placed in the state specified by - State. - @retval EFI_INVALID_PARAMETER State is NULL. - @retval EFI_DEVICE_ERROR Failed to set the state specified by State due to device error. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB_HC_PROTOCOL_SET_STATE)( - IN EFI_USB_HC_PROTOCOL *This, - IN EFI_USB_HC_STATE State - ); - -/** - Submits control transfer to a target USB device. - - @param This A pointer to the EFI_USB_HC_PROTOCOL instance. - @param DeviceAddress Represents the address of the target device on the USB, which is - assigned during USB enumeration. - @param IsSlowDevice Indicates whether the target device is slow device or full-speed - device. - @param MaximumPacketLength Indicates the maximum packet size that the default control - transfer endpoint is capable of sending or receiving. - @param Request A pointer to the USB device request that will be sent to the USB - device. - @param TransferDirection Specifies the data direction for the transfer. There are three - values available, EfiUsbDataIn, EfiUsbDataOut and EfiUsbNoData. - @param Data A pointer to the buffer of data that will be transmitted to USB - device or received from USB device. - @param DataLength On input, indicates the size, in bytes, of the data buffer specified - by Data. On output, indicates the amount of data actually - transferred. - @param TimeOut Indicates the maximum time, in milliseconds, which the transfer - is allowed to complete. - @param TransferResult A pointer to the detailed result information generated by this - control transfer. - - @retval EFI_SUCCESS The control transfer was completed successfully. - @retval EFI_OUT_OF_RESOURCES The control transfer could not be completed due to a lack of resources. - @retval EFI_INVALID_PARAMETER Some parameters are invalid. - @retval EFI_TIMEOUT The control transfer failed due to timeout. - @retval EFI_DEVICE_ERROR The control transfer failed due to host controller or device error. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB_HC_PROTOCOL_CONTROL_TRANSFER)( - IN EFI_USB_HC_PROTOCOL *This, - IN UINT8 DeviceAddress, - IN BOOLEAN IsSlowDevice, - IN UINT8 MaximumPacketLength, - IN EFI_USB_DEVICE_REQUEST *Request, - IN EFI_USB_DATA_DIRECTION TransferDirection, - IN OUT VOID *Data OPTIONAL, - IN OUT UINTN *DataLength OPTIONAL, - IN UINTN TimeOut, - OUT UINT32 *TransferResult - ); - -/** - Submits bulk transfer to a bulk endpoint of a USB device. - - @param This A pointer to the EFI_USB_HC_PROTOCOL instance. - @param DeviceAddress Represents the address of the target device on the USB, which is - assigned during USB enumeration. - @param EndPointAddress The combination of an endpoint number and an endpoint - direction of the target USB device. Each endpoint address - supports data transfer in one direction except the control - endpoint (whose default endpoint address is 0). It is the - caller's responsibility to make sure that the EndPointAddress - represents a bulk endpoint. - @param MaximumPacketLength Indicates the maximum packet size that the default control - transfer endpoint is capable of sending or receiving. - @param Data A pointer to the buffer of data that will be transmitted to USB - device or received from USB device. - @param DataLength On input, indicates the size, in bytes, of the data buffer specified - by Data. On output, indicates the amount of data actually - transferred. - @param DataToggle A pointer to the data toggle value. - @param TimeOut Indicates the maximum time, in milliseconds, which the transfer - is allowed to complete. - @param TransferResult A pointer to the detailed result information of the bulk transfer. - - @retval EFI_SUCCESS The bulk transfer was completed successfully. - @retval EFI_OUT_OF_RESOURCES The bulk transfer could not be completed due to a lack of resources. - @retval EFI_INVALID_PARAMETER Some parameters are invalid. - @retval EFI_TIMEOUT The bulk transfer failed due to timeout. - @retval EFI_DEVICE_ERROR The bulk transfer failed due to host controller or device error. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB_HC_PROTOCOL_BULK_TRANSFER)( - IN EFI_USB_HC_PROTOCOL *This, - IN UINT8 DeviceAddress, - IN UINT8 EndPointAddress, - IN UINT8 MaximumPacketLength, - IN OUT VOID *Data, - IN OUT UINTN *DataLength, - IN OUT UINT8 *DataToggle, - IN UINTN TimeOut, - OUT UINT32 *TransferResult - ); - -/** - Submits an asynchronous interrupt transfer to an interrupt endpoint of a USB device. - - @param This A pointer to the EFI_USB_HC_PROTOCOL instance. - @param DeviceAddress Represents the address of the target device on the USB, which is - assigned during USB enumeration. - @param EndPointAddress The combination of an endpoint number and an endpoint - direction of the target USB device. Each endpoint address - supports data transfer in one direction except the control - endpoint (whose default endpoint address is zero). It is the - caller's responsibility to make sure that the - EndPointAddress represents an interrupt endpoint. - @param IsSlowDevice Indicates whether the target device is slow device or full-speed - device. - @param MaximumPacketLength Indicates the maximum packet size that the default control - transfer endpoint is capable of sending or receiving. - @param IsNewTransfer If TRUE, an asynchronous interrupt pipe is built between the host - and the target interrupt endpoint. If FALSE, the specified asynchronous - interrupt pipe is canceled. If TRUE, and an interrupt transfer exists - for the target end point, then EFI_INVALID_PARAMETER is returned. - @param DataToggle A pointer to the data toggle value. On input, it is valid when - IsNewTransfer is TRUE, and it indicates the initial data toggle - value the asynchronous interrupt transfer should adopt. On output, - it is valid when IsNewTransfer is FALSE, and it is updated to indicate - the data toggle value of the subsequent asynchronous interrupt transfer. - @param PollingInterval Indicates the interval, in milliseconds, that the asynchronous - interrupt transfer is polled. - @param DataLength Indicates the length of data to be received at the rate specified by - PollingInterval from the target asynchronous interrupt - endpoint. This parameter is only required when IsNewTransfer is TRUE. - @param CallBackFunction The Callback function. This function is called at the rate specified by - PollingInterval. This parameter is only required when IsNewTransfer is TRUE. - @param Context The context that is passed to the CallBackFunction. - - @retval EFI_SUCCESS The asynchronous interrupt transfer request has been successfully - submitted or canceled. - @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources. - @retval EFI_INVALID_PARAMETER Some parameters are invalid. - @retval EFI_TIMEOUT The bulk transfer failed due to timeout. - @retval EFI_DEVICE_ERROR The bulk transfer failed due to host controller or device error. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB_HC_PROTOCOL_ASYNC_INTERRUPT_TRANSFER)( - IN EFI_USB_HC_PROTOCOL *This, - IN UINT8 DeviceAddress, - IN UINT8 EndPointAddress, - IN BOOLEAN IsSlowDevice, - IN UINT8 MaxiumPacketLength, - IN BOOLEAN IsNewTransfer, - IN OUT UINT8 *DataToggle, - IN UINTN PollingInterval OPTIONAL, - IN UINTN DataLength OPTIONAL, - IN EFI_ASYNC_USB_TRANSFER_CALLBACK CallBackFunction OPTIONAL, - IN VOID *Context OPTIONAL - ); - -/** - Submits synchronous interrupt transfer to an interrupt endpoint of a USB device. - - @param This A pointer to the EFI_USB_HC_PROTOCOL instance. - @param DeviceAddress Represents the address of the target device on the USB, which is - assigned during USB enumeration. - @param EndPointAddress The combination of an endpoint number and an endpoint - direction of the target USB device. Each endpoint address - supports data transfer in one direction except the control - endpoint (whose default endpoint address is zero). It is the - caller's responsibility to make sure that the - EndPointAddress represents an interrupt endpoint. - @param IsSlowDevice Indicates whether the target device is slow device or full-speed - device. - @param MaximumPacketLength Indicates the maximum packet size that the default control - transfer endpoint is capable of sending or receiving. - @param Data A pointer to the buffer of data that will be transmitted to USB - device or received from USB device. asynchronous interrupt pipe is canceled. - @param DataLength On input, the size, in bytes, of the data buffer specified by Data. - On output, the number of bytes transferred. - @param DataToggle A pointer to the data toggle value. On input, it indicates the initial - data toggle value the synchronous interrupt transfer should adopt; - on output, it is updated to indicate the data toggle value of the - subsequent synchronous interrupt transfer. - @param TimeOut Indicates the maximum time, in milliseconds, which the transfer - is allowed to complete. - @param TransferResult A pointer to the detailed result information from the synchronous - interrupt transfer. - - @retval EFI_SUCCESS The synchronous interrupt transfer was completed successfully. - @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources. - @retval EFI_INVALID_PARAMETER Some parameters are invalid. - @retval EFI_TIMEOUT The synchronous interrupt transfer failed due to timeout. - @retval EFI_DEVICE_ERROR The synchronous interrupt transfer failed due to host controller or device error. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB_HC_PROTOCOL_SYNC_INTERRUPT_TRANSFER)( - IN EFI_USB_HC_PROTOCOL *This, - IN UINT8 DeviceAddress, - IN UINT8 EndPointAddress, - IN BOOLEAN IsSlowDevice, - IN UINT8 MaximumPacketLength, - IN OUT VOID *Data, - IN OUT UINTN *DataLength, - IN OUT UINT8 *DataToggle, - IN UINTN TimeOut, - OUT UINT32 *TransferResult - ); - -/** - Submits isochronous transfer to an isochronous endpoint of a USB device. - - @param This A pointer to the EFI_USB_HC_PROTOCOL instance. - @param DeviceAddress Represents the address of the target device on the USB, which is - assigned during USB enumeration. - @param EndPointAddress The combination of an endpoint number and an endpoint - direction of the target USB device. Each endpoint address - supports data transfer in one direction except the control - endpoint (whose default endpoint address is 0). It is the caller's - responsibility to make sure that the EndPointAddress - represents an isochronous endpoint. - @param MaximumPacketLength Indicates the maximum packet size that the default control - transfer endpoint is capable of sending or receiving. - @param Data A pointer to the buffer of data that will be transmitted to USB - device or received from USB device. asynchronous interrupt pipe is canceled. - @param DataLength Specifies the length, in bytes, of the data to be sent to or received - from the USB device. - @param TransferResult A pointer to the detailed result information from the isochronous - transfer. - - @retval EFI_SUCCESS The isochronous transfer was completed successfully. - @retval EFI_OUT_OF_RESOURCES The isochronous could not be completed due to a lack of resources. - @retval EFI_INVALID_PARAMETER Some parameters are invalid. - @retval EFI_TIMEOUT The isochronous transfer failed due to timeout. - @retval EFI_DEVICE_ERROR The isochronous transfer failed due to host controller or device error. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB_HC_PROTOCOL_ISOCHRONOUS_TRANSFER)( - IN EFI_USB_HC_PROTOCOL *This, - IN UINT8 DeviceAddress, - IN UINT8 EndPointAddress, - IN UINT8 MaximumPacketLength, - IN OUT VOID *Data, - IN UINTN DataLength, - OUT UINT32 *TransferResult - ); - -/** - Submits nonblocking isochronous transfer to an isochronous endpoint of a USB device. - - @param This A pointer to the EFI_USB_HC_PROTOCOL instance. - @param DeviceAddress Represents the address of the target device on the USB, which is - assigned during USB enumeration. - @param EndPointAddress The combination of an endpoint number and an endpoint - direction of the target USB device. Each endpoint address - supports data transfer in one direction except the control - endpoint (whose default endpoint address is zero). It is the - caller's responsibility to make sure that the - EndPointAddress represents an isochronous endpoint. - @param MaximumPacketLength Indicates the maximum packet size that the default control - transfer endpoint is capable of sending or receiving. For isochronous - endpoints, this value is used to reserve the bus time in the schedule, - required for the perframe data payloads. The pipe may, on an ongoing basis, - actually use less bandwidth than that reserved. - @param Data A pointer to the buffer of data that will be transmitted to USB - device or received from USB device. asynchronous interrupt pipe is canceled. - @param DataLength Specifies the length, in bytes, of the data to be sent to or received - from the USB device. - @param IsochronousCallback The Callback function.This function is called if the requested - isochronous transfer is completed. - @param Context Data passed to the IsochronousCallback function. This is - an optional parameter and may be NULL. - - @retval EFI_SUCCESS The asynchronous isochronous transfer was completed successfully. - @retval EFI_OUT_OF_RESOURCES The asynchronous isochronous could not be completed due to a lack of resources. - @retval EFI_INVALID_PARAMETER Some parameters are invalid. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB_HC_PROTOCOL_ASYNC_ISOCHRONOUS_TRANSFER)( - IN EFI_USB_HC_PROTOCOL *This, - IN UINT8 DeviceAddress, - IN UINT8 EndPointAddress, - IN UINT8 MaximumPacketLength, - IN OUT VOID *Data, - IN UINTN DataLength, - IN EFI_ASYNC_USB_TRANSFER_CALLBACK IsochronousCallBack, - IN VOID *Context OPTIONAL - ); - -/** - Retrieves the number of root hub ports. - - @param This A pointer to the EFI_USB_HC_PROTOCOL instance. - @param PortNumber A pointer to the number of the root hub ports. - - @retval EFI_SUCCESS The port number was retrieved successfully. - @retval EFI_DEVICE_ERROR An error was encountered while attempting to retrieve the port number. - @retval EFI_INVALID_PARAMETER PortNumber is NULL. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB_HC_PROTOCOL_GET_ROOTHUB_PORT_NUMBER)( - IN EFI_USB_HC_PROTOCOL *This, - OUT UINT8 *PortNumber - ); - -/** - Retrieves the current status of a USB root hub port. - - @param This A pointer to the EFI_USB_HC_PROTOCOL instance. - @param PortNumber Specifies the root hub port from which the status is to be retrieved. - This value is zero based. For example, if a root hub has two ports, - then the first port is numbered 0, and the second port is - numbered 1. - @param PortStatus A pointer to the current port status bits and port status change bits. - - @retval EFI_SUCCESS The status of the USB root hub port specified by PortNumber - was returned in PortStatus. - @retval EFI_INVALID_PARAMETER PortNumber is invalid. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB_HC_PROTOCOL_GET_ROOTHUB_PORT_STATUS)( - IN EFI_USB_HC_PROTOCOL *This, - IN UINT8 PortNumber, - OUT EFI_USB_PORT_STATUS *PortStatus - ); - -/** - Sets a feature for the specified root hub port. - - @param This A pointer to the EFI_USB_HC_PROTOCOL instance. - @param PortNumber Specifies the root hub port from which the status is to be retrieved. - This value is zero based. For example, if a root hub has two ports, - then the first port is numbered 0, and the second port is - numbered 1. - @param PortFeature Indicates the feature selector associated with the feature set - request. - - @retval EFI_SUCCESS The feature specified by PortFeature was set for the USB - root hub port specified by PortNumber. - @retval EFI_INVALID_PARAMETER PortNumber is invalid or PortFeature is invalid for this function. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB_HC_PROTOCOL_SET_ROOTHUB_PORT_FEATURE)( - IN EFI_USB_HC_PROTOCOL *This, - IN UINT8 PortNumber, - IN EFI_USB_PORT_FEATURE PortFeature - ); - -/** - Clears a feature for the specified root hub port. - - @param This A pointer to the EFI_USB_HC_PROTOCOL instance. - @param PortNumber Specifies the root hub port from which the status is to be retrieved. - This value is zero based. For example, if a root hub has two ports, - then the first port is numbered 0, and the second port is - numbered 1. - @param PortFeature Indicates the feature selector associated with the feature clear - request. - - @retval EFI_SUCCESS The feature specified by PortFeature was cleared for the USB - root hub port specified by PortNumber. - @retval EFI_INVALID_PARAMETER PortNumber is invalid or PortFeature is invalid for this function. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB_HC_PROTOCOL_CLEAR_ROOTHUB_PORT_FEATURE)( - IN EFI_USB_HC_PROTOCOL *This, - IN UINT8 PortNumber, - IN EFI_USB_PORT_FEATURE PortFeature - ); - - -/// -/// The EFI_USB_HC_PROTOCOL provides USB host controller management, basic data transactions -/// over a USB bus, and USB root hub access. A device driver that wishes to manage a USB bus in a -/// system retrieves the EFI_USB_HC_PROTOCOL instance that is associated with the USB bus to be -/// managed. A device handle for a USB host controller will minimally contain an -/// EFI_DEVICE_PATH_PROTOCOL instance, and an EFI_USB_HC_PROTOCOL instance. -/// -struct _EFI_USB_HC_PROTOCOL { - EFI_USB_HC_PROTOCOL_RESET Reset; - EFI_USB_HC_PROTOCOL_GET_STATE GetState; - EFI_USB_HC_PROTOCOL_SET_STATE SetState; - EFI_USB_HC_PROTOCOL_CONTROL_TRANSFER ControlTransfer; - EFI_USB_HC_PROTOCOL_BULK_TRANSFER BulkTransfer; - EFI_USB_HC_PROTOCOL_ASYNC_INTERRUPT_TRANSFER AsyncInterruptTransfer; - EFI_USB_HC_PROTOCOL_SYNC_INTERRUPT_TRANSFER SyncInterruptTransfer; - EFI_USB_HC_PROTOCOL_ISOCHRONOUS_TRANSFER IsochronousTransfer; - EFI_USB_HC_PROTOCOL_ASYNC_ISOCHRONOUS_TRANSFER AsyncIsochronousTransfer; - EFI_USB_HC_PROTOCOL_GET_ROOTHUB_PORT_NUMBER GetRootHubPortNumber; - EFI_USB_HC_PROTOCOL_GET_ROOTHUB_PORT_STATUS GetRootHubPortStatus; - EFI_USB_HC_PROTOCOL_SET_ROOTHUB_PORT_FEATURE SetRootHubPortFeature; - EFI_USB_HC_PROTOCOL_CLEAR_ROOTHUB_PORT_FEATURE ClearRootHubPortFeature; - /// - /// The major revision number of the USB host controller. The revision information - /// indicates the release of the Universal Serial Bus Specification with which the - /// host controller is compliant. - /// - UINT16 MajorRevision; - /// - /// The minor revision number of the USB host controller. The revision information - /// indicates the release of the Universal Serial Bus Specification with which the - /// host controller is compliant. - /// - UINT16 MinorRevision; -}; - -extern EFI_GUID gEfiUsbHcProtocolGuid; - -#endif diff --git a/roms/ipxe/src/include/ipxe/efi/Protocol/UsbIo.h b/roms/ipxe/src/include/ipxe/efi/Protocol/UsbIo.h deleted file mode 100644 index b8d33ee0c..000000000 --- a/roms/ipxe/src/include/ipxe/efi/Protocol/UsbIo.h +++ /dev/null @@ -1,514 +0,0 @@ -/** @file - EFI Usb I/O Protocol as defined in UEFI specification. - This protocol is used by code, typically drivers, running in the EFI - boot services environment to access USB devices like USB keyboards, - mice and mass storage devices. In particular, functions for managing devices - on USB buses are defined here. - - Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR> - This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#ifndef __USB_IO_H__ -#define __USB_IO_H__ - -FILE_LICENCE ( BSD3 ); - -#include <ipxe/efi/IndustryStandard/Usb.h> - -// -// Global ID for the USB I/O Protocol -// -#define EFI_USB_IO_PROTOCOL_GUID \ - { \ - 0x2B2F68D6, 0x0CD2, 0x44cf, {0x8E, 0x8B, 0xBB, 0xA2, 0x0B, 0x1B, 0x5B, 0x75 } \ - } - -typedef struct _EFI_USB_IO_PROTOCOL EFI_USB_IO_PROTOCOL; - -// -// Related Definition for EFI USB I/O protocol -// - -// -// USB standard descriptors and reqeust -// -typedef USB_DEVICE_REQUEST EFI_USB_DEVICE_REQUEST; -typedef USB_DEVICE_DESCRIPTOR EFI_USB_DEVICE_DESCRIPTOR; -typedef USB_CONFIG_DESCRIPTOR EFI_USB_CONFIG_DESCRIPTOR; -typedef USB_INTERFACE_DESCRIPTOR EFI_USB_INTERFACE_DESCRIPTOR; -typedef USB_ENDPOINT_DESCRIPTOR EFI_USB_ENDPOINT_DESCRIPTOR; - -/// -/// USB data transfer direction -/// -typedef enum { - EfiUsbDataIn, - EfiUsbDataOut, - EfiUsbNoData -} EFI_USB_DATA_DIRECTION; - -// -// USB Transfer Results -// -#define EFI_USB_NOERROR 0x00 -#define EFI_USB_ERR_NOTEXECUTE 0x01 -#define EFI_USB_ERR_STALL 0x02 -#define EFI_USB_ERR_BUFFER 0x04 -#define EFI_USB_ERR_BABBLE 0x08 -#define EFI_USB_ERR_NAK 0x10 -#define EFI_USB_ERR_CRC 0x20 -#define EFI_USB_ERR_TIMEOUT 0x40 -#define EFI_USB_ERR_BITSTUFF 0x80 -#define EFI_USB_ERR_SYSTEM 0x100 - -/** - Async USB transfer callback routine. - - @param Data Data received or sent via the USB Asynchronous Transfer, if the - transfer completed successfully. - @param DataLength The length of Data received or sent via the Asynchronous - Transfer, if transfer successfully completes. - @param Context Data passed from UsbAsyncInterruptTransfer() request. - @param Status Indicates the result of the asynchronous transfer. - - @retval EFI_SUCCESS The asynchronous USB transfer request has been successfully executed. - @retval EFI_DEVICE_ERROR The asynchronous USB transfer request failed. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_ASYNC_USB_TRANSFER_CALLBACK)( - IN VOID *Data, - IN UINTN DataLength, - IN VOID *Context, - IN UINT32 Status - ); - -// -// Prototype for EFI USB I/O protocol -// - - -/** - This function is used to manage a USB device with a control transfer pipe. A control transfer is - typically used to perform device initialization and configuration. - - @param This A pointer to the EFI_USB_IO_PROTOCOL instance. - @param Request A pointer to the USB device request that will be sent to the USB - device. - @param Direction Indicates the data direction. - @param Timeout Indicating the transfer should be completed within this time frame. - The units are in milliseconds. - @param Data A pointer to the buffer of data that will be transmitted to USB - device or received from USB device. - @param DataLength The size, in bytes, of the data buffer specified by Data. - @param Status A pointer to the result of the USB transfer. - - @retval EFI_SUCCESS The control transfer has been successfully executed. - @retval EFI_DEVICE_ERROR The transfer failed. The transfer status is returned in Status. - @retval EFI_INVALID_PARAMETE One or more parameters are invalid. - @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources. - @retval EFI_TIMEOUT The control transfer fails due to timeout. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB_IO_CONTROL_TRANSFER)( - IN EFI_USB_IO_PROTOCOL *This, - IN EFI_USB_DEVICE_REQUEST *Request, - IN EFI_USB_DATA_DIRECTION Direction, - IN UINT32 Timeout, - IN OUT VOID *Data OPTIONAL, - IN UINTN DataLength OPTIONAL, - OUT UINT32 *Status - ); - -/** - This function is used to manage a USB device with the bulk transfer pipe. Bulk Transfers are - typically used to transfer large amounts of data to/from USB devices. - - @param This A pointer to the EFI_USB_IO_PROTOCOL instance. - @param DeviceEndpoint The destination USB device endpoint to which the - device request is being sent. DeviceEndpoint must - be between 0x01 and 0x0F or between 0x81 and 0x8F, - otherwise EFI_INVALID_PARAMETER is returned. If - the endpoint is not a BULK endpoint, EFI_INVALID_PARAMETER - is returned. The MSB of this parameter indicates - the endpoint direction. The number "1" stands for - an IN endpoint, and "0" stands for an OUT endpoint. - @param Data A pointer to the buffer of data that will be transmitted to USB - device or received from USB device. - @param DataLength The size, in bytes, of the data buffer specified by Data. - On input, the size, in bytes, of the data buffer specified by Data. - On output, the number of bytes that were actually transferred. - @param Timeout Indicating the transfer should be completed within this time frame. - The units are in milliseconds. If Timeout is 0, then the - caller must wait for the function to be completed until - EFI_SUCCESS or EFI_DEVICE_ERROR is returned. - @param Status This parameter indicates the USB transfer status. - - @retval EFI_SUCCESS The bulk transfer has been successfully executed. - @retval EFI_DEVICE_ERROR The transfer failed. The transfer status is returned in Status. - @retval EFI_INVALID_PARAMETE One or more parameters are invalid. - @retval EFI_OUT_OF_RESOURCES The request could not be submitted due to a lack of resources. - @retval EFI_TIMEOUT The control transfer fails due to timeout. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB_IO_BULK_TRANSFER)( - IN EFI_USB_IO_PROTOCOL *This, - IN UINT8 DeviceEndpoint, - IN OUT VOID *Data, - IN OUT UINTN *DataLength, - IN UINTN Timeout, - OUT UINT32 *Status - ); - -/** - This function is used to manage a USB device with an interrupt transfer pipe. An Asynchronous - Interrupt Transfer is typically used to query a device's status at a fixed rate. For example, - keyboard, mouse, and hub devices use this type of transfer to query their interrupt endpoints at - a fixed rate. - - @param This A pointer to the EFI_USB_IO_PROTOCOL instance. - @param DeviceEndpoint The destination USB device endpoint to which the - device request is being sent. DeviceEndpoint must - be between 0x01 and 0x0F or between 0x81 and 0x8F, - otherwise EFI_INVALID_PARAMETER is returned. If - the endpoint is not a BULK endpoint, EFI_INVALID_PARAMETER - is returned. The MSB of this parameter indicates - the endpoint direction. The number "1" stands for - an IN endpoint, and "0" stands for an OUT endpoint. - @param IsNewTransfer If TRUE, a new transfer will be submitted to USB controller. If - FALSE, the interrupt transfer is deleted from the device's interrupt - transfer queue. - @param PollingInterval Indicates the periodic rate, in milliseconds, that the transfer is to be - executed.This parameter is required when IsNewTransfer is TRUE. The - value must be between 1 to 255, otherwise EFI_INVALID_PARAMETER is returned. - The units are in milliseconds. - @param DataLength Specifies the length, in bytes, of the data to be received from the - USB device. This parameter is only required when IsNewTransfer is TRUE. - @param InterruptCallback The Callback function. This function is called if the asynchronous - interrupt transfer is completed. This parameter is required - when IsNewTransfer is TRUE. - @param Context Data passed to the InterruptCallback function. This is an optional - parameter and may be NULL. - - @retval EFI_SUCCESS The asynchronous USB transfer request transfer has been successfully executed. - @retval EFI_DEVICE_ERROR The asynchronous USB transfer request failed. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB_IO_ASYNC_INTERRUPT_TRANSFER)( - IN EFI_USB_IO_PROTOCOL *This, - IN UINT8 DeviceEndpoint, - IN BOOLEAN IsNewTransfer, - IN UINTN PollingInterval OPTIONAL, - IN UINTN DataLength OPTIONAL, - IN EFI_ASYNC_USB_TRANSFER_CALLBACK InterruptCallBack OPTIONAL, - IN VOID *Context OPTIONAL - ); - -/** - This function is used to manage a USB device with an interrupt transfer pipe. - - @param This A pointer to the EFI_USB_IO_PROTOCOL instance. - @param DeviceEndpoint The destination USB device endpoint to which the - device request is being sent. DeviceEndpoint must - be between 0x01 and 0x0F or between 0x81 and 0x8F, - otherwise EFI_INVALID_PARAMETER is returned. If - the endpoint is not a BULK endpoint, EFI_INVALID_PARAMETER - is returned. The MSB of this parameter indicates - the endpoint direction. The number "1" stands for - an IN endpoint, and "0" stands for an OUT endpoint. - @param Data A pointer to the buffer of data that will be transmitted to USB - device or received from USB device. - @param DataLength On input, then size, in bytes, of the buffer Data. On output, the - amount of data actually transferred. - @param Timeout The time out, in seconds, for this transfer. If Timeout is 0, - then the caller must wait for the function to be completed - until EFI_SUCCESS or EFI_DEVICE_ERROR is returned. If the - transfer is not completed in this time frame, then EFI_TIMEOUT is returned. - @param Status This parameter indicates the USB transfer status. - - @retval EFI_SUCCESS The sync interrupt transfer has been successfully executed. - @retval EFI_INVALID_PARAMETER One or more parameters are invalid. - @retval EFI_DEVICE_ERROR The sync interrupt transfer request failed. - @retval EFI_OUT_OF_RESOURCES The request could not be submitted due to a lack of resources. - @retval EFI_TIMEOUT The transfer fails due to timeout. -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB_IO_SYNC_INTERRUPT_TRANSFER)( - IN EFI_USB_IO_PROTOCOL *This, - IN UINT8 DeviceEndpoint, - IN OUT VOID *Data, - IN OUT UINTN *DataLength, - IN UINTN Timeout, - OUT UINT32 *Status - ); - -/** - This function is used to manage a USB device with an isochronous transfer pipe. An Isochronous - transfer is typically used to transfer streaming data. - - @param This A pointer to the EFI_USB_IO_PROTOCOL instance. - @param DeviceEndpoint The destination USB device endpoint to which the - device request is being sent. DeviceEndpoint must - be between 0x01 and 0x0F or between 0x81 and 0x8F, - otherwise EFI_INVALID_PARAMETER is returned. If - the endpoint is not a BULK endpoint, EFI_INVALID_PARAMETER - is returned. The MSB of this parameter indicates - the endpoint direction. The number "1" stands for - an IN endpoint, and "0" stands for an OUT endpoint. - @param Data A pointer to the buffer of data that will be transmitted to USB - device or received from USB device. - @param DataLength The size, in bytes, of the data buffer specified by Data. - @param Status This parameter indicates the USB transfer status. - - @retval EFI_SUCCESS The isochronous transfer has been successfully executed. - @retval EFI_INVALID_PARAMETER The parameter DeviceEndpoint is not valid. - @retval EFI_DEVICE_ERROR The transfer failed due to the reason other than timeout, The error status - is returned in Status. - @retval EFI_OUT_OF_RESOURCES The request could not be submitted due to a lack of resources. - @retval EFI_TIMEOUT The transfer fails due to timeout. -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB_IO_ISOCHRONOUS_TRANSFER)( - IN EFI_USB_IO_PROTOCOL *This, - IN UINT8 DeviceEndpoint, - IN OUT VOID *Data, - IN UINTN DataLength, - OUT UINT32 *Status - ); - -/** - This function is used to manage a USB device with an isochronous transfer pipe. An Isochronous - transfer is typically used to transfer streaming data. - - @param This A pointer to the EFI_USB_IO_PROTOCOL instance. - @param DeviceEndpoint The destination USB device endpoint to which the - device request is being sent. DeviceEndpoint must - be between 0x01 and 0x0F or between 0x81 and 0x8F, - otherwise EFI_INVALID_PARAMETER is returned. If - the endpoint is not a BULK endpoint, EFI_INVALID_PARAMETER - is returned. The MSB of this parameter indicates - the endpoint direction. The number "1" stands for - an IN endpoint, and "0" stands for an OUT endpoint. - @param Data A pointer to the buffer of data that will be transmitted to USB - device or received from USB device. - @param DataLength The size, in bytes, of the data buffer specified by Data. - This is an optional parameter and may be NULL. - @param IsochronousCallback The IsochronousCallback() function.This function is - called if the requested isochronous transfer is completed. - @param Context Data passed to the IsochronousCallback() function. - - @retval EFI_SUCCESS The asynchronous isochronous transfer has been successfully submitted - to the system. - @retval EFI_INVALID_PARAMETER The parameter DeviceEndpoint is not valid. - @retval EFI_OUT_OF_RESOURCES The request could not be submitted due to a lack of resources. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB_IO_ASYNC_ISOCHRONOUS_TRANSFER)( - IN EFI_USB_IO_PROTOCOL *This, - IN UINT8 DeviceEndpoint, - IN OUT VOID *Data, - IN UINTN DataLength, - IN EFI_ASYNC_USB_TRANSFER_CALLBACK IsochronousCallBack, - IN VOID *Context OPTIONAL - ); - -/** - Resets and reconfigures the USB controller. This function will work for all USB devices except - USB Hub Controllers. - - @param This A pointer to the EFI_USB_IO_PROTOCOL instance. - - @retval EFI_SUCCESS The USB controller was reset. - @retval EFI_INVALID_PARAMETER If the controller specified by This is a USB hub. - @retval EFI_DEVICE_ERROR An error occurred during the reconfiguration process. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB_IO_PORT_RESET)( - IN EFI_USB_IO_PROTOCOL *This - ); - -/** - Retrieves the USB Device Descriptor. - - @param This A pointer to the EFI_USB_IO_PROTOCOL instance. - @param DeviceDescriptor A pointer to the caller allocated USB Device Descriptor. - - @retval EFI_SUCCESS The device descriptor was retrieved successfully. - @retval EFI_INVALID_PARAMETER DeviceDescriptor is NULL. - @retval EFI_NOT_FOUND The device descriptor was not found. The device may not be configured. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB_IO_GET_DEVICE_DESCRIPTOR)( - IN EFI_USB_IO_PROTOCOL *This, - OUT EFI_USB_DEVICE_DESCRIPTOR *DeviceDescriptor - ); - -/** - Retrieves the USB Device Descriptor. - - @param This A pointer to the EFI_USB_IO_PROTOCOL instance. - @param ConfigurationDescriptor A pointer to the caller allocated USB Active Configuration - Descriptor. - @retval EFI_SUCCESS The active configuration descriptor was retrieved successfully. - @retval EFI_INVALID_PARAMETER ConfigurationDescriptor is NULL. - @retval EFI_NOT_FOUND An active configuration descriptor cannot be found. The device may not - be configured. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB_IO_GET_CONFIG_DESCRIPTOR)( - IN EFI_USB_IO_PROTOCOL *This, - OUT EFI_USB_CONFIG_DESCRIPTOR *ConfigurationDescriptor - ); - -/** - Retrieves the Interface Descriptor for a USB Device Controller. As stated earlier, an interface - within a USB device is equivalently to a USB Controller within the current configuration. - - @param This A pointer to the EFI_USB_IO_PROTOCOL instance. - @param InterfaceDescriptor A pointer to the caller allocated USB Interface Descriptor within - the configuration setting. - @retval EFI_SUCCESS The interface descriptor retrieved successfully. - @retval EFI_INVALID_PARAMETER InterfaceDescriptor is NULL. - @retval EFI_NOT_FOUND The interface descriptor cannot be found. The device may not be - correctly configured. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB_IO_GET_INTERFACE_DESCRIPTOR)( - IN EFI_USB_IO_PROTOCOL *This, - OUT EFI_USB_INTERFACE_DESCRIPTOR *InterfaceDescriptor - ); - -/** - Retrieves an Endpoint Descriptor within a USB Controller. - - @param This A pointer to the EFI_USB_IO_PROTOCOL instance. - @param EndpointIndex Indicates which endpoint descriptor to retrieve. - @param EndpointDescriptor A pointer to the caller allocated USB Endpoint Descriptor of - a USB controller. - - @retval EFI_SUCCESS The endpoint descriptor was retrieved successfully. - @retval EFI_INVALID_PARAMETER One or more parameters are invalid. - @retval EFI_NOT_FOUND The endpoint descriptor cannot be found. The device may not be - correctly configured. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB_IO_GET_ENDPOINT_DESCRIPTOR)( - IN EFI_USB_IO_PROTOCOL *This, - IN UINT8 EndpointIndex, - OUT EFI_USB_ENDPOINT_DESCRIPTOR *EndpointDescriptor - ); - -/** - Retrieves a string stored in a USB Device. - - @param This A pointer to the EFI_USB_IO_PROTOCOL instance. - @param LangID The Language ID for the string being retrieved. - @param StringID The ID of the string being retrieved. - @param String A pointer to a buffer allocated by this function with - AllocatePool() to store the string.If this function - returns EFI_SUCCESS, it stores the string the caller - wants to get. The caller should release the string - buffer with FreePool() after the string is not used any more. - - @retval EFI_SUCCESS The string was retrieved successfully. - @retval EFI_NOT_FOUND The string specified by LangID and StringID was not found. - @retval EFI_OUT_OF_RESOURCES There are not enough resources to allocate the return buffer String. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB_IO_GET_STRING_DESCRIPTOR)( - IN EFI_USB_IO_PROTOCOL *This, - IN UINT16 LangID, - IN UINT8 StringID, - OUT CHAR16 **String - ); - -/** - Retrieves all the language ID codes that the USB device supports. - - @param This A pointer to the EFI_USB_IO_PROTOCOL instance. - @param LangIDTable Language ID for the string the caller wants to get. - This is a 16-bit ID defined by Microsoft. This - buffer pointer is allocated and maintained by - the USB Bus Driver, the caller should not modify - its contents. - @param TableSize The size, in bytes, of the table LangIDTable. - - @retval EFI_SUCCESS The support languages were retrieved successfully. - -**/ -typedef -EFI_STATUS -(EFIAPI *EFI_USB_IO_GET_SUPPORTED_LANGUAGE)( - IN EFI_USB_IO_PROTOCOL *This, - OUT UINT16 **LangIDTable, - OUT UINT16 *TableSize - ); - -/// -/// The EFI_USB_IO_PROTOCOL provides four basic transfers types described -/// in the USB 1.1 Specification. These include control transfer, interrupt -/// transfer, bulk transfer and isochronous transfer. The EFI_USB_IO_PROTOCOL -/// also provides some basic USB device/controller management and configuration -/// interfaces. A USB device driver uses the services of this protocol to manage USB devices. -/// -struct _EFI_USB_IO_PROTOCOL { - // - // IO transfer - // - EFI_USB_IO_CONTROL_TRANSFER UsbControlTransfer; - EFI_USB_IO_BULK_TRANSFER UsbBulkTransfer; - EFI_USB_IO_ASYNC_INTERRUPT_TRANSFER UsbAsyncInterruptTransfer; - EFI_USB_IO_SYNC_INTERRUPT_TRANSFER UsbSyncInterruptTransfer; - EFI_USB_IO_ISOCHRONOUS_TRANSFER UsbIsochronousTransfer; - EFI_USB_IO_ASYNC_ISOCHRONOUS_TRANSFER UsbAsyncIsochronousTransfer; - - // - // Common device request - // - EFI_USB_IO_GET_DEVICE_DESCRIPTOR UsbGetDeviceDescriptor; - EFI_USB_IO_GET_CONFIG_DESCRIPTOR UsbGetConfigDescriptor; - EFI_USB_IO_GET_INTERFACE_DESCRIPTOR UsbGetInterfaceDescriptor; - EFI_USB_IO_GET_ENDPOINT_DESCRIPTOR UsbGetEndpointDescriptor; - EFI_USB_IO_GET_STRING_DESCRIPTOR UsbGetStringDescriptor; - EFI_USB_IO_GET_SUPPORTED_LANGUAGE UsbGetSupportedLanguages; - - // - // Reset controller's parent port - // - EFI_USB_IO_PORT_RESET UsbPortReset; -}; - -extern EFI_GUID gEfiUsbIoProtocolGuid; - -#endif diff --git a/roms/ipxe/src/include/ipxe/efi/Uefi/UefiBaseType.h b/roms/ipxe/src/include/ipxe/efi/Uefi/UefiBaseType.h index ef0ea671a..371dae649 100644 --- a/roms/ipxe/src/include/ipxe/efi/Uefi/UefiBaseType.h +++ b/roms/ipxe/src/include/ipxe/efi/Uefi/UefiBaseType.h @@ -1,8 +1,8 @@ /** @file Defines data types and constants introduced in UEFI. -Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR> -Portions copyright (c) 2011 - 2016, ARM Ltd. All rights reserved.<BR> +Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR> +Portions copyright (c) 2011 - 2013, ARM Ltd. All rights reserved.<BR> This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License that accompanies this distribution. @@ -153,14 +153,12 @@ typedef union { #define EFI_END_OF_FILE RETURN_END_OF_FILE #define EFI_INVALID_LANGUAGE RETURN_INVALID_LANGUAGE #define EFI_COMPROMISED_DATA RETURN_COMPROMISED_DATA -#define EFI_HTTP_ERROR RETURN_HTTP_ERROR #define EFI_WARN_UNKNOWN_GLYPH RETURN_WARN_UNKNOWN_GLYPH #define EFI_WARN_DELETE_FAILURE RETURN_WARN_DELETE_FAILURE #define EFI_WARN_WRITE_FAILURE RETURN_WARN_WRITE_FAILURE #define EFI_WARN_BUFFER_TOO_SMALL RETURN_WARN_BUFFER_TOO_SMALL #define EFI_WARN_STALE_DATA RETURN_WARN_STALE_DATA -#define EFI_WARN_FILE_SYSTEM RETURN_WARN_FILE_SYSTEM ///@} /// diff --git a/roms/ipxe/src/include/ipxe/efi/Uefi/UefiInternalFormRepresentation.h b/roms/ipxe/src/include/ipxe/efi/Uefi/UefiInternalFormRepresentation.h index 49ea24ff9..19121dea7 100644 --- a/roms/ipxe/src/include/ipxe/efi/Uefi/UefiInternalFormRepresentation.h +++ b/roms/ipxe/src/include/ipxe/efi/Uefi/UefiInternalFormRepresentation.h @@ -3,7 +3,7 @@ IFR is primarily consumed by the EFI presentation engine, and produced by EFI internal application and drivers as well as all add-in card option-ROM drivers -Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR> This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License that accompanies this distribution. The full text of the license may be found at @@ -782,7 +782,6 @@ typedef union { #define EFI_IFR_MODAL_TAG_OP 0x61 #define EFI_IFR_REFRESH_ID_OP 0x62 #define EFI_IFR_WARNING_IF_OP 0x63 -#define EFI_IFR_MATCH2_OP 0x64 // // Definitions of IFR Standard Headers @@ -814,11 +813,10 @@ typedef struct _EFI_IFR_QUESTION_HEADER { // // Flag values of EFI_IFR_QUESTION_HEADER // -#define EFI_IFR_FLAG_READ_ONLY 0x01 -#define EFI_IFR_FLAG_CALLBACK 0x04 -#define EFI_IFR_FLAG_RESET_REQUIRED 0x10 -#define EFI_IFR_FLAG_RECONNECT_REQUIRED 0x40 -#define EFI_IFR_FLAG_OPTIONS_ONLY 0x80 +#define EFI_IFR_FLAG_READ_ONLY 0x01 +#define EFI_IFR_FLAG_CALLBACK 0x04 +#define EFI_IFR_FLAG_RESET_REQUIRED 0x10 +#define EFI_IFR_FLAG_OPTIONS_ONLY 0x80 // // Definition for Opcode Reference @@ -1403,11 +1401,6 @@ typedef struct _EFI_IFR_MATCH { EFI_IFR_OP_HEADER Header; } EFI_IFR_MATCH; -typedef struct _EFI_IFR_MATCH2 { - EFI_IFR_OP_HEADER Header; - EFI_GUID SyntaxType; -} EFI_IFR_MATCH2; - typedef struct _EFI_IFR_MULTIPLY { EFI_IFR_OP_HEADER Header; } EFI_IFR_MULTIPLY; diff --git a/roms/ipxe/src/include/ipxe/efi/Uefi/UefiMultiPhase.h b/roms/ipxe/src/include/ipxe/efi/Uefi/UefiMultiPhase.h index 38ec09f3d..678f3ebd6 100644 --- a/roms/ipxe/src/include/ipxe/efi/Uefi/UefiMultiPhase.h +++ b/roms/ipxe/src/include/ipxe/efi/Uefi/UefiMultiPhase.h @@ -1,7 +1,7 @@ /** @file This includes some definitions introduced in UEFI that will be used in both PEI and DXE phases. -Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR> This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License that accompanies this distribution. The full text of the license may be found at @@ -84,48 +84,10 @@ typedef enum { /// Address space reserved by the firmware for code that is part of the processor. /// EfiPalCode, - /// - /// A memory region that operates as EfiConventionalMemory, - /// however it happens to also support byte-addressable non-volatility. - /// - EfiPersistentMemory, EfiMaxMemoryType } EFI_MEMORY_TYPE; /// -/// Enumeration of reset types. -/// -typedef enum { - /// - /// Used to induce a system-wide reset. This sets all circuitry within the - /// system to its initial state. This type of reset is asynchronous to system - /// operation and operates withgout regard to cycle boundaries. EfiColdReset - /// is tantamount to a system power cycle. - /// - EfiResetCold, - /// - /// Used to induce a system-wide initialization. The processors are set to their - /// initial state, and pending cycles are not corrupted. If the system does - /// not support this reset type, then an EfiResetCold must be performed. - /// - EfiResetWarm, - /// - /// Used to induce an entry into a power state equivalent to the ACPI G2/S5 or G3 - /// state. If the system does not support this reset type, then when the system - /// is rebooted, it should exhibit the EfiResetCold attributes. - /// - EfiResetShutdown, - /// - /// Used to induce a system-wide reset. The exact type of the reset is defined by - /// the EFI_GUID that follows the Null-terminated Unicode string passed into - /// ResetData. If the platform does not recognize the EFI_GUID in ResetData the - /// platform must pick a supported reset type to perform. The platform may - /// optionally log the parameters from any non-normal reset that occurs. - /// - EfiResetPlatformSpecific -} EFI_RESET_TYPE; - -/// /// Data structure that precedes all of the standard EFI table types. /// typedef struct { diff --git a/roms/ipxe/src/include/ipxe/efi/Uefi/UefiPxe.h b/roms/ipxe/src/include/ipxe/efi/Uefi/UefiPxe.h index 13be21aae..5c0b2038f 100644 --- a/roms/ipxe/src/include/ipxe/efi/Uefi/UefiPxe.h +++ b/roms/ipxe/src/include/ipxe/efi/Uefi/UefiPxe.h @@ -3,7 +3,7 @@ structure prototypes, global variables and constants that are needed for porting PXE to EFI. -Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR> This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License that accompanies this distribution. The full text of the license may be found at @@ -1460,26 +1460,6 @@ typedef struct s_pxe_db_statistics { /// #define PXE_STATISTICS_UNSUPPORTED_PROTOCOL 0x15 -/// -/// Number of valid frames received that were duplicated. -/// -#define PXE_STATISTICS_RX_DUPLICATED_FRAMES 0x16 - -/// -/// Number of encrypted frames received that failed to decrypt. -/// -#define PXE_STATISTICS_RX_DECRYPT_ERROR_FRAMES 0x17 - -/// -/// Number of frames that failed to transmit after exceeding the retry limit. -/// -#define PXE_STATISTICS_TX_ERROR_FRAMES 0x18 - -/// -/// Number of frames transmitted successfully after more than one attempt. -/// -#define PXE_STATISTICS_TX_RETRY_FRAMES 0x19 - typedef struct s_pxe_cpb_mcast_ip_to_mac { /// /// Multicast IP address to be converted to multicast MAC address. diff --git a/roms/ipxe/src/include/ipxe/efi/Uefi/UefiSpec.h b/roms/ipxe/src/include/ipxe/efi/Uefi/UefiSpec.h index 98ac8765f..422b2f30e 100644 --- a/roms/ipxe/src/include/ipxe/efi/Uefi/UefiSpec.h +++ b/roms/ipxe/src/include/ipxe/efi/Uefi/UefiSpec.h @@ -1,11 +1,11 @@ /** @file Include file that supports UEFI. - This include file must contain things defined in the UEFI 2.6 specification. - If a code construct is defined in the UEFI 2.6 specification it must be included + This include file must contain things defined in the UEFI 2.4 specification. + If a code construct is defined in the UEFI 2.4 specification it must be included by this include file. -Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR> This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License that accompanies this distribution. The full text of the license may be found at @@ -65,35 +65,21 @@ typedef enum { // // Memory cacheability attributes // -#define EFI_MEMORY_UC 0x0000000000000001ULL -#define EFI_MEMORY_WC 0x0000000000000002ULL -#define EFI_MEMORY_WT 0x0000000000000004ULL -#define EFI_MEMORY_WB 0x0000000000000008ULL -#define EFI_MEMORY_UCE 0x0000000000000010ULL +#define EFI_MEMORY_UC 0x0000000000000001ULL +#define EFI_MEMORY_WC 0x0000000000000002ULL +#define EFI_MEMORY_WT 0x0000000000000004ULL +#define EFI_MEMORY_WB 0x0000000000000008ULL +#define EFI_MEMORY_UCE 0x0000000000000010ULL // // Physical memory protection attributes // -// Note: UEFI spec 2.5 and following: use EFI_MEMORY_RO as write-protected physical memory -// protection attribute. Also, EFI_MEMORY_WP means cacheability attribute. -// -#define EFI_MEMORY_WP 0x0000000000001000ULL -#define EFI_MEMORY_RP 0x0000000000002000ULL -#define EFI_MEMORY_XP 0x0000000000004000ULL -#define EFI_MEMORY_RO 0x0000000000020000ULL -// -// Physical memory persistence attribute. -// The memory region supports byte-addressable non-volatility. -// -#define EFI_MEMORY_NV 0x0000000000008000ULL -// -// The memory region provides higher reliability relative to other memory in the system. -// If all memory has the same reliability, then this bit is not used. -// -#define EFI_MEMORY_MORE_RELIABLE 0x0000000000010000ULL +#define EFI_MEMORY_WP 0x0000000000001000ULL +#define EFI_MEMORY_RP 0x0000000000002000ULL +#define EFI_MEMORY_XP 0x0000000000004000ULL // // Runtime memory attribute // -#define EFI_MEMORY_RUNTIME 0x8000000000000000ULL +#define EFI_MEMORY_RUNTIME 0x8000000000000000ULL /// /// Memory descriptor version number. @@ -133,23 +119,18 @@ typedef struct { /** Allocates memory pages from the system. - @param[in] Type The type of allocation to perform. - @param[in] MemoryType The type of memory to allocate. - MemoryType values in the range 0x70000000..0x7FFFFFFF - are reserved for OEM use. MemoryType values in the range - 0x80000000..0xFFFFFFFF are reserved for use by UEFI OS loaders - that are provided by operating system vendors. - @param[in] Pages The number of contiguous 4 KB pages to allocate. - @param[in, out] Memory The pointer to a physical address. On input, the way in which the address is - used depends on the value of Type. + @param Type The type of allocation to perform. + @param MemoryType The type of memory to allocate. + @param Pages The number of contiguous 4 KB pages to allocate. + @param Memory The pointer to a physical address. On input, the way in which the address is + used depends on the value of Type. @retval EFI_SUCCESS The requested pages were allocated. @retval EFI_INVALID_PARAMETER 1) Type is not AllocateAnyPages or AllocateMaxAddress or AllocateAddress. 2) MemoryType is in the range - EfiMaxMemoryType..0x6FFFFFFF. 3) Memory is NULL. - 4) MemoryType is EfiPersistentMemory. + EfiMaxMemoryType..0x7FFFFFFF. @retval EFI_OUT_OF_RESOURCES The pages could not be allocated. @retval EFI_NOT_FOUND The requested pages could not be found. @@ -166,8 +147,8 @@ EFI_STATUS /** Frees memory pages. - @param[in] Memory The base physical address of the pages to be freed. - @param[in] Pages The number of contiguous 4 KB pages to free. + @param Memory The base physical address of the pages to be freed. + @param Pages The number of contiguous 4 KB pages to free. @retval EFI_SUCCESS The requested pages were freed. @retval EFI_INVALID_PARAMETER Memory is not a page-aligned address or Pages is invalid. @@ -185,19 +166,19 @@ EFI_STATUS /** Returns the current memory map. - @param[in, out] MemoryMapSize A pointer to the size, in bytes, of the MemoryMap buffer. - On input, this is the size of the buffer allocated by the caller. - On output, it is the size of the buffer returned by the firmware if - the buffer was large enough, or the size of the buffer needed to contain - the map if the buffer was too small. - @param[in, out] MemoryMap A pointer to the buffer in which firmware places the current memory - map. - @param[out] MapKey A pointer to the location in which firmware returns the key for the - current memory map. - @param[out] DescriptorSize A pointer to the location in which firmware returns the size, in bytes, of - an individual EFI_MEMORY_DESCRIPTOR. - @param[out] DescriptorVersion A pointer to the location in which firmware returns the version number - associated with the EFI_MEMORY_DESCRIPTOR. + @param MemoryMapSize A pointer to the size, in bytes, of the MemoryMap buffer. + On input, this is the size of the buffer allocated by the caller. + On output, it is the size of the buffer returned by the firmware if + the buffer was large enough, or the size of the buffer needed to contain + the map if the buffer was too small. + @param MemoryMap A pointer to the buffer in which firmware places the current memory + map. + @param MapKey A pointer to the location in which firmware returns the key for the + current memory map. + @param DescriptorSize A pointer to the location in which firmware returns the size, in bytes, of + an individual EFI_MEMORY_DESCRIPTOR. + @param DescriptorVersion A pointer to the location in which firmware returns the version number + associated with the EFI_MEMORY_DESCRIPTOR. @retval EFI_SUCCESS The memory map was returned in the MemoryMap buffer. @retval EFI_BUFFER_TOO_SMALL The MemoryMap buffer was too small. The current buffer size @@ -220,20 +201,14 @@ EFI_STATUS /** Allocates pool memory. - @param[in] PoolType The type of pool to allocate. - MemoryType values in the range 0x70000000..0x7FFFFFFF - are reserved for OEM use. MemoryType values in the range - 0x80000000..0xFFFFFFFF are reserved for use by UEFI OS loaders - that are provided by operating system vendors. - @param[in] Size The number of bytes to allocate from the pool. - @param[out] Buffer A pointer to a pointer to the allocated buffer if the call succeeds; + @param PoolType The type of pool to allocate. + @param Size The number of bytes to allocate from the pool. + @param Buffer A pointer to a pointer to the allocated buffer if the call succeeds; undefined otherwise. @retval EFI_SUCCESS The requested number of bytes was allocated. @retval EFI_OUT_OF_RESOURCES The pool requested could not be allocated. - @retval EFI_INVALID_PARAMETER Buffer is NULL. - PoolType is in the range EfiMaxMemoryType..0x6FFFFFFF. - PoolType is EfiPersistentMemory. + @retval EFI_INVALID_PARAMETER PoolType was invalid or Buffer is NULL. **/ typedef @@ -247,7 +222,7 @@ EFI_STATUS /** Returns pool memory to the system. - @param[in] Buffer The pointer to the buffer to free. + @param Buffer The pointer to the buffer to free. @retval EFI_SUCCESS The memory was returned to the system. @retval EFI_INVALID_PARAMETER Buffer was invalid. @@ -262,10 +237,10 @@ EFI_STATUS /** Changes the runtime addressing mode of EFI firmware from physical to virtual. - @param[in] MemoryMapSize The size in bytes of VirtualMap. - @param[in] DescriptorSize The size in bytes of an entry in the VirtualMap. - @param[in] DescriptorVersion The version of the structure entries in VirtualMap. - @param[in] VirtualMap An array of memory descriptors which contain new virtual + @param MemoryMapSize The size in bytes of VirtualMap. + @param DescriptorSize The size in bytes of an entry in the VirtualMap. + @param DescriptorVersion The version of the structure entries in VirtualMap. + @param VirtualMap An array of memory descriptors which contain new virtual address mapping information for all runtime ranges. @retval EFI_SUCCESS The virtual address map has been applied. @@ -290,15 +265,15 @@ EFI_STATUS /** Connects one or more drivers to a controller. - @param[in] ControllerHandle The handle of the controller to which driver(s) are to be connected. - @param[in] DriverImageHandle A pointer to an ordered list handles that support the - EFI_DRIVER_BINDING_PROTOCOL. - @param[in] RemainingDevicePath A pointer to the device path that specifies a child of the - controller specified by ControllerHandle. - @param[in] Recursive If TRUE, then ConnectController() is called recursively - until the entire tree of controllers below the controller specified - by ControllerHandle have been created. If FALSE, then - the tree of controllers is only expanded one level. + @param ControllerHandle The handle of the controller to which driver(s) are to be connected. + @param DriverImageHandle A pointer to an ordered list handles that support the + EFI_DRIVER_BINDING_PROTOCOL. + @param RemainingDevicePath A pointer to the device path that specifies a child of the + controller specified by ControllerHandle. + @param Recursive If TRUE, then ConnectController() is called recursively + until the entire tree of controllers below the controller specified + by ControllerHandle have been created. If FALSE, then + the tree of controllers is only expanded one level. @retval EFI_SUCCESS 1) One or more drivers were connected to ControllerHandle. 2) No drivers were connected to ControllerHandle, but @@ -324,13 +299,13 @@ EFI_STATUS /** Disconnects one or more drivers from a controller. - @param[in] ControllerHandle The handle of the controller from which driver(s) are to be disconnected. - @param[in] DriverImageHandle The driver to disconnect from ControllerHandle. - If DriverImageHandle is NULL, then all the drivers currently managing - ControllerHandle are disconnected from ControllerHandle. - @param[in] ChildHandle The handle of the child to destroy. - If ChildHandle is NULL, then all the children of ControllerHandle are - destroyed before the drivers are disconnected from ControllerHandle. + @param ControllerHandle The handle of the controller from which driver(s) are to be disconnected. + @param DriverImageHandle The driver to disconnect from ControllerHandle. + If DriverImageHandle is NULL, then all the drivers currently managing + ControllerHandle are disconnected from ControllerHandle. + @param ChildHandle The handle of the child to destroy. + If ChildHandle is NULL, then all the children of ControllerHandle are + destroyed before the drivers are disconnected from ControllerHandle. @retval EFI_SUCCESS 1) One or more drivers were disconnected from the controller. 2) On entry, no drivers are managing ControllerHandle. @@ -363,9 +338,9 @@ EFI_STATUS /** Determines the new virtual address that is to be used on subsequent memory accesses. - @param[in] DebugDisposition Supplies type information for the pointer being converted. - @param[in, out] Address A pointer to a pointer that is to be fixed to be the value needed - for the new virtual address mappings being applied. + @param DebugDisposition Supplies type information for the pointer being converted. + @param Address A pointer to a pointer that is to be fixed to be the value needed + for the new virtual address mappings being applied. @retval EFI_SUCCESS The pointer pointed to by Address was modified. @retval EFI_INVALID_PARAMETER 1) Address is NULL. @@ -407,9 +382,9 @@ EFI_STATUS /** Invoke a notification event - @param[in] Event Event whose notification function is being invoked. - @param[in] Context The pointer to the notification function's context, - which is implementation-dependent. + @param Event Event whose notification function is being invoked. + @param Context The pointer to the notification function's context, + which is implementation-dependent. **/ typedef @@ -422,12 +397,12 @@ VOID /** Creates an event. - @param[in] Type The type of event to create and its mode and attributes. - @param[in] NotifyTpl The task priority level of event notifications, if needed. - @param[in] NotifyFunction The pointer to the event's notification function, if any. - @param[in] NotifyContext The pointer to the notification function's context; corresponds to parameter + @param Type The type of event to create and its mode and attributes. + @param NotifyTpl The task priority level of event notifications, if needed. + @param NotifyFunction The pointer to the event's notification function, if any. + @param NotifyContext The pointer to the notification function's context; corresponds to parameter Context in the notification function. - @param[out] Event The pointer to the newly created event if the call succeeds; undefined + @param Event The pointer to the newly created event if the call succeeds; undefined otherwise. @retval EFI_SUCCESS The event structure was created. @@ -448,15 +423,15 @@ EFI_STATUS /** Creates an event in a group. - @param[in] Type The type of event to create and its mode and attributes. - @param[in] NotifyTpl The task priority level of event notifications,if needed. - @param[in] NotifyFunction The pointer to the event's notification function, if any. - @param[in] NotifyContext The pointer to the notification function's context; corresponds to parameter + @param Type The type of event to create and its mode and attributes. + @param NotifyTpl The task priority level of event notifications,if needed. + @param NotifyFunction The pointer to the event's notification function, if any. + @param NotifyContext The pointer to the notification function's context; corresponds to parameter Context in the notification function. - @param[in] EventGroup The pointer to the unique identifier of the group to which this event belongs. + @param EventGroup The pointer to the unique identifier of the group to which this event belongs. If this is NULL, then the function behaves as if the parameters were passed to CreateEvent. - @param[out] Event The pointer to the newly created event if the call succeeds; undefined + @param Event The pointer to the newly created event if the call succeeds; undefined otherwise. @retval EFI_SUCCESS The event structure was created. @@ -496,9 +471,9 @@ typedef enum { /** Sets the type of timer and the trigger time for a timer event. - @param[in] Event The timer event that is to be signaled at the specified time. - @param[in] Type The type of time that is specified in TriggerTime. - @param[in] TriggerTime The number of 100ns units until the timer expires. + @param Event The timer event that is to be signaled at the specified time. + @param Type The type of time that is specified in TriggerTime. + @param TriggerTime The number of 100ns units until the timer expires. A TriggerTime of 0 is legal. If Type is TimerRelative and TriggerTime is 0, then the timer event will be signaled on the next timer tick. @@ -520,7 +495,7 @@ EFI_STATUS /** Signals an event. - @param[in] Event The event to signal. + @param Event The event to signal. @retval EFI_SUCCESS The event has been signaled. @@ -534,9 +509,9 @@ EFI_STATUS /** Stops execution until an event is signaled. - @param[in] NumberOfEvents The number of events in the Event array. - @param[in] Event An array of EFI_EVENT. - @param[out] Index The pointer to the index of the event which satisfied the wait condition. + @param NumberOfEvents The number of events in the Event array. + @param Event An array of EFI_EVENT. + @param Index The pointer to the index of the event which satisfied the wait condition. @retval EFI_SUCCESS The event indicated by Index was signaled. @retval EFI_INVALID_PARAMETER 1) NumberOfEvents is 0. @@ -556,7 +531,7 @@ EFI_STATUS /** Closes an event. - @param[in] Event The event to close. + @param Event The event to close. @retval EFI_SUCCESS The event has been closed. @@ -570,7 +545,7 @@ EFI_STATUS /** Checks whether an event is in the signaled state. - @param[in] Event The event to check. + @param Event The event to check. @retval EFI_SUCCESS The event is in the signaled state. @retval EFI_NOT_READY The event is not in the signaled state. @@ -596,7 +571,7 @@ EFI_STATUS /** Raises a task's priority level and returns its previous level. - @param[in] NewTpl The new task priority level. + @param NewTpl The new task priority level. @return Previous task priority level @@ -610,7 +585,7 @@ EFI_TPL /** Restores a task's priority level to its previous value. - @param[in] OldTpl The previous task priority level to restore. + @param OldTpl The previous task priority level to restore. **/ typedef @@ -622,15 +597,14 @@ VOID /** Returns the value of a variable. - @param[in] VariableName A Null-terminated string that is the name of the vendor's - variable. - @param[in] VendorGuid A unique identifier for the vendor. - @param[out] Attributes If not NULL, a pointer to the memory location to return the - attributes bitmask for the variable. - @param[in, out] DataSize On input, the size in bytes of the return Data buffer. - On output the size of data returned in Data. - @param[out] Data The buffer to return the contents of the variable. May be NULL - with a zero DataSize in order to determine the size buffer needed. + @param VariableName A Null-terminated string that is the name of the vendor's + variable. + @param VendorGuid A unique identifier for the vendor. + @param Attributes If not NULL, a pointer to the memory location to return the + attributes bitmask for the variable. + @param DataSize On input, the size in bytes of the return Data buffer. + On output the size of data returned in Data. + @param Data The buffer to return the contents of the variable. @retval EFI_SUCCESS The function completed successfully. @retval EFI_NOT_FOUND The variable was not found. @@ -650,19 +624,19 @@ EFI_STATUS IN EFI_GUID *VendorGuid, OUT UINT32 *Attributes, OPTIONAL IN OUT UINTN *DataSize, - OUT VOID *Data OPTIONAL + OUT VOID *Data ); /** Enumerates the current variable names. - @param[in, out] VariableNameSize The size of the VariableName buffer. - @param[in, out] VariableName On input, supplies the last VariableName that was returned - by GetNextVariableName(). On output, returns the Nullterminated - string of the current variable. - @param[in, out] VendorGuid On input, supplies the last VendorGuid that was returned by - GetNextVariableName(). On output, returns the - VendorGuid of the current variable. + @param VariableNameSize The size of the VariableName buffer. + @param VariableName On input, supplies the last VariableName that was returned + by GetNextVariableName(). On output, returns the Nullterminated + string of the current variable. + @param VendorGuid On input, supplies the last VendorGuid that was returned by + GetNextVariableName(). On output, returns the + VendorGuid of the current variable. @retval EFI_SUCCESS The function completed successfully. @retval EFI_NOT_FOUND The next variable was not found. @@ -684,13 +658,13 @@ EFI_STATUS /** Sets the value of a variable. - @param[in] VariableName A Null-terminated string that is the name of the vendor's variable. + @param VariableName A Null-terminated string that is the name of the vendor's variable. Each VariableName is unique for each VendorGuid. VariableName must contain 1 or more characters. If VariableName is an empty string, then EFI_INVALID_PARAMETER is returned. - @param[in] VendorGuid A unique identifier for the vendor. - @param[in] Attributes Attributes bitmask to set for the variable. - @param[in] DataSize The size in bytes of the Data buffer. Unless the EFI_VARIABLE_APPEND_WRITE, + @param VendorGuid A unique identifier for the vendor. + @param Attributes Attributes bitmask to set for the variable. + @param DataSize The size in bytes of the Data buffer. Unless the EFI_VARIABLE_APPEND_WRITE, EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero causes the variable to be deleted. When the EFI_VARIABLE_APPEND_WRITE attribute is @@ -699,7 +673,7 @@ EFI_STATUS even if no new data value is provided,see the description of the EFI_VARIABLE_AUTHENTICATION_2 descriptor below. In this case the DataSize will not be zero since the EFI_VARIABLE_AUTHENTICATION_2 descriptor will be populated). - @param[in] Data The contents for the variable. + @param Data The contents for the variable. @retval EFI_SUCCESS The firmware has successfully stored the variable and its data as defined by the Attributes. @@ -761,8 +735,8 @@ typedef struct { Returns the current time and date information, and the time-keeping capabilities of the hardware platform. - @param[out] Time A pointer to storage to receive a snapshot of the current time. - @param[out] Capabilities An optional pointer to a buffer to receive the real time clock + @param Time A pointer to storage to receive a snapshot of the current time. + @param Capabilities An optional pointer to a buffer to receive the real time clock device's capabilities. @retval EFI_SUCCESS The operation completed successfully. @@ -780,7 +754,7 @@ EFI_STATUS /** Sets the current local time and date information. - @param[in] Time A pointer to the current time. + @param Time A pointer to the current time. @retval EFI_SUCCESS The operation completed successfully. @retval EFI_INVALID_PARAMETER A time field is out of range. @@ -796,9 +770,9 @@ EFI_STATUS /** Returns the current wakeup alarm clock setting. - @param[out] Enabled Indicates if the alarm is currently enabled or disabled. - @param[out] Pending Indicates if the alarm signal is pending and requires acknowledgement. - @param[out] Time The current alarm setting. + @param Enabled Indicates if the alarm is currently enabled or disabled. + @param Pending Indicates if the alarm signal is pending and requires acknowledgement. + @param Time The current alarm setting. @retval EFI_SUCCESS The alarm settings were returned. @retval EFI_INVALID_PARAMETER Enabled is NULL. @@ -819,8 +793,8 @@ EFI_STATUS /** Sets the system wakeup alarm clock time. - @param[in] Enable Enable or disable the wakeup alarm. - @param[in] Time If Enable is TRUE, the time to set the wakeup alarm for. + @param Enabled Enable or disable the wakeup alarm. + @param Time If Enable is TRUE, the time to set the wakeup alarm for. If Enable is FALSE, then this parameter is optional, and may be NULL. @retval EFI_SUCCESS If Enable is TRUE, then the wakeup alarm was enabled. If @@ -840,32 +814,32 @@ EFI_STATUS /** Loads an EFI image into memory. - @param[in] BootPolicy If TRUE, indicates that the request originates from the boot - manager, and that the boot manager is attempting to load - FilePath as a boot selection. Ignored if SourceBuffer is - not NULL. - @param[in] ParentImageHandle The caller's image handle. - @param[in] DevicePath The DeviceHandle specific file path from which the image is - loaded. - @param[in] SourceBuffer If not NULL, a pointer to the memory location containing a copy - of the image to be loaded. - @param[in] SourceSize The size in bytes of SourceBuffer. Ignored if SourceBuffer is NULL. - @param[out] ImageHandle The pointer to the returned image handle that is created when the - image is successfully loaded. - - @retval EFI_SUCCESS Image was loaded into memory correctly. - @retval EFI_NOT_FOUND Both SourceBuffer and DevicePath are NULL. - @retval EFI_INVALID_PARAMETER One or more parametes are invalid. - @retval EFI_UNSUPPORTED The image type is not supported. - @retval EFI_OUT_OF_RESOURCES Image was not loaded due to insufficient resources. - @retval EFI_LOAD_ERROR Image was not loaded because the image format was corrupt or not - understood. - @retval EFI_DEVICE_ERROR Image was not loaded because the device returned a read error. - @retval EFI_ACCESS_DENIED Image was not loaded because the platform policy prohibits the - image from being loaded. NULL is returned in *ImageHandle. + @param BootPolicy If TRUE, indicates that the request originates from the boot + manager, and that the boot manager is attempting to load + FilePath as a boot selection. Ignored if SourceBuffer is + not NULL. + @param ParentImageHandle The caller's image handle. + @param DevicePath The DeviceHandle specific file path from which the image is + loaded. + @param SourceBuffer If not NULL, a pointer to the memory location containing a copy + of the image to be loaded. + @param SourceSize The size in bytes of SourceBuffer. Ignored if SourceBuffer is NULL. + @param ImageHandle The pointer to the returned image handle that is created when the + image is successfully loaded. + + @retval EFI_SUCCESS Image was loaded into memory correctly. + @retval EFI_NOT_FOUND Both SourceBuffer and DevicePath are NULL. + @retval EFI_INVALID_PARAMETER One or more parametes are invalid. + @retval EFI_UNSUPPORTED The image type is not supported. + @retval EFI_OUT_OF_RESOURCES Image was not loaded due to insufficient resources. + @retval EFI_LOAD_ERROR Image was not loaded because the image format was corrupt or not + understood. + @retval EFI_DEVICE_ERROR Image was not loaded because the device returned a read error. + @retval EFI_ACCESS_DENIED Image was not loaded because the platform policy prohibits the + image from being loaded. NULL is returned in *ImageHandle. @retval EFI_SECURITY_VIOLATION Image was loaded and an ImageHandle was created with a - valid EFI_LOADED_IMAGE_PROTOCOL. However, the current - platform policy specifies that the image should not be started. + valid EFI_LOADED_IMAGE_PROTOCOL. However, the current + platform policy specifies that the image should not be started. **/ typedef EFI_STATUS @@ -881,10 +855,10 @@ EFI_STATUS /** Transfers control to a loaded image's entry point. - @param[in] ImageHandle Handle of image to be started. - @param[out] ExitDataSize The pointer to the size, in bytes, of ExitData. - @param[out] ExitData The pointer to a pointer to a data buffer that includes a Null-terminated - string, optionally followed by additional binary data. + @param ImageHandle Handle of image to be started. + @param ExitDataSize The pointer to the size, in bytes, of ExitData. + @param ExitData The pointer to a pointer to a data buffer that includes a Null-terminated + string, optionally followed by additional binary data. @retval EFI_INVALID_PARAMETER ImageHandle is either an invalid image handle or the image has already been initialized with StartImage. @@ -903,11 +877,11 @@ EFI_STATUS /** Terminates a loaded EFI image and returns control to boot services. - @param[in] ImageHandle Handle that identifies the image. This parameter is passed to the + @param ImageHandle Handle that identifies the image. This parameter is passed to the image on entry. - @param[in] ExitStatus The image's exit code. - @param[in] ExitDataSize The size, in bytes, of ExitData. Ignored if ExitStatus is EFI_SUCCESS. - @param[in] ExitData The pointer to a data buffer that includes a Null-terminated string, + @param ExitStatus The image's exit code. + @param ExitDataSize The size, in bytes, of ExitData. Ignored if ExitStatus is EFI_SUCCESS. + @param ExitData The pointer to a data buffer that includes a Null-terminated string, optionally followed by additional binary data. The string is a description that the caller may use to further indicate the reason for the image's exit. ExitData is only valid if ExitStatus @@ -932,7 +906,7 @@ EFI_STATUS /** Unloads an image. - @param[in] ImageHandle Handle that identifies the image to be unloaded. + @param ImageHandle Handle that identifies the image to be unloaded. @retval EFI_SUCCESS The image has been unloaded. @retval EFI_INVALID_PARAMETER ImageHandle is not a valid image handle. @@ -947,8 +921,8 @@ EFI_STATUS /** Terminates all boot services. - @param[in] ImageHandle Handle that identifies the exiting image. - @param[in] MapKey Key to the latest memory map. + @param ImageHandle Handle that identifies the exiting image. + @param MapKey Key to the latest memory map. @retval EFI_SUCCESS Boot services have been terminated. @retval EFI_INVALID_PARAMETER MapKey is incorrect. @@ -964,7 +938,7 @@ EFI_STATUS /** Induces a fine-grained stall. - @param[in] Microseconds The number of microseconds to stall execution. + @param Microseconds The number of microseconds to stall execution. @retval EFI_SUCCESS Execution was stalled at least the requested number of Microseconds. @@ -979,10 +953,10 @@ EFI_STATUS /** Sets the system's watchdog timer. - @param[in] Timeout The number of seconds to set the watchdog timer to. - @param[in] WatchdogCode The numeric code to log on a watchdog timer timeout event. - @param[in] DataSize The size, in bytes, of WatchdogData. - @param[in] WatchdogData A data buffer that includes a Null-terminated string, optionally + @param Timeout The number of seconds to set the watchdog timer to. + @param WatchdogCode The numeric code to log on a watchdog timer timeout event. + @param DataSize The size, in bytes, of WatchdogData. + @param WatchdogData A data buffer that includes a Null-terminated string, optionally followed by additional binary data. @retval EFI_SUCCESS The timeout has been set. @@ -1001,13 +975,46 @@ EFI_STATUS IN CHAR16 *WatchdogData OPTIONAL ); +/// +/// Enumeration of reset types. +/// +typedef enum { + /// + /// Used to induce a system-wide reset. This sets all circuitry within the + /// system to its initial state. This type of reset is asynchronous to system + /// operation and operates withgout regard to cycle boundaries. EfiColdReset + /// is tantamount to a system power cycle. + /// + EfiResetCold, + /// + /// Used to induce a system-wide initialization. The processors are set to their + /// initial state, and pending cycles are not corrupted. If the system does + /// not support this reset type, then an EfiResetCold must be performed. + /// + EfiResetWarm, + /// + /// Used to induce an entry into a power state equivalent to the ACPI G2/S5 or G3 + /// state. If the system does not support this reset type, then when the system + /// is rebooted, it should exhibit the EfiResetCold attributes. + /// + EfiResetShutdown, + /// + /// Used to induce a system-wide reset. The exact type of the reset is defined by + /// the EFI_GUID that follows the Null-terminated Unicode string passed into + /// ResetData. If the platform does not recognize the EFI_GUID in ResetData the + /// platform must pick a supported reset type to perform. The platform may + /// optionally log the parameters from any non-normal reset that occurs. + /// + EfiResetPlatformSpecific +} EFI_RESET_TYPE; + /** Resets the entire platform. - @param[in] ResetType The type of reset to perform. - @param[in] ResetStatus The status code for the reset. - @param[in] DataSize The size, in bytes, of WatchdogData. - @param[in] ResetData For a ResetType of EfiResetCold, EfiResetWarm, or + @param ResetType The type of reset to perform. + @param ResetStatus The status code for the reset. + @param DataSize The size, in bytes, of WatchdogData. + @param ResetData For a ResetType of EfiResetCold, EfiResetWarm, or EfiResetShutdown the data buffer starts with a Null-terminated string, optionally followed by additional binary data. @@ -1024,7 +1031,7 @@ VOID /** Returns a monotonically increasing count for the platform. - @param[out] Count The pointer to returned value. + @param Count The pointer to returned value. @retval EFI_SUCCESS The next monotonic count was returned. @retval EFI_INVALID_PARAMETER Count is NULL. @@ -1040,7 +1047,7 @@ EFI_STATUS /** Returns the next high 32 bits of the platform's monotonic counter. - @param[out] HighCount The pointer to returned value. + @param HighCount The pointer to returned value. @retval EFI_SUCCESS The next high monotonic count was returned. @retval EFI_INVALID_PARAMETER HighCount is NULL. @@ -1056,9 +1063,9 @@ EFI_STATUS /** Computes and returns a 32-bit CRC for a data buffer. - @param[in] Data A pointer to the buffer on which the 32-bit CRC is to be computed. - @param[in] DataSize The number of bytes in the buffer Data. - @param[out] Crc32 The 32-bit CRC that was computed for the data buffer specified by Data + @param Data A pointer to the buffer on which the 32-bit CRC is to be computed. + @param DataSize The number of bytes in the buffer Data. + @param Crc32 The 32-bit CRC that was computed for the data buffer specified by Data and DataSize. @retval EFI_SUCCESS The 32-bit CRC was computed for the data buffer and returned in @@ -1079,9 +1086,9 @@ EFI_STATUS /** Copies the contents of one buffer to another buffer. - @param[in] Destination The pointer to the destination buffer of the memory copy. - @param[in] Source The pointer to the source buffer of the memory copy. - @param[in] Length Number of bytes to copy from Source to Destination. + @param Destination The pointer to the destination buffer of the memory copy. + @param Source The pointer to the source buffer of the memory copy. + @param Length Number of bytes to copy from Source to Destination. **/ typedef @@ -1095,9 +1102,9 @@ VOID /** The SetMem() function fills a buffer with a specified value. - @param[in] Buffer The pointer to the buffer to fill. - @param[in] Size Number of bytes in Buffer to fill. - @param[in] Value Value to fill Buffer with. + @param Buffer The pointer to the buffer to fill. + @param Size Number of bytes in Buffer to fill. + @param Value Value to fill Buffer with. **/ typedef @@ -1125,10 +1132,10 @@ typedef enum { InstallMultipleProtocolInterfaces() be used in place of InstallProtocolInterface() - @param[in, out] Handle A pointer to the EFI_HANDLE on which the interface is to be installed. - @param[in] Protocol The numeric ID of the protocol interface. - @param[in] InterfaceType Indicates whether Interface is supplied in native form. - @param[in] Interface A pointer to the protocol interface. + @param Handle A pointer to the EFI_HANDLE on which the interface is to be installed. + @param Protocol The numeric ID of the protocol interface. + @param InterfaceType Indicates whether Interface is supplied in native form. + @param Interface A pointer to the protocol interface. @retval EFI_SUCCESS The protocol interface was installed. @retval EFI_OUT_OF_RESOURCES Space for a new handle could not be allocated. @@ -1150,7 +1157,7 @@ EFI_STATUS /** Installs one or more protocol interfaces into the boot services environment. - @param[in, out] Handle The pointer to a handle to install the new protocol interfaces on, + @param Handle The pointer to a handle to install the new protocol interfaces on, or a pointer to NULL if a new handle is to be allocated. @param ... A variable argument list containing pairs of protocol GUIDs and protocol interfaces. @@ -1173,11 +1180,11 @@ EFI_STATUS /** Reinstalls a protocol interface on a device handle. - @param[in] Handle Handle on which the interface is to be reinstalled. - @param[in] Protocol The numeric ID of the interface. - @param[in] OldInterface A pointer to the old interface. NULL can be used if a structure is not + @param Handle Handle on which the interface is to be reinstalled. + @param Protocol The numeric ID of the interface. + @param OldInterface A pointer to the old interface. NULL can be used if a structure is not associated with Protocol. - @param[in] NewInterface A pointer to the new interface. + @param NewInterface A pointer to the new interface. @retval EFI_SUCCESS The protocol interface was reinstalled. @retval EFI_NOT_FOUND The OldInterface on the handle was not found. @@ -1202,9 +1209,9 @@ EFI_STATUS UninstallMultipleProtocolInterfaces() be used in place of UninstallProtocolInterface(). - @param[in] Handle The handle on which the interface was installed. - @param[in] Protocol The numeric ID of the interface. - @param[in] Interface A pointer to the interface. + @param Handle The handle on which the interface was installed. + @param Protocol The numeric ID of the interface. + @param Interface A pointer to the interface. @retval EFI_SUCCESS The interface was removed. @retval EFI_NOT_FOUND The interface was not found. @@ -1225,7 +1232,7 @@ EFI_STATUS /** Removes one or more protocol interfaces into the boot services environment. - @param[in] Handle The handle to remove the protocol interfaces from. + @param Handle The handle to remove the protocol interfaces from. @param ... A variable argument list containing pairs of protocol GUIDs and protocol interfaces. @@ -1243,9 +1250,9 @@ EFI_STATUS /** Queries a handle to determine if it supports a specified protocol. - @param[in] Handle The handle being queried. - @param[in] Protocol The published unique identifier of the protocol. - @param[out] Interface Supplies the address where a pointer to the corresponding Protocol + @param Handle The handle being queried. + @param Protocol The published unique identifier of the protocol. + @param Interface Supplies the address where a pointer to the corresponding Protocol Interface is returned. @retval EFI_SUCCESS The interface information for the specified protocol was returned. @@ -1274,18 +1281,18 @@ EFI_STATUS Queries a handle to determine if it supports a specified protocol. If the protocol is supported by the handle, it opens the protocol on behalf of the calling agent. - @param[in] Handle The handle for the protocol interface that is being opened. - @param[in] Protocol The published unique identifier of the protocol. - @param[out] Interface Supplies the address where a pointer to the corresponding Protocol + @param Handle The handle for the protocol interface that is being opened. + @param Protocol The published unique identifier of the protocol. + @param Interface Supplies the address where a pointer to the corresponding Protocol Interface is returned. - @param[in] AgentHandle The handle of the agent that is opening the protocol interface + @param AgentHandle The handle of the agent that is opening the protocol interface specified by Protocol and Interface. - @param[in] ControllerHandle If the agent that is opening a protocol is a driver that follows the + @param ControllerHandle If the agent that is opening a protocol is a driver that follows the UEFI Driver Model, then this parameter is the controller handle that requires the protocol interface. If the agent does not follow the UEFI Driver Model, then this parameter is optional and may be NULL. - @param[in] Attributes The open mode of the protocol interface specified by Handle + @param Attributes The open mode of the protocol interface specified by Handle and Protocol. @retval EFI_SUCCESS An item was added to the open list for the protocol interface, and the @@ -1312,11 +1319,11 @@ EFI_STATUS /** Closes a protocol on a handle that was opened using OpenProtocol(). - @param[in] Handle The handle for the protocol interface that was previously opened + @param Handle The handle for the protocol interface that was previously opened with OpenProtocol(), and is now being closed. - @param[in] Protocol The published unique identifier of the protocol. - @param[in] AgentHandle The handle of the agent that is closing the protocol interface. - @param[in] ControllerHandle If the agent that opened a protocol is a driver that follows the + @param Protocol The published unique identifier of the protocol. + @param AgentHandle The handle of the agent that is closing the protocol interface. + @param ControllerHandle If the agent that opened a protocol is a driver that follows the UEFI Driver Model, then this parameter is the controller handle that required the protocol interface. @@ -1352,11 +1359,11 @@ typedef struct { /** Retrieves the list of agents that currently have a protocol interface opened. - @param[in] Handle The handle for the protocol interface that is being queried. - @param[in] Protocol The published unique identifier of the protocol. - @param[out] EntryBuffer A pointer to a buffer of open protocol information in the form of + @param Handle The handle for the protocol interface that is being queried. + @param Protocol The published unique identifier of the protocol. + @param EntryBuffer A pointer to a buffer of open protocol information in the form of EFI_OPEN_PROTOCOL_INFORMATION_ENTRY structures. - @param[out] EntryCount A pointer to the number of entries in EntryBuffer. + @param EntryCount A pointer to the number of entries in EntryBuffer. @retval EFI_SUCCESS The open protocol information was returned in EntryBuffer, and the number of entries was returned EntryCount. @@ -1377,12 +1384,12 @@ EFI_STATUS Retrieves the list of protocol interface GUIDs that are installed on a handle in a buffer allocated from pool. - @param[in] Handle The handle from which to retrieve the list of protocol interface - GUIDs. - @param[out] ProtocolBuffer A pointer to the list of protocol interface GUID pointers that are - installed on Handle. - @param[out] ProtocolBufferCount A pointer to the number of GUID pointers present in - ProtocolBuffer. + @param Handle The handle from which to retrieve the list of protocol interface + GUIDs. + @param ProtocolBuffer A pointer to the list of protocol interface GUID pointers that are + installed on Handle. + @param ProtocolBufferCount A pointer to the number of GUID pointers present in + ProtocolBuffer. @retval EFI_SUCCESS The list of protocol interface GUIDs installed on Handle was returned in ProtocolBuffer. The number of protocol interface GUIDs was @@ -1405,10 +1412,10 @@ EFI_STATUS /** Creates an event that is to be signaled whenever an interface is installed for a specified protocol. - @param[in] Protocol The numeric ID of the protocol for which the event is to be registered. - @param[in] Event Event that is to be signaled whenever a protocol interface is registered + @param Protocol The numeric ID of the protocol for which the event is to be registered. + @param Event Event that is to be signaled whenever a protocol interface is registered for Protocol. - @param[out] Registration A pointer to a memory location to receive the registration value. + @param Registration A pointer to a memory location to receive the registration value. @retval EFI_SUCCESS The notification event has been registered. @retval EFI_OUT_OF_RESOURCES Space for the notification event could not be allocated. @@ -1447,14 +1454,14 @@ typedef enum { /** Returns an array of handles that support a specified protocol. - @param[in] SearchType Specifies which handle(s) are to be returned. - @param[in] Protocol Specifies the protocol to search by. - @param[in] SearchKey Specifies the search key. - @param[in, out] BufferSize On input, the size in bytes of Buffer. On output, the size in bytes of + @param SearchType Specifies which handle(s) are to be returned. + @param Protocol Specifies the protocol to search by. + @param SearchKey Specifies the search key. + @param BufferSize On input, the size in bytes of Buffer. On output, the size in bytes of the array returned in Buffer (if the buffer was large enough) or the size, in bytes, of the buffer needed to obtain the array (if the buffer was not large enough). - @param[out] Buffer The buffer in which the array is returned. + @param Buffer The buffer in which the array is returned. @retval EFI_SUCCESS The array of handles was returned. @retval EFI_NOT_FOUND No handles match the search. @@ -1479,11 +1486,11 @@ EFI_STATUS /** Locates the handle to a device on the device path that supports the specified protocol. - @param[in] Protocol Specifies the protocol to search for. - @param[in, out] DevicePath On input, a pointer to a pointer to the device path. On output, the device + @param Protocol Specifies the protocol to search for. + @param DevicePath On input, a pointer to a pointer to the device path. On output, the device path pointer is modified to point to the remaining part of the device path. - @param[out] Device A pointer to the returned device handle. + @param Device A pointer to the returned device handle. @retval EFI_SUCCESS The resulting handle was returned. @retval EFI_NOT_FOUND No handles match the search. @@ -1503,8 +1510,8 @@ EFI_STATUS /** Adds, updates, or removes a configuration table entry from the EFI System Table. - @param[in] Guid A pointer to the GUID for the entry to add, update, or remove. - @param[in] Table A pointer to the configuration table for the entry to add, update, or + @param Guid A pointer to the GUID for the entry to add, update, or remove. + @param Table A pointer to the configuration table for the entry to add, update, or remove. May be NULL. @retval EFI_SUCCESS The (Guid, Table) pair was added, updated, or removed. @@ -1523,12 +1530,12 @@ EFI_STATUS /** Returns an array of handles that support the requested protocol in a buffer allocated from pool. - @param[in] SearchType Specifies which handle(s) are to be returned. - @param[in] Protocol Provides the protocol to search by. + @param SearchType Specifies which handle(s) are to be returned. + @param Protocol Provides the protocol to search by. This parameter is only valid for a SearchType of ByProtocol. - @param[in] SearchKey Supplies the search key depending on the SearchType. - @param[in, out] NoHandles The number of handles returned in Buffer. - @param[out] Buffer A pointer to the buffer to return the requested array of handles that + @param SearchKey Supplies the search key depending on the SearchType. + @param NoHandles The number of handles returned in Buffer. + @param Buffer A pointer to the buffer to return the requested array of handles that support Protocol. @retval EFI_SUCCESS The array of handles was returned in Buffer, and the number of @@ -1552,10 +1559,10 @@ EFI_STATUS /** Returns the first protocol instance that matches the given protocol. - @param[in] Protocol Provides the protocol to search for. - @param[in] Registration Optional registration key returned from + @param Protocol Provides the protocol to search for. + @param Registration Optional registration key returned from RegisterProtocolNotify(). - @param[out] Interface On return, a pointer to the first interface that matches Protocol and + @param Interface On return, a pointer to the first interface that matches Protocol and Registration. @retval EFI_SUCCESS A protocol instance matching Protocol was found and returned in @@ -1650,13 +1657,13 @@ typedef struct { be passed into ResetSystem() and will cause the capsule to be processed by the firmware as part of the reset process. - @param[in] CapsuleHeaderArray Virtual pointer to an array of virtual pointers to the capsules - being passed into update capsule. - @param[in] CapsuleCount Number of pointers to EFI_CAPSULE_HEADER in - CaspuleHeaderArray. - @param[in] ScatterGatherList Physical pointer to a set of - EFI_CAPSULE_BLOCK_DESCRIPTOR that describes the - location in physical memory of a set of capsules. + @param CapsuleHeaderArray Virtual pointer to an array of virtual pointers to the capsules + being passed into update capsule. + @param CapsuleCount Number of pointers to EFI_CAPSULE_HEADER in + CaspuleHeaderArray. + @param ScatterGatherList Physical pointer to a set of + EFI_CAPSULE_BLOCK_DESCRIPTOR that describes the + location in physical memory of a set of capsules. @retval EFI_SUCCESS Valid capsule was passed. If CAPSULE_FLAGS_PERSIT_ACROSS_RESET is not set, the @@ -1684,14 +1691,14 @@ EFI_STATUS /** Returns if the capsule can be supported via UpdateCapsule(). - @param[in] CapsuleHeaderArray Virtual pointer to an array of virtual pointers to the capsules - being passed into update capsule. - @param[in] CapsuleCount Number of pointers to EFI_CAPSULE_HEADER in - CaspuleHeaderArray. - @param[out] MaxiumCapsuleSize On output the maximum size that UpdateCapsule() can - support as an argument to UpdateCapsule() via - CapsuleHeaderArray and ScatterGatherList. - @param[out] ResetType Returns the type of reset required for the capsule update. + @param CapsuleHeaderArray Virtual pointer to an array of virtual pointers to the capsules + being passed into update capsule. + @param CapsuleCount Number of pointers to EFI_CAPSULE_HEADER in + CaspuleHeaderArray. + @param MaxiumCapsuleSize On output the maximum size that UpdateCapsule() can + support as an argument to UpdateCapsule() via + CapsuleHeaderArray and ScatterGatherList. + @param ResetType Returns the type of reset required for the capsule update. @retval EFI_SUCCESS Valid answer returned. @retval EFI_UNSUPPORTED The capsule type is not supported on this platform, and @@ -1716,16 +1723,16 @@ EFI_STATUS /** Returns information about the EFI variables. - @param[in] Attributes Attributes bitmask to specify the type of variables on - which to return information. - @param[out] MaximumVariableStorageSize On output the maximum size of the storage space - available for the EFI variables associated with the - attributes specified. - @param[out] RemainingVariableStorageSize Returns the remaining size of the storage space - available for the EFI variables associated with the - attributes specified. - @param[out] MaximumVariableSize Returns the maximum size of the individual EFI - variables associated with the attributes specified. + @param Attributes Attributes bitmask to specify the type of variables on + which to return information. + @param MaximumVariableStorageSize On output the maximum size of the storage space + available for the EFI variables associated with the + attributes specified. + @param RemainingVariableStorageSize Returns the remaining size of the storage space + available for the EFI variables associated with the + attributes specified. + @param MaximumVariableSize Returns the maximum size of the individual EFI + variables associated with the attributes specified. @retval EFI_SUCCESS Valid answer returned. @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied @@ -1752,14 +1759,11 @@ EFI_STATUS #define EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED 0x0000000000000004 #define EFI_OS_INDICATIONS_FMP_CAPSULE_SUPPORTED 0x0000000000000008 #define EFI_OS_INDICATIONS_CAPSULE_RESULT_VAR_SUPPORTED 0x0000000000000010 -#define EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY 0x0000000000000040 // // EFI Runtime Services Table // #define EFI_SYSTEM_TABLE_SIGNATURE SIGNATURE_64 ('I','B','I',' ','S','Y','S','T') -#define EFI_2_60_SYSTEM_TABLE_REVISION ((2 << 16) | (60)) -#define EFI_2_50_SYSTEM_TABLE_REVISION ((2 << 16) | (50)) #define EFI_2_40_SYSTEM_TABLE_REVISION ((2 << 16) | (40)) #define EFI_2_31_SYSTEM_TABLE_REVISION ((2 << 16) | (31)) #define EFI_2_30_SYSTEM_TABLE_REVISION ((2 << 16) | (30)) @@ -1768,7 +1772,7 @@ EFI_STATUS #define EFI_2_00_SYSTEM_TABLE_REVISION ((2 << 16) | (00)) #define EFI_1_10_SYSTEM_TABLE_REVISION ((1 << 16) | (10)) #define EFI_1_02_SYSTEM_TABLE_REVISION ((1 << 16) | (02)) -#define EFI_SYSTEM_TABLE_REVISION EFI_2_60_SYSTEM_TABLE_REVISION +#define EFI_SYSTEM_TABLE_REVISION EFI_2_40_SYSTEM_TABLE_REVISION #define EFI_SPECIFICATION_VERSION EFI_SYSTEM_TABLE_REVISION #define EFI_RUNTIME_SERVICES_SIGNATURE SIGNATURE_64 ('R','U','N','T','S','E','R','V') @@ -2010,8 +2014,8 @@ typedef struct { the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including both device drivers and bus drivers. - @param[in] ImageHandle The firmware allocated handle for the UEFI image. - @param[in] SystemTable A pointer to the EFI System Table. + @param ImageHandle The firmware allocated handle for the UEFI image. + @param SystemTable A pointer to the EFI System Table. @retval EFI_SUCCESS The operation completed successfully. @retval Others An unexpected error occurred. @@ -2024,69 +2028,19 @@ EFI_STATUS ); // -// EFI Load Option. This data structure describes format of UEFI boot option variables. -// -// NOTE: EFI Load Option is a byte packed buffer of variable length fields. -// The first two fields have fixed length. They are declared as members of the -// EFI_LOAD_OPTION structure. All the other fields are variable length fields. -// They are listed in the comment block below for reference purposes. -// -#pragma pack(1) -typedef struct _EFI_LOAD_OPTION { - /// - /// The attributes for this load option entry. All unused bits must be zero - /// and are reserved by the UEFI specification for future growth. - /// - UINT32 Attributes; - /// - /// Length in bytes of the FilePathList. OptionalData starts at offset - /// sizeof(UINT32) + sizeof(UINT16) + StrSize(Description) + FilePathListLength - /// of the EFI_LOAD_OPTION descriptor. - /// - UINT16 FilePathListLength; - /// - /// The user readable description for the load option. - /// This field ends with a Null character. - /// - // CHAR16 Description[]; - /// - /// A packed array of UEFI device paths. The first element of the array is a - /// device path that describes the device and location of the Image for this - /// load option. The FilePathList[0] is specific to the device type. Other - /// device paths may optionally exist in the FilePathList, but their usage is - /// OSV specific. Each element in the array is variable length, and ends at - /// the device path end structure. Because the size of Description is - /// arbitrary, this data structure is not guaranteed to be aligned on a - /// natural boundary. This data structure may have to be copied to an aligned - /// natural boundary before it is used. - /// - // EFI_DEVICE_PATH_PROTOCOL FilePathList[]; - /// - /// The remaining bytes in the load option descriptor are a binary data buffer - /// that is passed to the loaded image. If the field is zero bytes long, a - /// NULL pointer is passed to the loaded image. The number of bytes in - /// OptionalData can be computed by subtracting the starting offset of - /// OptionalData from total size in bytes of the EFI_LOAD_OPTION. - /// - // UINT8 OptionalData[]; -} EFI_LOAD_OPTION; -#pragma pack() - -// // EFI Load Options Attributes // -#define LOAD_OPTION_ACTIVE 0x00000001 -#define LOAD_OPTION_FORCE_RECONNECT 0x00000002 -#define LOAD_OPTION_HIDDEN 0x00000008 -#define LOAD_OPTION_CATEGORY 0x00001F00 - -#define LOAD_OPTION_CATEGORY_BOOT 0x00000000 -#define LOAD_OPTION_CATEGORY_APP 0x00000100 - -#define EFI_BOOT_OPTION_SUPPORT_KEY 0x00000001 -#define EFI_BOOT_OPTION_SUPPORT_APP 0x00000002 -#define EFI_BOOT_OPTION_SUPPORT_SYSPREP 0x00000010 -#define EFI_BOOT_OPTION_SUPPORT_COUNT 0x00000300 +#define LOAD_OPTION_ACTIVE 0x00000001 +#define LOAD_OPTION_FORCE_RECONNECT 0x00000002 +#define LOAD_OPTION_HIDDEN 0x00000008 +#define LOAD_OPTION_CATEGORY 0x00001F00 + +#define LOAD_OPTION_CATEGORY_BOOT 0x00000000 +#define LOAD_OPTION_CATEGORY_APP 0x00000100 + +#define EFI_BOOT_OPTION_SUPPORT_KEY 0x00000001 +#define EFI_BOOT_OPTION_SUPPORT_APP 0x00000002 +#define EFI_BOOT_OPTION_SUPPORT_COUNT 0x00000300 /// /// EFI Boot Key Data diff --git a/roms/ipxe/src/include/ipxe/efi/X64/ProcessorBind.h b/roms/ipxe/src/include/ipxe/efi/X64/ProcessorBind.h index b64c25c0f..4f21bb8de 100644 --- a/roms/ipxe/src/include/ipxe/efi/X64/ProcessorBind.h +++ b/roms/ipxe/src/include/ipxe/efi/X64/ProcessorBind.h @@ -1,7 +1,7 @@ /** @file Processor or Compiler specific defines and types x64 (Intel 64, AMD64). - Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR> + Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR> This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -96,26 +96,6 @@ FILE_LICENCE ( BSD3 ); // #pragma warning ( disable : 4206 ) -#if _MSC_VER == 1800 || _MSC_VER == 1900 - -// -// Disable these warnings for VS2013. -// - -// -// This warning is for potentially uninitialized local variable, and it may cause false -// positive issues in VS2013 and VS2015 build -// -#pragma warning ( disable : 4701 ) - -// -// This warning is for potentially uninitialized local pointer variable, and it may cause -// false positive issues in VS2013 and VS2015 build -// -#pragma warning ( disable : 4703 ) - -#endif - #endif @@ -271,12 +251,12 @@ typedef INT64 INTN; /// #elif defined(_MSC_EXTENSIONS) /// - /// Microsoft* compiler specific method for EFIAPI calling convention. + /// Microsoft* compiler specific method for EFIAPI calling convension /// #define EFIAPI __cdecl #elif defined(__GNUC__) /// - /// Define the standard calling convention regardless of optimization level. + /// Define the standard calling convention reguardless of optimization level. /// The GCC support assumes a GCC compiler that supports the EFI ABI. The EFI /// ABI is much closer to the x64 Microsoft* ABI than standard x64 (x86-64) /// GCC ABI. Thus a standard x64 (x86-64) GCC compiler can not be used for diff --git a/roms/ipxe/src/include/ipxe/efi/efi.h b/roms/ipxe/src/include/ipxe/efi/efi.h index db9943a42..ab52dd9e0 100644 --- a/roms/ipxe/src/include/ipxe/efi/efi.h +++ b/roms/ipxe/src/include/ipxe/efi/efi.h @@ -153,15 +153,12 @@ struct efi_config_table { */ #define EEFI( efirc ) EPLATFORM ( EINFO_EPLATFORM, efirc ) -extern EFI_GUID efi_absolute_pointer_protocol_guid; -extern EFI_GUID efi_apple_net_boot_protocol_guid; extern EFI_GUID efi_arp_protocol_guid; extern EFI_GUID efi_arp_service_binding_protocol_guid; extern EFI_GUID efi_block_io_protocol_guid; extern EFI_GUID efi_bus_specific_driver_override_protocol_guid; extern EFI_GUID efi_component_name_protocol_guid; extern EFI_GUID efi_component_name2_protocol_guid; -extern EFI_GUID efi_console_control_protocol_guid; extern EFI_GUID efi_device_path_protocol_guid; extern EFI_GUID efi_dhcp4_protocol_guid; extern EFI_GUID efi_dhcp4_service_binding_protocol_guid; @@ -169,7 +166,6 @@ extern EFI_GUID efi_disk_io_protocol_guid; extern EFI_GUID efi_driver_binding_protocol_guid; extern EFI_GUID efi_graphics_output_protocol_guid; extern EFI_GUID efi_hii_config_access_protocol_guid; -extern EFI_GUID efi_hii_font_protocol_guid; extern EFI_GUID efi_ip4_protocol_guid; extern EFI_GUID efi_ip4_config_protocol_guid; extern EFI_GUID efi_ip4_service_binding_protocol_guid; @@ -186,43 +182,23 @@ extern EFI_GUID efi_nii31_protocol_guid; extern EFI_GUID efi_pci_io_protocol_guid; extern EFI_GUID efi_pci_root_bridge_io_protocol_guid; extern EFI_GUID efi_pxe_base_code_protocol_guid; -extern EFI_GUID efi_serial_io_protocol_guid; extern EFI_GUID efi_simple_file_system_protocol_guid; extern EFI_GUID efi_simple_network_protocol_guid; -extern EFI_GUID efi_simple_pointer_protocol_guid; -extern EFI_GUID efi_simple_text_input_protocol_guid; -extern EFI_GUID efi_simple_text_input_ex_protocol_guid; -extern EFI_GUID efi_simple_text_output_protocol_guid; extern EFI_GUID efi_tcg_protocol_guid; extern EFI_GUID efi_tcp4_protocol_guid; extern EFI_GUID efi_tcp4_service_binding_protocol_guid; -extern EFI_GUID efi_tree_protocol_guid; extern EFI_GUID efi_udp4_protocol_guid; extern EFI_GUID efi_udp4_service_binding_protocol_guid; -extern EFI_GUID efi_uga_draw_protocol_guid; -extern EFI_GUID efi_unicode_collation_protocol_guid; -extern EFI_GUID efi_usb_hc_protocol_guid; -extern EFI_GUID efi_usb2_hc_protocol_guid; -extern EFI_GUID efi_usb_io_protocol_guid; extern EFI_GUID efi_vlan_config_protocol_guid; -extern EFI_GUID efi_file_info_id; -extern EFI_GUID efi_file_system_info_id; - extern EFI_HANDLE efi_image_handle; extern EFI_LOADED_IMAGE_PROTOCOL *efi_loaded_image; extern EFI_DEVICE_PATH_PROTOCOL *efi_loaded_image_path; extern EFI_SYSTEM_TABLE *efi_systab; -extern const __attribute__ (( pure )) char * efi_guid_ntoa ( EFI_GUID *guid ); -extern const __attribute__ (( pure )) char * -efi_locate_search_type_name ( EFI_LOCATE_SEARCH_TYPE search_type ); -extern const __attribute__ (( pure )) char * -efi_open_attributes_name ( unsigned int attributes ); -extern const __attribute__ (( pure )) char * -efi_devpath_text ( EFI_DEVICE_PATH_PROTOCOL *path ); -extern const __attribute__ (( pure )) char * -efi_handle_name ( EFI_HANDLE handle ); +extern const char * efi_guid_ntoa ( EFI_GUID *guid ); +extern const char * efi_devpath_text ( EFI_DEVICE_PATH_PROTOCOL *path ); +extern const char * efi_handle_name ( EFI_HANDLE handle ); extern void dbg_efi_openers ( EFI_HANDLE handle, EFI_GUID *protocol ); extern void dbg_efi_protocols ( EFI_HANDLE handle ); diff --git a/roms/ipxe/src/include/ipxe/efi/efi_driver.h b/roms/ipxe/src/include/ipxe/efi/efi_driver.h index 74ece90db..f497df3e3 100644 --- a/roms/ipxe/src/include/ipxe/efi/efi_driver.h +++ b/roms/ipxe/src/include/ipxe/efi/efi_driver.h @@ -19,8 +19,6 @@ struct efi_device { struct device dev; /** EFI device handle */ EFI_HANDLE device; - /** EFI device path copy */ - EFI_DEVICE_PATH_PROTOCOL *path; /** Driver for this device */ struct efi_driver *driver; /** Driver-private data */ diff --git a/roms/ipxe/src/include/ipxe/efi/efi_pxe.h b/roms/ipxe/src/include/ipxe/efi/efi_pxe.h deleted file mode 100644 index b356f3789..000000000 --- a/roms/ipxe/src/include/ipxe/efi/efi_pxe.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef _IPXE_EFI_PXE_H -#define _IPXE_EFI_PXE_H - -/** @file - * - * EFI PXE base code protocol - */ - -#include <ipxe/efi/efi.h> -#include <ipxe/netdevice.h> - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -extern int efi_pxe_install ( EFI_HANDLE handle, struct net_device *netdev ); -extern void efi_pxe_uninstall ( EFI_HANDLE handle ); - -#endif /* _IPXE_EFI_PXE_H */ diff --git a/roms/ipxe/src/include/ipxe/efi/efi_snp.h b/roms/ipxe/src/include/ipxe/efi/efi_snp.h index 4c5461ec4..1e5c66626 100644 --- a/roms/ipxe/src/include/ipxe/efi/efi_snp.h +++ b/roms/ipxe/src/include/ipxe/efi/efi_snp.h @@ -73,14 +73,14 @@ extern int efi_snp_hii_install ( struct efi_snp_device *snpdev ); extern void efi_snp_hii_uninstall ( struct efi_snp_device *snpdev ); extern struct efi_snp_device * find_snpdev ( EFI_HANDLE handle ); extern struct efi_snp_device * last_opened_snpdev ( void ); -extern void efi_snp_add_claim ( int delta ); +extern void efi_snp_set_claimed ( int claimed ); /** * Claim network devices for use by iPXE * */ static inline void efi_snp_claim ( void ) { - efi_snp_add_claim ( +1 ); + efi_snp_set_claimed ( 1 ); } /** @@ -88,7 +88,7 @@ static inline void efi_snp_claim ( void ) { * */ static inline void efi_snp_release ( void ) { - efi_snp_add_claim ( -1 ); + efi_snp_set_claimed ( 0 ); } #endif /* _IPXE_EFI_SNP_H */ diff --git a/roms/ipxe/src/include/ipxe/efi/efi_timer.h b/roms/ipxe/src/include/ipxe/efi/efi_timer.h index c49875988..c03765393 100644 --- a/roms/ipxe/src/include/ipxe/efi/efi_timer.h +++ b/roms/ipxe/src/include/ipxe/efi/efi_timer.h @@ -15,22 +15,4 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #define TIMER_PREFIX_efi __efi_ #endif -/** - * Number of ticks per second - * - * This is a policy decision. - */ -#define EFI_TICKS_PER_SEC 20 - -/** - * Get number of ticks per second - * - * @ret ticks_per_sec Number of ticks per second - */ -static inline __attribute__ (( always_inline )) unsigned long -TIMER_INLINE ( efi, ticks_per_sec ) ( void ) { - - return EFI_TICKS_PER_SEC; -} - #endif /* _IPXE_EFI_TIMER_H */ diff --git a/roms/ipxe/src/include/ipxe/efi/efi_usb.h b/roms/ipxe/src/include/ipxe/efi/efi_usb.h deleted file mode 100644 index 05b4fad00..000000000 --- a/roms/ipxe/src/include/ipxe/efi/efi_usb.h +++ /dev/null @@ -1,80 +0,0 @@ -#ifndef _IPXE_EFI_USB_H -#define _IPXE_EFI_USB_H - -/** @file - * - * USB I/O protocol - * - */ - -#include <ipxe/list.h> -#include <ipxe/efi/efi.h> -#include <ipxe/efi/efi_driver.h> -#include <ipxe/efi/Protocol/UsbIo.h> -#include <ipxe/usb.h> - -/** An EFI USB device */ -struct efi_usb_device { - /** Name */ - const char *name; - /** The underlying USB device */ - struct usb_device *usb; - /** The underlying EFI device */ - struct efi_device *efidev; - /** Configuration descriptor */ - struct usb_configuration_descriptor *config; - /** Supported languages */ - struct usb_descriptor_header *languages; - /** List of interfaces */ - struct list_head interfaces; -}; - -/** An EFI USB device interface */ -struct efi_usb_interface { - /** Name */ - char name[32]; - /** Containing USB device */ - struct efi_usb_device *usbdev; - /** List of interfaces */ - struct list_head list; - - /** Interface number */ - unsigned int interface; - /** Alternate setting */ - unsigned int alternate; - /** EFI handle */ - EFI_HANDLE handle; - /** USB I/O protocol */ - EFI_USB_IO_PROTOCOL usbio; - /** Device path */ - EFI_DEVICE_PATH_PROTOCOL *path; - - /** Opened endpoints */ - struct efi_usb_endpoint *endpoint[32]; -}; - -/** An EFI USB device endpoint */ -struct efi_usb_endpoint { - /** EFI USB device interface */ - struct efi_usb_interface *usbintf; - /** USB endpoint */ - struct usb_endpoint ep; - - /** Most recent synchronous completion status */ - int rc; - - /** Asynchronous timer event */ - EFI_EVENT event; - /** Asynchronous callback handler */ - EFI_ASYNC_USB_TRANSFER_CALLBACK callback; - /** Asynchronous callback context */ - void *context; -}; - -/** Asynchronous transfer fill level - * - * This is a policy decision. - */ -#define EFI_USB_ASYNC_FILL 2 - -#endif /* _IPXE_EFI_USB_H */ diff --git a/roms/ipxe/src/include/ipxe/efi/efi_utils.h b/roms/ipxe/src/include/ipxe/efi/efi_utils.h index 67acba17e..57268daf7 100644 --- a/roms/ipxe/src/include/ipxe/efi/efi_utils.h +++ b/roms/ipxe/src/include/ipxe/efi/efi_utils.h @@ -15,7 +15,6 @@ struct device; extern EFI_DEVICE_PATH_PROTOCOL * efi_devpath_end ( EFI_DEVICE_PATH_PROTOCOL *path ); -extern size_t efi_devpath_len ( EFI_DEVICE_PATH_PROTOCOL *path ); extern int efi_locate_device ( EFI_HANDLE device, EFI_GUID *protocol, EFI_HANDLE *parent ); extern int efi_child_add ( EFI_HANDLE parent, EFI_HANDLE child ); diff --git a/roms/ipxe/src/include/ipxe/eoib.h b/roms/ipxe/src/include/ipxe/eoib.h deleted file mode 100644 index 93f496c36..000000000 --- a/roms/ipxe/src/include/ipxe/eoib.h +++ /dev/null @@ -1,103 +0,0 @@ -#ifndef _IPXE_EOIB_H -#define _IPXE_EOIB_H - -/** @file - * - * Ethernet over Infiniband - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#include <stdint.h> -#include <byteswap.h> -#include <ipxe/netdevice.h> -#include <ipxe/infiniband.h> -#include <ipxe/ib_mcast.h> - -/** An EoIB header */ -struct eoib_header { - /** Signature */ - uint16_t magic; - /** Reserved */ - uint16_t reserved; -} __attribute__ (( packed )); - -/** EoIB magic signature */ -#define EOIB_MAGIC 0x8919 - -/** An EoIB device */ -struct eoib_device { - /** Name */ - const char *name; - /** Network device */ - struct net_device *netdev; - /** Underlying Infiniband device */ - struct ib_device *ibdev; - /** List of EoIB devices */ - struct list_head list; - /** Broadcast address */ - struct ib_address_vector broadcast; - - /** Completion queue */ - struct ib_completion_queue *cq; - /** Queue pair */ - struct ib_queue_pair *qp; - /** Broadcast group membership */ - struct ib_mc_membership membership; - - /** Peer cache */ - struct list_head peers; - - /** Send duplicate packet to gateway (or NULL) - * - * @v eoib EoIB device - * @v original Original I/O buffer - */ - void ( * duplicate ) ( struct eoib_device *eoib, - struct io_buffer *original ); - /** Gateway (if any) */ - struct ib_address_vector gateway; - /** Multicast group additional component mask */ - unsigned int mask; -}; - -/** - * Check if EoIB device uses a gateway - * - * @v eoib EoIB device - * @v has_gw EoIB device uses a gateway - */ -static inline int eoib_has_gateway ( struct eoib_device *eoib ) { - - return ( eoib->duplicate != NULL ); -} - -/** - * Force creation of multicast group - * - * @v eoib EoIB device - */ -static inline void eoib_force_group_creation ( struct eoib_device *eoib ) { - - /* Some dubious EoIB implementations require each endpoint to - * force the creation of the multicast group. Yes, this makes - * it impossible for the group parameters (e.g. SL) to ever be - * modified without breaking backwards compatiblity with every - * existing driver. - */ - eoib->mask = ( IB_SA_MCMEMBER_REC_PKEY | IB_SA_MCMEMBER_REC_QKEY | - IB_SA_MCMEMBER_REC_SL | IB_SA_MCMEMBER_REC_FLOW_LABEL | - IB_SA_MCMEMBER_REC_TRAFFIC_CLASS ); -} - -extern int eoib_create ( struct ib_device *ibdev, const uint8_t *hw_addr, - struct ib_address_vector *broadcast, - const char *name ); -extern struct eoib_device * eoib_find ( struct ib_device *ibdev, - const uint8_t *hw_addr ); -extern void eoib_destroy ( struct eoib_device *eoib ); -extern void eoib_set_gateway ( struct eoib_device *eoib, - struct ib_address_vector *av ); - -#endif /* _IPXE_EOIB_H */ diff --git a/roms/ipxe/src/include/ipxe/errfile.h b/roms/ipxe/src/include/ipxe/errfile.h index f743dae6f..e21c95938 100644 --- a/roms/ipxe/src/include/ipxe/errfile.h +++ b/roms/ipxe/src/include/ipxe/errfile.h @@ -85,7 +85,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #define ERRFILE_uhci ( ERRFILE_DRIVER | 0x000b0000 ) #define ERRFILE_usbhid ( ERRFILE_DRIVER | 0x000c0000 ) #define ERRFILE_usbkbd ( ERRFILE_DRIVER | 0x000d0000 ) -#define ERRFILE_usbio ( ERRFILE_DRIVER | 0x000e0000 ) #define ERRFILE_nvs ( ERRFILE_DRIVER | 0x00100000 ) #define ERRFILE_spi ( ERRFILE_DRIVER | 0x00110000 ) @@ -183,15 +182,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #define ERRFILE_smsc75xx ( ERRFILE_DRIVER | 0x00770000 ) #define ERRFILE_intelvf ( ERRFILE_DRIVER | 0x00780000 ) #define ERRFILE_intelxvf ( ERRFILE_DRIVER | 0x00790000 ) -#define ERRFILE_smsc95xx ( ERRFILE_DRIVER | 0x007a0000 ) -#define ERRFILE_acm ( ERRFILE_DRIVER | 0x007b0000 ) -#define ERRFILE_eoib ( ERRFILE_DRIVER | 0x007c0000 ) -#define ERRFILE_golan ( ERRFILE_DRIVER | 0x007d0000 ) -#define ERRFILE_flexboot_nodnic ( ERRFILE_DRIVER | 0x007e0000 ) -#define ERRFILE_virtio_pci ( ERRFILE_DRIVER | 0x007f0000 ) -#define ERRFILE_pciea ( ERRFILE_DRIVER | 0x00c00000 ) -#define ERRFILE_axge ( ERRFILE_DRIVER | 0x00c10000 ) -#define ERRFILE_thunderx ( ERRFILE_DRIVER | 0x00c20000 ) #define ERRFILE_aoe ( ERRFILE_NET | 0x00000000 ) #define ERRFILE_arp ( ERRFILE_NET | 0x00010000 ) @@ -265,8 +255,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #define ERRFILE_peerdisc ( ERRFILE_NET | 0x00450000 ) #define ERRFILE_peerblk ( ERRFILE_NET | 0x00460000 ) #define ERRFILE_peermux ( ERRFILE_NET | 0x00470000 ) -#define ERRFILE_xsigo ( ERRFILE_NET | 0x00480000 ) -#define ERRFILE_ntp ( ERRFILE_NET | 0x00490000 ) #define ERRFILE_image ( ERRFILE_IMAGE | 0x00000000 ) #define ERRFILE_elf ( ERRFILE_IMAGE | 0x00010000 ) @@ -351,11 +339,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #define ERRFILE_vmbus ( ERRFILE_OTHER | 0x00470000 ) #define ERRFILE_efi_time ( ERRFILE_OTHER | 0x00480000 ) #define ERRFILE_efi_watchdog ( ERRFILE_OTHER | 0x00490000 ) -#define ERRFILE_efi_pxe ( ERRFILE_OTHER | 0x004a0000 ) -#define ERRFILE_efi_usb ( ERRFILE_OTHER | 0x004b0000 ) -#define ERRFILE_efi_fbcon ( ERRFILE_OTHER | 0x004c0000 ) -#define ERRFILE_efi_local ( ERRFILE_OTHER | 0x004d0000 ) -#define ERRFILE_efi_entropy ( ERRFILE_OTHER | 0x004e0000 ) /** @} */ diff --git a/roms/ipxe/src/include/ipxe/fbcon.h b/roms/ipxe/src/include/ipxe/fbcon.h index 42ffca3d7..d442bb918 100644 --- a/roms/ipxe/src/include/ipxe/fbcon.h +++ b/roms/ipxe/src/include/ipxe/fbcon.h @@ -12,11 +12,15 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <stdint.h> #include <ipxe/ansiesc.h> #include <ipxe/uaccess.h> -#include <ipxe/console.h> + +struct pixel_buffer; /** Character width, in pixels */ #define FBCON_CHAR_WIDTH 9 +/** Character height, in pixels */ +#define FBCON_CHAR_HEIGHT 16 + /** Bold colour modifier (RGB value) */ #define FBCON_BOLD 0x555555 @@ -26,21 +30,14 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); /** A font glyph */ struct fbcon_font_glyph { /** Row bitmask */ - uint8_t bitmask[0]; -}; + uint8_t bitmask[FBCON_CHAR_HEIGHT]; +} __attribute__ (( packed )); /** A font definition */ struct fbcon_font { - /** Character height (in pixels) */ - unsigned int height; - /** - * Get character glyph - * - * @v character Character - * @v glyph Character glyph to fill in - */ - void ( * glyph ) ( unsigned int character, uint8_t *glyph ); -}; + /** Character glyphs */ + userptr_t start; +} __attribute__ (( packed )); /** A frame buffer geometry * @@ -148,9 +145,10 @@ struct fbcon { extern int fbcon_init ( struct fbcon *fbcon, userptr_t start, struct fbcon_geometry *pixel, + struct fbcon_margin *margin, struct fbcon_colour_map *map, struct fbcon_font *font, - struct console_configuration *config ); + struct pixel_buffer *pixbuf ); extern void fbcon_fini ( struct fbcon *fbcon ); extern void fbcon_putchar ( struct fbcon *fbcon, int character ); diff --git a/roms/ipxe/src/include/ipxe/ib_cmrc.h b/roms/ipxe/src/include/ipxe/ib_cmrc.h index f3276e6ef..47ad27fa6 100644 --- a/roms/ipxe/src/include/ipxe/ib_cmrc.h +++ b/roms/ipxe/src/include/ipxe/ib_cmrc.h @@ -12,8 +12,9 @@ FILE_LICENCE ( BSD2 ); #include <ipxe/infiniband.h> #include <ipxe/xfer.h> -extern int ib_cmrc_open ( struct interface *xfer, struct ib_device *ibdev, - union ib_gid *dgid, union ib_guid *service_id, - const char *name ); +extern int ib_cmrc_open ( struct interface *xfer, + struct ib_device *ibdev, + union ib_gid *dgid, + union ib_guid *service_id ); #endif /* _IPXE_IB_CMRC_H */ diff --git a/roms/ipxe/src/include/ipxe/ib_mad.h b/roms/ipxe/src/include/ipxe/ib_mad.h index 134274026..ae1eea7e4 100644 --- a/roms/ipxe/src/include/ipxe/ib_mad.h +++ b/roms/ipxe/src/include/ipxe/ib_mad.h @@ -144,9 +144,6 @@ struct ib_port_info { #define IB_LINK_SPEED_SDR 0x01 #define IB_LINK_SPEED_DDR 0x02 #define IB_LINK_SPEED_QDR 0x04 -#define IB_LINK_SPEED_FDR10 0x08 -#define IB_LINK_SPEED_FDR 0x10 -#define IB_LINK_SPEED_EDR 0x20 #define IB_PORT_STATE_DOWN 0x01 #define IB_PORT_STATE_INIT 0x02 @@ -219,25 +216,8 @@ struct ib_sa_hdr { uint32_t comp_mask[2]; } __attribute__ (( packed )); -#define IB_SA_ATTR_SERVICE_REC 0x31 -#define IB_SA_ATTR_PATH_REC 0x35 #define IB_SA_ATTR_MC_MEMBER_REC 0x38 - -struct ib_service_record { - uint64_t id; - union ib_gid gid; - uint16_t pkey; - uint16_t reserved; - uint32_t lease; - uint8_t key[16]; - char name[64]; - uint8_t data8[16]; - uint16_t data16[8]; - uint32_t data32[4]; - uint64_t data64[2]; -} __attribute__ (( packed )); - -#define IB_SA_SERVICE_REC_NAME (1<<6) +#define IB_SA_ATTR_PATH_REC 0x35 struct ib_path_record { uint32_t reserved0[2]; @@ -295,7 +275,6 @@ struct ib_mc_member_record { #define IB_SA_MCMEMBER_REC_PROXY_JOIN (1<<17) union ib_sa_data { - struct ib_service_record service_record; struct ib_path_record path_record; struct ib_mc_member_record mc_member_record; } __attribute__ (( packed )); @@ -525,12 +504,6 @@ union ib_mad_class_specific { struct ib_smp_class_specific smp; } __attribute__ (( packed )); -/** A management datagram transaction identifier */ -struct ib_mad_tid { - uint32_t high; - uint32_t low; -} __attribute__ (( packed )); - /** A management datagram common header * * Defined in section 13.4.2 of the IBA. @@ -542,7 +515,7 @@ struct ib_mad_hdr { uint8_t method; uint16_t status; union ib_mad_class_specific class_specific; - struct ib_mad_tid tid; + uint32_t tid[2]; uint16_t attr_id; uint8_t reserved[2]; uint32_t attr_mod; diff --git a/roms/ipxe/src/include/ipxe/ib_mcast.h b/roms/ipxe/src/include/ipxe/ib_mcast.h index df348bd9b..564066975 100644 --- a/roms/ipxe/src/include/ipxe/ib_mcast.h +++ b/roms/ipxe/src/include/ipxe/ib_mcast.h @@ -17,25 +17,30 @@ struct ib_mad_transaction; struct ib_mc_membership { /** Queue pair */ struct ib_queue_pair *qp; - /** Address vector */ - struct ib_address_vector *av; - /** Attached to multicast GID */ - int attached; + /** Multicast GID */ + union ib_gid gid; /** Multicast group join transaction */ struct ib_mad_transaction *madx; /** Handle join success/failure * + * @v ibdev Infiniband device + * @v qp Queue pair * @v membership Multicast group membership * @v rc Status code + * @v mad Response MAD (or NULL on error) */ - void ( * complete ) ( struct ib_mc_membership *membership, int rc ); + void ( * complete ) ( struct ib_device *ibdev, struct ib_queue_pair *qp, + struct ib_mc_membership *membership, int rc, + union ib_mad *mad ); }; extern int ib_mcast_join ( struct ib_device *ibdev, struct ib_queue_pair *qp, struct ib_mc_membership *membership, - struct ib_address_vector *av, unsigned int mask, - void ( * joined ) ( struct ib_mc_membership *memb, - int rc ) ); + union ib_gid *gid, + void ( * joined ) ( struct ib_device *ibdev, + struct ib_queue_pair *qp, + struct ib_mc_membership *memb, + int rc, union ib_mad *mad ) ); extern void ib_mcast_leave ( struct ib_device *ibdev, struct ib_queue_pair *qp, struct ib_mc_membership *membership ); diff --git a/roms/ipxe/src/include/ipxe/ib_packet.h b/roms/ipxe/src/include/ipxe/ib_packet.h index 747f96399..f275fcb09 100644 --- a/roms/ipxe/src/include/ipxe/ib_packet.h +++ b/roms/ipxe/src/include/ipxe/ib_packet.h @@ -19,7 +19,6 @@ union ib_guid { uint8_t bytes[8]; uint16_t words[4]; uint32_t dwords[2]; - uint64_t qword; }; /** Infiniband Globally Unique Identifier debug message format */ @@ -34,7 +33,6 @@ union ib_gid { uint8_t bytes[16]; uint16_t words[8]; uint32_t dwords[4]; - uint64_t qwords[2]; struct { union ib_guid prefix; union ib_guid guid; @@ -48,9 +46,6 @@ union ib_gid { #define IB_GID_ARGS( gid ) \ IB_GUID_ARGS ( &(gid)->s.prefix ), IB_GUID_ARGS ( &(gid)->s.guid ) -/** Test for multicast GID */ -#define IB_GID_MULTICAST( gid ) ( (gid)->bytes[0] == 0xff ) - /** An Infiniband Local Route Header */ struct ib_local_route_header { /** Virtual lane and link version */ diff --git a/roms/ipxe/src/include/ipxe/ib_service.h b/roms/ipxe/src/include/ipxe/ib_service.h deleted file mode 100644 index 88afe4e65..000000000 --- a/roms/ipxe/src/include/ipxe/ib_service.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef _IPXE_IB_SERVICE_H -#define _IPXE_IB_SERVICE_H - -/** @file - * - * Infiniband service records - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#include <ipxe/infiniband.h> -#include <ipxe/ib_mi.h> - -extern struct ib_mad_transaction * -ib_create_service_madx ( struct ib_device *ibdev, - struct ib_mad_interface *mi, const char *name, - struct ib_mad_transaction_operations *op ); - -#endif /* _IPXE_IB_SERVICE_H */ diff --git a/roms/ipxe/src/include/ipxe/if_arp.h b/roms/ipxe/src/include/ipxe/if_arp.h index 9d7b03fe8..4eb1f80b7 100644 --- a/roms/ipxe/src/include/ipxe/if_arp.h +++ b/roms/ipxe/src/include/ipxe/if_arp.h @@ -99,14 +99,4 @@ static inline void * arp_target_pa ( struct arphdr *arphdr ) { return ( arp_target_ha ( arphdr ) + arphdr->ar_hln ); } -/** ARP packet length - * - * @v arphdr ARP header - * @ret len Length (including header) - */ -static inline size_t arp_len ( struct arphdr *arphdr ) { - return ( sizeof ( *arphdr ) + - ( 2 * ( arphdr->ar_hln + arphdr->ar_pln ) ) ); -} - #endif /* _IPXE_IF_ARP_H */ diff --git a/roms/ipxe/src/include/ipxe/image.h b/roms/ipxe/src/include/ipxe/image.h index f33feddad..6abd7a2d2 100644 --- a/roms/ipxe/src/include/ipxe/image.h +++ b/roms/ipxe/src/include/ipxe/image.h @@ -158,7 +158,6 @@ static inline struct image * first_image ( void ) { } extern struct image * alloc_image ( struct uri *uri ); -extern int image_set_uri ( struct image *image, struct uri *uri ); extern int image_set_name ( struct image *image, const char *name ); extern int image_set_cmdline ( struct image *image, const char *cmdline ); extern int register_image ( struct image *image ); diff --git a/roms/ipxe/src/include/ipxe/infiniband.h b/roms/ipxe/src/include/ipxe/infiniband.h index d7ecd1623..87cfe5082 100644 --- a/roms/ipxe/src/include/ipxe/infiniband.h +++ b/roms/ipxe/src/include/ipxe/infiniband.h @@ -15,7 +15,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <ipxe/tables.h> #include <ipxe/ib_packet.h> #include <ipxe/ib_mad.h> -#include <ipxe/if_ether.h> /** Subnet management interface QPN */ #define IB_QPN_SMI 0 @@ -159,8 +158,6 @@ struct ib_queue_pair { struct ib_device *ibdev; /** List of queue pairs on this Infiniband device */ struct list_head list; - /** Queue pair name */ - const char *name; /** Queue pair number */ unsigned long qpn; /** Externally-visible queue pair number @@ -391,9 +388,6 @@ struct ib_device_operations { union ib_mad *mad ); }; -/** Maximum length of an Infiniband device name */ -#define IBDEV_NAME_LEN 8 - /** An Infiniband device */ struct ib_device { /** Reference counter */ @@ -402,10 +396,6 @@ struct ib_device { struct list_head list; /** List of open Infiniband devices */ struct list_head open_list; - /** Index of this Infiniband device */ - unsigned int index; - /** Name of this Infiniband device */ - char name[IBDEV_NAME_LEN]; /** Underlying device */ struct device *dev; /** List of completion queues */ @@ -458,11 +448,10 @@ struct ib_device { /** General services interface */ struct ib_mad_interface *gsi; - /** IPoIB LEMAC (if non-default) */ - uint8_t lemac[ETH_ALEN]; - /** Driver private data */ void *drv_priv; + /** Owner private data */ + void *owner_priv; }; /** An Infiniband upper-layer driver */ @@ -504,7 +493,7 @@ extern struct ib_queue_pair * ib_create_qp ( struct ib_device *ibdev, enum ib_queue_pair_type type, unsigned int num_send_wqes, struct ib_completion_queue *send_cq, unsigned int num_recv_wqes, struct ib_completion_queue *recv_cq, - struct ib_queue_pair_operations *op, const char *name ); + struct ib_queue_pair_operations *op ); extern int ib_modify_qp ( struct ib_device *ibdev, struct ib_queue_pair *qp ); extern void ib_destroy_qp ( struct ib_device *ibdev, struct ib_queue_pair *qp ); @@ -706,4 +695,26 @@ ib_get_drvdata ( struct ib_device *ibdev ) { return ibdev->drv_priv; } +/** + * Set Infiniband device owner-private data + * + * @v ibdev Infiniband device + * @v priv Private data + */ +static inline __always_inline void +ib_set_ownerdata ( struct ib_device *ibdev, void *priv ) { + ibdev->owner_priv = priv; +} + +/** + * Get Infiniband device owner-private data + * + * @v ibdev Infiniband device + * @ret priv Private data + */ +static inline __always_inline void * +ib_get_ownerdata ( struct ib_device *ibdev ) { + return ibdev->owner_priv; +} + #endif /* _IPXE_INFINIBAND_H */ diff --git a/roms/ipxe/src/include/ipxe/io.h b/roms/ipxe/src/include/ipxe/io.h index fe1388191..af767915d 100644 --- a/roms/ipxe/src/include/ipxe/io.h +++ b/roms/ipxe/src/include/ipxe/io.h @@ -20,8 +20,8 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <stdint.h> #include <ipxe/api.h> -#include <ipxe/iomap.h> #include <config/ioapi.h> +#include <ipxe/uaccess.h> /** Page size */ #define PAGE_SIZE ( 1 << PAGE_SHIFT ) @@ -197,6 +197,30 @@ static inline __always_inline void * bus_to_virt ( unsigned long bus_addr ) { } /** + * Map bus address as an I/O address + * + * @v bus_addr Bus address + * @v len Length of region + * @ret io_addr I/O address + */ +void * ioremap ( unsigned long bus_addr, size_t len ); + +/** + * Unmap I/O address + * + * @v io_addr I/O address + */ +void iounmap ( volatile const void *io_addr ); + +/** + * Convert I/O address to bus address (for debug only) + * + * @v io_addr I/O address + * @ret bus_addr Bus address + */ +unsigned long io_to_bus ( volatile const void *io_addr ); + +/** * Read byte from memory-mapped device * * @v io_addr I/O address diff --git a/roms/ipxe/src/include/ipxe/iomap.h b/roms/ipxe/src/include/ipxe/iomap.h deleted file mode 100644 index b8ded38ef..000000000 --- a/roms/ipxe/src/include/ipxe/iomap.h +++ /dev/null @@ -1,78 +0,0 @@ -#ifndef _IPXE_IOMAP_H -#define _IPXE_IOMAP_H - -/** @file - * - * iPXE I/O mapping API - * - * The I/O mapping API provides methods for mapping and unmapping I/O - * devices. - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#include <stdint.h> -#include <ipxe/api.h> -#include <config/ioapi.h> -#include <ipxe/uaccess.h> - -/** - * Calculate static inline I/O mapping API function name - * - * @v _prefix Subsystem prefix - * @v _api_func API function - * @ret _subsys_func Subsystem API function - */ -#define IOMAP_INLINE( _subsys, _api_func ) \ - SINGLE_API_INLINE ( IOMAP_PREFIX_ ## _subsys, _api_func ) - -/** - * Provide an I/O mapping API implementation - * - * @v _prefix Subsystem prefix - * @v _api_func API function - * @v _func Implementing function - */ -#define PROVIDE_IOMAP( _subsys, _api_func, _func ) \ - PROVIDE_SINGLE_API ( IOMAP_PREFIX_ ## _subsys, _api_func, _func ) - -/** - * Provide a static inline I/O mapping API implementation - * - * @v _prefix Subsystem prefix - * @v _api_func API function - */ -#define PROVIDE_IOMAP_INLINE( _subsys, _api_func ) \ - PROVIDE_SINGLE_API_INLINE ( IOMAP_PREFIX_ ## _subsys, _api_func ) - -/* Include all architecture-independent I/O API headers */ -#include <ipxe/iomap_virt.h> - -/* Include all architecture-dependent I/O API headers */ -#include <bits/iomap.h> - -/** - * Map bus address as an I/O address - * - * @v bus_addr Bus address - * @v len Length of region - * @ret io_addr I/O address - */ -void * ioremap ( unsigned long bus_addr, size_t len ); - -/** - * Unmap I/O address - * - * @v io_addr I/O address - */ -void iounmap ( volatile const void *io_addr ); - -/** - * Convert I/O address to bus address (for debug only) - * - * @v io_addr I/O address - * @ret bus_addr Bus address - */ -unsigned long io_to_bus ( volatile const void *io_addr ); - -#endif /* _IPXE_IOMAP_H */ diff --git a/roms/ipxe/src/include/ipxe/iomap_virt.h b/roms/ipxe/src/include/ipxe/iomap_virt.h deleted file mode 100644 index 4962b7c37..000000000 --- a/roms/ipxe/src/include/ipxe/iomap_virt.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef _IPXE_IOMAP_VIRT_H -#define _IPXE_IOMAP_VIRT_H - -/** @file - * - * iPXE I/O mapping API using phys_to_virt() - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#ifdef IOMAP_VIRT -#define IOMAP_PREFIX_virt -#else -#define IOMAP_PREFIX_virt __virt_ -#endif - -static inline __always_inline void * -IOMAP_INLINE ( virt, ioremap ) ( unsigned long bus_addr, size_t len __unused ) { - return ( bus_addr ? phys_to_virt ( bus_addr ) : NULL ); -} - -static inline __always_inline void -IOMAP_INLINE ( virt, iounmap ) ( volatile const void *io_addr __unused ) { - /* Nothing to do */ -} - -static inline __always_inline unsigned long -IOMAP_INLINE ( virt, io_to_bus ) ( volatile const void *io_addr ) { - return virt_to_phys ( io_addr ); -} - -#endif /* _IPXE_IOMAP_VIRT_H */ diff --git a/roms/ipxe/src/include/ipxe/ipoib.h b/roms/ipxe/src/include/ipxe/ipoib.h index 065eeabb7..b34dd32d0 100644 --- a/roms/ipxe/src/include/ipxe/ipoib.h +++ b/roms/ipxe/src/include/ipxe/ipoib.h @@ -62,6 +62,5 @@ struct ipoib_remac { extern const char * ipoib_ntoa ( const void *ll_addr ); extern struct net_device * alloc_ipoibdev ( size_t priv_size ); -extern struct net_device * ipoib_netdev ( struct ib_device *ibdev ); #endif /* _IPXE_IPOIB_H */ diff --git a/roms/ipxe/src/include/ipxe/linux_compat.h b/roms/ipxe/src/include/ipxe/linux_compat.h new file mode 100644 index 000000000..4704c4817 --- /dev/null +++ b/roms/ipxe/src/include/ipxe/linux_compat.h @@ -0,0 +1,27 @@ +#ifndef _IPXE_LINUX_COMPAT_H +#define _IPXE_LINUX_COMPAT_H + +/** @file + * + * Linux code compatibility + * + * This file exists to ease the building of Linux source code within + * iPXE. This is intended to facilitate quick testing; it is not + * intended to be a substitute for proper porting. + */ + +FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); + +#include <stdint.h> +#include <errno.h> +#include <stdio.h> +#include <byteswap.h> +#include <ipxe/bitops.h> + +#define __init +#define __exit +#define __initdata +#define __exitdata +#define printk printf + +#endif /* _IPXE_LINUX_COMPAT_H */ diff --git a/roms/ipxe/src/include/ipxe/ntp.h b/roms/ipxe/src/include/ipxe/ntp.h deleted file mode 100644 index f5b3d2326..000000000 --- a/roms/ipxe/src/include/ipxe/ntp.h +++ /dev/null @@ -1,109 +0,0 @@ -#ifndef _IPXE_NTP_H -#define _IPXE_NTP_H - -/** @file - * - * Network Time Protocol - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#include <stdint.h> -#include <ipxe/in.h> -#include <ipxe/interface.h> - -/** NTP port */ -#define NTP_PORT 123 - -/** An NTP short-format timestamp */ -struct ntp_short { - /** Seconds */ - uint16_t seconds; - /** Fraction of a second */ - uint16_t fraction; -} __attribute__ (( packed )); - -/** An NTP timestamp */ -struct ntp_timestamp { - /** Seconds */ - uint32_t seconds; - /** Fraction of a second */ - uint32_t fraction; -} __attribute__ (( packed )); - -/** An NTP reference identifier */ -union ntp_id { - /** Textual identifier */ - char text[4]; - /** IPv4 address */ - struct in_addr in; - /** Opaque integer */ - uint32_t opaque; -}; - -/** An NTP header */ -struct ntp_header { - /** Flags */ - uint8_t flags; - /** Stratum */ - uint8_t stratum; - /** Polling rate */ - int8_t poll; - /** Precision */ - int8_t precision; - /** Root delay */ - struct ntp_short delay; - /** Root dispersion */ - struct ntp_short dispersion; - /** Reference clock identifier */ - union ntp_id id; - /** Reference timestamp */ - struct ntp_timestamp reference; - /** Originate timestamp */ - struct ntp_timestamp originate; - /** Receive timestamp */ - struct ntp_timestamp receive; - /** Transmit timestamp */ - struct ntp_timestamp transmit; -} __attribute__ (( packed )); - -/** Leap second indicator: unknown */ -#define NTP_FL_LI_UNKNOWN 0xc0 - -/** NTP version: 1 */ -#define NTP_FL_VN_1 0x20 - -/** NTP mode: client */ -#define NTP_FL_MODE_CLIENT 0x03 - -/** NTP mode: server */ -#define NTP_FL_MODE_SERVER 0x04 - -/** NTP mode mask */ -#define NTP_FL_MODE_MASK 0x07 - -/** NTP timestamp for start of Unix epoch */ -#define NTP_EPOCH 2208988800UL - -/** NTP fraction of a second magic value - * - * This is a policy decision. - */ -#define NTP_FRACTION_MAGIC 0x69505845UL - -/** NTP minimum retransmission timeout - * - * This is a policy decision. - */ -#define NTP_MIN_TIMEOUT ( 1 * TICKS_PER_SEC ) - -/** NTP maximum retransmission timeout - * - * This is a policy decision. - */ -#define NTP_MAX_TIMEOUT ( 10 * TICKS_PER_SEC ) - -extern int start_ntp ( struct interface *job, const char *hostname ); - -#endif /* _IPXE_NTP_H */ diff --git a/roms/ipxe/src/include/ipxe/pci.h b/roms/ipxe/src/include/ipxe/pci.h index ddd8c8d1e..a841e00ff 100644 --- a/roms/ipxe/src/include/ipxe/pci.h +++ b/roms/ipxe/src/include/ipxe/pci.h @@ -94,7 +94,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #define PCI_CAP_ID_VPD 0x03 /**< Vital product data */ #define PCI_CAP_ID_VNDR 0x09 /**< Vendor-specific */ #define PCI_CAP_ID_EXP 0x10 /**< PCI Express */ -#define PCI_CAP_ID_EA 0x14 /**< Enhanced Allocation */ /** Next capability */ #define PCI_CAP_NEXT 0x01 @@ -105,10 +104,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #define PCI_PM_CTRL_PME_ENABLE 0x0100 /**< PME pin enable */ #define PCI_PM_CTRL_PME_STATUS 0x8000 /**< PME pin status */ -/** PCI Express */ -#define PCI_EXP_DEVCTL 0x08 -#define PCI_EXP_DEVCTL_FLR 0x8000 /**< Function level reset */ - /** Uncorrectable error status */ #define PCI_ERR_UNCOR_STATUS 0x04 @@ -133,9 +128,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); ( ( ( (base) & 0xff ) << 16 ) | ( ( (sub) & 0xff ) << 8 ) | \ ( ( (progif) & 0xff) << 0 ) ) -/** PCI Express function level reset delay (in ms) */ -#define PCI_EXP_FLR_DELAY_MS 100 - /** A PCI device ID list entry */ struct pci_device_id { /** Name */ @@ -195,8 +187,8 @@ struct pci_device { uint32_t class; /** Interrupt number */ uint8_t irq; - /** Segment, bus, device, and function (bus:dev.fn) number */ - uint32_t busdevfn; + /** Bus, device, and function (bus:dev.fn) number */ + uint16_t busdevfn; /** Driver for this device */ struct pci_driver *driver; /** Driver-private data @@ -241,13 +233,11 @@ struct pci_driver { /** Declare a fallback PCI driver */ #define __pci_driver_fallback __table_entry ( PCI_DRIVERS, 02 ) -#define PCI_SEG( busdevfn ) ( ( (busdevfn) >> 16 ) & 0xffff ) #define PCI_BUS( busdevfn ) ( ( (busdevfn) >> 8 ) & 0xff ) #define PCI_SLOT( busdevfn ) ( ( (busdevfn) >> 3 ) & 0x1f ) #define PCI_FUNC( busdevfn ) ( ( (busdevfn) >> 0 ) & 0x07 ) -#define PCI_BUSDEVFN( segment, bus, slot, func ) \ - ( ( (segment) << 16 ) | ( (bus) << 8 ) | \ - ( (slot) << 3 ) | ( (func) << 0 ) ) +#define PCI_BUSDEVFN( bus, slot, func ) \ + ( ( (bus) << 8 ) | ( (slot) << 3 ) | ( (func) << 0 ) ) #define PCI_FIRST_FUNC( busdevfn ) ( (busdevfn) & ~0x07 ) #define PCI_LAST_FUNC( busdevfn ) ( (busdevfn) | 0x07 ) @@ -273,12 +263,12 @@ struct pci_driver { PCI_ID( _vendor, _device, _name, _description, _data ) /** PCI device debug message format */ -#define PCI_FMT "%04x:%02x:%02x.%x" +#define PCI_FMT "PCI %02x:%02x.%x" /** PCI device debug message arguments */ #define PCI_ARGS( pci ) \ - PCI_SEG ( (pci)->busdevfn ), PCI_BUS ( (pci)->busdevfn ), \ - PCI_SLOT ( (pci)->busdevfn ), PCI_FUNC ( (pci)->busdevfn ) + PCI_BUS ( (pci)->busdevfn ), PCI_SLOT ( (pci)->busdevfn ), \ + PCI_FUNC ( (pci)->busdevfn ) extern void adjust_pci_device ( struct pci_device *pci ); extern unsigned long pci_bar_start ( struct pci_device *pci, @@ -289,8 +279,6 @@ extern int pci_find_driver ( struct pci_device *pci ); extern int pci_probe ( struct pci_device *pci ); extern void pci_remove ( struct pci_device *pci ); extern int pci_find_capability ( struct pci_device *pci, int capability ); -extern int pci_find_next_capability ( struct pci_device *pci, - int pos, int capability ); extern unsigned long pci_bar_size ( struct pci_device *pci, unsigned int reg ); /** diff --git a/roms/ipxe/src/include/ipxe/pciea.h b/roms/ipxe/src/include/ipxe/pciea.h deleted file mode 100644 index 941c94ed5..000000000 --- a/roms/ipxe/src/include/ipxe/pciea.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef _IPXE_PCIEA_H -#define _IPXE_PCIEA_H - -/** @file - * - * PCI Enhanced Allocation - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#include <ipxe/pci.h> - -/** Number of entries */ -#define PCIEA_ENTRIES 2 -#define PCIEA_ENTRIES_MASK 0x3f - -/** First entry */ -#define PCIEA_FIRST 4 - -/** Entry descriptor */ -#define PCIEA_DESC 0 - -/** Entry size */ -#define PCIEA_DESC_SIZE(desc) ( ( (desc) >> 0 ) & 0x7 ) - -/** BAR equivalent indicator */ -#define PCIEA_DESC_BEI(desc) ( ( (desc) >> 4 ) & 0xf ) - -/** BAR equivalent indicators */ -enum pciea_bei { - PCIEA_BEI_BAR_0 = 0, /**< Standard BAR 0 */ - PCIEA_BEI_BAR_1 = 1, /**< Standard BAR 1 */ - PCIEA_BEI_BAR_2 = 2, /**< Standard BAR 2 */ - PCIEA_BEI_BAR_3 = 3, /**< Standard BAR 3 */ - PCIEA_BEI_BAR_4 = 4, /**< Standard BAR 4 */ - PCIEA_BEI_BAR_5 = 5, /**< Standard BAR 5 */ - PCIEA_BEI_ROM = 8, /**< Expansion ROM BAR */ - PCIEA_BEI_VF_BAR_0 = 9, /**< Virtual function BAR 0 */ - PCIEA_BEI_VF_BAR_1 = 10, /**< Virtual function BAR 1 */ - PCIEA_BEI_VF_BAR_2 = 11, /**< Virtual function BAR 2 */ - PCIEA_BEI_VF_BAR_3 = 12, /**< Virtual function BAR 3 */ - PCIEA_BEI_VF_BAR_4 = 13, /**< Virtual function BAR 4 */ - PCIEA_BEI_VF_BAR_5 = 14, /**< Virtual function BAR 5 */ -}; - -/** Entry is enabled */ -#define PCIEA_DESC_ENABLED 0x80000000UL - -/** Base address low dword */ -#define PCIEA_LOW_BASE 4 - -/** Limit low dword */ -#define PCIEA_LOW_LIMIT 8 - -/** BAR is 64-bit */ -#define PCIEA_LOW_ATTR_64BIT 0x00000002UL - -/** Low dword attribute bit mask */ -#define PCIEA_LOW_ATTR_MASK 0x00000003UL - -/** Offset to high dwords */ -#define PCIEA_LOW_HIGH 8 - -extern unsigned long pciea_bar_start ( struct pci_device *pci, - unsigned int bei ); -extern unsigned long pciea_bar_size ( struct pci_device *pci, - unsigned int bei ); - -#endif /* _IPXE_PCIEA_H */ diff --git a/roms/ipxe/src/include/ipxe/pool.h b/roms/ipxe/src/include/ipxe/pool.h index 81ff57d75..27066e9b3 100644 --- a/roms/ipxe/src/include/ipxe/pool.h +++ b/roms/ipxe/src/include/ipxe/pool.h @@ -112,7 +112,7 @@ pool_is_reopenable ( struct pooled_connection *pool ) { /* A connection is reopenable if it has been recycled but is * not yet known to be alive. */ - return ( ( pool->flags & POOL_RECYCLED ) && + return ( ( pool->flags & POOL_RECYCLED ) & ( ! ( pool->flags & POOL_ALIVE ) ) ); } diff --git a/roms/ipxe/src/include/ipxe/pseudobit.h b/roms/ipxe/src/include/ipxe/pseudobit.h deleted file mode 100644 index 431b106fa..000000000 --- a/roms/ipxe/src/include/ipxe/pseudobit.h +++ /dev/null @@ -1,249 +0,0 @@ -#ifndef _IPXE_PSEUDOBIT_H -#define _IPXE_PSEUDOBIT_H - -/* - * Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>. - * - * 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 ); - -/** - * @file - * - * Pseudo-bit structures - * - */ - -#include <stdint.h> -#include <byteswap.h> - -/* Endianness selection. - * - * This is a property of the device, not a property of the host CPU. - */ -#ifdef PSEUDOBIT_LITTLE_ENDIAN -#define cpu_to_BIT64 cpu_to_le64 -#define cpu_to_BIT32 cpu_to_le32 -#define BIT64_to_cpu le64_to_cpu -#define BIT32_to_cpu le32_to_cpu -#define QWORD_SHIFT( offset, width ) (offset) -#endif -#ifdef PSEUDOBIT_BIG_ENDIAN -#define cpu_to_BIT64 cpu_to_be64 -#define cpu_to_BIT32 cpu_to_be32 -#define BIT64_to_cpu be64_to_cpu -#define BIT32_to_cpu be32_to_cpu -#define QWORD_SHIFT( offset, width ) ( 64 - (offset) - (width) ) -#endif - -/** Datatype used to represent a bit in the pseudo-structures */ -typedef unsigned char pseudo_bit_t; - -/** - * Wrapper structure for pseudo_bit_t structures - * - * This structure provides a wrapper around pseudo_bit_t structures. - * It has the correct size, and also encapsulates type information - * about the underlying pseudo_bit_t-based structure, which allows the - * BIT_FILL() etc. macros to work without requiring explicit type - * information. - */ -#define PSEUDO_BIT_STRUCT( _structure ) \ - union { \ - uint8_t bytes[ sizeof ( _structure ) / 8 ]; \ - uint32_t dwords[ sizeof ( _structure ) / 32 ]; \ - uint64_t qwords[ sizeof ( _structure ) / 64 ]; \ - _structure *dummy[0]; \ - } __attribute__ (( packed )) u - -/** Get pseudo_bit_t structure type from wrapper structure pointer */ -#define PSEUDO_BIT_STRUCT_TYPE( _ptr ) \ - typeof ( *((_ptr)->u.dummy[0]) ) - -/** Bit offset of a field within a pseudo_bit_t structure */ -#define BIT_OFFSET( _ptr, _field ) \ - offsetof ( PSEUDO_BIT_STRUCT_TYPE ( _ptr ), _field ) - -/** Bit width of a field within a pseudo_bit_t structure */ -#define BIT_WIDTH( _ptr, _field ) \ - sizeof ( ( ( PSEUDO_BIT_STRUCT_TYPE ( _ptr ) * ) NULL )->_field ) - -/** Qword offset of a field within a pseudo_bit_t structure */ -#define QWORD_OFFSET( _ptr, _field ) \ - ( BIT_OFFSET ( _ptr, _field ) / 64 ) - -/** Qword bit offset of a field within a pseudo_bit_t structure */ -#define QWORD_BIT_OFFSET( _ptr, _index, _field ) \ - ( BIT_OFFSET ( _ptr, _field ) - ( 64 * (_index) ) ) - -/** Qword bit shift for a field within a pseudo_bit_t structure */ -#define QWORD_BIT_SHIFT( _ptr, _index, _field ) \ - QWORD_SHIFT ( QWORD_BIT_OFFSET ( _ptr, _index, _field ), \ - BIT_WIDTH ( _ptr, _field ) ) - -/** Bit mask for a field within a pseudo_bit_t structure */ -#define BIT_MASK( _ptr, _field ) \ - ( ( ~( ( uint64_t ) 0 ) ) >> \ - ( 64 - BIT_WIDTH ( _ptr, _field ) ) ) - -/* - * Assemble native-endian qword from named fields and values - * - */ - -#define BIT_ASSEMBLE_1( _ptr, _index, _field, _value ) \ - ( ( ( uint64_t) (_value) ) << \ - QWORD_BIT_SHIFT ( _ptr, _index, _field ) ) - -#define BIT_ASSEMBLE_2( _ptr, _index, _field, _value, ... ) \ - ( BIT_ASSEMBLE_1 ( _ptr, _index, _field, _value ) | \ - BIT_ASSEMBLE_1 ( _ptr, _index, __VA_ARGS__ ) ) - -#define BIT_ASSEMBLE_3( _ptr, _index, _field, _value, ... ) \ - ( BIT_ASSEMBLE_1 ( _ptr, _index, _field, _value ) | \ - BIT_ASSEMBLE_2 ( _ptr, _index, __VA_ARGS__ ) ) - -#define BIT_ASSEMBLE_4( _ptr, _index, _field, _value, ... ) \ - ( BIT_ASSEMBLE_1 ( _ptr, _index, _field, _value ) | \ - BIT_ASSEMBLE_3 ( _ptr, _index, __VA_ARGS__ ) ) - -#define BIT_ASSEMBLE_5( _ptr, _index, _field, _value, ... ) \ - ( BIT_ASSEMBLE_1 ( _ptr, _index, _field, _value ) | \ - BIT_ASSEMBLE_4 ( _ptr, _index, __VA_ARGS__ ) ) - -#define BIT_ASSEMBLE_6( _ptr, _index, _field, _value, ... ) \ - ( BIT_ASSEMBLE_1 ( _ptr, _index, _field, _value ) | \ - BIT_ASSEMBLE_5 ( _ptr, _index, __VA_ARGS__ ) ) - -#define BIT_ASSEMBLE_7( _ptr, _index, _field, _value, ... ) \ - ( BIT_ASSEMBLE_1 ( _ptr, _index, _field, _value ) | \ - BIT_ASSEMBLE_6 ( _ptr, _index, __VA_ARGS__ ) ) - -/* - * Build native-endian (positive) qword bitmasks from named fields - * - */ - -#define BIT_MASK_1( _ptr, _index, _field ) \ - ( BIT_MASK ( _ptr, _field ) << \ - QWORD_BIT_SHIFT ( _ptr, _index, _field ) ) - -#define BIT_MASK_2( _ptr, _index, _field, ... ) \ - ( BIT_MASK_1 ( _ptr, _index, _field ) | \ - BIT_MASK_1 ( _ptr, _index, __VA_ARGS__ ) ) - -#define BIT_MASK_3( _ptr, _index, _field, ... ) \ - ( BIT_MASK_1 ( _ptr, _index, _field ) | \ - BIT_MASK_2 ( _ptr, _index, __VA_ARGS__ ) ) - -#define BIT_MASK_4( _ptr, _index, _field, ... ) \ - ( BIT_MASK_1 ( _ptr, _index, _field ) | \ - BIT_MASK_3 ( _ptr, _index, __VA_ARGS__ ) ) - -#define BIT_MASK_5( _ptr, _index, _field, ... ) \ - ( BIT_MASK_1 ( _ptr, _index, _field ) | \ - BIT_MASK_4 ( _ptr, _index, __VA_ARGS__ ) ) - -#define BIT_MASK_6( _ptr, _index, _field, ... ) \ - ( BIT_MASK_1 ( _ptr, _index, _field ) | \ - BIT_MASK_5 ( _ptr, _index, __VA_ARGS__ ) ) - -#define BIT_MASK_7( _ptr, _index, _field, ... ) \ - ( BIT_MASK_1 ( _ptr, _index, _field ) | \ - BIT_MASK_6 ( _ptr, _index, __VA_ARGS__ ) ) - -/* - * Populate device-endian qwords from named fields and values - * - */ - -#define BIT_FILL( _ptr, _index, _assembled ) do { \ - uint64_t *__ptr = &(_ptr)->u.qwords[(_index)]; \ - uint64_t __assembled = (_assembled); \ - *__ptr = cpu_to_BIT64 ( __assembled ); \ - } while ( 0 ) - -#define BIT_FILL_1( _ptr, _field1, ... ) \ - BIT_FILL ( _ptr, QWORD_OFFSET ( _ptr, _field1 ), \ - BIT_ASSEMBLE_1 ( _ptr, QWORD_OFFSET ( _ptr, _field1 ), \ - _field1, __VA_ARGS__ ) ) - -#define BIT_FILL_2( _ptr, _field1, ... ) \ - BIT_FILL ( _ptr, QWORD_OFFSET ( _ptr, _field1 ), \ - BIT_ASSEMBLE_2 ( _ptr, QWORD_OFFSET ( _ptr, _field1 ), \ - _field1, __VA_ARGS__ ) ) - -#define BIT_FILL_3( _ptr, _field1, ... ) \ - BIT_FILL ( _ptr, QWORD_OFFSET ( _ptr, _field1 ), \ - BIT_ASSEMBLE_3 ( _ptr, QWORD_OFFSET ( _ptr, _field1 ), \ - _field1, __VA_ARGS__ ) ) - -#define BIT_FILL_4( _ptr, _field1, ... ) \ - BIT_FILL ( _ptr, QWORD_OFFSET ( _ptr, _field1 ), \ - BIT_ASSEMBLE_4 ( _ptr, QWORD_OFFSET ( _ptr, _field1 ), \ - _field1, __VA_ARGS__ ) ) - -#define BIT_FILL_5( _ptr, _field1, ... ) \ - BIT_FILL ( _ptr, QWORD_OFFSET ( _ptr, _field1 ), \ - BIT_ASSEMBLE_5 ( _ptr, QWORD_OFFSET ( _ptr, _field1 ), \ - _field1, __VA_ARGS__ ) ) - -#define BIT_FILL_6( _ptr, _field1, ... ) \ - BIT_FILL ( _ptr, QWORD_OFFSET ( _ptr, _field1 ), \ - BIT_ASSEMBLE_6 ( _ptr, QWORD_OFFSET ( _ptr, _field1 ), \ - _field1, __VA_ARGS__ ) ) - -#define BIT_QWORD_PTR( _ptr, _field ) \ - ( { \ - unsigned int __index = QWORD_OFFSET ( _ptr, _field ); \ - uint64_t *__ptr = &(_ptr)->u.qwords[__index]; \ - __ptr; \ - } ) - -/** Extract value of named field */ -#define BIT_GET64( _ptr, _field ) \ - ( { \ - unsigned int __index = QWORD_OFFSET ( _ptr, _field ); \ - uint64_t *__ptr = &(_ptr)->u.qwords[__index]; \ - uint64_t __value = BIT64_to_cpu ( *__ptr ); \ - __value >>= \ - QWORD_BIT_SHIFT ( _ptr, __index, _field ); \ - __value &= BIT_MASK ( _ptr, _field ); \ - __value; \ - } ) - -/** Extract value of named field (for fields up to the size of a long) */ -#define BIT_GET( _ptr, _field ) \ - ( ( unsigned long ) BIT_GET64 ( _ptr, _field ) ) - -#define BIT_SET( _ptr, _field, _value ) do { \ - unsigned int __index = QWORD_OFFSET ( _ptr, _field ); \ - uint64_t *__ptr = &(_ptr)->u.qwords[__index]; \ - unsigned int __shift = \ - QWORD_BIT_SHIFT ( _ptr, __index, _field ); \ - uint64_t __value = (_value); \ - *__ptr &= cpu_to_BIT64 ( ~( BIT_MASK ( _ptr, _field ) << \ - __shift ) ); \ - *__ptr |= cpu_to_BIT64 ( __value << __shift ); \ - } while ( 0 ) - -#endif /* _IPXE_PSEUDOBIT_H */ diff --git a/roms/ipxe/src/include/ipxe/sanboot.h b/roms/ipxe/src/include/ipxe/sanboot.h index 041e18935..57025f2c6 100644 --- a/roms/ipxe/src/include/ipxe/sanboot.h +++ b/roms/ipxe/src/include/ipxe/sanboot.h @@ -70,7 +70,7 @@ unsigned int san_default_drive ( void ); * * @v uri URI * @v drive Drive number - * @ret drive Drive number, or negative error + * @ret rc Return status code */ int san_hook ( struct uri *uri, unsigned int drive ); diff --git a/roms/ipxe/src/include/ipxe/settings.h b/roms/ipxe/src/include/ipxe/settings.h index 6534c25b6..95a553cc8 100644 --- a/roms/ipxe/src/include/ipxe/settings.h +++ b/roms/ipxe/src/include/ipxe/settings.h @@ -40,7 +40,7 @@ struct setting { * (such as a DHCP option number, or an SMBIOS structure and * field number). */ - unsigned long tag; + unsigned int tag; /** Setting scope (or NULL) * * For historic reasons, a NULL scope with a non-zero tag @@ -452,18 +452,6 @@ extern const struct setting busid_setting __setting ( SETTING_NETDEV, busid ); extern const struct setting user_class_setting __setting ( SETTING_HOST_EXTRA, user-class ); -extern const struct setting -manufacturer_setting __setting ( SETTING_HOST_EXTRA, manufacturer ); -extern const struct setting -product_setting __setting ( SETTING_HOST_EXTRA, product ); -extern const struct setting -serial_setting __setting ( SETTING_HOST_EXTRA, serial ); -extern const struct setting -asset_setting __setting ( SETTING_HOST_EXTRA, asset ); -extern const struct setting -board_serial_setting __setting ( SETTING_HOST_EXTRA, board-serial ); -extern const struct setting dhcp_server_setting __setting ( SETTING_MISC, - dhcp-server ); /** * Initialise a settings block diff --git a/roms/ipxe/src/include/ipxe/smbios.h b/roms/ipxe/src/include/ipxe/smbios.h index c1d8fea3e..24b05ed62 100644 --- a/roms/ipxe/src/include/ipxe/smbios.h +++ b/roms/ipxe/src/include/ipxe/smbios.h @@ -152,9 +152,6 @@ struct smbios_enclosure_information { /** SMBIOS enclosure information structure type */ #define SMBIOS_TYPE_ENCLOSURE_INFORMATION 3 -/** SMBIOS OEM strings structure type */ -#define SMBIOS_TYPE_OEM_STRINGS 11 - /** * SMBIOS entry point descriptor * diff --git a/roms/ipxe/src/include/ipxe/tcp.h b/roms/ipxe/src/include/ipxe/tcp.h index 21be3ca8a..063ebaa4b 100644 --- a/roms/ipxe/src/include/ipxe/tcp.h +++ b/roms/ipxe/src/include/ipxe/tcp.h @@ -140,6 +140,8 @@ struct tcp_timestamp_padded_option { /** Parsed TCP options */ struct tcp_options { + /** MSS option, if present */ + const struct tcp_mss_option *mssopt; /** Window scale option, if present */ const struct tcp_window_scale_option *wsopt; /** SACK permitted option, if present */ @@ -379,14 +381,6 @@ struct tcp_options { #define TCP_MSL ( 2 * 60 * TICKS_PER_SEC ) /** - * TCP keepalive period - * - * We send keepalive ACKs after this period of inactivity has elapsed - * on an established connection. - */ -#define TCP_KEEPALIVE_DELAY ( 15 * TICKS_PER_SEC ) - -/** * TCP maximum header length * */ diff --git a/roms/ipxe/src/include/ipxe/tcpip.h b/roms/ipxe/src/include/ipxe/tcpip.h index 414daad53..3cfc8e3ac 100644 --- a/roms/ipxe/src/include/ipxe/tcpip.h +++ b/roms/ipxe/src/include/ipxe/tcpip.h @@ -13,48 +13,17 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <ipxe/socket.h> #include <ipxe/in.h> #include <ipxe/tables.h> - -extern uint16_t generic_tcpip_continue_chksum ( uint16_t partial, - const void *data, size_t len ); - #include <bits/tcpip.h> struct io_buffer; struct net_device; struct ip_statistics; -/** Positive zero checksum value */ -#define TCPIP_POSITIVE_ZERO_CSUM 0x0000 - -/** Negative zero checksum value */ -#define TCPIP_NEGATIVE_ZERO_CSUM 0xffff - /** Empty checksum value * - * All of our TCP/IP checksum algorithms will return only the positive - * representation of zero (0x0000) for a zero checksum over non-zero - * input data. This property arises since the end-around carry used - * to mimic one's complement addition using unsigned arithmetic - * prevents the running total from ever returning to 0x0000. The - * running total will therefore use only the negative representation - * of zero (0xffff). Since the return value is the one's complement - * negation of the running total (calculated by simply bit-inverting - * the running total), the return value will therefore use only the - * positive representation of zero (0x0000). - * - * It is a very common misconception (found in many places such as - * RFC1624) that this is a property guaranteed by the underlying - * mathematics. It is not; the choice of which zero representation is - * used is merely an artifact of the software implementation of the - * checksum algorithm. - * - * For consistency, we choose to use the positive representation of - * zero (0x0000) for the checksum of a zero-length block of data. - * This ensures that all of our TCP/IP checksum algorithms will return - * only the positive representation of zero (0x0000) for a zero - * checksum (regardless of the input data). + * This is the TCP/IP checksum over a zero-length block of data. */ -#define TCPIP_EMPTY_CSUM TCPIP_POSITIVE_ZERO_CSUM +#define TCPIP_EMPTY_CSUM 0xffff /** TCP/IP address flags */ enum tcpip_st_flags { @@ -119,13 +88,6 @@ struct tcpip_protocol { int ( * rx ) ( struct io_buffer *iobuf, struct net_device *netdev, struct sockaddr_tcpip *st_src, struct sockaddr_tcpip *st_dest, uint16_t pshdr_csum ); - /** Preferred zero checksum value - * - * The checksum is a one's complement value: zero may be - * represented by either positive zero (0x0000) or negative - * zero (0xffff). - */ - uint16_t zero_csum; /** * Transport-layer protocol number * @@ -144,8 +106,6 @@ struct tcpip_net_protocol { sa_family_t sa_family; /** Fixed header length */ size_t header_len; - /** Network-layer protocol */ - struct net_protocol *net_protocol; /** * Transmit packet * @@ -196,11 +156,19 @@ extern int tcpip_tx ( struct io_buffer *iobuf, struct tcpip_protocol *tcpip, struct sockaddr_tcpip *st_dest, struct net_device *netdev, uint16_t *trans_csum ); -extern struct tcpip_net_protocol * tcpip_net_protocol ( sa_family_t sa_family ); extern struct net_device * tcpip_netdev ( struct sockaddr_tcpip *st_dest ); extern size_t tcpip_mtu ( struct sockaddr_tcpip *st_dest ); +extern uint16_t generic_tcpip_continue_chksum ( uint16_t partial, + const void *data, size_t len ); extern uint16_t tcpip_chksum ( const void *data, size_t len ); extern int tcpip_bind ( struct sockaddr_tcpip *st_local, int ( * available ) ( int port ) ); +/* Use generic_tcpip_continue_chksum() if no architecture-specific + * version is available + */ +#ifndef tcpip_continue_chksum +#define tcpip_continue_chksum generic_tcpip_continue_chksum +#endif + #endif /* _IPXE_TCPIP_H */ diff --git a/roms/ipxe/src/include/ipxe/time.h b/roms/ipxe/src/include/ipxe/time.h index 89bf90e03..4c5bb2a00 100644 --- a/roms/ipxe/src/include/ipxe/time.h +++ b/roms/ipxe/src/include/ipxe/time.h @@ -50,24 +50,11 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); /* Include all architecture-dependent time API headers */ #include <bits/time.h> -extern signed long time_offset; - /** - * Get current time in seconds (ignoring system clock offset) + * Get current time in seconds * * @ret time Time, in seconds */ time_t time_now ( void ); -/** - * Adjust system clock - * - * @v delta Clock adjustment, in seconds - */ -static inline __attribute__ (( always_inline )) void -time_adjust ( signed long delta ) { - - time_offset += delta; -} - #endif /* _IPXE_TIME_H */ diff --git a/roms/ipxe/src/include/ipxe/uri.h b/roms/ipxe/src/include/ipxe/uri.h index 3879a0e73..00e5a24c4 100644 --- a/roms/ipxe/src/include/ipxe/uri.h +++ b/roms/ipxe/src/include/ipxe/uri.h @@ -191,11 +191,8 @@ uri_put ( struct uri *uri ) { extern struct uri *cwuri; -extern size_t uri_decode ( const char *encoded, void *buf, size_t len ); -extern size_t uri_encode ( unsigned int field, const void *raw, size_t raw_len, +extern size_t uri_encode ( const char *string, unsigned int field, char *buf, ssize_t len ); -extern size_t uri_encode_string ( unsigned int field, const char *string, - char *buf, ssize_t len ); extern struct uri * parse_uri ( const char *uri_string ); extern size_t format_uri ( const struct uri *uri, char *buf, size_t len ); extern char * format_uri_alloc ( const struct uri *uri ); @@ -206,8 +203,8 @@ extern char * resolve_path ( const char *base_path, const char *relative_path ); extern struct uri * resolve_uri ( const struct uri *base_uri, struct uri *relative_uri ); -extern struct uri * pxe_uri ( struct sockaddr *sa_server, - const char *filename ); +extern struct uri * tftp_uri ( struct in_addr next_server, unsigned int port, + const char *filename ); extern void churi ( struct uri *uri ); #endif /* _IPXE_URI_H */ diff --git a/roms/ipxe/src/include/ipxe/usb.h b/roms/ipxe/src/include/ipxe/usb.h index e7909d300..ab060b8f4 100644 --- a/roms/ipxe/src/include/ipxe/usb.h +++ b/roms/ipxe/src/include/ipxe/usb.h @@ -68,7 +68,7 @@ enum usb_pid { struct usb_setup_packet { /** Request */ uint16_t request; - /** Value parameter */ + /** Value paramer */ uint16_t value; /** Index parameter */ uint16_t index; @@ -91,9 +91,6 @@ struct usb_setup_packet { /** Vendor-specific request type */ #define USB_TYPE_VENDOR ( 2 << 5 ) -/** Request recipient mask */ -#define USB_RECIP_MASK ( 0x1f << 0 ) - /** Request recipient is the device */ #define USB_RECIP_DEVICE ( 0 << 0 ) @@ -414,9 +411,7 @@ struct usb_endpoint { /** Recycled I/O buffer list */ struct list_head recycled; - /** Refill buffer reserved header length */ - size_t reserve; - /** Refill buffer payload length */ + /** Refill buffer length */ size_t len; /** Maximum fill level */ unsigned int max; @@ -460,11 +455,11 @@ struct usb_endpoint_host_operations { * * @v ep USB endpoint * @v iobuf I/O buffer - * @v zlp Append a zero-length packet + * @v terminate Terminate using a short packet * @ret rc Return status code */ int ( * stream ) ( struct usb_endpoint *ep, struct io_buffer *iobuf, - int zlp ); + int terminate ); }; /** USB endpoint driver operations */ @@ -590,16 +585,13 @@ extern void usb_complete_err ( struct usb_endpoint *ep, * Initialise USB endpoint refill * * @v ep USB endpoint - * @v reserve Refill buffer reserved header length - * @v len Refill buffer payload length (zero for endpoint's MTU) + * @v len Refill buffer length (or zero to use endpoint's MTU) * @v max Maximum fill level */ static inline __attribute__ (( always_inline )) void -usb_refill_init ( struct usb_endpoint *ep, size_t reserve, size_t len, - unsigned int max ) { +usb_refill_init ( struct usb_endpoint *ep, size_t len, unsigned int max ) { INIT_LIST_HEAD ( &ep->recycled ); - ep->reserve = reserve; ep->len = len; ep->max = max; } @@ -620,31 +612,6 @@ extern int usb_prefill ( struct usb_endpoint *ep ); extern int usb_refill ( struct usb_endpoint *ep ); extern void usb_flush ( struct usb_endpoint *ep ); -/** A USB class descriptor */ -union usb_class_descriptor { - /** Class */ - struct usb_class class; - /** Scalar value */ - uint32_t scalar; -}; - -/** - * A USB function descriptor - * - * This is an internal descriptor used to represent an association of - * interfaces within a USB device. - */ -struct usb_function_descriptor { - /** Vendor ID */ - uint16_t vendor; - /** Product ID */ - uint16_t product; - /** Class */ - union usb_class_descriptor class; - /** Number of interfaces */ - unsigned int count; -}; - /** * A USB function * @@ -656,8 +623,10 @@ struct usb_function { const char *name; /** USB device */ struct usb_device *usb; - /** Function descriptor */ - struct usb_function_descriptor desc; + /** Class */ + struct usb_class class; + /** Number of interfaces */ + unsigned int count; /** Generic device */ struct device dev; /** List of functions within this USB device */ @@ -667,8 +636,6 @@ struct usb_function { struct usb_driver *driver; /** Driver private data */ void *priv; - /** Driver device ID */ - struct usb_device_id *id; /** List of interface numbers * @@ -705,8 +672,6 @@ struct usb_device { char name[32]; /** USB port */ struct usb_port *port; - /** Device speed */ - unsigned int speed; /** List of devices on this bus */ struct list_head list; /** Device address, if assigned */ @@ -1193,7 +1158,7 @@ usb_get_device_descriptor ( struct usb_device *usb, * @v data Configuration descriptor to fill in * @ret rc Return status code */ -static inline __attribute__ (( always_inline )) int +static inline __attribute (( always_inline )) int usb_get_config_descriptor ( struct usb_device *usb, unsigned int index, struct usb_configuration_descriptor *data, size_t len ) { @@ -1315,58 +1280,19 @@ struct usb_device_id { uint16_t vendor; /** Product ID */ uint16_t product; - /** Arbitrary driver data */ - unsigned long driver_data; + /** Class */ + struct usb_class class; }; /** Match-anything ID */ #define USB_ANY_ID 0xffff -/** A USB class ID */ -struct usb_class_id { - /** Class */ - union usb_class_descriptor class; - /** Class mask */ - union usb_class_descriptor mask; -}; - -/** Construct USB class ID - * - * @v base Base class code (or USB_ANY_ID) - * @v subclass Subclass code (or USB_ANY_ID) - * @v protocol Protocol code (or USB_ANY_ID) - */ -#define USB_CLASS_ID( base, subclass, protocol ) { \ - .class = { \ - .class = { \ - ( (base) & 0xff ), \ - ( (subclass) & 0xff ), \ - ( (protocol) & 0xff ), \ - }, \ - }, \ - .mask = { \ - .class = { \ - ( ( (base) == USB_ANY_ID ) ? 0x00 : 0xff ), \ - ( ( (subclass) == USB_ANY_ID ) ? 0x00 : 0xff ), \ - ( ( (protocol) == USB_ANY_ID ) ? 0x00 : 0xff ), \ - }, \ - }, \ - } - /** A USB driver */ struct usb_driver { /** USB ID table */ struct usb_device_id *ids; /** Number of entries in ID table */ unsigned int id_count; - /** Class ID */ - struct usb_class_id class; - /** Driver score - * - * This is used to determine the preferred configuration for a - * USB device. - */ - unsigned int score; /** * Probe device * @@ -1390,18 +1316,4 @@ struct usb_driver { /** Declare a USB driver */ #define __usb_driver __table_entry ( USB_DRIVERS, 01 ) -/** USB driver scores */ -enum usb_driver_score { - /** Fallback driver (has no effect on overall score) */ - USB_SCORE_FALLBACK = 0, - /** Deprecated driver */ - USB_SCORE_DEPRECATED = 1, - /** Normal driver */ - USB_SCORE_NORMAL = 2, -}; - -extern struct usb_driver * -usb_find_driver ( struct usb_function_descriptor *desc, - struct usb_device_id **id ); - #endif /* _IPXE_USB_H */ diff --git a/roms/ipxe/src/include/ipxe/usbhid.h b/roms/ipxe/src/include/ipxe/usbhid.h index 233534e0f..fe9d84455 100644 --- a/roms/ipxe/src/include/ipxe/usbhid.h +++ b/roms/ipxe/src/include/ipxe/usbhid.h @@ -33,20 +33,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); ( USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE | \ USB_REQUEST_TYPE ( 0x0a ) ) -/** Set report */ -#define USBHID_SET_REPORT \ - ( USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE | \ - USB_REQUEST_TYPE ( 0x09 ) ) - -/** Input report type */ -#define USBHID_REPORT_INPUT 0x01 - -/** Output report type */ -#define USBHID_REPORT_OUTPUT 0x02 - -/** Feature report type */ -#define USBHID_REPORT_FEATURE 0x03 - /** A USB human interface device */ struct usb_hid { /** USB function */ @@ -111,26 +97,6 @@ usbhid_set_idle ( struct usb_device *usb, unsigned int interface, interface, NULL, 0 ); } -/** - * Set report - * - * @v usb USB device - * @v interface Interface number - * @v type Report type - * @v report Report ID - * @v data Report data - * @v len Length of report data - * @ret rc Return status code - */ -static inline __attribute__ (( always_inline )) int -usbhid_set_report ( struct usb_device *usb, unsigned int interface, - unsigned int type, unsigned int report, void *data, - size_t len ) { - - return usb_control ( usb, USBHID_SET_REPORT, ( ( type << 8 ) | report ), - interface, data, len ); -} - extern int usbhid_open ( struct usb_hid *hid ); extern void usbhid_close ( struct usb_hid *hid ); extern int usbhid_refill ( struct usb_hid *hid ); diff --git a/roms/ipxe/src/include/ipxe/virtio-pci.h b/roms/ipxe/src/include/ipxe/virtio-pci.h index f3c9b17ca..a09c46316 100644 --- a/roms/ipxe/src/include/ipxe/virtio-pci.h +++ b/roms/ipxe/src/include/ipxe/virtio-pci.h @@ -37,104 +37,6 @@ /* Virtio ABI version, this must match exactly */ #define VIRTIO_PCI_ABI_VERSION 0 -/* PCI capability types: */ -#define VIRTIO_PCI_CAP_COMMON_CFG 1 /* Common configuration */ -#define VIRTIO_PCI_CAP_NOTIFY_CFG 2 /* Notifications */ -#define VIRTIO_PCI_CAP_ISR_CFG 3 /* ISR access */ -#define VIRTIO_PCI_CAP_DEVICE_CFG 4 /* Device specific configuration */ -#define VIRTIO_PCI_CAP_PCI_CFG 5 /* PCI configuration access */ - -#define __u8 uint8_t -#define __le16 uint16_t -#define __le32 uint32_t -#define __le64 uint64_t - -/* This is the PCI capability header: */ -struct virtio_pci_cap { - __u8 cap_vndr; /* Generic PCI field: PCI_CAP_ID_VNDR */ - __u8 cap_next; /* Generic PCI field: next ptr. */ - __u8 cap_len; /* Generic PCI field: capability length */ - __u8 cfg_type; /* Identifies the structure. */ - __u8 bar; /* Where to find it. */ - __u8 padding[3]; /* Pad to full dword. */ - __le32 offset; /* Offset within bar. */ - __le32 length; /* Length of the structure, in bytes. */ -}; - -struct virtio_pci_notify_cap { - struct virtio_pci_cap cap; - __le32 notify_off_multiplier; /* Multiplier for queue_notify_off. */ -}; - -struct virtio_pci_cfg_cap { - struct virtio_pci_cap cap; - __u8 pci_cfg_data[4]; /* Data for BAR access. */ -}; - -/* Fields in VIRTIO_PCI_CAP_COMMON_CFG: */ -struct virtio_pci_common_cfg { - /* About the whole device. */ - __le32 device_feature_select; /* read-write */ - __le32 device_feature; /* read-only */ - __le32 guest_feature_select; /* read-write */ - __le32 guest_feature; /* read-write */ - __le16 msix_config; /* read-write */ - __le16 num_queues; /* read-only */ - __u8 device_status; /* read-write */ - __u8 config_generation; /* read-only */ - - /* About a specific virtqueue. */ - __le16 queue_select; /* read-write */ - __le16 queue_size; /* read-write, power of 2. */ - __le16 queue_msix_vector; /* read-write */ - __le16 queue_enable; /* read-write */ - __le16 queue_notify_off; /* read-only */ - __le32 queue_desc_lo; /* read-write */ - __le32 queue_desc_hi; /* read-write */ - __le32 queue_avail_lo; /* read-write */ - __le32 queue_avail_hi; /* read-write */ - __le32 queue_used_lo; /* read-write */ - __le32 queue_used_hi; /* read-write */ -}; - -/* Virtio 1.0 PCI region descriptor. We support memory mapped I/O, port I/O, - * and PCI config space access via the cfg PCI capability as a fallback. */ -struct virtio_pci_region { - void *base; - size_t length; - u8 bar; - -/* How to interpret the base field */ -#define VIRTIO_PCI_REGION_TYPE_MASK 0x00000003 -/* The base field is a memory address */ -#define VIRTIO_PCI_REGION_MEMORY 0x00000001 -/* The base field is a port address */ -#define VIRTIO_PCI_REGION_PORT 0x00000002 -/* The base field is an offset within the PCI bar */ -#define VIRTIO_PCI_REGION_PCI_CONFIG 0x00000003 - unsigned flags; -}; - -/* Virtio 1.0 device state */ -struct virtio_pci_modern_device { - struct pci_device *pci; - - /* VIRTIO_PCI_CAP_PCI_CFG position */ - int cfg_cap_pos; - - /* VIRTIO_PCI_CAP_COMMON_CFG data */ - struct virtio_pci_region common; - - /* VIRTIO_PCI_CAP_DEVICE_CFG data */ - struct virtio_pci_region device; - - /* VIRTIO_PCI_CAP_ISR_CFG data */ - struct virtio_pci_region isr; - - /* VIRTIO_PCI_CAP_NOTIFY_CFG data */ - int notify_cap_pos; -}; - static inline u32 vp_get_features(unsigned int ioaddr) { return inl(ioaddr + VIRTIO_PCI_HOST_FEATURES); @@ -194,115 +96,6 @@ static inline void vp_del_vq(unsigned int ioaddr, int queue_index) outl(0, ioaddr + VIRTIO_PCI_QUEUE_PFN); } -struct vring_virtqueue; - int vp_find_vq(unsigned int ioaddr, int queue_index, struct vring_virtqueue *vq); - -/* Virtio 1.0 I/O routines abstract away the three possible HW access - * mechanisms - memory, port I/O, and PCI cfg space access. Also built-in - * are endianness conversions - to LE on write and from LE on read. */ - -void vpm_iowrite8(struct virtio_pci_modern_device *vdev, - struct virtio_pci_region *region, u8 data, size_t offset); - -void vpm_iowrite16(struct virtio_pci_modern_device *vdev, - struct virtio_pci_region *region, u16 data, size_t offset); - -void vpm_iowrite32(struct virtio_pci_modern_device *vdev, - struct virtio_pci_region *region, u32 data, size_t offset); - -static inline void vpm_iowrite64(struct virtio_pci_modern_device *vdev, - struct virtio_pci_region *region, - u64 data, size_t offset_lo, size_t offset_hi) -{ - vpm_iowrite32(vdev, region, (u32)data, offset_lo); - vpm_iowrite32(vdev, region, data >> 32, offset_hi); -} - -u8 vpm_ioread8(struct virtio_pci_modern_device *vdev, - struct virtio_pci_region *region, size_t offset); - -u16 vpm_ioread16(struct virtio_pci_modern_device *vdev, - struct virtio_pci_region *region, size_t offset); - -u32 vpm_ioread32(struct virtio_pci_modern_device *vdev, - struct virtio_pci_region *region, size_t offset); - -/* Virtio 1.0 device manipulation routines */ - -#define COMMON_OFFSET(field) offsetof(struct virtio_pci_common_cfg, field) - -static inline void vpm_reset(struct virtio_pci_modern_device *vdev) -{ - vpm_iowrite8(vdev, &vdev->common, 0, COMMON_OFFSET(device_status)); - while (vpm_ioread8(vdev, &vdev->common, COMMON_OFFSET(device_status))) - mdelay(1); -} - -static inline u8 vpm_get_status(struct virtio_pci_modern_device *vdev) -{ - return vpm_ioread8(vdev, &vdev->common, COMMON_OFFSET(device_status)); -} - -static inline void vpm_add_status(struct virtio_pci_modern_device *vdev, - u8 status) -{ - u8 curr_status = vpm_ioread8(vdev, &vdev->common, COMMON_OFFSET(device_status)); - vpm_iowrite8(vdev, &vdev->common, - curr_status | status, COMMON_OFFSET(device_status)); -} - -static inline u64 vpm_get_features(struct virtio_pci_modern_device *vdev) -{ - u32 features_lo, features_hi; - - vpm_iowrite32(vdev, &vdev->common, 0, COMMON_OFFSET(device_feature_select)); - features_lo = vpm_ioread32(vdev, &vdev->common, COMMON_OFFSET(device_feature)); - vpm_iowrite32(vdev, &vdev->common, 1, COMMON_OFFSET(device_feature_select)); - features_hi = vpm_ioread32(vdev, &vdev->common, COMMON_OFFSET(device_feature)); - - return ((u64)features_hi << 32) | features_lo; -} - -static inline void vpm_set_features(struct virtio_pci_modern_device *vdev, - u64 features) -{ - u32 features_lo = (u32)features; - u32 features_hi = features >> 32; - - vpm_iowrite32(vdev, &vdev->common, 0, COMMON_OFFSET(guest_feature_select)); - vpm_iowrite32(vdev, &vdev->common, features_lo, COMMON_OFFSET(guest_feature)); - vpm_iowrite32(vdev, &vdev->common, 1, COMMON_OFFSET(guest_feature_select)); - vpm_iowrite32(vdev, &vdev->common, features_hi, COMMON_OFFSET(guest_feature)); -} - -static inline void vpm_get(struct virtio_pci_modern_device *vdev, - unsigned offset, void *buf, unsigned len) -{ - u8 *ptr = buf; - unsigned i; - - for (i = 0; i < len; i++) - ptr[i] = vpm_ioread8(vdev, &vdev->device, offset + i); -} - -static inline u8 vpm_get_isr(struct virtio_pci_modern_device *vdev) -{ - return vpm_ioread8(vdev, &vdev->isr, 0); -} - -void vpm_notify(struct virtio_pci_modern_device *vdev, - struct vring_virtqueue *vq); - -int vpm_find_vqs(struct virtio_pci_modern_device *vdev, - unsigned nvqs, struct vring_virtqueue *vqs); - -int virtio_pci_find_capability(struct pci_device *pci, uint8_t cfg_type); - -int virtio_pci_map_capability(struct pci_device *pci, int cap, size_t minlen, - u32 align, u32 start, u32 size, - struct virtio_pci_region *region); - -void virtio_pci_unmap_capability(struct virtio_pci_region *region); #endif /* _VIRTIO_PCI_H_ */ diff --git a/roms/ipxe/src/include/ipxe/virtio-ring.h b/roms/ipxe/src/include/ipxe/virtio-ring.h index 6ba550b5a..c687acab7 100644 --- a/roms/ipxe/src/include/ipxe/virtio-ring.h +++ b/roms/ipxe/src/include/ipxe/virtio-ring.h @@ -1,8 +1,6 @@ #ifndef _VIRTIO_RING_H_ # define _VIRTIO_RING_H_ -#include <ipxe/virtio-pci.h> - /* Status byte for guest to report progress, and synchronize features. */ /* We have seen device and processed generic fields (VIRTIO_CONFIG_F_VIRTIO) */ #define VIRTIO_CONFIG_S_ACKNOWLEDGE 1 @@ -10,17 +8,9 @@ #define VIRTIO_CONFIG_S_DRIVER 2 /* Driver has used its parts of the config, and is happy */ #define VIRTIO_CONFIG_S_DRIVER_OK 4 -/* Driver has finished configuring features */ -#define VIRTIO_CONFIG_S_FEATURES_OK 8 /* We've given up on this device. */ #define VIRTIO_CONFIG_S_FAILED 0x80 -/* Virtio feature flags used to negotiate device and driver features. */ -/* Can the device handle any descriptor layout? */ -#define VIRTIO_F_ANY_LAYOUT 27 -/* v1.0 compliant. */ -#define VIRTIO_F_VERSION_1 32 - #define MAX_QUEUE_NUM (256) #define VRING_DESC_F_NEXT 1 @@ -81,7 +71,6 @@ struct vring_virtqueue { void *vdata[MAX_QUEUE_NUM]; /* PCI */ int queue_index; - struct virtio_pci_region notification; }; struct vring_list { @@ -145,7 +134,6 @@ void *vring_get_buf(struct vring_virtqueue *vq, unsigned int *len); void vring_add_buf(struct vring_virtqueue *vq, struct vring_list list[], unsigned int out, unsigned int in, void *index, int num_added); -void vring_kick(struct virtio_pci_modern_device *vdev, unsigned int ioaddr, - struct vring_virtqueue *vq, int num_added); +void vring_kick(unsigned int ioaddr, struct vring_virtqueue *vq, int num_added); #endif /* _VIRTIO_RING_H_ */ diff --git a/roms/ipxe/src/include/ipxe/xen.h b/roms/ipxe/src/include/ipxe/xen.h index 0fb8b7625..eac1145ad 100644 --- a/roms/ipxe/src/include/ipxe/xen.h +++ b/roms/ipxe/src/include/ipxe/xen.h @@ -13,7 +13,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #define __XEN_INTERFACE_VERSION__ 0x00040400 #include <stdint.h> -#include <ipxe/bitops.h> #include <ipxe/uaccess.h> #include <xen/xen.h> #include <xen/event_channel.h> @@ -59,19 +58,6 @@ struct xen_hypervisor { struct xen_store store; }; -/** - * Test and clear pending event - * - * @v xen Xen hypervisor - * @v port Event channel port - * @ret pending Event was pending - */ -static inline __attribute__ (( always_inline )) int -xenevent_pending ( struct xen_hypervisor *xen, evtchn_port_t port ) { - - return test_and_clear_bit ( port, xen->shared->evtchn_pending ); -} - #include <bits/xen.h> /** diff --git a/roms/ipxe/src/include/ipxe/xsigo.h b/roms/ipxe/src/include/ipxe/xsigo.h deleted file mode 100644 index f4f14c487..000000000 --- a/roms/ipxe/src/include/ipxe/xsigo.h +++ /dev/null @@ -1,406 +0,0 @@ -#ifndef _IPXE_XSIGO_H -#define _IPXE_XSIGO_H - -/** @file - * - * Xsigo virtual Ethernet devices - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#include <stdint.h> -#include <ipxe/infiniband.h> -#include <ipxe/eoib.h> - -/** Xsigo directory service record name */ -#define XDS_SERVICE_NAME "XSIGOXDS" - -/** Xsigo configuration manager service ID */ -#define XCM_SERVICE_ID { 0x00, 0x00, 0x00, 0x00, 0x02, 0x13, 0x97, 0x01 } - -/** Xsigo management class */ -#define XSIGO_MGMT_CLASS 0x0b - -/** Xsigo management class version */ -#define XSIGO_MGMT_CLASS_VERSION 2 - -/** Xsigo configuration manager request MAD */ -#define XSIGO_ATTR_XCM_REQUEST 0xb002 - -/** Generic operating system type */ -#define XSIGO_OS_TYPE_GENERIC 0x40 - -/** Xsigo virtual Ethernet broadcast GID prefix */ -#define XVE_PREFIX 0xff15101cUL - -/** Xsigo resource types */ -enum xsigo_resource_type { - /** Virtual Ethernet resource type */ - XSIGO_RESOURCE_XVE = ( 1 << 6 ), - /** Absence-of-high-availability "resource" type */ - XSIGO_RESOURCE_NO_HA = ( 1 << 4 ), -}; - -/** A Xsigo server identifier */ -struct xsigo_server_id { - /** Virtual machine ID */ - uint32_t vm; - /** Port GUID */ - union ib_guid guid; -} __attribute__ (( packed )); - -/** A Xsigo configuration manager identifier */ -struct xsigo_manager_id { - /** Port GUID */ - union ib_guid guid; - /** LID */ - uint16_t lid; - /** Reserved */ - uint8_t reserved[10]; -} __attribute__ (( packed )); - -/** A Xsigo configuration manager request MAD */ -struct xsigo_managers_request { - /** MAD header */ - struct ib_mad_hdr mad_hdr; - /** Reserved */ - uint8_t reserved0[32]; - /** Server ID */ - struct xsigo_server_id server; - /** Hostname */ - char hostname[ 65 /* Seriously, guys? */ ]; - /** OS version */ - char os_version[32]; - /** CPU architecture */ - char arch[16]; - /** OS type */ - uint8_t os_type; - /** Reserved */ - uint8_t reserved1[3]; - /** Firmware version */ - uint64_t firmware_version; - /** Hardware version */ - uint32_t hardware_version; - /** Driver version */ - uint32_t driver_version; - /** System ID */ - union ib_gid system_id; - /** Resource types */ - uint16_t resources; - /** Reserved */ - uint8_t reserved2[2]; - /** Build version */ - char build[16]; - /** Reserved */ - uint8_t reserved3[19]; -} __attribute__ (( packed )); - -/** Resource types are present */ -#define XSIGO_RESOURCES_PRESENT 0x8000 - -/** A Xsigo configuration manager reply MAD */ -struct xsigo_managers_reply { - /** MAD header */ - struct ib_mad_hdr mad_hdr; - /** Reserved */ - uint8_t reserved0[32]; - /** Server ID */ - struct xsigo_server_id server; - /** Number of XCM records */ - uint8_t count; - /** Version */ - uint8_t version; - /** Reserved */ - uint8_t reserved1[2]; - /** Managers */ - struct xsigo_manager_id manager[8]; - /** Reserved */ - uint8_t reserved2[24]; -} __attribute__ (( packed )); - -/** A Xsigo MAD */ -union xsigo_mad { - /** Generic MAD */ - union ib_mad mad; - /** Configuration manager request */ - struct xsigo_managers_request request; - /** Configuration manager reply */ - struct xsigo_managers_reply reply; -} __attribute__ (( packed )); - -/** An XSMP node identifier */ -struct xsmp_node_id { - /** Auxiliary ID (never used) */ - uint32_t aux; - /** Port GUID */ - union ib_guid guid; -} __attribute__ (( packed )); - -/** An XSMP message header */ -struct xsmp_message_header { - /** Message type */ - uint8_t type; - /** Reason code */ - uint8_t code; - /** Length */ - uint16_t len; - /** Sequence number */ - uint32_t seq; - /** Source node ID */ - struct xsmp_node_id src; - /** Destination node ID */ - struct xsmp_node_id dst; -} __attribute__ (( packed )); - -/** XSMP message types */ -enum xsmp_message_type { - /** Session message type */ - XSMP_TYPE_SESSION = 1, - /** Virtual Ethernet message type */ - XSMP_TYPE_XVE = 6, -}; - -/** An XSMP session message */ -struct xsmp_session_message { - /** Message header */ - struct xsmp_message_header hdr; - /** Message type */ - uint8_t type; - /** Reason code */ - uint8_t code; - /** Length (excluding message header) */ - uint16_t len; - /** Operating system type */ - uint8_t os_type; - /** Reserved */ - uint8_t reserved0; - /** Resource types */ - uint16_t resources; - /** Driver version */ - uint32_t driver_version; - /** Required chassis version */ - uint32_t chassis_version; - /** Boot flags */ - uint32_t boot; - /** Firmware version */ - uint64_t firmware_version; - /** Hardware version */ - uint32_t hardware_version; - /** Vendor part ID */ - uint32_t vendor; - /** Protocol version */ - uint32_t xsmp_version; - /** Chassis name */ - char chassis[32]; - /** Session name */ - char session[32]; - /** Reserved */ - uint8_t reserved1[120]; -} __attribute__ (( packed )); - -/** XSMP session message types */ -enum xsmp_session_type { - /** Keepalive message */ - XSMP_SESSION_TYPE_HELLO = 1, - /** Initial registration message */ - XSMP_SESSION_TYPE_REGISTER = 2, - /** Registration confirmation message */ - XSMP_SESSION_TYPE_CONFIRM = 3, - /** Registration rejection message */ - XSMP_SESSION_TYPE_REJECT = 4, - /** Shutdown message */ - XSMP_SESSION_TYPE_SHUTDOWN = 5, -}; - -/** XSMP boot flags */ -enum xsmp_session_boot { - /** PXE boot */ - XSMP_BOOT_PXE = ( 1 << 0 ), -}; - -/** XSMP virtual Ethernet channel adapter parameters */ -struct xsmp_xve_ca { - /** Subnet prefix (little-endian) */ - union ib_guid prefix_le; - /** Control queue pair number */ - uint32_t ctrl; - /** Data queue pair number */ - uint32_t data; - /** Partition key */ - uint16_t pkey; - /** Queue key */ - uint16_t qkey; -} __attribute__ (( packed )); - -/** XSMP virtual Ethernet MAC address */ -struct xsmp_xve_mac { - /** High 16 bits */ - uint16_t high; - /** Low 32 bits */ - uint32_t low; -} __attribute__ (( packed )); - -/** An XSMP virtual Ethernet message */ -struct xsmp_xve_message { - /** Message header */ - struct xsmp_message_header hdr; - /** Message type */ - uint8_t type; - /** Reason code */ - uint8_t code; - /** Length (excluding message header) */ - uint16_t len; - /** Update bitmask */ - uint32_t update; - /** Resource identifier */ - union ib_guid resource; - /** TCA GUID (little-endian) */ - union ib_guid guid_le; - /** TCA LID */ - uint16_t lid; - /** MAC address (little-endian) */ - struct xsmp_xve_mac mac_le; - /** Rate */ - uint16_t rate; - /** Administrative state (non-zero = "up") */ - uint16_t state; - /** Encapsulation (apparently obsolete and unused) */ - uint16_t encap; - /** MTU */ - uint16_t mtu; - /** Installation flags (apparently obsolete and unused) */ - uint32_t install; - /** Interface name */ - char name[16]; - /** Service level */ - uint16_t sl; - /** Flow control enabled (apparently obsolete and unused) */ - uint16_t flow; - /** Committed rate (in Mbps) */ - uint16_t committed_mbps; - /** Peak rate (in Mbps) */ - uint16_t peak_mbps; - /** Committed burst size (in bytes) */ - uint32_t committed_burst; - /** Peak burst size (in bytes) */ - uint32_t peak_burst; - /** VMware index */ - uint8_t vmware; - /** Reserved */ - uint8_t reserved0; - /** Multipath flags */ - uint16_t multipath; - /** Multipath group name */ - char group[48]; - /** Link aggregation flag */ - uint8_t agg; - /** Link aggregation policy */ - uint8_t policy; - /** Network ID */ - uint32_t network; - /** Mode */ - uint8_t mode; - /** Uplink type */ - uint8_t uplink; - /** Target channel adapter parameters */ - struct xsmp_xve_ca tca; - /** Host channel adapter parameters */ - struct xsmp_xve_ca hca; - /** Reserved */ - uint8_t reserved1[336]; -} __attribute__ (( packed )); - -/** XSMP virtual Ethernet message types */ -enum xsmp_xve_type { - /** Install virtual NIC */ - XSMP_XVE_TYPE_INSTALL = 1, - /** Delete virtual NIC */ - XSMP_XVE_TYPE_DELETE = 2, - /** Update virtual NIC */ - XSMP_XVE_TYPE_UPDATE = 3, - /** Set operational state up */ - XSMP_XVE_TYPE_OPER_UP = 6, - /** Set operational state down */ - XSMP_XVE_TYPE_OPER_DOWN = 7, - /** Get operational state */ - XSMP_XVE_TYPE_OPER_REQ = 15, - /** Virtual NIC is ready */ - XSMP_XVE_TYPE_READY = 20, -}; - -/** XSMP virtual Ethernet message codes */ -enum xsmp_xve_code { - /* Something went wrong */ - XSMP_XVE_CODE_ERROR = 0x84, -}; - -/** XSMP virtual Ethernet update bitmask */ -enum xsmp_xve_update { - /** Update MTU */ - XSMP_XVE_UPDATE_MTU = ( 1 << 2 ), - /** Update administrative state */ - XSMP_XVE_UPDATE_STATE = ( 1 << 6 ), - /** Update gateway to mark as down */ - XSMP_XVE_UPDATE_GW_DOWN = ( 1 << 30 ), - /** Update gateway information */ - XSMP_XVE_UPDATE_GW_CHANGE = ( 1 << 31 ), -}; - -/** XSMP virtual Ethernet modes */ -enum xsmp_xve_mode { - /** Reliable Connected */ - XSMP_XVE_MODE_RC = 1, - /** Unreliable Datagram */ - XSMP_XVE_MODE_UD = 2, -}; - -/** XSMP virtual Ethernet uplink types */ -enum xsmp_xve_uplink { - /** No uplink */ - XSMP_XVE_NO_UPLINK = 1, - /** Has uplink */ - XSMP_XVE_UPLINK = 2, -}; - -/** An XSMP message */ -union xsmp_message { - /** Message header */ - struct xsmp_message_header hdr; - /** Session message */ - struct xsmp_session_message sess; - /** Virtual Ethernet message */ - struct xsmp_xve_message xve; -}; - -/** Delay between attempts to open the Infiniband device - * - * This is a policy decision. - */ -#define XSIGO_OPEN_RETRY_DELAY ( 2 * TICKS_PER_SEC ) - -/** Delay between unsuccessful discovery attempts - * - * This is a policy decision. - */ -#define XSIGO_DISCOVERY_FAILURE_DELAY ( 10 * TICKS_PER_SEC ) - -/** Delay between successful discovery attempts - * - * This is a policy decision. - */ -#define XSIGO_DISCOVERY_SUCCESS_DELAY ( 20 * TICKS_PER_SEC ) - -/** Delay between keepalive requests - * - * This is a policy decision. - */ -#define XSIGO_KEEPALIVE_INTERVAL ( 10 * TICKS_PER_SEC ) - -/** Maximum time to wait for a keepalive response - * - * This is a policy decision. - */ -#define XSIGO_KEEPALIVE_MAX_WAIT ( 2 * TICKS_PER_SEC ) - -#endif /* _IPXE_XSIGO_H */ diff --git a/roms/ipxe/src/include/nic.h b/roms/ipxe/src/include/nic.h index 8b06e88f4..4c91f57a6 100644 --- a/roms/ipxe/src/include/nic.h +++ b/roms/ipxe/src/include/nic.h @@ -209,8 +209,7 @@ static inline void * legacy_isa_get_drvdata ( void *hwdev ) { #undef DRIVER #define DRIVER(_name_text,_unused2,_unused3,_name,_probe,_disable) \ - static __attribute__ (( unused )) const char \ - _name ## _text[] = _name_text; \ + static const char _name ## _text[] = _name_text; \ static inline int \ _name ## _probe ( struct nic *nic, void *hwdev ) { \ return _probe ( nic, hwdev ); \ diff --git a/roms/ipxe/src/include/stddef.h b/roms/ipxe/src/include/stddef.h index fb01c489d..3c056294f 100644 --- a/roms/ipxe/src/include/stddef.h +++ b/roms/ipxe/src/include/stddef.h @@ -34,7 +34,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); */ #define container_of( ptr, type, field ) ( { \ type *__container; \ - const volatile typeof ( __container->field ) *__field = (ptr); \ + const typeof ( __container->field ) *__field = (ptr); \ __container = ( ( ( void * ) __field ) - \ offsetof ( type, field ) ); \ __container; } ) diff --git a/roms/ipxe/src/include/string.h b/roms/ipxe/src/include/string.h index 0f4182001..0fab6c74b 100644 --- a/roms/ipxe/src/include/string.h +++ b/roms/ipxe/src/include/string.h @@ -10,14 +10,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <stddef.h> - -extern void * generic_memset ( void *dest, int character, - size_t len ) __nonnull; -extern void * generic_memcpy ( void *dest, const void *src, - size_t len ) __nonnull; -extern void * generic_memmove ( void *dest, const void *src, - size_t len ) __nonnull; - #include <bits/string.h> /* Architecture-specific code is expected to provide these functions, @@ -26,6 +18,12 @@ extern void * generic_memmove ( void *dest, const void *src, void * memset ( void *dest, int character, size_t len ) __nonnull; void * memcpy ( void *dest, const void *src, size_t len ) __nonnull; void * memmove ( void *dest, const void *src, size_t len ) __nonnull; +extern void * generic_memset ( void *dest, int character, + size_t len ) __nonnull; +extern void * generic_memcpy ( void *dest, const void *src, + size_t len ) __nonnull; +extern void * generic_memmove ( void *dest, const void *src, + size_t len ) __nonnull; extern int __pure memcmp ( const void *first, const void *second, size_t len ) __nonnull; diff --git a/roms/ipxe/src/include/time.h b/roms/ipxe/src/include/time.h index ab93a3dbb..462ac6999 100644 --- a/roms/ipxe/src/include/time.h +++ b/roms/ipxe/src/include/time.h @@ -39,10 +39,10 @@ struct tm { * @v t Time to fill in, or NULL * @ret time Current time */ -static inline __attribute__ (( always_inline )) time_t time ( time_t *t ) { +static inline time_t time ( time_t *t ) { time_t now; - now = ( time_now() + time_offset ); + now = time_now(); if ( t ) *t = now; return now; diff --git a/roms/ipxe/src/include/usr/ibmgmt.h b/roms/ipxe/src/include/usr/ibmgmt.h deleted file mode 100644 index 16a099134..000000000 --- a/roms/ipxe/src/include/usr/ibmgmt.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef _USR_IBMGMT_H -#define _USR_IBMGMT_H - -/** @file - * - * Infiniband device management - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -struct ib_device; - -extern void ibstat ( struct ib_device *ibdev ); - -#endif /* _USR_IBMGMT_H */ diff --git a/roms/ipxe/src/include/usr/lotest.h b/roms/ipxe/src/include/usr/lotest.h index bd66f4a44..ce0fe5eda 100644 --- a/roms/ipxe/src/include/usr/lotest.h +++ b/roms/ipxe/src/include/usr/lotest.h @@ -10,7 +10,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); extern int loopback_test ( struct net_device *sender, - struct net_device *receiver, - size_t mtu, int broadcast ); + struct net_device *receiver, size_t mtu ); #endif /* _USR_LOTEST_H */ diff --git a/roms/ipxe/src/include/usr/ntpmgmt.h b/roms/ipxe/src/include/usr/ntpmgmt.h deleted file mode 100644 index 284e668e6..000000000 --- a/roms/ipxe/src/include/usr/ntpmgmt.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef _USR_NTPMGMT_H -#define _USR_NTPMGMT_H - -/** @file - * - * NTP management - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -extern int ntp ( const char *hostname ); - -#endif /* _USR_NTPMGMT_H */ diff --git a/roms/ipxe/src/interface/bofm/bofm.c b/roms/ipxe/src/interface/bofm/bofm.c index 54039193a..545088dc6 100644 --- a/roms/ipxe/src/interface/bofm/bofm.c +++ b/roms/ipxe/src/interface/bofm/bofm.c @@ -313,12 +313,12 @@ int bofm ( userptr_t bofmtab, struct pci_device *pci ) { } DBG ( "BOFM: slot %d port %d%s is " PCI_FMT " mport %d\n", en.slot, ( en.port + 1 ), - ( ( en.slot || en.port ) ? "" : "(?)" ), 0, + ( ( en.slot || en.port ) ? "" : "(?)" ), PCI_BUS ( en.busdevfn ), PCI_SLOT ( en.busdevfn ), PCI_FUNC ( en.busdevfn ), en.mport ); bofm = bofm_find_busdevfn ( en.busdevfn ); if ( ! bofm ) { - DBG ( "BOFM: " PCI_FMT " mport %d ignored\n", 0, + DBG ( "BOFM: " PCI_FMT " mport %d ignored\n", PCI_BUS ( en.busdevfn ), PCI_SLOT ( en.busdevfn ), PCI_FUNC ( en.busdevfn ), en.mport ); continue; diff --git a/roms/ipxe/src/interface/efi/efi_bofm.c b/roms/ipxe/src/interface/efi/efi_bofm.c index 00f6a1d5c..ea0e15f7f 100644 --- a/roms/ipxe/src/interface/efi/efi_bofm.c +++ b/roms/ipxe/src/interface/efi/efi_bofm.c @@ -178,8 +178,8 @@ static int efi_bofm_supported ( EFI_HANDLE device ) { /* Look for a BOFM driver */ if ( ( rc = bofm_find_driver ( &pci ) ) != 0 ) { - DBGCP ( device, "EFIBOFM %s has no driver\n", - efi_handle_name ( device ) ); + DBGCP ( device, "EFIBOFM %p %s has no driver\n", + device, efi_handle_name ( device ) ); return rc; } @@ -187,8 +187,8 @@ static int efi_bofm_supported ( EFI_HANDLE device ) { if ( ( efirc = bs->LocateProtocol ( &bofm1_protocol_guid, NULL, &bofm1.interface ) ) != 0 ) { rc = -EEFI ( efirc ); - DBGC ( device, "EFIBOFM %s cannot find BOFM protocol\n", - efi_handle_name ( device ) ); + DBGC ( device, "EFIBOFM %p %s cannot find BOFM protocol\n", + device, efi_handle_name ( device ) ); return rc; } @@ -198,13 +198,13 @@ static int efi_bofm_supported ( EFI_HANDLE device ) { 0x00 /* No iSCSI */, 0x02 /* Version */ ))!=0){ rc = -EEFI ( efirc ); - DBGC ( device, "EFIBOFM %s could not register support: %s\n", - efi_handle_name ( device ), strerror ( rc ) ); + DBGC ( device, "EFIBOFM %p %s could not register support: %s\n", + device, efi_handle_name ( device ), strerror ( rc ) ); return rc; } - DBGC ( device, "EFIBOFM %s has driver \"%s\"\n", - efi_handle_name ( device ), pci.id->name ); + DBGC ( device, "EFIBOFM %p %s has driver \"%s\"\n", + device, efi_handle_name ( device ), pci.id->name ); return 0; } @@ -241,48 +241,49 @@ static int efi_bofm_start ( struct efi_device *efidev ) { if ( ( efirc = bs->LocateProtocol ( &bofm1_protocol_guid, NULL, &bofm1.interface ) ) != 0 ) { rc = -EEFI ( efirc ); - DBGC ( device, "EFIBOFM %s cannot find BOFM protocol\n", - efi_handle_name ( device ) ); + DBGC ( device, "EFIBOFM %p %s cannot find BOFM protocol\n", + device, efi_handle_name ( device ) ); goto err_locate_bofm; } bofmtab = &bofm1.bofm1->BofmTable; - DBGC ( device, "EFIBOFM %s found version 1 BOFM table at %p+%04x\n", - efi_handle_name ( device ), bofmtab, bofmtab->Parameters.Length); + DBGC ( device, "EFIBOFM %p %s found version 1 BOFM table at %p+%04x\n", + device, efi_handle_name ( device ), bofmtab, + bofmtab->Parameters.Length ); /* Locate BOFM2 protocol, if available */ if ( ( efirc = bs->LocateProtocol ( &bofm2_protocol_guid, NULL, &bofm2.interface ) ) == 0 ) { bofmtab2 = &bofm2.bofm2->BofmTable; - DBGC ( device, "EFIBOFM %s found version 2 BOFM table at " - "%p+%04x\n", efi_handle_name ( device ), bofmtab2, - bofmtab2->Parameters.Length ); + DBGC ( device, "EFIBOFM %p %s found version 2 BOFM table at " + "%p+%04x\n", device, efi_handle_name ( device ), + bofmtab2, bofmtab2->Parameters.Length ); assert ( bofm2.bofm2->RegisterSupport == bofm1.bofm1->RegisterSupport ); } else { - DBGC ( device, "EFIBOFM %s cannot find BOFM2 protocol\n", - efi_handle_name ( device ) ); + DBGC ( device, "EFIBOFM %p %s cannot find BOFM2 protocol\n", + device, efi_handle_name ( device ) ); /* Not a fatal error; may be a BOFM1-only system */ bofmtab2 = NULL; } /* Process BOFM table */ - DBGC2 ( device, "EFIBOFM %s version 1 before processing:\n", - efi_handle_name ( device ) ); + DBGC2 ( device, "EFIBOFM %p %s version 1 before processing:\n", + device, efi_handle_name ( device ) ); DBGC2_HD ( device, bofmtab, bofmtab->Parameters.Length ); if ( bofmtab2 ) { - DBGC2 ( device, "EFIBOFM %s version 2 before processing:\n", - efi_handle_name ( device ) ); + DBGC2 ( device, "EFIBOFM %p %s version 2 before processing:\n", + device, efi_handle_name ( device ) ); DBGC2_HD ( device, bofmtab2, bofmtab2->Parameters.Length ); } bofmrc = bofm ( virt_to_user ( bofmtab2 ? bofmtab2 : bofmtab ), &pci ); - DBGC ( device, "EFIBOFM %s status %08x\n", - efi_handle_name ( device ), bofmrc ); - DBGC2 ( device, "EFIBOFM %s version 1 after processing:\n", - efi_handle_name ( device ) ); + DBGC ( device, "EFIBOFM %p %s status %08x\n", + device, efi_handle_name ( device ), bofmrc ); + DBGC2 ( device, "EFIBOFM %p %s version 1 after processing:\n", + device, efi_handle_name ( device ) ); DBGC2_HD ( device, bofmtab, bofmtab->Parameters.Length ); if ( bofmtab2 ) { - DBGC2 ( device, "EFIBOFM %s version 2 after processing:\n", - efi_handle_name ( device ) ); + DBGC2 ( device, "EFIBOFM %p %s version 2 after processing:\n", + device, efi_handle_name ( device ) ); DBGC2_HD ( device, bofmtab2, bofmtab2->Parameters.Length ); } @@ -291,18 +292,18 @@ static int efi_bofm_start ( struct efi_device *efidev ) { if ( ( efirc = bofm2.bofm2->SetStatus ( bofm2.bofm2, device, FALSE, bofmrc ) ) != 0){ rc = -EEFI ( efirc ); - DBGC ( device, "EFIBOFM %s could not set BOFM2 " - "status: %s\n", efi_handle_name ( device ), - strerror ( rc ) ); + DBGC ( device, "EFIBOFM %p %s could not set BOFM2 " + "status: %s\n", device, + efi_handle_name ( device ), strerror ( rc ) ); goto err_set_status; } } else { if ( ( efirc = bofm1.bofm1->SetStatus ( bofm1.bofm1, device, FALSE, bofmrc ) ) != 0){ rc = -EEFI ( efirc ); - DBGC ( device, "EFIBOFM %s could not set BOFM " - "status: %s\n", efi_handle_name ( device ), - strerror ( rc ) ); + DBGC ( device, "EFIBOFM %p %s could not set BOFM " + "status: %s\n", device, + efi_handle_name ( device ), strerror ( rc ) ); goto err_set_status; } } diff --git a/roms/ipxe/src/interface/efi/efi_console.c b/roms/ipxe/src/interface/efi/efi_console.c index 047baed47..3b30f3097 100644 --- a/roms/ipxe/src/interface/efi/efi_console.c +++ b/roms/ipxe/src/interface/efi/efi_console.c @@ -239,14 +239,6 @@ static const char *ansi_sequences[] = { [SCAN_DELETE] = "[3~", [SCAN_PAGE_UP] = "[5~", [SCAN_PAGE_DOWN] = "[6~", - [SCAN_F5] = "[15~", - [SCAN_F6] = "[17~", - [SCAN_F7] = "[18~", - [SCAN_F8] = "[19~", - [SCAN_F9] = "[20~", - [SCAN_F10] = "[21~", - [SCAN_F11] = "[23~", - [SCAN_F12] = "[24~", /* EFI translates some (but not all) incoming escape sequences * via the serial console into equivalent scancodes. When it * doesn't recognise a sequence, it helpfully(!) translates diff --git a/roms/ipxe/src/interface/efi/efi_debug.c b/roms/ipxe/src/interface/efi/efi_debug.c index 19531fdc1..473803951 100644 --- a/roms/ipxe/src/interface/efi/efi_debug.c +++ b/roms/ipxe/src/interface/efi/efi_debug.c @@ -35,7 +35,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <errno.h> #include <ipxe/uuid.h> #include <ipxe/base16.h> -#include <ipxe/vsprintf.h> #include <ipxe/efi/efi.h> #include <ipxe/efi/efi_utils.h> #include <ipxe/efi/Protocol/ComponentName.h> @@ -69,10 +68,6 @@ struct efi_well_known_guid { /** Well-known GUIDs */ static struct efi_well_known_guid efi_well_known_guids[] = { - { &efi_absolute_pointer_protocol_guid, - "AbsolutePointer" }, - { &efi_apple_net_boot_protocol_guid, - "AppleNetBoot" }, { &efi_arp_protocol_guid, "Arp" }, { &efi_arp_service_binding_protocol_guid, @@ -85,8 +80,6 @@ static struct efi_well_known_guid efi_well_known_guids[] = { "ComponentName" }, { &efi_component_name2_protocol_guid, "ComponentName2" }, - { &efi_console_control_protocol_guid, - "ConsoleControl" }, { &efi_device_path_protocol_guid, "DevicePath" }, { &efi_driver_binding_protocol_guid, @@ -101,8 +94,6 @@ static struct efi_well_known_guid efi_well_known_guids[] = { "GraphicsOutput" }, { &efi_hii_config_access_protocol_guid, "HiiConfigAccess" }, - { &efi_hii_font_protocol_guid, - "HiiFont" }, { &efi_ip4_protocol_guid, "Ip4" }, { &efi_ip4_config_protocol_guid, @@ -137,42 +128,20 @@ static struct efi_well_known_guid efi_well_known_guids[] = { "PciRootBridgeIo" }, { &efi_pxe_base_code_protocol_guid, "PxeBaseCode" }, - { &efi_serial_io_protocol_guid, - "SerialIo" }, { &efi_simple_file_system_protocol_guid, "SimpleFileSystem" }, { &efi_simple_network_protocol_guid, "SimpleNetwork" }, - { &efi_simple_pointer_protocol_guid, - "SimplePointer" }, - { &efi_simple_text_input_protocol_guid, - "SimpleTextInput" }, - { &efi_simple_text_input_ex_protocol_guid, - "SimpleTextInputEx" }, - { &efi_simple_text_output_protocol_guid, - "SimpleTextOutput" }, { &efi_tcg_protocol_guid, "Tcg" }, { &efi_tcp4_protocol_guid, "Tcp4" }, { &efi_tcp4_service_binding_protocol_guid, "Tcp4Sb" }, - { &efi_tree_protocol_guid, - "TrEE" }, { &efi_udp4_protocol_guid, "Udp4" }, { &efi_udp4_service_binding_protocol_guid, "Udp4Sb" }, - { &efi_uga_draw_protocol_guid, - "UgaDraw" }, - { &efi_unicode_collation_protocol_guid, - "UnicodeCollation" }, - { &efi_usb_hc_protocol_guid, - "UsbHc" }, - { &efi_usb2_hc_protocol_guid, - "Usb2Hc" }, - { &efi_usb_io_protocol_guid, - "UsbIo" }, { &efi_vlan_config_protocol_guid, "VlanConfig" }, { &efi_vlan_config_dxe_guid, @@ -185,7 +154,7 @@ static struct efi_well_known_guid efi_well_known_guids[] = { * @v guid GUID * @ret string Printable string */ -const __attribute__ (( pure )) char * efi_guid_ntoa ( EFI_GUID *guid ) { +const char * efi_guid_ntoa ( EFI_GUID *guid ) { union { union uuid uuid; EFI_GUID guid; @@ -212,26 +181,6 @@ const __attribute__ (( pure )) char * efi_guid_ntoa ( EFI_GUID *guid ) { } /** - * Name locate search type - * - * @v search_type Locate search type - * @ret name Locate search type name - */ -const __attribute__ (( pure )) char * -efi_locate_search_type_name ( EFI_LOCATE_SEARCH_TYPE search_type ) { - static char buf[16]; - - switch ( search_type ) { - case AllHandles : return "AllHandles"; - case ByRegisterNotify: return "ByRegisterNotify"; - case ByProtocol: return "ByProtocol"; - default: - snprintf ( buf, sizeof ( buf ), "UNKNOWN<%d>", search_type ); - return buf; - } -} - -/** * Name protocol open attributes * * @v attributes Protocol open attributes @@ -242,8 +191,7 @@ efi_locate_search_type_name ( EFI_LOCATE_SEARCH_TYPE search_type ) { * (T)EST_PROTOCOL, BY_(C)HILD_CONTROLLER, BY_(D)RIVER, and * E(X)CLUSIVE. */ -const __attribute__ (( pure )) char * -efi_open_attributes_name ( unsigned int attributes ) { +static const char * efi_open_attributes_name ( unsigned int attributes ) { static char attribute_chars[] = "HGTCDX"; static char name[ sizeof ( attribute_chars ) ]; char *tmp = name; @@ -275,9 +223,8 @@ void dbg_efi_openers ( EFI_HANDLE handle, EFI_GUID *protocol ) { /* Sanity check */ if ( ( ! handle ) || ( ! protocol ) ) { - printf ( "HANDLE %s could not retrieve openers for %s\n", - efi_handle_name ( handle ), - efi_guid_ntoa ( protocol ) ); + printf ( "EFI could not retrieve openers for %s on %p\n", + efi_guid_ntoa ( protocol ), handle ); return; } @@ -285,24 +232,24 @@ void dbg_efi_openers ( EFI_HANDLE handle, EFI_GUID *protocol ) { if ( ( efirc = bs->OpenProtocolInformation ( handle, protocol, &openers, &count ) ) != 0 ) { rc = -EEFI ( efirc ); - printf ( "HANDLE %s could not retrieve openers for %s: %s\n", - efi_handle_name ( handle ), - efi_guid_ntoa ( protocol ), strerror ( rc ) ); + printf ( "EFI could not retrieve openers for %s on %p: %s\n", + efi_guid_ntoa ( protocol ), handle, strerror ( rc ) ); return; } /* Dump list of openers */ for ( i = 0 ; i < count ; i++ ) { opener = &openers[i]; - printf ( "HANDLE %s %s opened %dx (%s)", - efi_handle_name ( handle ), + printf ( "HANDLE %p %s %s opened %dx (%s)", + handle, efi_handle_name ( handle ), efi_guid_ntoa ( protocol ), opener->OpenCount, efi_open_attributes_name ( opener->Attributes ) ); - printf ( " by %s", efi_handle_name ( opener->AgentHandle ) ); + printf ( " by %p %s", opener->AgentHandle, + efi_handle_name ( opener->AgentHandle ) ); if ( opener->ControllerHandle == handle ) { printf ( "\n" ); } else { - printf ( " for %s\n", + printf ( " for %p %s\n", opener->ControllerHandle, efi_handle_name ( opener->ControllerHandle ) ); } } @@ -327,8 +274,7 @@ void dbg_efi_protocols ( EFI_HANDLE handle ) { /* Sanity check */ if ( ! handle ) { - printf ( "HANDLE %s could not retrieve protocols\n", - efi_handle_name ( handle ) ); + printf ( "EFI could not retrieve protocols for %p\n", handle ); return; } @@ -336,15 +282,16 @@ void dbg_efi_protocols ( EFI_HANDLE handle ) { if ( ( efirc = bs->ProtocolsPerHandle ( handle, &protocols, &count ) ) != 0 ) { rc = -EEFI ( efirc ); - printf ( "HANDLE %s could not retrieve protocols: %s\n", - efi_handle_name ( handle ), strerror ( rc ) ); + printf ( "EFI could not retrieve protocols for %p: %s\n", + handle, strerror ( rc ) ); return; } /* Dump list of protocols */ for ( i = 0 ; i < count ; i++ ) { protocol = protocols[i]; - printf ( "HANDLE %s %s supported\n", efi_handle_name ( handle ), + printf ( "HANDLE %p %s %s supported\n", + handle, efi_handle_name ( handle ), efi_guid_ntoa ( protocol ) ); dbg_efi_openers ( handle, protocol ); } @@ -359,10 +306,12 @@ void dbg_efi_protocols ( EFI_HANDLE handle ) { * @v path Device path * @ret text Textual representation of device path, or NULL */ -const __attribute__ (( pure )) char * -efi_devpath_text ( EFI_DEVICE_PATH_PROTOCOL *path ) { +const char * efi_devpath_text ( EFI_DEVICE_PATH_PROTOCOL *path ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; static char text[256]; + void *start; + void *end; + size_t max_len; size_t len; CHAR16 *wtext; @@ -375,8 +324,13 @@ efi_devpath_text ( EFI_DEVICE_PATH_PROTOCOL *path ) { /* If we have no DevicePathToText protocol then use a raw hex string */ if ( ! efidpt ) { DBG ( "[No DevicePathToText]" ); - len = efi_devpath_len ( path ); - base16_encode ( path, len, text, sizeof ( text ) ); + start = path; + end = efi_devpath_end ( path ); + len = ( end - start ); + max_len = ( ( sizeof ( text ) - 1 /* NUL */ ) / 2 /* "xx" */ ); + if ( len > max_len ) + len = max_len; + base16_encode ( start, len, text, sizeof ( text ) ); return text; } @@ -609,42 +563,6 @@ efi_loaded_image_filepath_name ( EFI_LOADED_IMAGE_PROTOCOL *loaded ) { return efi_devpath_text ( loaded->FilePath ); } -/** - * Get console input handle name - * - * @v input Simple text input protocol - * @ret name Console input handle name, or NULL - */ -static const char * -efi_conin_name ( EFI_SIMPLE_TEXT_INPUT_PROTOCOL *input ) { - - /* Check for match against ConIn */ - if ( input == efi_systab->ConIn ) - return "ConIn"; - - return NULL; -} - -/** - * Get console output handle name - * - * @v output Simple text output protocol - * @ret name Console output handle name, or NULL - */ -static const char * -efi_conout_name ( EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *output ) { - - /* Check for match against ConOut */ - if ( output == efi_systab->ConOut ) - return "ConOut"; - - /* Check for match against StdErr (if different from ConOut) */ - if ( output == efi_systab->StdErr ) - return "StdErr"; - - return NULL; -} - /** An EFI handle name type */ struct efi_handle_name_type { /** Protocol */ @@ -693,12 +611,6 @@ static struct efi_handle_name_type efi_handle_name_types[] = { /* Handle's loaded image file path (for image handles) */ EFI_HANDLE_NAME_TYPE ( &efi_loaded_image_protocol_guid, efi_loaded_image_filepath_name ), - /* Our standard input file handle */ - EFI_HANDLE_NAME_TYPE ( &efi_simple_text_input_protocol_guid, - efi_conin_name ), - /* Our standard output and standard error file handles */ - EFI_HANDLE_NAME_TYPE ( &efi_simple_text_output_protocol_guid, - efi_conout_name ), }; /** @@ -707,13 +619,9 @@ static struct efi_handle_name_type efi_handle_name_types[] = { * @v handle EFI handle * @ret text Name of handle, or NULL */ -const __attribute__ (( pure )) char * efi_handle_name ( EFI_HANDLE handle ) { +const char * efi_handle_name ( EFI_HANDLE handle ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; struct efi_handle_name_type *type; - static char buf[256]; - size_t used = 0; - EFI_GUID **protocols; - UINTN count; unsigned int i; void *interface; const char *name; @@ -753,19 +661,5 @@ const __attribute__ (( pure )) char * efi_handle_name ( EFI_HANDLE handle ) { return name; } - /* If no name is found, then use the raw handle value and a - * list of installed protocols. - */ - used = ssnprintf ( buf, sizeof ( buf ), "UNKNOWN<%p", handle ); - if ( ( efirc = bs->ProtocolsPerHandle ( handle, &protocols, - &count ) ) == 0 ) { - for ( i = 0 ; i < count ; i++ ) { - used += ssnprintf ( ( buf + used ), - ( sizeof ( buf ) - used ), ",%s", - efi_guid_ntoa ( protocols[i] ) ); - } - bs->FreePool ( protocols ); - } - used += ssnprintf ( ( buf + used ), ( sizeof ( buf ) - used ), ">" ); - return buf; + return "UNKNOWN"; } diff --git a/roms/ipxe/src/interface/efi/efi_driver.c b/roms/ipxe/src/interface/efi/efi_driver.c index 22aa3ee72..ba7784cd7 100644 --- a/roms/ipxe/src/interface/efi/efi_driver.c +++ b/roms/ipxe/src/interface/efi/efi_driver.c @@ -30,7 +30,6 @@ FILE_LICENCE ( GPL2_OR_LATER ); #include <ipxe/efi/Protocol/ComponentName2.h> #include <ipxe/efi/Protocol/DevicePath.h> #include <ipxe/efi/efi_strings.h> -#include <ipxe/efi/efi_utils.h> #include <ipxe/efi/efi_driver.h> /** @file @@ -69,16 +68,18 @@ static struct efi_device * efidev_find ( EFI_HANDLE device ) { * @ret efidev Parent EFI device, or NULL */ struct efi_device * efidev_parent ( struct device *dev ) { - struct device *parent; + struct device *parent = dev->parent; + struct efi_device *efidev; - /* Walk upwards until we find an EFI device */ - while ( ( parent = dev->parent ) ) { - if ( parent->desc.bus_type == BUS_TYPE_EFI ) - return container_of ( parent, struct efi_device, dev ); - dev = parent; - } + /* Check that parent exists and is an EFI device */ + if ( ! parent ) + return NULL; + if ( parent->desc.bus_type != BUS_TYPE_EFI ) + return NULL; - return NULL; + /* Get containing EFI device */ + efidev = container_of ( parent, struct efi_device, dev ); + return efidev; } /** @@ -95,29 +96,30 @@ efi_driver_supported ( EFI_DRIVER_BINDING_PROTOCOL *driver __unused, struct efi_driver *efidrv; int rc; - DBGCP ( device, "EFIDRV %s DRIVER_SUPPORTED", - efi_handle_name ( device ) ); + DBGCP ( device, "EFIDRV %p %s DRIVER_SUPPORTED", + device, efi_handle_name ( device ) ); if ( child ) DBGCP ( device, " (child %s)", efi_devpath_text ( child ) ); DBGCP ( device, "\n" ); /* Do nothing if we are already driving this device */ if ( efidev_find ( device ) != NULL ) { - DBGCP ( device, "EFIDRV %s is already started\n", - efi_handle_name ( device ) ); + DBGCP ( device, "EFIDRV %p %s is already started\n", + device, efi_handle_name ( device ) ); return EFI_ALREADY_STARTED; } /* Look for a driver claiming to support this device */ for_each_table_entry ( efidrv, EFI_DRIVERS ) { if ( ( rc = efidrv->supported ( device ) ) == 0 ) { - DBGC ( device, "EFIDRV %s has driver \"%s\"\n", - efi_handle_name ( device ), efidrv->name ); + DBGC ( device, "EFIDRV %p %s has driver \"%s\"\n", + device, efi_handle_name ( device ), + efidrv->name ); return 0; } } - DBGCP ( device, "EFIDRV %s has no driver\n", - efi_handle_name ( device ) ); + DBGCP ( device, "EFIDRV %p %s has no driver\n", + device, efi_handle_name ( device ) ); return EFI_UNSUPPORTED; } @@ -133,19 +135,13 @@ efi_driver_supported ( EFI_DRIVER_BINDING_PROTOCOL *driver __unused, static EFI_STATUS EFIAPI efi_driver_start ( EFI_DRIVER_BINDING_PROTOCOL *driver __unused, EFI_HANDLE device, EFI_DEVICE_PATH_PROTOCOL *child ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; struct efi_driver *efidrv; struct efi_device *efidev; - union { - EFI_DEVICE_PATH_PROTOCOL *path; - void *interface; - } path; - EFI_DEVICE_PATH_PROTOCOL *path_end; - size_t path_len; EFI_STATUS efirc; int rc; - DBGC ( device, "EFIDRV %s DRIVER_START", efi_handle_name ( device ) ); + DBGC ( device, "EFIDRV %p %s DRIVER_START", + device, efi_handle_name ( device ) ); if ( child ) DBGC ( device, " (child %s)", efi_devpath_text ( child ) ); DBGC ( device, "\n" ); @@ -153,73 +149,48 @@ efi_driver_start ( EFI_DRIVER_BINDING_PROTOCOL *driver __unused, /* Do nothing if we are already driving this device */ efidev = efidev_find ( device ); if ( efidev ) { - DBGCP ( device, "EFIDRV %s is already started\n", - efi_handle_name ( device ) ); + DBGCP ( device, "EFIDRV %p %s is already started\n", + device, efi_handle_name ( device ) ); efirc = EFI_ALREADY_STARTED; goto err_already_started; } - /* Open device path */ - if ( ( efirc = bs->OpenProtocol ( device, - &efi_device_path_protocol_guid, - &path.interface, efi_image_handle, - device, - EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){ - rc = -EEFI ( efirc ); - DBGC ( device, "EFIDRV %s could not open device path: %s\n", - efi_handle_name ( device ), strerror ( rc ) ); - goto err_open_path; - } - path_len = ( efi_devpath_len ( path.path ) + sizeof ( *path_end ) ); - /* Allocate and initialise structure */ - efidev = zalloc ( sizeof ( *efidev ) + path_len ); + efidev = zalloc ( sizeof ( *efidev ) ); if ( ! efidev ) { efirc = EFI_OUT_OF_RESOURCES; goto err_alloc; } efidev->device = device; efidev->dev.desc.bus_type = BUS_TYPE_EFI; - efidev->path = ( ( ( void * ) efidev ) + sizeof ( *efidev ) ); - memcpy ( efidev->path, path.path, path_len ); INIT_LIST_HEAD ( &efidev->dev.children ); list_add ( &efidev->dev.siblings, &efi_devices ); - /* Close device path */ - bs->CloseProtocol ( device, &efi_device_path_protocol_guid, - efi_image_handle, device ); - path.path = NULL; - /* Try to start this device */ for_each_table_entry ( efidrv, EFI_DRIVERS ) { if ( ( rc = efidrv->supported ( device ) ) != 0 ) { - DBGC ( device, "EFIDRV %s is not supported by driver " - "\"%s\": %s\n", efi_handle_name ( device ), - efidrv->name, + DBGC ( device, "EFIDRV %p %s is not supported by " + "driver \"%s\": %s\n", device, + efi_handle_name ( device ), efidrv->name, strerror ( rc ) ); continue; } if ( ( rc = efidrv->start ( efidev ) ) == 0 ) { efidev->driver = efidrv; - DBGC ( device, "EFIDRV %s using driver \"%s\"\n", - efi_handle_name ( device ), + DBGC ( device, "EFIDRV %p %s using driver \"%s\"\n", + device, efi_handle_name ( device ), efidev->driver->name ); return 0; } - DBGC ( device, "EFIDRV %s could not start driver \"%s\": %s\n", - efi_handle_name ( device ), efidrv->name, - strerror ( rc ) ); + DBGC ( device, "EFIDRV %p %s could not start driver \"%s\": " + "%s\n", device, efi_handle_name ( device ), + efidrv->name, strerror ( rc ) ); } efirc = EFI_UNSUPPORTED; list_del ( &efidev->dev.siblings ); free ( efidev ); err_alloc: - if ( path.path ) { - bs->CloseProtocol ( device, &efi_device_path_protocol_guid, - efi_image_handle, device ); - } - err_open_path: err_already_started: return efirc; } @@ -242,19 +213,20 @@ efi_driver_stop ( EFI_DRIVER_BINDING_PROTOCOL *driver __unused, struct efi_device *efidev; UINTN i; - DBGC ( device, "EFIDRV %s DRIVER_STOP", efi_handle_name ( device ) ); + DBGC ( device, "EFIDRV %p %s DRIVER_STOP", + device, efi_handle_name ( device ) ); for ( i = 0 ; i < num_children ; i++ ) { - DBGC ( device, "%s%s", ( i ? ", " : " child " ), - efi_handle_name ( children[i] ) ); + DBGC ( device, "%s%p %s", ( i ? ", " : " child " ), + children[i], efi_handle_name ( children[i] ) ); } DBGC ( device, "\n" ); /* Do nothing unless we are driving this device */ efidev = efidev_find ( device ); if ( ! efidev ) { - DBGCP ( device, "EFIDRV %s is not started\n", - efi_handle_name ( device ) ); - return EFI_DEVICE_ERROR; + DBGCP ( device, "EFIDRV %p %s is not started\n", + device, efi_handle_name ( device ) ); + return 0; } /* Stop this device */ @@ -406,35 +378,36 @@ static int efi_driver_connect ( EFI_HANDLE device ) { } /* Disconnect any existing drivers */ - DBGC2 ( device, "EFIDRV %s before disconnecting:\n", - efi_handle_name ( device ) ); + DBGC2 ( device, "EFIDRV %p %s before disconnecting:\n", + device, efi_handle_name ( device ) ); DBGC2_EFI_PROTOCOLS ( device, device ); - DBGC ( device, "EFIDRV %s disconnecting existing drivers\n", - efi_handle_name ( device ) ); + DBGC ( device, "EFIDRV %p %s disconnecting existing drivers\n", + device, efi_handle_name ( device ) ); if ( ( efirc = bs->DisconnectController ( device, NULL, NULL ) ) != 0 ) { rc = -EEFI ( efirc ); - DBGC ( device, "EFIDRV %s could not disconnect existing " - "drivers: %s\n", efi_handle_name ( device ), + DBGC ( device, "EFIDRV %p %s could not disconnect existing " + "drivers: %s\n", device, efi_handle_name ( device ), strerror ( rc ) ); /* Ignore the error and attempt to connect our drivers */ } - DBGC2 ( device, "EFIDRV %s after disconnecting:\n", - efi_handle_name ( device ) ); + DBGC2 ( device, "EFIDRV %p %s after disconnecting:\n", + device, efi_handle_name ( device ) ); DBGC2_EFI_PROTOCOLS ( device, device ); /* Connect our driver */ - DBGC ( device, "EFIDRV %s connecting new drivers\n", - efi_handle_name ( device ) ); + DBGC ( device, "EFIDRV %p %s connecting new drivers\n", + device, efi_handle_name ( device ) ); if ( ( efirc = bs->ConnectController ( device, drivers, NULL, FALSE ) ) != 0 ) { rc = -EEFI ( efirc ); - DBGC ( device, "EFIDRV %s could not connect new drivers: " - "%s\n", efi_handle_name ( device ), strerror ( rc ) ); + DBGC ( device, "EFIDRV %p %s could not connect new drivers: " + "%s\n", device, efi_handle_name ( device ), + strerror ( rc ) ); return rc; } - DBGC2 ( device, "EFIDRV %s after connecting:\n", - efi_handle_name ( device ) ); + DBGC2 ( device, "EFIDRV %p %s after connecting:\n", + device, efi_handle_name ( device ) ); DBGC2_EFI_PROTOCOLS ( device, device ); return 0; diff --git a/roms/ipxe/src/interface/efi/efi_fbcon.c b/roms/ipxe/src/interface/efi/efi_fbcon.c deleted file mode 100644 index abc5a9390..000000000 --- a/roms/ipxe/src/interface/efi/efi_fbcon.c +++ /dev/null @@ -1,573 +0,0 @@ -/* - * Copyright (C) 2015 Michael Brown <mbrown@fensystems.co.uk>. - * - * 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 ); - -/** - * @file - * - * EFI frame buffer console - * - */ - -#include <string.h> -#include <strings.h> -#include <ctype.h> -#include <errno.h> -#include <assert.h> -#include <limits.h> -#include <ipxe/efi/efi.h> -#include <ipxe/efi/Protocol/GraphicsOutput.h> -#include <ipxe/efi/Protocol/HiiFont.h> -#include <ipxe/ansicol.h> -#include <ipxe/fbcon.h> -#include <ipxe/console.h> -#include <ipxe/umalloc.h> -#include <ipxe/rotate.h> -#include <config/console.h> - -/* Avoid dragging in EFI console if not otherwise used */ -extern struct console_driver efi_console; -struct console_driver efi_console __attribute__ (( weak )); - -/* Set default console usage if applicable - * - * We accept either CONSOLE_FRAMEBUFFER or CONSOLE_EFIFB. - */ -#if ( defined ( CONSOLE_FRAMEBUFFER ) && ! defined ( CONSOLE_EFIFB ) ) -#define CONSOLE_EFIFB CONSOLE_FRAMEBUFFER -#endif -#if ! ( defined ( CONSOLE_EFIFB ) && CONSOLE_EXPLICIT ( CONSOLE_EFIFB ) ) -#undef CONSOLE_EFIFB -#define CONSOLE_EFIFB ( CONSOLE_USAGE_ALL & ~CONSOLE_USAGE_LOG ) -#endif - -/* Forward declaration */ -struct console_driver efifb_console __console_driver; - -/** An EFI frame buffer */ -struct efifb { - /** EFI graphics output protocol */ - EFI_GRAPHICS_OUTPUT_PROTOCOL *gop; - /** EFI HII font protocol */ - EFI_HII_FONT_PROTOCOL *hiifont; - /** Saved mode */ - UINT32 saved_mode; - - /** Frame buffer console */ - struct fbcon fbcon; - /** Physical start address */ - physaddr_t start; - /** Pixel geometry */ - struct fbcon_geometry pixel; - /** Colour mapping */ - struct fbcon_colour_map map; - /** Font definition */ - struct fbcon_font font; - /** Character glyphs */ - userptr_t glyphs; -}; - -/** The EFI frame buffer */ -static struct efifb efifb; - -/** - * Get character glyph - * - * @v character Character - * @v glyph Character glyph to fill in - */ -static void efifb_glyph ( unsigned int character, uint8_t *glyph ) { - size_t offset = ( character * efifb.font.height ); - - copy_from_user ( glyph, efifb.glyphs, offset, efifb.font.height ); -} - -/** - * Get character glyphs - * - * @ret rc Return status code - */ -static int efifb_glyphs ( void ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - EFI_IMAGE_OUTPUT *blt; - EFI_GRAPHICS_OUTPUT_BLT_PIXEL *pixel; - size_t offset; - size_t len; - uint8_t bitmask; - unsigned int character; - unsigned int x; - unsigned int y; - EFI_STATUS efirc; - int rc; - - /* Get font height. The GetFontInfo() call nominally returns - * this information in an EFI_FONT_DISPLAY_INFO structure, but - * is known to fail on many UEFI implementations. Instead, we - * iterate over all printable characters to find the maximum - * height. - */ - efifb.font.height = 0; - for ( character = 0 ; character < 256 ; character++ ) { - - /* Skip non-printable characters */ - if ( ! isprint ( character ) ) - continue; - - /* Get glyph */ - blt = NULL; - if ( ( efirc = efifb.hiifont->GetGlyph ( efifb.hiifont, - character, NULL, &blt, - NULL ) ) != 0 ) { - rc = -EEFI ( efirc ); - DBGC ( &efifb, "EFIFB could not get glyph %d: %s\n", - character, strerror ( rc ) ); - continue; - } - assert ( blt != NULL ); - - /* Calculate maximum height */ - if ( efifb.font.height < blt->Height ) - efifb.font.height = blt->Height; - - /* Free glyph */ - bs->FreePool ( blt ); - } - if ( ! efifb.font.height ) { - DBGC ( &efifb, "EFIFB could not get font height\n" ); - return -ENOENT; - } - - /* Allocate glyph data */ - len = ( 256 * efifb.font.height * sizeof ( bitmask ) ); - efifb.glyphs = umalloc ( len ); - if ( ! efifb.glyphs ) { - rc = -ENOMEM; - goto err_alloc; - } - memset_user ( efifb.glyphs, 0, 0, len ); - - /* Get font data */ - for ( character = 0 ; character < 256 ; character++ ) { - - /* Skip non-printable characters */ - if ( ! isprint ( character ) ) - continue; - - /* Get glyph */ - blt = NULL; - if ( ( efirc = efifb.hiifont->GetGlyph ( efifb.hiifont, - character, NULL, &blt, - NULL ) ) != 0 ) { - rc = -EEFI ( efirc ); - DBGC ( &efifb, "EFIFB could not get glyph %d: %s\n", - character, strerror ( rc ) ); - continue; - } - assert ( blt != NULL ); - - /* Sanity check */ - if ( blt->Width > 8 ) { - DBGC ( &efifb, "EFIFB glyph %d invalid width %d\n", - character, blt->Width ); - continue; - } - if ( blt->Height > efifb.font.height ) { - DBGC ( &efifb, "EFIFB glyph %d invalid height %d\n", - character, blt->Height ); - continue; - } - - /* Convert glyph to bitmap */ - pixel = blt->Image.Bitmap; - offset = ( character * efifb.font.height ); - for ( y = 0 ; y < blt->Height ; y++ ) { - bitmask = 0; - for ( x = 0 ; x < blt->Width ; x++ ) { - bitmask = rol8 ( bitmask, 1 ); - if ( pixel->Blue || pixel->Green || pixel->Red ) - bitmask |= 0x01; - pixel++; - } - copy_to_user ( efifb.glyphs, offset++, &bitmask, - sizeof ( bitmask ) ); - } - - /* Free glyph */ - bs->FreePool ( blt ); - } - - efifb.font.glyph = efifb_glyph; - return 0; - - ufree ( efifb.glyphs ); - err_alloc: - return rc; -} - -/** - * Generate colour mapping for a single colour component - * - * @v mask Mask value - * @v scale Scale value to fill in - * @v lsb LSB value to fill in - * @ret rc Return status code - */ -static int efifb_colour_map_mask ( uint32_t mask, uint8_t *scale, - uint8_t *lsb ) { - uint32_t check; - - /* Fill in LSB and scale */ - *lsb = ( mask ? ( ffs ( mask ) - 1 ) : 0 ); - *scale = ( mask ? ( 8 - ( fls ( mask ) - *lsb ) ) : 8 ); - - /* Check that original mask was contiguous */ - check = ( ( 0xff >> *scale ) << *lsb ); - if ( check != mask ) - return -ENOTSUP; - - return 0; -} - -/** - * Generate colour mapping - * - * @v info EFI mode information - * @v map Colour mapping to fill in - * @ret bpp Number of bits per pixel, or negative error - */ -static int efifb_colour_map ( EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info, - struct fbcon_colour_map *map ) { - static EFI_PIXEL_BITMASK rgb_mask = { - 0x000000ffUL, 0x0000ff00UL, 0x00ff0000UL, 0xff000000UL - }; - static EFI_PIXEL_BITMASK bgr_mask = { - 0x00ff0000UL, 0x0000ff00UL, 0x000000ffUL, 0xff000000UL - }; - EFI_PIXEL_BITMASK *mask; - uint8_t reserved_scale; - uint8_t reserved_lsb; - int rc; - - /* Determine applicable mask */ - switch ( info->PixelFormat ) { - case PixelRedGreenBlueReserved8BitPerColor: - mask = &rgb_mask; - break; - case PixelBlueGreenRedReserved8BitPerColor: - mask = &bgr_mask; - break; - case PixelBitMask: - mask = &info->PixelInformation; - break; - default: - DBGC ( &efifb, "EFIFB unrecognised pixel format %d\n", - info->PixelFormat ); - return -ENOTSUP; - } - - /* Map each colour component */ - if ( ( rc = efifb_colour_map_mask ( mask->RedMask, &map->red_scale, - &map->red_lsb ) ) != 0 ) - return rc; - if ( ( rc = efifb_colour_map_mask ( mask->GreenMask, &map->green_scale, - &map->green_lsb ) ) != 0 ) - return rc; - if ( ( rc = efifb_colour_map_mask ( mask->BlueMask, &map->blue_scale, - &map->blue_lsb ) ) != 0 ) - return rc; - if ( ( rc = efifb_colour_map_mask ( mask->ReservedMask, &reserved_scale, - &reserved_lsb ) ) != 0 ) - return rc; - - /* Calculate total number of bits per pixel */ - return ( 32 - ( reserved_scale + map->red_scale + map->green_scale + - map->blue_scale ) ); -} - -/** - * Select video mode - * - * @v min_width Minimum required width (in pixels) - * @v min_height Minimum required height (in pixels) - * @v min_bpp Minimum required colour depth (in bits per pixel) - * @ret mode_number Mode number, or negative error - */ -static int efifb_select_mode ( unsigned int min_width, unsigned int min_height, - unsigned int min_bpp ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - struct fbcon_colour_map map; - EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info; - int best_mode_number = -ENOENT; - unsigned int best_score = INT_MAX; - unsigned int score; - unsigned int mode; - int bpp; - UINTN size; - EFI_STATUS efirc; - int rc; - - /* Find the best mode */ - for ( mode = 0 ; mode < efifb.gop->Mode->MaxMode ; mode++ ) { - - /* Get mode information */ - if ( ( efirc = efifb.gop->QueryMode ( efifb.gop, mode, &size, - &info ) ) != 0 ) { - rc = -EEFI ( efirc ); - DBGC ( &efifb, "EFIFB could not get mode %d " - "information: %s\n", mode, strerror ( rc ) ); - goto err_query; - } - - /* Skip unusable modes */ - bpp = efifb_colour_map ( info, &map ); - if ( bpp < 0 ) { - rc = bpp; - DBGC ( &efifb, "EFIFB could not build colour map for " - "mode %d: %s\n", mode, strerror ( rc ) ); - goto err_map; - } - - /* Skip modes not meeting the requirements */ - if ( ( info->HorizontalResolution < min_width ) || - ( info->VerticalResolution < min_height ) || - ( ( ( unsigned int ) bpp ) < min_bpp ) ) { - goto err_requirements; - } - - /* Select this mode if it has the best (i.e. lowest) - * score. We choose the scoring system to favour - * modes close to the specified width and height; - * within modes of the same width and height we prefer - * a higher colour depth. - */ - score = ( ( info->HorizontalResolution * - info->VerticalResolution ) - bpp ); - if ( score < best_score ) { - best_mode_number = mode; - best_score = score; - } - - err_requirements: - err_map: - bs->FreePool ( info ); - err_query: - continue; - } - - if ( best_mode_number < 0 ) - DBGC ( &efifb, "EFIFB found no suitable mode\n" ); - return best_mode_number; -} - -/** - * Restore video mode - * - * @v rc Return status code - */ -static int efifb_restore ( void ) { - EFI_STATUS efirc; - int rc; - - /* Restore original mode */ - if ( ( efirc = efifb.gop->SetMode ( efifb.gop, - efifb.saved_mode ) ) != 0 ) { - rc = -EEFI ( efirc ); - DBGC ( &efifb, "EFIFB could not restore mode %d: %s\n", - efifb.saved_mode, strerror ( rc ) ); - return rc; - } - - return 0; -} - -/** - * Initialise EFI frame buffer - * - * @v config Console configuration, or NULL to reset - * @ret rc Return status code - */ -static int efifb_init ( struct console_configuration *config ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info; - void *interface; - int mode; - int bpp; - EFI_STATUS efirc; - int rc; - - /* Locate graphics output protocol */ - if ( ( efirc = bs->LocateProtocol ( &efi_graphics_output_protocol_guid, - NULL, &interface ) ) != 0 ) { - rc = -EEFI ( efirc ); - DBGC ( &efifb, "EFIFB could not locate graphics output " - "protocol: %s\n", strerror ( rc ) ); - goto err_locate_gop; - } - efifb.gop = interface; - - /* Locate HII font protocol */ - if ( ( efirc = bs->LocateProtocol ( &efi_hii_font_protocol_guid, - NULL, &interface ) ) != 0 ) { - rc = -EEFI ( efirc ); - DBGC ( &efifb, "EFIFB could not locate HII font protocol: %s\n", - strerror ( rc ) ); - goto err_locate_hiifont; - } - efifb.hiifont = interface; - - /* Locate glyphs */ - if ( ( rc = efifb_glyphs() ) != 0 ) - goto err_glyphs; - - /* Save original mode */ - efifb.saved_mode = efifb.gop->Mode->Mode; - - /* Select mode */ - if ( ( mode = efifb_select_mode ( config->width, config->height, - config->depth ) ) < 0 ) { - rc = mode; - goto err_select_mode; - } - - /* Set mode */ - if ( ( efirc = efifb.gop->SetMode ( efifb.gop, mode ) ) != 0 ) { - rc = -EEFI ( efirc ); - DBGC ( &efifb, "EFIFB could not set mode %d: %s\n", - mode, strerror ( rc ) ); - goto err_set_mode; - } - info = efifb.gop->Mode->Info; - - /* Populate colour map */ - bpp = efifb_colour_map ( info, &efifb.map ); - if ( bpp < 0 ) { - rc = bpp; - DBGC ( &efifb, "EFIFB could not build colour map for " - "mode %d: %s\n", mode, strerror ( rc ) ); - goto err_map; - } - - /* Populate pixel geometry */ - efifb.pixel.width = info->HorizontalResolution; - efifb.pixel.height = info->VerticalResolution; - efifb.pixel.len = ( ( bpp + 7 ) / 8 ); - efifb.pixel.stride = ( efifb.pixel.len * info->PixelsPerScanLine ); - - /* Populate frame buffer address */ - efifb.start = efifb.gop->Mode->FrameBufferBase; - DBGC ( &efifb, "EFIFB using mode %d (%dx%d %dbpp at %#08lx)\n", - mode, efifb.pixel.width, efifb.pixel.height, bpp, efifb.start ); - - /* Initialise frame buffer console */ - if ( ( rc = fbcon_init ( &efifb.fbcon, phys_to_user ( efifb.start ), - &efifb.pixel, &efifb.map, &efifb.font, - config ) ) != 0 ) - goto err_fbcon_init; - - return 0; - - fbcon_fini ( &efifb.fbcon ); - err_fbcon_init: - err_map: - efifb_restore(); - err_set_mode: - err_select_mode: - ufree ( efifb.glyphs ); - err_glyphs: - err_locate_hiifont: - err_locate_gop: - return rc; -} - -/** - * Finalise EFI frame buffer - * - */ -static void efifb_fini ( void ) { - - /* Finalise frame buffer console */ - fbcon_fini ( &efifb.fbcon ); - - /* Restore saved mode */ - efifb_restore(); - - /* Free glyphs */ - ufree ( efifb.glyphs ); -} - -/** - * Print a character to current cursor position - * - * @v character Character - */ -static void efifb_putchar ( int character ) { - - fbcon_putchar ( &efifb.fbcon, character ); -} - -/** - * Configure console - * - * @v config Console configuration, or NULL to reset - * @ret rc Return status code - */ -static int efifb_configure ( struct console_configuration *config ) { - int rc; - - /* Reset console, if applicable */ - if ( ! efifb_console.disabled ) { - efifb_fini(); - efi_console.disabled &= ~CONSOLE_DISABLED_OUTPUT; - ansicol_reset_magic(); - } - efifb_console.disabled = CONSOLE_DISABLED; - - /* Do nothing more unless we have a usable configuration */ - if ( ( config == NULL ) || - ( config->width == 0 ) || ( config->height == 0 ) ) { - return 0; - } - - /* Initialise EFI frame buffer */ - if ( ( rc = efifb_init ( config ) ) != 0 ) - return rc; - - /* Mark console as enabled */ - efifb_console.disabled = 0; - efi_console.disabled |= CONSOLE_DISABLED_OUTPUT; - - /* Set magic colour to transparent if we have a background picture */ - if ( config->pixbuf ) - ansicol_set_magic_transparent(); - - return 0; -} - -/** EFI graphics output protocol console driver */ -struct console_driver efifb_console __console_driver = { - .usage = CONSOLE_EFIFB, - .putchar = efifb_putchar, - .configure = efifb_configure, - .disabled = CONSOLE_DISABLED, -}; diff --git a/roms/ipxe/src/interface/efi/efi_file.c b/roms/ipxe/src/interface/efi/efi_file.c index 52de0987c..3715b70bf 100644 --- a/roms/ipxe/src/interface/efi/efi_file.c +++ b/roms/ipxe/src/interface/efi/efi_file.c @@ -47,6 +47,12 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <ipxe/efi/efi_strings.h> #include <ipxe/efi/efi_file.h> +/** EFI file information GUID */ +static EFI_GUID efi_file_info_id = EFI_FILE_INFO_ID; + +/** EFI file system information GUID */ +static EFI_GUID efi_file_system_info_id = EFI_FILE_SYSTEM_INFO_ID; + /** EFI media ID */ #define EFI_MEDIA_ID_MAGIC 0x69505845 @@ -608,9 +614,6 @@ int efi_file_install ( EFI_HANDLE handle ) { EFI_STATUS efirc; int rc; - /* Reset root directory state */ - efi_file_root.pos = 0; - /* Install the simple file system protocol, block I/O * protocol, and disk I/O protocol. We don't have a block * device, but large parts of the EDK2 codebase make the diff --git a/roms/ipxe/src/interface/efi/efi_guid.c b/roms/ipxe/src/interface/efi/efi_guid.c index 62ee5a517..ab1c91e9f 100644 --- a/roms/ipxe/src/interface/efi/efi_guid.c +++ b/roms/ipxe/src/interface/efi/efi_guid.c @@ -24,14 +24,11 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <ipxe/efi/efi.h> -#include <ipxe/efi/Protocol/AbsolutePointer.h> -#include <ipxe/efi/Protocol/AppleNetBoot.h> #include <ipxe/efi/Protocol/Arp.h> #include <ipxe/efi/Protocol/BlockIo.h> #include <ipxe/efi/Protocol/BusSpecificDriverOverride.h> #include <ipxe/efi/Protocol/ComponentName.h> #include <ipxe/efi/Protocol/ComponentName2.h> -#include <ipxe/efi/Protocol/ConsoleControl/ConsoleControl.h> #include <ipxe/efi/Protocol/DevicePath.h> #include <ipxe/efi/Protocol/DevicePathToText.h> #include <ipxe/efi/Protocol/Dhcp4.h> @@ -39,7 +36,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <ipxe/efi/Protocol/DriverBinding.h> #include <ipxe/efi/Protocol/GraphicsOutput.h> #include <ipxe/efi/Protocol/HiiConfigAccess.h> -#include <ipxe/efi/Protocol/HiiFont.h> #include <ipxe/efi/Protocol/Ip4.h> #include <ipxe/efi/Protocol/Ip4Config.h> #include <ipxe/efi/Protocol/LoadFile.h> @@ -51,24 +47,12 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <ipxe/efi/Protocol/PciIo.h> #include <ipxe/efi/Protocol/PciRootBridgeIo.h> #include <ipxe/efi/Protocol/PxeBaseCode.h> -#include <ipxe/efi/Protocol/SerialIo.h> #include <ipxe/efi/Protocol/SimpleFileSystem.h> #include <ipxe/efi/Protocol/SimpleNetwork.h> -#include <ipxe/efi/Protocol/SimplePointer.h> -#include <ipxe/efi/Protocol/SimpleTextIn.h> -#include <ipxe/efi/Protocol/SimpleTextInEx.h> -#include <ipxe/efi/Protocol/SimpleTextOut.h> #include <ipxe/efi/Protocol/TcgService.h> #include <ipxe/efi/Protocol/Tcp4.h> #include <ipxe/efi/Protocol/Udp4.h> -#include <ipxe/efi/Protocol/UgaDraw.h> -#include <ipxe/efi/Protocol/UnicodeCollation.h> -#include <ipxe/efi/Protocol/UsbHostController.h> -#include <ipxe/efi/Protocol/Usb2HostController.h> -#include <ipxe/efi/Protocol/UsbIo.h> #include <ipxe/efi/Protocol/VlanConfig.h> -#include <ipxe/efi/Guid/FileInfo.h> -#include <ipxe/efi/Guid/FileSystemInfo.h> /** @file * @@ -76,19 +60,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); * */ -/* TrEE protocol GUID definition in EDK2 headers is broken (missing braces) */ -#define EFI_TREE_PROTOCOL_GUID \ - { 0x607f766c, 0x7455, 0x42be, \ - { 0x93, 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f } } - -/** Absolute pointer protocol GUID */ -EFI_GUID efi_absolute_pointer_protocol_guid - = EFI_ABSOLUTE_POINTER_PROTOCOL_GUID; - -/** Apple NetBoot protocol GUID */ -EFI_GUID efi_apple_net_boot_protocol_guid - = EFI_APPLE_NET_BOOT_PROTOCOL_GUID; - /** ARP protocol GUID */ EFI_GUID efi_arp_protocol_guid = EFI_ARP_PROTOCOL_GUID; @@ -113,10 +84,6 @@ EFI_GUID efi_component_name_protocol_guid EFI_GUID efi_component_name2_protocol_guid = EFI_COMPONENT_NAME2_PROTOCOL_GUID; -/** Console control protocol GUID */ -EFI_GUID efi_console_control_protocol_guid - = EFI_CONSOLE_CONTROL_PROTOCOL_GUID; - /** Device path protocol GUID */ EFI_GUID efi_device_path_protocol_guid = EFI_DEVICE_PATH_PROTOCOL_GUID; @@ -145,10 +112,6 @@ EFI_GUID efi_graphics_output_protocol_guid EFI_GUID efi_hii_config_access_protocol_guid = EFI_HII_CONFIG_ACCESS_PROTOCOL_GUID; -/** HII font protocol GUID */ -EFI_GUID efi_hii_font_protocol_guid - = EFI_HII_FONT_PROTOCOL_GUID; - /** IPv4 protocol GUID */ EFI_GUID efi_ip4_protocol_guid = EFI_IP4_PROTOCOL_GUID; @@ -213,10 +176,6 @@ EFI_GUID efi_pci_root_bridge_io_protocol_guid EFI_GUID efi_pxe_base_code_protocol_guid = EFI_PXE_BASE_CODE_PROTOCOL_GUID; -/** Serial I/O protocol GUID */ -EFI_GUID efi_serial_io_protocol_guid - = EFI_SERIAL_IO_PROTOCOL_GUID; - /** Simple file system protocol GUID */ EFI_GUID efi_simple_file_system_protocol_guid = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID; @@ -225,22 +184,6 @@ EFI_GUID efi_simple_file_system_protocol_guid EFI_GUID efi_simple_network_protocol_guid = EFI_SIMPLE_NETWORK_PROTOCOL_GUID; -/** Simple pointer protocol GUID */ -EFI_GUID efi_simple_pointer_protocol_guid - = EFI_SIMPLE_POINTER_PROTOCOL_GUID; - -/** Simple text input protocol GUID */ -EFI_GUID efi_simple_text_input_protocol_guid - = EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID; - -/** Simple text input extension protocol GUID */ -EFI_GUID efi_simple_text_input_ex_protocol_guid - = EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID; - -/** Simple text output protocol GUID */ -EFI_GUID efi_simple_text_output_protocol_guid - = EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_GUID; - /** TCG protocol GUID */ EFI_GUID efi_tcg_protocol_guid = EFI_TCG_PROTOCOL_GUID; @@ -253,10 +196,6 @@ EFI_GUID efi_tcp4_protocol_guid EFI_GUID efi_tcp4_service_binding_protocol_guid = EFI_TCP4_SERVICE_BINDING_PROTOCOL_GUID; -/** TrEE protocol GUID */ -EFI_GUID efi_tree_protocol_guid - = EFI_TREE_PROTOCOL_GUID; - /** UDPv4 protocol GUID */ EFI_GUID efi_udp4_protocol_guid = EFI_UDP4_PROTOCOL_GUID; @@ -265,32 +204,6 @@ EFI_GUID efi_udp4_protocol_guid EFI_GUID efi_udp4_service_binding_protocol_guid = EFI_UDP4_SERVICE_BINDING_PROTOCOL_GUID; -/** UGA draw protocol GUID */ -EFI_GUID efi_uga_draw_protocol_guid - = EFI_UGA_DRAW_PROTOCOL_GUID; - -/** Unicode collation protocol GUID */ -EFI_GUID efi_unicode_collation_protocol_guid - = EFI_UNICODE_COLLATION_PROTOCOL_GUID; - -/** USB host controller protocol GUID */ -EFI_GUID efi_usb_hc_protocol_guid - = EFI_USB_HC_PROTOCOL_GUID; - -/** USB2 host controller protocol GUID */ -EFI_GUID efi_usb2_hc_protocol_guid - = EFI_USB2_HC_PROTOCOL_GUID; - -/** USB I/O protocol GUID */ -EFI_GUID efi_usb_io_protocol_guid - = EFI_USB_IO_PROTOCOL_GUID; - /** VLAN configuration protocol GUID */ EFI_GUID efi_vlan_config_protocol_guid = EFI_VLAN_CONFIG_PROTOCOL_GUID; - -/** File information GUID */ -EFI_GUID efi_file_info_id = EFI_FILE_INFO_ID; - -/** File system information GUID */ -EFI_GUID efi_file_system_info_id = EFI_FILE_SYSTEM_INFO_ID; diff --git a/roms/ipxe/src/interface/efi/efi_local.c b/roms/ipxe/src/interface/efi/efi_local.c deleted file mode 100644 index bd010ad2e..000000000 --- a/roms/ipxe/src/interface/efi/efi_local.c +++ /dev/null @@ -1,573 +0,0 @@ -/* - * Copyright (C) 2016 Michael Brown <mbrown@fensystems.co.uk>. - * - * 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 (at your option) 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 <string.h> -#include <strings.h> -#include <stdio.h> -#include <errno.h> -#include <assert.h> -#include <ipxe/refcnt.h> -#include <ipxe/malloc.h> -#include <ipxe/xfer.h> -#include <ipxe/open.h> -#include <ipxe/uri.h> -#include <ipxe/iobuf.h> -#include <ipxe/process.h> -#include <ipxe/efi/efi.h> -#include <ipxe/efi/efi_strings.h> -#include <ipxe/efi/efi_utils.h> -#include <ipxe/efi/Protocol/SimpleFileSystem.h> -#include <ipxe/efi/Guid/FileInfo.h> -#include <ipxe/efi/Guid/FileSystemInfo.h> - -/** @file - * - * EFI local file access - * - */ - -/** Download blocksize */ -#define EFI_LOCAL_BLKSIZE 4096 - -/** An EFI local file */ -struct efi_local { - /** Reference count */ - struct refcnt refcnt; - /** Data transfer interface */ - struct interface xfer; - /** Download process */ - struct process process; - - /** EFI root directory */ - EFI_FILE_PROTOCOL *root; - /** EFI file */ - EFI_FILE_PROTOCOL *file; - /** Length of file */ - size_t len; -}; - -/** - * Close local file - * - * @v local Local file - * @v rc Reason for close - */ -static void efi_local_close ( struct efi_local *local, int rc ) { - - /* Stop process */ - process_del ( &local->process ); - - /* Shut down data transfer interface */ - intf_shutdown ( &local->xfer, rc ); - - /* Close EFI file */ - if ( local->file ) { - local->file->Close ( local->file ); - local->file = NULL; - } - - /* Close EFI root directory */ - if ( local->root ) { - local->root->Close ( local->root ); - local->root = NULL; - } -} - -/** - * Local file process - * - * @v local Local file - */ -static void efi_local_step ( struct efi_local *local ) { - EFI_FILE_PROTOCOL *file = local->file; - struct io_buffer *iobuf = NULL; - size_t remaining; - size_t frag_len; - UINTN size; - EFI_STATUS efirc; - int rc; - - /* Wait until data transfer interface is ready */ - if ( ! xfer_window ( &local->xfer ) ) - return; - - /* Presize receive buffer */ - remaining = local->len; - xfer_seek ( &local->xfer, remaining ); - xfer_seek ( &local->xfer, 0 ); - - /* Get file contents */ - while ( remaining ) { - - /* Calculate length for this fragment */ - frag_len = remaining; - if ( frag_len > EFI_LOCAL_BLKSIZE ) - frag_len = EFI_LOCAL_BLKSIZE; - - /* Allocate I/O buffer */ - iobuf = xfer_alloc_iob ( &local->xfer, frag_len ); - if ( ! iobuf ) { - rc = -ENOMEM; - goto err; - } - - /* Read block */ - size = frag_len; - if ( ( efirc = file->Read ( file, &size, iobuf->data ) ) != 0 ){ - rc = -EEFI ( efirc ); - DBGC ( local, "LOCAL %p could not read from file: %s\n", - local, strerror ( rc ) ); - goto err; - } - assert ( size <= frag_len ); - iob_put ( iobuf, size ); - - /* Deliver data */ - if ( ( rc = xfer_deliver_iob ( &local->xfer, - iob_disown ( iobuf ) ) ) != 0 ) { - DBGC ( local, "LOCAL %p could not deliver data: %s\n", - local, strerror ( rc ) ); - goto err; - } - - /* Move to next block */ - remaining -= frag_len; - } - - /* Close download */ - efi_local_close ( local, 0 ); - - return; - - err: - free_iob ( iobuf ); - efi_local_close ( local, rc ); -} - -/** Data transfer interface operations */ -static struct interface_operation efi_local_operations[] = { - INTF_OP ( xfer_window_changed, struct efi_local *, efi_local_step ), - INTF_OP ( intf_close, struct efi_local *, efi_local_close ), -}; - -/** Data transfer interface descriptor */ -static struct interface_descriptor efi_local_xfer_desc = - INTF_DESC ( struct efi_local, xfer, efi_local_operations ); - -/** Process descriptor */ -static struct process_descriptor efi_local_process_desc = - PROC_DESC_ONCE ( struct efi_local, process, efi_local_step ); - -/** - * Check for matching volume name - * - * @v local Local file - * @v device Device handle - * @v root Root filesystem handle - * @v volume Volume name - * @ret rc Return status code - */ -static int efi_local_check_volume_name ( struct efi_local *local, - EFI_HANDLE device, - EFI_FILE_PROTOCOL *root, - const char *volume ) { - EFI_FILE_SYSTEM_INFO *info; - UINTN size; - char *label; - EFI_STATUS efirc; - int rc; - - /* Get length of file system information */ - size = 0; - root->GetInfo ( root, &efi_file_system_info_id, &size, NULL ); - - /* Allocate file system information */ - info = malloc ( size ); - if ( ! info ) { - rc = -ENOMEM; - goto err_alloc_info; - } - - /* Get file system information */ - if ( ( efirc = root->GetInfo ( root, &efi_file_system_info_id, &size, - info ) ) != 0 ) { - rc = -EEFI ( efirc ); - DBGC ( local, "LOCAL %p could not get file system info on %s: " - "%s\n", local, efi_handle_name ( device ), - strerror ( rc ) ); - goto err_get_info; - } - DBGC2 ( local, "LOCAL %p found %s with label \"%ls\"\n", - local, efi_handle_name ( device ), info->VolumeLabel ); - - /* Construct volume label for comparison */ - if ( asprintf ( &label, "%ls", info->VolumeLabel ) < 0 ) { - rc = -ENOMEM; - goto err_alloc_label; - } - - /* Compare volume label */ - if ( strcasecmp ( volume, label ) != 0 ) { - rc = -ENOENT; - goto err_compare; - } - - /* Success */ - rc = 0; - - err_compare: - free ( label ); - err_alloc_label: - err_get_info: - free ( info ); - err_alloc_info: - return rc; -} - -/** - * Open root filesystem - * - * @v local Local file - * @v device Device handle - * @v root Root filesystem handle to fill in - * @ret rc Return status code - */ -static int efi_local_open_root ( struct efi_local *local, EFI_HANDLE device, - EFI_FILE_PROTOCOL **root ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - union { - void *interface; - EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *fs; - } u; - EFI_STATUS efirc; - int rc; - - /* Open file system protocol */ - if ( ( efirc = bs->OpenProtocol ( device, - &efi_simple_file_system_protocol_guid, - &u.interface, efi_image_handle, - device, - EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){ - rc = -EEFI ( efirc ); - DBGC ( local, "LOCAL %p could not open filesystem on %s: %s\n", - local, efi_handle_name ( device ), strerror ( rc ) ); - goto err_filesystem; - } - - /* Open root directory */ - if ( ( efirc = u.fs->OpenVolume ( u.fs, root ) ) != 0 ) { - rc = -EEFI ( efirc ); - DBGC ( local, "LOCAL %p could not open volume on %s: %s\n", - local, efi_handle_name ( device ), strerror ( rc ) ); - goto err_volume; - } - - /* Success */ - rc = 0; - - err_volume: - bs->CloseProtocol ( device, &efi_simple_file_system_protocol_guid, - efi_image_handle, device ); - err_filesystem: - return rc; -} - -/** - * Open root filesystem of specified volume - * - * @v local Local file - * @v volume Volume name, or NULL to use loaded image's device - * @ret rc Return status code - */ -static int efi_local_open_volume ( struct efi_local *local, - const char *volume ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - EFI_GUID *protocol = &efi_simple_file_system_protocol_guid; - int ( * check ) ( struct efi_local *local, EFI_HANDLE device, - EFI_FILE_PROTOCOL *root, const char *volume ); - EFI_FILE_PROTOCOL *root; - EFI_HANDLE *handles; - EFI_HANDLE device; - UINTN num_handles; - UINTN i; - EFI_STATUS efirc; - int rc; - - /* Identify candidate handles */ - if ( volume ) { - /* Locate all filesystem handles */ - if ( ( efirc = bs->LocateHandleBuffer ( ByProtocol, protocol, - NULL, &num_handles, - &handles ) ) != 0 ) { - rc = -EEFI ( efirc ); - DBGC ( local, "LOCAL %p could not enumerate handles: " - "%s\n", local, strerror ( rc ) ); - return rc; - } - check = efi_local_check_volume_name; - } else { - /* Use our loaded image's device handle */ - handles = &efi_loaded_image->DeviceHandle; - num_handles = 1; - check = NULL; - } - - /* Find matching handle */ - for ( i = 0 ; i < num_handles ; i++ ) { - - /* Get this device handle */ - device = handles[i]; - - /* Open root directory */ - if ( ( rc = efi_local_open_root ( local, device, &root ) ) != 0) - continue; - - /* Check volume name, if applicable */ - if ( ( check == NULL ) || - ( ( rc = check ( local, device, root, volume ) ) == 0 ) ) { - DBGC ( local, "LOCAL %p using %s", - local, efi_handle_name ( device ) ); - if ( volume ) - DBGC ( local, " with label \"%s\"", volume ); - DBGC ( local, "\n" ); - local->root = root; - break; - } - - /* Close root directory */ - root->Close ( root ); - } - - /* Free handles, if applicable */ - if ( volume ) - bs->FreePool ( handles ); - - /* Fail if we found no matching handle */ - if ( ! local->root ) { - DBGC ( local, "LOCAL %p found no matching handle\n", local ); - return -ENOENT; - } - - return 0; -} - -/** - * Open fully-resolved path - * - * @v local Local file - * @v resolved Resolved path - * @ret rc Return status code - */ -static int efi_local_open_resolved ( struct efi_local *local, - const char *resolved ) { - size_t name_len = strlen ( resolved ); - CHAR16 name[ name_len + 1 /* wNUL */ ]; - EFI_FILE_PROTOCOL *file; - EFI_STATUS efirc; - int rc; - - /* Construct filename */ - efi_snprintf ( name, ( name_len + 1 /* wNUL */ ), "%s", resolved ); - - /* Open file */ - if ( ( efirc = local->root->Open ( local->root, &file, name, - EFI_FILE_MODE_READ, 0 ) ) != 0 ) { - rc = -EEFI ( efirc ); - DBGC ( local, "LOCAL %p could not open \"%s\": %s\n", - local, resolved, strerror ( rc ) ); - return rc; - } - local->file = file; - - return 0; -} - -/** - * Open specified path - * - * @v local Local file - * @v path Path to file - * @ret rc Return status code - */ -static int efi_local_open_path ( struct efi_local *local, const char *path ) { - FILEPATH_DEVICE_PATH *fp = container_of ( efi_loaded_image->FilePath, - FILEPATH_DEVICE_PATH, Header); - size_t fp_len = ( fp ? efi_devpath_len ( &fp->Header ) : 0 ); - char base[ fp_len / 2 /* Cannot exceed this length */ ]; - size_t remaining = sizeof ( base ); - size_t len; - char *resolved; - char *tmp; - int rc; - - /* Construct base path to our own image, if possible */ - memset ( base, 0, sizeof ( base ) ); - tmp = base; - while ( fp && ( fp->Header.Type != END_DEVICE_PATH_TYPE ) ) { - len = snprintf ( tmp, remaining, "%ls", fp->PathName ); - assert ( len < remaining ); - tmp += len; - remaining -= len; - fp = ( ( ( void * ) fp ) + ( ( fp->Header.Length[1] << 8 ) | - fp->Header.Length[0] ) ); - } - DBGC2 ( local, "LOCAL %p base path \"%s\"\n", - local, base ); - - /* Convert to sane path separators */ - for ( tmp = base ; *tmp ; tmp++ ) { - if ( *tmp == '\\' ) - *tmp = '/'; - } - - /* Resolve path */ - resolved = resolve_path ( base, path ); - if ( ! resolved ) { - rc = -ENOMEM; - goto err_resolve; - } - - /* Convert to insane path separators */ - for ( tmp = resolved ; *tmp ; tmp++ ) { - if ( *tmp == '/' ) - *tmp = '\\'; - } - DBGC ( local, "LOCAL %p using \"%s\"\n", - local, resolved ); - - /* Open resolved path */ - if ( ( rc = efi_local_open_resolved ( local, resolved ) ) != 0 ) - goto err_open; - - err_open: - free ( resolved ); - err_resolve: - return rc; -} - -/** - * Get file length - * - * @v local Local file - * @ret rc Return status code - */ -static int efi_local_len ( struct efi_local *local ) { - EFI_FILE_PROTOCOL *file = local->file; - EFI_FILE_INFO *info; - EFI_STATUS efirc; - UINTN size; - int rc; - - /* Get size of file information */ - size = 0; - file->GetInfo ( file, &efi_file_info_id, &size, NULL ); - - /* Allocate file information */ - info = malloc ( size ); - if ( ! info ) { - rc = -ENOMEM; - goto err_alloc; - } - - /* Get file information */ - if ( ( efirc = file->GetInfo ( file, &efi_file_info_id, &size, - info ) ) != 0 ) { - rc = -EEFI ( efirc ); - DBGC ( local, "LOCAL %p could not get file info: %s\n", - local, strerror ( rc ) ); - goto err_info; - } - - /* Record file length */ - local->len = info->FileSize; - - /* Success */ - rc = 0; - - err_info: - free ( info ); - err_alloc: - return rc; -} - -/** - * Open local file - * - * @v xfer Data transfer interface - * @v uri Request URI - * @ret rc Return status code - */ -static int efi_local_open ( struct interface *xfer, struct uri *uri ) { - struct efi_local *local; - const char *volume; - const char *path; - int rc; - - /* Parse URI */ - volume = ( ( uri->host && uri->host[0] ) ? uri->host : NULL ); - path = ( uri->opaque ? uri->opaque : uri->path ); - - /* Allocate and initialise structure */ - local = zalloc ( sizeof ( *local ) ); - if ( ! local ) { - rc = -ENOMEM; - goto err_alloc; - } - ref_init ( &local->refcnt, NULL ); - intf_init ( &local->xfer, &efi_local_xfer_desc, &local->refcnt ); - process_init ( &local->process, &efi_local_process_desc, - &local->refcnt ); - - /* Open specified volume */ - if ( ( rc = efi_local_open_volume ( local, volume ) ) != 0 ) - goto err_open_root; - - /* Open specified path */ - if ( ( rc = efi_local_open_path ( local, path ) ) != 0 ) - goto err_open_file; - - /* Get length of file */ - if ( ( rc = efi_local_len ( local ) ) != 0 ) - goto err_len; - - /* Attach to parent interface, mortalise self, and return */ - intf_plug_plug ( &local->xfer, xfer ); - ref_put ( &local->refcnt ); - return 0; - - err_len: - err_open_file: - err_open_root: - efi_local_close ( local, 0 ); - ref_put ( &local->refcnt ); - err_alloc: - return rc; -} - -/** EFI local file URI opener */ -struct uri_opener efi_local_uri_opener __uri_opener = { - .scheme = "file", - .open = efi_local_open, -}; diff --git a/roms/ipxe/src/interface/efi/efi_pci.c b/roms/ipxe/src/interface/efi/efi_pci.c index 9f0851a56..97ea72bb9 100644 --- a/roms/ipxe/src/interface/efi/efi_pci.c +++ b/roms/ipxe/src/interface/efi/efi_pci.c @@ -61,157 +61,58 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); ****************************************************************************** */ -/** - * Locate EFI PCI root bridge I/O protocol - * - * @v pci PCI device - * @ret handle EFI PCI root bridge handle - * @ret root EFI PCI root bridge I/O protocol, or NULL if not found - * @ret rc Return status code - */ -static int efipci_root ( struct pci_device *pci, EFI_HANDLE *handle, - EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL **root ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - EFI_HANDLE *handles; - UINTN num_handles; - union { - void *interface; - EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *root; - } u; - EFI_STATUS efirc; - UINTN i; - int rc; +/** PCI root bridge I/O protocol */ +static EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *efipci; +EFI_REQUEST_PROTOCOL ( EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL, &efipci ); - /* Enumerate all handles */ - if ( ( efirc = bs->LocateHandleBuffer ( ByProtocol, - &efi_pci_root_bridge_io_protocol_guid, - NULL, &num_handles, &handles ) ) != 0 ) { - rc = -EEFI ( efirc ); - DBGC ( pci, "EFIPCI cannot locate root bridges: %s\n", - strerror ( rc ) ); - goto err_locate; - } - - /* Look for matching root bridge I/O protocol */ - for ( i = 0 ; i < num_handles ; i++ ) { - *handle = handles[i]; - if ( ( efirc = bs->OpenProtocol ( *handle, - &efi_pci_root_bridge_io_protocol_guid, - &u.interface, efi_image_handle, *handle, - EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) { - rc = -EEFI ( efirc ); - DBGC ( pci, "EFIPCI cannot open %s: %s\n", - efi_handle_name ( *handle ), strerror ( rc ) ); - continue; - } - if ( u.root->SegmentNumber == PCI_SEG ( pci->busdevfn ) ) { - *root = u.root; - bs->FreePool ( handles ); - return 0; - } - bs->CloseProtocol ( *handle, - &efi_pci_root_bridge_io_protocol_guid, - efi_image_handle, *handle ); - } - DBGC ( pci, "EFIPCI found no root bridge for " PCI_FMT "\n", - PCI_ARGS ( pci ) ); - rc = -ENOENT; - - bs->FreePool ( handles ); - err_locate: - return rc; -} - -/** - * Calculate EFI PCI configuration space address - * - * @v pci PCI device - * @v location Encoded offset and width - * @ret address EFI PCI address - */ static unsigned long efipci_address ( struct pci_device *pci, unsigned long location ) { - return EFI_PCI_ADDRESS ( PCI_BUS ( pci->busdevfn ), PCI_SLOT ( pci->busdevfn ), PCI_FUNC ( pci->busdevfn ), EFIPCI_OFFSET ( location ) ); } -/** - * Read from PCI configuration space - * - * @v pci PCI device - * @v location Encoded offset and width - * @ret value Value - * @ret rc Return status code - */ int efipci_read ( struct pci_device *pci, unsigned long location, void *value ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *root; - EFI_HANDLE handle; EFI_STATUS efirc; int rc; - /* Identify root bridge */ - if ( ( rc = efipci_root ( pci, &handle, &root ) ) != 0 ) - goto err_root; + if ( ! efipci ) + return -ENOTSUP; - /* Read from configuration space */ - if ( ( efirc = root->Pci.Read ( root, EFIPCI_WIDTH ( location ), - efipci_address ( pci, location ), 1, - value ) ) != 0 ) { + if ( ( efirc = efipci->Pci.Read ( efipci, EFIPCI_WIDTH ( location ), + efipci_address ( pci, location ), 1, + value ) ) != 0 ) { rc = -EEFI ( efirc ); DBG ( "EFIPCI config read from " PCI_FMT " offset %02lx " "failed: %s\n", PCI_ARGS ( pci ), EFIPCI_OFFSET ( location ), strerror ( rc ) ); - goto err_read; + return -EIO; } - err_read: - bs->CloseProtocol ( handle, &efi_pci_root_bridge_io_protocol_guid, - efi_image_handle, handle ); - err_root: - return rc; + return 0; } -/** - * Write to PCI configuration space - * - * @v pci PCI device - * @v location Encoded offset and width - * @v value Value - * @ret rc Return status code - */ int efipci_write ( struct pci_device *pci, unsigned long location, unsigned long value ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *root; - EFI_HANDLE handle; EFI_STATUS efirc; int rc; - /* Identify root bridge */ - if ( ( rc = efipci_root ( pci, &handle, &root ) ) != 0 ) - goto err_root; + if ( ! efipci ) + return -ENOTSUP; - /* Read from configuration space */ - if ( ( efirc = root->Pci.Write ( root, EFIPCI_WIDTH ( location ), - efipci_address ( pci, location ), 1, - &value ) ) != 0 ) { + if ( ( efirc = efipci->Pci.Write ( efipci, EFIPCI_WIDTH ( location ), + efipci_address ( pci, location ), 1, + &value ) ) != 0 ) { rc = -EEFI ( efirc ); DBG ( "EFIPCI config write to " PCI_FMT " offset %02lx " "failed: %s\n", PCI_ARGS ( pci ), EFIPCI_OFFSET ( location ), strerror ( rc ) ); - goto err_write; + return -EIO; } - err_write: - bs->CloseProtocol ( handle, &efi_pci_root_bridge_io_protocol_guid, - efi_image_handle, handle ); - err_root: - return rc; + return 0; } PROVIDE_PCIAPI_INLINE ( efi, pci_num_bus ); @@ -245,7 +146,6 @@ int efipci_open ( EFI_HANDLE device, UINT32 attributes, void *interface; } pci_io; UINTN pci_segment, pci_bus, pci_dev, pci_fn; - unsigned int busdevfn; EFI_STATUS efirc; int rc; @@ -254,8 +154,8 @@ int efipci_open ( EFI_HANDLE device, UINT32 attributes, &pci_io.interface, efi_image_handle, device, attributes ) ) != 0 ) { rc = -EEFI_PCI ( efirc ); - DBGCP ( device, "EFIPCI %s cannot open PCI protocols: %s\n", - efi_handle_name ( device ), strerror ( rc ) ); + DBGCP ( device, "EFIPCI %p %s cannot open PCI protocols: %s\n", + device, efi_handle_name ( device ), strerror ( rc ) ); goto err_open_protocol; } @@ -264,11 +164,11 @@ int efipci_open ( EFI_HANDLE device, UINT32 attributes, &pci_bus, &pci_dev, &pci_fn ) ) != 0 ) { rc = -EEFI ( efirc ); - DBGC ( device, "EFIPCI %s could not get PCI location: %s\n", - efi_handle_name ( device ), strerror ( rc ) ); + DBGC ( device, "EFIPCI %p %s could not get PCI location: %s\n", + device, efi_handle_name ( device ), strerror ( rc ) ); goto err_get_location; } - DBGC2 ( device, "EFIPCI %s is PCI %04lx:%02lx:%02lx.%lx\n", + DBGC2 ( device, "EFIPCI %p %s is PCI %04lx:%02lx:%02lx.%lx\n", device, efi_handle_name ( device ), ( ( unsigned long ) pci_segment ), ( ( unsigned long ) pci_bus ), ( ( unsigned long ) pci_dev ), ( ( unsigned long ) pci_fn ) ); @@ -290,11 +190,11 @@ int efipci_open ( EFI_HANDLE device, UINT32 attributes, EFI_PCI_IO_ATTRIBUTE_BUS_MASTER, NULL ); /* Populate PCI device */ - busdevfn = PCI_BUSDEVFN ( pci_segment, pci_bus, pci_dev, pci_fn ); - pci_init ( pci, busdevfn ); + pci_init ( pci, PCI_BUSDEVFN ( pci_bus, pci_dev, pci_fn ) ); if ( ( rc = pci_read_config ( pci ) ) != 0 ) { - DBGC ( device, "EFIPCI %s cannot read PCI configuration: %s\n", - efi_handle_name ( device ), strerror ( rc ) ); + DBGC ( device, "EFIPCI %p %s cannot read PCI configuration: " + "%s\n", device, efi_handle_name ( device ), + strerror ( rc ) ); goto err_pci_read_config; } @@ -364,12 +264,12 @@ static int efipci_supported ( EFI_HANDLE device ) { /* Look for a driver */ if ( ( rc = pci_find_driver ( &pci ) ) != 0 ) { - DBGCP ( device, "EFIPCI %s has no driver\n", - efi_handle_name ( device ) ); + DBGCP ( device, "EFIPCI %p %s has no driver\n", + device, efi_handle_name ( device ) ); return rc; } - DBGC ( device, "EFIPCI %s has driver \"%s\"\n", - efi_handle_name ( device ), pci.id->name ); + DBGC ( device, "EFIPCI %p %s has driver \"%s\"\n", + device, efi_handle_name ( device ), pci.id->name ); return 0; } @@ -396,16 +296,16 @@ static int efipci_start ( struct efi_device *efidev ) { if ( ( rc = efipci_open ( device, ( EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE ), pci ) ) != 0 ) { - DBGC ( device, "EFIPCI %s could not open PCI device: %s\n", - efi_handle_name ( device ), strerror ( rc ) ); + DBGC ( device, "EFIPCI %p %s could not open PCI device: %s\n", + device, efi_handle_name ( device ), strerror ( rc ) ); DBGC_EFI_OPENERS ( device, device, &efi_pci_io_protocol_guid ); goto err_open; } /* Find driver */ if ( ( rc = pci_find_driver ( pci ) ) != 0 ) { - DBGC ( device, "EFIPCI %s has no driver\n", - efi_handle_name ( device ) ); + DBGC ( device, "EFIPCI %p %s has no driver\n", + device, efi_handle_name ( device ) ); goto err_find_driver; } @@ -415,13 +315,13 @@ static int efipci_start ( struct efi_device *efidev ) { /* Probe driver */ if ( ( rc = pci_probe ( pci ) ) != 0 ) { - DBGC ( device, "EFIPCI %s could not probe driver \"%s\": %s\n", - efi_handle_name ( device ), pci->id->name, - strerror ( rc ) ); + DBGC ( device, "EFIPCI %p %s could not probe driver \"%s\": " + "%s\n", device, efi_handle_name ( device ), + pci->id->name, strerror ( rc ) ); goto err_probe; } - DBGC ( device, "EFIPCI %s using driver \"%s\"\n", - efi_handle_name ( device ), pci->id->name ); + DBGC ( device, "EFIPCI %p %s using driver \"%s\"\n", + device, efi_handle_name ( device ), pci->id->name ); efidev_set_drvdata ( efidev, pci ); return 0; diff --git a/roms/ipxe/src/interface/efi/efi_pxe.c b/roms/ipxe/src/interface/efi/efi_pxe.c deleted file mode 100644 index a1f81df59..000000000 --- a/roms/ipxe/src/interface/efi/efi_pxe.c +++ /dev/null @@ -1,1687 +0,0 @@ -/* - * Copyright (C) 2015 Michael Brown <mbrown@fensystems.co.uk>. - * - * 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 (at your option) 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 <string.h> -#include <errno.h> -#include <ipxe/refcnt.h> -#include <ipxe/list.h> -#include <ipxe/netdevice.h> -#include <ipxe/fakedhcp.h> -#include <ipxe/process.h> -#include <ipxe/uri.h> -#include <ipxe/in.h> -#include <ipxe/socket.h> -#include <ipxe/tcpip.h> -#include <ipxe/xferbuf.h> -#include <ipxe/open.h> -#include <ipxe/dhcppkt.h> -#include <ipxe/udp.h> -#include <ipxe/efi/efi.h> -#include <ipxe/efi/efi_snp.h> -#include <ipxe/efi/efi_pxe.h> -#include <ipxe/efi/Protocol/PxeBaseCode.h> -#include <ipxe/efi/Protocol/AppleNetBoot.h> -#include <usr/ifmgmt.h> -#include <config/general.h> - -/** @file - * - * EFI PXE base code protocol - * - */ - -/* Downgrade user experience if configured to do so - * - * See comments in efi_snp.c - */ -#ifdef EFI_DOWNGRADE_UX -static EFI_GUID dummy_pxe_base_code_protocol_guid = { - 0x70647523, 0x2320, 0x7477, - { 0x66, 0x20, 0x23, 0x6d, 0x6f, 0x72, 0x6f, 0x6e } -}; -#define efi_pxe_base_code_protocol_guid dummy_pxe_base_code_protocol_guid -#endif - -/** A PXE base code */ -struct efi_pxe { - /** Reference count */ - struct refcnt refcnt; - /** Underlying network device */ - struct net_device *netdev; - /** Name */ - const char *name; - /** List of PXE base codes */ - struct list_head list; - - /** Installed handle */ - EFI_HANDLE handle; - /** PXE base code protocol */ - EFI_PXE_BASE_CODE_PROTOCOL base; - /** PXE base code mode */ - EFI_PXE_BASE_CODE_MODE mode; - /** Apple NetBoot protocol */ - EFI_APPLE_NET_BOOT_PROTOCOL apple; - - /** TCP/IP network-layer protocol */ - struct tcpip_net_protocol *tcpip; - /** Network-layer protocol */ - struct net_protocol *net; - - /** Data transfer buffer */ - struct xfer_buffer buf; - - /** (M)TFTP download interface */ - struct interface tftp; - /** Block size (for TFTP) */ - size_t blksize; - /** Overall return status */ - int rc; - - /** UDP interface */ - struct interface udp; - /** List of received UDP packets */ - struct list_head queue; - /** UDP interface closer process */ - struct process process; -}; - -/** - * Free PXE base code - * - * @v refcnt Reference count - */ -static void efi_pxe_free ( struct refcnt *refcnt ) { - struct efi_pxe *pxe = container_of ( refcnt, struct efi_pxe, refcnt ); - - netdev_put ( pxe->netdev ); - free ( pxe ); -} - -/** List of PXE base codes */ -static LIST_HEAD ( efi_pxes ); - -/** - * Locate PXE base code - * - * @v handle EFI handle - * @ret pxe PXE base code, or NULL - */ -static struct efi_pxe * efi_pxe_find ( EFI_HANDLE handle ) { - struct efi_pxe *pxe; - - /* Locate base code */ - list_for_each_entry ( pxe, &efi_pxes, list ) { - if ( pxe->handle == handle ) - return pxe; - } - - return NULL; -} - -/****************************************************************************** - * - * IP addresses - * - ****************************************************************************** - */ - -/** - * An EFI socket address - * - */ -struct sockaddr_efi { - /** Socket address family (part of struct @c sockaddr) */ - sa_family_t se_family; - /** Flags (part of struct @c sockaddr_tcpip) */ - uint16_t se_flags; - /** TCP/IP port (part of struct @c sockaddr_tcpip) */ - uint16_t se_port; - /** Scope ID (part of struct @c sockaddr_tcpip) - * - * For link-local or multicast addresses, this is the network - * device index. - */ - uint16_t se_scope_id; - /** IP address */ - EFI_IP_ADDRESS se_addr; - /** Padding - * - * This ensures that a struct @c sockaddr_tcpip is large - * enough to hold a socket address for any TCP/IP address - * family. - */ - char pad[ sizeof ( struct sockaddr ) - - ( sizeof ( sa_family_t ) /* se_family */ + - sizeof ( uint16_t ) /* se_flags */ + - sizeof ( uint16_t ) /* se_port */ + - sizeof ( uint16_t ) /* se_scope_id */ + - sizeof ( EFI_IP_ADDRESS ) /* se_addr */ ) ]; -} __attribute__ (( packed, may_alias )); - -/** - * Populate socket address from EFI IP address - * - * @v pxe PXE base code - * @v ip EFI IP address - * @v sa Socket address to fill in - */ -static void efi_pxe_ip_sockaddr ( struct efi_pxe *pxe, EFI_IP_ADDRESS *ip, - struct sockaddr *sa ) { - union { - struct sockaddr sa; - struct sockaddr_efi se; - } *sockaddr = container_of ( sa, typeof ( *sockaddr ), sa ); - - /* Initialise socket address */ - memset ( sockaddr, 0, sizeof ( *sockaddr ) ); - sockaddr->sa.sa_family = pxe->tcpip->sa_family; - memcpy ( &sockaddr->se.se_addr, ip, pxe->net->net_addr_len ); - sockaddr->se.se_scope_id = pxe->netdev->index; -} - -/** - * Transcribe EFI IP address (for debugging) - * - * @v pxe PXE base code - * @v ip EFI IP address - * @ret text Transcribed IP address - */ -static const char * efi_pxe_ip_ntoa ( struct efi_pxe *pxe, - EFI_IP_ADDRESS *ip ) { - - return pxe->net->ntoa ( ip ); -} - -/** - * Populate local IP address - * - * @v pxe PXE base code - * @ret rc Return status code - */ -static int efi_pxe_ip ( struct efi_pxe *pxe ) { - EFI_PXE_BASE_CODE_MODE *mode = &pxe->mode; - struct in_addr address; - struct in_addr netmask; - - /* It's unclear which of the potentially many IPv6 addresses - * is supposed to be used. - */ - if ( mode->UsingIpv6 ) - return -ENOTSUP; - - /* Fetch IP address and subnet mask */ - fetch_ipv4_setting ( netdev_settings ( pxe->netdev ), &ip_setting, - &address ); - fetch_ipv4_setting ( netdev_settings ( pxe->netdev ), &netmask_setting, - &netmask ); - - /* Populate IP address and subnet mask */ - memset ( &mode->StationIp, 0, sizeof ( mode->StationIp ) ); - memcpy ( &mode->StationIp, &address, sizeof ( address ) ); - memset ( &mode->SubnetMask, 0, sizeof ( mode->SubnetMask ) ); - memcpy ( &mode->SubnetMask, &netmask, sizeof ( netmask ) ); - - return 0; -} - -/** - * Check if IP address matches filter - * - * @v pxe PXE base code - * @v ip EFI IP address - * @ret is_match IP address matches filter - */ -static int efi_pxe_ip_filter ( struct efi_pxe *pxe, EFI_IP_ADDRESS *ip ) { - EFI_PXE_BASE_CODE_MODE *mode = &pxe->mode; - EFI_PXE_BASE_CODE_IP_FILTER *filter = &mode->IpFilter; - uint8_t filters = filter->Filters; - union { - EFI_IP_ADDRESS ip; - struct in_addr in; - struct in6_addr in6; - } *u = container_of ( ip, typeof ( *u ), ip ); - size_t addr_len = pxe->net->net_addr_len; - unsigned int i; - - /* Match everything, if applicable */ - if ( filters & EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS ) - return 1; - - /* Match all multicasts, if applicable */ - if ( filters & EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS_MULTICAST ) { - if ( mode->UsingIpv6 ) { - if ( IN6_IS_ADDR_MULTICAST ( &u->in6 ) ) - return 1; - } else { - if ( IN_IS_MULTICAST ( u->in.s_addr ) ) - return 1; - } - } - - /* Match IPv4 broadcasts, if applicable */ - if ( filters & EFI_PXE_BASE_CODE_IP_FILTER_BROADCAST ) { - if ( ( ! mode->UsingIpv6 ) && - ( u->in.s_addr == INADDR_BROADCAST ) ) - return 1; - } - - /* Match station address, if applicable */ - if ( filters & EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP ) { - if ( memcmp ( ip, &mode->StationIp, addr_len ) == 0 ) - return 1; - } - - /* Match explicit addresses, if applicable */ - for ( i = 0 ; i < filter->IpCnt ; i++ ) { - if ( memcmp ( ip, &filter->IpList[i], addr_len ) == 0 ) - return 1; - } - - return 0; -} - -/****************************************************************************** - * - * Data transfer buffer - * - ****************************************************************************** - */ - -/** - * Reallocate PXE data transfer buffer - * - * @v xferbuf Data transfer buffer - * @v len New length (or zero to free buffer) - * @ret rc Return status code - */ -static int efi_pxe_buf_realloc ( struct xfer_buffer *xferbuf __unused, - size_t len __unused ) { - - /* Can never reallocate: return EFI_BUFFER_TOO_SMALL */ - return -ERANGE; -} - -/** - * Write data to PXE data transfer buffer - * - * @v xferbuf Data transfer buffer - * @v offset Starting offset - * @v data Data to copy - * @v len Length of data - */ -static void efi_pxe_buf_write ( struct xfer_buffer *xferbuf, size_t offset, - const void *data, size_t len ) { - - /* Copy data to buffer */ - memcpy ( ( xferbuf->data + offset ), data, len ); -} - -/** PXE data transfer buffer operations */ -static struct xfer_buffer_operations efi_pxe_buf_operations = { - .realloc = efi_pxe_buf_realloc, - .write = efi_pxe_buf_write, -}; - -/****************************************************************************** - * - * (M)TFTP download interface - * - ****************************************************************************** - */ - -/** - * Close PXE (M)TFTP download interface - * - * @v pxe PXE base code - * @v rc Reason for close - */ -static void efi_pxe_tftp_close ( struct efi_pxe *pxe, int rc ) { - - /* Restart interface */ - intf_restart ( &pxe->tftp, rc ); - - /* Record overall status */ - pxe->rc = rc; -} - -/** - * Check PXE (M)TFTP download flow control window - * - * @v pxe PXE base code - * @ret len Length of window - */ -static size_t efi_pxe_tftp_window ( struct efi_pxe *pxe ) { - - /* Return requested blocksize */ - return pxe->blksize; -} - -/** - * Receive new PXE (M)TFTP download data - * - * @v pxe PXE base code - * @v iobuf I/O buffer - * @v meta Transfer metadata - * @ret rc Return status code - */ -static int efi_pxe_tftp_deliver ( struct efi_pxe *pxe, - struct io_buffer *iobuf, - struct xfer_metadata *meta ) { - int rc; - - /* Deliver to data transfer buffer */ - if ( ( rc = xferbuf_deliver ( &pxe->buf, iob_disown ( iobuf ), - meta ) ) != 0 ) - goto err_deliver; - - return 0; - - err_deliver: - efi_pxe_tftp_close ( pxe, rc ); - return rc; -} - -/** PXE file data transfer interface operations */ -static struct interface_operation efi_pxe_tftp_operations[] = { - INTF_OP ( xfer_deliver, struct efi_pxe *, efi_pxe_tftp_deliver ), - INTF_OP ( xfer_window, struct efi_pxe *, efi_pxe_tftp_window ), - INTF_OP ( intf_close, struct efi_pxe *, efi_pxe_tftp_close ), -}; - -/** PXE file data transfer interface descriptor */ -static struct interface_descriptor efi_pxe_tftp_desc = - INTF_DESC ( struct efi_pxe, tftp, efi_pxe_tftp_operations ); - -/** - * Open (M)TFTP download interface - * - * @v pxe PXE base code - * @v ip EFI IP address - * @v filename Filename - * @ret rc Return status code - */ -static int efi_pxe_tftp_open ( struct efi_pxe *pxe, EFI_IP_ADDRESS *ip, - const char *filename ) { - struct sockaddr server; - struct uri *uri; - int rc; - - /* Parse server address and filename */ - efi_pxe_ip_sockaddr ( pxe, ip, &server ); - uri = pxe_uri ( &server, filename ); - if ( ! uri ) { - DBGC ( pxe, "PXE %s could not parse %s:%s\n", pxe->name, - efi_pxe_ip_ntoa ( pxe, ip ), filename ); - rc = -ENOTSUP; - goto err_parse; - } - - /* Open URI */ - if ( ( rc = xfer_open_uri ( &pxe->tftp, uri ) ) != 0 ) { - DBGC ( pxe, "PXE %s could not open: %s\n", - pxe->name, strerror ( rc ) ); - goto err_open; - } - - err_open: - uri_put ( uri ); - err_parse: - return rc; -} - -/****************************************************************************** - * - * UDP interface - * - ****************************************************************************** - */ - -/** EFI UDP pseudo-header */ -struct efi_pxe_udp_pseudo_header { - /** Network-layer protocol */ - struct net_protocol *net; - /** Destination port */ - uint16_t dest_port; - /** Source port */ - uint16_t src_port; -} __attribute__ (( packed )); - -/** - * Close UDP interface - * - * @v pxe PXE base code - * @v rc Reason for close - */ -static void efi_pxe_udp_close ( struct efi_pxe *pxe, int rc ) { - struct io_buffer *iobuf; - struct io_buffer *tmp; - - /* Release our claim on SNP devices, if applicable */ - if ( process_running ( &pxe->process ) ) - efi_snp_release(); - - /* Stop process */ - process_del ( &pxe->process ); - - /* Restart UDP interface */ - intf_restart ( &pxe->udp, rc ); - - /* Flush any received UDP packets */ - list_for_each_entry_safe ( iobuf, tmp, &pxe->queue, list ) { - list_del ( &iobuf->list ); - free_iob ( iobuf ); - } -} - -/** - * Receive UDP packet - * - * @v pxe PXE base code - * @v iobuf I/O buffer - * @v meta Data transfer metadata - * @ret rc Return status code - */ -static int efi_pxe_udp_deliver ( struct efi_pxe *pxe, struct io_buffer *iobuf, - struct xfer_metadata *meta ) { - struct sockaddr_efi *se_src; - struct sockaddr_efi *se_dest; - struct tcpip_net_protocol *tcpip; - struct net_protocol *net; - struct efi_pxe_udp_pseudo_header *pshdr; - size_t addr_len; - size_t pshdr_len; - int rc; - - /* Sanity checks */ - assert ( meta != NULL ); - se_src = ( ( struct sockaddr_efi * ) meta->src ); - assert ( se_src != NULL ); - se_dest = ( ( struct sockaddr_efi * ) meta->dest ); - assert ( se_dest != NULL ); - assert ( se_src->se_family == se_dest->se_family ); - - /* Determine protocol */ - tcpip = tcpip_net_protocol ( se_src->se_family ); - if ( ! tcpip ) { - rc = -ENOTSUP; - goto err_unsupported; - } - net = tcpip->net_protocol; - addr_len = net->net_addr_len; - - /* Construct pseudo-header */ - pshdr_len = ( sizeof ( *pshdr ) + ( 2 * addr_len ) ); - if ( ( rc = iob_ensure_headroom ( iobuf, pshdr_len ) ) != 0 ) - goto err_headroom; - memcpy ( iob_push ( iobuf, addr_len ), &se_src->se_addr, addr_len ); - memcpy ( iob_push ( iobuf, addr_len ), &se_dest->se_addr, addr_len ); - pshdr = iob_push ( iobuf, sizeof ( *pshdr ) ); - pshdr->net = net; - pshdr->dest_port = ntohs ( se_dest->se_port ); - pshdr->src_port = ntohs ( se_src->se_port ); - - /* Add to queue */ - list_add_tail ( &iobuf->list, &pxe->queue ); - - return 0; - - err_unsupported: - err_headroom: - free_iob ( iobuf ); - return rc; -} - -/** PXE UDP interface operations */ -static struct interface_operation efi_pxe_udp_operations[] = { - INTF_OP ( xfer_deliver, struct efi_pxe *, efi_pxe_udp_deliver ), - INTF_OP ( intf_close, struct efi_pxe *, efi_pxe_udp_close ), -}; - -/** PXE UDP interface descriptor */ -static struct interface_descriptor efi_pxe_udp_desc = - INTF_DESC ( struct efi_pxe, udp, efi_pxe_udp_operations ); - -/** - * Open UDP interface - * - * @v pxe PXE base code - * @ret rc Return status code - */ -static int efi_pxe_udp_open ( struct efi_pxe *pxe ) { - int rc; - - /* If interface is already open, then cancel the scheduled close */ - if ( process_running ( &pxe->process ) ) { - process_del ( &pxe->process ); - return 0; - } - - /* Open promiscuous UDP interface */ - if ( ( rc = udp_open_promisc ( &pxe->udp ) ) != 0 ) { - DBGC ( pxe, "PXE %s could not open UDP connection: %s\n", - pxe->name, strerror ( rc ) ); - return rc; - } - - /* Claim network devices */ - efi_snp_claim(); - - return 0; -} - -/** - * Schedule close of UDP interface - * - * @v pxe PXE base code - */ -static void efi_pxe_udp_schedule_close ( struct efi_pxe *pxe ) { - - /* The EFI PXE base code protocol does not provide any - * explicit UDP open/close methods. To avoid the overhead of - * reopening a socket for each read/write operation, we start - * a process which will close the socket immediately if the - * next call into iPXE is anything other than a UDP - * read/write. - */ - process_add ( &pxe->process ); -} - -/** - * Scheduled close of UDP interface - * - * @v pxe PXE base code - */ -static void efi_pxe_udp_scheduled_close ( struct efi_pxe *pxe ) { - - /* Close UDP interface */ - efi_pxe_udp_close ( pxe, 0 ); -} - -/** UDP close process descriptor */ -static struct process_descriptor efi_pxe_process_desc = - PROC_DESC_ONCE ( struct efi_pxe, process, efi_pxe_udp_scheduled_close ); - -/****************************************************************************** - * - * Fake DHCP packets - * - ****************************************************************************** - */ - -/** - * Name fake DHCP packet - * - * @v pxe PXE base code - * @v packet Packet - * @ret name Name of packet - */ -static const char * efi_pxe_fake_name ( struct efi_pxe *pxe, - EFI_PXE_BASE_CODE_PACKET *packet ) { - EFI_PXE_BASE_CODE_MODE *mode = &pxe->mode; - - if ( packet == &mode->DhcpDiscover ) { - return "DhcpDiscover"; - } else if ( packet == &mode->DhcpAck ) { - return "DhcpAck"; - } else if ( packet == &mode->ProxyOffer ) { - return "ProxyOffer"; - } else if ( packet == &mode->PxeDiscover ) { - return "PxeDiscover"; - } else if ( packet == &mode->PxeReply ) { - return "PxeReply"; - } else if ( packet == &mode->PxeBisReply ) { - return "PxeBisReply"; - } else { - return "<UNKNOWN>"; - } -} - -/** - * Construct fake DHCP packet and flag - * - * @v pxe PXE base code - * @v fake Fake packet constructor - * @v packet Packet to fill in - * @ret exists Packet existence flag - */ -static BOOLEAN efi_pxe_fake ( struct efi_pxe *pxe, - int ( * fake ) ( struct net_device *netdev, - void *data, size_t len ), - EFI_PXE_BASE_CODE_PACKET *packet ) { - EFI_PXE_BASE_CODE_MODE *mode = &pxe->mode; - struct dhcp_packet dhcppkt; - struct dhcphdr *dhcphdr; - unsigned int len; - int rc; - - /* The fake packet constructors do not support IPv6 */ - if ( mode->UsingIpv6 ) - return FALSE; - - /* Attempt to construct packet */ - if ( ( rc = fake ( pxe->netdev, packet, sizeof ( *packet ) ) != 0 ) ) { - DBGC ( pxe, "PXE %s could not fake %s: %s\n", pxe->name, - efi_pxe_fake_name ( pxe, packet ), strerror ( rc ) ); - return FALSE; - } - - /* The WDS bootstrap wdsmgfw.efi has a buggy DHCPv4 packet - * parser which does not correctly handle DHCP padding bytes. - * Specifically, if a padding byte (i.e. a zero) is - * encountered, the parse will first increment the pointer by - * one to skip over the padding byte but will then drop into - * the code path for handling normal options, which increments - * the pointer by two to skip over the (already-skipped) type - * field and the (non-existent) length field. - * - * The upshot of this bug in WDS is that the parser will fail - * with an error 0xc0000023 if the number of spare bytes after - * the end of the options is not an exact multiple of three. - * - * Work around this buggy parser by adding an explicit - * DHCP_END tag. - */ - dhcphdr = container_of ( &packet->Dhcpv4.BootpOpcode, - struct dhcphdr, op ); - dhcppkt_init ( &dhcppkt, dhcphdr, sizeof ( *packet ) ); - len = dhcppkt_len ( &dhcppkt ); - if ( len < sizeof ( *packet ) ) - packet->Raw[len] = DHCP_END; - - return TRUE; -} - -/** - * Construct fake DHCP packets - * - * @v pxe PXE base code - */ -static void efi_pxe_fake_all ( struct efi_pxe *pxe ) { - EFI_PXE_BASE_CODE_MODE *mode = &pxe->mode; - - /* Construct fake packets */ - mode->DhcpDiscoverValid = - efi_pxe_fake ( pxe, create_fakedhcpdiscover, - &mode->DhcpDiscover ); - mode->DhcpAckReceived = - efi_pxe_fake ( pxe, create_fakedhcpack, - &mode->DhcpAck ); - mode->PxeReplyReceived = - efi_pxe_fake ( pxe, create_fakepxebsack, - &mode->PxeReply ); -} - -/****************************************************************************** - * - * Base code protocol - * - ****************************************************************************** - */ - -/** - * Start PXE base code - * - * @v base PXE base code protocol - * @v use_ipv6 Use IPv6 - * @ret efirc EFI status code - */ -static EFI_STATUS EFIAPI efi_pxe_start ( EFI_PXE_BASE_CODE_PROTOCOL *base, - BOOLEAN use_ipv6 ) { - struct efi_pxe *pxe = container_of ( base, struct efi_pxe, base ); - EFI_PXE_BASE_CODE_MODE *mode = &pxe->mode; - struct tcpip_net_protocol *ipv6 = tcpip_net_protocol ( AF_INET6 ); - sa_family_t family = ( use_ipv6 ? AF_INET6 : AF_INET ); - int rc; - - DBGC ( pxe, "PXE %s START %s\n", pxe->name, ( ipv6 ? "IPv6" : "IPv4" )); - - /* Initialise mode structure */ - memset ( mode, 0, sizeof ( *mode ) ); - mode->AutoArp = TRUE; - mode->TTL = DEFAULT_TTL; - mode->ToS = DEFAULT_ToS; - mode->IpFilter.Filters = - ( EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP | - EFI_PXE_BASE_CODE_IP_FILTER_BROADCAST | - EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS | - EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS_MULTICAST ); - - /* Check for IPv4/IPv6 support */ - mode->Ipv6Supported = ( ipv6 != NULL ); - mode->Ipv6Available = ( ipv6 != NULL ); - pxe->tcpip = tcpip_net_protocol ( family ); - if ( ! pxe->tcpip ) { - DBGC ( pxe, "PXE %s has no support for %s\n", - pxe->name, socket_family_name ( family ) ); - return EFI_UNSUPPORTED; - } - pxe->net = pxe->tcpip->net_protocol; - mode->UsingIpv6 = use_ipv6; - - /* Populate station IP address */ - if ( ( rc = efi_pxe_ip ( pxe ) ) != 0 ) - return rc; - - /* Construct fake DHCP packets */ - efi_pxe_fake_all ( pxe ); - - /* Record that base code is started */ - mode->Started = TRUE; - DBGC ( pxe, "PXE %s using %s\n", - pxe->name, pxe->net->ntoa ( &mode->StationIp ) ); - - return 0; -} - -/** - * Stop PXE base code - * - * @v base PXE base code protocol - * @ret efirc EFI status code - */ -static EFI_STATUS EFIAPI efi_pxe_stop ( EFI_PXE_BASE_CODE_PROTOCOL *base ) { - struct efi_pxe *pxe = container_of ( base, struct efi_pxe, base ); - EFI_PXE_BASE_CODE_MODE *mode = &pxe->mode; - - DBGC ( pxe, "PXE %s STOP\n", pxe->name ); - - /* Record that base code is stopped */ - mode->Started = FALSE; - - /* Close TFTP */ - efi_pxe_tftp_close ( pxe, 0 ); - - /* Close UDP */ - efi_pxe_udp_close ( pxe, 0 ); - - return 0; -} - -/** - * Perform DHCP - * - * @v base PXE base code protocol - * @v sort Offers should be sorted - * @ret efirc EFI status code - */ -static EFI_STATUS EFIAPI efi_pxe_dhcp ( EFI_PXE_BASE_CODE_PROTOCOL *base, - BOOLEAN sort ) { - struct efi_pxe *pxe = container_of ( base, struct efi_pxe, base ); - struct net_device *netdev = pxe->netdev; - int rc; - - DBGC ( pxe, "PXE %s DHCP %s\n", - pxe->name, ( sort ? "sorted" : "unsorted" ) ); - - /* Claim network devices */ - efi_snp_claim(); - - /* Initiate configuration */ - if ( ( rc = netdev_configure_all ( netdev ) ) != 0 ) { - DBGC ( pxe, "PXE %s could not initiate configuration: %s\n", - pxe->name, strerror ( rc ) ); - goto err_configure; - } - - /* Wait for configuration to complete (or time out) */ - while ( netdev_configuration_in_progress ( netdev ) ) - step(); - - /* Report timeout if configuration failed */ - if ( ! netdev_configuration_ok ( netdev ) ) { - rc = -ETIMEDOUT; - goto err_timeout; - } - - /* Update station IP address */ - if ( ( rc = efi_pxe_ip ( pxe ) ) != 0 ) - goto err_ip; - - /* Update faked DHCP packets */ - efi_pxe_fake_all ( pxe ); - - err_ip: - err_timeout: - err_configure: - efi_snp_release(); - return EFIRC ( rc ); -} - -/** - * Perform boot server discovery - * - * @v base PXE base code protocol - * @v type Boot server type - * @v layer Boot server layer - * @v bis Use boot integrity services - * @v info Additional information - * @ret efirc EFI status code - */ -static EFI_STATUS EFIAPI -efi_pxe_discover ( EFI_PXE_BASE_CODE_PROTOCOL *base, UINT16 type, UINT16 *layer, - BOOLEAN bis, EFI_PXE_BASE_CODE_DISCOVER_INFO *info ) { - struct efi_pxe *pxe = container_of ( base, struct efi_pxe, base ); - EFI_IP_ADDRESS *ip; - unsigned int i; - - DBGC ( pxe, "PXE %s DISCOVER type %d layer %d%s\n", - pxe->name, type, *layer, ( bis ? " bis" : "" ) ); - if ( info ) { - DBGC ( pxe, "%s%s%s%s %s", - ( info->UseMCast ? " mcast" : "" ), - ( info->UseBCast ? " bcast" : "" ), - ( info->UseUCast ? " ucast" : "" ), - ( info->MustUseList ? " list" : "" ), - efi_pxe_ip_ntoa ( pxe, &info->ServerMCastIp ) ); - for ( i = 0 ; i < info->IpCnt ; i++ ) { - ip = &info->SrvList[i].IpAddr; - DBGC ( pxe, " %d%s:%s", info->SrvList[i].Type, - ( info->SrvList[i].AcceptAnyResponse ? - ":any" : "" ), efi_pxe_ip_ntoa ( pxe, ip ) ); - } - } - DBGC ( pxe, "\n" ); - - /* Not used by any bootstrap I can find to test with */ - return EFI_UNSUPPORTED; -} - -/** - * Perform (M)TFTP - * - * @v base PXE base code protocol - * @v opcode TFTP opcode - * @v data Data buffer - * @v overwrite Overwrite file - * @v len Length of data buffer - * @v blksize Block size - * @v ip Server address - * @v filename Filename - * @v info Additional information - * @v callback Pass packets to callback instead of data buffer - * @ret efirc EFI status code - */ -static EFI_STATUS EFIAPI -efi_pxe_mtftp ( EFI_PXE_BASE_CODE_PROTOCOL *base, - EFI_PXE_BASE_CODE_TFTP_OPCODE opcode, VOID *data, - BOOLEAN overwrite, UINT64 *len, UINTN *blksize, - EFI_IP_ADDRESS *ip, UINT8 *filename, - EFI_PXE_BASE_CODE_MTFTP_INFO *info, BOOLEAN callback ) { - struct efi_pxe *pxe = container_of ( base, struct efi_pxe, base ); - int rc; - - DBGC ( pxe, "PXE %s MTFTP %d%s %p+%llx", pxe->name, opcode, - ( overwrite ? " overwrite" : "" ), data, *len ); - if ( blksize ) - DBGC ( pxe, " blksize %zd", ( ( size_t ) *blksize ) ); - DBGC ( pxe, " %s:%s", efi_pxe_ip_ntoa ( pxe, ip ), filename ); - if ( info ) { - DBGC ( pxe, " %s:%d:%d:%d:%d", - efi_pxe_ip_ntoa ( pxe, &info->MCastIp ), - info->CPort, info->SPort, info->ListenTimeout, - info->TransmitTimeout ); - } - DBGC ( pxe, "%s\n", ( callback ? " callback" : "" ) ); - - /* Fail unless operation is supported */ - if ( ! ( ( opcode == EFI_PXE_BASE_CODE_TFTP_READ_FILE ) || - ( opcode == EFI_PXE_BASE_CODE_MTFTP_READ_FILE ) ) ) { - DBGC ( pxe, "PXE %s unsupported MTFTP opcode %d\n", - pxe->name, opcode ); - rc = -ENOTSUP; - goto err_opcode; - } - - /* Claim network devices */ - efi_snp_claim(); - - /* Determine block size. Ignore the requested block size - * unless we are using callbacks, since limiting HTTP to a - * 512-byte TCP window is not sensible. - */ - pxe->blksize = ( ( callback && blksize ) ? *blksize : -1UL ); - - /* Initialise data transfer buffer */ - pxe->buf.data = data; - pxe->buf.len = *len; - - /* Open download */ - if ( ( rc = efi_pxe_tftp_open ( pxe, ip, - ( ( const char * ) filename ) ) ) != 0 ) - goto err_open; - - /* Wait for download to complete */ - pxe->rc = -EINPROGRESS; - while ( pxe->rc == -EINPROGRESS ) - step(); - if ( ( rc = pxe->rc ) != 0 ) { - DBGC ( pxe, "PXE %s download failed: %s\n", - pxe->name, strerror ( rc ) ); - goto err_download; - } - - err_download: - efi_pxe_tftp_close ( pxe, rc ); - err_open: - efi_snp_release(); - err_opcode: - return EFIRC ( rc ); -} - -/** - * Transmit UDP packet - * - * @v base PXE base code protocol - * @v flags Operation flags - * @v dest_ip Destination address - * @v dest_port Destination port - * @v gateway Gateway address - * @v src_ip Source address - * @v src_port Source port - * @v hdr_len Header length - * @v hdr Header data - * @v len Length - * @v data Data - * @ret efirc EFI status code - */ -static EFI_STATUS EFIAPI -efi_pxe_udp_write ( EFI_PXE_BASE_CODE_PROTOCOL *base, UINT16 flags, - EFI_IP_ADDRESS *dest_ip, - EFI_PXE_BASE_CODE_UDP_PORT *dest_port, - EFI_IP_ADDRESS *gateway, EFI_IP_ADDRESS *src_ip, - EFI_PXE_BASE_CODE_UDP_PORT *src_port, - UINTN *hdr_len, VOID *hdr, UINTN *len, VOID *data ) { - struct efi_pxe *pxe = container_of ( base, struct efi_pxe, base ); - EFI_PXE_BASE_CODE_MODE *mode = &pxe->mode; - struct io_buffer *iobuf; - struct xfer_metadata meta; - union { - struct sockaddr_tcpip st; - struct sockaddr sa; - } dest; - union { - struct sockaddr_tcpip st; - struct sockaddr sa; - } src; - int rc; - - DBGC2 ( pxe, "PXE %s UDP WRITE ", pxe->name ); - if ( src_ip ) - DBGC2 ( pxe, "%s", efi_pxe_ip_ntoa ( pxe, src_ip ) ); - DBGC2 ( pxe, ":" ); - if ( src_port && - ( ! ( flags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_PORT ) ) ) { - DBGC2 ( pxe, "%d", *src_port ); - } else { - DBGC2 ( pxe, "*" ); - } - DBGC2 ( pxe, "->%s:%d", efi_pxe_ip_ntoa ( pxe, dest_ip ), *dest_port ); - if ( gateway ) - DBGC2 ( pxe, " via %s", efi_pxe_ip_ntoa ( pxe, gateway ) ); - if ( hdr_len ) - DBGC2 ( pxe, " %p+%zx", hdr, ( ( size_t ) *hdr_len ) ); - DBGC2 ( pxe, " %p+%zx", data, ( ( size_t ) *len ) ); - if ( flags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_MAY_FRAGMENT ) - DBGC2 ( pxe, " frag" ); - DBGC2 ( pxe, "\n" ); - - /* Open UDP connection (if applicable) */ - if ( ( rc = efi_pxe_udp_open ( pxe ) ) != 0 ) - goto err_open; - - /* Construct destination address */ - efi_pxe_ip_sockaddr ( pxe, dest_ip, &dest.sa ); - dest.st.st_port = htons ( *dest_port ); - - /* Construct source address */ - efi_pxe_ip_sockaddr ( pxe, ( src_ip ? src_ip : &mode->StationIp ), - &src.sa ); - if ( src_port && - ( ! ( flags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_PORT ) ) ) { - src.st.st_port = htons ( *src_port ); - } else { - /* The API does not allow for a sensible concept of - * binding to a local port, so just use a random value. - */ - src.st.st_port = ( random() | htons ( 1024 ) ); - if ( src_port ) - *src_port = ntohs ( src.st.st_port ); - } - - /* Allocate I/O buffer */ - iobuf = xfer_alloc_iob ( &pxe->udp, - ( *len + ( hdr_len ? *hdr_len : 0 ) ) ); - if ( ! iobuf ) { - rc = -ENOMEM; - goto err_alloc; - } - - /* Populate I/O buffer */ - if ( hdr_len ) - memcpy ( iob_put ( iobuf, *hdr_len ), hdr, *hdr_len ); - memcpy ( iob_put ( iobuf, *len ), data, *len ); - - /* Construct metadata */ - memset ( &meta, 0, sizeof ( meta ) ); - meta.src = &src.sa; - meta.dest = &dest.sa; - meta.netdev = pxe->netdev; - - /* Deliver I/O buffer */ - if ( ( rc = xfer_deliver ( &pxe->udp, iob_disown ( iobuf ), - &meta ) ) != 0 ) { - DBGC ( pxe, "PXE %s could not transmit: %s\n", - pxe->name, strerror ( rc ) ); - goto err_deliver; - } - - err_deliver: - free_iob ( iobuf ); - err_alloc: - efi_pxe_udp_schedule_close ( pxe ); - err_open: - return EFIRC ( rc ); -} - -/** - * Receive UDP packet - * - * @v base PXE base code protocol - * @v flags Operation flags - * @v dest_ip Destination address - * @v dest_port Destination port - * @v src_ip Source address - * @v src_port Source port - * @v hdr_len Header length - * @v hdr Header data - * @v len Length - * @v data Data - * @ret efirc EFI status code - */ -static EFI_STATUS EFIAPI -efi_pxe_udp_read ( EFI_PXE_BASE_CODE_PROTOCOL *base, UINT16 flags, - EFI_IP_ADDRESS *dest_ip, - EFI_PXE_BASE_CODE_UDP_PORT *dest_port, - EFI_IP_ADDRESS *src_ip, - EFI_PXE_BASE_CODE_UDP_PORT *src_port, - UINTN *hdr_len, VOID *hdr, UINTN *len, VOID *data ) { - struct efi_pxe *pxe = container_of ( base, struct efi_pxe, base ); - struct io_buffer *iobuf; - struct efi_pxe_udp_pseudo_header *pshdr; - EFI_IP_ADDRESS *actual_dest_ip; - EFI_IP_ADDRESS *actual_src_ip; - size_t addr_len; - size_t frag_len; - int rc; - - DBGC2 ( pxe, "PXE %s UDP READ ", pxe->name ); - if ( flags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_USE_FILTER ) { - DBGC2 ( pxe, "(filter)" ); - } else if ( flags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_IP ) { - DBGC2 ( pxe, "*" ); - } else if ( dest_ip ) { - DBGC2 ( pxe, "%s", efi_pxe_ip_ntoa ( pxe, dest_ip ) ); - } - DBGC2 ( pxe, ":" ); - if ( flags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_PORT ) { - DBGC2 ( pxe, "*" ); - } else if ( dest_port ) { - DBGC2 ( pxe, "%d", *dest_port ); - } else { - DBGC2 ( pxe, "<NULL>" ); - } - DBGC2 ( pxe, "<-" ); - if ( flags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_IP ) { - DBGC2 ( pxe, "*" ); - } else if ( src_ip ) { - DBGC2 ( pxe, "%s", efi_pxe_ip_ntoa ( pxe, src_ip ) ); - } else { - DBGC2 ( pxe, "<NULL>" ); - } - DBGC2 ( pxe, ":" ); - if ( flags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_PORT ) { - DBGC2 ( pxe, "*" ); - } else if ( src_port ) { - DBGC2 ( pxe, "%d", *src_port ); - } else { - DBGC2 ( pxe, "<NULL>" ); - } - if ( hdr_len ) - DBGC2 ( pxe, " %p+%zx", hdr, ( ( size_t ) *hdr_len ) ); - DBGC2 ( pxe, " %p+%zx\n", data, ( ( size_t ) *len ) ); - - /* Open UDP connection (if applicable) */ - if ( ( rc = efi_pxe_udp_open ( pxe ) ) != 0 ) - goto err_open; - - /* Try receiving a packet, if the queue is empty */ - if ( list_empty ( &pxe->queue ) ) - step(); - - /* Remove first packet from the queue */ - iobuf = list_first_entry ( &pxe->queue, struct io_buffer, list ); - if ( ! iobuf ) { - rc = -ETIMEDOUT; /* "no packet" */ - goto err_empty; - } - list_del ( &iobuf->list ); - - /* Strip pseudo-header */ - pshdr = iobuf->data; - addr_len = ( pshdr->net->net_addr_len ); - iob_pull ( iobuf, sizeof ( *pshdr ) ); - actual_dest_ip = iobuf->data; - iob_pull ( iobuf, addr_len ); - actual_src_ip = iobuf->data; - iob_pull ( iobuf, addr_len ); - DBGC2 ( pxe, "PXE %s UDP RX %s:%d", pxe->name, - pshdr->net->ntoa ( actual_dest_ip ), pshdr->dest_port ); - DBGC2 ( pxe, "<-%s:%d len %#zx\n", pshdr->net->ntoa ( actual_src_ip ), - pshdr->src_port, iob_len ( iobuf ) ); - - /* Filter based on network-layer protocol */ - if ( pshdr->net != pxe->net ) { - DBGC2 ( pxe, "PXE %s filtered out %s packet\n", - pxe->name, pshdr->net->name ); - rc = -ETIMEDOUT; /* "no packet" */ - goto err_filter; - } - - /* Filter based on port numbers */ - if ( ! ( ( flags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_PORT ) || - ( dest_port && ( *dest_port == pshdr->dest_port ) ) ) ) { - DBGC2 ( pxe, "PXE %s filtered out destination port %d\n", - pxe->name, pshdr->dest_port ); - rc = -ETIMEDOUT; /* "no packet" */ - goto err_filter; - } - if ( ! ( ( flags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_PORT ) || - ( src_port && ( *src_port == pshdr->src_port ) ) ) ) { - DBGC2 ( pxe, "PXE %s filtered out source port %d\n", - pxe->name, pshdr->src_port ); - rc = -ETIMEDOUT; /* "no packet" */ - goto err_filter; - } - - /* Filter based on source IP address */ - if ( ! ( ( flags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_IP ) || - ( src_ip && - ( memcmp ( src_ip, actual_src_ip, addr_len ) == 0 ) ) ) ) { - DBGC2 ( pxe, "PXE %s filtered out source IP %s\n", - pxe->name, pshdr->net->ntoa ( actual_src_ip ) ); - rc = -ETIMEDOUT; /* "no packet" */ - goto err_filter; - } - - /* Filter based on destination IP address */ - if ( ! ( ( ( flags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_USE_FILTER ) && - efi_pxe_ip_filter ( pxe, actual_dest_ip ) ) || - ( ( ! ( flags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_USE_FILTER ) ) && - ( ( flags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_IP ) || - ( dest_ip && ( memcmp ( dest_ip, actual_dest_ip, - addr_len ) == 0 ) ) ) ) ) ) { - DBGC2 ( pxe, "PXE %s filtered out destination IP %s\n", - pxe->name, pshdr->net->ntoa ( actual_dest_ip ) ); - rc = -ETIMEDOUT; /* "no packet" */ - goto err_filter; - } - - /* Fill in addresses and port numbers */ - if ( dest_ip ) - memcpy ( dest_ip, actual_dest_ip, addr_len ); - if ( dest_port ) - *dest_port = pshdr->dest_port; - if ( src_ip ) - memcpy ( src_ip, actual_src_ip, addr_len ); - if ( src_port ) - *src_port = pshdr->src_port; - - /* Fill in header, if applicable */ - if ( hdr_len ) { - frag_len = iob_len ( iobuf ); - if ( frag_len > *hdr_len ) - frag_len = *hdr_len; - memcpy ( hdr, iobuf->data, frag_len ); - iob_pull ( iobuf, frag_len ); - *hdr_len = frag_len; - } - - /* Fill in data buffer */ - frag_len = iob_len ( iobuf ); - if ( frag_len > *len ) - frag_len = *len; - memcpy ( data, iobuf->data, frag_len ); - iob_pull ( iobuf, frag_len ); - *len = frag_len; - - /* Check for overflow */ - if ( iob_len ( iobuf ) ) { - rc = -ERANGE; - goto err_too_short; - } - - /* Success */ - rc = 0; - - err_too_short: - err_filter: - free_iob ( iobuf ); - err_empty: - efi_pxe_udp_schedule_close ( pxe ); - err_open: - return EFIRC ( rc ); -} - -/** - * Set receive filter - * - * @v base PXE base code protocol - * @v filter Receive filter - * @ret efirc EFI status code - */ -static EFI_STATUS EFIAPI -efi_pxe_set_ip_filter ( EFI_PXE_BASE_CODE_PROTOCOL *base, - EFI_PXE_BASE_CODE_IP_FILTER *filter ) { - struct efi_pxe *pxe = container_of ( base, struct efi_pxe, base ); - EFI_PXE_BASE_CODE_MODE *mode = &pxe->mode; - unsigned int i; - - DBGC ( pxe, "PXE %s SET IP FILTER %02x", - pxe->name, filter->Filters ); - for ( i = 0 ; i < filter->IpCnt ; i++ ) { - DBGC ( pxe, " %s", - efi_pxe_ip_ntoa ( pxe, &filter->IpList[i] ) ); - } - DBGC ( pxe, "\n" ); - - /* Update filter */ - memcpy ( &mode->IpFilter, filter, sizeof ( mode->IpFilter ) ); - - return 0; -} - -/** - * Resolve MAC address - * - * @v base PXE base code protocol - * @v ip IP address - * @v mac MAC address to fill in - * @ret efirc EFI status code - */ -static EFI_STATUS EFIAPI efi_pxe_arp ( EFI_PXE_BASE_CODE_PROTOCOL *base, - EFI_IP_ADDRESS *ip, - EFI_MAC_ADDRESS *mac ) { - struct efi_pxe *pxe = container_of ( base, struct efi_pxe, base ); - - DBGC ( pxe, "PXE %s ARP %s %p\n", - pxe->name, efi_pxe_ip_ntoa ( pxe, ip ), mac ); - - /* Not used by any bootstrap I can find to test with */ - return EFI_UNSUPPORTED; -} - -/** - * Set parameters - * - * @v base PXE base code protocol - * @v autoarp Automatic ARP packet generation - * @v sendguid Send GUID as client hardware address - * @v ttl IP time to live - * @v tos IP type of service - * @v callback Make callbacks - * @ret efirc EFI status code - */ -static EFI_STATUS EFIAPI -efi_pxe_set_parameters ( EFI_PXE_BASE_CODE_PROTOCOL *base, - BOOLEAN *autoarp, BOOLEAN *sendguid, UINT8 *ttl, - UINT8 *tos, BOOLEAN *callback ) { - struct efi_pxe *pxe = container_of ( base, struct efi_pxe, base ); - EFI_PXE_BASE_CODE_MODE *mode = &pxe->mode; - - DBGC ( pxe, "PXE %s SET PARAMETERS", pxe->name ); - if ( autoarp ) - DBGC ( pxe, " %s", ( *autoarp ? "autoarp" : "noautoarp" ) ); - if ( sendguid ) - DBGC ( pxe, " %s", ( *sendguid ? "sendguid" : "sendmac" ) ); - if ( ttl ) - DBGC ( pxe, " ttl %d", *ttl ); - if ( tos ) - DBGC ( pxe, " tos %d", *tos ); - if ( callback ) { - DBGC ( pxe, " %s", - ( *callback ? "callback" : "nocallback" ) ); - } - DBGC ( pxe, "\n" ); - - /* Update parameters */ - if ( autoarp ) - mode->AutoArp = *autoarp; - if ( sendguid ) - mode->SendGUID = *sendguid; - if ( ttl ) - mode->TTL = *ttl; - if ( tos ) - mode->ToS = *tos; - if ( callback ) - mode->MakeCallbacks = *callback; - - return 0; -} - -/** - * Set IP address - * - * @v base PXE base code protocol - * @v ip IP address - * @v netmask Subnet mask - * @ret efirc EFI status code - */ -static EFI_STATUS EFIAPI -efi_pxe_set_station_ip ( EFI_PXE_BASE_CODE_PROTOCOL *base, - EFI_IP_ADDRESS *ip, EFI_IP_ADDRESS *netmask ) { - struct efi_pxe *pxe = container_of ( base, struct efi_pxe, base ); - EFI_PXE_BASE_CODE_MODE *mode = &pxe->mode; - - DBGC ( pxe, "PXE %s SET STATION IP ", pxe->name ); - if ( ip ) - DBGC ( pxe, "%s", efi_pxe_ip_ntoa ( pxe, ip ) ); - if ( netmask ) - DBGC ( pxe, "/%s", efi_pxe_ip_ntoa ( pxe, netmask ) ); - DBGC ( pxe, "\n" ); - - /* Update IP address and netmask */ - if ( ip ) - memcpy ( &mode->StationIp, ip, sizeof ( mode->StationIp ) ); - if ( netmask ) - memcpy ( &mode->SubnetMask, netmask, sizeof (mode->SubnetMask)); - - return 0; -} - -/** - * Update cached DHCP packets - * - * @v base PXE base code protocol - * @v dhcpdisc_ok DHCPDISCOVER is valid - * @v dhcpack_ok DHCPACK received - * @v proxyoffer_ok ProxyDHCPOFFER received - * @v pxebsdisc_ok PxeBsDISCOVER valid - * @v pxebsack_ok PxeBsACK received - * @v pxebsbis_ok PxeBsBIS received - * @v dhcpdisc DHCPDISCOVER packet - * @v dhcpack DHCPACK packet - * @v proxyoffer ProxyDHCPOFFER packet - * @v pxebsdisc PxeBsDISCOVER packet - * @v pxebsack PxeBsACK packet - * @v pxebsbis PxeBsBIS packet - * @ret efirc EFI status code - */ -static EFI_STATUS EFIAPI -efi_pxe_set_packets ( EFI_PXE_BASE_CODE_PROTOCOL *base, BOOLEAN *dhcpdisc_ok, - BOOLEAN *dhcpack_ok, BOOLEAN *proxyoffer_ok, - BOOLEAN *pxebsdisc_ok, BOOLEAN *pxebsack_ok, - BOOLEAN *pxebsbis_ok, EFI_PXE_BASE_CODE_PACKET *dhcpdisc, - EFI_PXE_BASE_CODE_PACKET *dhcpack, - EFI_PXE_BASE_CODE_PACKET *proxyoffer, - EFI_PXE_BASE_CODE_PACKET *pxebsdisc, - EFI_PXE_BASE_CODE_PACKET *pxebsack, - EFI_PXE_BASE_CODE_PACKET *pxebsbis ) { - struct efi_pxe *pxe = container_of ( base, struct efi_pxe, base ); - EFI_PXE_BASE_CODE_MODE *mode = &pxe->mode; - - DBGC ( pxe, "PXE %s SET PACKETS\n", pxe->name ); - - /* Update fake packet flags */ - if ( dhcpdisc_ok ) - mode->DhcpDiscoverValid = *dhcpdisc_ok; - if ( dhcpack_ok ) - mode->DhcpAckReceived = *dhcpack_ok; - if ( proxyoffer_ok ) - mode->ProxyOfferReceived = *proxyoffer_ok; - if ( pxebsdisc_ok ) - mode->PxeDiscoverValid = *pxebsdisc_ok; - if ( pxebsack_ok ) - mode->PxeReplyReceived = *pxebsack_ok; - if ( pxebsbis_ok ) - mode->PxeBisReplyReceived = *pxebsbis_ok; - - /* Update fake packet contents */ - if ( dhcpdisc ) - memcpy ( &mode->DhcpDiscover, dhcpdisc, sizeof ( *dhcpdisc ) ); - if ( dhcpack ) - memcpy ( &mode->DhcpAck, dhcpack, sizeof ( *dhcpack ) ); - if ( proxyoffer ) - memcpy ( &mode->ProxyOffer, proxyoffer, sizeof ( *proxyoffer )); - if ( pxebsdisc ) - memcpy ( &mode->PxeDiscover, pxebsdisc, sizeof ( *pxebsdisc ) ); - if ( pxebsack ) - memcpy ( &mode->PxeReply, pxebsack, sizeof ( *pxebsack ) ); - if ( pxebsbis ) - memcpy ( &mode->PxeBisReply, pxebsbis, sizeof ( *pxebsbis ) ); - - return 0; -} - -/** PXE base code protocol */ -static EFI_PXE_BASE_CODE_PROTOCOL efi_pxe_base_code_protocol = { - .Revision = EFI_PXE_BASE_CODE_PROTOCOL_REVISION, - .Start = efi_pxe_start, - .Stop = efi_pxe_stop, - .Dhcp = efi_pxe_dhcp, - .Discover = efi_pxe_discover, - .Mtftp = efi_pxe_mtftp, - .UdpWrite = efi_pxe_udp_write, - .UdpRead = efi_pxe_udp_read, - .SetIpFilter = efi_pxe_set_ip_filter, - .Arp = efi_pxe_arp, - .SetParameters = efi_pxe_set_parameters, - .SetStationIp = efi_pxe_set_station_ip, - .SetPackets = efi_pxe_set_packets, -}; - -/****************************************************************************** - * - * Apple NetBoot protocol - * - ****************************************************************************** - */ - -/** - * Get DHCP/BSDP response - * - * @v packet Packet - * @v len Length of data buffer - * @v data Data buffer - * @ret efirc EFI status code - */ -static EFI_STATUS EFIAPI -efi_apple_get_response ( EFI_PXE_BASE_CODE_PACKET *packet, UINTN *len, - VOID *data ) { - - /* Check length */ - if ( *len < sizeof ( *packet ) ) { - *len = sizeof ( *packet ); - return EFI_BUFFER_TOO_SMALL; - } - - /* Copy packet */ - memcpy ( data, packet, sizeof ( *packet ) ); - *len = sizeof ( *packet ); - - return EFI_SUCCESS; -} - -/** - * Get DHCP response - * - * @v apple Apple NetBoot protocol - * @v len Length of data buffer - * @v data Data buffer - * @ret efirc EFI status code - */ -static EFI_STATUS EFIAPI -efi_apple_get_dhcp_response ( EFI_APPLE_NET_BOOT_PROTOCOL *apple, - UINTN *len, VOID *data ) { - struct efi_pxe *pxe = container_of ( apple, struct efi_pxe, apple ); - - return efi_apple_get_response ( &pxe->mode.DhcpAck, len, data ); -} - -/** - * Get BSDP response - * - * @v apple Apple NetBoot protocol - * @v len Length of data buffer - * @v data Data buffer - * @ret efirc EFI status code - */ -static EFI_STATUS EFIAPI -efi_apple_get_bsdp_response ( EFI_APPLE_NET_BOOT_PROTOCOL *apple, - UINTN *len, VOID *data ) { - struct efi_pxe *pxe = container_of ( apple, struct efi_pxe, apple ); - - return efi_apple_get_response ( &pxe->mode.PxeReply, len, data ); -} - -/** Apple NetBoot protocol */ -static EFI_APPLE_NET_BOOT_PROTOCOL efi_apple_net_boot_protocol = { - .GetDhcpResponse = efi_apple_get_dhcp_response, - .GetBsdpResponse = efi_apple_get_bsdp_response, -}; - -/****************************************************************************** - * - * Installer - * - ****************************************************************************** - */ - -/** - * Install PXE base code protocol - * - * @v handle EFI handle - * @v netdev Underlying network device - * @ret rc Return status code - */ -int efi_pxe_install ( EFI_HANDLE handle, struct net_device *netdev ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - struct tcpip_net_protocol *ipv6 = tcpip_net_protocol ( AF_INET6 ); - struct efi_pxe *pxe; - struct in_addr ip; - BOOLEAN use_ipv6; - EFI_STATUS efirc; - int rc; - - /* Allocate and initialise structure */ - pxe = zalloc ( sizeof ( *pxe ) ); - if ( ! pxe ) { - rc = -ENOMEM; - goto err_alloc; - } - ref_init ( &pxe->refcnt, efi_pxe_free ); - pxe->netdev = netdev_get ( netdev ); - pxe->name = netdev->name; - pxe->handle = handle; - memcpy ( &pxe->base, &efi_pxe_base_code_protocol, sizeof ( pxe->base )); - pxe->base.Mode = &pxe->mode; - memcpy ( &pxe->apple, &efi_apple_net_boot_protocol, - sizeof ( pxe->apple ) ); - pxe->buf.op = &efi_pxe_buf_operations; - intf_init ( &pxe->tftp, &efi_pxe_tftp_desc, &pxe->refcnt ); - intf_init ( &pxe->udp, &efi_pxe_udp_desc, &pxe->refcnt ); - INIT_LIST_HEAD ( &pxe->queue ); - process_init_stopped ( &pxe->process, &efi_pxe_process_desc, - &pxe->refcnt ); - - /* Crude heuristic: assume that we prefer to use IPv4 if we - * have an IPv4 address for the network device, otherwise - * prefer IPv6 (if available). - */ - fetch_ipv4_setting ( netdev_settings ( netdev ), &ip_setting, &ip ); - use_ipv6 = ( ip.s_addr ? FALSE : ( ipv6 != NULL ) ); - - /* Start base code */ - efi_pxe_start ( &pxe->base, use_ipv6 ); - - /* Install PXE base code protocol */ - if ( ( efirc = bs->InstallMultipleProtocolInterfaces ( - &handle, - &efi_pxe_base_code_protocol_guid, &pxe->base, - &efi_apple_net_boot_protocol_guid, &pxe->apple, - NULL ) ) != 0 ) { - rc = -EEFI ( efirc ); - DBGC ( pxe, "PXE %s could not install base code protocol: %s\n", - pxe->name, strerror ( rc ) ); - goto err_install_protocol; - } - - /* Transfer reference to list and return */ - list_add_tail ( &pxe->list, &efi_pxes ); - DBGC ( pxe, "PXE %s installed for %s\n", - pxe->name, efi_handle_name ( handle ) ); - return 0; - - bs->UninstallMultipleProtocolInterfaces ( - handle, - &efi_pxe_base_code_protocol_guid, &pxe->base, - &efi_apple_net_boot_protocol_guid, &pxe->apple, - NULL ); - err_install_protocol: - ref_put ( &pxe->refcnt ); - err_alloc: - return rc; -} - -/** - * Uninstall PXE base code protocol - * - * @v handle EFI handle - */ -void efi_pxe_uninstall ( EFI_HANDLE handle ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - struct efi_pxe *pxe; - - /* Locate PXE base code */ - pxe = efi_pxe_find ( handle ); - if ( ! handle ) { - DBG ( "PXE could not find base code for %s\n", - efi_handle_name ( handle ) ); - return; - } - - /* Stop base code */ - efi_pxe_stop ( &pxe->base ); - - /* Uninstall PXE base code protocol */ - bs->UninstallMultipleProtocolInterfaces ( - handle, - &efi_pxe_base_code_protocol_guid, &pxe->base, - &efi_apple_net_boot_protocol_guid, &pxe->apple, - NULL ); - - /* Remove from list and drop list's reference */ - list_del ( &pxe->list ); - ref_put ( &pxe->refcnt ); -} diff --git a/roms/ipxe/src/interface/efi/efi_snp.c b/roms/ipxe/src/interface/efi/efi_snp.c index e6388bf67..3dfcc5e16 100644 --- a/roms/ipxe/src/interface/efi/efi_snp.c +++ b/roms/ipxe/src/interface/efi/efi_snp.c @@ -25,11 +25,9 @@ FILE_LICENCE ( GPL2_OR_LATER ); #include <assert.h> #include <byteswap.h> #include <ipxe/netdevice.h> -#include <ipxe/vlan.h> #include <ipxe/iobuf.h> #include <ipxe/in.h> #include <ipxe/version.h> -#include <ipxe/console.h> #include <ipxe/efi/efi.h> #include <ipxe/efi/efi_driver.h> #include <ipxe/efi/efi_strings.h> @@ -185,7 +183,7 @@ efi_snp_start ( EFI_SIMPLE_NETWORK_PROTOCOL *snp ) { struct efi_snp_device *snpdev = container_of ( snp, struct efi_snp_device, snp ); - DBGC ( snpdev, "SNPDEV %p START\n", snpdev ); + DBGC2 ( snpdev, "SNPDEV %p START\n", snpdev ); /* Fail if net device is currently claimed for use by iPXE */ if ( efi_snp_claimed ) @@ -207,7 +205,7 @@ efi_snp_stop ( EFI_SIMPLE_NETWORK_PROTOCOL *snp ) { struct efi_snp_device *snpdev = container_of ( snp, struct efi_snp_device, snp ); - DBGC ( snpdev, "SNPDEV %p STOP\n", snpdev ); + DBGC2 ( snpdev, "SNPDEV %p STOP\n", snpdev ); /* Fail if net device is currently claimed for use by iPXE */ if ( efi_snp_claimed ) @@ -215,7 +213,6 @@ efi_snp_stop ( EFI_SIMPLE_NETWORK_PROTOCOL *snp ) { snpdev->started = 0; efi_snp_set_state ( snpdev ); - return 0; } @@ -234,9 +231,9 @@ efi_snp_initialize ( EFI_SIMPLE_NETWORK_PROTOCOL *snp, container_of ( snp, struct efi_snp_device, snp ); int rc; - DBGC ( snpdev, "SNPDEV %p INITIALIZE (%ld extra RX, %ld extra TX)\n", - snpdev, ( ( unsigned long ) extra_rx_bufsize ), - ( ( unsigned long ) extra_tx_bufsize ) ); + DBGC2 ( snpdev, "SNPDEV %p INITIALIZE (%ld extra RX, %ld extra TX)\n", + snpdev, ( ( unsigned long ) extra_rx_bufsize ), + ( ( unsigned long ) extra_tx_bufsize ) ); /* Fail if net device is currently claimed for use by iPXE */ if ( efi_snp_claimed ) @@ -265,8 +262,8 @@ efi_snp_reset ( EFI_SIMPLE_NETWORK_PROTOCOL *snp, BOOLEAN ext_verify ) { container_of ( snp, struct efi_snp_device, snp ); int rc; - DBGC ( snpdev, "SNPDEV %p RESET (%s extended verification)\n", - snpdev, ( ext_verify ? "with" : "without" ) ); + DBGC2 ( snpdev, "SNPDEV %p RESET (%s extended verification)\n", + snpdev, ( ext_verify ? "with" : "without" ) ); /* Fail if net device is currently claimed for use by iPXE */ if ( efi_snp_claimed ) @@ -297,7 +294,7 @@ efi_snp_shutdown ( EFI_SIMPLE_NETWORK_PROTOCOL *snp ) { struct efi_snp_device *snpdev = container_of ( snp, struct efi_snp_device, snp ); - DBGC ( snpdev, "SNPDEV %p SHUTDOWN\n", snpdev ); + DBGC2 ( snpdev, "SNPDEV %p SHUTDOWN\n", snpdev ); /* Fail if net device is currently claimed for use by iPXE */ if ( efi_snp_claimed ) @@ -329,21 +326,19 @@ efi_snp_receive_filters ( EFI_SIMPLE_NETWORK_PROTOCOL *snp, UINT32 enable, container_of ( snp, struct efi_snp_device, snp ); unsigned int i; - DBGC ( snpdev, "SNPDEV %p RECEIVE_FILTERS %08x&~%08x%s %ld mcast\n", - snpdev, enable, disable, ( mcast_reset ? " reset" : "" ), - ( ( unsigned long ) mcast_count ) ); + DBGC2 ( snpdev, "SNPDEV %p RECEIVE_FILTERS %08x&~%08x%s %ld mcast\n", + snpdev, enable, disable, ( mcast_reset ? " reset" : "" ), + ( ( unsigned long ) mcast_count ) ); for ( i = 0 ; i < mcast_count ; i++ ) { DBGC2_HDA ( snpdev, i, &mcast[i], snpdev->netdev->ll_protocol->ll_addr_len ); } - /* Lie through our teeth, otherwise MNP refuses to accept us. - * - * Return success even if the SNP device is currently claimed - * for use by iPXE, since otherwise Windows Deployment - * Services refuses to attempt to receive further packets via - * our EFI PXE Base Code protocol. - */ + /* Fail if net device is currently claimed for use by iPXE */ + if ( efi_snp_claimed ) + return EFI_NOT_READY; + + /* Lie through our teeth, otherwise MNP refuses to accept us */ return 0; } @@ -362,8 +357,8 @@ efi_snp_station_address ( EFI_SIMPLE_NETWORK_PROTOCOL *snp, BOOLEAN reset, container_of ( snp, struct efi_snp_device, snp ); struct ll_protocol *ll_protocol = snpdev->netdev->ll_protocol; - DBGC ( snpdev, "SNPDEV %p STATION_ADDRESS %s\n", snpdev, - ( reset ? "reset" : ll_protocol->ntoa ( new ) ) ); + DBGC2 ( snpdev, "SNPDEV %p STATION_ADDRESS %s\n", snpdev, + ( reset ? "reset" : ll_protocol->ntoa ( new ) ) ); /* Fail if net device is currently claimed for use by iPXE */ if ( efi_snp_claimed ) @@ -399,8 +394,8 @@ efi_snp_statistics ( EFI_SIMPLE_NETWORK_PROTOCOL *snp, BOOLEAN reset, container_of ( snp, struct efi_snp_device, snp ); EFI_NETWORK_STATISTICS stats_buf; - DBGC ( snpdev, "SNPDEV %p STATISTICS%s", snpdev, - ( reset ? " reset" : "" ) ); + DBGC2 ( snpdev, "SNPDEV %p STATISTICS%s", snpdev, + ( reset ? " reset" : "" ) ); /* Fail if net device is currently claimed for use by iPXE */ if ( efi_snp_claimed ) @@ -452,7 +447,7 @@ efi_snp_mcast_ip_to_mac ( EFI_SIMPLE_NETWORK_PROTOCOL *snp, BOOLEAN ipv6, ip_str = ( ipv6 ? "(IPv6)" /* FIXME when we have inet6_ntoa() */ : inet_ntoa ( *( ( struct in_addr * ) ip ) ) ); - DBGC ( snpdev, "SNPDEV %p MCAST_IP_TO_MAC %s\n", snpdev, ip_str ); + DBGC2 ( snpdev, "SNPDEV %p MCAST_IP_TO_MAC %s\n", snpdev, ip_str ); /* Fail if net device is currently claimed for use by iPXE */ if ( efi_snp_claimed ) @@ -485,9 +480,9 @@ efi_snp_nvdata ( EFI_SIMPLE_NETWORK_PROTOCOL *snp, BOOLEAN read, struct efi_snp_device *snpdev = container_of ( snp, struct efi_snp_device, snp ); - DBGC ( snpdev, "SNPDEV %p NVDATA %s %lx+%lx\n", snpdev, - ( read ? "read" : "write" ), ( ( unsigned long ) offset ), - ( ( unsigned long ) len ) ); + DBGC2 ( snpdev, "SNPDEV %p NVDATA %s %lx+%lx\n", snpdev, + ( read ? "read" : "write" ), ( ( unsigned long ) offset ), + ( ( unsigned long ) len ) ); if ( ! read ) DBGC2_HDA ( snpdev, offset, data, len ); @@ -807,608 +802,6 @@ static EFI_SIMPLE_NETWORK_PROTOCOL efi_snp_device_snp = { /****************************************************************************** * - * UNDI protocol - * - ****************************************************************************** - */ - -/** Union type for command parameter blocks */ -typedef union { - PXE_CPB_STATION_ADDRESS station_address; - PXE_CPB_FILL_HEADER fill_header; - PXE_CPB_FILL_HEADER_FRAGMENTED fill_header_fragmented; - PXE_CPB_TRANSMIT transmit; - PXE_CPB_RECEIVE receive; -} PXE_CPB_ANY; - -/** Union type for data blocks */ -typedef union { - PXE_DB_GET_INIT_INFO get_init_info; - PXE_DB_STATION_ADDRESS station_address; - PXE_DB_GET_STATUS get_status; - PXE_DB_RECEIVE receive; -} PXE_DB_ANY; - -/** - * Calculate UNDI byte checksum - * - * @v data Data - * @v len Length of data - * @ret sum Checksum - */ -static uint8_t efi_undi_checksum ( void *data, size_t len ) { - uint8_t *bytes = data; - uint8_t sum = 0; - - while ( len-- ) - sum += *bytes++; - return sum; -} - -/** - * Get UNDI SNP device interface number - * - * @v snpdev SNP device - * @ret ifnum UNDI interface number - */ -static unsigned int efi_undi_ifnum ( struct efi_snp_device *snpdev ) { - - /* iPXE network device indexes are one-based (leaving zero - * meaning "unspecified"). UNDI interface numbers are - * zero-based. - */ - return ( snpdev->netdev->index - 1 ); -} - -/** - * Identify UNDI SNP device - * - * @v ifnum Interface number - * @ret snpdev SNP device, or NULL if not found - */ -static struct efi_snp_device * efi_undi_snpdev ( unsigned int ifnum ) { - struct efi_snp_device *snpdev; - - list_for_each_entry ( snpdev, &efi_snp_devices, list ) { - if ( efi_undi_ifnum ( snpdev ) == ifnum ) - return snpdev; - } - return NULL; -} - -/** - * Convert EFI status code to UNDI status code - * - * @v efirc EFI status code - * @ret statcode UNDI status code - */ -static PXE_STATCODE efi_undi_statcode ( EFI_STATUS efirc ) { - - switch ( efirc ) { - case EFI_INVALID_PARAMETER: return PXE_STATCODE_INVALID_PARAMETER; - case EFI_UNSUPPORTED: return PXE_STATCODE_UNSUPPORTED; - case EFI_OUT_OF_RESOURCES: return PXE_STATCODE_BUFFER_FULL; - case EFI_PROTOCOL_ERROR: return PXE_STATCODE_DEVICE_FAILURE; - case EFI_NOT_READY: return PXE_STATCODE_NO_DATA; - default: - return PXE_STATCODE_INVALID_CDB; - } -} - -/** - * Get state - * - * @v snpdev SNP device - * @v cdb Command description block - * @ret efirc EFI status code - */ -static EFI_STATUS efi_undi_get_state ( struct efi_snp_device *snpdev, - PXE_CDB *cdb ) { - EFI_SIMPLE_NETWORK_MODE *mode = &snpdev->mode; - - DBGC ( snpdev, "UNDI %p GET STATE\n", snpdev ); - - /* Return current state */ - if ( mode->State == EfiSimpleNetworkInitialized ) { - cdb->StatFlags |= PXE_STATFLAGS_GET_STATE_INITIALIZED; - } else if ( mode->State == EfiSimpleNetworkStarted ) { - cdb->StatFlags |= PXE_STATFLAGS_GET_STATE_STARTED; - } else { - cdb->StatFlags |= PXE_STATFLAGS_GET_STATE_STOPPED; - } - - return 0; -} - -/** - * Start - * - * @v snpdev SNP device - * @ret efirc EFI status code - */ -static EFI_STATUS efi_undi_start ( struct efi_snp_device *snpdev ) { - EFI_STATUS efirc; - - DBGC ( snpdev, "UNDI %p START\n", snpdev ); - - /* Start SNP device */ - if ( ( efirc = efi_snp_start ( &snpdev->snp ) ) != 0 ) - return efirc; - - return 0; -} - -/** - * Stop - * - * @v snpdev SNP device - * @ret efirc EFI status code - */ -static EFI_STATUS efi_undi_stop ( struct efi_snp_device *snpdev ) { - EFI_STATUS efirc; - - DBGC ( snpdev, "UNDI %p STOP\n", snpdev ); - - /* Stop SNP device */ - if ( ( efirc = efi_snp_stop ( &snpdev->snp ) ) != 0 ) - return efirc; - - return 0; -} - -/** - * Get initialisation information - * - * @v snpdev SNP device - * @v cdb Command description block - * @v db Data block - * @ret efirc EFI status code - */ -static EFI_STATUS efi_undi_get_init_info ( struct efi_snp_device *snpdev, - PXE_CDB *cdb, - PXE_DB_GET_INIT_INFO *db ) { - struct net_device *netdev = snpdev->netdev; - struct ll_protocol *ll_protocol = netdev->ll_protocol; - - DBGC ( snpdev, "UNDI %p GET INIT INFO\n", snpdev ); - - /* Populate structure */ - memset ( db, 0, sizeof ( *db ) ); - db->FrameDataLen = ( netdev->max_pkt_len - ll_protocol->ll_header_len ); - db->MediaHeaderLen = ll_protocol->ll_header_len; - db->HWaddrLen = ll_protocol->ll_addr_len; - db->IFtype = ntohs ( ll_protocol->ll_proto ); - cdb->StatFlags |= ( PXE_STATFLAGS_CABLE_DETECT_SUPPORTED | - PXE_STATFLAGS_GET_STATUS_NO_MEDIA_SUPPORTED ); - - return 0; -} - -/** - * Initialise - * - * @v snpdev SNP device - * @v cdb Command description block - * @v efirc EFI status code - */ -static EFI_STATUS efi_undi_initialize ( struct efi_snp_device *snpdev, - PXE_CDB *cdb ) { - struct net_device *netdev = snpdev->netdev; - EFI_STATUS efirc; - - DBGC ( snpdev, "UNDI %p INITIALIZE\n", snpdev ); - - /* Reset SNP device */ - if ( ( efirc = efi_snp_initialize ( &snpdev->snp, 0, 0 ) ) != 0 ) - return efirc; - - /* Report link state */ - if ( ! netdev_link_ok ( netdev ) ) - cdb->StatFlags |= PXE_STATFLAGS_INITIALIZED_NO_MEDIA; - - return 0; -} - -/** - * Reset - * - * @v snpdev SNP device - * @v efirc EFI status code - */ -static EFI_STATUS efi_undi_reset ( struct efi_snp_device *snpdev ) { - EFI_STATUS efirc; - - DBGC ( snpdev, "UNDI %p RESET\n", snpdev ); - - /* Reset SNP device */ - if ( ( efirc = efi_snp_reset ( &snpdev->snp, 0 ) ) != 0 ) - return efirc; - - return 0; -} - -/** - * Shutdown - * - * @v snpdev SNP device - * @v efirc EFI status code - */ -static EFI_STATUS efi_undi_shutdown ( struct efi_snp_device *snpdev ) { - EFI_STATUS efirc; - - DBGC ( snpdev, "UNDI %p SHUTDOWN\n", snpdev ); - - /* Reset SNP device */ - if ( ( efirc = efi_snp_shutdown ( &snpdev->snp ) ) != 0 ) - return efirc; - - return 0; -} - -/** - * Get/set receive filters - * - * @v snpdev SNP device - * @v cdb Command description block - * @v efirc EFI status code - */ -static EFI_STATUS efi_undi_receive_filters ( struct efi_snp_device *snpdev, - PXE_CDB *cdb ) { - - DBGC ( snpdev, "UNDI %p RECEIVE FILTERS\n", snpdev ); - - /* Mark everything as supported */ - cdb->StatFlags |= ( PXE_STATFLAGS_RECEIVE_FILTER_UNICAST | - PXE_STATFLAGS_RECEIVE_FILTER_BROADCAST | - PXE_STATFLAGS_RECEIVE_FILTER_PROMISCUOUS | - PXE_STATFLAGS_RECEIVE_FILTER_ALL_MULTICAST ); - - return 0; -} - -/** - * Get/set station address - * - * @v snpdev SNP device - * @v cdb Command description block - * @v cpb Command parameter block - * @v efirc EFI status code - */ -static EFI_STATUS efi_undi_station_address ( struct efi_snp_device *snpdev, - PXE_CDB *cdb, - PXE_CPB_STATION_ADDRESS *cpb, - PXE_DB_STATION_ADDRESS *db ) { - struct net_device *netdev = snpdev->netdev; - struct ll_protocol *ll_protocol = netdev->ll_protocol; - void *mac; - int reset; - EFI_STATUS efirc; - - DBGC ( snpdev, "UNDI %p STATION ADDRESS\n", snpdev ); - - /* Update address if applicable */ - reset = ( cdb->OpFlags & PXE_OPFLAGS_STATION_ADDRESS_RESET ); - mac = ( cpb ? &cpb->StationAddr : NULL ); - if ( ( reset || mac ) && - ( ( efirc = efi_snp_station_address ( &snpdev->snp, reset, - mac ) ) != 0 ) ) - return efirc; - - /* Fill in current addresses, if applicable */ - if ( db ) { - memset ( db, 0, sizeof ( *db ) ); - memcpy ( &db->StationAddr, netdev->ll_addr, - ll_protocol->ll_addr_len ); - memcpy ( &db->BroadcastAddr, netdev->ll_broadcast, - ll_protocol->ll_addr_len ); - memcpy ( &db->PermanentAddr, netdev->hw_addr, - ll_protocol->hw_addr_len ); - } - - return 0; -} - -/** - * Get interrupt status - * - * @v snpdev SNP device - * @v cdb Command description block - * @v db Data block - * @v efirc EFI status code - */ -static EFI_STATUS efi_undi_get_status ( struct efi_snp_device *snpdev, - PXE_CDB *cdb, PXE_DB_GET_STATUS *db ) { - UINT32 interrupts; - VOID *txbuf; - struct io_buffer *rxbuf; - EFI_STATUS efirc; - - DBGC2 ( snpdev, "UNDI %p GET STATUS\n", snpdev ); - - /* Get status */ - if ( ( efirc = efi_snp_get_status ( &snpdev->snp, &interrupts, - &txbuf ) ) != 0 ) - return efirc; - - /* Report status */ - memset ( db, 0, sizeof ( *db ) ); - if ( interrupts & EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT ) - cdb->StatFlags |= PXE_STATFLAGS_GET_STATUS_RECEIVE; - if ( interrupts & EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT ) - cdb->StatFlags |= PXE_STATFLAGS_GET_STATUS_TRANSMIT; - if ( txbuf ) { - db->TxBuffer[0] = ( ( intptr_t ) txbuf ); - } else { - cdb->StatFlags |= PXE_STATFLAGS_GET_STATUS_NO_TXBUFS_WRITTEN; - /* The specification states clearly that UNDI drivers - * should set TXBUF_QUEUE_EMPTY if all completed - * buffer addresses are written into the returned data - * block. However, SnpDxe chooses to interpret - * TXBUF_QUEUE_EMPTY as a synonym for - * NO_TXBUFS_WRITTEN, thereby rendering it entirely - * pointless. Work around this UEFI stupidity, as per - * usual. - */ - if ( snpdev->tx_prod == snpdev->tx_cons ) - cdb->StatFlags |= - PXE_STATFLAGS_GET_STATUS_TXBUF_QUEUE_EMPTY; - } - rxbuf = list_first_entry ( &snpdev->rx, struct io_buffer, list ); - if ( rxbuf ) - db->RxFrameLen = iob_len ( rxbuf ); - if ( ! netdev_link_ok ( snpdev->netdev ) ) - cdb->StatFlags |= PXE_STATFLAGS_GET_STATUS_NO_MEDIA; - - return 0; -} - -/** - * Fill header - * - * @v snpdev SNP device - * @v cdb Command description block - * @v cpb Command parameter block - * @v efirc EFI status code - */ -static EFI_STATUS efi_undi_fill_header ( struct efi_snp_device *snpdev, - PXE_CDB *cdb, PXE_CPB_ANY *cpb ) { - struct net_device *netdev = snpdev->netdev; - struct ll_protocol *ll_protocol = netdev->ll_protocol; - PXE_CPB_FILL_HEADER *whole = &cpb->fill_header; - PXE_CPB_FILL_HEADER_FRAGMENTED *fragged = &cpb->fill_header_fragmented; - VOID *data; - void *dest; - void *src; - uint16_t proto; - struct io_buffer iobuf; - int rc; - - /* SnpDxe will (pointlessly) use PXE_CPB_FILL_HEADER_FRAGMENTED - * even though we choose to explicitly not claim support for - * fragments via PXE_ROMID_IMP_FRAG_SUPPORTED. - */ - if ( cdb->OpFlags & PXE_OPFLAGS_FILL_HEADER_FRAGMENTED ) { - data = ( ( void * ) ( intptr_t ) fragged->FragDesc[0].FragAddr); - dest = &fragged->DestAddr; - src = &fragged->SrcAddr; - proto = fragged->Protocol; - } else { - data = ( ( void * ) ( intptr_t ) whole->MediaHeader ); - dest = &whole->DestAddr; - src = &whole->SrcAddr; - proto = whole->Protocol; - } - - /* Construct link-layer header */ - iob_populate ( &iobuf, data, 0, ll_protocol->ll_header_len ); - iob_reserve ( &iobuf, ll_protocol->ll_header_len ); - if ( ( rc = ll_protocol->push ( netdev, &iobuf, dest, src, - proto ) ) != 0 ) - return EFIRC ( rc ); - - return 0; -} - -/** - * Transmit - * - * @v snpdev SNP device - * @v cpb Command parameter block - * @v efirc EFI status code - */ -static EFI_STATUS efi_undi_transmit ( struct efi_snp_device *snpdev, - PXE_CPB_TRANSMIT *cpb ) { - VOID *data = ( ( void * ) ( intptr_t ) cpb->FrameAddr ); - EFI_STATUS efirc; - - DBGC2 ( snpdev, "UNDI %p TRANSMIT\n", snpdev ); - - /* Transmit packet */ - if ( ( efirc = efi_snp_transmit ( &snpdev->snp, 0, cpb->DataLen, - data, NULL, NULL, NULL ) ) != 0 ) - return efirc; - - return 0; -} - -/** - * Receive - * - * @v snpdev SNP device - * @v cpb Command parameter block - * @v efirc EFI status code - */ -static EFI_STATUS efi_undi_receive ( struct efi_snp_device *snpdev, - PXE_CPB_RECEIVE *cpb, - PXE_DB_RECEIVE *db ) { - struct net_device *netdev = snpdev->netdev; - struct ll_protocol *ll_protocol = netdev->ll_protocol; - VOID *data = ( ( void * ) ( intptr_t ) cpb->BufferAddr ); - UINTN hdr_len; - UINTN len = cpb->BufferLen; - EFI_MAC_ADDRESS src; - EFI_MAC_ADDRESS dest; - UINT16 proto; - EFI_STATUS efirc; - - DBGC2 ( snpdev, "UNDI %p RECEIVE\n", snpdev ); - - /* Receive packet */ - if ( ( efirc = efi_snp_receive ( &snpdev->snp, &hdr_len, &len, data, - &src, &dest, &proto ) ) != 0 ) - return efirc; - - /* Describe frame */ - memset ( db, 0, sizeof ( *db ) ); - memcpy ( &db->SrcAddr, &src, ll_protocol->ll_addr_len ); - memcpy ( &db->DestAddr, &dest, ll_protocol->ll_addr_len ); - db->FrameLen = len; - db->Protocol = proto; - db->MediaHeaderLen = ll_protocol->ll_header_len; - db->Type = PXE_FRAME_TYPE_PROMISCUOUS; - - return 0; -} - -/** UNDI entry point */ -static EFIAPI VOID efi_undi_issue ( UINT64 cdb_phys ) { - PXE_CDB *cdb = ( ( void * ) ( intptr_t ) cdb_phys ); - PXE_CPB_ANY *cpb = ( ( void * ) ( intptr_t ) cdb->CPBaddr ); - PXE_DB_ANY *db = ( ( void * ) ( intptr_t ) cdb->DBaddr ); - struct efi_snp_device *snpdev; - EFI_STATUS efirc; - - /* Identify device */ - snpdev = efi_undi_snpdev ( cdb->IFnum ); - if ( ! snpdev ) { - DBGC ( cdb, "UNDI invalid interface number %d\n", cdb->IFnum ); - cdb->StatCode = PXE_STATCODE_INVALID_CDB; - cdb->StatFlags = PXE_STATFLAGS_COMMAND_FAILED; - return; - } - - /* Fail if net device is currently claimed for use by iPXE */ - if ( efi_snp_claimed ) { - cdb->StatCode = PXE_STATCODE_BUSY; - cdb->StatFlags = PXE_STATFLAGS_COMMAND_FAILED; - return; - } - - /* Handle opcode */ - cdb->StatCode = PXE_STATCODE_SUCCESS; - cdb->StatFlags = PXE_STATFLAGS_COMMAND_COMPLETE; - switch ( cdb->OpCode ) { - - case PXE_OPCODE_GET_STATE: - efirc = efi_undi_get_state ( snpdev, cdb ); - break; - - case PXE_OPCODE_START: - efirc = efi_undi_start ( snpdev ); - break; - - case PXE_OPCODE_STOP: - efirc = efi_undi_stop ( snpdev ); - break; - - case PXE_OPCODE_GET_INIT_INFO: - efirc = efi_undi_get_init_info ( snpdev, cdb, - &db->get_init_info ); - break; - - case PXE_OPCODE_INITIALIZE: - efirc = efi_undi_initialize ( snpdev, cdb ); - break; - - case PXE_OPCODE_RESET: - efirc = efi_undi_reset ( snpdev ); - break; - - case PXE_OPCODE_SHUTDOWN: - efirc = efi_undi_shutdown ( snpdev ); - break; - - case PXE_OPCODE_RECEIVE_FILTERS: - efirc = efi_undi_receive_filters ( snpdev, cdb ); - break; - - case PXE_OPCODE_STATION_ADDRESS: - efirc = efi_undi_station_address ( snpdev, cdb, - &cpb->station_address, - &db->station_address ); - break; - - case PXE_OPCODE_GET_STATUS: - efirc = efi_undi_get_status ( snpdev, cdb, &db->get_status ); - break; - - case PXE_OPCODE_FILL_HEADER: - efirc = efi_undi_fill_header ( snpdev, cdb, cpb ); - break; - - case PXE_OPCODE_TRANSMIT: - efirc = efi_undi_transmit ( snpdev, &cpb->transmit ); - break; - - case PXE_OPCODE_RECEIVE: - efirc = efi_undi_receive ( snpdev, &cpb->receive, - &db->receive ); - break; - - default: - DBGC ( snpdev, "UNDI %p unsupported opcode %#04x\n", - snpdev, cdb->OpCode ); - efirc = EFI_UNSUPPORTED; - break; - } - - /* Convert EFI status code to UNDI status code */ - if ( efirc != 0 ) { - cdb->StatFlags &= ~PXE_STATFLAGS_STATUS_MASK; - cdb->StatFlags |= PXE_STATFLAGS_COMMAND_FAILED; - cdb->StatCode = efi_undi_statcode ( efirc ); - } -} - -/** UNDI interface - * - * Must be aligned on a 16-byte boundary, for no particularly good - * reason. - */ -static PXE_SW_UNDI efi_snp_undi __attribute__ (( aligned ( 16 ) )) = { - .Signature = PXE_ROMID_SIGNATURE, - .Len = sizeof ( efi_snp_undi ), - .Rev = PXE_ROMID_REV, - .MajorVer = PXE_ROMID_MAJORVER, - .MinorVer = PXE_ROMID_MINORVER, - .Implementation = ( PXE_ROMID_IMP_SW_VIRT_ADDR | - PXE_ROMID_IMP_STATION_ADDR_SETTABLE | - PXE_ROMID_IMP_PROMISCUOUS_MULTICAST_RX_SUPPORTED | - PXE_ROMID_IMP_PROMISCUOUS_RX_SUPPORTED | - PXE_ROMID_IMP_BROADCAST_RX_SUPPORTED | - PXE_ROMID_IMP_TX_COMPLETE_INT_SUPPORTED | - PXE_ROMID_IMP_PACKET_RX_INT_SUPPORTED ), - /* SnpDxe checks that BusCnt is non-zero. It makes no further - * use of BusCnt, and never looks as BusType[]. As with much - * of the EDK2 code, this check seems to serve no purpose - * whatsoever but must nonetheless be humoured. - */ - .BusCnt = 1, - .BusType[0] = PXE_BUSTYPE ( 'i', 'P', 'X', 'E' ), -}; - -/** Network Identification Interface (NII) */ -static EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL efi_snp_device_nii = { - .Revision = EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL_REVISION, - .StringId = "UNDI", - .Type = EfiNetworkInterfaceUndi, - .MajorVer = 3, - .MinorVer = 1, - .Ipv6Supported = TRUE, /* This is a raw packet interface, FFS! */ -}; - -/****************************************************************************** - * * Component name protocol * ****************************************************************************** @@ -1497,9 +890,6 @@ efi_snp_load_file ( EFI_LOAD_FILE_PROTOCOL *load_file, if ( ( rc = ipxe ( netdev ) ) != 0 ) goto err_ipxe; - /* Reset console */ - console_reset(); - err_ipxe: efi_watchdog_stop(); efi_snp_release(); @@ -1544,13 +934,13 @@ static int efi_snp_probe ( struct net_device *netdev ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; struct efi_device *efidev; struct efi_snp_device *snpdev; + union { + EFI_DEVICE_PATH_PROTOCOL *path; + void *interface; + } path; EFI_DEVICE_PATH_PROTOCOL *path_end; MAC_ADDR_DEVICE_PATH *macpath; - VLAN_DEVICE_PATH *vlanpath; size_t path_prefix_len = 0; - unsigned int ifcnt; - unsigned int tag; - void *interface; EFI_STATUS efirc; int rc; @@ -1598,17 +988,10 @@ static int efi_snp_probe ( struct net_device *netdev ) { efi_snp_set_mode ( snpdev ); /* Populate the NII structure */ - memcpy ( &snpdev->nii, &efi_snp_device_nii, sizeof ( snpdev->nii ) ); - snpdev->nii.Id = ( ( intptr_t ) &efi_snp_undi ); - snpdev->nii.IfNum = efi_undi_ifnum ( snpdev ); - efi_snp_undi.EntryPoint = ( ( intptr_t ) efi_undi_issue ); - ifcnt = ( ( efi_snp_undi.IFcntExt << 8 ) | efi_snp_undi.IFcnt ); - if ( ifcnt < snpdev->nii.IfNum ) - ifcnt = snpdev->nii.IfNum; - efi_snp_undi.IFcnt = ( ifcnt & 0xff ); - efi_snp_undi.IFcntExt = ( ifcnt >> 8 ); - efi_snp_undi.Fudge -= efi_undi_checksum ( &efi_snp_undi, - sizeof ( efi_snp_undi ) ); + snpdev->nii.Revision = + EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL_REVISION; + strncpy ( snpdev->nii.StringId, "iPXE", + sizeof ( snpdev->nii.StringId ) ); /* Populate the component name structure */ efi_snprintf ( snpdev->driver_name, @@ -1634,36 +1017,40 @@ static int efi_snp_probe ( struct net_device *netdev ) { sizeof ( snpdev->name[0] ) ), "%s", netdev->name ); + /* Get the parent device path */ + if ( ( efirc = bs->OpenProtocol ( efidev->device, + &efi_device_path_protocol_guid, + &path.interface, efi_image_handle, + efidev->device, + EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){ + rc = -EEFI ( efirc ); + DBGC ( snpdev, "SNPDEV %p cannot get %p %s device path: %s\n", + snpdev, efidev->device, + efi_handle_name ( efidev->device ), strerror ( rc ) ); + goto err_open_device_path; + } + /* Allocate the new device path */ - path_prefix_len = efi_devpath_len ( efidev->path ); + path_end = efi_devpath_end ( path.path ); + path_prefix_len = ( ( ( void * ) path_end ) - ( ( void * ) path.path )); snpdev->path = zalloc ( path_prefix_len + sizeof ( *macpath ) + - sizeof ( *vlanpath ) + sizeof ( *path_end ) ); + sizeof ( *path_end ) ); if ( ! snpdev->path ) { rc = -ENOMEM; goto err_alloc_device_path; } /* Populate the device path */ - memcpy ( snpdev->path, efidev->path, path_prefix_len ); + memcpy ( snpdev->path, path.path, path_prefix_len ); macpath = ( ( ( void * ) snpdev->path ) + path_prefix_len ); + path_end = ( ( void * ) ( macpath + 1 ) ); memset ( macpath, 0, sizeof ( *macpath ) ); macpath->Header.Type = MESSAGING_DEVICE_PATH; macpath->Header.SubType = MSG_MAC_ADDR_DP; macpath->Header.Length[0] = sizeof ( *macpath ); memcpy ( &macpath->MacAddress, netdev->ll_addr, - netdev->ll_protocol->ll_addr_len ); + sizeof ( macpath->MacAddress ) ); macpath->IfType = ntohs ( netdev->ll_protocol->ll_proto ); - if ( ( tag = vlan_tag ( netdev ) ) ) { - vlanpath = ( ( ( void * ) macpath ) + sizeof ( *macpath ) ); - memset ( vlanpath, 0, sizeof ( *vlanpath ) ); - vlanpath->Header.Type = MESSAGING_DEVICE_PATH; - vlanpath->Header.SubType = MSG_VLAN_DP; - vlanpath->Header.Length[0] = sizeof ( *vlanpath ); - vlanpath->VlanId = tag; - path_end = ( ( ( void * ) vlanpath ) + sizeof ( *vlanpath ) ); - } else { - path_end = ( ( ( void * ) macpath ) + sizeof ( *macpath ) ); - } memset ( path_end, 0, sizeof ( *path_end ) ); path_end->Type = END_DEVICE_PATH_TYPE; path_end->SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE; @@ -1680,47 +1067,16 @@ static int efi_snp_probe ( struct net_device *netdev ) { &efi_load_file_protocol_guid, &snpdev->load_file, NULL ) ) != 0 ) { rc = -EEFI ( efirc ); - DBGC ( snpdev, "SNPDEV %p could not install protocols: %s\n", - snpdev, strerror ( rc ) ); + DBGC ( snpdev, "SNPDEV %p could not install protocols: " + "%s\n", snpdev, strerror ( rc ) ); goto err_install_protocol_interface; } - /* SnpDxe will repeatedly start up and shut down our NII/UNDI - * interface (in order to obtain the MAC address) before - * discovering that it cannot install another SNP on the same - * handle. This causes the underlying network device to be - * unexpectedly closed. - * - * Prevent this by opening our own NII (and NII31) protocol - * instances to prevent SnpDxe from attempting to bind to - * them. - */ - if ( ( efirc = bs->OpenProtocol ( snpdev->handle, - &efi_nii_protocol_guid, &interface, - efi_image_handle, snpdev->handle, - ( EFI_OPEN_PROTOCOL_BY_DRIVER | - EFI_OPEN_PROTOCOL_EXCLUSIVE )))!=0){ - rc = -EEFI ( efirc ); - DBGC ( snpdev, "SNPDEV %p could not open NII protocol: %s\n", - snpdev, strerror ( rc ) ); - goto err_open_nii; - } - if ( ( efirc = bs->OpenProtocol ( snpdev->handle, - &efi_nii31_protocol_guid, &interface, - efi_image_handle, snpdev->handle, - ( EFI_OPEN_PROTOCOL_BY_DRIVER | - EFI_OPEN_PROTOCOL_EXCLUSIVE )))!=0){ - rc = -EEFI ( efirc ); - DBGC ( snpdev, "SNPDEV %p could not open NII31 protocol: %s\n", - snpdev, strerror ( rc ) ); - goto err_open_nii31; - } - /* Add as child of EFI parent device */ if ( ( rc = efi_child_add ( efidev->device, snpdev->handle ) ) != 0 ) { - DBGC ( snpdev, "SNPDEV %p could not become child of %s: %s\n", - snpdev, efi_handle_name ( efidev->device ), - strerror ( rc ) ); + DBGC ( snpdev, "SNPDEV %p could not become child of %p %s: " + "%s\n", snpdev, efidev->device, + efi_handle_name ( efidev->device ), strerror ( rc ) ); goto err_efi_child_add; } @@ -1741,21 +1097,15 @@ static int efi_snp_probe ( struct net_device *netdev ) { bs->CloseProtocol ( efidev->device, &efi_device_path_protocol_guid, efi_image_handle, efidev->device ); - DBGC ( snpdev, "SNPDEV %p installed for %s as device %s\n", - snpdev, netdev->name, efi_handle_name ( snpdev->handle ) ); + DBGC ( snpdev, "SNPDEV %p installed for %s as device %p %s\n", + snpdev, netdev->name, snpdev->handle, + efi_handle_name ( snpdev->handle ) ); return 0; - list_del ( &snpdev->list ); if ( snpdev->package_list ) efi_snp_hii_uninstall ( snpdev ); efi_child_del ( efidev->device, snpdev->handle ); err_efi_child_add: - bs->CloseProtocol ( snpdev->handle, &efi_nii_protocol_guid, - efi_image_handle, snpdev->handle ); - err_open_nii: - bs->CloseProtocol ( snpdev->handle, &efi_nii31_protocol_guid, - efi_image_handle, snpdev->handle ); - err_open_nii31: bs->UninstallMultipleProtocolInterfaces ( snpdev->handle, &efi_simple_network_protocol_guid, &snpdev->snp, @@ -1768,6 +1118,9 @@ static int efi_snp_probe ( struct net_device *netdev ) { err_install_protocol_interface: free ( snpdev->path ); err_alloc_device_path: + bs->CloseProtocol ( efidev->device, &efi_device_path_protocol_guid, + efi_image_handle, efidev->device ); + err_open_device_path: bs->CloseEvent ( snpdev->snp.WaitForPacket ); err_create_event: err_ll_addr_len: @@ -1820,14 +1173,10 @@ static void efi_snp_remove ( struct net_device *netdev ) { } /* Uninstall the SNP */ - list_del ( &snpdev->list ); if ( snpdev->package_list ) efi_snp_hii_uninstall ( snpdev ); efi_child_del ( snpdev->efidev->device, snpdev->handle ); - bs->CloseProtocol ( snpdev->handle, &efi_nii_protocol_guid, - efi_image_handle, snpdev->handle ); - bs->CloseProtocol ( snpdev->handle, &efi_nii31_protocol_guid, - efi_image_handle, snpdev->handle ); + list_del ( &snpdev->list ); bs->UninstallMultipleProtocolInterfaces ( snpdev->handle, &efi_simple_network_protocol_guid, &snpdev->snp, @@ -1883,16 +1232,15 @@ struct efi_snp_device * last_opened_snpdev ( void ) { } /** - * Add to SNP claimed/released count + * Set SNP claimed/released state * - * @v delta Claim count change + * @v claimed Network devices are claimed for use by iPXE */ -void efi_snp_add_claim ( int delta ) { +void efi_snp_set_claimed ( int claimed ) { struct efi_snp_device *snpdev; /* Claim SNP devices */ - efi_snp_claimed += delta; - assert ( efi_snp_claimed >= 0 ); + efi_snp_claimed = claimed; /* Update SNP mode state for each interface */ list_for_each_entry ( snpdev, &efi_snp_devices, list ) diff --git a/roms/ipxe/src/interface/efi/efi_snp_hii.c b/roms/ipxe/src/interface/efi/efi_snp_hii.c index 1e87ea15a..720402bdb 100644 --- a/roms/ipxe/src/interface/efi/efi_snp_hii.c +++ b/roms/ipxe/src/interface/efi/efi_snp_hii.c @@ -546,13 +546,6 @@ efi_snp_hii_extract_config ( const EFI_HII_CONFIG_ACCESS_PROTOCOL *hii, /* Initialise results */ *results = NULL; - /* Work around apparently broken UEFI specification */ - if ( ! ( request && request[0] ) ) { - DBGC ( snpdev, "SNPDEV %p ExtractConfig ignoring malformed " - "request\n", snpdev ); - return EFI_INVALID_PARAMETER; - } - /* Process all request fragments */ for ( pos = *progress = request ; *progress && **progress ; pos = *progress + 1 ) { diff --git a/roms/ipxe/src/interface/efi/efi_timer.c b/roms/ipxe/src/interface/efi/efi_timer.c index da064120a..81620c92c 100644 --- a/roms/ipxe/src/interface/efi/efi_timer.c +++ b/roms/ipxe/src/interface/efi/efi_timer.c @@ -25,10 +25,12 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <string.h> #include <errno.h> +#include <limits.h> +#include <assert.h> #include <unistd.h> #include <ipxe/timer.h> -#include <ipxe/init.h> #include <ipxe/efi/efi.h> +#include <ipxe/efi/Protocol/Cpu.h> /** @file * @@ -36,14 +38,19 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); * */ -/** Current tick count */ -static unsigned long efi_jiffies; +/** Scale factor to apply to CPU timer 0 + * + * The timer is scaled down in order to ensure that reasonable values + * for "number of ticks" don't exceed the size of an unsigned long. + */ +#define EFI_TIMER0_SHIFT 12 -/** Timer tick event */ -static EFI_EVENT efi_tick_event; +/** Calibration time */ +#define EFI_CALIBRATE_DELAY_MS 1 -/** Colour for debug messages */ -#define colour &efi_jiffies +/** CPU protocol */ +static EFI_CPU_ARCH_PROTOCOL *cpu_arch; +EFI_REQUIRE_PROTOCOL ( EFI_CPU_ARCH_PROTOCOL, &cpu_arch ); /** * Delay for a fixed number of microseconds @@ -57,8 +64,8 @@ static void efi_udelay ( unsigned long usecs ) { if ( ( efirc = bs->Stall ( usecs ) ) != 0 ) { rc = -EEFI ( efirc ); - DBGC ( colour, "EFI could not delay for %ldus: %s\n", - usecs, strerror ( rc ) ); + DBG ( "EFI could not delay for %ldus: %s\n", + usecs, strerror ( rc ) ); /* Probably screwed */ } } @@ -69,92 +76,53 @@ static void efi_udelay ( unsigned long usecs ) { * @ret ticks Current time, in ticks */ static unsigned long efi_currticks ( void ) { - - return efi_jiffies; -} - -/** - * Timer tick - * - * @v event Timer tick event - * @v context Event context - */ -static EFIAPI void efi_tick ( EFI_EVENT event __unused, - void *context __unused ) { - - /* Increment tick count */ - efi_jiffies++; -} - -/** - * Start timer tick - * - */ -static void efi_tick_startup ( void ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; + UINT64 time; EFI_STATUS efirc; int rc; - /* Create timer tick event */ - if ( ( efirc = bs->CreateEvent ( ( EVT_TIMER | EVT_NOTIFY_SIGNAL ), - TPL_CALLBACK, efi_tick, NULL, - &efi_tick_event ) ) != 0 ) { + /* Read CPU timer 0 (TSC) */ + if ( ( efirc = cpu_arch->GetTimerValue ( cpu_arch, 0, &time, + NULL ) ) != 0 ) { rc = -EEFI ( efirc ); - DBGC ( colour, "EFI could not create timer tick: %s\n", - strerror ( rc ) ); - /* Nothing we can do about it */ - return; + DBG ( "EFI could not read CPU timer: %s\n", strerror ( rc ) ); + /* Probably screwed */ + return -1UL; } - /* Start timer tick */ - if ( ( efirc = bs->SetTimer ( efi_tick_event, TimerPeriodic, - ( 10000000 / EFI_TICKS_PER_SEC ) ) ) !=0){ - rc = -EEFI ( efirc ); - DBGC ( colour, "EFI could not start timer tick: %s\n", - strerror ( rc ) ); - /* Nothing we can do about it */ - return; - } - DBGC ( colour, "EFI timer started at %d ticks per second\n", - EFI_TICKS_PER_SEC ); + return ( time >> EFI_TIMER0_SHIFT ); } /** - * Stop timer tick + * Get number of ticks per second * - * @v booting System is shutting down in order to boot + * @ret ticks_per_sec Number of ticks per second */ -static void efi_tick_shutdown ( int booting __unused ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - EFI_STATUS efirc; - int rc; - - /* Stop timer tick */ - if ( ( efirc = bs->SetTimer ( efi_tick_event, TimerCancel, 0 ) ) != 0 ){ - rc = -EEFI ( efirc ); - DBGC ( colour, "EFI could not stop timer tick: %s\n", - strerror ( rc ) ); - /* Self-destruct initiated */ - return; +static unsigned long efi_ticks_per_sec ( void ) { + static unsigned long ticks_per_sec = 0; + + /* Calibrate timer, if necessary. EFI does nominally provide + * the timer speed via the (optional) TimerPeriod parameter to + * the GetTimerValue() call, but it gets the speed slightly + * wrong. By up to three orders of magnitude. Not helpful. + */ + if ( ! ticks_per_sec ) { + unsigned long start; + unsigned long elapsed; + + DBG ( "Calibrating EFI timer with a %d ms delay\n", + EFI_CALIBRATE_DELAY_MS ); + start = currticks(); + mdelay ( EFI_CALIBRATE_DELAY_MS ); + elapsed = ( currticks() - start ); + ticks_per_sec = ( elapsed * ( 1000 / EFI_CALIBRATE_DELAY_MS )); + DBG ( "EFI CPU timer calibrated at %ld ticks in %d ms (%ld " + "ticks/sec)\n", elapsed, EFI_CALIBRATE_DELAY_MS, + ticks_per_sec ); } - DBGC ( colour, "EFI timer stopped\n" ); - /* Destroy timer tick event */ - if ( ( efirc = bs->CloseEvent ( efi_tick_event ) ) != 0 ) { - rc = -EEFI ( efirc ); - DBGC ( colour, "EFI could not destroy timer tick: %s\n", - strerror ( rc ) ); - /* Probably non-fatal */ - return; - } + return ticks_per_sec; } -/** Timer tick startup function */ -struct startup_fn efi_tick_startup_fn __startup_fn ( STARTUP_EARLY ) = { - .startup = efi_tick_startup, - .shutdown = efi_tick_shutdown, -}; - PROVIDE_TIMER ( efi, udelay, efi_udelay ); PROVIDE_TIMER ( efi, currticks, efi_currticks ); -PROVIDE_TIMER_INLINE ( efi, ticks_per_sec ); +PROVIDE_TIMER ( efi, ticks_per_sec, efi_ticks_per_sec ); diff --git a/roms/ipxe/src/interface/efi/efi_usb.c b/roms/ipxe/src/interface/efi/efi_usb.c deleted file mode 100644 index db8c3d348..000000000 --- a/roms/ipxe/src/interface/efi/efi_usb.c +++ /dev/null @@ -1,1305 +0,0 @@ -/* - * Copyright (C) 2015 Michael Brown <mbrown@fensystems.co.uk>. - * - * 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 (at your option) 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 <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <errno.h> -#include <assert.h> -#include <ipxe/efi/efi.h> -#include <ipxe/efi/efi_utils.h> -#include <ipxe/efi/efi_driver.h> -#include <ipxe/efi/efi_usb.h> -#include <ipxe/usb.h> - -/** @file - * - * EFI USB I/O PROTOCOL - * - */ - -/** - * Transcribe data direction (for debugging) - * - * @v direction Data direction - * @ret text Transcribed data direction - */ -static const char * efi_usb_direction_name ( EFI_USB_DATA_DIRECTION direction ){ - - switch ( direction ) { - case EfiUsbDataIn: return "in"; - case EfiUsbDataOut: return "out"; - case EfiUsbNoData: return "none"; - default: return "<UNKNOWN>"; - } -} - -/****************************************************************************** - * - * Endpoints - * - ****************************************************************************** - */ - -/** - * Poll USB bus - * - * @v usbdev EFI USB device - */ -static void efi_usb_poll ( struct efi_usb_device *usbdev ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - struct usb_bus *bus = usbdev->usb->port->hub->bus; - EFI_TPL tpl; - - /* UEFI manages to ingeniously combine the worst aspects of - * both polling and interrupt-driven designs. There is no way - * to support proper interrupt-driven operation, since there - * is no way to hook in an interrupt service routine. A - * mockery of interrupts is provided by UEFI timers, which - * trigger at a preset rate and can fire at any time. - * - * We therefore have all of the downsides of a polling design - * (inefficiency and inability to sleep until something - * interesting happens) combined with all of the downsides of - * an interrupt-driven design (the complexity of code that - * could be preempted at any time). - * - * The UEFI specification expects us to litter the entire - * codebase with calls to RaiseTPL() as needed for sections of - * code that are not reentrant. Since this doesn't actually - * gain us any substantive benefits (since even with such - * calls we would still be suffering from the limitations of a - * polling design), we instead choose to wrap only calls to - * usb_poll(). This should be sufficient for most practical - * purposes. - * - * A "proper" solution would involve rearchitecting the whole - * codebase to support interrupt-driven operation. - */ - tpl = bs->RaiseTPL ( TPL_NOTIFY ); - - /* Poll bus */ - usb_poll ( bus ); - - /* Restore task priority level */ - bs->RestoreTPL ( tpl ); -} - -/** - * Poll USB bus (from endpoint event timer) - * - * @v event EFI event - * @v context EFI USB endpoint - */ -static VOID EFIAPI efi_usb_timer ( EFI_EVENT event __unused, - VOID *context ) { - struct efi_usb_endpoint *usbep = context; - struct usb_bus *bus = usbep->usbintf->usbdev->usb->port->hub->bus; - - /* Poll bus */ - usb_poll ( bus ); - - /* Refill endpoint */ - usb_refill ( &usbep->ep ); -} - -/** - * Get endpoint MTU - * - * @v usbintf EFI USB interface - * @v endpoint Endpoint address - * @ret mtu Endpoint MTU, or negative error - */ -static int efi_usb_mtu ( struct efi_usb_interface *usbintf, - unsigned int endpoint ) { - struct efi_usb_device *usbdev = usbintf->usbdev; - struct usb_interface_descriptor *interface; - struct usb_endpoint_descriptor *desc; - - /* Locate cached interface descriptor */ - interface = usb_interface_descriptor ( usbdev->config, - usbintf->interface, - usbintf->alternate ); - if ( ! interface ) { - DBGC ( usbdev, "USBDEV %s alt %d has no interface descriptor\n", - usbintf->name, usbintf->alternate ); - return -ENOENT; - } - - /* Locate and copy cached endpoint descriptor */ - for_each_interface_descriptor ( desc, usbdev->config, interface ) { - if ( ( desc->header.type == USB_ENDPOINT_DESCRIPTOR ) && - ( desc->endpoint == endpoint ) ) - return USB_ENDPOINT_MTU ( le16_to_cpu ( desc->sizes ) ); - } - - DBGC ( usbdev, "USBDEV %s alt %d ep %02x has no descriptor\n", - usbintf->name, usbintf->alternate, endpoint ); - return -ENOENT; -} - -/** - * Open endpoint - * - * @v usbintf EFI USB interface - * @v endpoint Endpoint address - * @v attributes Endpoint attributes - * @v interval Interval (in milliseconds) - * @v driver Driver operations - * @ret rc Return status code - */ -static int efi_usb_open ( struct efi_usb_interface *usbintf, - unsigned int endpoint, unsigned int attributes, - unsigned int interval, - struct usb_endpoint_driver_operations *driver ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - struct efi_usb_device *usbdev = usbintf->usbdev; - struct efi_usb_endpoint *usbep; - unsigned int index = USB_ENDPOINT_IDX ( endpoint ); - int mtu; - EFI_STATUS efirc; - int rc; - - /* Get endpoint MTU */ - mtu = efi_usb_mtu ( usbintf, endpoint ); - if ( mtu < 0 ) { - rc = mtu; - goto err_mtu; - } - - /* Allocate and initialise structure */ - usbep = zalloc ( sizeof ( *usbep ) ); - if ( ! usbep ) { - rc = -ENOMEM; - goto err_alloc; - } - usbep->usbintf = usbintf; - usb_endpoint_init ( &usbep->ep, usbdev->usb, driver ); - usb_endpoint_describe ( &usbep->ep, endpoint, attributes, mtu, 0, - ( interval << 3 /* microframes */ ) ); - - /* Open endpoint */ - if ( ( rc = usb_endpoint_open ( &usbep->ep ) ) != 0 ) { - DBGC ( usbdev, "USBDEV %s %s could not open: %s\n", - usbintf->name, usb_endpoint_name ( &usbep->ep ), - strerror ( rc ) ); - goto err_open; - } - - /* Record opened endpoint */ - usbintf->endpoint[index] = usbep; - DBGC ( usbdev, "USBDEV %s %s opened\n", - usbintf->name, usb_endpoint_name ( &usbep->ep ) ); - - /* Create event */ - if ( ( efirc = bs->CreateEvent ( ( EVT_TIMER | EVT_NOTIFY_SIGNAL ), - TPL_NOTIFY, efi_usb_timer, usbep, - &usbep->event ) ) != 0 ) { - rc = -EEFI ( efirc ); - DBGC ( usbdev, "USBDEV %s %s could not create event: %s\n", - usbintf->name, usb_endpoint_name ( &usbep->ep ), - strerror ( rc ) ); - goto err_event; - } - - return 0; - - bs->CloseEvent ( usbep->event ); - err_event: - usbintf->endpoint[index] = usbep; - usb_endpoint_close ( &usbep->ep ); - err_open: - free ( usbep ); - err_alloc: - err_mtu: - return rc; -} - -/** - * Close endpoint - * - * @v usbep EFI USB endpoint - */ -static void efi_usb_close ( struct efi_usb_endpoint *usbep ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - struct efi_usb_interface *usbintf = usbep->usbintf; - struct efi_usb_device *usbdev = usbintf->usbdev; - unsigned int index = USB_ENDPOINT_IDX ( usbep->ep.address ); - - /* Sanity check */ - assert ( usbintf->endpoint[index] == usbep ); - - /* Cancel timer (if applicable) and close event */ - bs->SetTimer ( usbep->event, TimerCancel, 0 ); - bs->CloseEvent ( usbep->event ); - - /* Close endpoint */ - usb_endpoint_close ( &usbep->ep ); - DBGC ( usbdev, "USBDEV %s %s closed\n", - usbintf->name, usb_endpoint_name ( &usbep->ep ) ); - - /* Free endpoint */ - free ( usbep ); - - /* Record closed endpoint */ - usbintf->endpoint[index] = NULL; -} - -/** - * Close all endpoints - * - * @v usbintf EFI USB interface - */ -static void efi_usb_close_all ( struct efi_usb_interface *usbintf ) { - struct efi_usb_endpoint *usbep; - unsigned int i; - - for ( i = 0 ; i < ( sizeof ( usbintf->endpoint ) / - sizeof ( usbintf->endpoint[0] ) ) ; i++ ) { - usbep = usbintf->endpoint[i]; - if ( usbep ) - efi_usb_close ( usbep ); - } -} - -/** - * Complete synchronous transfer - * - * @v ep USB endpoint - * @v iobuf I/O buffer - * @v rc Completion status code - */ -static void efi_usb_sync_complete ( struct usb_endpoint *ep, - struct io_buffer *iobuf __unused, int rc ) { - struct efi_usb_endpoint *usbep = - container_of ( ep, struct efi_usb_endpoint, ep ); - - /* Record completion status */ - usbep->rc = rc; -} - -/** Synchronous endpoint operations */ -static struct usb_endpoint_driver_operations efi_usb_sync_driver = { - .complete = efi_usb_sync_complete, -}; - -/** - * Perform synchronous transfer - * - * @v usbintf USB endpoint - * @v endpoint Endpoint address - * @v attributes Endpoint attributes - * @v timeout Timeout (in milliseconds) - * @v data Data buffer - * @v len Length of data buffer - * @ret rc Return status code - */ -static int efi_usb_sync_transfer ( struct efi_usb_interface *usbintf, - unsigned int endpoint, - unsigned int attributes, - unsigned int timeout, - void *data, size_t *len ) { - struct efi_usb_device *usbdev = usbintf->usbdev; - struct efi_usb_endpoint *usbep; - struct io_buffer *iobuf; - unsigned int index = USB_ENDPOINT_IDX ( endpoint ); - unsigned int i; - int rc; - - /* Open endpoint, if applicable */ - if ( ( ! usbintf->endpoint[index] ) && - ( ( rc = efi_usb_open ( usbintf, endpoint, attributes, 0, - &efi_usb_sync_driver ) ) != 0 ) ) { - goto err_open; - } - usbep = usbintf->endpoint[index]; - - /* Allocate and construct I/O buffer */ - iobuf = alloc_iob ( *len ); - if ( ! iobuf ) { - rc = -ENOMEM; - goto err_alloc; - } - iob_put ( iobuf, *len ); - if ( ! ( endpoint & USB_ENDPOINT_IN ) ) - memcpy ( iobuf->data, data, *len ); - - /* Initialise completion status */ - usbep->rc = -EINPROGRESS; - - /* Enqueue transfer */ - if ( ( rc = usb_stream ( &usbep->ep, iobuf, 0 ) ) != 0 ) { - DBGC ( usbdev, "USBDEV %s %s could not enqueue: %s\n", - usbintf->name, usb_endpoint_name ( &usbep->ep ), - strerror ( rc ) ); - goto err_stream; - } - - /* Wait for completion */ - rc = -ETIMEDOUT; - for ( i = 0 ; ( ( timeout == 0 ) || ( i < timeout ) ) ; i++ ) { - - /* Poll bus */ - efi_usb_poll ( usbdev ); - - /* Check for completion */ - if ( usbep->rc != -EINPROGRESS ) { - rc = usbep->rc; - break; - } - - /* Delay */ - mdelay ( 1 ); - } - - /* Check for errors */ - if ( rc != 0 ) { - DBGC ( usbdev, "USBDEV %s %s failed: %s\n", usbintf->name, - usb_endpoint_name ( &usbep->ep ), strerror ( rc ) ); - goto err_completion; - } - - /* Copy completion to data buffer, if applicable */ - assert ( iob_len ( iobuf ) <= *len ); - if ( endpoint & USB_ENDPOINT_IN ) - memcpy ( data, iobuf->data, iob_len ( iobuf ) ); - *len = iob_len ( iobuf ); - - /* Free I/O buffer */ - free_iob ( iobuf ); - - /* Leave endpoint open */ - return 0; - - err_completion: - err_stream: - free_iob ( iobuf ); - err_alloc: - efi_usb_close ( usbep ); - err_open: - return EFIRC ( rc ); -} - -/** - * Complete asynchronous transfer - * - * @v ep USB endpoint - * @v iobuf I/O buffer - * @v rc Completion status code - */ -static void efi_usb_async_complete ( struct usb_endpoint *ep, - struct io_buffer *iobuf, int rc ) { - struct efi_usb_endpoint *usbep = - container_of ( ep, struct efi_usb_endpoint, ep ); - UINT32 status; - - /* Ignore packets cancelled when the endpoint closes */ - if ( ! ep->open ) - goto drop; - - /* Construct status */ - status = ( ( rc == 0 ) ? 0 : EFI_USB_ERR_STALL ); - - /* Report completion */ - usbep->callback ( iobuf->data, iob_len ( iobuf ), usbep->context, - status ); - - drop: - /* Recycle I/O buffer */ - usb_recycle ( &usbep->ep, iobuf ); -} - -/** Asynchronous endpoint operations */ -static struct usb_endpoint_driver_operations efi_usb_async_driver = { - .complete = efi_usb_async_complete, -}; - -/** - * Start asynchronous transfer - * - * @v usbintf EFI USB interface - * @v endpoint Endpoint address - * @v interval Interval (in milliseconds) - * @v len Transfer length - * @v callback Callback function - * @v context Context for callback function - * @ret rc Return status code - */ -static int efi_usb_async_start ( struct efi_usb_interface *usbintf, - unsigned int endpoint, unsigned int interval, - size_t len, - EFI_ASYNC_USB_TRANSFER_CALLBACK callback, - void *context ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - struct efi_usb_device *usbdev = usbintf->usbdev; - struct efi_usb_endpoint *usbep; - unsigned int index = USB_ENDPOINT_IDX ( endpoint ); - EFI_STATUS efirc; - int rc; - - /* Open endpoint */ - if ( ( rc = efi_usb_open ( usbintf, endpoint, - USB_ENDPOINT_ATTR_INTERRUPT, interval, - &efi_usb_async_driver ) ) != 0 ) - goto err_open; - usbep = usbintf->endpoint[index]; - - /* Record callback parameters */ - usbep->callback = callback; - usbep->context = context; - - /* Prefill endpoint */ - usb_refill_init ( &usbep->ep, 0, len, EFI_USB_ASYNC_FILL ); - if ( ( rc = usb_prefill ( &usbep->ep ) ) != 0 ) { - DBGC ( usbdev, "USBDEV %s %s could not prefill: %s\n", - usbintf->name, usb_endpoint_name ( &usbep->ep ), - strerror ( rc ) ); - goto err_prefill; - } - - /* Start timer */ - if ( ( efirc = bs->SetTimer ( usbep->event, TimerPeriodic, - ( interval * 10000 ) ) ) != 0 ) { - rc = -EEFI ( efirc ); - DBGC ( usbdev, "USBDEV %s %s could not set timer: %s\n", - usbintf->name, usb_endpoint_name ( &usbep->ep ), - strerror ( rc ) ); - goto err_timer; - } - - return 0; - - bs->SetTimer ( usbep->event, TimerCancel, 0 ); - err_timer: - err_prefill: - efi_usb_close ( usbep ); - err_open: - return rc; -} - -/** - * Stop asynchronous transfer - * - * @v usbintf EFI USB interface - * @v endpoint Endpoint address - */ -static void efi_usb_async_stop ( struct efi_usb_interface *usbintf, - unsigned int endpoint ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - struct efi_usb_endpoint *usbep; - unsigned int index = USB_ENDPOINT_IDX ( endpoint ); - - /* Do nothing if endpoint is already closed */ - usbep = usbintf->endpoint[index]; - if ( ! usbep ) - return; - - /* Stop timer */ - bs->SetTimer ( usbep->event, TimerCancel, 0 ); - - /* Close endpoint */ - efi_usb_close ( usbep ); -} - -/****************************************************************************** - * - * USB I/O protocol - * - ****************************************************************************** - */ - -/** - * Perform control transfer - * - * @v usbio USB I/O protocol - * @v packet Setup packet - * @v direction Data direction - * @v timeout Timeout (in milliseconds) - * @v data Data buffer - * @v len Length of data - * @ret status Transfer status - * @ret efirc EFI status code - */ -static EFI_STATUS EFIAPI -efi_usb_control_transfer ( EFI_USB_IO_PROTOCOL *usbio, - EFI_USB_DEVICE_REQUEST *packet, - EFI_USB_DATA_DIRECTION direction, - UINT32 timeout, VOID *data, UINTN len, - UINT32 *status ) { - struct efi_usb_interface *usbintf = - container_of ( usbio, struct efi_usb_interface, usbio ); - struct efi_usb_device *usbdev = usbintf->usbdev; - unsigned int request = ( packet->RequestType | - USB_REQUEST_TYPE ( packet->Request ) ); - unsigned int value = le16_to_cpu ( packet->Value ); - unsigned int index = le16_to_cpu ( packet->Index ); - int rc; - - DBGC2 ( usbdev, "USBDEV %s control %04x:%04x:%04x:%04x %s %dms " - "%p+%zx\n", usbintf->name, request, value, index, - le16_to_cpu ( packet->Length ), - efi_usb_direction_name ( direction ), timeout, data, - ( ( size_t ) len ) ); - - /* Clear status */ - *status = 0; - - /* Block attempts to change the device configuration, since - * this is logically impossible to do given the constraints of - * the EFI_USB_IO_PROTOCOL design. - */ - if ( ( request == USB_SET_CONFIGURATION ) && - ( value != usbdev->config->config ) ) { - DBGC ( usbdev, "USBDEV %s cannot set configuration %d: not " - "logically possible\n", usbintf->name, index ); - rc = -ENOTSUP; - goto err_change_config; - } - - /* If we are selecting a new alternate setting then close all - * open endpoints. - */ - if ( ( request == USB_SET_INTERFACE ) && - ( value != usbintf->alternate ) ) - efi_usb_close_all ( usbintf ); - - /* Issue control transfer */ - if ( ( rc = usb_control ( usbdev->usb, request, value, index, - data, len ) ) != 0 ) { - DBGC ( usbdev, "USBDEV %s control %04x:%04x:%04x:%04x %p+%zx " - "failed: %s\n", usbintf->name, request, value, index, - le16_to_cpu ( packet->Length ), data, ( ( size_t ) len ), - strerror ( rc ) ); - /* Assume that any error represents a stall */ - *status = EFI_USB_ERR_STALL; - goto err_control; - } - - /* Update alternate setting, if applicable */ - if ( request == USB_SET_INTERFACE ) { - usbintf->alternate = value; - DBGC ( usbdev, "USBDEV %s alt %d selected\n", - usbintf->name, usbintf->alternate ); - } - - err_control: - err_change_config: - return EFIRC ( rc ); -} - -/** - * Perform bulk transfer - * - * @v usbio USB I/O protocol - * @v endpoint Endpoint address - * @v data Data buffer - * @v len Length of data - * @v timeout Timeout (in milliseconds) - * @ret status Transfer status - * @ret efirc EFI status code - */ -static EFI_STATUS EFIAPI -efi_usb_bulk_transfer ( EFI_USB_IO_PROTOCOL *usbio, UINT8 endpoint, VOID *data, - UINTN *len, UINTN timeout, UINT32 *status ) { - struct efi_usb_interface *usbintf = - container_of ( usbio, struct efi_usb_interface, usbio ); - struct efi_usb_device *usbdev = usbintf->usbdev; - size_t actual = *len; - int rc; - - DBGC2 ( usbdev, "USBDEV %s bulk %s %p+%zx %dms\n", usbintf->name, - ( ( endpoint & USB_ENDPOINT_IN ) ? "IN" : "OUT" ), data, - ( ( size_t ) *len ), ( ( unsigned int ) timeout ) ); - - /* Clear status */ - *status = 0; - - /* Perform synchronous transfer */ - if ( ( rc = efi_usb_sync_transfer ( usbintf, endpoint, - USB_ENDPOINT_ATTR_BULK, timeout, - data, &actual ) ) != 0 ) { - /* Assume that any error represents a timeout */ - *status = EFI_USB_ERR_TIMEOUT; - return rc; - } - - return 0; -} - -/** - * Perform synchronous interrupt transfer - * - * @v usbio USB I/O protocol - * @v endpoint Endpoint address - * @v data Data buffer - * @v len Length of data - * @v timeout Timeout (in milliseconds) - * @ret status Transfer status - * @ret efirc EFI status code - */ -static EFI_STATUS EFIAPI -efi_usb_sync_interrupt_transfer ( EFI_USB_IO_PROTOCOL *usbio, UINT8 endpoint, - VOID *data, UINTN *len, UINTN timeout, - UINT32 *status ) { - struct efi_usb_interface *usbintf = - container_of ( usbio, struct efi_usb_interface, usbio ); - struct efi_usb_device *usbdev = usbintf->usbdev; - size_t actual = *len; - int rc; - - DBGC2 ( usbdev, "USBDEV %s sync intr %s %p+%zx %dms\n", usbintf->name, - ( ( endpoint & USB_ENDPOINT_IN ) ? "IN" : "OUT" ), data, - ( ( size_t ) *len ), ( ( unsigned int ) timeout ) ); - - /* Clear status */ - *status = 0; - - /* Perform synchronous transfer */ - if ( ( rc = efi_usb_sync_transfer ( usbintf, endpoint, - USB_ENDPOINT_ATTR_INTERRUPT, - timeout, data, &actual ) ) != 0 ) { - /* Assume that any error represents a timeout */ - *status = EFI_USB_ERR_TIMEOUT; - return rc; - } - - return 0; -} - -/** - * Perform asynchronous interrupt transfer - * - * @v usbio USB I/O protocol - * @v endpoint Endpoint address - * @v start Start (rather than stop) transfer - * @v interval Polling interval (in milliseconds) - * @v len Data length - * @v callback Callback function - * @v context Context for callback function - * @ret efirc EFI status code - */ -static EFI_STATUS EFIAPI -efi_usb_async_interrupt_transfer ( EFI_USB_IO_PROTOCOL *usbio, UINT8 endpoint, - BOOLEAN start, UINTN interval, UINTN len, - EFI_ASYNC_USB_TRANSFER_CALLBACK callback, - VOID *context ) { - struct efi_usb_interface *usbintf = - container_of ( usbio, struct efi_usb_interface, usbio ); - struct efi_usb_device *usbdev = usbintf->usbdev; - int rc; - - DBGC2 ( usbdev, "USBDEV %s async intr %s len %#zx int %d %p/%p\n", - usbintf->name, - ( ( endpoint & USB_ENDPOINT_IN ) ? "IN" : "OUT" ), - ( ( size_t ) len ), ( ( unsigned int ) interval ), - callback, context ); - - /* Start/stop transfer as applicable */ - if ( start ) { - - /* Start new transfer */ - if ( ( rc = efi_usb_async_start ( usbintf, endpoint, interval, - len, callback, - context ) ) != 0 ) - goto err_start; - - } else { - - /* Stop transfer */ - efi_usb_async_stop ( usbintf, endpoint ); - - } - - return 0; - - err_start: - return EFIRC ( rc ); -} - -/** - * Perform synchronous isochronous transfer - * - * @v usbio USB I/O protocol - * @v endpoint Endpoint address - * @v data Data buffer - * @v len Length of data - * @ret status Transfer status - * @ret efirc EFI status code - */ -static EFI_STATUS EFIAPI -efi_usb_isochronous_transfer ( EFI_USB_IO_PROTOCOL *usbio, UINT8 endpoint, - VOID *data, UINTN len, UINT32 *status ) { - struct efi_usb_interface *usbintf = - container_of ( usbio, struct efi_usb_interface, usbio ); - struct efi_usb_device *usbdev = usbintf->usbdev; - - DBGC2 ( usbdev, "USBDEV %s sync iso %s %p+%zx\n", usbintf->name, - ( ( endpoint & USB_ENDPOINT_IN ) ? "IN" : "OUT" ), data, - ( ( size_t ) len ) ); - - /* Clear status */ - *status = 0; - - /* Not supported */ - return EFI_UNSUPPORTED; -} - -/** - * Perform asynchronous isochronous transfers - * - * @v usbio USB I/O protocol - * @v endpoint Endpoint address - * @v data Data buffer - * @v len Length of data - * @v callback Callback function - * @v context Context for callback function - * @ret status Transfer status - * @ret efirc EFI status code - */ -static EFI_STATUS EFIAPI -efi_usb_async_isochronous_transfer ( EFI_USB_IO_PROTOCOL *usbio, UINT8 endpoint, - VOID *data, UINTN len, - EFI_ASYNC_USB_TRANSFER_CALLBACK callback, - VOID *context ) { - struct efi_usb_interface *usbintf = - container_of ( usbio, struct efi_usb_interface, usbio ); - struct efi_usb_device *usbdev = usbintf->usbdev; - - DBGC2 ( usbdev, "USBDEV %s async iso %s %p+%zx %p/%p\n", usbintf->name, - ( ( endpoint & USB_ENDPOINT_IN ) ? "IN" : "OUT" ), data, - ( ( size_t ) len ), callback, context ); - - /* Not supported */ - return EFI_UNSUPPORTED; -} - -/** - * Get device descriptor - * - * @v usbio USB I/O protocol - * @ret efidesc EFI device descriptor - * @ret efirc EFI status code - */ -static EFI_STATUS EFIAPI -efi_usb_get_device_descriptor ( EFI_USB_IO_PROTOCOL *usbio, - EFI_USB_DEVICE_DESCRIPTOR *efidesc ) { - struct efi_usb_interface *usbintf = - container_of ( usbio, struct efi_usb_interface, usbio ); - struct efi_usb_device *usbdev = usbintf->usbdev; - - DBGC2 ( usbdev, "USBDEV %s get device descriptor\n", usbintf->name ); - - /* Copy cached device descriptor */ - memcpy ( efidesc, &usbdev->usb->device, sizeof ( *efidesc ) ); - - return 0; -} - -/** - * Get configuration descriptor - * - * @v usbio USB I/O protocol - * @ret efidesc EFI interface descriptor - * @ret efirc EFI status code - */ -static EFI_STATUS EFIAPI -efi_usb_get_config_descriptor ( EFI_USB_IO_PROTOCOL *usbio, - EFI_USB_CONFIG_DESCRIPTOR *efidesc ) { - struct efi_usb_interface *usbintf = - container_of ( usbio, struct efi_usb_interface, usbio ); - struct efi_usb_device *usbdev = usbintf->usbdev; - - DBGC2 ( usbdev, "USBDEV %s get configuration descriptor\n", - usbintf->name ); - - /* Copy cached configuration descriptor */ - memcpy ( efidesc, usbdev->config, sizeof ( *efidesc ) ); - - return 0; -} - -/** - * Get interface descriptor - * - * @v usbio USB I/O protocol - * @ret efidesc EFI interface descriptor - * @ret efirc EFI status code - */ -static EFI_STATUS EFIAPI -efi_usb_get_interface_descriptor ( EFI_USB_IO_PROTOCOL *usbio, - EFI_USB_INTERFACE_DESCRIPTOR *efidesc ) { - struct efi_usb_interface *usbintf = - container_of ( usbio, struct efi_usb_interface, usbio ); - struct efi_usb_device *usbdev = usbintf->usbdev; - struct usb_interface_descriptor *desc; - - DBGC2 ( usbdev, "USBDEV %s get interface descriptor\n", usbintf->name ); - - /* Locate cached interface descriptor */ - desc = usb_interface_descriptor ( usbdev->config, usbintf->interface, - usbintf->alternate ); - if ( ! desc ) { - DBGC ( usbdev, "USBDEV %s alt %d has no interface descriptor\n", - usbintf->name, usbintf->alternate ); - return -ENOENT; - } - - /* Copy cached interface descriptor */ - memcpy ( efidesc, desc, sizeof ( *efidesc ) ); - - return 0; -} - -/** - * Get endpoint descriptor - * - * @v usbio USB I/O protocol - * @v address Endpoint index - * @ret efidesc EFI interface descriptor - * @ret efirc EFI status code - */ -static EFI_STATUS EFIAPI -efi_usb_get_endpoint_descriptor ( EFI_USB_IO_PROTOCOL *usbio, UINT8 index, - EFI_USB_ENDPOINT_DESCRIPTOR *efidesc ) { - struct efi_usb_interface *usbintf = - container_of ( usbio, struct efi_usb_interface, usbio ); - struct efi_usb_device *usbdev = usbintf->usbdev; - struct usb_interface_descriptor *interface; - struct usb_endpoint_descriptor *desc; - - DBGC2 ( usbdev, "USBDEV %s get endpoint %d descriptor\n", - usbintf->name, index ); - - /* Locate cached interface descriptor */ - interface = usb_interface_descriptor ( usbdev->config, - usbintf->interface, - usbintf->alternate ); - if ( ! interface ) { - DBGC ( usbdev, "USBDEV %s alt %d has no interface descriptor\n", - usbintf->name, usbintf->alternate ); - return -ENOENT; - } - - /* Locate and copy cached endpoint descriptor */ - for_each_interface_descriptor ( desc, usbdev->config, interface ) { - if ( ( desc->header.type == USB_ENDPOINT_DESCRIPTOR ) && - ( index-- == 0 ) ) { - memcpy ( efidesc, desc, sizeof ( *efidesc ) ); - return 0; - } - } - return -ENOENT; -} - -/** - * Get string descriptor - * - * @v usbio USB I/O protocol - * @v language Language ID - * @v index String index - * @ret string String - * @ret efirc EFI status code - */ -static EFI_STATUS EFIAPI -efi_usb_get_string_descriptor ( EFI_USB_IO_PROTOCOL *usbio, UINT16 language, - UINT8 index, CHAR16 **string ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - struct efi_usb_interface *usbintf = - container_of ( usbio, struct efi_usb_interface, usbio ); - struct efi_usb_device *usbdev = usbintf->usbdev; - struct usb_descriptor_header header; - VOID *buffer; - size_t len; - EFI_STATUS efirc; - int rc; - - DBGC2 ( usbdev, "USBDEV %s get string %d:%d descriptor\n", - usbintf->name, language, index ); - - /* Read descriptor header */ - if ( ( rc = usb_get_descriptor ( usbdev->usb, 0, USB_STRING_DESCRIPTOR, - index, language, &header, - sizeof ( header ) ) ) != 0 ) { - DBGC ( usbdev, "USBDEV %s could not get string %d:%d " - "descriptor header: %s\n", usbintf->name, language, - index, strerror ( rc ) ); - goto err_get_header; - } - len = header.len; - - /* Allocate buffer */ - if ( ( efirc = bs->AllocatePool ( EfiBootServicesData, len, - &buffer ) ) != 0 ) { - rc = -EEFI ( efirc ); - goto err_alloc; - } - - /* Read whole descriptor */ - if ( ( rc = usb_get_descriptor ( usbdev->usb, 0, USB_STRING_DESCRIPTOR, - index, language, buffer, - len ) ) != 0 ) { - DBGC ( usbdev, "USBDEV %s could not get string %d:%d " - "descriptor: %s\n", usbintf->name, language, - index, strerror ( rc ) ); - goto err_get_descriptor; - } - - /* Shuffle down and terminate string */ - memmove ( buffer, ( buffer + sizeof ( header ) ), - ( len - sizeof ( header ) ) ); - memset ( ( buffer + len - sizeof ( header ) ), 0, sizeof ( **string ) ); - - /* Return allocated string */ - *string = buffer; - return 0; - - err_get_descriptor: - bs->FreePool ( buffer ); - err_alloc: - err_get_header: - return EFIRC ( rc ); -} - -/** - * Get supported languages - * - * @v usbio USB I/O protocol - * @ret languages Language ID table - * @ret len Length of language ID table - * @ret efirc EFI status code - */ -static EFI_STATUS EFIAPI -efi_usb_get_supported_languages ( EFI_USB_IO_PROTOCOL *usbio, - UINT16 **languages, UINT16 *len ) { - struct efi_usb_interface *usbintf = - container_of ( usbio, struct efi_usb_interface, usbio ); - struct efi_usb_device *usbdev = usbintf->usbdev; - - DBGC2 ( usbdev, "USBDEV %s get supported languages\n", usbintf->name ); - - /* Return cached supported languages */ - *languages = ( ( ( void * ) usbdev->languages ) + - sizeof ( *(usbdev->languages) ) ); - *len = usbdev->languages->len; - - return 0; -} - -/** - * Reset port - * - * @v usbio USB I/O protocol - * @ret efirc EFI status code - */ -static EFI_STATUS EFIAPI -efi_usb_port_reset ( EFI_USB_IO_PROTOCOL *usbio ) { - struct efi_usb_interface *usbintf = - container_of ( usbio, struct efi_usb_interface, usbio ); - struct efi_usb_device *usbdev = usbintf->usbdev; - - DBGC2 ( usbdev, "USBDEV %s reset port\n", usbintf->name ); - - /* This is logically impossible to do, since resetting the - * port may destroy state belonging to other - * EFI_USB_IO_PROTOCOL instances belonging to the same USB - * device. (This is yet another artifact of the incredibly - * poor design of the EFI_USB_IO_PROTOCOL.) - */ - return EFI_INVALID_PARAMETER; -} - -/** USB I/O protocol */ -static EFI_USB_IO_PROTOCOL efi_usb_io_protocol = { - .UsbControlTransfer = efi_usb_control_transfer, - .UsbBulkTransfer = efi_usb_bulk_transfer, - .UsbAsyncInterruptTransfer = efi_usb_async_interrupt_transfer, - .UsbSyncInterruptTransfer = efi_usb_sync_interrupt_transfer, - .UsbIsochronousTransfer = efi_usb_isochronous_transfer, - .UsbAsyncIsochronousTransfer = efi_usb_async_isochronous_transfer, - .UsbGetDeviceDescriptor = efi_usb_get_device_descriptor, - .UsbGetConfigDescriptor = efi_usb_get_config_descriptor, - .UsbGetInterfaceDescriptor = efi_usb_get_interface_descriptor, - .UsbGetEndpointDescriptor = efi_usb_get_endpoint_descriptor, - .UsbGetStringDescriptor = efi_usb_get_string_descriptor, - .UsbGetSupportedLanguages = efi_usb_get_supported_languages, - .UsbPortReset = efi_usb_port_reset, -}; - -/****************************************************************************** - * - * USB driver - * - ****************************************************************************** - */ - -/** - * Install interface - * - * @v usbdev EFI USB device - * @v interface Interface number - * @ret rc Return status code - */ -static int efi_usb_install ( struct efi_usb_device *usbdev, - unsigned int interface ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - struct efi_device *efidev = usbdev->efidev; - struct efi_usb_interface *usbintf; - struct usb_device *usb; - EFI_DEVICE_PATH_PROTOCOL *path_end; - USB_DEVICE_PATH *usbpath; - unsigned int path_count; - size_t path_prefix_len; - size_t path_len; - EFI_STATUS efirc; - int rc; - - /* Calculate device path length */ - path_count = ( usb_depth ( usbdev->usb ) + 1 ); - path_prefix_len = efi_devpath_len ( efidev->path ); - path_len = ( path_prefix_len + ( path_count * sizeof ( *usbpath ) ) + - sizeof ( *path_end ) ); - - /* Allocate and initialise structure */ - usbintf = zalloc ( sizeof ( *usbintf ) + path_len ); - if ( ! usbintf ) { - rc = -ENOMEM; - goto err_alloc; - } - snprintf ( usbintf->name, sizeof ( usbintf->name ), "%s[%d]", - usbdev->name, interface ); - usbintf->usbdev = usbdev; - usbintf->interface = interface; - memcpy ( &usbintf->usbio, &efi_usb_io_protocol, - sizeof ( usbintf->usbio ) ); - usbintf->path = ( ( ( void * ) usbintf ) + sizeof ( *usbintf ) ); - - /* Construct device path */ - memcpy ( usbintf->path, efidev->path, path_prefix_len ); - path_end = ( ( ( void * ) usbintf->path ) + path_len - - sizeof ( *path_end ) ); - path_end->Type = END_DEVICE_PATH_TYPE; - path_end->SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE; - path_end->Length[0] = sizeof ( *path_end ); - usbpath = ( ( ( void * ) path_end ) - sizeof ( *usbpath ) ); - usbpath->InterfaceNumber = interface; - for ( usb = usbdev->usb ; usb ; usbpath--, usb = usb->port->hub->usb ) { - usbpath->Header.Type = MESSAGING_DEVICE_PATH; - usbpath->Header.SubType = MSG_USB_DP; - usbpath->Header.Length[0] = sizeof ( *usbpath ); - usbpath->ParentPortNumber = usb->port->address; - } - - /* Add to list of interfaces */ - list_add_tail ( &usbintf->list, &usbdev->interfaces ); - - /* Install protocols */ - if ( ( efirc = bs->InstallMultipleProtocolInterfaces ( - &usbintf->handle, - &efi_usb_io_protocol_guid, &usbintf->usbio, - &efi_device_path_protocol_guid, usbintf->path, - NULL ) ) != 0 ) { - rc = -EEFI ( efirc ); - DBGC ( usbdev, "USBDEV %s could not install protocols: %s\n", - usbintf->name, strerror ( rc ) ); - goto err_install_protocol; - } - - DBGC ( usbdev, "USBDEV %s installed as %s\n", - usbintf->name, efi_handle_name ( usbintf->handle ) ); - return 0; - - efi_usb_close_all ( usbintf ); - bs->UninstallMultipleProtocolInterfaces ( - usbintf->handle, - &efi_usb_io_protocol_guid, &usbintf->usbio, - &efi_device_path_protocol_guid, usbintf->path, - NULL ); - err_install_protocol: - list_del ( &usbintf->list ); - free ( usbintf ); - err_alloc: - return rc; -} - -/** - * Uninstall interface - * - * @v usbintf EFI USB interface - */ -static void efi_usb_uninstall ( struct efi_usb_interface *usbintf ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - - /* Close all endpoints */ - efi_usb_close_all ( usbintf ); - - /* Uninstall protocols */ - bs->UninstallMultipleProtocolInterfaces ( - usbintf->handle, - &efi_usb_io_protocol_guid, &usbintf->usbio, - &efi_device_path_protocol_guid, usbintf->path, - NULL ); - - /* Remove from list of interfaces */ - list_del ( &usbintf->list ); - - /* Free interface */ - free ( usbintf ); -} - -/** - * Uninstall all interfaces - * - * @v usbdev EFI USB device - */ -static void efi_usb_uninstall_all ( struct efi_usb_device *efiusb ) { - struct efi_usb_interface *usbintf; - - /* Uninstall all interfaces */ - while ( ( usbintf = list_first_entry ( &efiusb->interfaces, - struct efi_usb_interface, - list ) ) ) { - efi_usb_uninstall ( usbintf ); - } -} - -/** - * Probe device - * - * @v func USB function - * @v config Configuration descriptor - * @ret rc Return status code - */ -static int efi_usb_probe ( struct usb_function *func, - struct usb_configuration_descriptor *config ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - struct usb_device *usb = func->usb; - struct efi_usb_device *usbdev; - struct efi_usb_interface *usbintf; - struct efi_device *efidev; - struct usb_descriptor_header header; - size_t config_len; - unsigned int i; - int rc; - - /* Find parent EFI device */ - efidev = efidev_parent ( &func->dev ); - if ( ! efidev ) { - rc = -ENOTTY; - goto err_no_efidev; - } - - /* Get configuration length */ - config_len = le16_to_cpu ( config->len ); - - /* Get supported languages descriptor header */ - if ( ( rc = usb_get_descriptor ( usb, 0, USB_STRING_DESCRIPTOR, 0, 0, - &header, sizeof ( header ) ) ) != 0 ) { - /* Assume no strings are present */ - header.len = 0; - } - - /* Allocate and initialise structure */ - usbdev = zalloc ( sizeof ( *usbdev ) + config_len + header.len ); - if ( ! usbdev ) { - rc = -ENOMEM; - goto err_alloc; - } - usb_func_set_drvdata ( func, usbdev ); - usbdev->name = func->name; - usbdev->usb = usb; - usbdev->efidev = efidev; - usbdev->config = ( ( ( void * ) usbdev ) + sizeof ( *usbdev ) ); - memcpy ( usbdev->config, config, config_len ); - usbdev->languages = ( ( ( void * ) usbdev->config ) + config_len ); - INIT_LIST_HEAD ( &usbdev->interfaces ); - - /* Get supported languages descriptor */ - if ( header.len && - ( rc = usb_get_descriptor ( usb, 0, USB_STRING_DESCRIPTOR, 0, 0, - usbdev->languages, - header.len ) ) != 0 ) { - DBGC ( usbdev, "USBDEV %s could not get supported languages: " - "%s\n", usbdev->name, strerror ( rc ) ); - goto err_get_languages; - } - - /* Install interfaces */ - for ( i = 0 ; i < func->desc.count ; i++ ) { - if ( ( rc = efi_usb_install ( usbdev, - func->interface[i] ) ) != 0 ) - goto err_install; - } - - /* Connect any external drivers */ - list_for_each_entry ( usbintf, &usbdev->interfaces, list ) - bs->ConnectController ( usbintf->handle, NULL, NULL, TRUE ); - - return 0; - - err_install: - efi_usb_uninstall_all ( usbdev ); - assert ( list_empty ( &usbdev->interfaces ) ); - err_get_languages: - free ( usbdev ); - err_alloc: - err_no_efidev: - return rc; -} - -/** - * Remove device - * - * @v func USB function - */ -static void efi_usb_remove ( struct usb_function *func ) { - struct efi_usb_device *usbdev = usb_func_get_drvdata ( func ); - - /* Uninstall all interfaces */ - efi_usb_uninstall_all ( usbdev ); - assert ( list_empty ( &usbdev->interfaces ) ); - - /* Free device */ - free ( usbdev ); -} - -/** USB I/O protocol device IDs */ -static struct usb_device_id efi_usb_ids[] = { - { - .name = "usbio", - .vendor = USB_ANY_ID, - .product = USB_ANY_ID, - }, -}; - -/** USB I/O protocol driver */ -struct usb_driver usbio_driver __usb_driver = { - .ids = efi_usb_ids, - .id_count = ( sizeof ( efi_usb_ids ) / sizeof ( efi_usb_ids[0] ) ), - .class = USB_CLASS_ID ( USB_ANY_ID, USB_ANY_ID, USB_ANY_ID ), - .score = USB_SCORE_FALLBACK, - .probe = efi_usb_probe, - .remove = efi_usb_remove, -}; diff --git a/roms/ipxe/src/interface/efi/efi_utils.c b/roms/ipxe/src/interface/efi/efi_utils.c index 4dc75414c..936ad48ec 100644 --- a/roms/ipxe/src/interface/efi/efi_utils.c +++ b/roms/ipxe/src/interface/efi/efi_utils.c @@ -51,18 +51,6 @@ EFI_DEVICE_PATH_PROTOCOL * efi_devpath_end ( EFI_DEVICE_PATH_PROTOCOL *path ) { } /** - * Find length of device path (excluding terminator) - * - * @v path Path to device - * @ret path_len Length of device path - */ -size_t efi_devpath_len ( EFI_DEVICE_PATH_PROTOCOL *path ) { - EFI_DEVICE_PATH_PROTOCOL *end = efi_devpath_end ( path ); - - return ( ( ( void * ) end ) - ( ( void * ) path ) ); -} - -/** * Locate parent device supporting a given protocol * * @v device EFI device handle @@ -88,8 +76,8 @@ int efi_locate_device ( EFI_HANDLE device, EFI_GUID *protocol, efi_image_handle, device, EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){ rc = -EEFI ( efirc ); - DBGC ( device, "EFIDEV %s cannot open device path: %s\n", - efi_handle_name ( device ), strerror ( rc ) ); + DBGC ( device, "EFIDEV %p %s cannot open device path: %s\n", + device, efi_handle_name ( device ), strerror ( rc ) ); goto err_open_device_path; } devpath = path.path; @@ -98,8 +86,8 @@ int efi_locate_device ( EFI_HANDLE device, EFI_GUID *protocol, if ( ( efirc = bs->LocateDevicePath ( protocol, &devpath, parent ) ) != 0 ) { rc = -EEFI ( efirc ); - DBGC ( device, "EFIDEV %s has no parent supporting %s: %s\n", - efi_handle_name ( device ), + DBGC ( device, "EFIDEV %p %s has no parent supporting %s: %s\n", + device, efi_handle_name ( device ), efi_guid_ntoa ( protocol ), strerror ( rc ) ); goto err_locate_protocol; } @@ -135,17 +123,18 @@ int efi_child_add ( EFI_HANDLE parent, EFI_HANDLE child ) { EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER ) ) != 0 ) { rc = -EEFI ( efirc ); - DBGC ( parent, "EFIDEV %s could not add child", - efi_handle_name ( parent ) ); - DBGC ( parent, " %s: %s\n", + DBGC ( parent, "EFIDEV %p %s could not add child", + parent, efi_handle_name ( parent ) ); + DBGC ( parent, " %p %s: %s\n", child, efi_handle_name ( child ), strerror ( rc ) ); DBGC_EFI_OPENERS ( parent, parent, &efi_device_path_protocol_guid ); return rc; } - DBGC2 ( parent, "EFIDEV %s added child", efi_handle_name ( parent ) ); - DBGC2 ( parent, " %s\n", efi_handle_name ( child ) ); + DBGC2 ( parent, "EFIDEV %p %s added child", + parent, efi_handle_name ( parent ) ); + DBGC2 ( parent, " %p %s\n", child, efi_handle_name ( child ) ); return 0; } @@ -160,8 +149,10 @@ void efi_child_del ( EFI_HANDLE parent, EFI_HANDLE child ) { bs->CloseProtocol ( parent, &efi_device_path_protocol_guid, efi_image_handle, child ); - DBGC2 ( parent, "EFIDEV %s removed child", efi_handle_name ( parent ) ); - DBGC2 ( parent, " %s\n", efi_handle_name ( child ) ); + DBGC2 ( parent, "EFIDEV %p %s removed child", + parent, efi_handle_name ( parent ) ); + DBGC2 ( parent, " %p %s\n", + child, efi_handle_name ( child ) ); } /** @@ -181,15 +172,16 @@ static int efi_pci_info ( EFI_HANDLE device, const char *prefix, /* Find parent PCI device */ if ( ( rc = efi_locate_device ( device, &efi_pci_io_protocol_guid, &pci_device ) ) != 0 ) { - DBGC ( device, "EFIDEV %s is not a PCI device: %s\n", - efi_handle_name ( device ), strerror ( rc ) ); + DBGC ( device, "EFIDEV %p %s is not a PCI device: %s\n", + device, efi_handle_name ( device ), strerror ( rc ) ); return rc; } /* Get PCI device information */ if ( ( rc = efipci_info ( pci_device, &pci ) ) != 0 ) { - DBGC ( device, "EFIDEV %s could not get PCI information: %s\n", - efi_handle_name ( device ), strerror ( rc ) ); + DBGC ( device, "EFIDEV %p %s could not get PCI information: " + "%s\n", device, efi_handle_name ( device ), + strerror ( rc ) ); return rc; } @@ -219,8 +211,8 @@ void efi_device_info ( EFI_HANDLE device, const char *prefix, /* If we cannot get any underlying device information, fall * back to providing information about the EFI handle. */ - DBGC ( device, "EFIDEV %s could not get underlying device " - "information\n", efi_handle_name ( device ) ); + DBGC ( device, "EFIDEV %p %s could not get underlying device " + "information\n", device, efi_handle_name ( device ) ); dev->desc.bus_type = BUS_TYPE_EFI; snprintf ( dev->name, sizeof ( dev->name ), "%s-%p", prefix, device ); } diff --git a/roms/ipxe/src/interface/efi/efi_wrap.c b/roms/ipxe/src/interface/efi/efi_wrap.c index c0c40eec6..2ea184e97 100644 --- a/roms/ipxe/src/interface/efi/efi_wrap.c +++ b/roms/ipxe/src/interface/efi/efi_wrap.c @@ -101,81 +101,6 @@ static const char * efi_status ( EFI_STATUS efirc ) { } /** - * Convert EFI boolean to text - * - * @v boolean Boolean value - * @ret text Boolean value text - */ -static const char * efi_boolean ( BOOLEAN boolean ) { - - return ( boolean ? "TRUE" : "FALSE" ); -} - -/** - * Wrap InstallProtocolInterface() - * - */ -static EFI_STATUS EFIAPI -efi_install_protocol_interface_wrapper ( EFI_HANDLE *handle, EFI_GUID *protocol, - EFI_INTERFACE_TYPE interface_type, - VOID *interface ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - void *retaddr = __builtin_return_address ( 0 ); - EFI_STATUS efirc; - - DBGC ( colour, "InstallProtocolInterface ( %s, %s, %d, %p ) ", - efi_handle_name ( *handle ), efi_guid_ntoa ( protocol ), - interface_type, interface ); - efirc = bs->InstallProtocolInterface ( handle, protocol, interface_type, - interface ); - DBGC ( colour, "= %s ( %s ) -> %p\n", - efi_status ( efirc ), efi_handle_name ( *handle ), retaddr ); - return efirc; -} - -/** - * Wrap ReinstallProtocolInterface() - * - */ -static EFI_STATUS EFIAPI -efi_reinstall_protocol_interface_wrapper ( EFI_HANDLE handle, - EFI_GUID *protocol, - VOID *old_interface, - VOID *new_interface ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - void *retaddr = __builtin_return_address ( 0 ); - EFI_STATUS efirc; - - DBGC ( colour, "ReinstallProtocolInterface ( %s, %s, %p, %p ) ", - efi_handle_name ( handle ), efi_guid_ntoa ( protocol ), - old_interface, new_interface ); - efirc = bs->ReinstallProtocolInterface ( handle, protocol, - old_interface, new_interface ); - DBGC ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr ); - return efirc; -} - -/** - * Wrap UninstallProtocolInterface() - * - */ -static EFI_STATUS EFIAPI -efi_uninstall_protocol_interface_wrapper ( EFI_HANDLE handle, - EFI_GUID *protocol, - VOID *interface ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - void *retaddr = __builtin_return_address ( 0 ); - EFI_STATUS efirc; - - DBGC ( colour, "UninstallProtocolInterface ( %s, %s, %p ) ", - efi_handle_name ( handle ), efi_guid_ntoa ( protocol ), - interface ); - efirc = bs->UninstallProtocolInterface ( handle, protocol, interface ); - DBGC ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr ); - return efirc; -} - -/** * Wrap HandleProtocol() * */ @@ -186,7 +111,7 @@ efi_handle_protocol_wrapper ( EFI_HANDLE handle, EFI_GUID *protocol, void *retaddr = __builtin_return_address ( 0 ); EFI_STATUS efirc; - DBGC ( colour, "HandleProtocol ( %s, %s ) ", + DBGC ( colour, "HandleProtocol ( %p %s, %s, ... ) ", handle, efi_handle_name ( handle ), efi_guid_ntoa ( protocol ) ); efirc = bs->HandleProtocol ( handle, protocol, interface ); DBGC ( colour, "= %s ( %p ) -> %p\n", @@ -204,26 +129,14 @@ efi_locate_handle_wrapper ( EFI_LOCATE_SEARCH_TYPE search_type, UINTN *buffer_size, EFI_HANDLE *buffer ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; void *retaddr = __builtin_return_address ( 0 ); - unsigned int i; EFI_STATUS efirc; - DBGC ( colour, "LocateHandle ( %s, %s, %p, %zd ) ", - efi_locate_search_type_name ( search_type ), - efi_guid_ntoa ( protocol ), search_key, - ( ( size_t ) *buffer_size ) ); + DBGC ( colour, "LocateHandle ( %d, %s, ..., %zd, ... ) ", search_type, + efi_guid_ntoa ( protocol ), ( ( size_t ) *buffer_size ) ); efirc = bs->LocateHandle ( search_type, protocol, search_key, buffer_size, buffer ); - DBGC ( colour, "= %s ( %zd", efi_status ( efirc ), - ( ( size_t ) *buffer_size ) ); - if ( efirc == 0 ) { - DBGC ( colour, ", {" ); - for ( i = 0; i < ( *buffer_size / sizeof ( buffer[0] ) ); i++ ){ - DBGC ( colour, "%s%s", ( i ? ", " : " " ), - efi_handle_name ( buffer[i] ) ); - } - DBGC ( colour, " }" ); - } - DBGC ( colour, " ) -> %p\n", retaddr ); + DBGC ( colour, "= %s ( %zd ) -> %p\n", + efi_status ( efirc ), ( ( size_t ) *buffer_size ), retaddr ); return efirc; } @@ -239,12 +152,13 @@ efi_locate_device_path_wrapper ( EFI_GUID *protocol, void *retaddr = __builtin_return_address ( 0 ); EFI_STATUS efirc; - DBGC ( colour, "LocateDevicePath ( %s, %s ) ", + DBGC ( colour, "LocateDevicePath ( %s, %s, ... ) ", efi_guid_ntoa ( protocol ), efi_devpath_text ( *device_path ) ); efirc = bs->LocateDevicePath ( protocol, device_path, device ); - DBGC ( colour, "= %s ( %s, ", + DBGC ( colour, "= %s ( %p, ", efi_status ( efirc ), efi_devpath_text ( *device_path ) ); - DBGC ( colour, "%s ) -> %p\n", efi_handle_name ( *device ), retaddr ); + DBGC ( colour, "%p %s ) -> %p\n", + *device, efi_handle_name ( *device ), retaddr ); return efirc; } @@ -261,16 +175,18 @@ efi_load_image_wrapper ( BOOLEAN boot_policy, EFI_HANDLE parent_image_handle, void *retaddr = __builtin_return_address ( 0 ); EFI_STATUS efirc; - DBGC ( colour, "LoadImage ( %s, %s, ", efi_boolean ( boot_policy ), - efi_handle_name ( parent_image_handle ) ); - DBGC ( colour, "%s, %p, %#llx ) ", + DBGC ( colour, "LoadImage ( %d, %p %s, ", boot_policy, + parent_image_handle, efi_handle_name ( parent_image_handle ) ); + DBGC ( colour, "%s, %p, %#llx, ... ) ", efi_devpath_text ( device_path ), source_buffer, ( ( unsigned long long ) source_size ) ); efirc = bs->LoadImage ( boot_policy, parent_image_handle, device_path, source_buffer, source_size, image_handle ); DBGC ( colour, "= %s ( ", efi_status ( efirc ) ); - if ( efirc == 0 ) - DBGC ( colour, "%s ", efi_handle_name ( *image_handle ) ); + if ( efirc == 0 ) { + DBGC ( colour, "%p %s ", *image_handle, + efi_handle_name ( *image_handle ) ); + } DBGC ( colour, ") -> %p\n", retaddr ); /* Wrap the new image */ @@ -281,69 +197,6 @@ efi_load_image_wrapper ( BOOLEAN boot_policy, EFI_HANDLE parent_image_handle, } /** - * Wrap StartImage() - * - */ -static EFI_STATUS EFIAPI -efi_start_image_wrapper ( EFI_HANDLE image_handle, UINTN *exit_data_size, - CHAR16 **exit_data ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - void *retaddr = __builtin_return_address ( 0 ); - EFI_STATUS efirc; - - DBGC ( colour, "StartImage ( %s ) ", efi_handle_name ( image_handle ) ); - efirc = bs->StartImage ( image_handle, exit_data_size, exit_data ); - DBGC ( colour, "= %s", efi_status ( efirc ) ); - if ( ( efirc != 0 ) && exit_data && *exit_data_size ) - DBGC ( colour, " ( \"%ls\" )", *exit_data ); - DBGC ( colour, " -> %p\n", retaddr ); - if ( ( efirc != 0 ) && exit_data && *exit_data_size ) - DBGC_HD ( colour, *exit_data, *exit_data_size ); - return efirc; -} - -/** - * Wrap Exit() - * - */ -static EFI_STATUS EFIAPI -efi_exit_wrapper ( EFI_HANDLE image_handle, EFI_STATUS exit_status, - UINTN exit_data_size, CHAR16 *exit_data ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - void *retaddr = __builtin_return_address ( 0 ); - EFI_STATUS efirc; - - if ( ( exit_status != 0 ) && exit_data && exit_data_size ) - DBGC_HD ( colour, exit_data, exit_data_size ); - DBGC ( colour, "Exit ( %s, %s", - efi_handle_name ( image_handle ), efi_status ( exit_status ) ); - if ( ( exit_status != 0 ) && exit_data && exit_data_size ) - DBGC ( colour, ", \"%ls\"", exit_data ); - DBGC ( colour, " ) " ); - efirc = bs->Exit ( image_handle, exit_status, exit_data_size, - exit_data ); - DBGC ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr ); - return efirc; -} - -/** - * Wrap UnloadImage() - * - */ -static EFI_STATUS EFIAPI -efi_unload_image_wrapper ( EFI_HANDLE image_handle ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - void *retaddr = __builtin_return_address ( 0 ); - EFI_STATUS efirc; - - DBGC ( colour, "UnloadImage ( %s ) ", - efi_handle_name ( image_handle ) ); - efirc = bs->UnloadImage ( image_handle ); - DBGC ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr ); - return efirc; -} - -/** * Wrap ExitBootServices() * */ @@ -353,8 +206,8 @@ efi_exit_boot_services_wrapper ( EFI_HANDLE image_handle, UINTN map_key ) { void *retaddr = __builtin_return_address ( 0 ); EFI_STATUS efirc; - DBGC ( colour, "ExitBootServices ( %s, %#llx ) ", - efi_handle_name ( image_handle ), + DBGC ( colour, "ExitBootServices ( %p %s, %#llx ) ", + image_handle, efi_handle_name ( image_handle ), ( ( unsigned long long ) map_key ) ); efirc = bs->ExitBootServices ( image_handle, map_key ); DBGC ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr ); @@ -362,60 +215,6 @@ efi_exit_boot_services_wrapper ( EFI_HANDLE image_handle, UINTN map_key ) { } /** - * Wrap ConnectController() - * - */ -static EFI_STATUS EFIAPI -efi_connect_controller_wrapper ( EFI_HANDLE controller_handle, - EFI_HANDLE *driver_image_handle, - EFI_DEVICE_PATH_PROTOCOL *remaining_path, - BOOLEAN recursive ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - void *retaddr = __builtin_return_address ( 0 ); - EFI_HANDLE *tmp; - EFI_STATUS efirc; - - DBGC ( colour, "ConnectController ( %s, {", - efi_handle_name ( controller_handle ) ); - if ( driver_image_handle ) { - for ( tmp = driver_image_handle ; *tmp ; tmp++ ) { - DBGC ( colour, "%s%s", - ( ( tmp == driver_image_handle ) ? " " : ", " ), - efi_handle_name ( *tmp ) ); - } - } - DBGC ( colour, " }, %s, %s ) ", efi_devpath_text ( remaining_path ), - efi_boolean ( recursive ) ); - efirc = bs->ConnectController ( controller_handle, driver_image_handle, - remaining_path, recursive ); - DBGC ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr ); - return efirc; -} - -/** - * Wrap DisconnectController() - * - */ -static EFI_STATUS EFIAPI -efi_disconnect_controller_wrapper ( EFI_HANDLE controller_handle, - EFI_HANDLE driver_image_handle, - EFI_HANDLE child_handle ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - void *retaddr = __builtin_return_address ( 0 ); - EFI_STATUS efirc; - - DBGC ( colour, "DisconnectController ( %s", - efi_handle_name ( controller_handle ) ); - DBGC ( colour, ", %s", efi_handle_name ( driver_image_handle ) ); - DBGC ( colour, ", %s ) ", efi_handle_name ( child_handle ) ); - efirc = bs->DisconnectController ( controller_handle, - driver_image_handle, - child_handle ); - DBGC ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr ); - return efirc; -} - -/** * Wrap OpenProtocol() * */ @@ -427,11 +226,12 @@ efi_open_protocol_wrapper ( EFI_HANDLE handle, EFI_GUID *protocol, void *retaddr = __builtin_return_address ( 0 ); EFI_STATUS efirc; - DBGC ( colour, "OpenProtocol ( %s, %s, ", + DBGC ( colour, "OpenProtocol ( %p %s, %s, ..., ", handle, efi_handle_name ( handle ), efi_guid_ntoa ( protocol ) ); - DBGC ( colour, "%s, ", efi_handle_name ( agent_handle ) ); - DBGC ( colour, "%s, %s ) ", efi_handle_name ( controller_handle ), - efi_open_attributes_name ( attributes ) ); + DBGC ( colour, "%p %s, ", agent_handle, + efi_handle_name ( agent_handle ) ); + DBGC ( colour, "%p %s, %#x ) ", controller_handle, + efi_handle_name ( controller_handle ), attributes ); efirc = bs->OpenProtocol ( handle, protocol, interface, agent_handle, controller_handle, attributes ); DBGC ( colour, "= %s ( %p ) -> %p\n", @@ -440,90 +240,6 @@ efi_open_protocol_wrapper ( EFI_HANDLE handle, EFI_GUID *protocol, } /** - * Wrap CloseProtocol() - * - */ -static EFI_STATUS EFIAPI -efi_close_protocol_wrapper ( EFI_HANDLE handle, EFI_GUID *protocol, - EFI_HANDLE agent_handle, - EFI_HANDLE controller_handle ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - void *retaddr = __builtin_return_address ( 0 ); - EFI_STATUS efirc; - - DBGC ( colour, "CloseProtocol ( %s, %s, ", - efi_handle_name ( handle ), efi_guid_ntoa ( protocol ) ); - DBGC ( colour, "%s, ", efi_handle_name ( agent_handle ) ); - DBGC ( colour, "%s ) ", efi_handle_name ( controller_handle ) ); - efirc = bs->CloseProtocol ( handle, protocol, agent_handle, - controller_handle ); - DBGC ( colour, "= %s -> %p\n", - efi_status ( efirc ), retaddr ); - return efirc; -} - -/** - * Wrap ProtocolsPerHandle() - * - */ -static EFI_STATUS EFIAPI -efi_protocols_per_handle_wrapper ( EFI_HANDLE handle, - EFI_GUID ***protocol_buffer, - UINTN *protocol_buffer_count ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - void *retaddr = __builtin_return_address ( 0 ); - unsigned int i; - EFI_STATUS efirc; - - DBGC ( colour, "ProtocolsPerHandle ( %s ) ", - efi_handle_name ( handle ) ); - efirc = bs->ProtocolsPerHandle ( handle, protocol_buffer, - protocol_buffer_count ); - DBGC ( colour, "= %s", efi_status ( efirc ) ); - if ( efirc == 0 ) { - DBGC ( colour, " ( {" ); - for ( i = 0 ; i < *protocol_buffer_count ; i++ ) { - DBGC ( colour, "%s%s", ( i ? ", " : " " ), - efi_guid_ntoa ( (*protocol_buffer)[i] ) ); - } - DBGC ( colour, " } )" ); - } - DBGC ( colour, " -> %p\n", retaddr ); - return efirc; -} - -/** - * Wrap LocateHandleBuffer() - * - */ -static EFI_STATUS EFIAPI -efi_locate_handle_buffer_wrapper ( EFI_LOCATE_SEARCH_TYPE search_type, - EFI_GUID *protocol, VOID *search_key, - UINTN *no_handles, EFI_HANDLE **buffer ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - void *retaddr = __builtin_return_address ( 0 ); - unsigned int i; - EFI_STATUS efirc; - - DBGC ( colour, "LocateHandleBuffer ( %s, %s, %p ) ", - efi_locate_search_type_name ( search_type ), - efi_guid_ntoa ( protocol ), search_key ); - efirc = bs->LocateHandleBuffer ( search_type, protocol, search_key, - no_handles, buffer ); - DBGC ( colour, "= %s", efi_status ( efirc ) ); - if ( efirc == 0 ) { - DBGC ( colour, " ( %d, {", ( ( unsigned int ) *no_handles ) ); - for ( i = 0 ; i < *no_handles ; i++ ) { - DBGC ( colour, "%s%s", ( i ? ", " : " " ), - efi_handle_name ( (*buffer)[i] ) ); - } - DBGC ( colour, " } )" ); - } - DBGC ( colour, " -> %p\n", retaddr ); - return efirc; -} - -/** * Wrap LocateProtocol() * */ @@ -534,7 +250,7 @@ efi_locate_protocol_wrapper ( EFI_GUID *protocol, VOID *registration, void *retaddr = __builtin_return_address ( 0 ); EFI_STATUS efirc; - DBGC ( colour, "LocateProtocol ( %s, %p ) ", + DBGC ( colour, "LocateProtocol ( %s, %p, ... ) ", efi_guid_ntoa ( protocol ), registration ); efirc = bs->LocateProtocol ( protocol, registration, interface ); DBGC ( colour, "= %s ( %p ) -> %p\n", @@ -565,30 +281,12 @@ efi_locate_protocol_wrapper ( EFI_GUID *protocol, VOID *registration, sizeof ( efi_systab_wrapper ) ); memcpy ( &efi_bs_wrapper, bs, sizeof ( efi_bs_wrapper ) ); efi_systab_wrapper.BootServices = &efi_bs_wrapper; - efi_bs_wrapper.InstallProtocolInterface - = efi_install_protocol_interface_wrapper; - efi_bs_wrapper.ReinstallProtocolInterface - = efi_reinstall_protocol_interface_wrapper; - efi_bs_wrapper.UninstallProtocolInterface - = efi_uninstall_protocol_interface_wrapper; efi_bs_wrapper.HandleProtocol = efi_handle_protocol_wrapper; efi_bs_wrapper.LocateHandle = efi_locate_handle_wrapper; efi_bs_wrapper.LocateDevicePath = efi_locate_device_path_wrapper; efi_bs_wrapper.LoadImage = efi_load_image_wrapper; - efi_bs_wrapper.StartImage = efi_start_image_wrapper; - efi_bs_wrapper.Exit = efi_exit_wrapper; - efi_bs_wrapper.UnloadImage = efi_unload_image_wrapper; efi_bs_wrapper.ExitBootServices = efi_exit_boot_services_wrapper; - efi_bs_wrapper.ConnectController - = efi_connect_controller_wrapper; - efi_bs_wrapper.DisconnectController - = efi_disconnect_controller_wrapper; efi_bs_wrapper.OpenProtocol = efi_open_protocol_wrapper; - efi_bs_wrapper.CloseProtocol = efi_close_protocol_wrapper; - efi_bs_wrapper.ProtocolsPerHandle - = efi_protocols_per_handle_wrapper; - efi_bs_wrapper.LocateHandleBuffer - = efi_locate_handle_buffer_wrapper; efi_bs_wrapper.LocateProtocol = efi_locate_protocol_wrapper; /* Open loaded image protocol */ @@ -597,22 +295,23 @@ efi_locate_protocol_wrapper ( EFI_GUID *protocol, VOID *registration, &loaded.intf, efi_image_handle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){ rc = -EEFI ( efirc ); - DBGC ( colour, "WRAP %s could not get loaded image protocol: " - "%s\n", efi_handle_name ( handle ), strerror ( rc ) ); + DBGC ( colour, "Could not get loaded image protocol for %p %s: " + "%s\n", handle, efi_handle_name ( handle ), + strerror ( rc ) ); return; } /* Provide system table wrapper to image */ loaded.image->SystemTable = &efi_systab_wrapper; - DBGC ( colour, "WRAP %s at base %p has protocols:\n", - efi_handle_name ( handle ), loaded.image->ImageBase ); + DBGC ( colour, "Wrapped image %p %s at base %p has protocols:\n", + handle, efi_handle_name ( handle ), loaded.image->ImageBase ); DBGC_EFI_PROTOCOLS ( colour, handle ); - DBGC ( colour, "WRAP %s parent", efi_handle_name ( handle ) ); - DBGC ( colour, " %s\n", efi_handle_name ( loaded.image->ParentHandle )); - DBGC ( colour, "WRAP %s device", efi_handle_name ( handle ) ); - DBGC ( colour, " %s\n", efi_handle_name ( loaded.image->DeviceHandle )); - DBGC ( colour, "WRAP %s file", efi_handle_name ( handle ) ); - DBGC ( colour, " %s\n", efi_devpath_text ( loaded.image->FilePath ) ); + DBGC ( colour, "Parent image %p %s\n", loaded.image->ParentHandle, + efi_handle_name ( loaded.image->ParentHandle ) ); + DBGC ( colour, "Device %p %s ", loaded.image->DeviceHandle, + efi_handle_name ( loaded.image->DeviceHandle ) ); + DBGC ( colour, "file %p %s\n", loaded.image->FilePath, + efi_devpath_text ( loaded.image->FilePath ) ); /* Close loaded image protocol */ bs->CloseProtocol ( handle, &efi_loaded_image_protocol_guid, diff --git a/roms/ipxe/src/interface/hyperv/vmbus.c b/roms/ipxe/src/interface/hyperv/vmbus.c index fd809dda4..795929eae 100644 --- a/roms/ipxe/src/interface/hyperv/vmbus.c +++ b/roms/ipxe/src/interface/hyperv/vmbus.c @@ -39,7 +39,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <ipxe/nap.h> #include <ipxe/malloc.h> #include <ipxe/iobuf.h> -#include <ipxe/bitops.h> #include <ipxe/hyperv.h> #include <ipxe/vmbus.h> @@ -560,7 +559,7 @@ static void vmbus_signal_monitor ( struct vmbus_device *vmdev ) { group = ( vmdev->monitor / ( 8 * sizeof ( trigger->pending ) )); bit = ( vmdev->monitor % ( 8 * sizeof ( trigger->pending ) ) ); trigger = &vmbus->monitor_out->trigger[group]; - set_bit ( bit, trigger ); + hv_set_bit ( trigger, bit ); } /** @@ -721,7 +720,7 @@ static int vmbus_send ( struct vmbus_device *vmdev, return 0; /* Set channel bit in interrupt page */ - set_bit ( vmdev->channel, vmbus->intr->out ); + hv_set_bit ( vmbus->intr->out, vmdev->channel ); /* Signal the host */ vmdev->signal ( vmdev ); diff --git a/roms/ipxe/src/interface/smbios/smbios_settings.c b/roms/ipxe/src/interface/smbios/smbios_settings.c index 2d571f2e4..5eadfa081 100644 --- a/roms/ipxe/src/interface/smbios/smbios_settings.c +++ b/roms/ipxe/src/interface/smbios/smbios_settings.c @@ -248,7 +248,7 @@ const struct setting asset_setting __setting ( SETTING_HOST_EXTRA, asset ) = { /** Board serial number setting (may differ from chassis serial number) */ const struct setting board_serial_setting __setting ( SETTING_HOST_EXTRA, - board-serial ) = { + board_serial ) = { .name = "board-serial", .description = "Base board serial", .tag = SMBIOS_STRING_TAG ( SMBIOS_TYPE_BASE_BOARD_INFORMATION, diff --git a/roms/ipxe/src/libgcc/__divdi3.c b/roms/ipxe/src/libgcc/__divdi3.c index 224bb69c7..7097b11e1 100644 --- a/roms/ipxe/src/libgcc/__divdi3.c +++ b/roms/ipxe/src/libgcc/__divdi3.c @@ -6,5 +6,21 @@ __libgcc int64_t __divdi3(int64_t num, int64_t den) { - return __divmoddi4(num, den, NULL); + int minus = 0; + int64_t v; + + if ( num < 0 ) { + num = -num; + minus = 1; + } + if ( den < 0 ) { + den = -den; + minus ^= 1; + } + + v = __udivmoddi4(num, den, NULL); + if ( minus ) + v = -v; + + return v; } diff --git a/roms/ipxe/src/libgcc/__divmoddi4.c b/roms/ipxe/src/libgcc/__divmoddi4.c deleted file mode 100644 index 95e328d06..000000000 --- a/roms/ipxe/src/libgcc/__divmoddi4.c +++ /dev/null @@ -1,25 +0,0 @@ -#include "libgcc.h" - -__libgcc int64_t __divmoddi4(int64_t num, int64_t den, int64 *rem_p) -{ - int minus = 0; - int64_t v; - - if ( num < 0 ) { - num = -num; - minus = 1; - } - if ( den < 0 ) { - den = -den; - minus ^= 1; - } - - v = __udivmoddi4(num, den, (uint64_t *)rem_p); - if ( minus ) { - v = -v; - if ( rem_p ) - *rem_p = -(*rem_p); - } - - return v; -} diff --git a/roms/ipxe/src/libgcc/__moddi3.c b/roms/ipxe/src/libgcc/__moddi3.c index ea6fd6f7b..d671bbc4d 100644 --- a/roms/ipxe/src/libgcc/__moddi3.c +++ b/roms/ipxe/src/libgcc/__moddi3.c @@ -6,8 +6,21 @@ __libgcc int64_t __moddi3(int64_t num, int64_t den) { + int minus = 0; int64_t v; - (void) __divmoddi4(num, den, &v); + if ( num < 0 ) { + num = -num; + minus = 1; + } + if ( den < 0 ) { + den = -den; + minus ^= 1; + } + + (void) __udivmoddi4(num, den, (uint64_t *)&v); + if ( minus ) + v = -v; + return v; } diff --git a/roms/ipxe/src/libgcc/implicit.c b/roms/ipxe/src/libgcc/implicit.c deleted file mode 100644 index 645ae6d22..000000000 --- a/roms/ipxe/src/libgcc/implicit.c +++ /dev/null @@ -1,26 +0,0 @@ -/** @file - * - * gcc sometimes likes to insert implicit calls to memcpy() and - * memset(). Unfortunately, there doesn't seem to be any way to - * prevent it from doing this, or to force it to use the optimised - * versions as seen by C code; it insists on inserting symbol - * references to "memcpy" and "memset". We therefore include wrapper - * functions just to keep gcc happy. - * - */ - -#include <string.h> - -void * gcc_implicit_memcpy ( void *dest, const void *src, - size_t len ) asm ( "memcpy" ); - -void * gcc_implicit_memcpy ( void *dest, const void *src, size_t len ) { - return memcpy ( dest, src, len ); -} - -void * gcc_implicit_memset ( void *dest, int character, - size_t len ) asm ( "memset" ); - -void * gcc_implicit_memset ( void *dest, int character, size_t len ) { - return memset ( dest, character, len ); -} diff --git a/roms/ipxe/src/libgcc/libgcc.h b/roms/ipxe/src/libgcc/libgcc.h index eb7c68ec5..d3e9bdd73 100644 --- a/roms/ipxe/src/libgcc/libgcc.h +++ b/roms/ipxe/src/libgcc/libgcc.h @@ -8,7 +8,6 @@ extern __libgcc uint64_t __udivmoddi4 ( uint64_t num, uint64_t den, uint64_t *rem ); extern __libgcc uint64_t __udivdi3 (uint64_t num, uint64_t den ); extern __libgcc uint64_t __umoddi3 ( uint64_t num, uint64_t den ); -extern __libgcc int64_t __divmoddi4 ( int64_t num, int64_t den, int64_t *rem ); extern __libgcc int64_t __divdi3 ( int64_t num, int64_t den ); extern __libgcc int64_t __moddi3 ( int64_t num, int64_t den ); diff --git a/roms/ipxe/src/libgcc/memcpy.c b/roms/ipxe/src/libgcc/memcpy.c new file mode 100644 index 000000000..e98b78384 --- /dev/null +++ b/roms/ipxe/src/libgcc/memcpy.c @@ -0,0 +1,18 @@ +/** @file + * + * gcc sometimes likes to insert implicit calls to memcpy(). + * Unfortunately, there doesn't seem to be any way to prevent it from + * doing this, or to force it to use the optimised memcpy() as seen by + * C code; it insists on inserting a symbol reference to "memcpy". We + * therefore include wrapper functions just to keep gcc happy. + * + */ + +#include <string.h> + +void * gcc_implicit_memcpy ( void *dest, const void *src, + size_t len ) asm ( "memcpy" ); + +void * gcc_implicit_memcpy ( void *dest, const void *src, size_t len ) { + return memcpy ( dest, src, len ); +} diff --git a/roms/ipxe/src/net/arp.c b/roms/ipxe/src/net/arp.c index c9b4109a9..1e27c44e7 100644 --- a/roms/ipxe/src/net/arp.c +++ b/roms/ipxe/src/net/arp.c @@ -139,15 +139,8 @@ static int arp_rx ( struct io_buffer *iobuf, struct net_device *netdev, struct arp_net_protocol *arp_net_protocol; struct net_protocol *net_protocol; struct ll_protocol *ll_protocol; - size_t len = iob_len ( iobuf ); int rc; - /* Sanity check */ - if ( ( len < sizeof ( *arphdr ) ) || ( len < arp_len ( arphdr ) ) ) { - rc = -EINVAL; - goto done; - } - /* Identify network-layer and link-layer protocols */ arp_net_protocol = arp_find_protocol ( arphdr->ar_pro ); if ( ! arp_net_protocol ) { diff --git a/roms/ipxe/src/net/ethernet.c b/roms/ipxe/src/net/ethernet.c index 26fdedea8..6ddf05344 100644 --- a/roms/ipxe/src/net/ethernet.c +++ b/roms/ipxe/src/net/ethernet.c @@ -278,3 +278,6 @@ REQUIRING_SYMBOL ( ethernet_protocol ); /* Drag in Ethernet configuration */ REQUIRE_OBJECT ( config_ethernet ); + +/* Drag in Ethernet slow protocols */ +REQUIRE_OBJECT ( eth_slow ); diff --git a/roms/ipxe/src/net/fakedhcp.c b/roms/ipxe/src/net/fakedhcp.c index 009b12c56..b6c456a59 100644 --- a/roms/ipxe/src/net/fakedhcp.c +++ b/roms/ipxe/src/net/fakedhcp.c @@ -199,10 +199,6 @@ int create_fakepxebsack ( struct net_device *netdev, return rc; } - /* Populate ciaddr */ - fetch_ipv4_setting ( netdev_settings ( netdev ), &ip_setting, - &dhcppkt.dhcphdr->ciaddr ); - /* Merge in ProxyDHCP options */ if ( proxy_settings && ( ( rc = copy_settings ( &dhcppkt, proxy_settings ) ) != 0 ) ) { diff --git a/roms/ipxe/src/net/infiniband.c b/roms/ipxe/src/net/infiniband.c index 15ff0529b..2e3d76d54 100644 --- a/roms/ipxe/src/net/infiniband.c +++ b/roms/ipxe/src/net/infiniband.c @@ -37,7 +37,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <ipxe/netdevice.h> #include <ipxe/iobuf.h> #include <ipxe/process.h> -#include <ipxe/profile.h> #include <ipxe/infiniband.h> #include <ipxe/ib_mi.h> #include <ipxe/ib_sma.h> @@ -54,17 +53,6 @@ struct list_head ib_devices = LIST_HEAD_INIT ( ib_devices ); /** List of open Infiniband devices, in reverse order of opening */ static struct list_head open_ib_devices = LIST_HEAD_INIT ( open_ib_devices ); -/** Infiniband device index */ -static unsigned int ibdev_index = 0; - -/** Post send work queue entry profiler */ -static struct profiler ib_post_send_profiler __profiler = - { .name = "ib.post_send" }; - -/** Post receive work queue entry profiler */ -static struct profiler ib_post_recv_profiler __profiler = - { .name = "ib.post_recv" }; - /* Disambiguate the various possible EINPROGRESSes */ #define EINPROGRESS_INIT __einfo_error ( EINFO_EINPROGRESS_INIT ) #define EINFO_EINPROGRESS_INIT __einfo_uniqify \ @@ -100,27 +88,27 @@ ib_create_cq ( struct ib_device *ibdev, unsigned int num_cqes, struct ib_completion_queue *cq; int rc; - DBGC ( ibdev, "IBDEV %s creating completion queue\n", ibdev->name ); + DBGC ( ibdev, "IBDEV %p creating completion queue\n", ibdev ); /* Allocate and initialise data structure */ cq = zalloc ( sizeof ( *cq ) ); if ( ! cq ) goto err_alloc_cq; cq->ibdev = ibdev; - list_add_tail ( &cq->list, &ibdev->cqs ); + list_add ( &cq->list, &ibdev->cqs ); cq->num_cqes = num_cqes; INIT_LIST_HEAD ( &cq->work_queues ); cq->op = op; /* Perform device-specific initialisation and get CQN */ if ( ( rc = ibdev->op->create_cq ( ibdev, cq ) ) != 0 ) { - DBGC ( ibdev, "IBDEV %s could not initialise completion " - "queue: %s\n", ibdev->name, strerror ( rc ) ); + DBGC ( ibdev, "IBDEV %p could not initialise completion " + "queue: %s\n", ibdev, strerror ( rc ) ); goto err_dev_create_cq; } - DBGC ( ibdev, "IBDEV %s created %d-entry completion queue %p (%p) " - "with CQN %#lx\n", ibdev->name, num_cqes, cq, + DBGC ( ibdev, "IBDEV %p created %d-entry completion queue %p (%p) " + "with CQN %#lx\n", ibdev, num_cqes, cq, ib_cq_get_drvdata ( cq ), cq->cqn ); return cq; @@ -140,8 +128,8 @@ ib_create_cq ( struct ib_device *ibdev, unsigned int num_cqes, */ void ib_destroy_cq ( struct ib_device *ibdev, struct ib_completion_queue *cq ) { - DBGC ( ibdev, "IBDEV %s destroying completion queue %#lx\n", - ibdev->name, cq->cqn ); + DBGC ( ibdev, "IBDEV %p destroying completion queue %#lx\n", + ibdev, cq->cqn ); assert ( list_empty ( &cq->work_queues ) ); ibdev->op->destroy_cq ( ibdev, cq ); list_del ( &cq->list ); @@ -185,7 +173,6 @@ void ib_poll_cq ( struct ib_device *ibdev, * @v num_recv_wqes Number of receive work queue entries * @v recv_cq Receive completion queue * @v op Queue pair operations - * @v name Queue pair name * @ret qp Queue pair * * The queue pair will be left in the INIT state; you must call @@ -197,13 +184,12 @@ struct ib_queue_pair * ib_create_qp ( struct ib_device *ibdev, struct ib_completion_queue *send_cq, unsigned int num_recv_wqes, struct ib_completion_queue *recv_cq, - struct ib_queue_pair_operations *op, - const char *name ) { + struct ib_queue_pair_operations *op ) { struct ib_queue_pair *qp; size_t total_size; int rc; - DBGC ( ibdev, "IBDEV %s creating queue pair\n", ibdev->name ); + DBGC ( ibdev, "IBDEV %p creating queue pair\n", ibdev ); /* Allocate and initialise data structure */ total_size = ( sizeof ( *qp ) + @@ -213,39 +199,38 @@ struct ib_queue_pair * ib_create_qp ( struct ib_device *ibdev, if ( ! qp ) goto err_alloc_qp; qp->ibdev = ibdev; - list_add_tail ( &qp->list, &ibdev->qps ); + list_add ( &qp->list, &ibdev->qps ); qp->type = type; qp->send.qp = qp; qp->send.is_send = 1; qp->send.cq = send_cq; - list_add_tail ( &qp->send.list, &send_cq->work_queues ); + list_add ( &qp->send.list, &send_cq->work_queues ); qp->send.psn = ( random() & 0xffffffUL ); qp->send.num_wqes = num_send_wqes; qp->send.iobufs = ( ( ( void * ) qp ) + sizeof ( *qp ) ); qp->recv.qp = qp; qp->recv.cq = recv_cq; - list_add_tail ( &qp->recv.list, &recv_cq->work_queues ); + list_add ( &qp->recv.list, &recv_cq->work_queues ); qp->recv.psn = ( random() & 0xffffffUL ); qp->recv.num_wqes = num_recv_wqes; qp->recv.iobufs = ( ( ( void * ) qp ) + sizeof ( *qp ) + ( num_send_wqes * sizeof ( qp->send.iobufs[0] ) )); INIT_LIST_HEAD ( &qp->mgids ); qp->op = op; - qp->name = name; /* Perform device-specific initialisation and get QPN */ if ( ( rc = ibdev->op->create_qp ( ibdev, qp ) ) != 0 ) { - DBGC ( ibdev, "IBDEV %s could not initialise queue pair: " - "%s\n", ibdev->name, strerror ( rc ) ); + DBGC ( ibdev, "IBDEV %p could not initialise queue pair: " + "%s\n", ibdev, strerror ( rc ) ); goto err_dev_create_qp; } - DBGC ( ibdev, "IBDEV %s created queue pair %p (%p) with QPN %#lx\n", - ibdev->name, qp, ib_qp_get_drvdata ( qp ), qp->qpn ); - DBGC ( ibdev, "IBDEV %s QPN %#lx has %d send entries at [%p,%p)\n", - ibdev->name, qp->qpn, num_send_wqes, qp->send.iobufs, + DBGC ( ibdev, "IBDEV %p created queue pair %p (%p) with QPN %#lx\n", + ibdev, qp, ib_qp_get_drvdata ( qp ), qp->qpn ); + DBGC ( ibdev, "IBDEV %p QPN %#lx has %d send entries at [%p,%p)\n", + ibdev, qp->qpn, num_send_wqes, qp->send.iobufs, qp->recv.iobufs ); - DBGC ( ibdev, "IBDEV %s QPN %#lx has %d receive entries at [%p,%p)\n", - ibdev->name, qp->qpn, num_recv_wqes, qp->recv.iobufs, + DBGC ( ibdev, "IBDEV %p QPN %#lx has %d receive entries at [%p,%p)\n", + ibdev, qp->qpn, num_recv_wqes, qp->recv.iobufs, ( ( ( void * ) qp ) + total_size ) ); /* Calculate externally-visible QPN */ @@ -261,8 +246,8 @@ struct ib_queue_pair * ib_create_qp ( struct ib_device *ibdev, break; } if ( qp->ext_qpn != qp->qpn ) { - DBGC ( ibdev, "IBDEV %s QPN %#lx has external QPN %#lx\n", - ibdev->name, qp->qpn, qp->ext_qpn ); + DBGC ( ibdev, "IBDEV %p QPN %#lx has external QPN %#lx\n", + ibdev, qp->qpn, qp->ext_qpn ); } return qp; @@ -287,11 +272,11 @@ struct ib_queue_pair * ib_create_qp ( struct ib_device *ibdev, int ib_modify_qp ( struct ib_device *ibdev, struct ib_queue_pair *qp ) { int rc; - DBGC ( ibdev, "IBDEV %s modifying QPN %#lx\n", ibdev->name, qp->qpn ); + DBGC ( ibdev, "IBDEV %p modifying QPN %#lx\n", ibdev, qp->qpn ); if ( ( rc = ibdev->op->modify_qp ( ibdev, qp ) ) != 0 ) { - DBGC ( ibdev, "IBDEV %s could not modify QPN %#lx: %s\n", - ibdev->name, qp->qpn, strerror ( rc ) ); + DBGC ( ibdev, "IBDEV %p could not modify QPN %#lx: %s\n", + ibdev, qp->qpn, strerror ( rc ) ); return rc; } @@ -308,8 +293,8 @@ void ib_destroy_qp ( struct ib_device *ibdev, struct ib_queue_pair *qp ) { struct io_buffer *iobuf; unsigned int i; - DBGC ( ibdev, "IBDEV %s destroying QPN %#lx\n", - ibdev->name, qp->qpn ); + DBGC ( ibdev, "IBDEV %p destroying QPN %#lx\n", + ibdev, qp->qpn ); assert ( list_empty ( &qp->mgids ) ); @@ -412,13 +397,10 @@ int ib_post_send ( struct ib_device *ibdev, struct ib_queue_pair *qp, struct ib_address_vector dest_copy; int rc; - /* Start profiling */ - profile_start ( &ib_post_send_profiler ); - /* Check queue fill level */ if ( qp->send.fill >= qp->send.num_wqes ) { - DBGC ( ibdev, "IBDEV %s QPN %#lx send queue full\n", - ibdev->name, qp->qpn ); + DBGC ( ibdev, "IBDEV %p QPN %#lx send queue full\n", + ibdev, qp->qpn ); return -ENOBUFS; } @@ -438,17 +420,12 @@ int ib_post_send ( struct ib_device *ibdev, struct ib_queue_pair *qp, /* Post to hardware */ if ( ( rc = ibdev->op->post_send ( ibdev, qp, dest, iobuf ) ) != 0 ) { - DBGC ( ibdev, "IBDEV %s QPN %#lx could not post send WQE: " - "%s\n", ibdev->name, qp->qpn, strerror ( rc ) ); + DBGC ( ibdev, "IBDEV %p QPN %#lx could not post send WQE: " + "%s\n", ibdev, qp->qpn, strerror ( rc ) ); return rc; } - /* Increase fill level */ qp->send.fill++; - - /* Stop profiling */ - profile_stop ( &ib_post_send_profiler ); - return 0; } @@ -464,36 +441,28 @@ int ib_post_recv ( struct ib_device *ibdev, struct ib_queue_pair *qp, struct io_buffer *iobuf ) { int rc; - /* Start profiling */ - profile_start ( &ib_post_recv_profiler ); - /* Check packet length */ if ( iob_tailroom ( iobuf ) < IB_MAX_PAYLOAD_SIZE ) { - DBGC ( ibdev, "IBDEV %s QPN %#lx wrong RX buffer size (%zd)\n", - ibdev->name, qp->qpn, iob_tailroom ( iobuf ) ); + DBGC ( ibdev, "IBDEV %p QPN %#lx wrong RX buffer size (%zd)\n", + ibdev, qp->qpn, iob_tailroom ( iobuf ) ); return -EINVAL; } /* Check queue fill level */ if ( qp->recv.fill >= qp->recv.num_wqes ) { - DBGC ( ibdev, "IBDEV %s QPN %#lx receive queue full\n", - ibdev->name, qp->qpn ); + DBGC ( ibdev, "IBDEV %p QPN %#lx receive queue full\n", + ibdev, qp->qpn ); return -ENOBUFS; } /* Post to hardware */ if ( ( rc = ibdev->op->post_recv ( ibdev, qp, iobuf ) ) != 0 ) { - DBGC ( ibdev, "IBDEV %s QPN %#lx could not post receive WQE: " - "%s\n", ibdev->name, qp->qpn, strerror ( rc ) ); + DBGC ( ibdev, "IBDEV %p QPN %#lx could not post receive WQE: " + "%s\n", ibdev, qp->qpn, strerror ( rc ) ); return rc; } - /* Increase fill level */ qp->recv.fill++; - - /* Stop profiling */ - profile_stop ( &ib_post_recv_profiler ); - return 0; } @@ -562,8 +531,8 @@ void ib_refill_recv ( struct ib_device *ibdev, struct ib_queue_pair *qp ) { /* Post I/O buffer */ if ( ( rc = ib_post_recv ( ibdev, qp, iobuf ) ) != 0 ) { - DBGC ( ibdev, "IBDEV %s could not refill: %s\n", - ibdev->name, strerror ( rc ) ); + DBGC ( ibdev, "IBDEV %p could not refill: %s\n", + ibdev, strerror ( rc ) ); free_iob ( iobuf ); /* Give up */ return; @@ -629,8 +598,8 @@ static void ib_notify ( struct ib_device *ibdev ) { */ void ib_link_state_changed ( struct ib_device *ibdev ) { - DBGC ( ibdev, "IBDEV %s link state is %s\n", - ibdev->name, ib_link_state_text ( ibdev ) ); + DBGC ( ibdev, "IBDEV %p link state is %s\n", + ibdev, ib_link_state_text ( ibdev ) ); /* Notify drivers of link state change */ ib_notify ( ibdev ); @@ -653,30 +622,30 @@ int ib_open ( struct ib_device *ibdev ) { /* Open device */ if ( ( rc = ibdev->op->open ( ibdev ) ) != 0 ) { - DBGC ( ibdev, "IBDEV %s could not open: %s\n", - ibdev->name, strerror ( rc ) ); + DBGC ( ibdev, "IBDEV %p could not open: %s\n", + ibdev, strerror ( rc ) ); goto err_open; } /* Create subnet management interface */ ibdev->smi = ib_create_mi ( ibdev, IB_QPT_SMI ); if ( ! ibdev->smi ) { - DBGC ( ibdev, "IBDEV %s could not create SMI\n", ibdev->name ); + DBGC ( ibdev, "IBDEV %p could not create SMI\n", ibdev ); rc = -ENOMEM; goto err_create_smi; } /* Create subnet management agent */ if ( ( rc = ib_create_sma ( ibdev, ibdev->smi ) ) != 0 ) { - DBGC ( ibdev, "IBDEV %s could not create SMA: %s\n", - ibdev->name, strerror ( rc ) ); + DBGC ( ibdev, "IBDEV %p could not create SMA: %s\n", + ibdev, strerror ( rc ) ); goto err_create_sma; } /* Create general services interface */ ibdev->gsi = ib_create_mi ( ibdev, IB_QPT_GSI ); if ( ! ibdev->gsi ) { - DBGC ( ibdev, "IBDEV %s could not create GSI\n", ibdev->name ); + DBGC ( ibdev, "IBDEV %p could not create GSI\n", ibdev ); rc = -ENOMEM; goto err_create_gsi; } @@ -759,7 +728,7 @@ int ib_mcast_attach ( struct ib_device *ibdev, struct ib_queue_pair *qp, goto err_alloc_mgid; } memcpy ( &mgid->gid, gid, sizeof ( mgid->gid ) ); - list_add_tail ( &mgid->list, &qp->mgids ); + list_add ( &mgid->list, &qp->mgids ); /* Add to hardware multicast GID list */ if ( ( rc = ibdev->op->mcast_attach ( ibdev, qp, gid ) ) != 0 ) @@ -839,14 +808,14 @@ int ib_set_port_info ( struct ib_device *ibdev, union ib_mad *mad ) { /* Adapters with embedded SMAs do not need to support this method */ if ( ! ibdev->op->set_port_info ) { - DBGC ( ibdev, "IBDEV %s does not support setting port " - "information\n", ibdev->name ); + DBGC ( ibdev, "IBDEV %p does not support setting port " + "information\n", ibdev ); return -ENOTSUP; } if ( ( rc = ibdev->op->set_port_info ( ibdev, mad ) ) != 0 ) { - DBGC ( ibdev, "IBDEV %s could not set port information: %s\n", - ibdev->name, strerror ( rc ) ); + DBGC ( ibdev, "IBDEV %p could not set port information: %s\n", + ibdev, strerror ( rc ) ); return rc; } @@ -864,14 +833,14 @@ int ib_set_pkey_table ( struct ib_device *ibdev, union ib_mad *mad ) { /* Adapters with embedded SMAs do not need to support this method */ if ( ! ibdev->op->set_pkey_table ) { - DBGC ( ibdev, "IBDEV %s does not support setting partition " - "key table\n", ibdev->name ); + DBGC ( ibdev, "IBDEV %p does not support setting partition " + "key table\n", ibdev ); return -ENOTSUP; } if ( ( rc = ibdev->op->set_pkey_table ( ibdev, mad ) ) != 0 ) { - DBGC ( ibdev, "IBDEV %s could not set partition key table: " - "%s\n", ibdev->name, strerror ( rc ) ); + DBGC ( ibdev, "IBDEV %p could not set partition key table: " + "%s\n", ibdev, strerror ( rc ) ); return rc; } @@ -960,24 +929,17 @@ int register_ibdev ( struct ib_device *ibdev ) { struct ib_driver *driver; int rc; - /* Record device index and create device name */ - if ( ibdev->name[0] == '\0' ) { - snprintf ( ibdev->name, sizeof ( ibdev->name ), "inf%d", - ibdev_index ); - } - ibdev->index = ++ibdev_index; - /* Add to device list */ ibdev_get ( ibdev ); list_add_tail ( &ibdev->list, &ib_devices ); - DBGC ( ibdev, "IBDEV %s registered (phys %s)\n", ibdev->name, + DBGC ( ibdev, "IBDEV %p registered (phys %s)\n", ibdev, ibdev->dev->name ); /* Probe device */ for_each_table_entry ( driver, IB_DRIVERS ) { if ( ( rc = driver->probe ( ibdev ) ) != 0 ) { - DBGC ( ibdev, "IBDEV %s could not add %s device: %s\n", - ibdev->name, driver->name, strerror ( rc ) ); + DBGC ( ibdev, "IBDEV %p could not add %s device: %s\n", + ibdev, driver->name, strerror ( rc ) ); goto err_probe; } } @@ -1007,11 +969,7 @@ void unregister_ibdev ( struct ib_device *ibdev ) { /* Remove from device list */ list_del ( &ibdev->list ); ibdev_put ( ibdev ); - DBGC ( ibdev, "IBDEV %s unregistered\n", ibdev->name ); - - /* Reset device index if no devices remain */ - if ( list_empty ( &ib_devices ) ) - ibdev_index = 0; + DBGC ( ibdev, "IBDEV %p unregistered\n", ibdev ); } /** @@ -1052,3 +1010,6 @@ REQUIRING_SYMBOL ( register_ibdev ); /* Drag in Infiniband configuration */ REQUIRE_OBJECT ( config_infiniband ); + +/* Drag in IPoIB */ +REQUIRE_OBJECT ( ipoib ); diff --git a/roms/ipxe/src/net/infiniband/ib_cm.c b/roms/ipxe/src/net/infiniband/ib_cm.c index 247b8e7a0..85982f09d 100644 --- a/roms/ipxe/src/net/infiniband/ib_cm.c +++ b/roms/ipxe/src/net/infiniband/ib_cm.c @@ -65,7 +65,6 @@ static struct ib_connection * ib_cm_find ( uint32_t local_id ) { * * @v ibdev Infiniband device * @v mi Management interface - * @v tid Transaction identifier * @v av Address vector * @v local_id Local communication ID * @v remote_id Remote communication ID @@ -73,7 +72,6 @@ static struct ib_connection * ib_cm_find ( uint32_t local_id ) { */ static int ib_cm_send_rtu ( struct ib_device *ibdev, struct ib_mad_interface *mi, - struct ib_mad_tid *tid, struct ib_address_vector *av, uint32_t local_id, uint32_t remote_id ) { union ib_mad mad; @@ -85,13 +83,11 @@ static int ib_cm_send_rtu ( struct ib_device *ibdev, mad.hdr.mgmt_class = IB_MGMT_CLASS_CM; mad.hdr.class_version = IB_CM_CLASS_VERSION; mad.hdr.method = IB_MGMT_METHOD_SEND; - memcpy ( &mad.hdr.tid, tid, sizeof ( mad.hdr.tid ) ); mad.hdr.attr_id = htons ( IB_CM_ATTR_READY_TO_USE ); rtu->local_id = htonl ( local_id ); rtu->remote_id = htonl ( remote_id ); - if ( ( rc = ib_mi_send ( ibdev, mi, &mad, av ) ) != 0 ) { - DBGC ( local_id, "CM %08x could not send RTU: %s\n", - local_id, strerror ( rc ) ); + if ( ( rc = ib_mi_send ( ibdev, mi, &mad, av ) ) != 0 ){ + DBG ( "CM could not send RTU: %s\n", strerror ( rc ) ); return rc; } @@ -124,13 +120,12 @@ static void ib_cm_recv_rep ( struct ib_device *ibdev, conn = ib_cm_find ( local_id ); if ( conn ) { /* Try to send "ready to use" reply */ - if ( ( rc = ib_cm_send_rtu ( ibdev, mi, &mad->hdr.tid, av, - conn->local_id, + if ( ( rc = ib_cm_send_rtu ( ibdev, mi, av, conn->local_id, conn->remote_id ) ) != 0 ) { /* Ignore errors; the remote end will retry */ } } else { - DBGC ( local_id, "CM %08x unexpected REP\n", local_id ); + DBG ( "CM unidentified connection %08x\n", local_id ); } } @@ -139,7 +134,6 @@ static void ib_cm_recv_rep ( struct ib_device *ibdev, * * @v ibdev Infiniband device * @v mi Management interface - * @v tid Transaction identifier * @v av Address vector * @v local_id Local communication ID * @v remote_id Remote communication ID @@ -147,7 +141,6 @@ static void ib_cm_recv_rep ( struct ib_device *ibdev, */ static int ib_cm_send_drep ( struct ib_device *ibdev, struct ib_mad_interface *mi, - struct ib_mad_tid *tid, struct ib_address_vector *av, uint32_t local_id, uint32_t remote_id ) { union ib_mad mad; @@ -159,13 +152,11 @@ static int ib_cm_send_drep ( struct ib_device *ibdev, mad.hdr.mgmt_class = IB_MGMT_CLASS_CM; mad.hdr.class_version = IB_CM_CLASS_VERSION; mad.hdr.method = IB_MGMT_METHOD_SEND; - memcpy ( &mad.hdr.tid, tid, sizeof ( mad.hdr.tid ) ); mad.hdr.attr_id = htons ( IB_CM_ATTR_DISCONNECT_REPLY ); drep->local_id = htonl ( local_id ); drep->remote_id = htonl ( remote_id ); - if ( ( rc = ib_mi_send ( ibdev, mi, &mad, av ) ) != 0 ) { - DBGC ( local_id, "CM %08x could not send DREP: %s\n", - local_id, strerror ( rc ) ); + if ( ( rc = ib_mi_send ( ibdev, mi, &mad, av ) ) != 0 ){ + DBG ( "CM could not send DREP: %s\n", strerror ( rc ) ); return rc; } @@ -200,11 +191,11 @@ static void ib_cm_recv_dreq ( struct ib_device *ibdev, &dreq->private_data, sizeof ( dreq->private_data ) ); } else { - DBGC ( local_id, "CM %08x unexpected DREQ\n", local_id ); + DBG ( "CM unidentified connection %08x\n", local_id ); } /* Send reply */ - if ( ( rc = ib_cm_send_drep ( ibdev, mi, &mad->hdr.tid, av, local_id, + if ( ( rc = ib_cm_send_drep ( ibdev, mi, av, local_id, remote_id ) ) != 0 ) { /* Ignore errors; the remote end will retry */ } @@ -265,7 +256,6 @@ static void ib_cm_req_complete ( struct ib_device *ibdev, struct ib_cm_common *common = &mad->cm.cm_data.common; struct ib_cm_connect_reply *rep = &mad->cm.cm_data.connect_reply; struct ib_cm_connect_reject *rej = &mad->cm.cm_data.connect_reject; - uint32_t local_id = conn->local_id; void *private_data = NULL; size_t private_data_len = 0; @@ -273,8 +263,8 @@ static void ib_cm_req_complete ( struct ib_device *ibdev, if ( ( rc == 0 ) && ( mad->hdr.status != htons ( IB_MGMT_STATUS_OK ) )) rc = -EIO; if ( rc != 0 ) { - DBGC ( local_id, "CM %08x connection request failed: %s\n", - local_id, strerror ( rc ) ); + DBGC ( conn, "CM %p connection request failed: %s\n", + conn, strerror ( rc ) ); goto out; } @@ -290,19 +280,18 @@ static void ib_cm_req_complete ( struct ib_device *ibdev, qp->send.psn = ( ntohl ( rep->starting_psn ) >> 8 ); private_data = &rep->private_data; private_data_len = sizeof ( rep->private_data ); - DBGC ( local_id, "CM %08x connected to QPN %#lx PSN %#x\n", - local_id, qp->av.qpn, qp->send.psn ); + DBGC ( conn, "CM %p connected to QPN %lx PSN %x\n", + conn, qp->av.qpn, qp->send.psn ); /* Modify queue pair */ if ( ( rc = ib_modify_qp ( ibdev, qp ) ) != 0 ) { - DBGC ( local_id, "CM %08x could not modify queue " - "pair: %s\n", local_id, strerror ( rc ) ); + DBGC ( conn, "CM %p could not modify queue pair: %s\n", + conn, strerror ( rc ) ); goto out; } /* Send "ready to use" reply */ - if ( ( rc = ib_cm_send_rtu ( ibdev, mi, &mad->hdr.tid, av, - conn->local_id, + if ( ( rc = ib_cm_send_rtu ( ibdev, mi, av, conn->local_id, conn->remote_id ) ) != 0 ) { /* Treat as non-fatal */ rc = 0; @@ -311,8 +300,8 @@ static void ib_cm_req_complete ( struct ib_device *ibdev, case htons ( IB_CM_ATTR_CONNECT_REJECT ) : /* Extract fields */ - DBGC ( local_id, "CM %08x connection rejected (reason %d)\n", - local_id, ntohs ( rej->reason ) ); + DBGC ( conn, "CM %p connection rejected (reason %d)\n", + conn, ntohs ( rej->reason ) ); /* Private data is valid only for a Consumer Reject */ if ( rej->reason == htons ( IB_CM_REJECT_CONSUMER ) ) { private_data = &rej->private_data; @@ -322,8 +311,8 @@ static void ib_cm_req_complete ( struct ib_device *ibdev, break; default: - DBGC ( local_id, "CM %08x unexpected response (attribute " - "%04x)\n", local_id, ntohs ( mad->hdr.attr_id ) ); + DBGC ( conn, "CM %p unexpected response (attribute %04x)\n", + conn, ntohs ( mad->hdr.attr_id ) ); rc = -ENOTSUP; break; } @@ -358,13 +347,12 @@ static void ib_cm_path_complete ( struct ib_device *ibdev, struct ib_queue_pair *qp = conn->qp; union ib_mad mad; struct ib_cm_connect_request *req = &mad.cm.cm_data.connect_request; - uint32_t local_id = conn->local_id; size_t private_data_len; /* Report failures */ if ( rc != 0 ) { - DBGC ( local_id, "CM %08x path lookup failed: %s\n", - local_id, strerror ( rc ) ); + DBGC ( conn, "CM %p path lookup failed: %s\n", + conn, strerror ( rc ) ); conn->op->changed ( ibdev, qp, conn, rc, NULL, 0 ); goto out; } @@ -417,8 +405,8 @@ static void ib_cm_path_complete ( struct ib_device *ibdev, conn->madx = ib_create_madx ( ibdev, ibdev->gsi, &mad, av, &ib_cm_req_op ); if ( ! conn->madx ) { - DBGC ( local_id, "CM %08x could not create connection " - "request\n", local_id ); + DBGC ( conn, "CM %p could not create connection request\n", + conn ); conn->op->changed ( ibdev, qp, conn, rc, NULL, 0 ); goto out; } @@ -453,7 +441,6 @@ ib_create_conn ( struct ib_device *ibdev, struct ib_queue_pair *qp, void *private_data, size_t private_data_len, struct ib_connection_operations *op ) { struct ib_connection *conn; - uint32_t local_id; /* Allocate and initialise request */ conn = zalloc ( sizeof ( *conn ) + private_data_len ); @@ -464,7 +451,7 @@ ib_create_conn ( struct ib_device *ibdev, struct ib_queue_pair *qp, memset ( &qp->av, 0, sizeof ( qp->av ) ); qp->av.gid_present = 1; memcpy ( &qp->av.gid, dgid, sizeof ( qp->av.gid ) ); - conn->local_id = local_id = random(); + conn->local_id = random(); memcpy ( &conn->service_id, service_id, sizeof ( conn->service_id ) ); conn->op = op; conn->private_data_len = private_data_len; @@ -479,11 +466,10 @@ ib_create_conn ( struct ib_device *ibdev, struct ib_queue_pair *qp, /* Add to list of connections */ list_add ( &conn->list, &ib_cm_conns ); - DBGC ( local_id, "CM %08x created for IBDEV %s QPN %#lx\n", - local_id, ibdev->name, qp->qpn ); - DBGC ( local_id, "CM %08x connecting to " IB_GID_FMT " " - IB_GUID_FMT "\n", local_id, IB_GID_ARGS ( dgid ), - IB_GUID_ARGS ( service_id ) ); + DBGC ( conn, "CM %p created for IBDEV %p QPN %lx\n", + conn, ibdev, qp->qpn ); + DBGC ( conn, "CM %p connecting to " IB_GID_FMT " " IB_GUID_FMT "\n", + conn, IB_GID_ARGS ( dgid ), IB_GUID_ARGS ( service_id ) ); return conn; diff --git a/roms/ipxe/src/net/infiniband/ib_cmrc.c b/roms/ipxe/src/net/infiniband/ib_cmrc.c index 2cd49018f..1cc0fcfef 100644 --- a/roms/ipxe/src/net/infiniband/ib_cmrc.c +++ b/roms/ipxe/src/net/infiniband/ib_cmrc.c @@ -69,8 +69,6 @@ FILE_LICENCE ( BSD2 ); struct ib_cmrc_connection { /** Reference count */ struct refcnt refcnt; - /** Name */ - const char *name; /** Data transfer interface */ struct interface xfer; /** Infiniband device */ @@ -110,19 +108,14 @@ struct ib_cmrc_connection { * shutdown process has run. */ static void ib_cmrc_shutdown ( struct ib_cmrc_connection *cmrc ) { - struct ib_device *ibdev = cmrc->ibdev; - DBGC ( cmrc, "CMRC %s %s shutting down\n", - ibdev->name, cmrc->name ); + DBGC ( cmrc, "CMRC %p shutting down\n", cmrc ); /* Shut down Infiniband interface */ - ib_destroy_conn ( ibdev, cmrc->qp, cmrc->conn ); - ib_destroy_qp ( ibdev, cmrc->qp ); - ib_destroy_cq ( ibdev, cmrc->cq ); - ib_close ( ibdev ); - - /* Cancel any pending shutdown */ - process_del ( &cmrc->shutdown ); + ib_destroy_conn ( cmrc->ibdev, cmrc->qp, cmrc->conn ); + ib_destroy_qp ( cmrc->ibdev, cmrc->qp ); + ib_destroy_cq ( cmrc->ibdev, cmrc->cq ); + ib_close ( cmrc->ibdev ); /* Drop the remaining reference */ ref_put ( &cmrc->refcnt ); @@ -153,7 +146,7 @@ static void ib_cmrc_close ( struct ib_cmrc_connection *cmrc, int rc ) { * @v private_data Private data, if available * @v private_data_len Length of private data */ -static void ib_cmrc_changed ( struct ib_device *ibdev, +static void ib_cmrc_changed ( struct ib_device *ibdev __unused, struct ib_queue_pair *qp, struct ib_connection *conn __unused, int rc_cm, void *private_data, size_t private_data_len ) { @@ -162,24 +155,22 @@ static void ib_cmrc_changed ( struct ib_device *ibdev, /* Record connection status */ if ( rc_cm == 0 ) { - DBGC ( cmrc, "CMRC %s %s connected\n", - ibdev->name, cmrc->name ); + DBGC ( cmrc, "CMRC %p connected\n", cmrc ); cmrc->connected = 1; } else { - DBGC ( cmrc, "CMRC %s %s disconnected: %s\n", - ibdev->name, cmrc->name, strerror ( rc_cm ) ); + DBGC ( cmrc, "CMRC %p disconnected: %s\n", + cmrc, strerror ( rc_cm ) ); cmrc->connected = 0; } /* Pass up any private data */ - DBGC2 ( cmrc, "CMRC %s %s received private data:\n", - ibdev->name, cmrc->name ); + DBGC2 ( cmrc, "CMRC %p received private data:\n", cmrc ); DBGC2_HDA ( cmrc, 0, private_data, private_data_len ); if ( private_data && ( rc_xfer = xfer_deliver_raw ( &cmrc->xfer, private_data, private_data_len ) ) != 0 ) { - DBGC ( cmrc, "CMRC %s %s could not deliver private data: %s\n", - ibdev->name, cmrc->name, strerror ( rc_xfer ) ); + DBGC ( cmrc, "CMRC %p could not deliver private data: %s\n", + cmrc, strerror ( rc_xfer ) ); ib_cmrc_close ( cmrc, rc_xfer ); return; } @@ -207,7 +198,7 @@ static struct ib_connection_operations ib_cmrc_conn_op = { * @v iobuf I/O buffer * @v rc Completion status code */ -static void ib_cmrc_complete_send ( struct ib_device *ibdev, +static void ib_cmrc_complete_send ( struct ib_device *ibdev __unused, struct ib_queue_pair *qp, struct io_buffer *iobuf, int rc ) { struct ib_cmrc_connection *cmrc = ib_qp_get_ownerdata ( qp ); @@ -217,8 +208,8 @@ static void ib_cmrc_complete_send ( struct ib_device *ibdev, /* Close the connection on any send errors */ if ( rc != 0 ) { - DBGC ( cmrc, "CMRC %s %s send error: %s\n", - ibdev->name, cmrc->name, strerror ( rc ) ); + DBGC ( cmrc, "CMRC %p send error: %s\n", + cmrc, strerror ( rc ) ); ib_cmrc_close ( cmrc, rc ); return; } @@ -234,7 +225,7 @@ static void ib_cmrc_complete_send ( struct ib_device *ibdev, * @v iobuf I/O buffer * @v rc Completion status code */ -static void ib_cmrc_complete_recv ( struct ib_device *ibdev, +static void ib_cmrc_complete_recv ( struct ib_device *ibdev __unused, struct ib_queue_pair *qp, struct ib_address_vector *dest __unused, struct ib_address_vector *source __unused, @@ -243,20 +234,20 @@ static void ib_cmrc_complete_recv ( struct ib_device *ibdev, /* Close the connection on any receive errors */ if ( rc != 0 ) { - DBGC ( cmrc, "CMRC %s %s receive error: %s\n", - ibdev->name, cmrc->name, strerror ( rc ) ); + DBGC ( cmrc, "CMRC %p receive error: %s\n", + cmrc, strerror ( rc ) ); free_iob ( iobuf ); ib_cmrc_close ( cmrc, rc ); return; } - DBGC2 ( cmrc, "CMRC %s %s received:\n", ibdev->name, cmrc->name ); + DBGC2 ( cmrc, "CMRC %p received:\n", cmrc ); DBGC2_HDA ( cmrc, 0, iobuf->data, iob_len ( iobuf ) ); /* Pass up data */ if ( ( rc = xfer_deliver_iob ( &cmrc->xfer, iobuf ) ) != 0 ) { - DBGC ( cmrc, "CMRC %s %s could not deliver data: %s\n", - ibdev->name, cmrc->name, strerror ( rc ) ); + DBGC ( cmrc, "CMRC %p could not deliver data: %s\n", + cmrc, strerror ( rc ) ); ib_cmrc_close ( cmrc, rc ); return; } @@ -284,7 +275,6 @@ static struct ib_queue_pair_operations ib_cmrc_queue_pair_ops = { static int ib_cmrc_xfer_deliver ( struct ib_cmrc_connection *cmrc, struct io_buffer *iobuf, struct xfer_metadata *meta __unused ) { - struct ib_device *ibdev = cmrc->ibdev; int rc; /* If no connection has yet been attempted, send this datagram @@ -294,9 +284,8 @@ static int ib_cmrc_xfer_deliver ( struct ib_cmrc_connection *cmrc, /* Abort if we have already sent a CM connection request */ if ( cmrc->conn ) { - DBGC ( cmrc, "CMRC %s %s attempt to send before " - "connection is complete\n", - ibdev->name, cmrc->name ); + DBGC ( cmrc, "CMRC %p attempt to send before " + "connection is complete\n", cmrc ); rc = -EIO; goto out; } @@ -307,21 +296,18 @@ static int ib_cmrc_xfer_deliver ( struct ib_cmrc_connection *cmrc, iobuf->data, iob_len ( iobuf ), &ib_cmrc_conn_op ); if ( ! cmrc->conn ) { - DBGC ( cmrc, "CMRC %s %s could not connect\n", - ibdev->name, cmrc->name ); + DBGC ( cmrc, "CMRC %p could not connect\n", cmrc ); rc = -ENOMEM; goto out; } - DBGC ( cmrc, "CMRC %s %s using CM %08x\n", - ibdev->name, cmrc->name, cmrc->conn->local_id ); } else { /* Send via QP */ if ( ( rc = ib_post_send ( cmrc->ibdev, cmrc->qp, NULL, iob_disown ( iobuf ) ) ) != 0 ) { - DBGC ( cmrc, "CMRC %s %s could not send: %s\n", - ibdev->name, cmrc->name, strerror ( rc ) ); + DBGC ( cmrc, "CMRC %p could not send: %s\n", + cmrc, strerror ( rc ) ); goto out; } @@ -391,12 +377,10 @@ static struct process_descriptor ib_cmrc_shutdown_desc = * @v ibdev Infiniband device * @v dgid Destination GID * @v service_id Service ID - * @v name Connection name * @ret rc Returns status code */ int ib_cmrc_open ( struct interface *xfer, struct ib_device *ibdev, - union ib_gid *dgid, union ib_guid *service_id, - const char *name ) { + union ib_gid *dgid, union ib_guid *service_id ) { struct ib_cmrc_connection *cmrc; int rc; @@ -407,7 +391,6 @@ int ib_cmrc_open ( struct interface *xfer, struct ib_device *ibdev, goto err_alloc; } ref_init ( &cmrc->refcnt, NULL ); - cmrc->name = name; intf_init ( &cmrc->xfer, &ib_cmrc_xfer_desc, &cmrc->refcnt ); cmrc->ibdev = ibdev; memcpy ( &cmrc->dgid, dgid, sizeof ( cmrc->dgid ) ); @@ -417,8 +400,8 @@ int ib_cmrc_open ( struct interface *xfer, struct ib_device *ibdev, /* Open Infiniband device */ if ( ( rc = ib_open ( ibdev ) ) != 0 ) { - DBGC ( cmrc, "CMRC %s %s could not open device: %s\n", - ibdev->name, cmrc->name, strerror ( rc ) ); + DBGC ( cmrc, "CMRC %p could not open device: %s\n", + cmrc, strerror ( rc ) ); goto err_open; } @@ -426,8 +409,8 @@ int ib_cmrc_open ( struct interface *xfer, struct ib_device *ibdev, cmrc->cq = ib_create_cq ( ibdev, IB_CMRC_NUM_CQES, &ib_cmrc_completion_ops ); if ( ! cmrc->cq ) { - DBGC ( cmrc, "CMRC %s %s could not create completion queue\n", - ibdev->name, cmrc->name ); + DBGC ( cmrc, "CMRC %p could not create completion queue\n", + cmrc ); rc = -ENOMEM; goto err_create_cq; } @@ -435,16 +418,14 @@ int ib_cmrc_open ( struct interface *xfer, struct ib_device *ibdev, /* Create queue pair */ cmrc->qp = ib_create_qp ( ibdev, IB_QPT_RC, IB_CMRC_NUM_SEND_WQES, cmrc->cq, IB_CMRC_NUM_RECV_WQES, cmrc->cq, - &ib_cmrc_queue_pair_ops, name ); + &ib_cmrc_queue_pair_ops ); if ( ! cmrc->qp ) { - DBGC ( cmrc, "CMRC %s %s could not create queue pair\n", - ibdev->name, cmrc->name ); + DBGC ( cmrc, "CMRC %p could not create queue pair\n", cmrc ); rc = -ENOMEM; goto err_create_qp; } ib_qp_set_ownerdata ( cmrc->qp, cmrc ); - DBGC ( cmrc, "CMRC %s %s using QPN %#lx\n", - ibdev->name, cmrc->name, cmrc->qp->qpn ); + DBGC ( cmrc, "CMRC %p using QPN %lx\n", cmrc, cmrc->qp->qpn ); /* Attach to parent interface, transfer reference (implicitly) * to our shutdown process, and return. diff --git a/roms/ipxe/src/net/infiniband/ib_mcast.c b/roms/ipxe/src/net/infiniband/ib_mcast.c index f7264287c..fc4ff7f0a 100644 --- a/roms/ipxe/src/net/infiniband/ib_mcast.c +++ b/roms/ipxe/src/net/infiniband/ib_mcast.c @@ -42,34 +42,26 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); * Generate multicast membership MAD * * @v ibdev Infiniband device - * @v av Address vector - * @v method Method (IB_MGMT_METHOD_SET or IB_MGMT_METHOD_DELETE) - * @v mask Additional component mask + * @v gid Multicast GID + * @v join Join (rather than leave) group * @v mad MAD to fill in */ -static void ib_mcast_mad ( struct ib_device *ibdev, - struct ib_address_vector *av, - unsigned int method, unsigned int mask, - union ib_mad *mad ) { +static void ib_mcast_mad ( struct ib_device *ibdev, union ib_gid *gid, + int join, union ib_mad *mad ) { struct ib_mad_sa *sa = &mad->sa; /* Construct multicast membership record request */ memset ( sa, 0, sizeof ( *sa ) ); sa->mad_hdr.mgmt_class = IB_MGMT_CLASS_SUBN_ADM; sa->mad_hdr.class_version = IB_SA_CLASS_VERSION; - sa->mad_hdr.method = method; + sa->mad_hdr.method = + ( join ? IB_MGMT_METHOD_SET : IB_MGMT_METHOD_DELETE ); sa->mad_hdr.attr_id = htons ( IB_SA_ATTR_MC_MEMBER_REC ); sa->sa_hdr.comp_mask[1] = htonl ( IB_SA_MCMEMBER_REC_MGID | IB_SA_MCMEMBER_REC_PORT_GID | - IB_SA_MCMEMBER_REC_JOIN_STATE | mask ); - sa->sa_data.mc_member_record.qkey = htonl ( av->qkey ); - sa->sa_data.mc_member_record.pkey = - htons ( ibdev->pkey | IB_PKEY_FULL ); - sa->sa_data.mc_member_record.rate_selector__rate = av->rate; - sa->sa_data.mc_member_record.sl__flow_label__hop_limit = - htonl ( av->sl << 28 ); - sa->sa_data.mc_member_record.scope__join_state = 0x01; - memcpy ( &sa->sa_data.mc_member_record.mgid, &av->gid, + IB_SA_MCMEMBER_REC_JOIN_STATE ); + sa->sa_data.mc_member_record.scope__join_state = 1; + memcpy ( &sa->sa_data.mc_member_record.mgid, gid, sizeof ( sa->sa_data.mc_member_record.mgid ) ); memcpy ( &sa->sa_data.mc_member_record.port_gid, &ibdev->gid, sizeof ( sa->sa_data.mc_member_record.port_gid ) ); @@ -83,45 +75,42 @@ static void ib_mcast_mad ( struct ib_device *ibdev, * @v madx Management transaction * @v rc Status code * @v mad Received MAD (or NULL on error) - * @v src Source address vector (or NULL on error) + * @v av Source address vector (or NULL on error) */ static void ib_mcast_complete ( struct ib_device *ibdev, struct ib_mad_interface *mi __unused, struct ib_mad_transaction *madx, int rc, union ib_mad *mad, - struct ib_address_vector *src __unused ) { + struct ib_address_vector *av __unused ) { struct ib_mc_membership *membership = ib_madx_get_ownerdata ( madx ); struct ib_queue_pair *qp = membership->qp; - struct ib_address_vector *av = membership->av; + union ib_gid *gid = &membership->gid; struct ib_mc_member_record *mc_member_record = &mad->sa.sa_data.mc_member_record; int joined; + unsigned long qkey; /* Report failures */ if ( ( rc == 0 ) && ( mad->hdr.status != htons ( IB_MGMT_STATUS_OK ) )) rc = -ENOTCONN; if ( rc != 0 ) { - DBGC ( ibdev, "IBDEV %s QPN %#lx join failed: %s\n", - ibdev->name, qp->qpn, strerror ( rc ) ); + DBGC ( ibdev, "IBDEV %p QPN %lx join failed: %s\n", + ibdev, qp->qpn, strerror ( rc ) ); goto out; } /* Extract values from MAD */ joined = ( mad->hdr.method == IB_MGMT_METHOD_GET_RESP ); - av->qkey = ntohl ( mc_member_record->qkey ); - av->lid = ntohs ( mc_member_record->mlid ); - av->rate = ( mc_member_record->rate_selector__rate & 0x3f ); - av->sl = ( ( ntohl ( mc_member_record->sl__flow_label__hop_limit ) - >> 28 ) & 0x0f ); - DBGC ( ibdev, "IBDEV %s QPN %#lx %s " IB_GID_FMT " qkey %#lx\n", - ibdev->name, qp->qpn, ( joined ? "joined" : "left" ), - IB_GID_ARGS ( &av->gid ), av->qkey ); + qkey = ntohl ( mc_member_record->qkey ); + DBGC ( ibdev, "IBDEV %p QPN %lx %s " IB_GID_FMT " qkey %lx\n", + ibdev, qp->qpn, ( joined ? "joined" : "left" ), + IB_GID_ARGS ( gid ), qkey ); /* Set queue key */ - qp->qkey = av->qkey; + qp->qkey = qkey; if ( ( rc = ib_modify_qp ( ibdev, qp ) ) != 0 ) { - DBGC ( ibdev, "IBDEV %s QPN %#lx could not modify qkey: %s\n", - ibdev->name, qp->qpn, strerror ( rc ) ); + DBGC ( ibdev, "IBDEV %p QPN %lx could not modify qkey: %s\n", + ibdev, qp->qpn, strerror ( rc ) ); goto out; } @@ -131,7 +120,7 @@ static void ib_mcast_complete ( struct ib_device *ibdev, membership->madx = NULL; /* Hand off to upper completion handler */ - membership->complete ( membership, rc ); + membership->complete ( ibdev, qp, membership, rc, mad ); } /** Multicast membership management transaction completion operations */ @@ -145,45 +134,44 @@ static struct ib_mad_transaction_operations ib_mcast_op = { * @v ibdev Infiniband device * @v qp Queue pair * @v membership Multicast group membership - * @v av Address vector to fill in + * @v gid Multicast GID to join * @v joined Join completion handler * @ret rc Return status code */ int ib_mcast_join ( struct ib_device *ibdev, struct ib_queue_pair *qp, - struct ib_mc_membership *membership, - struct ib_address_vector *av, unsigned int mask, - void ( * complete ) ( struct ib_mc_membership *membership, - int rc ) ) { + struct ib_mc_membership *membership, union ib_gid *gid, + void ( * complete ) ( struct ib_device *ibdev, + struct ib_queue_pair *qp, + struct ib_mc_membership *membership, + int rc, union ib_mad *mad ) ) { union ib_mad mad; int rc; - DBGC ( ibdev, "IBDEV %s QPN %#lx joining " IB_GID_FMT "\n", - ibdev->name, qp->qpn, IB_GID_ARGS ( &av->gid ) ); + DBGC ( ibdev, "IBDEV %p QPN %lx joining " IB_GID_FMT "\n", + ibdev, qp->qpn, IB_GID_ARGS ( gid ) ); - /* Sanity checks */ + /* Sanity check */ assert ( qp != NULL ); - assert ( ! membership->attached ); /* Initialise structure */ membership->qp = qp; - membership->av = av; + memcpy ( &membership->gid, gid, sizeof ( membership->gid ) ); membership->complete = complete; /* Attach queue pair to multicast GID */ - if ( ( rc = ib_mcast_attach ( ibdev, qp, &av->gid ) ) != 0 ) { - DBGC ( ibdev, "IBDEV %s QPN %#lx could not attach: %s\n", - ibdev->name, qp->qpn, strerror ( rc ) ); + if ( ( rc = ib_mcast_attach ( ibdev, qp, gid ) ) != 0 ) { + DBGC ( ibdev, "IBDEV %p QPN %lx could not attach: %s\n", + ibdev, qp->qpn, strerror ( rc ) ); goto err_mcast_attach; } - membership->attached = 1; /* Initiate multicast membership join */ - ib_mcast_mad ( ibdev, av, IB_MGMT_METHOD_SET, mask, &mad ); + ib_mcast_mad ( ibdev, gid, 1, &mad ); membership->madx = ib_create_madx ( ibdev, ibdev->gsi, &mad, NULL, &ib_mcast_op ); if ( ! membership->madx ) { - DBGC ( ibdev, "IBDEV %s QPN %#lx could not create join " - "transaction\n", ibdev->name, qp->qpn ); + DBGC ( ibdev, "IBDEV %p QPN %lx could not create join " + "transaction\n", ibdev, qp->qpn ); rc = -ENOMEM; goto err_create_madx; } @@ -193,8 +181,7 @@ int ib_mcast_join ( struct ib_device *ibdev, struct ib_queue_pair *qp, ib_destroy_madx ( ibdev, ibdev->gsi, membership->madx ); err_create_madx: - ib_mcast_detach ( ibdev, qp, &av->gid ); - membership->attached = 0; + ib_mcast_detach ( ibdev, qp, gid ); err_mcast_attach: return rc; } @@ -208,23 +195,18 @@ int ib_mcast_join ( struct ib_device *ibdev, struct ib_queue_pair *qp, */ void ib_mcast_leave ( struct ib_device *ibdev, struct ib_queue_pair *qp, struct ib_mc_membership *membership ) { - struct ib_address_vector *av = membership->av; + union ib_gid *gid = &membership->gid; union ib_mad mad; int rc; - /* Do nothing if we are already detached from the multicast GID */ - if ( ! membership->attached ) - return; - - DBGC ( ibdev, "IBDEV %s QPN %#lx leaving " IB_GID_FMT "\n", - ibdev->name, qp->qpn, IB_GID_ARGS ( &av->gid ) ); + DBGC ( ibdev, "IBDEV %p QPN %lx leaving " IB_GID_FMT "\n", + ibdev, qp->qpn, IB_GID_ARGS ( gid ) ); /* Sanity check */ assert ( qp != NULL ); /* Detach from multicast GID */ - ib_mcast_detach ( ibdev, qp, &av->gid ); - membership->attached = 0; + ib_mcast_detach ( ibdev, qp, &membership->gid ); /* Cancel multicast membership join, if applicable */ if ( membership->madx ) { @@ -233,9 +215,9 @@ void ib_mcast_leave ( struct ib_device *ibdev, struct ib_queue_pair *qp, } /* Send a single group leave MAD */ - ib_mcast_mad ( ibdev, av, IB_MGMT_METHOD_DELETE, 0, &mad ); + ib_mcast_mad ( ibdev, &membership->gid, 0, &mad ); if ( ( rc = ib_mi_send ( ibdev, ibdev->gsi, &mad, NULL ) ) != 0 ) { - DBGC ( ibdev, "IBDEV %s QPN %#lx could not send leave request: " - "%s\n", ibdev->name, qp->qpn, strerror ( rc ) ); + DBGC ( ibdev, "IBDEV %p QPN %lx could not send leave request: " + "%s\n", ibdev, qp->qpn, strerror ( rc ) ); } } diff --git a/roms/ipxe/src/net/infiniband/ib_mi.c b/roms/ipxe/src/net/infiniband/ib_mi.c index 548a1c829..b43212974 100644 --- a/roms/ipxe/src/net/infiniband/ib_mi.c +++ b/roms/ipxe/src/net/infiniband/ib_mi.c @@ -106,7 +106,7 @@ static int ib_mi_handle ( struct ib_device *ibdev, /* Otherwise, ignore it */ DBGC ( mi, "MI %p RX TID %08x%08x ignored\n", - mi, ntohl ( hdr->tid.high ), ntohl ( hdr->tid.low ) ); + mi, ntohl ( hdr->tid[0] ), ntohl ( hdr->tid[1] ) ); return -ENOTSUP; } @@ -152,7 +152,7 @@ static void ib_mi_complete_recv ( struct ib_device *ibdev, goto out; } DBGC ( mi, "MI %p RX TID %08x%08x (%02x,%02x,%02x,%04x) status " - "%04x\n", mi, ntohl ( hdr->tid.high ), ntohl ( hdr->tid.low ), + "%04x\n", mi, ntohl ( hdr->tid[0] ), ntohl ( hdr->tid[1] ), hdr->mgmt_class, hdr->class_version, hdr->method, ntohs ( hdr->attr_id ), ntohs ( hdr->status ) ); DBGC2_HDA ( mi, 0, mad, sizeof ( *mad ) ); @@ -192,12 +192,12 @@ int ib_mi_send ( struct ib_device *ibdev, struct ib_mad_interface *mi, /* Set common fields */ hdr->base_version = IB_MGMT_BASE_VERSION; - if ( ( hdr->tid.high == 0 ) && ( hdr->tid.low == 0 ) ) { - hdr->tid.high = htonl ( IB_MI_TID_MAGIC ); - hdr->tid.low = htonl ( ++next_tid ); + if ( ( hdr->tid[0] == 0 ) && ( hdr->tid[1] == 0 ) ) { + hdr->tid[0] = htonl ( IB_MI_TID_MAGIC ); + hdr->tid[1] = htonl ( ++next_tid ); } DBGC ( mi, "MI %p TX TID %08x%08x (%02x,%02x,%02x,%04x) status " - "%04x\n", mi, ntohl ( hdr->tid.high ), ntohl ( hdr->tid.low ), + "%04x\n", mi, ntohl ( hdr->tid[0] ), ntohl ( hdr->tid[1] ), hdr->mgmt_class, hdr->class_version, hdr->method, ntohs ( hdr->attr_id ), ntohs ( hdr->status ) ); DBGC2_HDA ( mi, 0, mad, sizeof ( *mad ) ); @@ -217,8 +217,8 @@ int ib_mi_send ( struct ib_device *ibdev, struct ib_mad_interface *mi, smp->return_path.hops[hop_pointer] = ibdev->port; } else { DBGC ( mi, "MI %p TX TID %08x%08x invalid hop pointer " - "%d\n", mi, ntohl ( hdr->tid.high ), - ntohl ( hdr->tid.low ), hop_pointer ); + "%d\n", mi, ntohl ( hdr->tid[0] ), + ntohl ( hdr->tid[1] ), hop_pointer ); return -EINVAL; } } @@ -228,7 +228,7 @@ int ib_mi_send ( struct ib_device *ibdev, struct ib_mad_interface *mi, if ( ! iobuf ) { DBGC ( mi, "MI %p could not allocate buffer for TID " "%08x%08x\n", - mi, ntohl ( hdr->tid.high ), ntohl ( hdr->tid.low ) ); + mi, ntohl ( hdr->tid[0] ), ntohl ( hdr->tid[1] ) ); return -ENOMEM; } memcpy ( iob_put ( iobuf, sizeof ( *mad ) ), mad, sizeof ( *mad ) ); @@ -236,7 +236,7 @@ int ib_mi_send ( struct ib_device *ibdev, struct ib_mad_interface *mi, /* Send I/O buffer */ if ( ( rc = ib_post_send ( ibdev, mi->qp, av, iobuf ) ) != 0 ) { DBGC ( mi, "MI %p TX TID %08x%08x failed: %s\n", - mi, ntohl ( hdr->tid.high ), ntohl ( hdr->tid.low ), + mi, ntohl ( hdr->tid[0] ), ntohl ( hdr->tid[1] ), strerror ( rc ) ); free_iob ( iobuf ); return rc; @@ -261,7 +261,7 @@ static void ib_mi_timer_expired ( struct retry_timer *timer, int expired ) { /* Abandon transaction if we have tried too many times */ if ( expired ) { DBGC ( mi, "MI %p abandoning TID %08x%08x\n", - mi, ntohl ( hdr->tid.high ), ntohl ( hdr->tid.low ) ); + mi, ntohl ( hdr->tid[0] ), ntohl ( hdr->tid[1] ) ); madx->op->complete ( ibdev, mi, madx, -ETIMEDOUT, NULL, NULL ); return; } @@ -346,7 +346,6 @@ void ib_destroy_madx ( struct ib_device *ibdev __unused, struct ib_mad_interface * ib_create_mi ( struct ib_device *ibdev, enum ib_queue_pair_type type ) { struct ib_mad_interface *mi; - const char *name; int rc; /* Allocate and initialise fields */ @@ -364,17 +363,16 @@ struct ib_mad_interface * ib_create_mi ( struct ib_device *ibdev, } /* Create queue pair */ - name = ( ( type == IB_QPT_SMI ) ? "SMI" : "GSI" ); mi->qp = ib_create_qp ( ibdev, type, IB_MI_NUM_SEND_WQES, mi->cq, IB_MI_NUM_RECV_WQES, mi->cq, - &ib_mi_queue_pair_ops, name ); + &ib_mi_queue_pair_ops ); if ( ! mi->qp ) { DBGC ( mi, "MI %p could not allocate queue pair\n", mi ); goto err_create_qp; } ib_qp_set_ownerdata ( mi->qp, mi ); DBGC ( mi, "MI %p (%s) running on QPN %#lx\n", - mi, mi->qp->name, mi->qp->qpn ); + mi, ( ( type == IB_QPT_SMI ) ? "SMI" : "GSI" ), mi->qp->qpn ); /* Set queue key */ mi->qp->qkey = ( ( type == IB_QPT_SMI ) ? IB_QKEY_SMI : IB_QKEY_GSI ); @@ -410,8 +408,8 @@ void ib_destroy_mi ( struct ib_device *ibdev, struct ib_mad_interface *mi ) { /* Flush any outstanding requests */ list_for_each_entry_safe ( madx, tmp, &mi->madx, list ) { DBGC ( mi, "MI %p destroyed while TID %08x%08x in progress\n", - mi, ntohl ( madx->mad.hdr.tid.high ), - ntohl ( madx->mad.hdr.tid.low ) ); + mi, ntohl ( madx->mad.hdr.tid[0] ), + ntohl ( madx->mad.hdr.tid[1] ) ); madx->op->complete ( ibdev, mi, madx, -ECANCELED, NULL, NULL ); } diff --git a/roms/ipxe/src/net/infiniband/ib_packet.c b/roms/ipxe/src/net/infiniband/ib_packet.c index 8169925f1..d3a22d309 100644 --- a/roms/ipxe/src/net/infiniband/ib_packet.c +++ b/roms/ipxe/src/net/infiniband/ib_packet.c @@ -63,8 +63,8 @@ int ib_push ( struct ib_device *ibdev, struct io_buffer *iobuf, unsigned int vl; unsigned int lnh; - DBGC2 ( ibdev, "IBDEV %s TX %04x:%08lx => %04x:%08lx (key %08lx)\n", - ibdev->name, ibdev->lid, qp->ext_qpn, dest->lid, dest->qpn, + DBGC2 ( ibdev, "IBDEV %p TX %04x:%08lx => %04x:%08lx (key %08lx)\n", + ibdev, ibdev->lid, qp->ext_qpn, dest->lid, dest->qpn, dest->qkey ); /* Calculate packet length */ @@ -152,8 +152,8 @@ int ib_pull ( struct ib_device *ibdev, struct io_buffer *iobuf, /* Extract LRH */ if ( iob_len ( iobuf ) < sizeof ( *lrh ) ) { - DBGC ( ibdev, "IBDEV %s RX too short (%zd bytes) for LRH\n", - ibdev->name, iob_len ( iobuf ) ); + DBGC ( ibdev, "IBDEV %p RX too short (%zd bytes) for LRH\n", + ibdev, iob_len ( iobuf ) ); return -EINVAL; } lrh = iobuf->data; @@ -166,16 +166,16 @@ int ib_pull ( struct ib_device *ibdev, struct io_buffer *iobuf, /* Reject unsupported packets */ if ( ! ( ( lnh == IB_LNH_BTH ) || ( lnh == IB_LNH_GRH ) ) ) { - DBGC ( ibdev, "IBDEV %s RX unsupported LNH %x\n", - ibdev->name, lnh ); + DBGC ( ibdev, "IBDEV %p RX unsupported LNH %x\n", + ibdev, lnh ); return -ENOTSUP; } /* Extract GRH, if present */ if ( lnh == IB_LNH_GRH ) { if ( iob_len ( iobuf ) < sizeof ( *grh ) ) { - DBGC ( ibdev, "IBDEV %s RX too short (%zd bytes) " - "for GRH\n", ibdev->name, iob_len ( iobuf ) ); + DBGC ( ibdev, "IBDEV %p RX too short (%zd bytes) " + "for GRH\n", ibdev, iob_len ( iobuf ) ); return -EINVAL; } grh = iobuf->data; @@ -190,23 +190,23 @@ int ib_pull ( struct ib_device *ibdev, struct io_buffer *iobuf, /* Extract BTH */ if ( iob_len ( iobuf ) < sizeof ( *bth ) ) { - DBGC ( ibdev, "IBDEV %s RX too short (%zd bytes) for BTH\n", - ibdev->name, iob_len ( iobuf ) ); + DBGC ( ibdev, "IBDEV %p RX too short (%zd bytes) for BTH\n", + ibdev, iob_len ( iobuf ) ); return -EINVAL; } bth = iobuf->data; iob_pull ( iobuf, sizeof ( *bth ) ); if ( bth->opcode != BTH_OPCODE_UD_SEND ) { - DBGC ( ibdev, "IBDEV %s unsupported BTH opcode %x\n", - ibdev->name, bth->opcode ); + DBGC ( ibdev, "IBDEV %p unsupported BTH opcode %x\n", + ibdev, bth->opcode ); return -ENOTSUP; } dest->qpn = ntohl ( bth->dest_qp ); /* Extract DETH */ if ( iob_len ( iobuf ) < sizeof ( *deth ) ) { - DBGC ( ibdev, "IBDEV %s RX too short (%zd bytes) for DETH\n", - ibdev->name, iob_len ( iobuf ) ); + DBGC ( ibdev, "IBDEV %p RX too short (%zd bytes) for DETH\n", + ibdev, iob_len ( iobuf ) ); return -EINVAL; } deth = iobuf->data; @@ -226,25 +226,24 @@ int ib_pull ( struct ib_device *ibdev, struct io_buffer *iobuf, if ( qp ) { if ( IB_LID_MULTICAST ( dest->lid ) && grh ) { if ( ! ( *qp = ib_find_qp_mgid ( ibdev, &grh->dgid ))){ - DBGC ( ibdev, "IBDEV %s RX for unknown MGID " - IB_GID_FMT "\n", ibdev->name, - IB_GID_ARGS ( &grh->dgid ) ); + DBGC ( ibdev, "IBDEV %p RX for unknown MGID " + IB_GID_FMT "\n", + ibdev, IB_GID_ARGS ( &grh->dgid ) ); return -ENODEV; } } else { if ( ! ( *qp = ib_find_qp_qpn ( ibdev, dest->qpn ) ) ) { - DBGC ( ibdev, "IBDEV %s RX for nonexistent " - "QPN %#lx\n", ibdev->name, dest->qpn ); + DBGC ( ibdev, "IBDEV %p RX for nonexistent " + "QPN %lx\n", ibdev, dest->qpn ); return -ENODEV; } } assert ( *qp ); } - DBGC2 ( ibdev, "IBDEV %s RX %04x:%08lx <= %04x:%08lx (key %08x)\n", - ibdev->name, dest->lid, - ( IB_LID_MULTICAST ( dest->lid ) ? - ( qp ? (*qp)->ext_qpn : -1UL ) : dest->qpn ), + DBGC2 ( ibdev, "IBDEV %p RX %04x:%08lx <= %04x:%08lx (key %08x)\n", + ibdev, dest->lid, ( IB_LID_MULTICAST ( dest->lid ) ? + ( qp ? (*qp)->ext_qpn : -1UL ) : dest->qpn ), source->lid, source->qpn, ntohl ( deth->qkey ) ); DBGCP_HDA ( ibdev, 0, ( iobuf->data - ( orig_iob_len - iob_len ( iobuf ) ) ), diff --git a/roms/ipxe/src/net/infiniband/ib_pathrec.c b/roms/ipxe/src/net/infiniband/ib_pathrec.c index f846710f2..f9cbab87f 100644 --- a/roms/ipxe/src/net/infiniband/ib_pathrec.c +++ b/roms/ipxe/src/net/infiniband/ib_pathrec.c @@ -61,9 +61,9 @@ static void ib_path_complete ( struct ib_device *ibdev, if ( ( rc == 0 ) && ( mad->hdr.status != htons ( IB_MGMT_STATUS_OK ) )) rc = -ENETUNREACH; if ( rc != 0 ) { - DBGC ( ibdev, "IBDEV %s path lookup for " IB_GID_FMT + DBGC ( ibdev, "IBDEV %p path lookup for " IB_GID_FMT " failed: %s\n", - ibdev->name, IB_GID_ARGS ( dgid ), strerror ( rc ) ); + ibdev, IB_GID_ARGS ( dgid ), strerror ( rc ) ); goto out; } @@ -71,15 +71,9 @@ static void ib_path_complete ( struct ib_device *ibdev, path->av.lid = ntohs ( pathrec->dlid ); path->av.sl = ( pathrec->reserved__sl & 0x0f ); path->av.rate = ( pathrec->rate_selector__rate & 0x3f ); - DBGC ( ibdev, "IBDEV %s path to " IB_GID_FMT " lid %d sl %d rate " - "%d\n", ibdev->name, IB_GID_ARGS ( dgid ), path->av.lid, - path->av.sl, path->av.rate ); - - /* Use only the LID if no GRH is needed for this path */ - if ( memcmp ( &path->av.gid.s.prefix, &ibdev->gid.s.prefix, - sizeof ( path->av.gid.s.prefix ) ) == 0 ) { - path->av.gid_present = 0; - } + DBGC ( ibdev, "IBDEV %p path to " IB_GID_FMT " is %04x sl %d rate " + "%d\n", ibdev, IB_GID_ARGS ( dgid ), path->av.lid, path->av.sl, + path->av.rate ); out: /* Destroy the completed transaction */ @@ -251,6 +245,13 @@ int ib_resolve_path ( struct ib_device *ibdev, struct ib_address_vector *av ) { struct ib_cached_path *cached; unsigned int cache_idx; + /* Sanity check */ + if ( ! av->gid_present ) { + DBGC ( ibdev, "IBDEV %p attempt to look up path without GID\n", + ibdev ); + return -EINVAL; + } + /* Look in cache for a matching entry */ cached = ib_find_path_cache_entry ( ibdev, gid ); if ( cached && cached->path->av.lid ) { @@ -258,12 +259,11 @@ int ib_resolve_path ( struct ib_device *ibdev, struct ib_address_vector *av ) { av->lid = cached->path->av.lid; av->rate = cached->path->av.rate; av->sl = cached->path->av.sl; - av->gid_present = cached->path->av.gid_present; - DBGC2 ( ibdev, "IBDEV %s cache hit for " IB_GID_FMT "\n", - ibdev->name, IB_GID_ARGS ( gid ) ); + DBGC2 ( ibdev, "IBDEV %p cache hit for " IB_GID_FMT "\n", + ibdev, IB_GID_ARGS ( gid ) ); return 0; } - DBGC ( ibdev, "IBDEV %s cache miss for " IB_GID_FMT "%s\n", ibdev->name, + DBGC ( ibdev, "IBDEV %p cache miss for " IB_GID_FMT "%s\n", ibdev, IB_GID_ARGS ( gid ), ( cached ? " (in progress)" : "" ) ); /* If lookup is already in progress, do nothing */ @@ -282,8 +282,8 @@ int ib_resolve_path ( struct ib_device *ibdev, struct ib_address_vector *av ) { /* Create new path */ cached->path = ib_create_path ( ibdev, av, &ib_cached_path_op ); if ( ! cached->path ) { - DBGC ( ibdev, "IBDEV %s could not create path\n", - ibdev->name ); + DBGC ( ibdev, "IBDEV %p could not create path\n", + ibdev ); return -ENOMEM; } ib_path_set_ownerdata ( cached->path, cached ); diff --git a/roms/ipxe/src/net/infiniband/ib_service.c b/roms/ipxe/src/net/infiniband/ib_service.c deleted file mode 100644 index f035382ee..000000000 --- a/roms/ipxe/src/net/infiniband/ib_service.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2016 Michael Brown <mbrown@fensystems.co.uk>. - * - * 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 <string.h> -#include <stdio.h> -#include <byteswap.h> -#include <ipxe/infiniband.h> -#include <ipxe/ib_mi.h> -#include <ipxe/ib_service.h> - -/** @file - * - * Infiniband service records - * - */ - -/** - * Create service record management transaction - * - * @v ibdev Infiniband device - * @v mi Management interface - * @v name Service name - * @v op Management transaction operations - * @ret madx Management transaction, or NULL on error - */ -struct ib_mad_transaction * -ib_create_service_madx ( struct ib_device *ibdev, - struct ib_mad_interface *mi, const char *name, - struct ib_mad_transaction_operations *op ) { - union ib_mad mad; - struct ib_mad_sa *sa = &mad.sa; - struct ib_service_record *svc = &sa->sa_data.service_record; - - /* Construct service record request */ - memset ( sa, 0, sizeof ( *sa ) ); - sa->mad_hdr.mgmt_class = IB_MGMT_CLASS_SUBN_ADM; - sa->mad_hdr.class_version = IB_SA_CLASS_VERSION; - sa->mad_hdr.method = IB_MGMT_METHOD_GET; - sa->mad_hdr.attr_id = htons ( IB_SA_ATTR_SERVICE_REC ); - sa->sa_hdr.comp_mask[1] = htonl ( IB_SA_SERVICE_REC_NAME ); - snprintf ( svc->name, sizeof ( svc->name ), "%s", name ); - - /* Create management transaction */ - return ib_create_madx ( ibdev, mi, &mad, NULL, op ); -} diff --git a/roms/ipxe/src/net/infiniband/ib_sma.c b/roms/ipxe/src/net/infiniband/ib_sma.c index 24ec9f4e0..a05d7c924 100644 --- a/roms/ipxe/src/net/infiniband/ib_sma.c +++ b/roms/ipxe/src/net/infiniband/ib_sma.c @@ -176,9 +176,9 @@ static int ib_sma_set_port_info ( struct ib_device *ibdev, ( port_info->link_speed_active__link_speed_enabled & 0xf ) ) ) ibdev->link_speed_enabled = link_speed_enabled; ibdev->sm_sl = ( port_info->neighbour_mtu__mastersm_sl & 0xf ); - DBGC ( mi, "SMA %p set LID %d SMLID %d link width %d speed %d\n", - mi, ibdev->lid, ibdev->sm_lid, ibdev->link_width_enabled, - ibdev->link_speed_enabled ); + DBGC ( mi, "SMA %p set LID %04x SMLID %04x link width %02x speed " + "%02x\n", mi, ibdev->lid, ibdev->sm_lid, + ibdev->link_width_enabled, ibdev->link_speed_enabled ); /* Update parameters on device */ if ( ( rc = ib_set_port_info ( ibdev, mad ) ) != 0 ) { @@ -358,7 +358,7 @@ struct ib_mad_agent ib_sma_agent[] __ib_mad_agent = { int ib_create_sma ( struct ib_device *ibdev, struct ib_mad_interface *mi ) { /* Nothing to do */ - DBGC ( ibdev, "IBDEV %s SMA using SMI %p\n", ibdev->name, mi ); + DBGC ( ibdev, "IBDEV %p SMA using SMI %p\n", ibdev, mi ); return 0; } diff --git a/roms/ipxe/src/net/infiniband/ib_smc.c b/roms/ipxe/src/net/infiniband/ib_smc.c index 5de7deba2..c1741b26c 100644 --- a/roms/ipxe/src/net/infiniband/ib_smc.c +++ b/roms/ipxe/src/net/infiniband/ib_smc.c @@ -86,8 +86,8 @@ static int ib_smc_get_node_info ( struct ib_device *ibdev, /* Issue MAD */ if ( ( rc = ib_smc_mad ( ibdev, htons ( IB_SMP_ATTR_NODE_INFO ), 0, local_mad, mad ) ) != 0 ) { - DBGC ( ibdev, "IBDEV %s could not get node info: %s\n", - ibdev->name, strerror ( rc ) ); + DBGC ( ibdev, "IBDEV %p could not get node info: %s\n", + ibdev, strerror ( rc ) ); return rc; } return 0; @@ -109,8 +109,8 @@ static int ib_smc_get_port_info ( struct ib_device *ibdev, /* Issue MAD */ if ( ( rc = ib_smc_mad ( ibdev, htons ( IB_SMP_ATTR_PORT_INFO ), htonl ( ibdev->port ), local_mad, mad )) !=0){ - DBGC ( ibdev, "IBDEV %s could not get port info: %s\n", - ibdev->name, strerror ( rc ) ); + DBGC ( ibdev, "IBDEV %p could not get port info: %s\n", + ibdev, strerror ( rc ) ); return rc; } return 0; @@ -132,8 +132,8 @@ static int ib_smc_get_guid_info ( struct ib_device *ibdev, /* Issue MAD */ if ( ( rc = ib_smc_mad ( ibdev, htons ( IB_SMP_ATTR_GUID_INFO ), 0, local_mad, mad ) ) != 0 ) { - DBGC ( ibdev, "IBDEV %s could not get GUID info: %s\n", - ibdev->name, strerror ( rc ) ); + DBGC ( ibdev, "IBDEV %p could not get GUID info: %s\n", + ibdev, strerror ( rc ) ); return rc; } return 0; @@ -155,8 +155,8 @@ static int ib_smc_get_pkey_table ( struct ib_device *ibdev, /* Issue MAD */ if ( ( rc = ib_smc_mad ( ibdev, htons ( IB_SMP_ATTR_PKEY_TABLE ), 0, local_mad, mad ) ) != 0 ) { - DBGC ( ibdev, "IBDEV %s could not get pkey table: %s\n", - ibdev->name, strerror ( rc ) ); + DBGC ( ibdev, "IBDEV %p could not get pkey table: %s\n", + ibdev, strerror ( rc ) ); return rc; } return 0; @@ -216,8 +216,8 @@ static int ib_smc_get ( struct ib_device *ibdev, ib_local_mad_t local_mad ) { return rc; ibdev->pkey = ntohs ( pkey_table->pkey[0] ); - DBGC ( ibdev, "IBDEV %s port GID is " IB_GID_FMT "\n", - ibdev->name, IB_GID_ARGS ( &ibdev->gid ) ); + DBGC ( ibdev, "IBDEV %p port GID is " IB_GID_FMT "\n", + ibdev, IB_GID_ARGS ( &ibdev->gid ) ); return 0; } diff --git a/roms/ipxe/src/net/infiniband/ib_srp.c b/roms/ipxe/src/net/infiniband/ib_srp.c index 3b4914abf..3700184c0 100644 --- a/roms/ipxe/src/net/infiniband/ib_srp.c +++ b/roms/ipxe/src/net/infiniband/ib_srp.c @@ -210,7 +210,7 @@ static int ib_srp_open ( struct interface *block, struct ib_device *ibdev, /* Open CMRC socket */ if ( ( rc = ib_cmrc_open ( &ib_srp->cmrc, ibdev, dgid, - service_id, "SRP" ) ) != 0 ) { + service_id ) ) != 0 ) { DBGC ( ib_srp, "IBSRP %p could not open CMRC socket: %s\n", ib_srp, strerror ( rc ) ); goto err_cmrc_open; diff --git a/roms/ipxe/src/net/infiniband/xsigo.c b/roms/ipxe/src/net/infiniband/xsigo.c deleted file mode 100644 index 91b7b71f1..000000000 --- a/roms/ipxe/src/net/infiniband/xsigo.c +++ /dev/null @@ -1,1858 +0,0 @@ -/* - * Copyright (C) 2016 Michael Brown <mbrown@fensystems.co.uk>. - * - * 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 <string.h> -#include <stdio.h> -#include <errno.h> -#include <byteswap.h> -#include <ipxe/version.h> -#include <ipxe/timer.h> -#include <ipxe/malloc.h> -#include <ipxe/iobuf.h> -#include <ipxe/retry.h> -#include <ipxe/process.h> -#include <ipxe/settings.h> -#include <ipxe/infiniband.h> -#include <ipxe/ib_service.h> -#include <ipxe/ib_cmrc.h> -#include <ipxe/if_ether.h> -#include <ipxe/ethernet.h> -#include <ipxe/eoib.h> -#include <ipxe/xsigo.h> - -/** @file - * - * Xsigo virtual Ethernet devices - * - */ - -/** A Xsigo device */ -struct xsigo_device { - /** Reference count */ - struct refcnt refcnt; - /** Underlying Infiniband device */ - struct ib_device *ibdev; - /** List of Xsigo devices */ - struct list_head list; - /** Device name */ - const char *name; - - /** Link opener timer */ - struct retry_timer opener; - - /** Discovery timer */ - struct retry_timer discovery; - /** Discovery management transaction (if any) */ - struct ib_mad_transaction *madx; - - /** List of configuration managers */ - struct list_head managers; -}; - -/** A Xsigo configuration manager */ -struct xsigo_manager { - /** Reference count */ - struct refcnt refcnt; - /** Xsigo device */ - struct xsigo_device *xdev; - /** List of managers */ - struct list_head list; - /** Device name */ - char name[16]; - /** Manager ID */ - struct xsigo_manager_id id; - - /** Data transfer interface */ - struct interface xfer; - /** Connection timer */ - struct retry_timer reopen; - /** Keepalive timer */ - struct retry_timer keepalive; - /** Transmission process */ - struct process process; - /** Pending transmissions */ - unsigned int pending; - /** Transmit sequence number */ - uint32_t seq; - - /** List of virtual Ethernet devices */ - struct list_head nics; -}; - -/** Configuration manager pending transmissions */ -enum xsigo_manager_pending { - /** Send connection request */ - XCM_TX_CONNECT = 0x0001, - /** Send registration message */ - XCM_TX_REGISTER = 0x0002, -}; - -/** A Xsigo virtual Ethernet device */ -struct xsigo_nic { - /** Configuration manager */ - struct xsigo_manager *xcm; - /** List of virtual Ethernet devices */ - struct list_head list; - /** Device name */ - char name[16]; - - /** Resource identifier */ - union ib_guid resource; - /** MAC address */ - uint8_t mac[ETH_ALEN]; - /** Network ID */ - unsigned long network; -}; - -/** Configuration manager service ID */ -static union ib_guid xcm_service_id = { - .bytes = XCM_SERVICE_ID, -}; - -/** List of all Xsigo devices */ -static LIST_HEAD ( xsigo_devices ); - -/** - * Free Xsigo device - * - * @v refcnt Reference count - */ -static void xsigo_free ( struct refcnt *refcnt ) { - struct xsigo_device *xdev = - container_of ( refcnt, struct xsigo_device, refcnt ); - - /* Sanity checks */ - assert ( ! timer_running ( &xdev->opener ) ); - assert ( ! timer_running ( &xdev->discovery ) ); - assert ( xdev->madx == NULL ); - assert ( list_empty ( &xdev->managers ) ); - - /* Drop reference to Infiniband device */ - ibdev_put ( xdev->ibdev ); - - /* Free device */ - free ( xdev ); -} - -/** - * Free configuration manager - * - * @v refcnt Reference count - */ -static void xcm_free ( struct refcnt *refcnt ) { - struct xsigo_manager *xcm = - container_of ( refcnt, struct xsigo_manager, refcnt ); - - /* Sanity checks */ - assert ( ! timer_running ( &xcm->reopen ) ); - assert ( ! timer_running ( &xcm->keepalive ) ); - assert ( ! process_running ( &xcm->process ) ); - assert ( list_empty ( &xcm->nics ) ); - - /* Drop reference to Xsigo device */ - ref_put ( &xcm->xdev->refcnt ); - - /* Free manager */ - free ( xcm ); -} - -/**************************************************************************** - * - * Virtual Ethernet (XVE) devices - * - **************************************************************************** - */ - -/** - * Create virtual Ethernet device - * - * @v xcm Configuration manager - * @v resource Resource identifier - * @v mac Ethernet MAC - * @v network Network identifier - * @v name Device name - * @ret rc Return status code - */ -static int xve_create ( struct xsigo_manager *xcm, union ib_guid *resource, - const uint8_t *mac, unsigned long network, - unsigned long qkey, const char *name ) { - struct xsigo_device *xdev = xcm->xdev; - struct ib_device *ibdev = xdev->ibdev; - struct xsigo_nic *xve; - struct ib_address_vector broadcast; - int rc; - - /* Allocate and initialise structure */ - xve = zalloc ( sizeof ( *xve ) ); - if ( ! xve ) { - rc = -ENOMEM; - goto err_alloc; - } - xve->xcm = xcm; - snprintf ( xve->name, sizeof ( xve->name ), "%s", name ); - memcpy ( &xve->resource, resource, sizeof ( xve->resource ) ); - memcpy ( xve->mac, mac, ETH_ALEN ); - xve->network = network; - DBGC ( xve, "XVE %s created for %s " IB_GUID_FMT "\n", - xve->name, xcm->name, IB_GUID_ARGS ( resource ) ); - DBGC ( xve, "XVE %s is MAC %s on network %ld\n", - xve->name, eth_ntoa ( mac ), network ); - - /* Construct broadcast address vector */ - memset ( &broadcast, 0, sizeof ( broadcast ) ); - broadcast.qpn = IB_QPN_BROADCAST; - broadcast.qkey = qkey; - broadcast.gid_present = 1; - broadcast.gid.dwords[0] = htonl ( XVE_PREFIX ); - broadcast.gid.words[2] = htons ( ibdev->pkey ); - broadcast.gid.dwords[3] = htonl ( network ); - - /* Create EoIB device */ - if ( ( rc = eoib_create ( ibdev, xve->mac, &broadcast, - xve->name ) ) != 0 ) { - DBGC ( xve, "XVE %s could not create EoIB device: %s\n", - xve->name, strerror ( rc ) ); - goto err_create; - } - - /* Add to list of virtual Ethernet devices. Do this only - * after creating the EoIB device, so that our net device - * notifier won't attempt to send an operational state update - * before we have acknowledged the installation. - */ - list_add ( &xve->list, &xcm->nics ); - - return 0; - - list_del ( &xve->list ); - err_create: - free ( xve ); - err_alloc: - return rc; -} - -/** - * Find virtual Ethernet device - * - * @v xcm Configuration manager - * @v resource Resource identifier - * @ret xve Virtual Ethernet device, or NULL - */ -static struct xsigo_nic * xve_find ( struct xsigo_manager *xcm, - union ib_guid *resource ) { - struct xsigo_nic *xve; - - list_for_each_entry ( xve, &xcm->nics, list ) { - if ( memcmp ( resource, &xve->resource, - sizeof ( *resource ) ) == 0 ) - return xve; - } - return NULL; -} - -/** - * Destroy virtual Ethernet device - * - * @v xve Virtual Ethernet device - */ -static void xve_destroy ( struct xsigo_nic *xve ) { - struct xsigo_manager *xcm = xve->xcm; - struct xsigo_device *xdev = xcm->xdev; - struct ib_device *ibdev = xdev->ibdev; - struct eoib_device *eoib; - - /* Destroy corresponding EoIB device, if any */ - if ( ( eoib = eoib_find ( ibdev, xve->mac ) ) ) - eoib_destroy ( eoib ); - - /* Remove from list of virtual Ethernet devices */ - list_del ( &xve->list ); - - /* Free virtual Ethernet device */ - DBGC ( xve, "XVE %s destroyed\n", xve->name ); - free ( xve ); -} - -/** - * Update virtual Ethernet device MTU - * - * @v xve Virtual Ethernet device - * @v eoib EoIB device - * @v mtu New MTU (excluding Ethernet and EoIB headers) - * @ret rc Return status code - */ -static int xve_update_mtu ( struct xsigo_nic *xve, struct eoib_device *eoib, - size_t mtu ) { - struct net_device *netdev = eoib->netdev; - size_t max; - - /* Check that we can support this MTU */ - max = ( IB_MAX_PAYLOAD_SIZE - ( sizeof ( struct ethhdr ) + - sizeof ( struct eoib_header ) ) ); - if ( mtu > max ) { - DBGC ( xve, "XVE %s cannot support MTU %zd (max %zd)\n", - xve->name, mtu, max ); - return -ERANGE; - } - - /* Update MTU. No need to close/reopen the network device, - * since our Infiniband stack uses a fixed MTU anyway. Note - * that the network device sees the Ethernet frame header but - * not the EoIB header. - */ - netdev->max_pkt_len = ( mtu + sizeof ( struct ethhdr ) ); - DBGC ( xve, "XVE %s has MTU %zd\n", xve->name, mtu ); - - return 0; -} - -/** - * Open virtual Ethernet device - * - * @v xve Virtual Ethernet device - * @v eoib EoIB device - * @v open New administrative state - * @ret rc Return status code - */ -static int xve_open ( struct xsigo_nic *xve, struct eoib_device *eoib ) { - struct net_device *netdev = eoib->netdev; - int rc; - - /* Do nothing if network device is already open */ - if ( netdev_is_open ( netdev ) ) - return 0; - DBGC ( xve, "XVE %s opening network device\n", xve->name ); - - /* Open network device */ - if ( ( rc = netdev_open ( netdev ) ) != 0 ) { - DBGC ( xve, "XVE %s could not open: %s\n", - xve->name, strerror ( rc ) ); - return rc; - } - - return 0; -} - -/** - * Close virtual Ethernet device - * - * @v xve Virtual Ethernet device - * @v eoib EoIB device - */ -static void xve_close ( struct xsigo_nic *xve, struct eoib_device *eoib ) { - struct net_device *netdev = eoib->netdev; - - /* Do nothing if network device is already closed */ - if ( ! netdev_is_open ( netdev ) ) - return; - - /* Close network device */ - netdev_close ( netdev ); - DBGC ( xve, "XVE %s closed network device\n", xve->name ); -} - -/** - * Update virtual Ethernet device administrative state - * - * @v xve Virtual Ethernet device - * @v eoib EoIB device - * @v open New administrative state - * @ret rc Return status code - */ -static int xve_update_state ( struct xsigo_nic *xve, struct eoib_device *eoib, - int open ) { - - /* Open or close device, as applicable */ - if ( open ) { - return xve_open ( xve, eoib ); - } else { - xve_close ( xve, eoib ); - return 0; - } -} - -/** - * Update gateway (TCA) - * - * @v xve Virtual Ethernet device - * @v eoib EoIB device - * @v av Address vector, or NULL if no gateway - * @ret rc Return status code - */ -static int xve_update_tca ( struct xsigo_nic *xve, struct eoib_device *eoib, - struct ib_address_vector *av ) { - - /* Update gateway address */ - eoib_set_gateway ( eoib, av ); - if ( av ) { - DBGC ( xve, "XVE %s has TCA " IB_GID_FMT " data %#lx qkey " - "%#lx\n", xve->name, IB_GID_ARGS ( &av->gid ), av->qpn, - av->qkey ); - } else { - DBGC ( xve, "XVE %s has no TCA\n", xve->name ); - } - - /* The Linux driver will modify the local device's link state - * to reflect the EoIB-to-Ethernet gateway's link state, but - * this seems philosophically incorrect since communication - * within the EoIB broadcast domain still works regardless of - * the state of the gateway. - */ - - return 0; -} - -/**************************************************************************** - * - * Server management protocol (XSMP) session messages - * - **************************************************************************** - */ - -/** - * Get session message name (for debugging) - * - * @v type Message type - * @ret name Message name - */ -static const char * xsmp_session_type ( unsigned int type ) { - static char buf[16]; - - switch ( type ) { - case XSMP_SESSION_TYPE_HELLO: return "HELLO"; - case XSMP_SESSION_TYPE_REGISTER: return "REGISTER"; - case XSMP_SESSION_TYPE_CONFIRM: return "CONFIRM"; - case XSMP_SESSION_TYPE_REJECT: return "REJECT"; - case XSMP_SESSION_TYPE_SHUTDOWN: return "SHUTDOWN"; - default: - snprintf ( buf, sizeof ( buf ), "UNKNOWN<%d>", type ); - return buf; - } -} - -/** - * Extract chassis name (for debugging) - * - * @v msg Session message - * @ret chassis Chassis name - */ -static const char * xsmp_chassis_name ( struct xsmp_session_message *msg ) { - static char chassis[ sizeof ( msg->chassis ) + 1 /* NUL */ ]; - - memcpy ( chassis, msg->chassis, sizeof ( msg->chassis ) ); - return chassis; -} - -/** - * Extract session name (for debugging) - * - * @v msg Session message - * @ret session Session name - */ -static const char * xsmp_session_name ( struct xsmp_session_message *msg ) { - static char session[ sizeof ( msg->session ) + 1 /* NUL */ ]; - - memcpy ( session, msg->session, sizeof ( msg->session ) ); - return session; -} - -/** - * Send session message - * - * @v xcm Configuration manager - * @v type Message type - * @ret rc Return status code - */ -static int xsmp_tx_session ( struct xsigo_manager *xcm, unsigned int type ) { - struct xsigo_device *xdev = xcm->xdev; - struct ib_device *ibdev = xdev->ibdev; - struct xsmp_session_message msg; - int rc; - - /* Construct session message */ - memset ( &msg, 0, sizeof ( msg ) ); - msg.hdr.type = XSMP_TYPE_SESSION; - msg.hdr.len = htons ( sizeof ( msg ) ); - msg.hdr.seq = htonl ( ++xcm->seq ); - memcpy ( &msg.hdr.src.guid, &ibdev->gid.s.guid, - sizeof ( msg.hdr.src.guid ) ); - memcpy ( &msg.hdr.dst.guid, &xcm->id.guid, - sizeof ( msg.hdr.dst.guid ) ); - msg.type = type; - msg.len = htons ( sizeof ( msg ) - sizeof ( msg.hdr ) ); - msg.os_type = XSIGO_OS_TYPE_GENERIC; - msg.resources = htons ( XSIGO_RESOURCE_XVE | - XSIGO_RESOURCE_NO_HA ); - msg.boot = htonl ( XSMP_BOOT_PXE ); - DBGCP ( xcm, "XCM %s TX[%d] session %s\n", xcm->name, - ntohl ( msg.hdr.seq ), xsmp_session_type ( msg.type ) ); - DBGCP_HDA ( xcm, 0, &msg, sizeof ( msg ) ); - - /* Send session message */ - if ( ( rc = xfer_deliver_raw ( &xcm->xfer, &msg, - sizeof ( msg ) ) ) != 0 ) { - DBGC ( xcm, "XCM %s TX session %s failed: %s\n", xcm->name, - xsmp_session_type ( msg.type ), strerror ( rc ) ); - return rc; - } - - return 0; -} - -/** - * Send registration message - * - * @v xcm Configuration manager - * @ret rc Return status code - */ -static inline int xsmp_tx_session_register ( struct xsigo_manager *xcm ) { - - DBGC ( xcm, "XCM %s registering with " IB_GUID_FMT "\n", - xcm->name, IB_GUID_ARGS ( &xcm->id.guid ) ); - - /* Send registration message */ - return xsmp_tx_session ( xcm, XSMP_SESSION_TYPE_REGISTER ); -} - -/** - * Send keepalive message - * - * @v xcm Configuration manager - * @ret rc Return status code - */ -static int xsmp_tx_session_hello ( struct xsigo_manager *xcm ) { - - /* Send keepalive message */ - return xsmp_tx_session ( xcm, XSMP_SESSION_TYPE_HELLO ); -} - -/** - * Handle received keepalive message - * - * @v xcm Configuration manager - * @v msg Keepalive message - * @ret rc Return status code - */ -static int xsmp_rx_session_hello ( struct xsigo_manager *xcm, - struct xsmp_session_message *msg __unused ) { - - /* Respond to keepalive message. Note that the XCM doesn't - * seem to actually ever send these. - */ - return xsmp_tx_session_hello ( xcm ); -} - -/** - * Handle received registration confirmation message - * - * @v xcm Configuration manager - * @v msg Registration confirmation message - * @ret rc Return status code - */ -static int xsmp_rx_session_confirm ( struct xsigo_manager *xcm, - struct xsmp_session_message *msg ) { - - DBGC ( xcm, "XCM %s registered with \"%s\" as \"%s\"\n", xcm->name, - xsmp_chassis_name ( msg ), xsmp_session_name ( msg ) ); - - return 0; -} - -/** - * Handle received registration rejection message - * - * @v xcm Configuration manager - * @v msg Registration confirmation message - * @ret rc Return status code - */ -static int xsmp_rx_session_reject ( struct xsigo_manager *xcm, - struct xsmp_session_message *msg ) { - - DBGC ( xcm, "XCM %s rejected by \"%s\":\n", - xcm->name, xsmp_chassis_name ( msg ) ); - DBGC_HDA ( xcm, 0, msg, sizeof ( *msg ) ); - - return -EPERM; -} - -/** - * Handle received shutdown message - * - * @v xcm Configuration manager - * @v msg Registration confirmation message - * @ret rc Return status code - */ -static int xsmp_rx_session_shutdown ( struct xsigo_manager *xcm, - struct xsmp_session_message *msg ) { - - DBGC ( xcm, "XCM %s shut down by \"%s\":\n", - xcm->name, xsmp_chassis_name ( msg ) ); - DBGC_HDA ( xcm, 0, msg, sizeof ( *msg ) ); - - return -ENOTCONN; -} - -/** - * Handle received session message - * - * @v xcm Configuration manager - * @v msg Session message - * @ret rc Return status code - */ -static int xsmp_rx_session ( struct xsigo_manager *xcm, - struct xsmp_session_message *msg ) { - - DBGCP ( xcm, "XCM %s RX[%d] session %s\n", xcm->name, - ntohl ( msg->hdr.seq ), xsmp_session_type ( msg->type ) ); - DBGCP_HDA ( xcm, 0, msg, sizeof ( *msg ) ); - - /* Handle message according to type */ - switch ( msg->type ) { - case XSMP_SESSION_TYPE_HELLO: - return xsmp_rx_session_hello ( xcm, msg ); - case XSMP_SESSION_TYPE_CONFIRM: - return xsmp_rx_session_confirm ( xcm, msg ); - case XSMP_SESSION_TYPE_REJECT: - return xsmp_rx_session_reject ( xcm, msg ); - case XSMP_SESSION_TYPE_SHUTDOWN: - return xsmp_rx_session_shutdown ( xcm, msg ); - default: - DBGC ( xcm, "XCM %s RX[%d] session unexpected %s:\n", xcm->name, - ntohl ( msg->hdr.seq ), xsmp_session_type ( msg->type )); - DBGC_HDA ( xcm, 0, msg, sizeof ( *msg ) ); - return -EPROTO; - } -} - -/**************************************************************************** - * - * Server management protocol (XSMP) virtual Ethernet (XVE) messages - * - **************************************************************************** - */ - -/** - * Get virtual Ethernet message name (for debugging) - * - * @v type Message type - * @ret name Message name - */ -static const char * xsmp_xve_type ( unsigned int type ) { - static char buf[16]; - - switch ( type ) { - case XSMP_XVE_TYPE_INSTALL: return "INSTALL"; - case XSMP_XVE_TYPE_DELETE: return "DELETE"; - case XSMP_XVE_TYPE_UPDATE: return "UPDATE"; - case XSMP_XVE_TYPE_OPER_UP: return "OPER_UP"; - case XSMP_XVE_TYPE_OPER_DOWN: return "OPER_DOWN"; - case XSMP_XVE_TYPE_OPER_REQ: return "OPER_REQ"; - case XSMP_XVE_TYPE_READY: return "READY"; - default: - snprintf ( buf, sizeof ( buf ), "UNKNOWN<%d>", type ); - return buf; - } -} - -/** - * Send virtual Ethernet message - * - * @v xcm Configuration manager - * @v msg Partial message - * @ret rc Return status code - */ -static int xsmp_tx_xve ( struct xsigo_manager *xcm, - struct xsmp_xve_message *msg ) { - struct xsigo_device *xdev = xcm->xdev; - struct ib_device *ibdev = xdev->ibdev; - int rc; - - /* Fill in common header fields */ - msg->hdr.type = XSMP_TYPE_XVE; - msg->hdr.len = htons ( sizeof ( *msg ) ); - msg->hdr.seq = htonl ( ++xcm->seq ); - memcpy ( &msg->hdr.src.guid, &ibdev->gid.s.guid, - sizeof ( msg->hdr.src.guid ) ); - memcpy ( &msg->hdr.dst.guid, &xcm->id.guid, - sizeof ( msg->hdr.dst.guid ) ); - msg->len = htons ( sizeof ( *msg ) - sizeof ( msg->hdr ) ); - DBGCP ( xcm, "XCM %s TX[%d] xve %s code %#02x\n", xcm->name, - ntohl ( msg->hdr.seq ), xsmp_xve_type ( msg->type ), - msg->code ); - DBGCP_HDA ( xcm, 0, msg, sizeof ( *msg ) ); - - /* Send virtual Ethernet message */ - if ( ( rc = xfer_deliver_raw ( &xcm->xfer, msg, - sizeof ( *msg ) ) ) != 0 ) { - DBGC ( xcm, "XCM %s TX xve %s failed: %s\n", xcm->name, - xsmp_xve_type ( msg->type ), strerror ( rc ) ); - return rc; - } - - return 0; -} - -/** - * Send virtual Ethernet message including current device parameters - * - * @v xcm Configuration manager - * @v msg Partial virtual Ethernet message - * @v xve Virtual Ethernet device - * @v eoib EoIB device - * @ret rc Return status code - */ -static int xsmp_tx_xve_params ( struct xsigo_manager *xcm, - struct xsmp_xve_message *msg, - struct xsigo_nic *xve, - struct eoib_device *eoib ) { - struct xsigo_device *xdev = xcm->xdev; - struct ib_device *ibdev = xdev->ibdev; - struct net_device *netdev = eoib->netdev; - - /* Set successful response code */ - msg->code = 0; - - /* Include network identifier, MTU, and current HCA parameters */ - msg->network = htonl ( xve->network ); - msg->mtu = htons ( netdev->max_pkt_len - sizeof ( struct ethhdr ) ); - msg->hca.prefix_le.qword = bswap_64 ( ibdev->gid.s.prefix.qword ); - msg->hca.pkey = htons ( ibdev->pkey ); - msg->hca.qkey = msg->tca.qkey; - if ( eoib->qp ) { - msg->hca.data = htonl ( eoib->qp->ext_qpn ); - msg->hca.qkey = htons ( eoib->qp->qkey ); - } - - /* The message type field is (ab)used to return the current - * operational status. - */ - if ( msg->type == XSMP_XVE_TYPE_OPER_REQ ) { - msg->type = ( netdev_is_open ( netdev ) ? - XSMP_XVE_TYPE_OPER_UP : XSMP_XVE_TYPE_OPER_DOWN ); - } - - /* Send message */ - DBGC ( xve, "XVE %s network %d MTU %d ctrl %#x data %#x qkey %#04x " - "%s\n", xve->name, ntohl ( msg->network ), ntohs ( msg->mtu ), - ntohl ( msg->hca.ctrl ), ntohl ( msg->hca.data ), - ntohs ( msg->hca.qkey ), xsmp_xve_type ( msg->type ) ); - - return xsmp_tx_xve ( xcm, msg ); -} - -/** - * Send virtual Ethernet error response - * - * @v xcm Configuration manager - * @v msg Partial virtual Ethernet message - * @ret rc Return status code - */ -static inline int xsmp_tx_xve_nack ( struct xsigo_manager *xcm, - struct xsmp_xve_message *msg ) { - - /* Set error response code. (There aren't any meaningful - * detailed response codes defined by the wire protocol.) - */ - msg->code = XSMP_XVE_CODE_ERROR; - - /* Send message */ - return xsmp_tx_xve ( xcm, msg ); -} - -/** - * Send virtual Ethernet notification - * - * @v xcm Configuration manager - * @v type Message type - * @v xve Virtual Ethernet device - * @v eoib EoIB device - * @ret rc Return status code - */ -static int xsmp_tx_xve_notify ( struct xsigo_manager *xcm, - unsigned int type, - struct xsigo_nic *xve, - struct eoib_device *eoib ) { - struct xsmp_xve_message msg; - - /* Construct message */ - memset ( &msg, 0, sizeof ( msg ) ); - msg.type = type; - memcpy ( &msg.resource, &xve->resource, sizeof ( msg.resource ) ); - - /* Send message */ - return xsmp_tx_xve_params ( xcm, &msg, xve, eoib ); -} - -/** - * Send virtual Ethernet current operational state - * - * @v xcm Configuration manager - * @v xve Virtual Ethernet device - * @v eoib EoIB device - * @ret rc Return status code - */ -static inline int xsmp_tx_xve_oper ( struct xsigo_manager *xcm, - struct xsigo_nic *xve, - struct eoib_device *eoib ) { - - /* Send notification */ - return xsmp_tx_xve_notify ( xcm, XSMP_XVE_TYPE_OPER_REQ, xve, eoib ); -} - -/** - * Handle received virtual Ethernet modification message - * - * @v xcm Configuration manager - * @v msg Virtual Ethernet message - * @v update Update bitmask - * @ret rc Return status code - */ -static int xsmp_rx_xve_modify ( struct xsigo_manager *xcm, - struct xsmp_xve_message *msg, - unsigned int update ) { - struct xsigo_device *xdev = xcm->xdev; - struct ib_device *ibdev = xdev->ibdev; - struct xsigo_nic *xve; - struct eoib_device *eoib; - struct ib_address_vector tca; - size_t mtu; - int rc; - - /* Avoid returning uninitialised HCA parameters in response */ - memset ( &msg->hca, 0, sizeof ( msg->hca ) ); - - /* Find virtual Ethernet device */ - xve = xve_find ( xcm, &msg->resource ); - if ( ! xve ) { - DBGC ( xcm, "XCM %s unrecognised resource " IB_GUID_FMT "\n", - xcm->name, IB_GUID_ARGS ( &msg->resource ) ); - rc = -ENOENT; - goto err_no_xve; - } - - /* Find corresponding EoIB device */ - eoib = eoib_find ( ibdev, xve->mac ); - if ( ! eoib ) { - DBGC ( xve, "XVE %s has no EoIB device\n", xve->name ); - rc = -EPIPE; - goto err_no_eoib; - } - - /* The Xsigo management software fails to create the EoIB - * multicast group. This is a fundamental design flaw. - */ - eoib_force_group_creation ( eoib ); - - /* Extract modifiable parameters. Note that the TCA GID is - * erroneously transmitted as little-endian. - */ - mtu = ntohs ( msg->mtu ); - tca.qpn = ntohl ( msg->tca.data ); - tca.qkey = ntohs ( msg->tca.qkey ); - tca.gid_present = 1; - tca.gid.s.prefix.qword = bswap_64 ( msg->tca.prefix_le.qword ); - tca.gid.s.guid.qword = bswap_64 ( msg->guid_le.qword ); - - /* Update MTU, if applicable */ - if ( ( update & XSMP_XVE_UPDATE_MTU ) && - ( ( rc = xve_update_mtu ( xve, eoib, mtu ) ) != 0 ) ) - goto err_mtu; - update &= ~XSMP_XVE_UPDATE_MTU; - - /* Update admin state, if applicable */ - if ( ( update & XSMP_XVE_UPDATE_STATE ) && - ( ( rc = xve_update_state ( xve, eoib, msg->state ) ) != 0 ) ) - goto err_state; - update &= ~XSMP_XVE_UPDATE_STATE; - - /* Remove gateway, if applicable */ - if ( ( update & XSMP_XVE_UPDATE_GW_DOWN ) && - ( ( rc = xve_update_tca ( xve, eoib, NULL ) ) != 0 ) ) - goto err_gw_down; - update &= ~XSMP_XVE_UPDATE_GW_DOWN; - - /* Update gateway, if applicable */ - if ( ( update & XSMP_XVE_UPDATE_GW_CHANGE ) && - ( ( rc = xve_update_tca ( xve, eoib, &tca ) ) != 0 ) ) - goto err_gw_change; - update &= ~XSMP_XVE_UPDATE_GW_CHANGE; - - /* Warn about unexpected updates */ - if ( update ) { - DBGC ( xve, "XVE %s unrecognised update(s) %#08x\n", - xve->name, update ); - } - - xsmp_tx_xve_params ( xcm, msg, xve, eoib ); - return 0; - - err_gw_change: - err_gw_down: - err_state: - err_mtu: - err_no_eoib: - err_no_xve: - /* Send NACK */ - xsmp_tx_xve_nack ( xcm, msg ); - return rc; -} - -/** - * Handle received virtual Ethernet installation message - * - * @v xcm Configuration manager - * @v msg Virtual Ethernet message - * @ret rc Return status code - */ -static int xsmp_rx_xve_install ( struct xsigo_manager *xcm, - struct xsmp_xve_message *msg ) { - union { - struct xsmp_xve_mac msg; - uint8_t raw[ETH_ALEN]; - } mac; - char name[ sizeof ( msg->name ) + 1 /* NUL */ ]; - unsigned long network; - unsigned long qkey; - unsigned int update; - int rc; - - /* Demangle MAC address (which is erroneously transmitted as - * little-endian). - */ - mac.msg.high = bswap_16 ( msg->mac_le.high ); - mac.msg.low = bswap_32 ( msg->mac_le.low ); - - /* Extract interface name (which may not be NUL-terminated) */ - memcpy ( name, msg->name, ( sizeof ( name ) - 1 /* NUL */ ) ); - name[ sizeof ( name ) - 1 /* NUL */ ] = '\0'; - - /* Extract remaining message parameters */ - network = ntohl ( msg->network ); - qkey = ntohs ( msg->tca.qkey ); - DBGC2 ( xcm, "XCM %s " IB_GUID_FMT " install \"%s\" %s net %ld qkey " - "%#lx\n", xcm->name, IB_GUID_ARGS ( &msg->resource ), name, - eth_ntoa ( mac.raw ), network, qkey ); - - /* Create virtual Ethernet device, if applicable */ - if ( ( xve_find ( xcm, &msg->resource ) == NULL ) && - ( ( rc = xve_create ( xcm, &msg->resource, mac.raw, network, - qkey, name ) ) != 0 ) ) - goto err_create; - - /* Handle remaining parameters as for a modification message */ - update = XSMP_XVE_UPDATE_MTU; - if ( msg->uplink == XSMP_XVE_UPLINK ) - update |= XSMP_XVE_UPDATE_GW_CHANGE; - return xsmp_rx_xve_modify ( xcm, msg, update ); - - err_create: - /* Send NACK */ - xsmp_tx_xve_nack ( xcm, msg ); - return rc; -} - -/** - * Handle received virtual Ethernet deletion message - * - * @v xcm Configuration manager - * @v msg Virtual Ethernet message - * @ret rc Return status code - */ -static int xsmp_rx_xve_delete ( struct xsigo_manager *xcm, - struct xsmp_xve_message *msg ) { - struct xsigo_nic *xve; - - DBGC2 ( xcm, "XCM %s " IB_GUID_FMT " delete\n", - xcm->name, IB_GUID_ARGS ( &msg->resource ) ); - - /* Destroy virtual Ethernet device (if any) */ - if ( ( xve = xve_find ( xcm, &msg->resource ) ) ) - xve_destroy ( xve ); - - /* Send ACK */ - msg->code = 0; - xsmp_tx_xve ( xcm, msg ); - - return 0; -} - -/** - * Handle received virtual Ethernet update message - * - * @v xcm Configuration manager - * @v msg Virtual Ethernet message - * @ret rc Return status code - */ -static int xsmp_rx_xve_update ( struct xsigo_manager *xcm, - struct xsmp_xve_message *msg ) { - unsigned int update = ntohl ( msg->update ); - - DBGC2 ( xcm, "XCM %s " IB_GUID_FMT " update (%08x)\n", - xcm->name, IB_GUID_ARGS ( &msg->resource ), update ); - - /* Handle as a modification message */ - return xsmp_rx_xve_modify ( xcm, msg, update ); -} - -/** - * Handle received virtual Ethernet operational request message - * - * @v xcm Configuration manager - * @v msg Virtual Ethernet message - * @ret rc Return status code - */ -static int xsmp_rx_xve_oper_req ( struct xsigo_manager *xcm, - struct xsmp_xve_message *msg ) { - - DBGC2 ( xcm, "XCM %s " IB_GUID_FMT " operational request\n", - xcm->name, IB_GUID_ARGS ( &msg->resource ) ); - - /* Handle as a nullipotent modification message */ - return xsmp_rx_xve_modify ( xcm, msg, 0 ); -} - -/** - * Handle received virtual Ethernet readiness message - * - * @v xcm Configuration manager - * @v msg Virtual Ethernet message - * @ret rc Return status code - */ -static int xsmp_rx_xve_ready ( struct xsigo_manager *xcm, - struct xsmp_xve_message *msg ) { - int rc; - - DBGC2 ( xcm, "XCM %s " IB_GUID_FMT " ready\n", - xcm->name, IB_GUID_ARGS ( &msg->resource ) ); - - /* Handle as a nullipotent modification message */ - if ( ( rc = xsmp_rx_xve_modify ( xcm, msg, 0 ) ) != 0 ) - return rc; - - /* Send an unsolicited operational state update, since there - * is no other way to convey the current operational state. - */ - msg->type = XSMP_XVE_TYPE_OPER_REQ; - if ( ( rc = xsmp_rx_xve_modify ( xcm, msg, 0 ) ) != 0 ) - return rc; - - return 0; -} - -/** - * Handle received virtual Ethernet message - * - * @v xcm Configuration manager - * @v msg Virtual Ethernet message - * @ret rc Return status code - */ -static int xsmp_rx_xve ( struct xsigo_manager *xcm, - struct xsmp_xve_message *msg ) { - - DBGCP ( xcm, "XCM %s RX[%d] xve %s\n", xcm->name, - ntohl ( msg->hdr.seq ), xsmp_xve_type ( msg->type ) ); - DBGCP_HDA ( xcm, 0, msg, sizeof ( *msg ) ); - - /* Handle message according to type */ - switch ( msg->type ) { - case XSMP_XVE_TYPE_INSTALL: - return xsmp_rx_xve_install ( xcm, msg ); - case XSMP_XVE_TYPE_DELETE: - return xsmp_rx_xve_delete ( xcm, msg ); - case XSMP_XVE_TYPE_UPDATE: - return xsmp_rx_xve_update ( xcm, msg ); - case XSMP_XVE_TYPE_OPER_REQ: - return xsmp_rx_xve_oper_req ( xcm, msg ); - case XSMP_XVE_TYPE_READY: - return xsmp_rx_xve_ready ( xcm, msg ); - default: - DBGC ( xcm, "XCM %s RX[%d] xve unexpected %s:\n", xcm->name, - ntohl ( msg->hdr.seq ), xsmp_xve_type ( msg->type ) ); - DBGC_HDA ( xcm, 0, msg, sizeof ( *msg ) ); - return -EPROTO; - } -} - -/**************************************************************************** - * - * Configuration managers (XCM) - * - **************************************************************************** - */ - -/** - * Close configuration manager connection - * - * @v xcm Configuration manager - * @v rc Reason for close - */ -static void xcm_close ( struct xsigo_manager *xcm, int rc ) { - - DBGC ( xcm, "XCM %s closed: %s\n", xcm->name, strerror ( rc ) ); - - /* Stop transmission process */ - process_del ( &xcm->process ); - - /* Stop keepalive timer */ - stop_timer ( &xcm->keepalive ); - - /* Restart data transfer interface */ - intf_restart ( &xcm->xfer, rc ); - - /* Schedule reconnection attempt */ - start_timer ( &xcm->reopen ); -} - -/** - * Send data to configuration manager - * - * @v xcm Configuration manager - */ -static void xcm_step ( struct xsigo_manager *xcm ) { - int rc; - - /* Do nothing unless we have something to send */ - if ( ! xcm->pending ) - return; - - /* Send (empty) connection request, if applicable */ - if ( xcm->pending & XCM_TX_CONNECT ) { - if ( ( rc = xfer_deliver_raw ( &xcm->xfer, NULL, 0 ) ) != 0 ) { - DBGC ( xcm, "XCM %s could not send connection request: " - "%s\n", xcm->name, strerror ( rc ) ); - goto err; - } - xcm->pending &= ~XCM_TX_CONNECT; - return; - } - - /* Wait until data transfer interface is connected */ - if ( ! xfer_window ( &xcm->xfer ) ) - return; - - /* Send registration message, if applicable */ - if ( xcm->pending & XCM_TX_REGISTER ) { - if ( ( rc = xsmp_tx_session_register ( xcm ) ) != 0 ) - goto err; - xcm->pending &= ~XCM_TX_REGISTER; - return; - } - - return; - - err: - xcm_close ( xcm, rc ); -} - -/** - * Receive data from configuration manager - * - * @v xcm Configuration manager - * @v iobuf I/O buffer - * @v meta Data transfer metadata - * @ret rc Return status code - */ -static int xcm_deliver ( struct xsigo_manager *xcm, struct io_buffer *iobuf, - struct xfer_metadata *meta __unused ) { - union xsmp_message *msg; - size_t len = iob_len ( iobuf ); - int rc; - - /* Sanity check */ - if ( len < sizeof ( msg->hdr ) ) { - DBGC ( xcm, "XCM %s underlength message:\n", xcm->name ); - DBGC_HDA ( xcm, 0, iobuf->data, iob_len ( iobuf ) ); - rc = -EPROTO; - goto out; - } - msg = iobuf->data; - - /* Handle message according to type */ - if ( ! msg->hdr.type ) { - - /* Ignore unused communication manager private data blocks */ - rc = 0; - - } else if ( ( msg->hdr.type == XSMP_TYPE_SESSION ) && - ( len >= sizeof ( msg->sess ) ) ) { - - /* Session message */ - rc = xsmp_rx_session ( xcm, &msg->sess ); - - } else if ( ( msg->hdr.type == XSMP_TYPE_XVE ) && - ( len >= sizeof ( msg->xve ) ) ) { - - /* Virtual Ethernet message */ - xsmp_rx_xve ( xcm, &msg->xve ); - - /* Virtual Ethernet message errors are non-fatal */ - rc = 0; - - } else { - - /* Unknown message */ - DBGC ( xcm, "XCM %s unexpected message type %d:\n", - xcm->name, msg->hdr.type ); - DBGC_HDA ( xcm, 0, iobuf->data, iob_len ( iobuf ) ); - rc = -EPROTO; - } - - out: - free_iob ( iobuf ); - if ( rc != 0 ) - xcm_close ( xcm, rc ); - return rc; -} - -/** Configuration manager data transfer interface operations */ -static struct interface_operation xcm_xfer_op[] = { - INTF_OP ( xfer_deliver, struct xsigo_manager *, xcm_deliver ), - INTF_OP ( xfer_window_changed, struct xsigo_manager *, xcm_step ), - INTF_OP ( intf_close, struct xsigo_manager *, xcm_close ), -}; - -/** Configuration manager data transfer interface descriptor */ -static struct interface_descriptor xcm_xfer_desc = - INTF_DESC ( struct xsigo_manager, xfer, xcm_xfer_op ); - -/** Configuration manager process descriptor */ -static struct process_descriptor xcm_process_desc = - PROC_DESC_ONCE ( struct xsigo_manager, process, xcm_step ); - -/** - * Handle configuration manager connection timer expiry - * - * @v timer Connection timer - * @v fail Failure indicator - */ -static void xcm_reopen ( struct retry_timer *timer, int fail __unused ) { - struct xsigo_manager *xcm = - container_of ( timer, struct xsigo_manager, reopen ); - struct xsigo_device *xdev = xcm->xdev; - struct ib_device *ibdev = xdev->ibdev; - union ib_gid gid; - int rc; - - /* Stop transmission process */ - process_del ( &xcm->process ); - - /* Stop keepalive timer */ - stop_timer ( &xcm->keepalive ); - - /* Restart data transfer interface */ - intf_restart ( &xcm->xfer, -ECANCELED ); - - /* Reset sequence number */ - xcm->seq = 0; - - /* Construct GID */ - memcpy ( &gid.s.prefix, &ibdev->gid.s.prefix, sizeof ( gid.s.prefix ) ); - memcpy ( &gid.s.guid, &xcm->id.guid, sizeof ( gid.s.guid ) ); - DBGC ( xcm, "XCM %s connecting to " IB_GID_FMT "\n", - xcm->name, IB_GID_ARGS ( &gid ) ); - - /* Open CMRC connection */ - if ( ( rc = ib_cmrc_open ( &xcm->xfer, ibdev, &gid, - &xcm_service_id, xcm->name ) ) != 0 ) { - DBGC ( xcm, "XCM %s could not open CMRC connection: %s\n", - xcm->name, strerror ( rc ) ); - start_timer ( &xcm->reopen ); - return; - } - - /* Schedule transmissions */ - xcm->pending |= ( XCM_TX_CONNECT | XCM_TX_REGISTER ); - process_add ( &xcm->process ); - - /* Start keepalive timer */ - start_timer_fixed ( &xcm->keepalive, XSIGO_KEEPALIVE_INTERVAL ); - - return; -} - -/** - * Handle configuration manager keepalive timer expiry - * - * @v timer Connection timer - * @v fail Failure indicator - */ -static void xcm_keepalive ( struct retry_timer *timer, int fail __unused ) { - struct xsigo_manager *xcm = - container_of ( timer, struct xsigo_manager, keepalive ); - int rc; - - /* Send keepalive message. The server won't actually respond - * to these, but it gives the RC queue pair a chance to - * complain if it doesn't ever at least get an ACK. - */ - if ( ( rc = xsmp_tx_session_hello ( xcm ) ) != 0 ) { - xcm_close ( xcm, rc ); - return; - } - - /* Restart keepalive timer */ - start_timer_fixed ( &xcm->keepalive, XSIGO_KEEPALIVE_INTERVAL ); -} - -/** - * Create configuration manager - * - * @v xsigo Xsigo device - * @v id Configuration manager ID - * @ret rc Return status code - */ -static int xcm_create ( struct xsigo_device *xdev, - struct xsigo_manager_id *id ) { - struct xsigo_manager *xcm; - - /* Allocate and initialise structure */ - xcm = zalloc ( sizeof ( *xcm ) ); - if ( ! xcm ) - return -ENOMEM; - ref_init ( &xcm->refcnt, xcm_free ); - xcm->xdev = xdev; - ref_get ( &xcm->xdev->refcnt ); - snprintf ( xcm->name, sizeof ( xcm->name ), "%s:xcm-%d", - xdev->name, ntohs ( id->lid ) ); - memcpy ( &xcm->id, id, sizeof ( xcm->id ) ); - intf_init ( &xcm->xfer, &xcm_xfer_desc, &xcm->refcnt ); - timer_init ( &xcm->keepalive, xcm_keepalive, &xcm->refcnt ); - timer_init ( &xcm->reopen, xcm_reopen, &xcm->refcnt ); - process_init_stopped ( &xcm->process, &xcm_process_desc, &xcm->refcnt ); - INIT_LIST_HEAD ( &xcm->nics ); - - /* Start timer to open connection */ - start_timer_nodelay ( &xcm->reopen ); - - /* Add to list of managers and transfer reference to list */ - list_add ( &xcm->list, &xdev->managers ); - DBGC ( xcm, "XCM %s created for " IB_GUID_FMT " (LID %d)\n", xcm->name, - IB_GUID_ARGS ( &xcm->id.guid ), ntohs ( id->lid ) ); - return 0; -} - -/** - * Find configuration manager - * - * @v xsigo Xsigo device - * @v id Configuration manager ID - * @ret xcm Configuration manager, or NULL - */ -static struct xsigo_manager * xcm_find ( struct xsigo_device *xdev, - struct xsigo_manager_id *id ) { - struct xsigo_manager *xcm; - union ib_guid *guid = &id->guid; - - /* Find configuration manager */ - list_for_each_entry ( xcm, &xdev->managers, list ) { - if ( memcmp ( guid, &xcm->id.guid, sizeof ( *guid ) ) == 0 ) - return xcm; - } - return NULL; -} - -/** - * Destroy configuration manager - * - * @v xcm Configuration manager - */ -static void xcm_destroy ( struct xsigo_manager *xcm ) { - struct xsigo_nic *xve; - - /* Remove all EoIB NICs */ - while ( ( xve = list_first_entry ( &xcm->nics, struct xsigo_nic, - list ) ) ) { - xve_destroy ( xve ); - } - - /* Stop transmission process */ - process_del ( &xcm->process ); - - /* Stop timers */ - stop_timer ( &xcm->keepalive ); - stop_timer ( &xcm->reopen ); - - /* Shut down data transfer interface */ - intf_shutdown ( &xcm->xfer, 0 ); - - /* Remove from list of managers and drop list's reference */ - DBGC ( xcm, "XCM %s destroyed\n", xcm->name ); - list_del ( &xcm->list ); - ref_put ( &xcm->refcnt ); -} - -/** - * Synchronise list of configuration managers - * - * @v xdev Xsigo device - * @v ids List of manager IDs - * @v count Number of manager IDs - * @ret rc Return status code - */ -static int xcm_list ( struct xsigo_device *xdev, struct xsigo_manager_id *ids, - unsigned int count ) { - struct xsigo_manager_id *id; - struct xsigo_manager *xcm; - struct xsigo_manager *tmp; - struct list_head list; - unsigned int i; - int rc; - - /* Create list of managers to be retained */ - INIT_LIST_HEAD ( &list ); - for ( i = 0, id = ids ; i < count ; i++, id++ ) { - if ( ( xcm = xcm_find ( xdev, id ) ) ) { - list_del ( &xcm->list ); - list_add_tail ( &xcm->list, &list ); - } - } - - /* Destroy any managers not in the list */ - list_for_each_entry_safe ( xcm, tmp, &xdev->managers, list ) - xcm_destroy ( xcm ); - list_splice ( &list, &xdev->managers ); - - /* Create any new managers in the list, and force reconnection - * for any changed LIDs. - */ - for ( i = 0, id = ids ; i < count ; i++, id++ ) { - if ( ( xcm = xcm_find ( xdev, id ) ) ) { - if ( xcm->id.lid != id->lid ) - start_timer_nodelay ( &xcm->reopen ); - continue; - } - if ( ( rc = xcm_create ( xdev, id ) ) != 0 ) { - DBGC ( xdev, "XDEV %s could not create manager: %s\n", - xdev->name, strerror ( rc ) ); - return rc; - } - } - - return 0; -} - -/**************************************************************************** - * - * Configuration manager discovery - * - **************************************************************************** - */ - -/** A stage of discovery */ -struct xsigo_discovery { - /** Name */ - const char *name; - /** Management transaction operations */ - struct ib_mad_transaction_operations op; -}; - -/** - * Handle configuration manager lookup completion - * - * @v ibdev Infiniband device - * @v mi Management interface - * @v madx Management transaction - * @v rc Status code - * @v mad Received MAD (or NULL on error) - * @v av Source address vector (or NULL on error) - */ -static void xsigo_xcm_complete ( struct ib_device *ibdev, - struct ib_mad_interface *mi __unused, - struct ib_mad_transaction *madx, - int rc, union ib_mad *mad, - struct ib_address_vector *av __unused ) { - struct xsigo_device *xdev = ib_madx_get_ownerdata ( madx ); - union xsigo_mad *xsmad = container_of ( mad, union xsigo_mad, mad ); - struct xsigo_managers_reply *reply = &xsmad->reply; - - /* Check for failures */ - if ( ( rc == 0 ) && ( mad->hdr.status != htons ( IB_MGMT_STATUS_OK ) ) ) - rc = -ENODEV; - if ( rc != 0 ) { - DBGC ( xdev, "XDEV %s manager lookup failed: %s\n", - xdev->name, strerror ( rc ) ); - goto out; - } - - /* Sanity checks */ - if ( reply->count > ( sizeof ( reply->manager ) / - sizeof ( reply->manager[0] ) ) ) { - DBGC ( xdev, "XDEV %s has too many managers (%d)\n", - xdev->name, reply->count ); - goto out; - } - - /* Synchronise list of managers */ - if ( ( rc = xcm_list ( xdev, reply->manager, reply->count ) ) != 0 ) - goto out; - - /* Report an empty list of managers */ - if ( reply->count == 0 ) - DBGC ( xdev, "XDEV %s has no managers\n", xdev->name ); - - /* Delay next discovery attempt */ - start_timer_fixed ( &xdev->discovery, XSIGO_DISCOVERY_SUCCESS_DELAY ); - -out: - /* Destroy the completed transaction */ - ib_destroy_madx ( ibdev, ibdev->gsi, madx ); - xdev->madx = NULL; -} - -/** Configuration manager lookup discovery stage */ -static struct xsigo_discovery xsigo_xcm_discovery = { - .name = "manager", - .op = { - .complete = xsigo_xcm_complete, - }, -}; - -/** - * Handle directory service lookup completion - * - * @v ibdev Infiniband device - * @v mi Management interface - * @v madx Management transaction - * @v rc Status code - * @v mad Received MAD (or NULL on error) - * @v av Source address vector (or NULL on error) - */ -static void xsigo_xds_complete ( struct ib_device *ibdev, - struct ib_mad_interface *mi __unused, - struct ib_mad_transaction *madx, - int rc, union ib_mad *mad, - struct ib_address_vector *av __unused ) { - struct xsigo_device *xdev = ib_madx_get_ownerdata ( madx ); - union xsigo_mad *xsmad = container_of ( mad, union xsigo_mad, mad ); - struct xsigo_managers_request *request = &xsmad->request; - struct ib_service_record *svc; - struct ib_address_vector dest; - union ib_guid *guid; - - /* Allow for reuse of transaction pointer */ - xdev->madx = NULL; - - /* Check for failures */ - if ( ( rc == 0 ) && ( mad->hdr.status != htons ( IB_MGMT_STATUS_OK ) ) ) - rc = -ENODEV; - if ( rc != 0 ) { - DBGC ( xdev, "XDEV %s directory lookup failed: %s\n", - xdev->name, strerror ( rc ) ); - goto out; - } - - /* Construct address vector */ - memset ( &dest, 0, sizeof ( dest ) ); - svc = &mad->sa.sa_data.service_record; - dest.lid = ntohs ( svc->data16[0] ); - dest.sl = ibdev->sm_sl; - dest.qpn = IB_QPN_GSI; - dest.qkey = IB_QKEY_GSI; - guid = ( ( union ib_guid * ) &svc->data64[0] ); - DBGC2 ( xdev, "XDEV %s found directory at LID %d GUID " IB_GUID_FMT - "\n", xdev->name, dest.lid, IB_GUID_ARGS ( guid ) ); - - /* Construct request (reusing MAD buffer) */ - memset ( request, 0, sizeof ( *request ) ); - request->mad_hdr.mgmt_class = XSIGO_MGMT_CLASS; - request->mad_hdr.class_version = XSIGO_MGMT_CLASS_VERSION; - request->mad_hdr.method = IB_MGMT_METHOD_GET; - request->mad_hdr.attr_id = htons ( XSIGO_ATTR_XCM_REQUEST ); - memcpy ( &request->server.guid, &ibdev->gid.s.guid, - sizeof ( request->server.guid ) ); - snprintf ( request->os_version, sizeof ( request->os_version ), - "%s %s", product_short_name, product_version ); - snprintf ( request->arch, sizeof ( request->arch ), _S2 ( ARCH ) ); - request->os_type = XSIGO_OS_TYPE_GENERIC; - request->resources = htons ( XSIGO_RESOURCES_PRESENT | - XSIGO_RESOURCE_XVE | - XSIGO_RESOURCE_NO_HA ); - - /* The handling of this request on the server side is a - * textbook example of how not to design a wire protocol. The - * server uses the _driver_ version number to determine which - * fields are present. - */ - request->driver_version = htonl ( 0x2a2a2a ); - - /* The build version field is ignored unless it happens to - * contain the substring "xg-". - */ - snprintf ( request->build, sizeof ( request->build ), - "not-xg-%08lx", build_id ); - - /* The server side user interface occasionally has no way to - * refer to an entry with an empty hostname. - */ - fetch_string_setting ( NULL, &hostname_setting, request->hostname, - sizeof ( request->hostname ) ); - if ( ! request->hostname[0] ) { - snprintf ( request->hostname, sizeof ( request->hostname ), - "%s-" IB_GUID_FMT, product_short_name, - IB_GUID_ARGS ( &ibdev->gid.s.guid ) ); - } - - /* Start configuration manager lookup */ - xdev->madx = ib_create_madx ( ibdev, ibdev->gsi, mad, &dest, - &xsigo_xcm_discovery.op ); - if ( ! xdev->madx ) { - DBGC ( xdev, "XDEV %s could not start manager lookup\n", - xdev->name ); - goto out; - } - ib_madx_set_ownerdata ( xdev->madx, xdev ); - -out: - /* Destroy the completed transaction */ - ib_destroy_madx ( ibdev, ibdev->gsi, madx ); -} - -/** Directory service lookup discovery stage */ -static struct xsigo_discovery xsigo_xds_discovery = { - .name = "directory", - .op = { - .complete = xsigo_xds_complete, - }, -}; - -/** - * Discover configuration managers - * - * @v timer Retry timer - * @v over Failure indicator - */ -static void xsigo_discover ( struct retry_timer *timer, int over __unused ) { - struct xsigo_device *xdev = - container_of ( timer, struct xsigo_device, discovery ); - struct ib_device *ibdev = xdev->ibdev; - struct xsigo_discovery *discovery; - - /* Restart timer */ - start_timer_fixed ( &xdev->discovery, XSIGO_DISCOVERY_FAILURE_DELAY ); - - /* Cancel any pending discovery transaction */ - if ( xdev->madx ) { - discovery = container_of ( xdev->madx->op, - struct xsigo_discovery, op ); - DBGC ( xdev, "XDEV %s timed out waiting for %s lookup\n", - xdev->name, discovery->name ); - ib_destroy_madx ( ibdev, ibdev->gsi, xdev->madx ); - xdev->madx = NULL; - } - - /* Start directory service lookup */ - xdev->madx = ib_create_service_madx ( ibdev, ibdev->gsi, - XDS_SERVICE_NAME, - &xsigo_xds_discovery.op ); - if ( ! xdev->madx ) { - DBGC ( xdev, "XDEV %s could not start directory lookup\n", - xdev->name ); - return; - } - ib_madx_set_ownerdata ( xdev->madx, xdev ); -} - -/**************************************************************************** - * - * Infiniband device driver - * - **************************************************************************** - */ - -/** - * Open link and start discovery - * - * @v opener Link opener - * @v over Failure indicator - */ -static void xsigo_ib_open ( struct retry_timer *opener, int over __unused ) { - struct xsigo_device *xdev = - container_of ( opener, struct xsigo_device, opener ); - struct ib_device *ibdev = xdev->ibdev; - int rc; - - /* Open Infiniband device */ - if ( ( rc = ib_open ( ibdev ) ) != 0 ) { - DBGC ( xdev, "XDEV %s could not open: %s\n", - xdev->name, strerror ( rc ) ); - /* Delay and try again */ - start_timer_fixed ( &xdev->opener, XSIGO_OPEN_RETRY_DELAY ); - return; - } - - /* If link is already up, then start discovery */ - if ( ib_link_ok ( ibdev ) ) - start_timer_nodelay ( &xdev->discovery ); -} - -/** - * Probe Xsigo device - * - * @v ibdev Infiniband device - * @ret rc Return status code - */ -static int xsigo_ib_probe ( struct ib_device *ibdev ) { - struct xsigo_device *xdev; - - /* Allocate and initialise structure */ - xdev = zalloc ( sizeof ( *xdev ) ); - if ( ! xdev ) - return -ENOMEM; - ref_init ( &xdev->refcnt, xsigo_free ); - xdev->ibdev = ibdev_get ( ibdev ); - xdev->name = ibdev->name; - timer_init ( &xdev->opener, xsigo_ib_open, &xdev->refcnt ); - timer_init ( &xdev->discovery, xsigo_discover, &xdev->refcnt ); - INIT_LIST_HEAD ( &xdev->managers ); - - /* Start timer to open Infiniband device. (We are currently - * within the Infiniband device probe callback list; opening - * the device here would have interesting side-effects.) - */ - start_timer_nodelay ( &xdev->opener ); - - /* Add to list of devices and transfer reference to list */ - list_add_tail ( &xdev->list, &xsigo_devices ); - DBGC ( xdev, "XDEV %s created for " IB_GUID_FMT "\n", - xdev->name, IB_GUID_ARGS ( &ibdev->gid.s.guid ) ); - return 0; -} - -/** - * Handle device or link status change - * - * @v ibdev Infiniband device - */ -static void xsigo_ib_notify ( struct ib_device *ibdev ) { - struct xsigo_device *xdev; - - /* Stop/restart discovery on any attached devices */ - list_for_each_entry ( xdev, &xsigo_devices, list ) { - - /* Skip non-attached devices */ - if ( xdev->ibdev != ibdev ) - continue; - - /* Stop any ongoing discovery */ - if ( xdev->madx ) { - ib_destroy_madx ( ibdev, ibdev->gsi, xdev->madx ); - xdev->madx = NULL; - } - stop_timer ( &xdev->discovery ); - - /* If link is up, then start discovery */ - if ( ib_link_ok ( ibdev ) ) - start_timer_nodelay ( &xdev->discovery ); - } -} - -/** - * Remove Xsigo device - * - * @v ibdev Infiniband device - */ -static void xsigo_ib_remove ( struct ib_device *ibdev ) { - struct xsigo_device *xdev; - struct xsigo_device *tmp; - - /* Remove any attached Xsigo devices */ - list_for_each_entry_safe ( xdev, tmp, &xsigo_devices, list ) { - - /* Skip non-attached devices */ - if ( xdev->ibdev != ibdev ) - continue; - - /* Stop any ongoing discovery */ - if ( xdev->madx ) { - ib_destroy_madx ( ibdev, ibdev->gsi, xdev->madx ); - xdev->madx = NULL; - } - stop_timer ( &xdev->discovery ); - - /* Destroy all configuration managers */ - xcm_list ( xdev, NULL, 0 ); - - /* Close Infiniband device, if applicable */ - if ( ! timer_running ( &xdev->opener ) ) - ib_close ( xdev->ibdev ); - - /* Stop link opener */ - stop_timer ( &xdev->opener ); - - /* Remove from list of devices and drop list's reference */ - DBGC ( xdev, "XDEV %s destroyed\n", xdev->name ); - list_del ( &xdev->list ); - ref_put ( &xdev->refcnt ); - } -} - -/** Xsigo Infiniband driver */ -struct ib_driver xsigo_ib_driver __ib_driver = { - .name = "Xsigo", - .probe = xsigo_ib_probe, - .notify = xsigo_ib_notify, - .remove = xsigo_ib_remove, -}; - -/**************************************************************************** - * - * Network device driver - * - **************************************************************************** - */ - -/** - * Handle device or link status change - * - * @v netdev Network device - */ -static void xsigo_net_notify ( struct net_device *netdev ) { - struct xsigo_device *xdev; - struct ib_device *ibdev; - struct xsigo_manager *xcm; - struct xsigo_nic *xve; - struct eoib_device *eoib; - - /* Send current operational state to XCM, if applicable */ - list_for_each_entry ( xdev, &xsigo_devices, list ) { - ibdev = xdev->ibdev; - list_for_each_entry ( xcm, &xdev->managers, list ) { - list_for_each_entry ( xve, &xcm->nics, list ) { - eoib = eoib_find ( ibdev, xve->mac ); - if ( ! eoib ) - continue; - if ( eoib->netdev != netdev ) - continue; - xsmp_tx_xve_oper ( xcm, xve, eoib ); - } - } - } -} - -/** Xsigo network driver */ -struct net_driver xsigo_net_driver __net_driver = { - .name = "Xsigo", - .notify = xsigo_net_notify, -}; diff --git a/roms/ipxe/src/net/ipv4.c b/roms/ipxe/src/net/ipv4.c index 8eb04a65f..a54784049 100644 --- a/roms/ipxe/src/net/ipv4.c +++ b/roms/ipxe/src/net/ipv4.c @@ -358,11 +358,8 @@ static int ipv4_tx ( struct io_buffer *iobuf, ( ( netdev->rx_stats.good & 0xf ) << 0 ) ); /* Fix up checksums */ - if ( trans_csum ) { + if ( trans_csum ) *trans_csum = ipv4_pshdr_chksum ( iobuf, *trans_csum ); - if ( ! *trans_csum ) - *trans_csum = tcpip_protocol->zero_csum; - } iphdr->chksum = tcpip_chksum ( iphdr, sizeof ( *iphdr ) ); /* Print IP4 header for debugging */ @@ -717,7 +714,6 @@ struct tcpip_net_protocol ipv4_tcpip_protocol __tcpip_net_protocol = { .name = "IPv4", .sa_family = AF_INET, .header_len = sizeof ( struct iphdr ), - .net_protocol = &ipv4_protocol, .tx = ipv4_tx, .netdev = ipv4_netdev, }; diff --git a/roms/ipxe/src/net/ipv6.c b/roms/ipxe/src/net/ipv6.c index bbc00d33e..a75e72ddb 100644 --- a/roms/ipxe/src/net/ipv6.c +++ b/roms/ipxe/src/net/ipv6.c @@ -522,8 +522,6 @@ static int ipv6_tx ( struct io_buffer *iobuf, *trans_csum = ipv6_pshdr_chksum ( iphdr, len, tcpip_protocol->tcpip_proto, *trans_csum ); - if ( ! *trans_csum ) - *trans_csum = tcpip_protocol->zero_csum; } /* Print IPv6 header for debugging */ @@ -1003,7 +1001,6 @@ struct tcpip_net_protocol ipv6_tcpip_protocol __tcpip_net_protocol = { .name = "IPv6", .sa_family = AF_INET6, .header_len = sizeof ( struct ipv6_header ), - .net_protocol = &ipv6_protocol, .tx = ipv6_tx, .netdev = ipv6_netdev, }; diff --git a/roms/ipxe/src/net/netdev_settings.c b/roms/ipxe/src/net/netdev_settings.c index 7d893a126..edd4c4b9f 100644 --- a/roms/ipxe/src/net/netdev_settings.c +++ b/roms/ipxe/src/net/netdev_settings.c @@ -65,11 +65,6 @@ const struct setting chip_setting __setting ( SETTING_NETDEV, chip ) = { .description = "Chip", .type = &setting_type_string, }; -const struct setting ifname_setting __setting ( SETTING_NETDEV, ifname ) = { - .name = "ifname", - .description = "Interface name", - .type = &setting_type_string, -}; /** * Store MAC address setting @@ -141,8 +136,7 @@ static int netdev_fetch_bustype ( struct net_device *netdev, void *data, assert ( desc->bus_type < ( sizeof ( bustypes ) / sizeof ( bustypes[0] ) ) ); bustype = bustypes[desc->bus_type]; - if ( ! bustype ) - return -ENOENT; + assert ( bustype != NULL ); strncpy ( data, bustype, len ); return strlen ( bustype ); } @@ -205,22 +199,6 @@ static int netdev_fetch_chip ( struct net_device *netdev, void *data, return strlen ( chip ); } -/** - * Fetch ifname setting - * - * @v netdev Network device - * @v data Buffer to fill with setting data - * @v len Length of buffer - * @ret len Length of setting data, or negative error - */ -static int netdev_fetch_ifname ( struct net_device *netdev, void *data, - size_t len ) { - const char *ifname = netdev->name; - - strncpy ( data, ifname, len ); - return strlen ( ifname ); -} - /** A network device setting operation */ struct netdev_setting_operation { /** Setting */ @@ -251,7 +229,6 @@ static struct netdev_setting_operation netdev_setting_operations[] = { { &busloc_setting, NULL, netdev_fetch_busloc }, { &busid_setting, NULL, netdev_fetch_busid }, { &chip_setting, NULL, netdev_fetch_chip }, - { &ifname_setting, NULL, netdev_fetch_ifname }, }; /** diff --git a/roms/ipxe/src/net/netdevice.c b/roms/ipxe/src/net/netdevice.c index 9df21196c..7c40a2ac8 100644 --- a/roms/ipxe/src/net/netdevice.c +++ b/roms/ipxe/src/net/netdevice.c @@ -675,14 +675,6 @@ int register_netdev ( struct net_device *netdev ) { goto err_duplicate; } - /* Reject named network devices that already exist */ - if ( netdev->name[0] && ( duplicate = find_netdev ( netdev->name ) ) ) { - DBGC ( netdev, "NETDEV rejecting duplicate name %s\n", - duplicate->name ); - rc = -EEXIST; - goto err_duplicate; - } - /* Record device index and create device name */ if ( netdev->name[0] == '\0' ) { snprintf ( netdev->name, sizeof ( netdev->name ), "net%d", @@ -733,8 +725,6 @@ int register_netdev ( struct net_device *netdev ) { clear_settings ( netdev_settings ( netdev ) ); unregister_settings ( netdev_settings ( netdev ) ); err_register_settings: - list_del ( &netdev->list ); - netdev_put ( netdev ); err_duplicate: return rc; } diff --git a/roms/ipxe/src/net/peerblk.c b/roms/ipxe/src/net/peerblk.c index 9fd52b736..fd7ea0893 100644 --- a/roms/ipxe/src/net/peerblk.c +++ b/roms/ipxe/src/net/peerblk.c @@ -700,20 +700,17 @@ static int peerblk_parse_header ( struct peerdist_block *peerblk ) { return -EPROTO; } - /* Allocate cipher context, if applicable. Freeing the cipher - * context (on error or otherwise) is handled by peerblk_reset(). + /* Allocate cipher context. Freeing the cipher context (on + * error or otherwise) is handled by peerblk_reset(). */ peerblk->cipher = cipher; assert ( peerblk->cipherctx == NULL ); - if ( cipher ) { - peerblk->cipherctx = malloc ( cipher->ctxsize ); - if ( ! peerblk->cipherctx ) - return -ENOMEM; - } + peerblk->cipherctx = malloc ( cipher->ctxsize ); + if ( ! peerblk->cipherctx ) + return -ENOMEM; - /* Initialise cipher, if applicable */ - if ( cipher && - ( rc = cipher_setkey ( cipher, peerblk->cipherctx, peerblk->secret, + /* Initialise cipher */ + if ( ( rc = cipher_setkey ( cipher, peerblk->cipherctx, peerblk->secret, keylen ) ) != 0 ) { DBGC ( peerblk, "PEERBLK %p %d.%d could not set key: %s\n", peerblk, peerblk->segment, peerblk->block, diff --git a/roms/ipxe/src/net/stp.c b/roms/ipxe/src/net/stp.c index defdaed9e..d4e65a1a2 100644 --- a/roms/ipxe/src/net/stp.c +++ b/roms/ipxe/src/net/stp.c @@ -40,15 +40,15 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); /* Disambiguate the various error causes */ #define ENOTSUP_PROTOCOL __einfo_error ( EINFO_ENOTSUP_PROTOCOL ) #define EINFO_ENOTSUP_PROTOCOL \ - __einfo_uniqify ( EINFO_ENOTSUP, 0x02, \ + __einfo_uniqify ( EINFO_ENOTSUP, 0x01, \ "Non-STP packet received" ) #define ENOTSUP_VERSION __einfo_error ( EINFO_ENOTSUP_VERSION ) #define EINFO_ENOTSUP_VERSION \ - __einfo_uniqify ( EINFO_ENOTSUP, 0x03, \ + __einfo_uniqify ( EINFO_ENOTSUP, 0x01, \ "Legacy STP packet received" ) #define ENOTSUP_TYPE __einfo_error ( EINFO_ENOTSUP_TYPE ) #define EINFO_ENOTSUP_TYPE \ - __einfo_uniqify ( EINFO_ENOTSUP, 0x04, \ + __einfo_uniqify ( EINFO_ENOTSUP, 0x01, \ "Non-RSTP packet received" ) /** diff --git a/roms/ipxe/src/net/tcp.c b/roms/ipxe/src/net/tcp.c index 37a202ef1..c69c83b85 100644 --- a/roms/ipxe/src/net/tcp.c +++ b/roms/ipxe/src/net/tcp.c @@ -113,8 +113,6 @@ struct tcp_connection { struct process process; /** Retransmission timer */ struct retry_timer timer; - /** Keepalive timer */ - struct retry_timer keepalive; /** Shutdown (TIME_WAIT) timer */ struct retry_timer wait; @@ -179,7 +177,6 @@ static struct profiler tcp_xfer_profiler __profiler = { .name = "tcp.xfer" }; static struct process_descriptor tcp_process_desc; static struct interface_descriptor tcp_xfer_desc; static void tcp_expired ( struct retry_timer *timer, int over ); -static void tcp_keepalive_expired ( struct retry_timer *timer, int over ); static void tcp_wait_expired ( struct retry_timer *timer, int over ); static struct tcp_connection * tcp_demux ( unsigned int local_port ); static int tcp_rx_ack ( struct tcp_connection *tcp, uint32_t ack, @@ -287,7 +284,6 @@ static int tcp_open ( struct interface *xfer, struct sockaddr *peer, intf_init ( &tcp->xfer, &tcp_xfer_desc, &tcp->refcnt ); process_init_stopped ( &tcp->process, &tcp_process_desc, &tcp->refcnt ); timer_init ( &tcp->timer, tcp_expired, &tcp->refcnt ); - timer_init ( &tcp->keepalive, tcp_keepalive_expired, &tcp->refcnt ); timer_init ( &tcp->wait, tcp_wait_expired, &tcp->refcnt ); tcp->prev_tcp_state = TCP_CLOSED; tcp->tcp_state = TCP_STATE_SENT ( TCP_SYN ); @@ -384,7 +380,6 @@ static void tcp_close ( struct tcp_connection *tcp, int rc ) { /* Remove from list and drop reference */ process_del ( &tcp->process ); stop_timer ( &tcp->timer ); - stop_timer ( &tcp->keepalive ); stop_timer ( &tcp->wait ); list_del ( &tcp->list ); ref_put ( &tcp->refcnt ); @@ -399,9 +394,6 @@ static void tcp_close ( struct tcp_connection *tcp, int rc ) { if ( ! ( tcp->tcp_state & TCP_STATE_ACKED ( TCP_SYN ) ) ) tcp_rx_ack ( tcp, ( tcp->snd_seq + 1 ), 0 ); - /* Stop keepalive timer */ - stop_timer ( &tcp->keepalive ); - /* If we have no data remaining to send, start sending FIN */ if ( list_empty ( &tcp->tx_queue ) && ! ( tcp->tcp_state & TCP_STATE_SENT ( TCP_FIN ) ) ) { @@ -810,32 +802,6 @@ static void tcp_expired ( struct retry_timer *timer, int over ) { } /** - * Keepalive timer expired - * - * @v timer Keepalive timer - * @v over Failure indicator - */ -static void tcp_keepalive_expired ( struct retry_timer *timer, - int over __unused ) { - struct tcp_connection *tcp = - container_of ( timer, struct tcp_connection, keepalive ); - - DBGC ( tcp, "TCP %p sending keepalive\n", tcp ); - - /* Reset keepalive timer */ - start_timer_fixed ( &tcp->keepalive, TCP_KEEPALIVE_DELAY ); - - /* Send keepalive. We do this only to preserve or restore - * state in intermediate devices (e.g. firewall NAT tables); - * we don't actually care about eliciting a response to verify - * that the peer is still alive. We therefore send just a - * pure ACK, to keep our transmit path simple. - */ - tcp->flags |= TCP_ACK_PENDING; - tcp_xmit ( tcp ); -} - -/** * Shutdown timer expired * * @v timer Shutdown timer @@ -938,86 +904,50 @@ static struct tcp_connection * tcp_demux ( unsigned int local_port ) { /** * Parse TCP received options * - * @v tcp TCP connection (may be NULL) - * @v tcphdr TCP header - * @v hlen TCP header length + * @v tcp TCP connection + * @v data Raw options data + * @v len Raw options length * @v options Options structure to fill in - * @ret rc Return status code */ -static int tcp_rx_opts ( struct tcp_connection *tcp, - const struct tcp_header *tcphdr, size_t hlen, - struct tcp_options *options ) { - const void *data = ( ( ( void * ) tcphdr ) + sizeof ( *tcphdr ) ); - const void *end = ( ( ( void * ) tcphdr ) + hlen ); +static void tcp_rx_opts ( struct tcp_connection *tcp, const void *data, + size_t len, struct tcp_options *options ) { + const void *end = ( data + len ); const struct tcp_option *option; unsigned int kind; - size_t remaining; - size_t min; - - /* Sanity check */ - assert ( hlen >= sizeof ( *tcphdr ) ); - /* Parse options */ memset ( options, 0, sizeof ( *options ) ); - while ( ( remaining = ( end - data ) ) ) { - - /* Extract option code */ + while ( data < end ) { option = data; kind = option->kind; - - /* Handle single-byte options */ if ( kind == TCP_OPTION_END ) - break; + return; if ( kind == TCP_OPTION_NOP ) { data++; continue; } - - /* Handle multi-byte options */ - min = sizeof ( *option ); switch ( kind ) { case TCP_OPTION_MSS: - /* Ignore received MSS */ + options->mssopt = data; break; case TCP_OPTION_WS: options->wsopt = data; - min = sizeof ( *options->wsopt ); break; case TCP_OPTION_SACK_PERMITTED: options->spopt = data; - min = sizeof ( *options->spopt ); break; case TCP_OPTION_SACK: /* Ignore received SACKs */ break; case TCP_OPTION_TS: options->tsopt = data; - min = sizeof ( *options->tsopt ); break; default: DBGC ( tcp, "TCP %p received unknown option %d\n", tcp, kind ); break; } - if ( remaining < min ) { - DBGC ( tcp, "TCP %p received truncated option %d\n", - tcp, kind ); - return -EINVAL; - } - if ( option->length < min ) { - DBGC ( tcp, "TCP %p received underlength option %d\n", - tcp, kind ); - return -EINVAL; - } - if ( option->length > remaining ) { - DBGC ( tcp, "TCP %p received overlength option %d\n", - tcp, kind ); - return -EINVAL; - } data += option->length; } - - return 0; } /** @@ -1081,12 +1011,6 @@ static int tcp_rx_syn ( struct tcp_connection *tcp, uint32_t seq, tcp->snd_win_scale = options->wsopt->scale; tcp->rcv_win_scale = TCP_RX_WINDOW_SCALE; } - DBGC ( tcp, "TCP %p using %stimestamps, %sSACK, TX window " - "x%d, RX window x%d\n", tcp, - ( ( tcp->flags & TCP_TS_ENABLED ) ? "" : "no " ), - ( ( tcp->flags & TCP_SACK_ENABLED ) ? "" : "no " ), - ( 1 << tcp->snd_win_scale ), - ( 1 << tcp->rcv_win_scale ) ); } /* Ignore duplicate SYN */ @@ -1139,10 +1063,6 @@ static int tcp_rx_ack ( struct tcp_connection *tcp, uint32_t ack, /* Update window size */ tcp->snd_win = win; - /* Hold off (or start) the keepalive timer, if applicable */ - if ( ! ( tcp->tcp_state & TCP_STATE_SENT ( TCP_FIN ) ) ) - start_timer_fixed ( &tcp->keepalive, TCP_KEEPALIVE_DELAY ); - /* Ignore ACKs that don't actually acknowledge any new data. * (In particular, do not stop the retransmission timer; this * avoids creating a sorceror's apprentice syndrome when a @@ -1449,8 +1369,8 @@ static int tcp_rx ( struct io_buffer *iobuf, ack = ntohl ( tcphdr->ack ); raw_win = ntohs ( tcphdr->win ); flags = tcphdr->flags; - if ( ( rc = tcp_rx_opts ( tcp, tcphdr, hlen, &options ) ) != 0 ) - goto discard; + tcp_rx_opts ( tcp, ( ( ( void * ) tcphdr ) + sizeof ( *tcphdr ) ), + ( hlen - sizeof ( *tcphdr ) ), &options ); if ( tcp && options.tsopt ) tcp->ts_val = ntohl ( options.tsopt->tsval ); iob_pull ( iobuf, hlen ); diff --git a/roms/ipxe/src/net/tcp/httpconn.c b/roms/ipxe/src/net/tcp/httpconn.c index a2c01a418..7e4877b7b 100644 --- a/roms/ipxe/src/net/tcp/httpconn.c +++ b/roms/ipxe/src/net/tcp/httpconn.c @@ -237,7 +237,6 @@ int http_connect ( struct interface *xfer, struct uri *uri ) { struct http_scheme *scheme; struct sockaddr_tcpip server; struct interface *socket; - unsigned int port; int rc; /* Identify scheme */ @@ -249,9 +248,6 @@ int http_connect ( struct interface *xfer, struct uri *uri ) { if ( ! uri->host ) return -EINVAL; - /* Identify port */ - port = uri_port ( uri, scheme->port ); - /* Look for a reusable connection in the pool */ list_for_each_entry ( conn, &http_connection_pool, pool.list ) { @@ -261,16 +257,15 @@ int http_connect ( struct interface *xfer, struct uri *uri ) { /* Reuse connection, if possible */ if ( ( scheme == conn->scheme ) && - ( strcmp ( uri->host, conn->uri->host ) == 0 ) && - ( port == uri_port ( conn->uri, scheme->port ) ) ) { + ( strcmp ( uri->host, conn->uri->host ) == 0 ) ) { /* Remove from connection pool, stop timer, * attach to parent interface, and return. */ pool_del ( &conn->pool ); intf_plug_plug ( &conn->xfer, xfer ); - DBGC2 ( conn, "HTTPCONN %p reused %s://%s:%d\n", conn, - conn->scheme->name, conn->uri->host, port ); + DBGC2 ( conn, "HTTPCONN %p reused %s://%s\n", + conn, conn->scheme->name, conn->uri->host ); return 0; } } @@ -286,7 +281,7 @@ int http_connect ( struct interface *xfer, struct uri *uri ) { /* Open socket */ memset ( &server, 0, sizeof ( server ) ); - server.st_port = htons ( port ); + server.st_port = htons ( uri_port ( uri, scheme->port ) ); socket = &conn->socket; if ( scheme->filter && ( ( rc = scheme->filter ( socket, uri->host, &socket ) ) != 0 ) ) @@ -301,13 +296,13 @@ int http_connect ( struct interface *xfer, struct uri *uri ) { ref_put ( &conn->refcnt ); DBGC2 ( conn, "HTTPCONN %p created %s://%s:%d\n", conn, - conn->scheme->name, conn->uri->host, port ); + conn->scheme->name, conn->uri->host, ntohs ( server.st_port ) ); return 0; err_open: err_filter: - DBGC2 ( conn, "HTTPCONN %p could not create %s://%s:%d: %s\n", conn, - conn->scheme->name, conn->uri->host, port, strerror ( rc ) ); + DBGC2 ( conn, "HTTPCONN %p could not create %s://%s: %s\n", + conn, conn->scheme->name, conn->uri->host, strerror ( rc ) ); http_conn_close ( conn, rc ); ref_put ( &conn->refcnt ); return rc; diff --git a/roms/ipxe/src/net/tcp/httpcore.c b/roms/ipxe/src/net/tcp/httpcore.c index b1f74bc4f..af3ca9780 100644 --- a/roms/ipxe/src/net/tcp/httpcore.c +++ b/roms/ipxe/src/net/tcp/httpcore.c @@ -189,8 +189,8 @@ char * http_token ( char **line, char **value ) { if ( value ) *value = NULL; - /* Skip any initial whitespace or commas */ - while ( ( isspace ( **line ) ) || ( **line == ',' ) ) + /* Skip any initial whitespace */ + while ( isspace ( **line ) ) (*line)++; /* Check for end of line and record token position */ @@ -201,8 +201,8 @@ char * http_token ( char **line, char **value ) { /* Scan for end of token */ while ( ( c = **line ) ) { - /* Terminate if we hit an unquoted whitespace or comma */ - if ( ( isspace ( c ) || ( c == ',' ) ) && ! quote ) + /* Terminate if we hit an unquoted whitespace */ + if ( isspace ( c ) && ! quote ) break; /* Terminate if we hit a closing quote */ @@ -685,51 +685,6 @@ int http_open ( struct interface *xfer, struct http_method *method, } /** - * Redirect HTTP transaction - * - * @v http HTTP transaction - * @v location New location - * @ret rc Return status code - */ -static int http_redirect ( struct http_transaction *http, - const char *location ) { - struct uri *location_uri; - struct uri *resolved_uri; - int rc; - - DBGC2 ( http, "HTTP %p redirecting to \"%s\"\n", http, location ); - - /* Parse location URI */ - location_uri = parse_uri ( location ); - if ( ! location_uri ) { - rc = -ENOMEM; - goto err_parse_uri; - } - - /* Resolve as relative to original URI */ - resolved_uri = resolve_uri ( http->uri, location_uri ); - if ( ! resolved_uri ) { - rc = -ENOMEM; - goto err_resolve_uri; - } - - /* Redirect to new URI */ - if ( ( rc = xfer_redirect ( &http->xfer, LOCATION_URI, - resolved_uri ) ) != 0 ) { - DBGC ( http, "HTTP %p could not redirect: %s\n", - http, strerror ( rc ) ); - goto err_redirect; - } - - err_redirect: - uri_put ( resolved_uri ); - err_resolve_uri: - uri_put ( location_uri ); - err_parse_uri: - return rc; -} - -/** * Handle successful transfer completion * * @v http HTTP transaction @@ -762,8 +717,14 @@ static int http_transfer_complete ( struct http_transaction *http ) { /* Perform redirection, if applicable */ if ( ( location = http->response.location ) ) { - if ( ( rc = http_redirect ( http, location ) ) != 0 ) + DBGC2 ( http, "HTTP %p redirecting to \"%s\"\n", + http, location ); + if ( ( rc = xfer_redirect ( &http->xfer, LOCATION_URI_STRING, + location ) ) != 0 ) { + DBGC ( http, "HTTP %p could not redirect: %s\n", + http, strerror ( rc ) ); return rc; + } http_close ( http, 0 ); return 0; } @@ -1201,17 +1162,13 @@ static int http_parse_header ( struct http_transaction *http, char *line ) { DBGC2 ( http, "HTTP %p RX %s\n", http, line ); /* Extract header name */ - sep = strchr ( line, ':' ); + sep = strstr ( line, ": " ); if ( ! sep ) { DBGC ( http, "HTTP %p malformed header \"%s\"\n", http, line ); return -EINVAL_HEADER; } *sep = '\0'; - - /* Extract remainder of line */ - line = ( sep + 1 ); - while ( isspace ( *line ) ) - line++; + line = ( sep + 2 /* ": " */ ); /* Process header, if recognised */ for_each_table_entry ( header, HTTP_RESPONSE_HEADERS ) { @@ -1319,17 +1276,19 @@ http_response_transfer_encoding __http_response_header = { * @ret rc Return status code */ static int http_parse_connection ( struct http_transaction *http, char *line ) { - char *token; /* Check for known connection intentions */ - while ( ( token = http_token ( &line, NULL ) ) ) { - if ( strcasecmp ( token, "keep-alive" ) == 0 ) - http->response.flags |= HTTP_RESPONSE_KEEPALIVE; - if ( strcasecmp ( token, "close" ) == 0 ) - http->response.flags &= ~HTTP_RESPONSE_KEEPALIVE; + if ( strcasecmp ( line, "keep-alive" ) == 0 ) { + http->response.flags |= HTTP_RESPONSE_KEEPALIVE; + return 0; + } + if ( strcasecmp ( line, "close" ) == 0 ) { + http->response.flags &= ~HTTP_RESPONSE_KEEPALIVE; + return 0; } - return 0; + DBGC ( http, "HTTP %p unrecognised Connection \"%s\"\n", http, line ); + return -ENOTSUP_CONNECTION; } /** HTTP "Connection" header */ @@ -1867,7 +1826,7 @@ static size_t http_params ( struct parameters *params, char *buf, size_t len ) { } /* URI-encode the key */ - frag_len = uri_encode_string ( 0, param->key, buf, remaining ); + frag_len = uri_encode ( param->key, 0, buf, remaining ); buf += frag_len; len += frag_len; remaining -= frag_len; @@ -1880,7 +1839,7 @@ static size_t http_params ( struct parameters *params, char *buf, size_t len ) { remaining--; /* URI-encode the value */ - frag_len = uri_encode_string ( 0, param->value, buf, remaining); + frag_len = uri_encode ( param->value, 0, buf, remaining ); buf += frag_len; len += frag_len; remaining -= frag_len; diff --git a/roms/ipxe/src/net/tcpip.c b/roms/ipxe/src/net/tcpip.c index c9e4ee789..5ad982fd1 100644 --- a/roms/ipxe/src/net/tcpip.c +++ b/roms/ipxe/src/net/tcpip.c @@ -62,18 +62,19 @@ int tcpip_rx ( struct io_buffer *iobuf, struct net_device *netdev, /** * Find TCP/IP network-layer protocol * - * @v sa_family Address family + * @v st_dest Destination address * @ret tcpip_net TCP/IP network-layer protocol, or NULL if not found */ -struct tcpip_net_protocol * tcpip_net_protocol ( sa_family_t sa_family ) { +static struct tcpip_net_protocol * +tcpip_net_protocol ( struct sockaddr_tcpip *st_dest ) { struct tcpip_net_protocol *tcpip_net; for_each_table_entry ( tcpip_net, TCPIP_NET_PROTOCOLS ) { - if ( tcpip_net->sa_family == sa_family ) + if ( tcpip_net->sa_family == st_dest->st_family ) return tcpip_net; } - DBG ( "Unrecognised TCP/IP address family %d\n", sa_family ); + DBG ( "Unrecognised TCP/IP address family %d\n", st_dest->st_family ); return NULL; } @@ -94,7 +95,7 @@ int tcpip_tx ( struct io_buffer *iobuf, struct tcpip_protocol *tcpip_protocol, struct tcpip_net_protocol *tcpip_net; /* Hand off packet to the appropriate network-layer protocol */ - tcpip_net = tcpip_net_protocol ( st_dest->st_family ); + tcpip_net = tcpip_net_protocol ( st_dest ); if ( tcpip_net ) { DBG ( "TCP/IP sending %s packet\n", tcpip_net->name ); return tcpip_net->tx ( iobuf, tcpip_protocol, st_src, st_dest, @@ -115,7 +116,7 @@ struct net_device * tcpip_netdev ( struct sockaddr_tcpip *st_dest ) { struct tcpip_net_protocol *tcpip_net; /* Hand off to the appropriate network-layer protocol */ - tcpip_net = tcpip_net_protocol ( st_dest->st_family ); + tcpip_net = tcpip_net_protocol ( st_dest ); if ( tcpip_net ) return tcpip_net->netdev ( st_dest ); @@ -134,7 +135,7 @@ size_t tcpip_mtu ( struct sockaddr_tcpip *st_dest ) { size_t mtu; /* Find appropriate network-layer protocol */ - tcpip_net = tcpip_net_protocol ( st_dest->st_family ); + tcpip_net = tcpip_net_protocol ( st_dest ); if ( ! tcpip_net ) return 0; diff --git a/roms/ipxe/src/net/tls.c b/roms/ipxe/src/net/tls.c index 90f9f9767..db01fb291 100644 --- a/roms/ipxe/src/net/tls.c +++ b/roms/ipxe/src/net/tls.c @@ -1271,9 +1271,10 @@ static int tls_new_alert ( struct tls_session *tls, const void *data, uint8_t description; char next[0]; } __attribute__ (( packed )) *alert = data; + const void *end = alert->next; /* Sanity check */ - if ( sizeof ( *alert ) != len ) { + if ( end != ( data + len ) ) { DBGC ( tls, "TLS %p received overlength Alert\n", tls ); DBGC_HD ( tls, data, len ); return -EINVAL_ALERT; @@ -1309,28 +1310,24 @@ static int tls_new_server_hello ( struct tls_session *tls, uint16_t version; uint8_t random[32]; uint8_t session_id_len; - uint8_t session_id[0]; + char next[0]; } __attribute__ (( packed )) *hello_a = data; - const uint8_t *session_id; const struct { + uint8_t session_id[hello_a->session_id_len]; uint16_t cipher_suite; uint8_t compression_method; char next[0]; - } __attribute__ (( packed )) *hello_b; + } __attribute__ (( packed )) *hello_b = ( void * ) &hello_a->next; + const void *end = hello_b->next; uint16_t version; int rc; - /* Parse header */ - if ( ( sizeof ( *hello_a ) > len ) || - ( hello_a->session_id_len > ( len - sizeof ( *hello_a ) ) ) || - ( sizeof ( *hello_b ) > ( len - sizeof ( *hello_a ) - - hello_a->session_id_len ) ) ) { + /* Sanity check */ + if ( end > ( data + len ) ) { DBGC ( tls, "TLS %p received underlength Server Hello\n", tls ); DBGC_HD ( tls, data, len ); return -EINVAL_HELLO; } - session_id = hello_a->session_id; - hello_b = ( ( void * ) ( session_id + hello_a->session_id_len ) ); /* Check and store protocol version */ version = ntohs ( hello_a->version ); @@ -1383,7 +1380,14 @@ static int tls_new_server_hello ( struct tls_session *tls, */ static int tls_parse_chain ( struct tls_session *tls, const void *data, size_t len ) { - size_t remaining = len; + const void *end = ( data + len ); + const struct { + tls24_t length; + uint8_t data[0]; + } __attribute__ (( packed )) *certificate; + size_t certificate_len; + struct x509_certificate *cert; + const void *next; int rc; /* Free any existing certificate chain */ @@ -1398,37 +1402,25 @@ static int tls_parse_chain ( struct tls_session *tls, } /* Add certificates to chain */ - while ( remaining ) { - const struct { - tls24_t length; - uint8_t data[0]; - } __attribute__ (( packed )) *certificate = data; - size_t certificate_len; - size_t record_len; - struct x509_certificate *cert; - - /* Parse header */ - if ( sizeof ( *certificate ) > remaining ) { - DBGC ( tls, "TLS %p underlength certificate:\n", tls ); - DBGC_HDA ( tls, 0, data, remaining ); - rc = -EINVAL_CERTIFICATE; - goto err_underlength; - } + while ( data < end ) { + + /* Extract raw certificate data */ + certificate = data; certificate_len = tls_uint24 ( &certificate->length ); - if ( certificate_len > ( remaining - sizeof ( *certificate ) )){ + next = ( certificate->data + certificate_len ); + if ( next > end ) { DBGC ( tls, "TLS %p overlength certificate:\n", tls ); - DBGC_HDA ( tls, 0, data, remaining ); + DBGC_HDA ( tls, 0, data, ( end - data ) ); rc = -EINVAL_CERTIFICATE; goto err_overlength; } - record_len = ( sizeof ( *certificate ) + certificate_len ); /* Add certificate to chain */ if ( ( rc = x509_append_raw ( tls->chain, certificate->data, certificate_len ) ) != 0 ) { DBGC ( tls, "TLS %p could not append certificate: %s\n", tls, strerror ( rc ) ); - DBGC_HDA ( tls, 0, data, remaining ); + DBGC_HDA ( tls, 0, data, ( end - data ) ); goto err_parse; } cert = x509_last ( tls->chain ); @@ -1436,15 +1428,13 @@ static int tls_parse_chain ( struct tls_session *tls, tls, x509_name ( cert ) ); /* Move to next certificate in list */ - data += record_len; - remaining -= record_len; + data = next; } return 0; err_parse: err_overlength: - err_underlength: x509_chain_put ( tls->chain ); tls->chain = NULL; err_alloc_chain: @@ -1465,18 +1455,12 @@ static int tls_new_certificate ( struct tls_session *tls, tls24_t length; uint8_t certificates[0]; } __attribute__ (( packed )) *certificate = data; - size_t certificates_len; + size_t certificates_len = tls_uint24 ( &certificate->length ); + const void *end = ( certificate->certificates + certificates_len ); int rc; - /* Parse header */ - if ( sizeof ( *certificate ) > len ) { - DBGC ( tls, "TLS %p received underlength Server Certificate\n", - tls ); - DBGC_HD ( tls, data, len ); - return -EINVAL_CERTIFICATES; - } - certificates_len = tls_uint24 ( &certificate->length ); - if ( certificates_len > ( len - sizeof ( *certificate ) ) ) { + /* Sanity check */ + if ( end != ( data + len ) ) { DBGC ( tls, "TLS %p received overlength Server Certificate\n", tls ); DBGC_HD ( tls, data, len ); @@ -1537,10 +1521,11 @@ static int tls_new_server_hello_done ( struct tls_session *tls, const struct { char next[0]; } __attribute__ (( packed )) *hello_done = data; + const void *end = hello_done->next; int rc; /* Sanity check */ - if ( sizeof ( *hello_done ) != len ) { + if ( end != ( data + len ) ) { DBGC ( tls, "TLS %p received overlength Server Hello Done\n", tls ); DBGC_HD ( tls, data, len ); @@ -1572,11 +1557,12 @@ static int tls_new_finished ( struct tls_session *tls, uint8_t verify_data[12]; char next[0]; } __attribute__ (( packed )) *finished = data; + const void *end = finished->next; uint8_t digest_out[ digest->digestsize ]; uint8_t verify_data[ sizeof ( finished->verify_data ) ]; /* Sanity check */ - if ( sizeof ( *finished ) != len ) { + if ( end != ( data + len ) ) { DBGC ( tls, "TLS %p received overlength Finished\n", tls ); DBGC_HD ( tls, data, len ); return -EINVAL_FINISHED; @@ -1612,37 +1598,27 @@ static int tls_new_finished ( struct tls_session *tls, */ static int tls_new_handshake ( struct tls_session *tls, const void *data, size_t len ) { - size_t remaining = len; + const void *end = ( data + len ); int rc; - while ( remaining ) { + while ( data != end ) { const struct { uint8_t type; tls24_t length; uint8_t payload[0]; } __attribute__ (( packed )) *handshake = data; - const void *payload; - size_t payload_len; - size_t record_len; + const void *payload = &handshake->payload; + size_t payload_len = tls_uint24 ( &handshake->length ); + const void *next = ( payload + payload_len ); - /* Parse header */ - if ( sizeof ( *handshake ) > remaining ) { - DBGC ( tls, "TLS %p received underlength Handshake\n", - tls ); - DBGC_HD ( tls, data, remaining ); - return -EINVAL_HANDSHAKE; - } - payload_len = tls_uint24 ( &handshake->length ); - if ( payload_len > ( remaining - sizeof ( *handshake ) ) ) { + /* Sanity check */ + if ( next > end ) { DBGC ( tls, "TLS %p received overlength Handshake\n", tls ); DBGC_HD ( tls, data, len ); return -EINVAL_HANDSHAKE; } - payload = &handshake->payload; - record_len = ( sizeof ( *handshake ) + payload_len ); - /* Handle payload */ switch ( handshake->type ) { case TLS_SERVER_HELLO: rc = tls_new_server_hello ( tls, payload, payload_len ); @@ -1672,15 +1648,16 @@ static int tls_new_handshake ( struct tls_session *tls, * which are explicitly excluded). */ if ( handshake->type != TLS_HELLO_REQUEST ) - tls_add_handshake ( tls, data, record_len ); + tls_add_handshake ( tls, data, + sizeof ( *handshake ) + + payload_len ); /* Abort on failure */ if ( rc != 0 ) return rc; /* Move to next handshake record */ - data += record_len; - remaining -= record_len; + data = next; } return 0; diff --git a/roms/ipxe/src/net/udp.c b/roms/ipxe/src/net/udp.c index 1fbc12d48..0f7dfb24a 100644 --- a/roms/ipxe/src/net/udp.c +++ b/roms/ipxe/src/net/udp.c @@ -328,7 +328,6 @@ static int udp_rx ( struct io_buffer *iobuf, struct tcpip_protocol udp_protocol __tcpip_protocol = { .name = "UDP", .rx = udp_rx, - .zero_csum = TCPIP_NEGATIVE_ZERO_CSUM, .tcpip_proto = IP_UDP, }; diff --git a/roms/ipxe/src/net/udp/dhcp.c b/roms/ipxe/src/net/udp/dhcp.c index 9342ad21e..aed5ee360 100644 --- a/roms/ipxe/src/net/udp/dhcp.c +++ b/roms/ipxe/src/net/udp/dhcp.c @@ -296,9 +296,8 @@ static void dhcp_set_state ( struct dhcp_session *dhcp, */ static int dhcp_has_pxeopts ( struct dhcp_packet *dhcppkt ) { - /* Check for a next-server and boot filename */ - if ( dhcppkt->dhcphdr->siaddr.s_addr && - ( dhcppkt_fetch ( dhcppkt, DHCP_BOOTFILE_NAME, NULL, 0 ) > 0 ) ) + /* Check for a boot filename */ + if ( dhcppkt_fetch ( dhcppkt, DHCP_BOOTFILE_NAME, NULL, 0 ) > 0 ) return 1; /* Check for a PXE boot menu */ @@ -444,10 +443,8 @@ static void dhcp_discovery_expired ( struct dhcp_session *dhcp ) { unsigned long elapsed = ( currticks() - dhcp->start ); /* If link is blocked, defer DHCP discovery (and reset timeout) */ - if ( netdev_link_blocked ( dhcp->netdev ) && - ( dhcp->count <= DHCP_DISC_MAX_DEFERRALS ) ) { + if ( netdev_link_blocked ( dhcp->netdev ) ) { DBGC ( dhcp, "DHCP %p deferring discovery\n", dhcp ); - dhcp->start = currticks(); start_timer_fixed ( &dhcp->timer, ( DHCP_DISC_START_TIMEOUT_SEC * TICKS_PER_SEC ) ); @@ -1116,7 +1113,7 @@ static int dhcp_tx ( struct dhcp_session *dhcp ) { * session state into packet traces. Useful for extracting * debug information from non-debug builds. */ - dhcppkt.dhcphdr->secs = htons ( ( dhcp->count << 2 ) | + dhcppkt.dhcphdr->secs = htons ( ( ++(dhcp->count) << 2 ) | ( dhcp->offer.s_addr ? 0x02 : 0 ) | ( dhcp->proxy_offer ? 0x01 : 0 ) ); @@ -1260,9 +1257,6 @@ static void dhcp_timer_expired ( struct retry_timer *timer, int fail ) { return; } - /* Increment transmission counter */ - dhcp->count++; - /* Handle timer expiry based on current state */ dhcp->state->expired ( dhcp ); } diff --git a/roms/ipxe/src/net/udp/ntp.c b/roms/ipxe/src/net/udp/ntp.c deleted file mode 100644 index 11f8ccc00..000000000 --- a/roms/ipxe/src/net/udp/ntp.c +++ /dev/null @@ -1,275 +0,0 @@ -/* - * Copyright (C) 2016 Michael Brown <mbrown@fensystems.co.uk>. - * - * 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 (at your option) 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 <stdint.h> -#include <string.h> -#include <errno.h> -#include <time.h> -#include <ipxe/malloc.h> -#include <ipxe/refcnt.h> -#include <ipxe/iobuf.h> -#include <ipxe/xfer.h> -#include <ipxe/open.h> -#include <ipxe/retry.h> -#include <ipxe/timer.h> -#include <ipxe/time.h> -#include <ipxe/tcpip.h> -#include <ipxe/ntp.h> - -/** @file - * - * Network Time Protocol - * - */ - -/** An NTP client */ -struct ntp_client { - /** Reference count */ - struct refcnt refcnt; - /** Job control interface */ - struct interface job; - /** Data transfer interface */ - struct interface xfer; - /** Retransmission timer */ - struct retry_timer timer; -}; - -/** - * Close NTP client - * - * @v ntp NTP client - * @v rc Reason for close - */ -static void ntp_close ( struct ntp_client *ntp, int rc ) { - - /* Stop timer */ - stop_timer ( &ntp->timer ); - - /* Shut down interfaces */ - intf_shutdown ( &ntp->xfer, rc ); - intf_shutdown ( &ntp->job, rc ); -} - -/** - * Send NTP request - * - * @v ntp NTP client - * @ret rc Return status code - */ -static int ntp_request ( struct ntp_client *ntp ) { - struct ntp_header hdr; - int rc; - - DBGC ( ntp, "NTP %p sending request\n", ntp ); - - /* Construct header */ - memset ( &hdr, 0, sizeof ( hdr ) ); - hdr.flags = ( NTP_FL_LI_UNKNOWN | NTP_FL_VN_1 | NTP_FL_MODE_CLIENT ); - hdr.transmit.seconds = htonl ( time ( NULL ) + NTP_EPOCH ); - hdr.transmit.fraction = htonl ( NTP_FRACTION_MAGIC ); - - /* Send request */ - if ( ( rc = xfer_deliver_raw ( &ntp->xfer, &hdr, - sizeof ( hdr ) ) ) != 0 ) { - DBGC ( ntp, "NTP %p could not send request: %s\n", - ntp, strerror ( rc ) ); - return rc; - } - - return 0; -} - -/** - * Handle NTP response - * - * @v ntp NTP client - * @v iobuf I/O buffer - * @v meta Data transfer metadata - * @ret rc Return status code - */ -static int ntp_deliver ( struct ntp_client *ntp, struct io_buffer *iobuf, - struct xfer_metadata *meta ) { - struct ntp_header *hdr; - struct sockaddr_tcpip *st_src; - int32_t delta; - int rc; - - /* Check source port */ - st_src = ( ( struct sockaddr_tcpip * ) meta->src ); - if ( st_src->st_port != htons ( NTP_PORT ) ) { - DBGC ( ntp, "NTP %p received non-NTP packet:\n", ntp ); - DBGC_HDA ( ntp, 0, iobuf->data, iob_len ( iobuf ) ); - goto ignore; - } - - /* Check packet length */ - if ( iob_len ( iobuf ) < sizeof ( *hdr ) ) { - DBGC ( ntp, "NTP %p received malformed packet:\n", ntp ); - DBGC_HDA ( ntp, 0, iobuf->data, iob_len ( iobuf ) ); - goto ignore; - } - hdr = iobuf->data; - - /* Check mode */ - if ( ( hdr->flags & NTP_FL_MODE_MASK ) != NTP_FL_MODE_SERVER ) { - DBGC ( ntp, "NTP %p received non-server packet:\n", ntp ); - DBGC_HDA ( ntp, 0, iobuf->data, iob_len ( iobuf ) ); - goto ignore; - } - - /* Check magic value */ - if ( hdr->originate.fraction != htonl ( NTP_FRACTION_MAGIC ) ) { - DBGC ( ntp, "NTP %p received unrecognised packet:\n", ntp ); - DBGC_HDA ( ntp, 0, iobuf->data, iob_len ( iobuf ) ); - goto ignore; - } - - /* Check for Kiss-o'-Death packets */ - if ( ! hdr->stratum ) { - DBGC ( ntp, "NTP %p received kiss-o'-death:\n", ntp ); - DBGC_HDA ( ntp, 0, iobuf->data, iob_len ( iobuf ) ); - rc = -EPROTO; - goto close; - } - - /* Calculate clock delta */ - delta = ( ntohl ( hdr->receive.seconds ) - - ntohl ( hdr->originate.seconds ) ); - DBGC ( ntp, "NTP %p delta %d seconds\n", ntp, delta ); - - /* Adjust system clock */ - time_adjust ( delta ); - - /* Success */ - rc = 0; - - close: - ntp_close ( ntp, rc ); - ignore: - free_iob ( iobuf ); - return 0; -} - -/** - * Handle data transfer window change - * - * @v ntp NTP client - */ -static void ntp_window_changed ( struct ntp_client *ntp ) { - - /* Start timer to send initial request */ - start_timer_nodelay ( &ntp->timer ); -} - -/** Data transfer interface operations */ -static struct interface_operation ntp_xfer_op[] = { - INTF_OP ( xfer_deliver, struct ntp_client *, ntp_deliver ), - INTF_OP ( xfer_window_changed, struct ntp_client *, - ntp_window_changed ), - INTF_OP ( intf_close, struct ntp_client *, ntp_close ), -}; - -/** Data transfer interface descriptor */ -static struct interface_descriptor ntp_xfer_desc = - INTF_DESC_PASSTHRU ( struct ntp_client, xfer, ntp_xfer_op, job ); - -/** Job control interface operations */ -static struct interface_operation ntp_job_op[] = { - INTF_OP ( intf_close, struct ntp_client *, ntp_close ), -}; - -/** Job control interface descriptor */ -static struct interface_descriptor ntp_job_desc = - INTF_DESC_PASSTHRU ( struct ntp_client, job, ntp_job_op, xfer ); - -/** - * Handle NTP timer expiry - * - * @v timer Retransmission timer - * @v fail Failure indicator - */ -static void ntp_expired ( struct retry_timer *timer, int fail ) { - struct ntp_client *ntp = - container_of ( timer, struct ntp_client, timer ); - - /* Shut down client if we have failed */ - if ( fail ) { - ntp_close ( ntp, -ETIMEDOUT ); - return; - } - - /* Otherwise, restart timer and (re)transmit request */ - start_timer ( &ntp->timer ); - ntp_request ( ntp ); -} - -/** - * Start NTP client - * - * @v job Job control interface - * @v hostname NTP server - * @ret rc Return status code - */ -int start_ntp ( struct interface *job, const char *hostname ) { - struct ntp_client *ntp; - union { - struct sockaddr_tcpip st; - struct sockaddr sa; - } server; - int rc; - - /* Allocate and initialise structure*/ - ntp = zalloc ( sizeof ( *ntp ) ); - if ( ! ntp ) { - rc = -ENOMEM; - goto err_alloc; - } - ref_init ( &ntp->refcnt, NULL ); - intf_init ( &ntp->job, &ntp_job_desc, &ntp->refcnt ); - intf_init ( &ntp->xfer, &ntp_xfer_desc, &ntp->refcnt ); - timer_init ( &ntp->timer, ntp_expired, &ntp->refcnt ); - set_timer_limits ( &ntp->timer, NTP_MIN_TIMEOUT, NTP_MAX_TIMEOUT ); - - /* Open socket */ - memset ( &server, 0, sizeof ( server ) ); - server.st.st_port = htons ( NTP_PORT ); - if ( ( rc = xfer_open_named_socket ( &ntp->xfer, SOCK_DGRAM, &server.sa, - hostname, NULL ) ) != 0 ) { - DBGC ( ntp, "NTP %p could not open socket: %s\n", - ntp, strerror ( rc ) ); - goto err_open; - } - - /* Attach parent interface, mortalise self, and return */ - intf_plug_plug ( &ntp->job, job ); - ref_put ( &ntp->refcnt ); - return 0; - - err_open: - ntp_close ( ntp, rc ); - ref_put ( &ntp->refcnt ); - err_alloc: - return rc; -} diff --git a/roms/ipxe/src/net/udp/slam.c b/roms/ipxe/src/net/udp/slam.c index 8fcc97632..8b26bfb3c 100644 --- a/roms/ipxe/src/net/udp/slam.c +++ b/roms/ipxe/src/net/udp/slam.c @@ -415,8 +415,6 @@ static int slam_pull_value ( struct slam_request *slam, static int slam_pull_header ( struct slam_request *slam, struct io_buffer *iobuf ) { void *header = iobuf->data; - unsigned long total_bytes; - unsigned long block_size; int rc; /* If header matches cached header, just pull it and return */ @@ -433,26 +431,22 @@ static int slam_pull_header ( struct slam_request *slam, */ if ( ( rc = slam_pull_value ( slam, iobuf, NULL ) ) != 0 ) return rc; - if ( ( rc = slam_pull_value ( slam, iobuf, &total_bytes ) ) != 0 ) + if ( ( rc = slam_pull_value ( slam, iobuf, + &slam->total_bytes ) ) != 0 ) return rc; - if ( ( rc = slam_pull_value ( slam, iobuf, &block_size ) ) != 0 ) + if ( ( rc = slam_pull_value ( slam, iobuf, + &slam->block_size ) ) != 0 ) return rc; - /* Sanity check */ - if ( block_size == 0 ) { - DBGC ( slam, "SLAM %p ignoring zero block size\n", slam ); - return -EINVAL; - } - /* Update the cached header */ slam->header_len = ( iobuf->data - header ); assert ( slam->header_len <= sizeof ( slam->header ) ); memcpy ( slam->header, header, slam->header_len ); /* Calculate number of blocks */ - slam->total_bytes = total_bytes; - slam->block_size = block_size; - slam->num_blocks = ( ( total_bytes + block_size - 1 ) / block_size ); + slam->num_blocks = ( ( slam->total_bytes + slam->block_size - 1 ) / + slam->block_size ); + DBGC ( slam, "SLAM %p has total bytes %ld, block size %ld, num " "blocks %ld\n", slam, slam->total_bytes, slam->block_size, slam->num_blocks ); diff --git a/roms/ipxe/src/net/udp/tftp.c b/roms/ipxe/src/net/udp/tftp.c index 4255472ee..953bcb46a 100644 --- a/roms/ipxe/src/net/udp/tftp.c +++ b/roms/ipxe/src/net/udp/tftp.c @@ -325,7 +325,7 @@ void tftp_set_mtftp_port ( unsigned int port ) { * @ret rc Return status code */ static int tftp_send_rrq ( struct tftp_request *tftp ) { - const char *path = ( tftp->uri->path + 1 /* skip '/' */ ); + const char *path = tftp->uri->path; struct tftp_rrq *rrq; size_t len; struct io_buffer *iobuf; @@ -1067,8 +1067,6 @@ static int tftp_core_open ( struct interface *xfer, struct uri *uri, return -EINVAL; if ( ! uri->path ) return -EINVAL; - if ( uri->path[0] != '/' ) - return -EINVAL; /* Allocate and populate TFTP structure */ tftp = zalloc ( sizeof ( *tftp ) ); @@ -1182,12 +1180,13 @@ struct uri_opener mtftp_uri_opener __uri_opener = { */ static int tftp_apply_settings ( void ) { static struct in_addr tftp_server = { 0 }; - struct in_addr new_tftp_server; + struct in_addr last_tftp_server; char uri_string[32]; struct uri *uri; /* Retrieve TFTP server setting */ - fetch_ipv4_setting ( NULL, &next_server_setting, &new_tftp_server ); + last_tftp_server = tftp_server; + fetch_ipv4_setting ( NULL, &next_server_setting, &tftp_server ); /* If TFTP server setting has changed, set the current working * URI to match. Do it only when the TFTP server has changed @@ -1196,19 +1195,18 @@ static int tftp_apply_settings ( void ) { * an unrelated setting and triggered all the settings * applicators. */ - if ( new_tftp_server.s_addr && - ( new_tftp_server.s_addr != tftp_server.s_addr ) ) { - DBGC ( &tftp_server, "TFTP server changed %s => ", - inet_ntoa ( tftp_server ) ); - DBGC ( &tftp_server, "%s\n", inet_ntoa ( new_tftp_server ) ); - snprintf ( uri_string, sizeof ( uri_string ), - "tftp://%s/", inet_ntoa ( new_tftp_server ) ); - uri = parse_uri ( uri_string ); - if ( ! uri ) - return -ENOMEM; + if ( tftp_server.s_addr != last_tftp_server.s_addr ) { + if ( tftp_server.s_addr ) { + snprintf ( uri_string, sizeof ( uri_string ), + "tftp://%s/", inet_ntoa ( tftp_server ) ); + uri = parse_uri ( uri_string ); + if ( ! uri ) + return -ENOMEM; + } else { + uri = NULL; + } churi ( uri ); uri_put ( uri ); - tftp_server = new_tftp_server; } return 0; diff --git a/roms/ipxe/src/net/validator.c b/roms/ipxe/src/net/validator.c index 57ad0e7b6..db968398a 100644 --- a/roms/ipxe/src/net/validator.c +++ b/roms/ipxe/src/net/validator.c @@ -41,7 +41,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <ipxe/crc32.h> #include <ipxe/ocsp.h> #include <ipxe/validator.h> -#include <config/crypto.h> /** @file * @@ -134,7 +133,7 @@ const struct setting crosscert_setting __setting ( SETTING_CRYPTO, crosscert )={ }; /** Default cross-signed certificate source */ -static const char crosscert_default[] = CROSSCERT; +static const char crosscert_default[] = "http://ca.ipxe.org/auto"; /** * Append cross-signing certificates to certificate chain diff --git a/roms/ipxe/src/tests/bitops_test.c b/roms/ipxe/src/tests/bitops_test.c deleted file mode 100644 index f29fc6801..000000000 --- a/roms/ipxe/src/tests/bitops_test.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (C) 2016 Michael Brown <mbrown@fensystems.co.uk>. - * - * 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 (at your option) 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 ); - -/** @file - * - * Bit operations self-tests - * - */ - -/* Forcibly enable assertions */ -#undef NDEBUG - -#include <stdint.h> -#include <string.h> -#include <assert.h> -#include <ipxe/bitops.h> -#include <ipxe/test.h> - -/** - * Perform bit operations self-tests - * - */ -static void bitops_test_exec ( void ) { - uint8_t bits[32]; - - /* Initialise bits */ - memset ( bits, 0, sizeof ( bits ) ); - - /* Test set_bit() */ - set_bit ( 0, bits ); - ok ( bits[0] == 0x01 ); - set_bit ( 17, bits ); - ok ( bits[2] == 0x02 ); - set_bit ( 22, bits ); - ok ( bits[2] == 0x42 ); - set_bit ( 22, bits ); - ok ( bits[2] == 0x42 ); - - /* Test clear_bit() */ - clear_bit ( 0, bits ); - ok ( bits[0] == 0x00 ); - bits[5] = 0xff; - clear_bit ( 42, bits ); - ok ( bits[5] == 0xfb ); - clear_bit ( 42, bits ); - ok ( bits[5] == 0xfb ); - clear_bit ( 44, bits ); - ok ( bits[5] == 0xeb ); - - /* Test test_and_set_bit() */ - ok ( test_and_set_bit ( 0, bits ) == 0 ); - ok ( bits[0] == 0x01 ); - ok ( test_and_set_bit ( 0, bits ) != 0 ); - ok ( bits[0] == 0x01 ); - ok ( test_and_set_bit ( 69, bits ) == 0 ); - ok ( bits[8] == 0x20 ); - ok ( test_and_set_bit ( 69, bits ) != 0 ); - ok ( bits[8] == 0x20 ); - ok ( test_and_set_bit ( 69, bits ) != 0 ); - ok ( bits[8] == 0x20 ); - - /* Test test_and_clear_bit() */ - ok ( test_and_clear_bit ( 0, bits ) != 0 ); - ok ( bits[0] == 0x00 ); - ok ( test_and_clear_bit ( 0, bits ) == 0 ); - ok ( bits[0] == 0x00 ); - bits[31] = 0xeb; - ok ( test_and_clear_bit ( 255, bits ) != 0 ); - ok ( bits[31] == 0x6b ); - ok ( test_and_clear_bit ( 255, bits ) == 0 ); - ok ( bits[31] == 0x6b ); - ok ( test_and_clear_bit ( 255, bits ) == 0 ); - ok ( bits[31] == 0x6b ); -} - -/** Bit operations self-test */ -struct self_test bitops_test __self_test = { - .name = "bitops", - .exec = bitops_test_exec, -}; diff --git a/roms/ipxe/src/arch/x86/tests/comboot/shuffle-simple.asm b/roms/ipxe/src/tests/comboot/shuffle-simple.asm index fa574bd72..efc7d9b46 100644 --- a/roms/ipxe/src/arch/x86/tests/comboot/shuffle-simple.asm +++ b/roms/ipxe/src/tests/comboot/shuffle-simple.asm @@ -2,7 +2,7 @@ org 100h jmp start - + shuffle_start: push 0xB800 pop es @@ -37,3 +37,4 @@ source: dd 0 dd shuffle_len num_shuffle_descriptors equ 1 + diff --git a/roms/ipxe/src/arch/x86/tests/comboot/version.asm b/roms/ipxe/src/tests/comboot/version.asm index 011404239..011404239 100644 --- a/roms/ipxe/src/arch/x86/tests/comboot/version.asm +++ b/roms/ipxe/src/tests/comboot/version.asm diff --git a/roms/ipxe/src/arch/i386/tests/gdbstub_test.S b/roms/ipxe/src/tests/gdbstub_test.S index 739b0527a..739b0527a 100644 --- a/roms/ipxe/src/arch/i386/tests/gdbstub_test.S +++ b/roms/ipxe/src/tests/gdbstub_test.S diff --git a/roms/ipxe/src/arch/i386/tests/gdbstub_test.gdb b/roms/ipxe/src/tests/gdbstub_test.gdb index bcfa07dae..bcfa07dae 100755 --- a/roms/ipxe/src/arch/i386/tests/gdbstub_test.gdb +++ b/roms/ipxe/src/tests/gdbstub_test.gdb diff --git a/roms/ipxe/src/tests/iobuf_test.c b/roms/ipxe/src/tests/iobuf_test.c deleted file mode 100644 index a417c2e8c..000000000 --- a/roms/ipxe/src/tests/iobuf_test.c +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (C) 2016 Michael Brown <mbrown@fensystems.co.uk>. - * - * 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 (at your option) 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 ); - -/** @file - * - * I/O buffer tests - * - */ - -/* Forcibly enable assertions */ -#undef NDEBUG - -#include <stdint.h> -#include <string.h> -#include <assert.h> -#include <ipxe/iobuf.h> -#include <ipxe/io.h> -#include <ipxe/test.h> - -/* Forward declaration */ -struct self_test iobuf_test __self_test; - -/** - * Report I/O buffer allocation test result - * - * @v len Required length of buffer - * @v align Physical alignment - * @v offset Offset from physical alignment - * @v file Test code file - * @v line Test code line - */ -static inline void alloc_iob_okx ( size_t len, size_t align, size_t offset, - const char *file, unsigned int line ) { - struct io_buffer *iobuf; - - /* Allocate I/O buffer */ - iobuf = alloc_iob_raw ( len, align, offset ); - okx ( iobuf != NULL, file, line ); - DBGC ( &iobuf_test, "IOBUF %p (%#08lx+%#zx) for %#zx align %#zx " - "offset %#zx\n", iobuf, virt_to_phys ( iobuf->data ), - iob_tailroom ( iobuf ), len, align, offset ); - - /* Validate requested length and alignment */ - okx ( ( ( ( intptr_t ) iobuf ) & ( __alignof__ ( *iobuf ) - 1 ) ) == 0, - file, line ); - okx ( iob_tailroom ( iobuf ) >= len, file, line ); - okx ( ( ( align == 0 ) || - ( ( virt_to_phys ( iobuf->data ) & ( align - 1 ) ) == - ( offset & ( align - 1 ) ) ) ), file, line ); - - /* Overwrite entire content of I/O buffer (for Valgrind) */ - memset ( iob_put ( iobuf, len ), 0x55, len ); - - /* Free I/O buffer */ - free_iob ( iobuf ); -} -#define alloc_iob_ok( len, align, offset ) \ - alloc_iob_okx ( len, align, offset, __FILE__, __LINE__ ) - -/** - * Report I/O buffer allocation failure test result - * - * @v len Required length of buffer - * @v align Physical alignment - * @v offset Offset from physical alignment - * @v file Test code file - * @v line Test code line - */ -static inline void alloc_iob_fail_okx ( size_t len, size_t align, size_t offset, - const char *file, unsigned int line ) { - struct io_buffer *iobuf; - - /* Allocate I/O buffer */ - iobuf = alloc_iob_raw ( len, align, offset ); - okx ( iobuf == NULL, file, line ); -} -#define alloc_iob_fail_ok( len, align, offset ) \ - alloc_iob_fail_okx ( len, align, offset, __FILE__, __LINE__ ) - -/** - * Perform I/O buffer self-tests - * - */ -static void iobuf_test_exec ( void ) { - - /* Check zero-length allocations */ - alloc_iob_ok ( 0, 0, 0 ); - alloc_iob_ok ( 0, 0, 1 ); - alloc_iob_ok ( 0, 1, 0 ); - alloc_iob_ok ( 0, 1024, 0 ); - alloc_iob_ok ( 0, 139, -17 ); - - /* Check various sensible allocations */ - alloc_iob_ok ( 1, 0, 0 ); - alloc_iob_ok ( 16, 16, 0 ); - alloc_iob_ok ( 64, 0, 0 ); - alloc_iob_ok ( 65, 0, 0 ); - alloc_iob_ok ( 65, 1024, 19 ); - alloc_iob_ok ( 1536, 1536, 0 ); - alloc_iob_ok ( 2048, 2048, 0 ); - alloc_iob_ok ( 2048, 2048, -10 ); - - /* Excessively large or excessively aligned allocations should fail */ - alloc_iob_fail_ok ( -1UL, 0, 0 ); - alloc_iob_fail_ok ( -1UL, 1024, 0 ); - alloc_iob_fail_ok ( 0, -1UL, 0 ); - alloc_iob_fail_ok ( 1024, -1UL, 0 ); -} - -/** I/O buffer self-test */ -struct self_test iobuf_test __self_test = { - .name = "iobuf", - .exec = iobuf_test_exec, -}; diff --git a/roms/ipxe/src/tests/rsa_test.c b/roms/ipxe/src/tests/rsa_test.c index 91066faab..c0d05d263 100644 --- a/roms/ipxe/src/tests/rsa_test.c +++ b/roms/ipxe/src/tests/rsa_test.c @@ -34,7 +34,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); /* Forcibly enable assertions */ #undef NDEBUG -#include <string.h> #include <ipxe/crypto.h> #include <ipxe/rsa.h> #include <ipxe/md5.h> diff --git a/roms/ipxe/src/tests/settings_test.c b/roms/ipxe/src/tests/settings_test.c index 828901b06..f7fb35d0d 100644 --- a/roms/ipxe/src/tests/settings_test.c +++ b/roms/ipxe/src/tests/settings_test.c @@ -166,12 +166,6 @@ static struct setting test_string_setting = { .type = &setting_type_string, }; -/** Test URI-encoded string setting */ -static struct setting test_uristring_setting = { - .name = "test_uristring", - .type = &setting_type_uristring, -}; - /** Test IPv4 address setting type */ static struct setting test_ipv4_setting = { .name = "test_ipv4", @@ -271,16 +265,6 @@ static void settings_test_exec ( void ) { fetchf_ok ( &test_settings, &test_string_setting, RAW ( 'w', 'o', 'r', 'l', 'd' ), "world" ); - /* "uristring" setting type */ - storef_ok ( &test_settings, &test_uristring_setting, "hello%20world", - RAW ( 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', - 'd' ) ); - fetchf_ok ( &test_settings, &test_uristring_setting, - RAW ( 1, 2, 3, 4, 5 ), "%01%02%03%04%05" ); - fetchf_ok ( &test_settings, &test_uristring_setting, - RAW ( 0, ' ', '%', '/', '#', ':', '@', '?', '=', '&' ), - "%00%20%25%2F%23%3A%40%3F%3D%26" ); - /* "ipv4" setting type */ storef_ok ( &test_settings, &test_ipv4_setting, "192.168.0.1", RAW ( 192, 168, 0, 1 ) ); @@ -422,9 +406,7 @@ static void settings_test_exec ( void ) { /* "busdevfn" setting type (no store capability) */ fetchf_ok ( &test_settings, &test_busdevfn_setting, - RAW ( 0x03, 0x45 ), "0000:03:08.5" ); - fetchf_ok ( &test_settings, &test_busdevfn_setting, - RAW ( 0x00, 0x02, 0x0a, 0x21 ), "0002:0a:04.1" ); + RAW ( 0x03, 0x45 ), "03:08.5" ); /* Clear and unregister test settings block */ clear_settings ( &test_settings ); diff --git a/roms/ipxe/src/tests/tcpip_test.c b/roms/ipxe/src/tests/tcpip_test.c index fac0ec26d..759f886bc 100644 --- a/roms/ipxe/src/tests/tcpip_test.c +++ b/roms/ipxe/src/tests/tcpip_test.c @@ -94,12 +94,6 @@ TCPIP_TEST ( one_byte, DATA ( 0xeb ) ); /** Double byte */ TCPIP_TEST ( two_bytes, DATA ( 0xba, 0xbe ) ); -/** Positive zero data */ -TCPIP_TEST ( positive_zero, DATA ( 0x00, 0x00 ) ); - -/** Negative zero data */ -TCPIP_TEST ( negative_zero, DATA ( 0xff, 0xff ) ); - /** Final wrap-around carry (big-endian) */ TCPIP_TEST ( final_carry_big, DATA ( 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ) ); @@ -132,17 +126,9 @@ TCPIP_RANDOM_TEST ( partial, 0xcafebabe, 121, 5 ); * * This is a reference implementation taken from RFC1071 (and modified * to fix compilation without warnings under gcc). - * - * The initial value of the one's complement @c sum is changed from - * positive zero (0x0000) to negative zero (0xffff). This ensures - * that the return value will always use the positive representation - * of zero (0x0000). Without this change, the return value would use - * negative zero (0xffff) if the input data is zero length (or all - * zeros) but positive zero (0x0000) for any other data which sums to - * zero. */ static uint16_t rfc_tcpip_chksum ( const void *data, size_t len ) { - unsigned long sum = 0xffff; + unsigned long sum = 0; while ( len > 1 ) { sum += *( ( uint16_t * ) data ); @@ -156,7 +142,6 @@ static uint16_t rfc_tcpip_chksum ( const void *data, size_t len ) { while ( sum >> 16 ) sum = ( ( sum & 0xffff ) + ( sum >> 16 ) ); - assert ( sum != 0x0000 ); return ~sum; } @@ -242,8 +227,6 @@ static void tcpip_test_exec ( void ) { tcpip_ok ( &empty ); tcpip_ok ( &one_byte ); tcpip_ok ( &two_bytes ); - tcpip_ok ( &positive_zero ); - tcpip_ok ( &negative_zero ); tcpip_ok ( &final_carry_big ); tcpip_ok ( &final_carry_little ); tcpip_random_ok ( &random_aligned ); diff --git a/roms/ipxe/src/tests/tests.c b/roms/ipxe/src/tests/tests.c index 0ec885f4f..54ce86677 100644 --- a/roms/ipxe/src/tests/tests.c +++ b/roms/ipxe/src/tests/tests.c @@ -67,5 +67,3 @@ REQUIRE_OBJECT ( profile_test ); REQUIRE_OBJECT ( setjmp_test ); REQUIRE_OBJECT ( pccrc_test ); REQUIRE_OBJECT ( linebuf_test ); -REQUIRE_OBJECT ( iobuf_test ); -REQUIRE_OBJECT ( bitops_test ); diff --git a/roms/ipxe/src/tests/uri_test.c b/roms/ipxe/src/tests/uri_test.c index 92c2f9037..da7fb8abe 100644 --- a/roms/ipxe/src/tests/uri_test.c +++ b/roms/ipxe/src/tests/uri_test.c @@ -35,7 +35,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <string.h> #include <byteswap.h> #include <ipxe/uri.h> -#include <ipxe/tcpip.h> #include <ipxe/params.h> #include <ipxe/test.h> @@ -67,15 +66,12 @@ struct uri_resolve_test { const char *resolved; }; -/** A PXE URI test */ -struct uri_pxe_test { - /** Server address */ - union { - struct sockaddr sa; - struct sockaddr_in sin; - struct sockaddr_in6 sin6; - struct sockaddr_tcpip st; - } server; +/** A TFTP URI test */ +struct uri_tftp_test { + /** Next-server address */ + struct in_addr next_server; + /** Port number */ + unsigned int port; /** Filename */ const char *filename; /** URI */ @@ -327,20 +323,20 @@ static void uri_resolve_path_okx ( struct uri_resolve_test *test, uri_resolve_path_okx ( test, __FILE__, __LINE__ ) /** - * Report URI PXE test result + * Report URI TFTP test result * - * @v test URI PXE test + * @v test URI TFTP test * @v file Test code file * @v line Test code line */ -static void uri_pxe_okx ( struct uri_pxe_test *test, const char *file, - unsigned int line ) { +static void uri_tftp_okx ( struct uri_tftp_test *test, const char *file, + unsigned int line ) { char buf[ strlen ( test->string ) + 1 /* NUL */ ]; struct uri *uri; size_t len; /* Construct URI */ - uri = pxe_uri ( &test->server.sa, test->filename ); + uri = tftp_uri ( test->next_server, test->port, test->filename ); okx ( uri != NULL, file, line ); if ( uri ) { uri_okx ( uri, &test->uri, file, line ); @@ -350,7 +346,7 @@ static void uri_pxe_okx ( struct uri_pxe_test *test, const char *file, } uri_put ( uri ); } -#define uri_pxe_ok( test ) uri_pxe_okx ( test, __FILE__, __LINE__ ) +#define uri_tftp_ok( test ) uri_tftp_okx ( test, __FILE__, __LINE__ ) /** * Report current working URI test result @@ -499,18 +495,6 @@ static struct uri_test uri_mailto = { { .scheme = "mailto", .opaque = "ipxe-devel@lists.ipxe.org" } }; -/** Basic path-only URI */ -static struct uri_test uri_path = { - "/var/lib/tftpboot/pxelinux.0", - { .path = "/var/lib/tftpboot/pxelinux.0" }, -}; - -/** Path-only URI with escaped characters */ -static struct uri_test uri_path_escaped = { - "/hello%20world%3F", - { .path = "/hello world?" }, -}; - /** HTTP URI with all the trimmings */ static struct uri_test uri_http_all = { "http://anon:password@example.com:3001/~foo/cgi-bin/foo.pl?a=b&c=d#bit", @@ -610,34 +594,6 @@ static struct uri_test uri_iscsi = { }, }; -/** File URI with relative (opaque) path */ -static struct uri_test uri_file_relative = { - "file:boot/script.ipxe", - { - .scheme = "file", - .opaque = "boot/script.ipxe", - }, -}; - -/** File URI with absolute path */ -static struct uri_test uri_file_absolute = { - "file:/boot/script.ipxe", - { - .scheme = "file", - .path = "/boot/script.ipxe", - }, -}; - -/** File URI with volume name */ -static struct uri_test uri_file_volume = { - "file://hpilo/boot/script.ipxe", - { - .scheme = "file", - .host = "hpilo", - .path = "/boot/script.ipxe", - }, -}; - /** URI with port number */ static struct uri_port_test uri_explicit_port = { "http://192.168.0.1:8080/boot.php", @@ -722,96 +678,53 @@ static struct uri_resolve_test uri_fragment = { "http://192.168.0.254/test#bar", }; -/** PXE URI with absolute URI */ -static struct uri_pxe_test uri_pxe_absolute = { - { - /* 192.168.0.3 */ - .sin = { - .sin_family = AF_INET, - .sin_addr = { .s_addr = htonl ( 0xc0a80003 ) }, - }, - }, - "http://not.a.tftp/uri", - { - .scheme = "http", - .host = "not.a.tftp", - .path = "/uri", - }, - "http://not.a.tftp/uri", -}; - -/** PXE URI with absolute path */ -static struct uri_pxe_test uri_pxe_absolute_path = { - { - /* 192.168.0.2 */ - .sin = { - .sin_family = AF_INET, - .sin_addr = { .s_addr = htonl ( 0xc0a80002 ) }, - }, - }, +/** TFTP URI with absolute path */ +static struct uri_tftp_test uri_tftp_absolute = { + { .s_addr = htonl ( 0xc0a80002 ) /* 192.168.0.2 */ }, 0, "/absolute/path", { .scheme = "tftp", .host = "192.168.0.2", - .path = "//absolute/path", + .path = "/absolute/path", }, - "tftp://192.168.0.2//absolute/path", + "tftp://192.168.0.2/absolute/path", }; -/** PXE URI with relative path */ -static struct uri_pxe_test uri_pxe_relative_path = { - { - /* 192.168.0.3 */ - .sin = { - .sin_family = AF_INET, - .sin_addr = { .s_addr = htonl ( 0xc0a80003 ) }, - }, - }, +/** TFTP URI with relative path */ +static struct uri_tftp_test uri_tftp_relative = { + { .s_addr = htonl ( 0xc0a80003 ) /* 192.168.0.3 */ }, 0, "relative/path", { .scheme = "tftp", .host = "192.168.0.3", - .path = "/relative/path", + .path = "relative/path", }, "tftp://192.168.0.3/relative/path", }; -/** PXE URI with path containing special characters */ -static struct uri_pxe_test uri_pxe_icky = { - { - /* 10.0.0.6 */ - .sin = { - .sin_family = AF_INET, - .sin_addr = { .s_addr = htonl ( 0x0a000006 ) }, - }, - }, +/** TFTP URI with path containing special characters */ +static struct uri_tftp_test uri_tftp_icky = { + { .s_addr = htonl ( 0x0a000006 ) /* 10.0.0.6 */ }, 0, "C:\\tftpboot\\icky#path", { .scheme = "tftp", .host = "10.0.0.6", - .path = "/C:\\tftpboot\\icky#path", + .path = "C:\\tftpboot\\icky#path", }, "tftp://10.0.0.6/C%3A\\tftpboot\\icky%23path", }; -/** PXE URI with custom port */ -static struct uri_pxe_test uri_pxe_port = { - { - /* 192.168.0.1:4069 */ - .sin = { - .sin_family = AF_INET, - .sin_addr = { .s_addr = htonl ( 0xc0a80001 ) }, - .sin_port = htons ( 4069 ), - }, - }, +/** TFTP URI with custom port */ +static struct uri_tftp_test uri_tftp_port = { + { .s_addr = htonl ( 0xc0a80001 ) /* 192.168.0.1 */ }, 4069, "/another/path", { .scheme = "tftp", .host = "192.168.0.1", .port = "4069", - .path = "//another/path", + .path = "/another/path", }, - "tftp://192.168.0.1:4069//another/path", + "tftp://192.168.0.1:4069/another/path", }; /** Current working URI test */ @@ -917,8 +830,6 @@ static void uri_test_exec ( void ) { uri_parse_format_dup_ok ( &uri_empty ); uri_parse_format_dup_ok ( &uri_boot_ipxe_org ); uri_parse_format_dup_ok ( &uri_mailto ); - uri_parse_format_dup_ok ( &uri_path ); - uri_parse_format_dup_ok ( &uri_path_escaped ); uri_parse_format_dup_ok ( &uri_http_all ); uri_parse_format_dup_ok ( &uri_http_escaped ); uri_parse_ok ( &uri_http_escaped_improper ); /* Parse only */ @@ -927,9 +838,6 @@ static void uri_test_exec ( void ) { uri_parse_format_dup_ok ( &uri_ipv6_local ); uri_parse_ok ( &uri_ipv6_local_non_conforming ); /* Parse only */ uri_parse_format_dup_ok ( &uri_iscsi ); - uri_parse_format_dup_ok ( &uri_file_relative ); - uri_parse_format_dup_ok ( &uri_file_absolute ); - uri_parse_format_dup_ok ( &uri_file_volume ); /** URI port number tests */ uri_port_ok ( &uri_explicit_port ); @@ -949,12 +857,11 @@ static void uri_test_exec ( void ) { uri_resolve_ok ( &uri_query ); uri_resolve_ok ( &uri_fragment ); - /* PXE URI construction tests */ - uri_pxe_ok ( &uri_pxe_absolute ); - uri_pxe_ok ( &uri_pxe_absolute_path ); - uri_pxe_ok ( &uri_pxe_relative_path ); - uri_pxe_ok ( &uri_pxe_icky ); - uri_pxe_ok ( &uri_pxe_port ); + /* TFTP URI construction tests */ + uri_tftp_ok ( &uri_tftp_absolute ); + uri_tftp_ok ( &uri_tftp_relative ); + uri_tftp_ok ( &uri_tftp_icky ); + uri_tftp_ok ( &uri_tftp_port ); /* Current working URI tests */ uri_churi_ok ( uri_churi ); diff --git a/roms/ipxe/src/tests/vsprintf_test.c b/roms/ipxe/src/tests/vsprintf_test.c index f388b3ded..0ad4f1c56 100644 --- a/roms/ipxe/src/tests/vsprintf_test.c +++ b/roms/ipxe/src/tests/vsprintf_test.c @@ -39,32 +39,21 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); /** * Report an snprintf() test result * - * @v len Buffer length - * @v expected Expected result - * @v file Test code file - * @v line Test code line - * @v format Format string - * @v ... Arguments */ -static void snprintf_okx ( size_t len, const char *expected, const char *file, - unsigned int line, const char *fmt, ... ) { - char actual[len]; - size_t actual_len; - va_list args; - - va_start ( args, fmt ); - actual_len = vsnprintf ( actual, sizeof ( actual ), fmt, args ); - va_end ( args ); - okx ( actual_len >= strlen ( expected ), file, line ); - okx ( strcmp ( actual, expected ) == 0, file, line ); - if ( strcmp ( actual, expected ) != 0 ) { - DBG ( "SNPRINTF expected \"%s\", got \"%s\"\n", - expected, actual ); - } -} -#define snprintf_ok( len, result, format, ... ) \ - snprintf_okx ( len, result, __FILE__, __LINE__, format, \ - ##__VA_ARGS__ ) +#define snprintf_ok( len, result, format, ... ) do { \ + char actual[ (len) ]; \ + const char expected[] = result; \ + size_t actual_len; \ + \ + actual_len = snprintf ( actual, sizeof ( actual ), \ + format, ##__VA_ARGS__ ); \ + ok ( actual_len >= strlen ( result ) ); \ + ok ( strcmp ( actual, expected ) == 0 ); \ + if ( strcmp ( actual, expected ) != 0 ) { \ + DBG ( "SNPRINTF expected \"%s\", got \"%s\"\n", \ + expected, actual ); \ + } \ + } while ( 0 ) /** * Perform vsprintf() self-tests @@ -108,10 +97,6 @@ static void vsprintf_test_exec ( void ) { snprintf_ok ( 64, "PCI 00:1f.3", "PCI %02x:%02x.%x", 0x00, 0x1f, 0x03 ); snprintf_ok ( 64, "Region [1000000,3f000000)", "Region [%llx,%llx)", 0x1000000ULL, 0x3f000000ULL ); - - /* Null string (used for debug messages) */ - snprintf_ok ( 16, "<NULL>", "%s", ( ( char * ) NULL ) ); - snprintf_ok ( 16, "<NULL>", "%ls", ( ( wchar_t * ) NULL ) ); } /** vsprintf() self-test */ diff --git a/roms/ipxe/src/usr/autoboot.c b/roms/ipxe/src/usr/autoboot.c index 57bf96ef2..912543828 100644 --- a/roms/ipxe/src/usr/autoboot.c +++ b/roms/ipxe/src/usr/autoboot.c @@ -87,6 +87,33 @@ __weak int pxe_menu_boot ( struct net_device *netdev __unused ) { return -ENOTSUP; } +/** + * Parse next-server and filename into a URI + * + * @v next_server Next-server address + * @v filename Filename + * @ret uri URI, or NULL on failure + */ +static struct uri * parse_next_server_and_filename ( struct in_addr next_server, + const char *filename ) { + struct uri *uri; + + /* Parse filename */ + uri = parse_uri ( filename ); + if ( ! uri ) + return NULL; + + /* Construct a TFTP URI for the filename, if applicable */ + if ( next_server.s_addr && filename[0] && ! uri_is_absolute ( uri ) ) { + uri_put ( uri ); + uri = tftp_uri ( next_server, 0, filename ); + if ( ! uri ) + return NULL; + } + + return uri; +} + /** The "keep-san" setting */ const struct setting keep_san_setting __setting ( SETTING_SANBOOT_EXTRA, keep-san ) = { @@ -127,9 +154,7 @@ int uriboot ( struct uri *filename, struct uri *root_path, int drive, /* Hook SAN device, if applicable */ if ( root_path ) { - drive = san_hook ( root_path, drive ); - if ( drive < 0 ) { - rc = drive; + if ( ( rc = san_hook ( root_path, drive ) ) != 0 ) { printf ( "Could not open SAN device: %s\n", strerror ( rc ) ); goto err_san_hook; @@ -138,7 +163,7 @@ int uriboot ( struct uri *filename, struct uri *root_path, int drive, } /* Describe SAN device, if applicable */ - if ( ! ( flags & URIBOOT_NO_SAN_DESCRIBE ) ) { + if ( ( drive >= 0 ) && ! ( flags & URIBOOT_NO_SAN_DESCRIBE ) ) { if ( ( rc = san_describe ( drive ) ) != 0 ) { printf ( "Could not describe SAN device %#02x: %s\n", drive, strerror ( rc ) ); @@ -172,7 +197,7 @@ int uriboot ( struct uri *filename, struct uri *root_path, int drive, } /* Attempt SAN boot if applicable */ - if ( ! ( flags & URIBOOT_NO_SAN_BOOT ) ) { + if ( ( drive >= 0 ) && ! ( flags & URIBOOT_NO_SAN_BOOT ) ) { if ( fetch_intz_setting ( NULL, &skip_san_boot_setting) == 0 ) { printf ( "Booting from SAN device %#02x\n", drive ); rc = san_boot ( drive ); @@ -190,7 +215,7 @@ int uriboot ( struct uri *filename, struct uri *root_path, int drive, err_download: err_san_describe: /* Unhook SAN device, if applicable */ - if ( ! ( flags & URIBOOT_NO_SAN_UNHOOK ) ) { + if ( ( drive >= 0 ) && ! ( flags & URIBOOT_NO_SAN_UNHOOK ) ) { if ( fetch_intz_setting ( NULL, &keep_san_setting ) == 0 ) { san_unhook ( drive ); printf ( "Unregistered SAN device %#02x\n", drive ); @@ -225,17 +250,11 @@ static void close_all_netdevs ( void ) { * @ret uri URI, or NULL on failure */ struct uri * fetch_next_server_and_filename ( struct settings *settings ) { - union { - struct sockaddr sa; - struct sockaddr_in sin; - } next_server; + struct in_addr next_server = { 0 }; char *raw_filename = NULL; struct uri *uri = NULL; char *filename; - /* Initialise server address */ - memset ( &next_server, 0, sizeof ( next_server ) ); - /* If we have a filename, fetch it along with the next-server * setting from the same settings block. */ @@ -244,27 +263,20 @@ struct uri * fetch_next_server_and_filename ( struct settings *settings ) { fetch_string_setting_copy ( settings, &filename_setting, &raw_filename ); fetch_ipv4_setting ( settings, &next_server_setting, - &next_server.sin.sin_addr ); - } - if ( ! raw_filename ) - goto err_fetch; - - /* Populate server address */ - if ( next_server.sin.sin_addr.s_addr ) { - next_server.sin.sin_family = AF_INET; - printf ( "Next server: %s\n", - inet_ntoa ( next_server.sin.sin_addr ) ); + &next_server ); } /* Expand filename setting */ - filename = expand_settings ( raw_filename ); + filename = expand_settings ( raw_filename ? raw_filename : "" ); if ( ! filename ) goto err_expand; + + /* Parse next server and filename */ + if ( next_server.s_addr ) + printf ( "Next server: %s\n", inet_ntoa ( next_server ) ); if ( filename[0] ) printf ( "Filename: %s\n", filename ); - - /* Construct URI */ - uri = pxe_uri ( &next_server.sa, filename ); + uri = parse_next_server_and_filename ( next_server, filename ); if ( ! uri ) goto err_parse; @@ -272,7 +284,6 @@ struct uri * fetch_next_server_and_filename ( struct settings *settings ) { free ( filename ); err_expand: free ( raw_filename ); - err_fetch: return uri; } @@ -290,11 +301,9 @@ static struct uri * fetch_root_path ( struct settings *settings ) { /* Fetch root-path setting */ fetch_string_setting_copy ( settings, &root_path_setting, &raw_root_path ); - if ( ! raw_root_path ) - goto err_fetch; /* Expand filename setting */ - root_path = expand_settings ( raw_root_path ); + root_path = expand_settings ( raw_root_path ? raw_root_path : "" ); if ( ! root_path ) goto err_expand; @@ -309,7 +318,6 @@ static struct uri * fetch_root_path ( struct settings *settings ) { free ( root_path ); err_expand: free ( raw_root_path ); - err_fetch: return uri; } @@ -370,19 +378,32 @@ int netboot ( struct net_device *netdev ) { goto err_pxe_menu_boot; } - /* Fetch next server and filename (if any) */ + /* Fetch next server and filename */ filename = fetch_next_server_and_filename ( NULL ); + if ( ! filename ) + goto err_filename; + if ( ! uri_has_path ( filename ) ) { + /* Ignore empty filename */ + uri_put ( filename ); + filename = NULL; + } - /* Fetch root path (if any) */ + /* Fetch root path */ root_path = fetch_root_path ( NULL ); + if ( ! root_path ) + goto err_root_path; + if ( ! uri_is_absolute ( root_path ) ) { + /* Ignore empty root path */ + uri_put ( root_path ); + root_path = NULL; + } /* If we have both a filename and a root path, ignore an - * unsupported or missing URI scheme in the root path, since - * it may represent an NFS root. + * unsupported URI scheme in the root path, since it may + * represent an NFS root. */ if ( filename && root_path && - ( ( ! uri_is_absolute ( root_path ) ) || - ( xfer_uri_opener ( root_path->scheme ) == NULL ) ) ) { + ( xfer_uri_opener ( root_path->scheme ) == NULL ) ) { printf ( "Ignoring unsupported root path\n" ); uri_put ( root_path ); root_path = NULL; @@ -403,7 +424,9 @@ int netboot ( struct net_device *netdev ) { err_uriboot: err_no_boot: uri_put ( root_path ); + err_root_path: uri_put ( filename ); + err_filename: err_pxe_menu_boot: err_dhcp: err_ifopen: diff --git a/roms/ipxe/src/usr/ibmgmt.c b/roms/ipxe/src/usr/ibmgmt.c deleted file mode 100644 index 7857664d6..000000000 --- a/roms/ipxe/src/usr/ibmgmt.c +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2016 Michael Brown <mbrown@fensystems.co.uk>. - * - * 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 <string.h> -#include <stdio.h> -#include <errno.h> -#include <byteswap.h> -#include <ipxe/infiniband.h> -#include <usr/ibmgmt.h> - -/** @file - * - * Infiniband device management - * - */ - -/** - * Print status of Infiniband device - * - * @v ibdev Infiniband device - */ -void ibstat ( struct ib_device *ibdev ) { - struct ib_queue_pair *qp; - - printf ( "%s: " IB_GUID_FMT " using %s on %s port %d (%s)\n", - ibdev->name, IB_GUID_ARGS ( &ibdev->gid.s.guid ), - ibdev->dev->driver_name, ibdev->dev->name, ibdev->port, - ( ib_is_open ( ibdev ) ? "open" : "closed" ) ); - if ( ib_link_ok ( ibdev ) ) { - printf ( " [Link:up LID %d prefix " IB_GUID_FMT "]\n", - ibdev->lid, IB_GUID_ARGS ( &ibdev->gid.s.prefix ) ); - } else { - printf ( " [Link:down, port state %d]\n", ibdev->port_state ); - } - list_for_each_entry ( qp, &ibdev->qps, list ) { - printf ( " QPN %#lx send %d/%d recv %d/%d %s\n", - qp->qpn, qp->send.fill, qp->send.num_wqes, - qp->recv.fill, qp->recv.num_wqes, qp->name ); - } -} diff --git a/roms/ipxe/src/usr/ifmgmt.c b/roms/ipxe/src/usr/ifmgmt.c index f367149f7..aefdaa45d 100644 --- a/roms/ipxe/src/usr/ifmgmt.c +++ b/roms/ipxe/src/usr/ifmgmt.c @@ -33,7 +33,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <ipxe/job.h> #include <ipxe/monojob.h> #include <ipxe/timer.h> -#include <ipxe/errortab.h> #include <usr/ifmgmt.h> /** @file @@ -51,11 +50,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); __einfo_uniqify ( EINFO_EADDRNOTAVAIL, 0x01, \ "No configuration methods succeeded" ) -/** Human-readable error message */ -struct errortab ifmgmt_errors[] __errortab = { - __einfo_errortab ( EINFO_EADDRNOTAVAIL_CONFIG ), -}; - /** * Open network device * diff --git a/roms/ipxe/src/usr/lotest.c b/roms/ipxe/src/usr/lotest.c index 6b75b5048..6b328713c 100644 --- a/roms/ipxe/src/usr/lotest.c +++ b/roms/ipxe/src/usr/lotest.c @@ -188,15 +188,13 @@ static int loopback_wait ( void *data, size_t len ) { * @v sender Sending network device * @v receiver Received network device * @v mtu Packet size (excluding link-layer headers) - * @v broadcast Use broadcast link-layer address * @ret rc Return status code */ int loopback_test ( struct net_device *sender, struct net_device *receiver, - size_t mtu, int broadcast ) { + size_t mtu ) { uint8_t *buf; uint32_t *seq; struct io_buffer *iobuf; - const void *ll_dest; unsigned int i; unsigned int successes; int rc; @@ -221,13 +219,9 @@ int loopback_test ( struct net_device *sender, struct net_device *receiver, return -ENOMEM; seq = ( ( void * ) buf ); - /* Determine destination address */ - ll_dest = ( broadcast ? sender->ll_broadcast : receiver->ll_addr ); - /* Print initial statistics */ - printf ( "Performing %sloopback test from %s to %s with %zd byte MTU\n", - ( broadcast ? "broadcast " : "" ), sender->name, - receiver->name, mtu ); + printf ( "Performing loopback test from %s to %s with %zd byte MTU\n", + sender->name, receiver->name, mtu ); ifstat ( sender ); ifstat ( receiver ); @@ -256,7 +250,7 @@ int loopback_test ( struct net_device *sender, struct net_device *receiver, /* Transmit packet */ if ( ( rc = net_tx ( iob_disown ( iobuf ), sender, - &lotest_protocol, ll_dest, + &lotest_protocol, receiver->ll_addr, sender->ll_addr ) ) != 0 ) { printf ( "\nFailed to transmit packet: %s", strerror ( rc ) ); diff --git a/roms/ipxe/src/usr/ntpmgmt.c b/roms/ipxe/src/usr/ntpmgmt.c deleted file mode 100644 index 765c6dc9e..000000000 --- a/roms/ipxe/src/usr/ntpmgmt.c +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2016 Michael Brown <mbrown@fensystems.co.uk>. - * - * 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 <stdint.h> -#include <stdio.h> -#include <string.h> -#include <ipxe/ntp.h> -#include <ipxe/monojob.h> -#include <usr/ntpmgmt.h> - -/** @file - * - * NTP management - * - */ - -/** - * Get time and date via NTP - * - * @v hostname Hostname - * @ret rc Return status code - */ -int ntp ( const char *hostname ) { - int rc; - - /* Start NTP client */ - if ( ( rc = start_ntp ( &monojob, hostname ) ) != 0 ) - return rc; - - /* Wait for NTP to complete */ - if ( ( rc = monojob_wait ( NULL, 0 ) ) != 0 ) - return rc; - - return 0; -} diff --git a/roms/ipxe/src/util/efifatbin.c b/roms/ipxe/src/util/efifatbin.c index 918e7a3c4..c02f750b6 100644 --- a/roms/ipxe/src/util/efifatbin.c +++ b/roms/ipxe/src/util/efifatbin.c @@ -17,7 +17,6 @@ * 02110-1301, USA. */ -#define FILE_LICENCE(...) extern void __file_licence ( void ) #include <stdint.h> #include <stddef.h> #include <stdlib.h> @@ -28,7 +27,7 @@ #include <errno.h> #include <assert.h> #include <getopt.h> -#include <ipxe/efi/Uefi.h> +#include <ipxe/efi/efi.h> #include <ipxe/efi/IndustryStandard/PeImage.h> #define eprintf(...) fprintf ( stderr, __VA_ARGS__ ) diff --git a/roms/ipxe/src/util/efirom.c b/roms/ipxe/src/util/efirom.c index 943a66910..abee496dd 100644 --- a/roms/ipxe/src/util/efirom.c +++ b/roms/ipxe/src/util/efirom.c @@ -17,7 +17,6 @@ * 02110-1301, USA. */ -#define FILE_LICENCE(...) extern void __file_licence ( void ) #include <stdint.h> #include <stddef.h> #include <stdlib.h> @@ -28,7 +27,7 @@ #include <errno.h> #include <assert.h> #include <getopt.h> -#include <ipxe/efi/Uefi.h> +#include <ipxe/efi/efi.h> #include <ipxe/efi/IndustryStandard/PeImage.h> #include <ipxe/efi/IndustryStandard/Pci22.h> @@ -81,11 +80,9 @@ static void read_pe_info ( void *pe, uint16_t *machine, *machine = nt->nt32.FileHeader.Machine; switch ( *machine ) { case EFI_IMAGE_MACHINE_IA32: - case EFI_IMAGE_MACHINE_ARMTHUMB_MIXED: *subsystem = nt->nt32.OptionalHeader.Subsystem; break; case EFI_IMAGE_MACHINE_X64: - case EFI_IMAGE_MACHINE_AARCH64: *subsystem = nt->nt64.OptionalHeader.Subsystem; break; default: diff --git a/roms/ipxe/src/util/elf2efi.c b/roms/ipxe/src/util/elf2efi.c index 152bf5333..e68fa5d14 100644 --- a/roms/ipxe/src/util/elf2efi.c +++ b/roms/ipxe/src/util/elf2efi.c @@ -17,7 +17,9 @@ * 02110-1301, USA. */ -#define FILE_LICENCE(...) extern void __file_licence ( void ) +#define _GNU_SOURCE +#define PACKAGE "elf2efi" +#define PACKAGE_VERSION "1" #include <stdint.h> #include <stddef.h> #include <stdlib.h> @@ -27,90 +29,18 @@ #include <errno.h> #include <assert.h> #include <getopt.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/mman.h> -#include <fcntl.h> -#include <elf.h> -#include <ipxe/efi/Uefi.h> +#include <bfd.h> +#include <ipxe/efi/efi.h> #include <ipxe/efi/IndustryStandard/PeImage.h> #include <libgen.h> #define eprintf(...) fprintf ( stderr, __VA_ARGS__ ) -#ifdef EFI_TARGET32 - -#define EFI_IMAGE_NT_HEADERS EFI_IMAGE_NT_HEADERS32 -#define EFI_IMAGE_NT_OPTIONAL_HDR_MAGIC EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC -#define EFI_IMAGE_FILE_MACHINE EFI_IMAGE_FILE_32BIT_MACHINE -#define ELFCLASS ELFCLASS32 -#define Elf_Ehdr Elf32_Ehdr -#define Elf_Shdr Elf32_Shdr -#define Elf_Sym Elf32_Sym -#define Elf_Addr Elf32_Addr -#define Elf_Rel Elf32_Rel -#define Elf_Rela Elf32_Rela -#define ELF_R_TYPE ELF32_R_TYPE -#define ELF_R_SYM ELF32_R_SYM - -#elif defined(EFI_TARGET64) - -#define EFI_IMAGE_NT_HEADERS EFI_IMAGE_NT_HEADERS64 -#define EFI_IMAGE_NT_OPTIONAL_HDR_MAGIC EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC -#define EFI_IMAGE_FILE_MACHINE 0 -#define ELFCLASS ELFCLASS64 -#define Elf_Ehdr Elf64_Ehdr -#define Elf_Shdr Elf64_Shdr -#define Elf_Sym Elf64_Sym -#define Elf_Addr Elf64_Addr -#define Elf_Rel Elf64_Rel -#define Elf_Rela Elf64_Rela -#define ELF_R_TYPE ELF64_R_TYPE -#define ELF_R_SYM ELF64_R_SYM - -#endif - -#define ELF_MREL( mach, type ) ( (mach) | ( (type) << 16 ) ) - -/* Allow for building with older versions of elf.h */ -#ifndef EM_AARCH64 -#define EM_AARCH64 183 -#define R_AARCH64_NONE 0 -#define R_AARCH64_ABS64 257 -#define R_AARCH64_CALL26 283 -#define R_AARCH64_JUMP26 282 -#define R_AARCH64_ADR_PREL_LO21 274 -#define R_AARCH64_ADR_PREL_PG_HI21 275 -#define R_AARCH64_ADD_ABS_LO12_NC 277 -#define R_AARCH64_LDST8_ABS_LO12_NC 278 -#define R_AARCH64_LDST16_ABS_LO12_NC 284 -#define R_AARCH64_LDST32_ABS_LO12_NC 285 -#define R_AARCH64_LDST64_ABS_LO12_NC 286 -#endif /* EM_AARCH64 */ -#ifndef R_ARM_CALL -#define R_ARM_CALL 28 -#endif -#ifndef R_ARM_THM_JUMP24 -#define R_ARM_THM_JUMP24 30 -#endif - -/* Seems to be missing from elf.h */ -#ifndef R_AARCH64_NULL -#define R_AARCH64_NULL 256 -#endif - #define EFI_FILE_ALIGN 0x20 -struct elf_file { - void *data; - size_t len; - const Elf_Ehdr *ehdr; -}; - struct pe_section { struct pe_section *next; EFI_IMAGE_SECTION_HEADER hdr; - void ( * fixup ) ( struct pe_section *section ); uint8_t contents[0]; }; @@ -125,7 +55,11 @@ struct pe_relocs { struct pe_header { EFI_IMAGE_DOS_HEADER dos; uint8_t padding[128]; - EFI_IMAGE_NT_HEADERS nt; +#if defined(EFI_TARGET_IA32) + EFI_IMAGE_NT_HEADERS32 nt; +#elif defined(EFI_TARGET_X64) + EFI_IMAGE_NT_HEADERS64 nt; +#endif }; static struct pe_header efi_pe_header = { @@ -136,17 +70,26 @@ static struct pe_header efi_pe_header = { .nt = { .Signature = EFI_IMAGE_NT_SIGNATURE, .FileHeader = { +#if defined(EFI_TARGET_IA32) + .Machine = EFI_IMAGE_MACHINE_IA32, +#elif defined(EFI_TARGET_X64) + .Machine = EFI_IMAGE_MACHINE_X64, +#endif .TimeDateStamp = 0x10d1a884, .SizeOfOptionalHeader = sizeof ( efi_pe_header.nt.OptionalHeader ), .Characteristics = ( EFI_IMAGE_FILE_DLL | - EFI_IMAGE_FILE_MACHINE | +#if defined(EFI_TARGET_IA32) + EFI_IMAGE_FILE_32BIT_MACHINE | +#endif EFI_IMAGE_FILE_EXECUTABLE_IMAGE ), }, .OptionalHeader = { - .Magic = EFI_IMAGE_NT_OPTIONAL_HDR_MAGIC, - .MajorLinkerVersion = 42, - .MinorLinkerVersion = 42, +#if defined(EFI_TARGET_IA32) + .Magic = EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC, +#elif defined(EFI_TARGET_X64) + .Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC, +#endif .SectionAlignment = EFI_FILE_ALIGN, .FileAlignment = EFI_FILE_ALIGN, .SizeOfImage = sizeof ( efi_pe_header ), @@ -288,175 +231,110 @@ static size_t output_pe_reltab ( struct pe_relocs *pe_reltab, } /** - * Read input ELF file + * Open input BFD file * - * @v name File name - * @v elf ELF file + * @v filename File name + * @ret ibfd BFD file */ -static void read_elf_file ( const char *name, struct elf_file *elf ) { - static const unsigned char ident[] = { - ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3, ELFCLASS, ELFDATA2LSB - }; - struct stat stat; - const Elf_Ehdr *ehdr; - const Elf_Shdr *shdr; - void *data; - size_t offset; - unsigned int i; - int fd; - - /* Open file */ - fd = open ( name, O_RDONLY ); - if ( fd < 0 ) { - eprintf ( "Could not open %s: %s\n", name, strerror ( errno ) ); +static bfd * open_input_bfd ( const char *filename ) { + bfd *bfd; + + /* Open the file */ + bfd = bfd_openr ( filename, NULL ); + if ( ! bfd ) { + eprintf ( "Cannot open %s: ", filename ); + bfd_perror ( NULL ); exit ( 1 ); } - /* Get file size */ - if ( fstat ( fd, &stat ) < 0 ) { - eprintf ( "Could not get size of %s: %s\n", - name, strerror ( errno ) ); + /* The call to bfd_check_format() must be present, otherwise + * we get a segfault from later BFD calls. + */ + if ( ! bfd_check_format ( bfd, bfd_object ) ) { + eprintf ( "%s is not an object file: ", filename ); + bfd_perror ( NULL ); exit ( 1 ); } - elf->len = stat.st_size; - /* Map file */ - data = mmap ( NULL, elf->len, PROT_READ, MAP_SHARED, fd, 0 ); - if ( data == MAP_FAILED ) { - eprintf ( "Could not map %s: %s\n", name, strerror ( errno ) ); - exit ( 1 ); - } - elf->data = data; - - /* Close file */ - close ( fd ); - - /* Check header */ - ehdr = elf->data; - if ( ( elf->len < sizeof ( *ehdr ) ) || - ( memcmp ( ident, ehdr->e_ident, sizeof ( ident ) ) != 0 ) ) { - eprintf ( "Invalid ELF header in %s\n", name ); - exit ( 1 ); - } - elf->ehdr = ehdr; - - /* Check section headers */ - for ( i = 0 ; i < ehdr->e_shnum ; i++ ) { - offset = ( ehdr->e_shoff + ( i * ehdr->e_shentsize ) ); - if ( elf->len < ( offset + sizeof ( *shdr ) ) ) { - eprintf ( "ELF section header outside file in %s\n", - name ); - exit ( 1 ); - } - shdr = ( data + offset ); - if ( ( shdr->sh_type != SHT_NOBITS ) && - ( ( elf->len < shdr->sh_offset ) || - ( ( ( elf->len - shdr->sh_offset ) < shdr->sh_size ) ))){ - eprintf ( "ELF section %d outside file in %s\n", - i, name ); - exit ( 1 ); - } - if ( shdr->sh_link >= ehdr->e_shnum ) { - eprintf ( "ELF section %d link section %d out of " - "range\n", i, shdr->sh_link ); - exit ( 1 ); - } - } + return bfd; } /** - * Get ELF string + * Read symbol table * - * @v elf ELF file - * @v section String table section number - * @v offset String table offset - * @ret string ELF string + * @v bfd BFD file */ -static const char * elf_string ( struct elf_file *elf, unsigned int section, - size_t offset ) { - const Elf_Ehdr *ehdr = elf->ehdr; - const Elf_Shdr *shdr; - char *string; - char *last; - - /* Locate section header */ - if ( section >= ehdr->e_shnum ) { - eprintf ( "Invalid ELF string section %d\n", section ); +static asymbol ** read_symtab ( bfd *bfd ) { + long symtab_size; + asymbol **symtab; + long symcount; + + /* Get symbol table size */ + symtab_size = bfd_get_symtab_upper_bound ( bfd ); + if ( symtab_size < 0 ) { + bfd_perror ( "Could not get symbol table upper bound" ); exit ( 1 ); } - shdr = ( elf->data + ehdr->e_shoff + ( section * ehdr->e_shentsize ) ); - /* Sanity check section */ - if ( shdr->sh_type != SHT_STRTAB ) { - eprintf ( "ELF section %d (type %d) is not a string table\n", - section, shdr->sh_type ); - exit ( 1 ); - } - last = ( elf->data + shdr->sh_offset + shdr->sh_size - 1 ); - if ( *last != '\0' ) { - eprintf ( "ELF section %d is not NUL-terminated\n", section ); + /* Allocate and read symbol table */ + symtab = xmalloc ( symtab_size ); + symcount = bfd_canonicalize_symtab ( bfd, symtab ); + if ( symcount < 0 ) { + bfd_perror ( "Cannot read symbol table" ); exit ( 1 ); } - /* Locate string */ - if ( offset >= shdr->sh_size ) { - eprintf ( "Invalid ELF string offset %zd in section %d\n", - offset, section ); - exit ( 1 ); - } - string = ( elf->data + shdr->sh_offset + offset ); - - return string; + return symtab; } /** - * Set machine architecture + * Read relocation table * - * @v elf ELF file - * @v pe_header PE file header + * @v bfd BFD file + * @v symtab Symbol table + * @v section Section + * @v symtab Symbol table + * @ret reltab Relocation table */ -static void set_machine ( struct elf_file *elf, struct pe_header *pe_header ) { - const Elf_Ehdr *ehdr = elf->ehdr; - uint16_t machine; - - /* Identify machine architecture */ - switch ( ehdr->e_machine ) { - case EM_386: - machine = EFI_IMAGE_MACHINE_IA32; - break; - case EM_X86_64: - machine = EFI_IMAGE_MACHINE_X64; - break; - case EM_ARM: - machine = EFI_IMAGE_MACHINE_ARMTHUMB_MIXED; - break; - case EM_AARCH64: - machine = EFI_IMAGE_MACHINE_AARCH64; - break; - default: - eprintf ( "Unknown ELF architecture %d\n", ehdr->e_machine ); +static arelent ** read_reltab ( bfd *bfd, asymbol **symtab, + asection *section ) { + long reltab_size; + arelent **reltab; + long numrels; + + /* Get relocation table size */ + reltab_size = bfd_get_reloc_upper_bound ( bfd, section ); + if ( reltab_size < 0 ) { + bfd_perror ( "Could not get relocation table upper bound" ); exit ( 1 ); } - /* Set machine architecture */ - pe_header->nt.FileHeader.Machine = machine; + /* Allocate and read relocation table */ + reltab = xmalloc ( reltab_size ); + numrels = bfd_canonicalize_reloc ( bfd, section, reltab, symtab ); + if ( numrels < 0 ) { + bfd_perror ( "Cannot read relocation table" ); + exit ( 1 ); + } + + return reltab; } /** * Process section * - * @v elf ELF file - * @v shdr ELF section header + * @v bfd BFD file * @v pe_header PE file header + * @v section Section * @ret new New PE section */ -static struct pe_section * process_section ( struct elf_file *elf, - const Elf_Shdr *shdr, - struct pe_header *pe_header ) { +static struct pe_section * process_section ( bfd *bfd, + struct pe_header *pe_header, + asection *section ) { struct pe_section *new; - const char *name; size_t section_memsz; size_t section_filesz; + unsigned long flags = bfd_get_section_flags ( bfd, section ); unsigned long code_start; unsigned long code_end; unsigned long data_start; @@ -467,15 +345,12 @@ static struct pe_section * process_section ( struct elf_file *elf, unsigned long *applicable_start; unsigned long *applicable_end; - /* Get section name */ - name = elf_string ( elf, elf->ehdr->e_shstrndx, shdr->sh_name ); - /* Extract current RVA limits from file header */ code_start = pe_header->nt.OptionalHeader.BaseOfCode; code_end = ( code_start + pe_header->nt.OptionalHeader.SizeOfCode ); -#if defined(EFI_TARGET32) +#if defined(EFI_TARGET_IA32) data_start = pe_header->nt.OptionalHeader.BaseOfData; -#elif defined(EFI_TARGET64) +#elif defined(EFI_TARGET_X64) data_start = code_end; #endif data_mid = ( data_start + @@ -484,21 +359,21 @@ static struct pe_section * process_section ( struct elf_file *elf, pe_header->nt.OptionalHeader.SizeOfUninitializedData ); /* Allocate PE section */ - section_memsz = shdr->sh_size; - section_filesz = ( ( shdr->sh_type == SHT_PROGBITS ) ? + section_memsz = bfd_section_size ( bfd, section ); + section_filesz = ( ( flags & SEC_LOAD ) ? efi_file_align ( section_memsz ) : 0 ); new = xmalloc ( sizeof ( *new ) + section_filesz ); memset ( new, 0, sizeof ( *new ) + section_filesz ); /* Fill in section header details */ - strncpy ( ( char * ) new->hdr.Name, name, sizeof ( new->hdr.Name ) ); + strncpy ( ( char * ) new->hdr.Name, section->name, + sizeof ( new->hdr.Name ) ); new->hdr.Misc.VirtualSize = section_memsz; - new->hdr.VirtualAddress = shdr->sh_addr; + new->hdr.VirtualAddress = bfd_get_section_vma ( bfd, section ); new->hdr.SizeOfRawData = section_filesz; /* Fill in section characteristics and update RVA limits */ - if ( ( shdr->sh_type == SHT_PROGBITS ) && - ( shdr->sh_flags & SHF_EXECINSTR ) ) { + if ( flags & SEC_CODE ) { /* .text-type section */ new->hdr.Characteristics = ( EFI_IMAGE_SCN_CNT_CODE | @@ -507,8 +382,7 @@ static struct pe_section * process_section ( struct elf_file *elf, EFI_IMAGE_SCN_MEM_READ ); applicable_start = &code_start; applicable_end = &code_end; - } else if ( ( shdr->sh_type == SHT_PROGBITS ) && - ( shdr->sh_flags & SHF_WRITE ) ) { + } else if ( flags & SEC_DATA ) { /* .data-type section */ new->hdr.Characteristics = ( EFI_IMAGE_SCN_CNT_INITIALIZED_DATA | @@ -517,7 +391,7 @@ static struct pe_section * process_section ( struct elf_file *elf, EFI_IMAGE_SCN_MEM_WRITE ); applicable_start = &data_start; applicable_end = &data_mid; - } else if ( shdr->sh_type == SHT_PROGBITS ) { + } else if ( flags & SEC_READONLY ) { /* .rodata-type section */ new->hdr.Characteristics = ( EFI_IMAGE_SCN_CNT_INITIALIZED_DATA | @@ -525,7 +399,7 @@ static struct pe_section * process_section ( struct elf_file *elf, EFI_IMAGE_SCN_MEM_READ ); applicable_start = &data_start; applicable_end = &data_mid; - } else if ( shdr->sh_type == SHT_NOBITS ) { + } else if ( ! ( flags & SEC_LOAD ) ) { /* .bss-type section */ new->hdr.Characteristics = ( EFI_IMAGE_SCN_CNT_UNINITIALIZED_DATA | @@ -535,15 +409,19 @@ static struct pe_section * process_section ( struct elf_file *elf, applicable_start = &data_mid; applicable_end = &data_end; } else { - eprintf ( "Unrecognised characteristics for section %s\n", - name ); + eprintf ( "Unrecognised characteristics %#lx for section %s\n", + flags, section->name ); exit ( 1 ); } /* Copy in section contents */ - if ( shdr->sh_type == SHT_PROGBITS ) { - memcpy ( new->contents, ( elf->data + shdr->sh_offset ), - shdr->sh_size ); + if ( flags & SEC_LOAD ) { + if ( ! bfd_get_section_contents ( bfd, section, new->contents, + 0, section_memsz ) ) { + eprintf ( "Cannot read section %s: ", section->name ); + bfd_perror ( NULL ); + exit ( 1 ); + } } /* Update RVA limits */ @@ -563,7 +441,7 @@ static struct pe_section * process_section ( struct elf_file *elf, /* Write RVA limits back to file header */ pe_header->nt.OptionalHeader.BaseOfCode = code_start; pe_header->nt.OptionalHeader.SizeOfCode = ( code_end - code_start ); -#if defined(EFI_TARGET32) +#if defined(EFI_TARGET_IA32) pe_header->nt.OptionalHeader.BaseOfData = data_start; #endif pe_header->nt.OptionalHeader.SizeOfInitializedData = @@ -583,104 +461,43 @@ static struct pe_section * process_section ( struct elf_file *elf, /** * Process relocation record * - * @v elf ELF file - * @v shdr ELF section header - * @v syms Symbol table - * @v nsyms Number of symbol table entries - * @v rel Relocation record + * @v bfd BFD file + * @v section Section + * @v rel Relocation entry * @v pe_reltab PE relocation table to fill in */ -static void process_reloc ( struct elf_file *elf, const Elf_Shdr *shdr, - const Elf_Sym *syms, unsigned int nsyms, - const Elf_Rel *rel, struct pe_relocs **pe_reltab ) { - unsigned int type = ELF_R_TYPE ( rel->r_info ); - unsigned int sym = ELF_R_SYM ( rel->r_info ); - unsigned int mrel = ELF_MREL ( elf->ehdr->e_machine, type ); - size_t offset = ( shdr->sh_addr + rel->r_offset ); - - /* Look up symbol and process relocation */ - if ( sym >= nsyms ) { - eprintf ( "Symbol out of range\n" ); - exit ( 1 ); - } - if ( syms[sym].st_shndx == SHN_ABS ) { +static void process_reloc ( bfd *bfd __attribute__ (( unused )), + asection *section, arelent *rel, + struct pe_relocs **pe_reltab ) { + reloc_howto_type *howto = rel->howto; + asymbol *sym = *(rel->sym_ptr_ptr); + unsigned long offset = ( bfd_get_section_vma ( bfd, section ) + + rel->address ); + + if ( bfd_is_abs_section ( sym->section ) ) { /* Skip absolute symbols; the symbol value won't * change when the object is loaded. */ + } else if ( ( strcmp ( howto->name, "R_386_NONE" ) == 0 ) || + ( strcmp ( howto->name, "R_X86_64_NONE" ) == 0 ) ) { + /* Ignore dummy relocations used by REQUIRE_SYMBOL() */ + } else if ( strcmp ( howto->name, "R_X86_64_64" ) == 0 ) { + /* Generate an 8-byte PE relocation */ + generate_pe_reloc ( pe_reltab, offset, 8 ); + } else if ( strcmp ( howto->name, "R_386_32" ) == 0 ) { + /* Generate a 4-byte PE relocation */ + generate_pe_reloc ( pe_reltab, offset, 4 ); + } else if ( strcmp ( howto->name, "R_386_16" ) == 0 ) { + /* Generate a 2-byte PE relocation */ + generate_pe_reloc ( pe_reltab, offset, 2 ); + } else if ( ( strcmp ( howto->name, "R_386_PC32" ) == 0 ) || + ( strcmp ( howto->name, "R_X86_64_PC32" ) == 0 ) ) { + /* Skip PC-relative relocations; all relative offsets + * remain unaltered when the object is loaded. + */ } else { - switch ( mrel ) { - case ELF_MREL ( EM_386, R_386_NONE ) : - case ELF_MREL ( EM_ARM, R_ARM_NONE ) : - case ELF_MREL ( EM_X86_64, R_X86_64_NONE ) : - case ELF_MREL ( EM_AARCH64, R_AARCH64_NONE ) : - case ELF_MREL ( EM_AARCH64, R_AARCH64_NULL ) : - /* Ignore dummy relocations used by REQUIRE_SYMBOL() */ - break; - case ELF_MREL ( EM_386, R_386_32 ) : - case ELF_MREL ( EM_ARM, R_ARM_ABS32 ) : - /* Generate a 4-byte PE relocation */ - generate_pe_reloc ( pe_reltab, offset, 4 ); - break; - case ELF_MREL ( EM_X86_64, R_X86_64_64 ) : - case ELF_MREL ( EM_AARCH64, R_AARCH64_ABS64 ) : - /* Generate an 8-byte PE relocation */ - generate_pe_reloc ( pe_reltab, offset, 8 ); - break; - case ELF_MREL ( EM_386, R_386_PC32 ) : - case ELF_MREL ( EM_ARM, R_ARM_CALL ) : - case ELF_MREL ( EM_ARM, R_ARM_THM_PC22 ) : - case ELF_MREL ( EM_ARM, R_ARM_THM_JUMP24 ) : - case ELF_MREL ( EM_X86_64, R_X86_64_PC32 ) : - case ELF_MREL ( EM_AARCH64, R_AARCH64_CALL26 ) : - case ELF_MREL ( EM_AARCH64, R_AARCH64_JUMP26 ) : - case ELF_MREL ( EM_AARCH64, R_AARCH64_ADR_PREL_LO21 ) : - case ELF_MREL ( EM_AARCH64, R_AARCH64_ADR_PREL_PG_HI21 ) : - case ELF_MREL ( EM_AARCH64, R_AARCH64_ADD_ABS_LO12_NC ) : - case ELF_MREL ( EM_AARCH64, R_AARCH64_LDST8_ABS_LO12_NC ) : - case ELF_MREL ( EM_AARCH64, R_AARCH64_LDST16_ABS_LO12_NC ) : - case ELF_MREL ( EM_AARCH64, R_AARCH64_LDST32_ABS_LO12_NC ) : - case ELF_MREL ( EM_AARCH64, R_AARCH64_LDST64_ABS_LO12_NC ) : - /* Skip PC-relative relocations; all relative - * offsets remain unaltered when the object is - * loaded. - */ - break; - default: - eprintf ( "Unrecognised relocation type %d\n", type ); - exit ( 1 ); - } - } -} - -/** - * Process relocation records - * - * @v elf ELF file - * @v shdr ELF section header - * @v stride Relocation record size - * @v pe_reltab PE relocation table to fill in - */ -static void process_relocs ( struct elf_file *elf, const Elf_Shdr *shdr, - size_t stride, struct pe_relocs **pe_reltab ) { - const Elf_Shdr *symtab; - const Elf_Sym *syms; - const Elf_Rel *rel; - unsigned int nsyms; - unsigned int nrels; - unsigned int i; - - /* Identify symbol table */ - symtab = ( elf->data + elf->ehdr->e_shoff + - ( shdr->sh_link * elf->ehdr->e_shentsize ) ); - syms = ( elf->data + symtab->sh_offset ); - nsyms = ( symtab->sh_size / sizeof ( syms[0] ) ); - - /* Process each relocation */ - rel = ( elf->data + shdr->sh_offset ); - nrels = ( shdr->sh_size / stride ); - for ( i = 0 ; i < nrels ; i++ ) { - process_reloc ( elf, shdr, syms, nsyms, rel, pe_reltab ); - rel = ( ( ( const void * ) rel ) + stride ); + eprintf ( "Unrecognised relocation type %s\n", howto->name ); + exit ( 1 ); } } @@ -731,20 +548,6 @@ create_reloc_section ( struct pe_header *pe_header, } /** - * Fix up debug section - * - * @v debug Debug section - */ -static void fixup_debug_section ( struct pe_section *debug ) { - EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *contents; - - /* Fix up FileOffset */ - contents = ( ( void * ) debug->contents ); - contents->FileOffset += ( debug->hdr.PointerToRawData - - debug->hdr.VirtualAddress ); -} - -/** * Create debug section * * @v pe_header PE file header @@ -778,7 +581,6 @@ create_debug_section ( struct pe_header *pe_header, const char *filename ) { debug->hdr.Characteristics = ( EFI_IMAGE_SCN_CNT_INITIALIZED_DATA | EFI_IMAGE_SCN_MEM_NOT_PAGED | EFI_IMAGE_SCN_MEM_READ ); - debug->fixup = fixup_debug_section; /* Create section contents */ contents->debug.TimeDateStamp = 0x10d1a884; @@ -787,7 +589,6 @@ create_debug_section ( struct pe_header *pe_header, const char *filename ) { ( sizeof ( *contents ) - sizeof ( contents->debug ) ); contents->debug.RVA = ( debug->hdr.VirtualAddress + offsetof ( typeof ( *contents ), rsds ) ); - contents->debug.FileOffset = contents->debug.RVA; contents->rsds.Signature = CODEVIEW_SIGNATURE_RSDS; snprintf ( contents->name, sizeof ( contents->name ), "%s", filename ); @@ -799,7 +600,7 @@ create_debug_section ( struct pe_header *pe_header, const char *filename ) { debugdir = &(pe_header->nt.OptionalHeader.DataDirectory [EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]); debugdir->VirtualAddress = debug->hdr.VirtualAddress; - debugdir->Size = sizeof ( contents->debug ); + debugdir->Size = debug->hdr.Misc.VirtualSize; return debug; } @@ -828,8 +629,6 @@ static void write_pe_file ( struct pe_header *pe_header, fpos += section->hdr.SizeOfRawData; fpos = efi_file_align ( fpos ); } - if ( section->fixup ) - section->fixup ( section ); } /* Write file header */ @@ -875,60 +674,53 @@ static void write_pe_file ( struct pe_header *pe_header, static void elf2pe ( const char *elf_name, const char *pe_name, struct options *opts ) { char pe_name_tmp[ strlen ( pe_name ) + 1 ]; + bfd *bfd; + asymbol **symtab; + asection *section; + arelent **reltab; + arelent **rel; struct pe_relocs *pe_reltab = NULL; struct pe_section *pe_sections = NULL; struct pe_section **next_pe_section = &pe_sections; struct pe_header pe_header; - struct elf_file elf; - const Elf_Shdr *shdr; - size_t offset; - unsigned int i; FILE *pe; /* Create a modifiable copy of the PE name */ memcpy ( pe_name_tmp, pe_name, sizeof ( pe_name_tmp ) ); - /* Read ELF file */ - read_elf_file ( elf_name, &elf ); + /* Open the file */ + bfd = open_input_bfd ( elf_name ); + symtab = read_symtab ( bfd ); /* Initialise the PE header */ memcpy ( &pe_header, &efi_pe_header, sizeof ( pe_header ) ); - set_machine ( &elf, &pe_header ); - pe_header.nt.OptionalHeader.AddressOfEntryPoint = elf.ehdr->e_entry; + pe_header.nt.OptionalHeader.AddressOfEntryPoint = + bfd_get_start_address ( bfd ); pe_header.nt.OptionalHeader.Subsystem = opts->subsystem; - /* Process input sections */ - for ( i = 0 ; i < elf.ehdr->e_shnum ; i++ ) { - offset = ( elf.ehdr->e_shoff + ( i * elf.ehdr->e_shentsize ) ); - shdr = ( elf.data + offset ); - - /* Process section */ - if ( shdr->sh_flags & SHF_ALLOC ) { - - /* Create output section */ - *(next_pe_section) = process_section ( &elf, shdr, - &pe_header ); - next_pe_section = &(*next_pe_section)->next; - - } else if ( shdr->sh_type == SHT_REL ) { - - /* Process .rel relocations */ - process_relocs ( &elf, shdr, sizeof ( Elf_Rel ), - &pe_reltab ); - - } else if ( shdr->sh_type == SHT_RELA ) { - - /* Process .rela relocations */ - process_relocs ( &elf, shdr, sizeof ( Elf_Rela ), - &pe_reltab ); - } + /* For each input section, build an output section and create + * the appropriate relocation records + */ + for ( section = bfd->sections ; section ; section = section->next ) { + /* Discard non-allocatable sections */ + if ( ! ( bfd_get_section_flags ( bfd, section ) & SEC_ALLOC ) ) + continue; + /* Create output section */ + *(next_pe_section) = process_section ( bfd, &pe_header, + section ); + next_pe_section = &(*next_pe_section)->next; + /* Add relocations from this section */ + reltab = read_reltab ( bfd, symtab, section ); + for ( rel = reltab ; *rel ; rel++ ) + process_reloc ( bfd, section, *rel, &pe_reltab ); + free ( reltab ); } /* Create the .reloc section */ *(next_pe_section) = create_reloc_section ( &pe_header, pe_reltab ); next_pe_section = &(*next_pe_section)->next; - /* Create the .debug section */ + /* Create the .reloc section */ *(next_pe_section) = create_debug_section ( &pe_header, basename ( pe_name_tmp ) ); next_pe_section = &(*next_pe_section)->next; @@ -943,8 +735,8 @@ static void elf2pe ( const char *elf_name, const char *pe_name, write_pe_file ( &pe_header, pe_sections, pe ); fclose ( pe ); - /* Unmap ELF file */ - munmap ( elf.data, elf.len ); + /* Close BFD file */ + bfd_close ( bfd ); } /** @@ -1011,6 +803,9 @@ int main ( int argc, char **argv ) { const char *infile; const char *outfile; + /* Initialise libbfd */ + bfd_init(); + /* Parse command-line arguments */ infile_index = parse_options ( argc, argv, &opts ); if ( argc != ( infile_index + 2 ) ) { diff --git a/roms/ipxe/src/util/genefidsk b/roms/ipxe/src/util/genefidsk deleted file mode 100755 index 7064f99b6..000000000 --- a/roms/ipxe/src/util/genefidsk +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/sh -# -# Generate an EFI bootable disk image - -set -e - -function help() { - echo "Usage: ${0} [OPTIONS] <ipxe.efi>" - echo - echo "where OPTIONS are:" - echo " -h Show this help" - echo " -b Specify boot file name (e.g. bootx64.efi)" - echo " -o FILE Save disk image to file" -} - -BOOT=bootx64.efi - -while getopts "hb:o:" opt; do - case ${opt} in - h) - help - exit 0 - ;; - b) - BOOT="${OPTARG}" - ;; - o) - OUT="${OPTARG}" - ;; - esac -done - -shift $((OPTIND - 1)) -IN=$1 - -if [ -z "${IN}" ]; then - echo "${0}: no input file given" >&2 - help - exit 1 -fi - -if [ -z "${OUT}" ]; then - echo "${0}: no output file given" >&2 - help - exit 1 -fi - -# Create sparse output file -rm -f ${OUT} -truncate -s 1440K ${OUT} - -# Format disk -mformat -i ${OUT} -f 1440 :: - -# Create directory structure -mmd -i ${OUT} ::efi -mmd -i ${OUT} ::efi/boot - -# Copy bootable image -mcopy -i ${OUT} ${IN} ::efi/boot/${BOOT} diff --git a/roms/ipxe/src/util/geniso b/roms/ipxe/src/util/geniso index ff090d4a0..521c929e1 100755 --- a/roms/ipxe/src/util/geniso +++ b/roms/ipxe/src/util/geniso @@ -123,7 +123,8 @@ case "${LEGACY}" in cp ${ISOLINUX_BIN} ${dir} # syslinux 6.x needs a file called ldlinux.c32 - if [ -n "${LDLINUX_C32}" -a -s "${LDLINUX_C32}" ]; then + LDLINUX_C32=$(dirname ${ISOLINUX_BIN})/ldlinux.c32 + if [ -s ${LDLINUX_C32} ]; then cp ${LDLINUX_C32} ${dir} fi diff --git a/roms/ipxe/src/util/parserom.pl b/roms/ipxe/src/util/parserom.pl index 5a849a540..28df60652 100755 --- a/roms/ipxe/src/util/parserom.pl +++ b/roms/ipxe/src/util/parserom.pl @@ -157,7 +157,7 @@ sub process_isa_rom { # Output Makefile rules for the specified ROM declarations sub print_make_rules { - my ( $state, $image, $desc, $vendor, $device, $dup ) = @_; + my ( $state, my $image, my $desc, my $vendor, my $device, my $dup ) = @_; unless ( $state->{'is_header_printed'} ) { print "# NIC\t\n"; print "# NIC\tfamily\t$state->{family}\n"; diff --git a/roms/ipxe/src/util/zbin.c b/roms/ipxe/src/util/zbin.c index 75fba583f..1862a3827 100644 --- a/roms/ipxe/src/util/zbin.c +++ b/roms/ipxe/src/util/zbin.c @@ -144,7 +144,6 @@ static int read_zinfo_file ( const char *filename, static int alloc_output_file ( size_t max_len, struct output_file *output ) { output->len = 0; - output->hdr_len = 0; output->max_len = ( max_len ); output->buf = malloc ( max_len ); if ( ! output->buf ) { @@ -242,41 +241,19 @@ static void bcj_filter ( void *data, size_t len ) { }; } -#define CRCPOLY 0xedb88320 -#define CRCSEED 0xffffffff - -static uint32_t crc32_le ( uint32_t crc, const void *data, size_t len ) { - const uint8_t *src = data; - uint32_t mult; - unsigned int i; - - while ( len-- ) { - crc ^= *(src++); - for ( i = 0 ; i < 8 ; i++ ) { - mult = ( ( crc & 1 ) ? CRCPOLY : 0 ); - crc = ( ( crc >> 1 ) ^ mult ); - } - } - return crc; -} - static int process_zinfo_pack ( struct input_file *input, struct output_file *output, union zinfo_record *zinfo ) { struct zinfo_pack *pack = &zinfo->pack; size_t offset = pack->offset; size_t len = pack->len; - size_t start_len; size_t packed_len = 0; - size_t remaining; + size_t remaining = ( output->max_len - output->len ); lzma_options_lzma options; const lzma_filter filters[] = { { .id = LZMA_FILTER_LZMA1, .options = &options }, { .id = LZMA_VLI_UNKNOWN } }; - void *packed; - uint32_t *len32; - uint32_t *crc32; if ( ( offset + len ) > input->len ) { fprintf ( stderr, "Input buffer overrun on pack\n" ); @@ -284,9 +261,6 @@ static int process_zinfo_pack ( struct input_file *input, } output->len = align ( output->len, pack->align ); - start_len = output->len; - len32 = ( output->buf + output->len ); - output->len += sizeof ( *len32 ); if ( output->len > output->max_len ) { fprintf ( stderr, "Output buffer overrun on pack\n" ); return -1; @@ -294,34 +268,28 @@ static int process_zinfo_pack ( struct input_file *input, bcj_filter ( ( input->buf + offset ), len ); - packed = ( output->buf + output->len ); - remaining = ( output->max_len - output->len ); lzma_lzma_preset ( &options, LZMA_PRESET ); options.lc = LZMA_LC; options.lp = LZMA_LP; options.pb = LZMA_PB; if ( lzma_raw_buffer_encode ( filters, NULL, ( input->buf + offset ), - len, packed, &packed_len, - remaining ) != LZMA_OK ) { + len, ( output->buf + output->len ), + &packed_len, remaining ) != LZMA_OK ) { fprintf ( stderr, "Compression failure\n" ); return -1; } - output->len += packed_len; - crc32 = ( output->buf + output->len ); - output->len += sizeof ( *crc32 ); + if ( DEBUG ) { + fprintf ( stderr, "PACK [%#zx,%#zx) to [%#zx,%#zx)\n", + offset, ( offset + len ), output->len, + ( output->len + packed_len ) ); + } + + output->len += packed_len; if ( output->len > output->max_len ) { fprintf ( stderr, "Output buffer overrun on pack\n" ); return -1; } - *len32 = ( packed_len + sizeof ( *crc32 ) ); - *crc32 = crc32_le ( CRCSEED, packed, packed_len ); - - if ( DEBUG ) { - fprintf ( stderr, "PACK [%#zx,%#zx) to [%#zx,%#zx) crc %#08x\n", - offset, ( offset + len ), start_len, output->len, - *crc32 ); - } return 0; } diff --git a/roms/openbios/arch/amd64/context.c b/roms/openbios/arch/amd64/context.c index 33ab51e62..2e4df6a3d 100644 --- a/roms/openbios/arch/amd64/context.c +++ b/roms/openbios/arch/amd64/context.c @@ -97,15 +97,14 @@ init_context(uint8_t *stack, uint32_t stack_size, int num_params) /* Switch to another context. */ struct context *switch_to(struct context *ctx) { - volatile struct context *save; - struct context *ret; + struct context *save, *ret; debug("switching to new context:\n"); save = __context; __context = ctx; asm ("pushl %cs; call __switch_context"); ret = __context; - __context = (struct context *)save; + __context = save; return ret; } diff --git a/roms/openbios/arch/ppc/build.xml b/roms/openbios/arch/ppc/build.xml index e6063136f..29f6601f9 100644 --- a/roms/openbios/arch/ppc/build.xml +++ b/roms/openbios/arch/ppc/build.xml @@ -182,8 +182,6 @@ $(call quiet-command,$(NM) $@.nostrip | sort > $(ODIR)/openbios-qemu.syms," GEN $(TARGET_DIR)$@.syms") $(call quiet-command,$(STRIP) $@.nostrip -o $@," STRIP $(TARGET_DIR)$@")</rule> <object source="qemu/start.S"/> - <object source="qemu/switch.S"/> - <object source="qemu/context.c"/> <object source="timebase.S"/> <external-object source="libqemu.a"/> <external-object source="libbootstrap.a"/> diff --git a/roms/openbios/arch/ppc/qemu/context.c b/roms/openbios/arch/ppc/qemu/context.c deleted file mode 100644 index 78205a27c..000000000 --- a/roms/openbios/arch/ppc/qemu/context.c +++ /dev/null @@ -1,140 +0,0 @@ -/* - * context switching - * 2003-10 by SONE Takeshi - */ - -#include "config.h" -#include "kernel/kernel.h" -#include "context.h" -#include "libopenbios/sys_info.h" - -#define MAIN_STACK_SIZE 16384 -#define IMAGE_STACK_SIZE 4096*2 - -#define debug printk - -#ifdef CONFIG_PPC_64BITSUPPORT - #ifdef __powerpc64__ - #define ULONG_SIZE 8 - #define STACKFRAME_MINSIZE 48 - #define STKOFF STACKFRAME_MINSIZE - #define SAVE_SPACE 320 - #else - #define ULONG_SIZE 4 - #define STACKFRAME_MINSIZE 16 - #define STKOFF 8 - #define SAVE_SPACE 144 - #endif -#endif - -static void start_main(void); /* forward decl. */ -void __exit_context(void); /* assembly routine */ - -unsigned int start_elf(unsigned long entry_point, unsigned long param); -void entry(void); -void of_client_callback(void); - -/* - * Main context structure - * It is placed at the bottom of our stack, and loaded by assembly routine - * to start us up. - */ -static struct context main_ctx = { - .sp = (unsigned long) &_estack - SAVE_SPACE, - .pc = (unsigned long) start_main, - .return_addr = (unsigned long) __exit_context, -}; - -/* This is used by assembly routine to load/store the context which - * it is to switch/switched. */ -struct context * volatile __context = &main_ctx; - -/* Stack for loaded ELF image */ -static uint8_t image_stack[IMAGE_STACK_SIZE]; - -/* Pointer to startup context (physical address) */ -unsigned long __boot_ctx; - -/* - * Main starter - * This is the C function that runs first. - */ -static void start_main(void) -{ - /* Save startup context, so we can refer to it later. - * We have to keep it in physical address since we will relocate. */ - __boot_ctx = virt_to_phys(__context); - - /* Start the real fun */ - entry(); - - /* Returning from here should jump to __exit_context */ - __context = boot_ctx; -} - -/* Setup a new context using the given stack. - */ -struct context * -init_context(uint8_t *stack, uint32_t stack_size, int num_params) -{ - struct context *ctx; - - ctx = (struct context *) - (stack + stack_size - (sizeof(*ctx) + num_params*sizeof(unsigned long))); - memset(ctx, 0, sizeof(*ctx)); - - /* Fill in reasonable default for flat memory model */ - ctx->sp = virt_to_phys(SP_LOC(ctx)); - ctx->return_addr = virt_to_phys(__exit_context); - - return ctx; -} - -/* Switch to another context. */ -struct context *switch_to(struct context *ctx) -{ - volatile struct context *save; - struct context *ret; - unsigned int lr; - - debug("switching to new context:\n"); - save = __context; - __context = ctx; - - asm __volatile__ ("mflr %%r9\n\t" - "stw %%r9, %0\n\t" - "bl __switch_context\n\t" - "lwz %%r9, %0\n\t" - "mtlr %%r9\n\t" : "=m" (lr) : "m" (lr) : "%r9" ); - - ret = __context; - __context = (struct context *)save; - return ret; -} - -/* Start ELF Boot image */ -unsigned int start_elf(unsigned long entry_point, unsigned long param) -{ - struct context *ctx; - - /* According to IEEE 1275, PPC bindings: - * - * MSR = FP, ME + (DR|IR) - * r1 = stack (32 K + 32 bytes link area above) - * r5 = client interface handler - * r6 = address of client program arguments (unused) - * r7 = length of client program arguments (unused) - * - * Yaboot and Linux use r3 and r4 for initrd address and size - */ - - ctx = init_context(image_stack, sizeof image_stack, 1); - ctx->pc = entry_point; - ctx->regs[REG_R5] = (unsigned long)of_client_callback; - ctx->regs[REG_R6] = 0; - ctx->regs[REG_R7] = 0; - ctx->param[0] = param; - - ctx = switch_to(ctx); - return ctx->regs[REG_R3]; -} diff --git a/roms/openbios/arch/ppc/qemu/context.h b/roms/openbios/arch/ppc/qemu/context.h deleted file mode 100644 index 8135bb4c1..000000000 --- a/roms/openbios/arch/ppc/qemu/context.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef PPC_CONTEXT_H -#define PPC_CONTEXT_H - -struct context { -#define SP_LOC(ctx) (&(ctx)->sp) - unsigned long _sp; - unsigned long return_addr; - unsigned long sp; - unsigned long pc; - /* General registers */ - unsigned long regs[34]; -#define REG_R3 3 -#define REG_R5 8 -#define REG_R6 9 -#define REG_R7 10 - /* Flags */ - /* Optional stack contents */ - unsigned long param[0]; -}; - -/* Create a new context in the given stack */ -struct context * -init_context(uint8_t *stack, uint32_t stack_size, int num_param); - -/* Switch context */ -struct context *switch_to(struct context *); - -/* Holds physical address of boot context */ -extern unsigned long __boot_ctx; - -/* This can always be safely used to refer to the boot context */ -#define boot_ctx ((struct context *) phys_to_virt(__boot_ctx)) - -#endif /* PPC_CONTEXT_H */ diff --git a/roms/openbios/arch/ppc/qemu/init.c b/roms/openbios/arch/ppc/qemu/init.c index 8f264f41d..b76c5706f 100644 --- a/roms/openbios/arch/ppc/qemu/init.c +++ b/roms/openbios/arch/ppc/qemu/init.c @@ -35,7 +35,6 @@ #define NO_QEMU_PROTOS #include "arch/common/fw_cfg.h" #include "arch/ppc/processor.h" -#include "context.h" #define UUID_FMT "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x" @@ -596,7 +595,6 @@ id_cpu(void) } static void go(void); -unsigned int start_elf(unsigned long entry_point, unsigned long param); static void go(void) @@ -611,7 +609,7 @@ go(void) feval("saved-program-state >sps.entry @"); addr = POP(); - start_elf((unsigned long)addr, 0); + call_elf(0, 0, addr); } static void kvm_of_init(void) diff --git a/roms/openbios/arch/ppc/qemu/ldscript b/roms/openbios/arch/ppc/qemu/ldscript index 11ebf4b39..8027b39db 100644 --- a/roms/openbios/arch/ppc/qemu/ldscript +++ b/roms/openbios/arch/ppc/qemu/ldscript @@ -51,11 +51,7 @@ SECTIONS *(.bss) *(.bss.*) *(COMMON) - - _stack = .; - . += CSTACK_SIZE; - . = ALIGN(16); - _estack = .; + _ebss = .; } . = HRESET_ADDR; diff --git a/roms/openbios/arch/ppc/qemu/ofmem.c b/roms/openbios/arch/ppc/qemu/ofmem.c index 7b8ced0e0..6f346a3d4 100644 --- a/roms/openbios/arch/ppc/qemu/ofmem.c +++ b/roms/openbios/arch/ppc/qemu/ofmem.c @@ -359,11 +359,9 @@ hash_page_64(unsigned long ea, phys_addr_t phys, ucell mode) found = 1; /* otherwise use a free slot */ - if (!found) { - for (i = 0; !found && i < 8; i++) - if (!pp[i].v) - found = 1; - } + for (i = 0; !found && i < 8; i++) + if (!pp[i].v) + found = 1; /* out of slots, just evict one */ if (!found) @@ -416,11 +414,9 @@ hash_page_32(unsigned long ea, phys_addr_t phys, ucell mode) found = 1; /* otherwise use a free slot */ - if (!found) { - for (i = 0; !found && i < 8; i++) - if (!pp[i].v) - found = 1; - } + for (i = 0; !found && i < 8; i++) + if (!pp[i].v) + found = 1; /* out of slots, just evict one */ if (!found) @@ -482,36 +478,6 @@ isi_exception(void) hash_page(nip, phys, mode); } -/* - * Power ISA 2.x has deleted the rfi instruction and rfid shoud be - * used instead on cpus following this instruction set or later. - * - * OpenBIOS 32bits is compiled to use rfi. But, when it runs on a - * Power ISA 2.x cpu (a 970 for instance), we need to replace the rfi - * instructions with rfid in the vectors' memory section. Else we - * won't go any futher than the first exception ... - */ -#define RFI 0x4c000064 -#define RFID 0x4c000024 - -extern char __vectors[]; -extern char __vectors_end[]; - -static void patch_rfi(void) -{ - uint32_t* ptr; - uint32_t* vec_start = (uint32_t*) 0x100UL; - uint32_t* vec_end = (uint32_t*) (__vectors_end - __vectors); - - if (!is_ppc64()) - return; - - for (ptr = vec_start; ptr != vec_end; ptr++) { - if (*ptr == RFI) - *ptr = RFID; - } - flush_icache_range((char*) vec_start , (char*) vec_end); -} /************************************************************************/ /* init / cleanup */ @@ -566,8 +532,6 @@ setup_mmu(unsigned long ramsize) memcpy((void *)get_rom_base(), (void *)OF_CODE_START, OF_CODE_SIZE); - patch_rfi(); - /* Enable MMU */ mtmsr(mfmsr() | MSR_IR | MSR_DR); diff --git a/roms/openbios/arch/ppc/qemu/start.S b/roms/openbios/arch/ppc/qemu/start.S index 33ca1e03e..ae2fd53dc 100644 --- a/roms/openbios/arch/ppc/qemu/start.S +++ b/roms/openbios/arch/ppc/qemu/start.S @@ -482,15 +482,56 @@ real_entry: #endif bl BRANCH_LABEL(setup_mmu) - bl BRANCH_LABEL(__switch_context_nosave) + bl BRANCH_LABEL(entry) 1: nop b 1b + + /* According to IEEE 1275, PPC bindings: + * + * MSR = FP, ME + (DR|IR) + * r1 = stack (32 K + 32 bytes link area above) + * r5 = client interface handler + * r6 = address of client program arguments (unused) + * r7 = length of client program arguments (unused) + * + * Yaboot and Linux use r3 and r4 for initrd address and size + */ .data -_GLOBAL(saved_stack): - DATA_LONG(0) - +saved_stack: + DATA_LONG(0) .previous + /* void call_elf( arg1, arg2, entry ) */ +_GLOBAL(call_elf): + mflr r0 + PPC_STLU r1, -STACKFRAME_MINSIZE(r1) + PPC_STL r0, (STACKFRAME_MINSIZE + PPC_LR_STKOFF)(r1) + mtlr r5 + LOAD_REG_IMMEDIATE(r8, saved_stack) // save our stack pointer + PPC_STL r1,0(r8) + mfsdr1 r1 + addi r1, r1, -32768 /* - 32 KiB exception stack */ + addis r1, r1, -1 /* - 64 KiB stack */ + LOAD_REG_IMMEDIATE(r5, of_client_callback) // r5 = callback + li r6,0 // r6 = address of client program arguments (unused) + li r7,0 // r7 = length of client program arguments (unused) + li r0,MSR_FP | MSR_ME | MSR_DR | MSR_IR + MTMSRD(r0) + blrl + +#ifdef CONFIG_PPC64 + /* Restore SF bit */ + LOAD_REG_IMMEDIATE(r0, MSR_SF | MSR_FP | MSR_ME | MSR_DR | MSR_IR) + MTMSRD(r0) +#endif + LOAD_REG_IMMEDIATE(r8, saved_stack) // restore stack pointer + mr r1,r8 + PPC_LL r0, (STACKFRAME_MINSIZE + PPC_LR_STKOFF)(r1) + mtlr r0 + addi r1, r1, STACKFRAME_MINSIZE + // XXX: should restore r12-r31 etc.. + // we should not really come here though + blr #ifdef __powerpc64__ #define STKOFF STACKFRAME_MINSIZE @@ -499,126 +540,133 @@ _GLOBAL(saved_stack): #define STKOFF 8 #define SAVE_SPACE 144 #endif - GLOBL(of_client_callback): + #ifdef CONFIG_PPC64 - PPC_STLU r1, -(STACKFRAME_MINSIZE + 16)(r1) + PPC_STLU r1, -(STACKFRAME_MINSIZE + 16)(r1) #else - PPC_STLU r1, -STACKFRAME_MINSIZE(r1) /* fits within alignment */ + PPC_STLU r1, -STACKFRAME_MINSIZE(r1) /* fits within alignment */ #endif /* save r4 */ - PPC_STL r4, STKOFF(r1) - + + PPC_STL r4, STKOFF(r1) + /* save lr */ + mflr r4 - PPC_STL r4, PPC_LR_STKOFF(r1) - + PPC_STL r4, PPC_LR_STKOFF(r1) + /* restore OF stack */ + LOAD_REG_IMMEDIATE(r4, saved_stack) - PPC_LL r4, 0(r4) - - PPC_STLU r4, -SAVE_SPACE(r4) - PPC_STL r1, (STKOFF)(r4) // save caller stack + PPC_LL r4, 0(r4) + + PPC_STLU r4,-SAVE_SPACE(r4) + PPC_STL r1,(STKOFF)(r4) // save caller stack mr r1,r4 - - PPC_STL r3, (STKOFF + 5 * ULONG_SIZE)(r1) - PPC_STL r2, (STKOFF + 4 * ULONG_SIZE)(r1) - PPC_STL r0, (STKOFF + 3 * ULONG_SIZE)(r1) - + + PPC_STL r2, (STKOFF + 1 * ULONG_SIZE)(r1) + PPC_STL r0, (STKOFF + 2 * ULONG_SIZE)(r1) + /* save ctr, cr and xer */ + mfctr r2 - PPC_STL r2, (STKOFF + 6 * ULONG_SIZE)(r1) + PPC_STL r2, (STKOFF + 3 * ULONG_SIZE)(r1) mfcr r2 - PPC_STL r2, (STKOFF + 7 * ULONG_SIZE)(r1) + PPC_STL r2, (STKOFF + 4 * ULONG_SIZE)(r1) mfxer r2 - PPC_STL r2, (STKOFF + 8 * ULONG_SIZE)(r1) - + PPC_STL r2, (STKOFF + 5 * ULONG_SIZE)(r1) + /* save r5 - r31 */ - PPC_STL r5, (STKOFF + 10 * ULONG_SIZE)(r1) - PPC_STL r6, (STKOFF + 11 * ULONG_SIZE)(r1) - PPC_STL r7, (STKOFF + 12 * ULONG_SIZE)(r1) - PPC_STL r8, (STKOFF + 13 * ULONG_SIZE)(r1) - PPC_STL r9, (STKOFF + 14 * ULONG_SIZE)(r1) - PPC_STL r10, (STKOFF + 15 * ULONG_SIZE)(r1) - PPC_STL r11, (STKOFF + 16 * ULONG_SIZE)(r1) - PPC_STL r12, (STKOFF + 17 * ULONG_SIZE)(r1) - PPC_STL r13, (STKOFF + 18 * ULONG_SIZE)(r1) - PPC_STL r14, (STKOFF + 19 * ULONG_SIZE)(r1) - PPC_STL r15, (STKOFF + 20 * ULONG_SIZE)(r1) - PPC_STL r16, (STKOFF + 21 * ULONG_SIZE)(r1) - PPC_STL r17, (STKOFF + 22 * ULONG_SIZE)(r1) - PPC_STL r18, (STKOFF + 23 * ULONG_SIZE)(r1) - PPC_STL r19, (STKOFF + 24 * ULONG_SIZE)(r1) - PPC_STL r20, (STKOFF + 25 * ULONG_SIZE)(r1) - PPC_STL r21, (STKOFF + 26 * ULONG_SIZE)(r1) - PPC_STL r22, (STKOFF + 27 * ULONG_SIZE)(r1) - PPC_STL r23, (STKOFF + 28 * ULONG_SIZE)(r1) - PPC_STL r24, (STKOFF + 29 * ULONG_SIZE)(r1) - PPC_STL r25, (STKOFF + 30 * ULONG_SIZE)(r1) - PPC_STL r26, (STKOFF + 31 * ULONG_SIZE)(r1) - PPC_STL r27, (STKOFF + 32 * ULONG_SIZE)(r1) - PPC_STL r28, (STKOFF + 33 * ULONG_SIZE)(r1) - PPC_STL r29, (STKOFF + 34 * ULONG_SIZE)(r1) - PPC_STL r30, (STKOFF + 35 * ULONG_SIZE)(r1) - PPC_STL r31, (STKOFF + 36 * ULONG_SIZE)(r1) - + + PPC_STL r5, (STKOFF + 6 * ULONG_SIZE)(r1) + PPC_STL r6, (STKOFF + 7 * ULONG_SIZE)(r1) + PPC_STL r7, (STKOFF + 8 * ULONG_SIZE)(r1) + PPC_STL r8, (STKOFF + 9 * ULONG_SIZE)(r1) + PPC_STL r9, (STKOFF + 10 * ULONG_SIZE)(r1) + PPC_STL r10, (STKOFF + 11 * ULONG_SIZE)(r1) + PPC_STL r11, (STKOFF + 12 * ULONG_SIZE)(r1) + PPC_STL r12, (STKOFF + 13 * ULONG_SIZE)(r1) + PPC_STL r13, (STKOFF + 14 * ULONG_SIZE)(r1) + PPC_STL r14, (STKOFF + 15 * ULONG_SIZE)(r1) + PPC_STL r15, (STKOFF + 16 * ULONG_SIZE)(r1) + PPC_STL r16, (STKOFF + 17 * ULONG_SIZE)(r1) + PPC_STL r17, (STKOFF + 18 * ULONG_SIZE)(r1) + PPC_STL r18, (STKOFF + 19 * ULONG_SIZE)(r1) + PPC_STL r19, (STKOFF + 20 * ULONG_SIZE)(r1) + PPC_STL r20, (STKOFF + 21 * ULONG_SIZE)(r1) + PPC_STL r21, (STKOFF + 22 * ULONG_SIZE)(r1) + PPC_STL r22, (STKOFF + 23 * ULONG_SIZE)(r1) + PPC_STL r23, (STKOFF + 24 * ULONG_SIZE)(r1) + PPC_STL r24, (STKOFF + 25 * ULONG_SIZE)(r1) + PPC_STL r25, (STKOFF + 26 * ULONG_SIZE)(r1) + PPC_STL r26, (STKOFF + 27 * ULONG_SIZE)(r1) + PPC_STL r27, (STKOFF + 28 * ULONG_SIZE)(r1) + PPC_STL r28, (STKOFF + 29 * ULONG_SIZE)(r1) + PPC_STL r29, (STKOFF + 30 * ULONG_SIZE)(r1) + PPC_STL r30, (STKOFF + 31 * ULONG_SIZE)(r1) + PPC_STL r31, (STKOFF + 32 * ULONG_SIZE)(r1) + #ifdef CONFIG_PPC64 - LOAD_REG_IMMEDIATE(r2, of_client_interface) - ld r2, 8(r2) + LOAD_REG_IMMEDIATE(r2, of_client_interface) + ld r2, 8(r2) #endif - - bl BRANCH_LABEL(of_client_interface) - + bl BRANCH_LABEL(of_client_interface) + /* restore r5 - r31 */ - PPC_LL r5, (STKOFF + 10 * ULONG_SIZE)(r1) - PPC_LL r6, (STKOFF + 11 * ULONG_SIZE)(r1) - PPC_LL r7, (STKOFF + 12 * ULONG_SIZE)(r1) - PPC_LL r8, (STKOFF + 13 * ULONG_SIZE)(r1) - PPC_LL r9, (STKOFF + 14 * ULONG_SIZE)(r1) - PPC_LL r10, (STKOFF + 15 * ULONG_SIZE)(r1) - PPC_LL r11, (STKOFF + 16 * ULONG_SIZE)(r1) - PPC_LL r12, (STKOFF + 17 * ULONG_SIZE)(r1) - PPC_LL r13, (STKOFF + 18 * ULONG_SIZE)(r1) - PPC_LL r14, (STKOFF + 19 * ULONG_SIZE)(r1) - PPC_LL r15, (STKOFF + 20 * ULONG_SIZE)(r1) - PPC_LL r16, (STKOFF + 21 * ULONG_SIZE)(r1) - PPC_LL r17, (STKOFF + 22 * ULONG_SIZE)(r1) - PPC_LL r18, (STKOFF + 23 * ULONG_SIZE)(r1) - PPC_LL r19, (STKOFF + 24 * ULONG_SIZE)(r1) - PPC_LL r20, (STKOFF + 25 * ULONG_SIZE)(r1) - PPC_LL r21, (STKOFF + 26 * ULONG_SIZE)(r1) - PPC_LL r22, (STKOFF + 27 * ULONG_SIZE)(r1) - PPC_LL r23, (STKOFF + 28 * ULONG_SIZE)(r1) - PPC_LL r24, (STKOFF + 29 * ULONG_SIZE)(r1) - PPC_LL r25, (STKOFF + 30 * ULONG_SIZE)(r1) - PPC_LL r26, (STKOFF + 31 * ULONG_SIZE)(r1) - PPC_LL r27, (STKOFF + 32 * ULONG_SIZE)(r1) - PPC_LL r28, (STKOFF + 33 * ULONG_SIZE)(r1) - PPC_LL r29, (STKOFF + 34 * ULONG_SIZE)(r1) - PPC_LL r30, (STKOFF + 35 * ULONG_SIZE)(r1) - PPC_LL r31, (STKOFF + 36 * ULONG_SIZE)(r1) - + + PPC_LL r5, (STKOFF + 6 * ULONG_SIZE)(r1) + PPC_LL r6, (STKOFF + 7 * ULONG_SIZE)(r1) + PPC_LL r7, (STKOFF + 8 * ULONG_SIZE)(r1) + PPC_LL r8, (STKOFF + 9 * ULONG_SIZE)(r1) + PPC_LL r9, (STKOFF + 10 * ULONG_SIZE)(r1) + PPC_LL r10, (STKOFF + 11 * ULONG_SIZE)(r1) + PPC_LL r11, (STKOFF + 12 * ULONG_SIZE)(r1) + PPC_LL r12, (STKOFF + 13 * ULONG_SIZE)(r1) + PPC_LL r13, (STKOFF + 14 * ULONG_SIZE)(r1) + PPC_LL r14, (STKOFF + 15 * ULONG_SIZE)(r1) + PPC_LL r15, (STKOFF + 16 * ULONG_SIZE)(r1) + PPC_LL r16, (STKOFF + 17 * ULONG_SIZE)(r1) + PPC_LL r17, (STKOFF + 18 * ULONG_SIZE)(r1) + PPC_LL r18, (STKOFF + 19 * ULONG_SIZE)(r1) + PPC_LL r19, (STKOFF + 20 * ULONG_SIZE)(r1) + PPC_LL r20, (STKOFF + 21 * ULONG_SIZE)(r1) + PPC_LL r21, (STKOFF + 22 * ULONG_SIZE)(r1) + PPC_LL r22, (STKOFF + 23 * ULONG_SIZE)(r1) + PPC_LL r23, (STKOFF + 24 * ULONG_SIZE)(r1) + PPC_LL r24, (STKOFF + 25 * ULONG_SIZE)(r1) + PPC_LL r25, (STKOFF + 26 * ULONG_SIZE)(r1) + PPC_LL r26, (STKOFF + 27 * ULONG_SIZE)(r1) + PPC_LL r27, (STKOFF + 28 * ULONG_SIZE)(r1) + PPC_LL r28, (STKOFF + 29 * ULONG_SIZE)(r1) + PPC_LL r29, (STKOFF + 30 * ULONG_SIZE)(r1) + PPC_LL r30, (STKOFF + 31 * ULONG_SIZE)(r1) + PPC_LL r31, (STKOFF + 32 * ULONG_SIZE)(r1) + /* restore ctr, cr and xer */ - PPC_LL r2, (STKOFF + 6 * ULONG_SIZE)(r1) + + PPC_LL r2, (STKOFF + 3 * ULONG_SIZE)(r1) mtctr r2 - PPC_LL r2, (STKOFF + 7 * ULONG_SIZE)(r1) + PPC_LL r2, (STKOFF + 4 * ULONG_SIZE)(r1) mtcr r2 - PPC_LL r2, (STKOFF + 8 * ULONG_SIZE)(r1) + PPC_LL r2, (STKOFF + 5 * ULONG_SIZE)(r1) mtxer r2 - + /* restore r0 and r2 */ - PPC_LL r2, (STKOFF + 4 * ULONG_SIZE)(r1) - PPC_LL r0, (STKOFF + 3 * ULONG_SIZE)(r1) - + + PPC_LL r2, (STKOFF + 1 * ULONG_SIZE)(r1) + PPC_LL r0, (STKOFF + 2 * ULONG_SIZE)(r1) + /* restore caller stack */ - PPC_LL r1, (STKOFF)(r1) - - PPC_LL r4, PPC_LR_STKOFF(r1) + + PPC_LL r1, (STKOFF)(r1) + + PPC_LL r4, PPC_LR_STKOFF(r1) mtlr r4 - PPC_LL r4, STKOFF(r1) - PPC_LL r1, 0(r1) - + PPC_LL r4, STKOFF(r1) + PPC_LL r1, 0(r1) + blr /* rtas glue (must be reloctable) */ diff --git a/roms/openbios/arch/ppc/qemu/switch.S b/roms/openbios/arch/ppc/qemu/switch.S deleted file mode 100644 index c3d9d7078..000000000 --- a/roms/openbios/arch/ppc/qemu/switch.S +++ /dev/null @@ -1,211 +0,0 @@ -#include "autoconf.h" -#include "asm/asmdefs.h" -#include "asm/processor.h" - - -#ifdef CONFIG_PPC_64BITSUPPORT - #ifdef __powerpc64__ - #define ULONG_SIZE 8 - #define STACKFRAME_MINSIZE 48 - #define STKOFF STACKFRAME_MINSIZE - #define SAVE_SPACE 320 - #else - #define ULONG_SIZE 4 - #define STACKFRAME_MINSIZE 16 - #define STKOFF 8 - #define SAVE_SPACE 144 - #endif -#endif - - /* According to IEEE 1275, PPC bindings: - * - * MSR = FP, ME + (DR|IR) - * r1 = stack (32 K + 32 bytes link area above) - * r5 = client interface handler - * r6 = address of client program arguments (unused) - * r7 = length of client program arguments (unused) - * - * Yaboot and Linux use r3 and r4 for initrd address and size - */ - - /* void call_elf( arg1, arg2, entry ) */ -_GLOBAL(call_elf): - mflr r0 - PPC_STLU r1, -STACKFRAME_MINSIZE(r1) - PPC_STL r0, (STACKFRAME_MINSIZE + PPC_LR_STKOFF)(r1) - mtlr r5 - LOAD_REG_IMMEDIATE(r8, saved_stack) // save our stack pointer - PPC_STL r1,0(r8) - mfsdr1 r1 - addi r1, r1, -32768 /* - 32 KiB exception stack */ - addis r1, r1, -1 /* - 64 KiB stack */ - LOAD_REG_IMMEDIATE(r5, of_client_callback) // r5 = callback - li r6,0 // r6 = address of client program arguments (unused) - li r7,0 // r7 = length of client program arguments (unused) - li r0,MSR_FP | MSR_ME | MSR_DR | MSR_IR - MTMSRD(r0) - blrl - -#ifdef CONFIG_PPC64 - /* Restore SF bit */ - LOAD_REG_IMMEDIATE(r0, MSR_SF | MSR_FP | MSR_ME | MSR_DR | MSR_IR) - MTMSRD(r0) -#endif - LOAD_REG_IMMEDIATE(r8, saved_stack) // restore stack pointer - mr r1,r8 - PPC_LL r0, (STACKFRAME_MINSIZE + PPC_LR_STKOFF)(r1) - mtlr r0 - addi r1, r1, STACKFRAME_MINSIZE - // XXX: should restore r12-r31 etc.. - // we should not really come here though - blrl - -/* - * Switch execution context - * This saves registers in the stack, then - * switches the stack, and restores everything from the new stack. - * This function takes no argument. New stack pointer is - * taken from global variable __context, and old stack pointer - * is also saved to __context. This way we can just jump to - * this routine to get back to the original context. - */ - -_GLOBAL(__switch_context): - /* save internal stack pointer */ -#ifdef CONFIG_PPC64 - PPC_STL r1, -(SAVE_SPACE + 16) + STKOFF(r1) -#else - PPC_STL r1, -SAVE_SPACE + STKOFF(r1) -#endif - -#ifdef CONFIG_PPC64 - PPC_STLU r1, -(SAVE_SPACE + 16)(r1) -#else - PPC_STLU r1, -SAVE_SPACE(r1) /* fits within alignment */ -#endif - - /* r4, r5 */ - PPC_STL r4, (STKOFF + 9 * ULONG_SIZE)(r1) - PPC_STL r5, (STKOFF + 10 * ULONG_SIZE)(r1) - - /* link register */ - mflr r4 - PPC_STL r4, PPC_LR_STKOFF(r1) - PPC_STL r4, (STKOFF + ULONG_SIZE)(r1) - - PPC_STL r3, (STKOFF + 5 * ULONG_SIZE)(r1) - PPC_STL r2, (STKOFF + 4 * ULONG_SIZE)(r1) - PPC_STL r0, (STKOFF + 3 * ULONG_SIZE)(r1) - - /* ctr, cr and xer */ - mfctr r4 - PPC_STL r4, (STKOFF + 6 * ULONG_SIZE)(r1) - mfcr r4 - PPC_STL r4, (STKOFF + 7 * ULONG_SIZE)(r1) - mfxer r4 - PPC_STL r4, (STKOFF + 8 * ULONG_SIZE)(r1) - - /* r6-r31 */ - PPC_STL r6, (STKOFF + 11 * ULONG_SIZE)(r1) - PPC_STL r7, (STKOFF + 12 * ULONG_SIZE)(r1) - PPC_STL r8, (STKOFF + 13 * ULONG_SIZE)(r1) - PPC_STL r9, (STKOFF + 14 * ULONG_SIZE)(r1) - PPC_STL r10, (STKOFF + 15 * ULONG_SIZE)(r1) - PPC_STL r11, (STKOFF + 16 * ULONG_SIZE)(r1) - PPC_STL r12, (STKOFF + 17 * ULONG_SIZE)(r1) - PPC_STL r13, (STKOFF + 18 * ULONG_SIZE)(r1) - PPC_STL r14, (STKOFF + 19 * ULONG_SIZE)(r1) - PPC_STL r15, (STKOFF + 20 * ULONG_SIZE)(r1) - PPC_STL r16, (STKOFF + 21 * ULONG_SIZE)(r1) - PPC_STL r17, (STKOFF + 22 * ULONG_SIZE)(r1) - PPC_STL r18, (STKOFF + 23 * ULONG_SIZE)(r1) - PPC_STL r19, (STKOFF + 24 * ULONG_SIZE)(r1) - PPC_STL r20, (STKOFF + 25 * ULONG_SIZE)(r1) - PPC_STL r21, (STKOFF + 26 * ULONG_SIZE)(r1) - PPC_STL r22, (STKOFF + 27 * ULONG_SIZE)(r1) - PPC_STL r23, (STKOFF + 28 * ULONG_SIZE)(r1) - PPC_STL r24, (STKOFF + 29 * ULONG_SIZE)(r1) - PPC_STL r25, (STKOFF + 30 * ULONG_SIZE)(r1) - PPC_STL r26, (STKOFF + 31 * ULONG_SIZE)(r1) - PPC_STL r27, (STKOFF + 32 * ULONG_SIZE)(r1) - PPC_STL r28, (STKOFF + 33 * ULONG_SIZE)(r1) - PPC_STL r29, (STKOFF + 34 * ULONG_SIZE)(r1) - PPC_STL r30, (STKOFF + 35 * ULONG_SIZE)(r1) - PPC_STL r31, (STKOFF + 36 * ULONG_SIZE)(r1) - - /* swap context */ - LOAD_REG_IMMEDIATE(r4, __context) - PPC_LL r5, 0(r4) - PPC_STL r1, 0(r4) - mr r4, r5 - - b __set_context - -_GLOBAL(__switch_context_nosave): - LOAD_REG_IMMEDIATE(r4, __context) - PPC_LL r4, 0(r4) - -__set_context: - /* link register */ - PPC_LL r5, (STKOFF + ULONG_SIZE)(r4) - mtlr r5 - - PPC_LL r3, (STKOFF + 5 * ULONG_SIZE)(r4) - PPC_LL r2, (STKOFF + 4 * ULONG_SIZE)(r4) - PPC_LL r0, (STKOFF + 3 * ULONG_SIZE)(r4) - - /* ctr, cr and xer */ - PPC_LL r5, (STKOFF + 6 * ULONG_SIZE)(r4) - mtctr r5 - PPC_LL r5, (STKOFF + 7 * ULONG_SIZE)(r4) - mtcr r5 - PPC_LL r5, (STKOFF + 8 * ULONG_SIZE)(r4) - mtxer r5 - - /* r5-r31 */ - PPC_LL r5, (STKOFF + 10 * ULONG_SIZE)(r4) - PPC_LL r6, (STKOFF + 11 * ULONG_SIZE)(r4) - PPC_LL r7, (STKOFF + 12 * ULONG_SIZE)(r4) - PPC_LL r8, (STKOFF + 13 * ULONG_SIZE)(r4) - PPC_LL r9, (STKOFF + 14 * ULONG_SIZE)(r4) - PPC_LL r10, (STKOFF + 15 * ULONG_SIZE)(r4) - PPC_LL r11, (STKOFF + 16 * ULONG_SIZE)(r4) - PPC_LL r12, (STKOFF + 17 * ULONG_SIZE)(r4) - PPC_LL r13, (STKOFF + 18 * ULONG_SIZE)(r4) - PPC_LL r14, (STKOFF + 19 * ULONG_SIZE)(r4) - PPC_LL r15, (STKOFF + 20 * ULONG_SIZE)(r4) - PPC_LL r16, (STKOFF + 21 * ULONG_SIZE)(r4) - PPC_LL r17, (STKOFF + 22 * ULONG_SIZE)(r4) - PPC_LL r18, (STKOFF + 23 * ULONG_SIZE)(r4) - PPC_LL r19, (STKOFF + 24 * ULONG_SIZE)(r4) - PPC_LL r20, (STKOFF + 25 * ULONG_SIZE)(r4) - PPC_LL r21, (STKOFF + 26 * ULONG_SIZE)(r4) - PPC_LL r22, (STKOFF + 27 * ULONG_SIZE)(r4) - PPC_LL r23, (STKOFF + 28 * ULONG_SIZE)(r4) - PPC_LL r24, (STKOFF + 29 * ULONG_SIZE)(r4) - PPC_LL r25, (STKOFF + 30 * ULONG_SIZE)(r4) - PPC_LL r26, (STKOFF + 31 * ULONG_SIZE)(r4) - PPC_LL r27, (STKOFF + 32 * ULONG_SIZE)(r4) - PPC_LL r28, (STKOFF + 33 * ULONG_SIZE)(r4) - PPC_LL r29, (STKOFF + 34 * ULONG_SIZE)(r4) - PPC_LL r30, (STKOFF + 35 * ULONG_SIZE)(r4) - PPC_LL r31, (STKOFF + 36 * ULONG_SIZE)(r4) - - /* r4, r1 */ - PPC_LL r1, STKOFF(r4) - PPC_LL r4, (STKOFF + 8 * ULONG_SIZE)(r4) - - LOAD_REG_IMMEDIATE(r0, MSR_FP | MSR_ME | MSR_DR | MSR_IR) - MTMSRD(r0) - - blrl - -#ifdef CONFIG_PPC64 - /* Restore SF bit */ - LOAD_REG_IMMEDIATE(r0, MSR_SF | MSR_FP | MSR_ME | MSR_DR | MSR_IR) - MTMSRD(r0) -#endif - -_GLOBAL(__exit_context): - /* Get back to the original context */ - b __switch_context diff --git a/roms/openbios/arch/sparc32/openbios.c b/roms/openbios/arch/sparc32/openbios.c index 10ac9b9f3..6f4ee454e 100644 --- a/roms/openbios/arch/sparc32/openbios.c +++ b/roms/openbios/arch/sparc32/openbios.c @@ -897,7 +897,7 @@ arch_init( void ) push_str("floppy"); break; case 'c': - push_str("disk:a disk"); + push_str("disk"); break; default: case 'd': diff --git a/roms/openbios/arch/sparc64/context.c b/roms/openbios/arch/sparc64/context.c index 823116f11..98932ee9c 100644 --- a/roms/openbios/arch/sparc64/context.c +++ b/roms/openbios/arch/sparc64/context.c @@ -88,8 +88,7 @@ init_context(uint8_t *stack, uint64_t stack_size, int num_params) /* Switch to another context. */ struct context *switch_to(struct context *ctx) { - volatile struct context *save; - struct context *ret; + struct context *save, *ret; debug("switching to new context: entry point %#llx stack 0x%016llx\n", ctx->pc, ctx->regs[REG_SP]); save = __context; @@ -97,7 +96,7 @@ struct context *switch_to(struct context *ctx) //asm ("pushl %cs; call __switch_context"); asm ("call __switch_context_nosave; nop"); ret = __context; - __context = (struct context *)save; + __context = save; return ret; } diff --git a/roms/openbios/forth/bootstrap/interpreter.fs b/roms/openbios/forth/bootstrap/interpreter.fs index f02000f8e..51870581f 100644 --- a/roms/openbios/forth/bootstrap/interpreter.fs +++ b/roms/openbios/forth/bootstrap/interpreter.fs @@ -163,11 +163,9 @@ defer outer-interpreter : evaluate ( str len -- ?? ) 2dup + -rot over + over do - i c@ dup 0a = swap 0d = or if + i c@ 0a = if i over - - rot >r (evaluate) - r> i 1+ then loop diff --git a/roms/openbios/forth/lib/build.xml b/roms/openbios/forth/lib/build.xml index f1c9a45f2..34eee4072 100644 --- a/roms/openbios/forth/lib/build.xml +++ b/roms/openbios/forth/lib/build.xml @@ -8,7 +8,6 @@ --> <dictionary name="openbios" target="forth"> - <object source="rstack.fs"/> <object source="vocabulary.fs"/> <object source="string.fs"/> <object source="preprocessor.fs"/> diff --git a/roms/openbios/forth/lib/rstack.fs b/roms/openbios/forth/lib/rstack.fs deleted file mode 100644 index c095a9efd..000000000 --- a/roms/openbios/forth/lib/rstack.fs +++ /dev/null @@ -1,21 +0,0 @@ -\ tag: pseudo r-stack implementation for openbios -\ -\ Copyright (C) 2016 Mark Cave-Ayland -\ -\ See the file "COPYING" for further information about -\ the copyright and warranty status of this work. -\ - -\ -\ Pseudo r-stack implementation for interpret mode -\ - -create prstack h# 20 cells allot -variable #prstack 0 #prstack ! - -: prstack-push prstack #prstack @ cells + ! 1 #prstack +! ; -: prstack-pop -1 #prstack +! prstack #prstack @ cells + @ ; - -: >r state @ if ['] >r , exit then r> swap prstack-push >r ; immediate -: r> state @ if ['] r> , exit then r> prstack-pop swap >r ; immediate -: r@ state @ if ['] r@ , exit then r> prstack-pop dup prstack-push swap >r ; immediate diff --git a/roms/openbios/include/arch/ppc/io.h b/roms/openbios/include/arch/ppc/io.h index 39c60d7e6..3449c5bf0 100644 --- a/roms/openbios/include/arch/ppc/io.h +++ b/roms/openbios/include/arch/ppc/io.h @@ -6,7 +6,7 @@ #define NO_QEMU_PROTOS #include "arch/common/fw_cfg.h" -extern char _start, _end, _estack; +extern char _start, _end; extern unsigned long virt_offset; #define phys_to_virt(phys) ((void *) ((unsigned long) (phys) - virt_offset)) diff --git a/roms/seabios/.version b/roms/seabios/.version index 904325020..89c0c6acb 100644 --- a/roms/seabios/.version +++ b/roms/seabios/.version @@ -1 +1 @@ -rel-1.9.3-0-ge2fc41e +rel-1.9.1-0-gb3ef39f diff --git a/roms/seabios/scripts/layoutrom.py b/roms/seabios/scripts/layoutrom.py index 6616721d1..b976fb056 100755 --- a/roms/seabios/scripts/layoutrom.py +++ b/roms/seabios/scripts/layoutrom.py @@ -34,22 +34,18 @@ COMMONTRAILER = """ # Determine section locations ###################################################################### -# Align 'pos' up to 'alignbytes' offset +# Align 'pos' to 'alignbytes' offset def alignpos(pos, alignbytes): mask = alignbytes - 1 return (pos + mask) & ~mask -# Align 'pos' down to 'alignbytes' offset -def aligndown(pos, alignbytes): - mask = alignbytes - 1 - return pos & ~mask - # Determine the final addresses for a list of sections that end at an # address. def setSectionsStart(sections, endaddr, minalign=1, segoffset=0): totspace = 0 for section in sections: - minalign = max(minalign, section.align) + if section.align > minalign: + minalign = section.align totspace = alignpos(totspace, section.align) + section.size startaddr = int((endaddr - totspace) / minalign) * minalign curaddr = startaddr @@ -273,7 +269,7 @@ def doLayout(sections, config, genreloc): final_sec32low_end = BUILD_LOWRAM_END zonelow_base = final_sec32low_end - 64*1024 relocdelta = final_sec32low_end - sec32low_end - li.sec32low_start, sec32low_align = setSectionsStart( + li.sec32low_start, li.sec32low_align = setSectionsStart( sections32low, sec32low_end, 16 , segoffset=zonelow_base - relocdelta) li.sec32low_end = sec32low_end @@ -409,8 +405,6 @@ def writeLinkerScripts(li, out16, out32seg, out32flat): if li.config.get('CONFIG_MULTIBOOT'): multiboot_header = "LONG(0x1BADB002) LONG(0) LONG(-0x1BADB002)" sec32all_start -= 3 * 4 - sec32all_align = max([section.align for section in li.sections]) - sec32all_start = aligndown(sec32all_start, sec32all_align) out += outXRefs(filesections32flat, exportsyms=[li.entrysym]) + """ _reloc_min_align = 0x%x ; zonefseg_start = 0x%x ; diff --git a/roms/seabios/src/fw/paravirt.c b/roms/seabios/src/fw/paravirt.c index e8e419ea8..3fae13a83 100644 --- a/roms/seabios/src/fw/paravirt.c +++ b/roms/seabios/src/fw/paravirt.c @@ -130,15 +130,6 @@ qemu_preinit(void) dprintf(1, "RamSize: 0x%08x [cmos]\n", RamSize); } -#define MSR_IA32_FEATURE_CONTROL 0x0000003a - -static void msr_feature_control_setup(void) -{ - u64 feature_control_bits = romfile_loadint("etc/msr_feature_control", 0); - if (feature_control_bits) - wrmsr_smp(MSR_IA32_FEATURE_CONTROL, feature_control_bits); -} - void qemu_platform_setup(void) { @@ -157,9 +148,8 @@ qemu_platform_setup(void) smm_device_setup(); smm_setup(); - // Initialize mtrr, msr_feature_control and smp + // Initialize mtrr and smp mtrr_setup(); - msr_feature_control_setup(); smp_setup(); // Create bios tables diff --git a/roms/seabios/src/fw/pciinit.c b/roms/seabios/src/fw/pciinit.c index 66e9f5a5f..c31c2fa0c 100644 --- a/roms/seabios/src/fw/pciinit.c +++ b/roms/seabios/src/fw/pciinit.c @@ -149,22 +149,6 @@ static void piix_isa_bridge_setup(struct pci_device *pci, void *arg) dprintf(1, "PIIX3/PIIX4 init: elcr=%02x %02x\n", elcr[0], elcr[1]); } -static void mch_isa_lpc_setup(u16 bdf) -{ - /* pm io base */ - pci_config_writel(bdf, ICH9_LPC_PMBASE, - acpi_pm_base | ICH9_LPC_PMBASE_RTE); - - /* acpi enable, SCI: IRQ9 000b = irq9*/ - pci_config_writeb(bdf, ICH9_LPC_ACPI_CTRL, ICH9_LPC_ACPI_CTRL_ACPI_EN); - - /* set root complex register block BAR */ - pci_config_writel(bdf, ICH9_LPC_RCBA, - ICH9_LPC_RCBA_ADDR | ICH9_LPC_RCBA_EN); -} - -static int ICH9LpcBDF = -1; - /* ICH9 LPC PCI to ISA bridge */ /* PCI_VENDOR_ID_INTEL && PCI_DEVICE_ID_INTEL_ICH9_LPC */ static void mch_isa_bridge_setup(struct pci_device *dev, void *arg) @@ -192,10 +176,16 @@ static void mch_isa_bridge_setup(struct pci_device *dev, void *arg) outb(elcr[1], ICH9_LPC_PORT_ELCR2); dprintf(1, "Q35 LPC init: elcr=%02x %02x\n", elcr[0], elcr[1]); - ICH9LpcBDF = bdf; + /* pm io base */ + pci_config_writel(bdf, ICH9_LPC_PMBASE, + acpi_pm_base | ICH9_LPC_PMBASE_RTE); - mch_isa_lpc_setup(bdf); + /* acpi enable, SCI: IRQ9 000b = irq9*/ + pci_config_writeb(bdf, ICH9_LPC_ACPI_CTRL, ICH9_LPC_ACPI_CTRL_ACPI_EN); + /* set root complex register block BAR */ + pci_config_writel(bdf, ICH9_LPC_RCBA, + ICH9_LPC_RCBA_ADDR | ICH9_LPC_RCBA_EN); e820_add(ICH9_LPC_RCBA_ADDR, 16*1024, E820_RESERVED); acpi_pm1a_cnt = acpi_pm_base + 0x04; @@ -254,8 +244,11 @@ static void piix4_pm_setup(struct pci_device *pci, void *arg) pmtimer_setup(acpi_pm_base + 0x08); } -static void ich9_smbus_enable(u16 bdf) +/* ICH9 SMBUS */ +/* PCI_VENDOR_ID_INTEL && PCI_DEVICE_ID_INTEL_ICH9_SMBUS */ +static void ich9_smbus_setup(struct pci_device *dev, void *arg) { + u16 bdf = dev->bdf; /* map smbus into io space */ pci_config_writel(bdf, ICH9_SMB_SMB_BASE, (acpi_pm_base + 0x100) | PCI_BASE_ADDRESS_SPACE_IO); @@ -264,61 +257,6 @@ static void ich9_smbus_enable(u16 bdf) pci_config_writeb(bdf, ICH9_SMB_HOSTC, ICH9_SMB_HOSTC_HST_EN); } -static int ICH9SmbusBDF = -1; - -/* ICH9 SMBUS */ -/* PCI_VENDOR_ID_INTEL && PCI_DEVICE_ID_INTEL_ICH9_SMBUS */ -static void ich9_smbus_setup(struct pci_device *dev, void *arg) -{ - ICH9SmbusBDF = dev->bdf; - - ich9_smbus_enable(dev->bdf); -} - -static void intel_igd_setup(struct pci_device *dev, void *arg) -{ - struct romfile_s *opregion = romfile_find("etc/igd-opregion"); - u64 bdsm_size = le64_to_cpu(romfile_loadint("etc/igd-bdsm-size", 0)); - void *addr; - u16 bdf = dev->bdf; - - /* Apply OpRegion to any Intel VGA device, more than one is undefined */ - if (opregion && opregion->size) { - addr = memalign_high(PAGE_SIZE, opregion->size); - if (!addr) { - warn_noalloc(); - return; - } - - if (opregion->copy(opregion, addr, opregion->size) < 0) { - free(addr); - return; - } - - pci_config_writel(bdf, 0xFC, cpu_to_le32((u32)addr)); - - dprintf(1, "Intel IGD OpRegion enabled at 0x%08x, size %dKB, dev " - "%02x:%02x.%x\n", (u32)addr, opregion->size >> 10, - pci_bdf_to_bus(bdf), pci_bdf_to_dev(bdf), pci_bdf_to_fn(bdf)); - } - - /* Apply BDSM only to Intel VGA at 00:02.0 */ - if (bdsm_size && (bdf == pci_to_bdf(0, 2, 0))) { - addr = memalign_tmphigh(1024 * 1024, bdsm_size); - if (!addr) { - warn_noalloc(); - return; - } - - e820_add((u32)addr, bdsm_size, E820_RESERVED); - - pci_config_writel(bdf, 0x5C, cpu_to_le32((u32)addr)); - - dprintf(1, "Intel IGD BDSM enabled at 0x%08x, size %lldMB, dev " - "00:02.0\n", (u32)addr, bdsm_size >> 20); - } -} - static const struct pci_device_id pci_device_tbl[] = { /* PIIX3/PIIX4 PCI to ISA bridge */ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371SB_0, @@ -352,16 +290,9 @@ static const struct pci_device_id pci_device_tbl[] = { PCI_DEVICE_CLASS(PCI_VENDOR_ID_APPLE, 0x0017, 0xff00, apple_macio_setup), PCI_DEVICE_CLASS(PCI_VENDOR_ID_APPLE, 0x0022, 0xff00, apple_macio_setup), - /* Intel IGD OpRegion setup */ - PCI_DEVICE_CLASS(PCI_VENDOR_ID_INTEL, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA, - intel_igd_setup), - PCI_DEVICE_END, }; -static int MCHMmcfgBDF = -1; -static void mch_mmconfig_setup(u16 bdf); - void pci_resume(void) { if (!CONFIG_QEMU) { @@ -371,18 +302,6 @@ void pci_resume(void) if (PiixPmBDF >= 0) { piix4_pm_config_setup(PiixPmBDF); } - - if (ICH9LpcBDF >= 0) { - mch_isa_lpc_setup(ICH9LpcBDF); - } - - if (ICH9SmbusBDF >= 0) { - ich9_smbus_enable(ICH9SmbusBDF); - } - - if(MCHMmcfgBDF >= 0) { - mch_mmconfig_setup(MCHMmcfgBDF); - } } static void pci_bios_init_device(struct pci_device *pci) @@ -469,24 +388,18 @@ static void i440fx_mem_addr_setup(struct pci_device *dev, void *arg) pci_slot_get_irq = piix_pci_slot_get_irq; } -static void mch_mmconfig_setup(u16 bdf) +static void mch_mem_addr_setup(struct pci_device *dev, void *arg) { u64 addr = Q35_HOST_BRIDGE_PCIEXBAR_ADDR; + u32 size = Q35_HOST_BRIDGE_PCIEXBAR_SIZE; + + /* setup mmconfig */ + u16 bdf = dev->bdf; u32 upper = addr >> 32; u32 lower = (addr & 0xffffffff) | Q35_HOST_BRIDGE_PCIEXBAREN; pci_config_writel(bdf, Q35_HOST_BRIDGE_PCIEXBAR, 0); pci_config_writel(bdf, Q35_HOST_BRIDGE_PCIEXBAR + 4, upper); pci_config_writel(bdf, Q35_HOST_BRIDGE_PCIEXBAR, lower); -} - -static void mch_mem_addr_setup(struct pci_device *dev, void *arg) -{ - u64 addr = Q35_HOST_BRIDGE_PCIEXBAR_ADDR; - u32 size = Q35_HOST_BRIDGE_PCIEXBAR_SIZE; - - /* setup mmconfig */ - MCHMmcfgBDF = dev->bdf; - mch_mmconfig_setup(dev->bdf); e820_add(addr, size, E820_RESERVED); /* setup pci i/o window (above mmconfig) */ diff --git a/roms/seabios/src/fw/smp.c b/roms/seabios/src/fw/smp.c index 6e706e42a..579acdbd0 100644 --- a/roms/seabios/src/fw/smp.c +++ b/roms/seabios/src/fw/smp.c @@ -10,7 +10,7 @@ #include "output.h" // dprintf #include "romfile.h" // romfile_loadint #include "stacks.h" // yield -#include "util.h" // smp_setup, msr_feature_control_setup +#include "util.h" // smp_setup #include "x86.h" // wrmsr #define APIC_ICR_LOW ((u8*)BUILD_APIC_ADDR + 0x300) @@ -20,20 +20,20 @@ #define APIC_ENABLED 0x0100 -static struct { u32 index; u64 val; } smp_msr[32]; -static u32 smp_msr_count; +static struct { u32 index; u64 val; } smp_mtrr[32]; +static u32 smp_mtrr_count; void wrmsr_smp(u32 index, u64 val) { wrmsr(index, val); - if (smp_msr_count >= ARRAY_SIZE(smp_msr)) { + if (smp_mtrr_count >= ARRAY_SIZE(smp_mtrr)) { warn_noalloc(); return; } - smp_msr[smp_msr_count].index = index; - smp_msr[smp_msr_count].val = val; - smp_msr_count++; + smp_mtrr[smp_mtrr_count].index = index; + smp_mtrr[smp_mtrr_count].val = val; + smp_mtrr_count++; } u32 MaxCountCPUs; @@ -58,10 +58,10 @@ handle_smp(void) u8 apic_id = ebx>>24; dprintf(DEBUG_HDL_smp, "handle_smp: apic_id=%d\n", apic_id); - // MTRR and MSR_IA32_FEATURE_CONTROL setup + // MTRR setup int i; - for (i=0; i<smp_msr_count; i++) - wrmsr(smp_msr[i].index, smp_msr[i].val); + for (i=0; i<smp_mtrr_count; i++) + wrmsr(smp_mtrr[i].index, smp_mtrr[i].val); // Set bit on FoundAPICIDs FoundAPICIDs[apic_id/32] |= (1 << (apic_id % 32)); |