summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2021-03-08 15:55:33 +0100
committerSimon Rettberg2021-03-08 15:55:33 +0100
commit6707d9218c8e6e760e53068d5f41ceb31fac6ea0 (patch)
tree88e8fc84ede2a0ed2c1cec3a6109beb9fb53abf5
parentMerge branch 'master' into openslx (diff)
parent[linux] Do not assume that stat() works on sysfs files (diff)
downloadipxe-6707d9218c8e6e760e53068d5f41ceb31fac6ea0.tar.gz
ipxe-6707d9218c8e6e760e53068d5f41ceb31fac6ea0.tar.xz
ipxe-6707d9218c8e6e760e53068d5f41ceb31fac6ea0.zip
Merge branch 'master' into openslx
-rw-r--r--.github/workflows/build.yml71
-rw-r--r--.github/workflows/coverity.yml37
-rw-r--r--.travis.yml57
-rwxr-xr-xcontrib/cloud/aws-import100
-rw-r--r--contrib/vm/bochsrc.txt910
-rw-r--r--src/Makefile2
-rw-r--r--src/Makefile.efi8
-rw-r--r--src/Makefile.housekeeping208
-rw-r--r--src/Makefile.linux51
-rw-r--r--src/arch/arm64/Makefile.efi4
-rw-r--r--src/arch/i386/Makefile16
-rw-r--r--src/arch/i386/Makefile.linux10
-rw-r--r--src/arch/i386/core/linux/linux_syscall.S45
-rw-r--r--src/arch/i386/core/linux/linuxprefix.S28
-rw-r--r--src/arch/i386/include/bits/compiler.h2
-rw-r--r--src/arch/i386/include/bits/linux_api.h6
-rw-r--r--src/arch/x86/Makefile.linux17
-rw-r--r--src/arch/x86/Makefile.pcbios54
-rw-r--r--src/arch/x86/core/linux/linux_api.c149
-rw-r--r--src/arch/x86/core/linux/linux_strerror.c169
-rw-r--r--src/arch/x86/core/pcidirect.c1
-rw-r--r--src/arch/x86/core/runtime.c47
-rw-r--r--src/arch/x86/core/stack.S2
-rw-r--r--src/arch/x86/core/stack16.S2
-rw-r--r--src/arch/x86/drivers/hyperv/hyperv.c12
-rw-r--r--src/arch/x86/drivers/xen/hvm.c10
-rw-r--r--src/arch/x86/drivers/xen/hvm.h2
-rw-r--r--src/arch/x86/image/initrd.c12
-rw-r--r--src/arch/x86/include/bits/bitops.h8
-rw-r--r--src/arch/x86/include/bits/linux_api_platform.h6
-rw-r--r--src/arch/x86/include/ipxe/cpuid.h3
-rw-r--r--src/arch/x86/include/ipxe/pcibios.h13
-rw-r--r--src/arch/x86/include/ipxe/pcidirect.h13
-rw-r--r--src/arch/x86/include/ipxe/rsdp.h13
-rw-r--r--src/arch/x86/interface/pcbios/bios_cachedhcp.c76
-rw-r--r--src/arch/x86/interface/pcbios/bios_console.c2
-rw-r--r--src/arch/x86/interface/pcbios/e820mangler.S2
-rw-r--r--src/arch/x86/interface/pcbios/int13.c2
-rw-r--r--src/arch/x86/interface/pcbios/pcibios.c1
-rw-r--r--src/arch/x86/interface/pcbios/rsdp.c1
-rw-r--r--src/arch/x86/interface/pxe/pxe_entry.S4
-rw-r--r--src/arch/x86/interface/syslinux/comboot_call.c6
-rw-r--r--src/arch/x86/prefix/exeprefix.S2
-rw-r--r--src/arch/x86/prefix/mromprefix.S2
-rw-r--r--src/arch/x86/prefix/rawprefix.S53
-rw-r--r--src/arch/x86/prefix/romprefix.S8
-rw-r--r--src/arch/x86/prefix/unlzma.S2
-rw-r--r--src/arch/x86/scripts/pcbios.lds63
-rw-r--r--src/arch/x86/scripts/prefixonly.lds29
-rw-r--r--src/arch/x86/transitions/liba20.S2
-rw-r--r--src/arch/x86/transitions/librm.S29
-rw-r--r--src/arch/x86/transitions/librm_mgmt.c18
-rw-r--r--src/arch/x86/transitions/librm_test.c3
-rw-r--r--src/arch/x86_64/Makefile.linux8
-rw-r--r--src/arch/x86_64/core/linux/linux_syscall.S33
-rw-r--r--src/arch/x86_64/core/linux/linuxprefix.S25
-rw-r--r--src/arch/x86_64/include/bits/compiler.h2
-rw-r--r--src/arch/x86_64/include/bits/linux_api.h6
-rw-r--r--src/config/cloud/console.h5
-rw-r--r--src/config/cloud/general.h4
-rw-r--r--src/config/cloud/ioapi.h7
-rw-r--r--src/config/config.c3
-rw-r--r--src/config/config_ethernet.c3
-rw-r--r--src/config/config_usb.c3
-rw-r--r--src/config/defaults/efi.h4
-rw-r--r--src/config/defaults/linux.h2
-rw-r--r--src/config/defaults/pcbios.h2
-rw-r--r--src/config/dhcp.h2
-rw-r--r--src/config/general.h4
-rw-r--r--src/config/ioapi.h3
-rw-r--r--src/config/qemu/ioapi.h0
-rw-r--r--src/config/rpi/ioapi.h0
-rw-r--r--src/config/usb.h1
-rw-r--r--src/config/vbox/ioapi.h0
-rw-r--r--src/core/acpi.c35
-rw-r--r--src/core/blocktrans.c4
-rw-r--r--src/core/cachedhcp.c (renamed from src/arch/x86/core/cachedhcp.c)53
-rw-r--r--src/core/dma.c179
-rw-r--r--src/core/image.c68
-rw-r--r--src/core/interface.c22
-rw-r--r--src/core/iobuf.c57
-rw-r--r--src/core/malloc.c4
-rw-r--r--src/core/null_acpi.c2
-rw-r--r--src/crypto/certstore.c4
-rw-r--r--src/crypto/cms.c2
-rw-r--r--src/crypto/mishmash/oid_md4.c2
-rw-r--r--src/crypto/mishmash/oid_md5.c2
-rw-r--r--src/crypto/mishmash/oid_rsa.c2
-rw-r--r--src/crypto/mishmash/oid_sha1.c2
-rw-r--r--src/crypto/mishmash/oid_sha224.c2
-rw-r--r--src/crypto/mishmash/oid_sha256.c2
-rw-r--r--src/crypto/mishmash/oid_sha384.c2
-rw-r--r--src/crypto/mishmash/oid_sha512.c2
-rw-r--r--src/crypto/mishmash/oid_sha512_224.c2
-rw-r--r--src/crypto/mishmash/oid_sha512_256.c2
-rw-r--r--src/crypto/mishmash/rsa_md5.c2
-rw-r--r--src/crypto/mishmash/rsa_sha1.c2
-rw-r--r--src/crypto/mishmash/rsa_sha224.c2
-rw-r--r--src/crypto/mishmash/rsa_sha256.c2
-rw-r--r--src/crypto/mishmash/rsa_sha384.c2
-rw-r--r--src/crypto/mishmash/rsa_sha512.c2
-rw-r--r--src/crypto/ocsp.c20
-rw-r--r--src/crypto/privkey.c35
-rw-r--r--src/crypto/rootcert.c1
-rw-r--r--src/crypto/x509.c95
-rw-r--r--src/drivers/block/ibft.c8
-rw-r--r--src/drivers/bus/isa.c3
-rw-r--r--src/drivers/bus/pcimsix.c2
-rw-r--r--src/drivers/bus/usb.c96
-rw-r--r--src/drivers/bus/virtio-pci.c2
-rw-r--r--src/drivers/infiniband/MT25218_PRM.h176
-rw-r--r--src/drivers/infiniband/MT25408_PRM.h264
-rw-r--r--src/drivers/infiniband/arbel.c78
-rw-r--r--src/drivers/infiniband/flexboot_nodnic.c3
-rwxr-xr-xsrc/drivers/infiniband/golan.c68
-rw-r--r--src/drivers/infiniband/hermon.c406
-rw-r--r--src/drivers/infiniband/hermon.h37
-rw-r--r--src/drivers/infiniband/linda.c19
-rw-r--r--src/drivers/infiniband/mlx_utils_flexboot/src/mlx_memory_priv.c4
-rw-r--r--src/drivers/infiniband/mlx_utils_flexboot/src/mlx_pci_priv.c2
-rw-r--r--src/drivers/infiniband/nodnic_prm.h4
-rw-r--r--src/drivers/infiniband/qib7322.c19
-rw-r--r--src/drivers/linux/af_packet.c2
-rw-r--r--src/drivers/linux/linux.c50
-rw-r--r--src/drivers/linux/slirp.c552
-rw-r--r--src/drivers/linux/tap.c2
-rw-r--r--src/drivers/net/3c90x.c8
-rw-r--r--src/drivers/net/amd8111e.c2
-rw-r--r--src/drivers/net/ath/ath5k/ath5k.c8
-rw-r--r--src/drivers/net/ath/ath5k/ath5k_eeprom.c1
-rw-r--r--src/drivers/net/ath/ath9k/ath9k.c2
-rw-r--r--src/drivers/net/ath/ath9k/ath9k_init.c6
-rw-r--r--src/drivers/net/atl1e.c4
-rw-r--r--src/drivers/net/b44.c14
-rw-r--r--src/drivers/net/bnx2.c2
-rw-r--r--src/drivers/net/bnxt/bnxt.c32
-rw-r--r--src/drivers/net/eepro100.c18
-rw-r--r--src/drivers/net/efi/nii.c42
-rw-r--r--src/drivers/net/ena.c66
-rw-r--r--src/drivers/net/ena.h2
-rw-r--r--src/drivers/net/etherfabric.c6
-rw-r--r--src/drivers/net/exanic.c10
-rw-r--r--src/drivers/net/forcedeth.c6
-rw-r--r--src/drivers/net/icplus.c8
-rw-r--r--src/drivers/net/igbvf/igbvf_main.c12
-rw-r--r--src/drivers/net/intel.c47
-rw-r--r--src/drivers/net/intel.h5
-rw-r--r--src/drivers/net/intelx.c8
-rw-r--r--src/drivers/net/intelxl.c122
-rw-r--r--src/drivers/net/intelxl.h34
-rw-r--r--src/drivers/net/intelxlvf.c23
-rw-r--r--src/drivers/net/intelxvf.c7
-rw-r--r--src/drivers/net/iphone.c2268
-rw-r--r--src/drivers/net/iphone.h291
-rw-r--r--src/drivers/net/jme.c10
-rw-r--r--src/drivers/net/myri10ge.c8
-rw-r--r--src/drivers/net/myson.c8
-rw-r--r--src/drivers/net/natsemi.c8
-rw-r--r--src/drivers/net/ncm.c13
-rw-r--r--src/drivers/net/netfront.c6
-rw-r--r--src/drivers/net/pcnet32.c8
-rw-r--r--src/drivers/net/phantom/phantom.c18
-rw-r--r--src/drivers/net/prism2_pci.c2
-rw-r--r--src/drivers/net/realtek.c135
-rw-r--r--src/drivers/net/realtek.h18
-rw-r--r--src/drivers/net/rhine.c6
-rw-r--r--src/drivers/net/rtl818x/rtl818x.c12
-rw-r--r--src/drivers/net/sfc/efx_common.c7
-rw-r--r--src/drivers/net/sfc/efx_hunt.c9
-rw-r--r--src/drivers/net/sfc/efx_hunt.h5
-rw-r--r--src/drivers/net/sfc/mcdi.h6
-rw-r--r--src/drivers/net/sfc/sfc_hunt.c5
-rw-r--r--src/drivers/net/sis190.c10
-rw-r--r--src/drivers/net/skeleton.c2
-rwxr-xr-xsrc/drivers/net/skge.c9
-rw-r--r--src/drivers/net/sky2.c16
-rw-r--r--src/drivers/net/tg3/tg3.c22
-rw-r--r--src/drivers/net/thunderx.c16
-rw-r--r--src/drivers/net/velocity.c14
-rw-r--r--src/drivers/net/vmxnet3.c15
-rw-r--r--src/drivers/net/vxge/vxge_config.c12
-rw-r--r--src/drivers/net/vxge/vxge_main.c2
-rw-r--r--src/drivers/usb/ehci.c31
-rw-r--r--src/drivers/usb/uhci.c26
-rw-r--r--src/drivers/usb/usbblk.c912
-rw-r--r--src/drivers/usb/usbblk.h121
-rw-r--r--src/drivers/usb/usbio.c5
-rw-r--r--src/drivers/usb/xhci.c265
-rw-r--r--src/drivers/usb/xhci.h43
-rw-r--r--src/hci/commands/ifmgmt_cmd.c56
-rw-r--r--src/hci/commands/image_mem_cmd.c96
-rw-r--r--src/hci/linux_args.c20
-rw-r--r--src/image/efi_image.c15
-rw-r--r--src/image/embedded.c3
-rw-r--r--src/include/errno.h4
-rw-r--r--src/include/ipxe/acpi.h148
-rw-r--r--src/include/ipxe/aoe.h31
-rw-r--r--src/include/ipxe/asn1.h53
-rw-r--r--src/include/ipxe/cachedhcp.h17
-rw-r--r--src/include/ipxe/certstore.h3
-rw-r--r--src/include/ipxe/dma.h480
-rw-r--r--src/include/ipxe/eap.h69
-rw-r--r--src/include/ipxe/eapol.h127
-rw-r--r--src/include/ipxe/efi/efi.h48
-rw-r--r--src/include/ipxe/efi/efi_acpi.h13
-rw-r--r--src/include/ipxe/efi/efi_autoboot.h4
-rw-r--r--src/include/ipxe/efi/efi_autoexec.h16
-rw-r--r--src/include/ipxe/efi/efi_blacklist.h13
-rw-r--r--src/include/ipxe/efi/efi_cachedhcp.h16
-rw-r--r--src/include/ipxe/efi/efi_null.h33
-rw-r--r--src/include/ipxe/efi/efi_path.h43
-rw-r--r--src/include/ipxe/efi/efi_pci.h12
-rw-r--r--src/include/ipxe/efi/efi_snp.h2
-rw-r--r--src/include/ipxe/efi/efi_usb.h10
-rw-r--r--src/include/ipxe/efi/efi_utils.h4
-rw-r--r--src/include/ipxe/efi/efi_veto.h13
-rw-r--r--src/include/ipxe/efi/efi_wrap.h1
-rw-r--r--src/include/ipxe/errfile.h13
-rw-r--r--src/include/ipxe/fcp.h8
-rw-r--r--src/include/ipxe/http.h8
-rw-r--r--src/include/ipxe/ib_srp.h35
-rw-r--r--src/include/ipxe/image.h3
-rw-r--r--src/include/ipxe/infiniband.h3
-rw-r--r--src/include/ipxe/interface.h17
-rw-r--r--src/include/ipxe/iobuf.h69
-rw-r--r--src/include/ipxe/linux/linux_acpi.h18
-rw-r--r--src/include/ipxe/linux/linux_pci.h24
-rw-r--r--src/include/ipxe/linux_api.h106
-rw-r--r--src/include/ipxe/linux_sysfs.h16
-rw-r--r--src/include/ipxe/malloc.h32
-rw-r--r--src/include/ipxe/netdevice.h6
-rw-r--r--src/include/ipxe/null_acpi.h6
-rw-r--r--src/include/ipxe/pci.h3
-rw-r--r--src/include/ipxe/pci_io.h11
-rw-r--r--src/include/ipxe/privkey.h55
-rw-r--r--src/include/ipxe/slirp.h155
-rw-r--r--src/include/ipxe/smbios.h52
-rw-r--r--src/include/ipxe/tables.h71
-rw-r--r--src/include/ipxe/tls.h16
-rw-r--r--src/include/ipxe/usb.h23
-rw-r--r--src/include/ipxe/validator.h3
-rw-r--r--src/include/ipxe/x509.h48
-rw-r--r--src/include/linux_api.h81
-rw-r--r--src/include/usr/ifmgmt.h3
-rw-r--r--src/include/usr/imgmgmt.h1
-rw-r--r--src/interface/efi/efi_acpi.c1
-rw-r--r--src/interface/efi/efi_autoboot.c26
-rw-r--r--src/interface/efi/efi_autoexec.c206
-rw-r--r--src/interface/efi/efi_blacklist.c237
-rw-r--r--src/interface/efi/efi_block.c147
-rw-r--r--src/interface/efi/efi_bofm.c15
-rw-r--r--src/interface/efi/efi_cachedhcp.c94
-rw-r--r--src/interface/efi/efi_console.c77
-rw-r--r--src/interface/efi/efi_debug.c47
-rw-r--r--src/interface/efi/efi_driver.c23
-rw-r--r--src/interface/efi/efi_entropy.c4
-rw-r--r--src/interface/efi/efi_init.c38
-rw-r--r--src/interface/efi/efi_local.c11
-rw-r--r--src/interface/efi/efi_null.c672
-rw-r--r--src/interface/efi/efi_path.c506
-rw-r--r--src/interface/efi/efi_pci.c525
-rw-r--r--src/interface/efi/efi_pxe.c40
-rw-r--r--src/interface/efi/efi_smbios.c44
-rw-r--r--src/interface/efi/efi_snp.c178
-rw-r--r--src/interface/efi/efi_snp_hii.c83
-rw-r--r--src/interface/efi/efi_timer.c15
-rw-r--r--src/interface/efi/efi_usb.c319
-rw-r--r--src/interface/efi/efi_utils.c38
-rw-r--r--src/interface/efi/efi_veto.c609
-rw-r--r--src/interface/efi/efi_wrap.c675
-rw-r--r--src/interface/efi/efidrvprefix.c8
-rw-r--r--src/interface/efi/efiprefix.c34
-rw-r--r--src/interface/hyperv/vmbus.c6
-rw-r--r--src/interface/linux/linux_acpi.c148
-rw-r--r--src/interface/linux/linux_api.c551
-rw-r--r--src/interface/linux/linux_console.c2
-rw-r--r--src/interface/linux/linux_entropy.c2
-rw-r--r--src/interface/linux/linux_nap.c2
-rw-r--r--src/interface/linux/linux_pci.c2
-rw-r--r--src/interface/linux/linux_smbios.c142
-rw-r--r--src/interface/linux/linux_sysfs.c96
-rw-r--r--src/interface/linux/linux_time.c2
-rw-r--r--src/interface/linux/linux_timer.c2
-rw-r--r--src/interface/linux/linux_umalloc.c2
-rw-r--r--src/interface/linux/linuxprefix.c (renamed from src/include/hci/linux_args.h)27
-rw-r--r--src/interface/smbios/smbios.c19
-rw-r--r--src/net/80211/wpa.c25
-rw-r--r--src/net/aoe.c31
-rw-r--r--src/net/eap.c142
-rw-r--r--src/net/eapol.c139
-rw-r--r--src/net/eth_slow.c11
-rw-r--r--src/net/fcp.c28
-rw-r--r--src/net/infiniband.c20
-rw-r--r--src/net/infiniband/ib_sma.c2
-rw-r--r--src/net/infiniband/ib_srp.c35
-rw-r--r--src/net/ndp.c29
-rw-r--r--src/net/netdevice.c34
-rw-r--r--src/net/tcp/httpconn.c13
-rw-r--r--src/net/tcp/httpcore.c15
-rw-r--r--src/net/tcp/https.c14
-rw-r--r--src/net/tcp/iscsi.c2
-rw-r--r--src/net/tcp/syslogs.c29
-rw-r--r--src/net/tls.c143
-rw-r--r--src/net/udp/dhcp.c23
-rw-r--r--src/net/udp/dns.c18
-rw-r--r--src/net/udp/tftp.c24
-rw-r--r--src/net/validator.c12
-rw-r--r--src/tests/cms_test.c2
-rw-r--r--src/tests/ocsp_test.c3
-rw-r--r--src/tests/x509_test.c7
-rw-r--r--src/usr/autoboot.c13
-rw-r--r--src/usr/certmgmt.c2
-rw-r--r--src/usr/ifmgmt.c14
-rw-r--r--src/usr/imgmgmt.c21
-rw-r--r--src/usr/imgtrust.c3
-rw-r--r--src/usr/lotest.c4
-rw-r--r--src/util/.gitignore1
-rw-r--r--src/util/eficompress.c1588
-rw-r--r--src/util/efirom.c66
-rw-r--r--src/util/elf2efi.c37
-rwxr-xr-xsrc/util/genefidsk60
-rwxr-xr-xsrc/util/genfsimg306
-rwxr-xr-xsrc/util/geniso141
-rwxr-xr-xsrc/util/gensdsk65
-rw-r--r--src/util/iccfix.c157
325 files changed, 16789 insertions, 4180 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
new file mode 100644
index 000000000..6dc577ef1
--- /dev/null
+++ b/.github/workflows/build.yml
@@ -0,0 +1,71 @@
+name: Build
+
+on: push
+
+jobs:
+
+ x86:
+ name: x86
+ runs-on: ubuntu-20.04
+ steps:
+ - name: Check out code
+ uses: actions/checkout@v2
+ with:
+ fetch-depth: 0
+ - name: Install packages
+ run: |
+ sudo dpkg --add-architecture i386
+ sudo apt update
+ sudo apt install -y -o Acquire::Retries=50 \
+ mtools syslinux isolinux \
+ libc6-dev-i386 libc6-dbg:i386 valgrind
+ - name: Build (BIOS)
+ run: |
+ make -j 4 -C src
+ - name: Build (Everything)
+ run: |
+ make -j 4 -C src everything
+ - name: Test
+ run: |
+ valgrind ./src/bin-i386-linux/tests.linux
+ valgrind ./src/bin-x86_64-linux/tests.linux
+
+ arm32:
+ name: ARM32
+ runs-on: ubuntu-20.04
+ steps:
+ - name: Check out code
+ uses: actions/checkout@v2
+ with:
+ fetch-depth: 0
+ - name: Install packages
+ run: |
+ sudo apt update
+ sudo apt install -y -o Acquire::Retries=50 \
+ mtools syslinux isolinux gcc-arm-none-eabi
+ - name: Build
+ run: |
+ make -j 4 -C src CROSS=arm-none-eabi- \
+ bin-arm32-efi/intel.efi \
+ bin-arm32-efi/intel.usb \
+ bin-arm32-efi/intel.iso
+
+ arm64:
+ name: ARM64
+ runs-on: ubuntu-20.04
+ steps:
+ - name: Check out code
+ uses: actions/checkout@v2
+ with:
+ fetch-depth: 0
+ - name: Install packages
+ run: |
+ sudo apt update
+ sudo apt install -y -o Acquire::Retries=50 \
+ mtools syslinux isolinux gcc-aarch64-linux-gnu
+ - name: Build
+ run: |
+ make -j 4 -C src CROSS=aarch64-linux-gnu- \
+ bin-arm64-efi/ipxe.efi \
+ bin-arm64-efi/ipxe.usb \
+ bin-arm64-efi/ipxe.iso
diff --git a/.github/workflows/coverity.yml b/.github/workflows/coverity.yml
new file mode 100644
index 000000000..20634be42
--- /dev/null
+++ b/.github/workflows/coverity.yml
@@ -0,0 +1,37 @@
+name: Coverity Scan
+
+on:
+ push:
+ branches:
+ - coverity_scan
+
+jobs:
+ submit:
+ name: Submit
+ runs-on: ubuntu-20.04
+ steps:
+ - name: Check out code
+ uses: actions/checkout@v2
+ - name: Download Coverity Scan
+ run: |
+ curl --form token=${{ secrets.COVERITY_SCAN_TOKEN }} \
+ --form project=${{ github.repository }} \
+ --output coverity.tar.gz \
+ https://scan.coverity.com/download/cxx/linux64
+ mkdir -p /opt/coverity
+ sudo tar xvzf coverity.tar.gz --strip 1 --directory /opt/coverity
+ - name: Build via Coverity Scan
+ run: |
+ make -C src bin/deps
+ /opt/coverity/bin/cov-build --dir cov-int make -C src bin/blib.a
+ - name: Create submission
+ run : |
+ tar cvzf cov-int.tar.gz cov-int
+ - name: Submit to Coverity Scan
+ run: |
+ curl --form token=${{ secrets.COVERITY_SCAN_TOKEN }} \
+ --form email=${{ secrets.COVERITY_SCAN_EMAIL }} \
+ --form file=@cov-int.tar.gz \
+ --form version=${{ github.sha }} \
+ --form description=${{ github.ref }} \
+ https://scan.coverity.com/builds?project=${{ github.repository }}
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 43849cc5b..000000000
--- a/.travis.yml
+++ /dev/null
@@ -1,57 +0,0 @@
-dist: trusty
-
-sudo: false
-
-git:
- depth: false
-
-language: c
-
-cache: ccache
-
-compiler:
- - gcc
-
-addons:
- apt:
- packages:
- - binutils-dev
- - liblzma-dev
- - syslinux
- - genisoimage
- coverity_scan:
- project:
- name: "ipxe/ipxe"
- version: $TRAVIS_COMMIT
- build_command_prepend: "make -C src bin/deps"
- build_command: "make -C src bin/blib.a"
- branch_pattern: coverity_scan
-
-env:
- global:
- - MAKEFLAGS="-j 4"
-
-script:
- - make -C src bin/blib.a
- - make -C src bin/ipxe.pxe
- - make -C src bin/ipxe.usb
- - make -C src bin/ipxe.iso
- - make -C src bin/8086100e.mrom
- - make -C src bin-x86_64-pcbios/blib.a
- - make -C src bin-x86_64-pcbios/ipxe.pxe
- - make -C src bin-x86_64-pcbios/ipxe.usb
- - make -C src bin-x86_64-pcbios/ipxe.iso
- - make -C src bin-x86_64-pcbios/8086100e.mrom
- - make -C src bin-x86_64-efi/blib.a
- - make -C src bin-x86_64-efi/ipxe.efi
- - make -C src bin-x86_64-efi/intel.efidrv
- - make -C src bin-x86_64-efi/intel.efirom
- - make -C src bin-i386-efi/blib.a
- - make -C src bin-i386-efi/ipxe.efi
- - make -C src bin-i386-efi/intel.efidrv
- - make -C src bin-i386-efi/intel.efirom
- - make -C src bin-x86_64-linux/blib.a
- - make -C src bin-x86_64-linux/tap.linux
- - make -C src bin-x86_64-linux/af_packet.linux
- - make -C src bin-x86_64-linux/tests.linux
- - ./src/bin-x86_64-linux/tests.linux
diff --git a/contrib/cloud/aws-import b/contrib/cloud/aws-import
new file mode 100755
index 000000000..9ee53e704
--- /dev/null
+++ b/contrib/cloud/aws-import
@@ -0,0 +1,100 @@
+#!/usr/bin/env python3
+
+import argparse
+from base64 import b64encode
+from concurrent.futures import ThreadPoolExecutor, as_completed
+from hashlib import sha256
+from itertools import count
+
+import boto3
+
+BLOCKSIZE = 512 * 1024
+
+
+def create_snapshot(region, description, image):
+ """Create an EBS snapshot"""
+ client = boto3.client('ebs', region_name=region)
+ snapshot = client.start_snapshot(VolumeSize=1,
+ Description=description)
+ snapshot_id = snapshot['SnapshotId']
+ with open(image, 'rb') as fh:
+ for block in count():
+ data = fh.read(BLOCKSIZE)
+ if not data:
+ break
+ data = data.ljust(BLOCKSIZE, b'\0')
+ checksum = b64encode(sha256(data).digest()).decode()
+ client.put_snapshot_block(SnapshotId=snapshot_id,
+ BlockIndex=block,
+ BlockData=data,
+ DataLength=BLOCKSIZE,
+ Checksum=checksum,
+ ChecksumAlgorithm='SHA256')
+ client.complete_snapshot(SnapshotId=snapshot_id,
+ ChangedBlocksCount=block)
+ return snapshot_id
+
+
+def import_image(region, name, architecture, image, public):
+ """Import an AMI image"""
+ client = boto3.client('ec2', region_name=region)
+ resource = boto3.resource('ec2', region_name=region)
+ description = '%s (%s)' % (name, architecture)
+ snapshot_id = create_snapshot(region=region, description=description,
+ image=image)
+ client.get_waiter('snapshot_completed').wait(SnapshotIds=[snapshot_id])
+ image = client.register_image(Architecture=architecture,
+ BlockDeviceMappings=[{
+ 'DeviceName': '/dev/sda1',
+ 'Ebs': {
+ 'SnapshotId': snapshot_id,
+ 'VolumeType': 'standard',
+ },
+ }],
+ EnaSupport=True,
+ Name=description,
+ RootDeviceName='/dev/sda1',
+ SriovNetSupport='simple',
+ VirtualizationType='hvm')
+ image_id = image['ImageId']
+ client.get_waiter('image_available').wait(ImageIds=[image_id])
+ if public:
+ resource.Image(image_id).modify_attribute(Attribute='launchPermission',
+ OperationType='add',
+ UserGroups=['all'])
+ return image_id
+
+
+# Parse command-line arguments
+parser = argparse.ArgumentParser(description="Import AWS EC2 image (AMI)")
+parser.add_argument('--architecture', '-a', default='x86_64',
+ help="CPU architecture")
+parser.add_argument('--name', '-n', required=True,
+ help="Image name")
+parser.add_argument('--public', '-p', action='store_true',
+ help="Make image public")
+parser.add_argument('--region', '-r', action='append',
+ help="AWS region(s)")
+parser.add_argument('image', help="iPXE disk image")
+args = parser.parse_args()
+
+# Use all regions if none specified
+if not args.region:
+ args.region = sorted(x['RegionName'] for x in
+ boto3.client('ec2').describe_regions()['Regions'])
+
+# Use one thread per region to maximise parallelism
+with ThreadPoolExecutor(max_workers=len(args.region)) as executor:
+ futures = {executor.submit(import_image,
+ region=region,
+ name=args.name,
+ architecture=args.architecture,
+ image=args.image,
+ public=args.public): region
+ for region in args.region}
+ results = {futures[future]: future.result()
+ for future in as_completed(futures)}
+
+# Show created images
+for region in args.region:
+ print("%s: %s" % (region, results[region]))
diff --git a/contrib/vm/bochsrc.txt b/contrib/vm/bochsrc.txt
index d0f12504b..feda98595 100644
--- a/contrib/vm/bochsrc.txt
+++ b/contrib/vm/bochsrc.txt
@@ -7,10 +7,15 @@
# directly with this option and some of them install a config option that is
# only available when the plugin device is loaded. The value "1" means to load
# the plugin and "0" will unload it (if loaded before).
-# These plugins are currently supported: 'biosdev', 'e1000', 'es1370',
-# 'extfpuirq', 'gameport', 'iodebug', 'ne2k', 'parallel', 'pcidev', 'pcipnic',
-# 'sb16', 'serial', 'speaker', 'unmapped', 'usb_ohci', 'usb_uhci' and 'usb_xhci'.
+#
+# These plugins will be loaded by default (if present): 'biosdev', 'extfpuirq',
+# 'gameport', 'iodebug','parallel', 'serial', 'speaker' and 'unmapped'.
+#
+# These plugins are also supported, but they are usually loaded directly with
+# their bochsrc option: 'e1000', 'es1370', 'ne2k', 'pcidev', 'pcipnic', 'sb16',
+# 'usb_ehci', 'usb_ohci', 'usb_uhci', 'usb_xhci' and 'voodoo'.
#=======================================================================
+#plugin_ctrl: unmapped=0, e1000=1 # unload 'unmapped' and load 'e1000'
plugin_ctrl: unmapped=1, biosdev=1, speaker=1, e1000=1, parallel=1, serial=1
#=======================================================================
@@ -50,10 +55,11 @@ plugin_ctrl: unmapped=1, biosdev=1, speaker=1, e1000=1, parallel=1, serial=1
# carbon use Carbon library (for MacOS X)
# macintosh use MacOS pre-10
# amigaos use native AmigaOS libraries
-# sdl use SDL library, cross platform
-# svga use SVGALIB library for Linux, allows graphics without X11
+# sdl use SDL 1.2.x library, cross platform
+# sdl2 use SDL 2.x library, cross platform
# term text only, uses curses/ncurses library, cross platform
# rfb provides an interface to AT&T's VNC viewer, cross platform
+# vncsrv use LibVNCServer for extended RFB(VNC) support
# wx use wxWidgets library, cross platform
# nogui no display at all
#
@@ -64,52 +70,50 @@ plugin_ctrl: unmapped=1, biosdev=1, speaker=1, e1000=1, parallel=1, serial=1
# Some display libraries now support specific options to control their
# behaviour. These options are supported by more than one display library:
#
-# "gui_debug" - use GTK debugger gui (sdl, x) / Win32 debugger gui (win32)
-# "hideIPS" - disable IPS output in status bar (sdl, wx, x)
-# "nokeyrepeat" - turn off host keyboard repeat (sdl, win32, x)
+# "cmdmode" - call a headerbar button handler after pressing F7 (sdl, sdl2,
+# win32, x)
+# "fullscreen" - startup in fullscreen mode (sdl, sdl2)
+# "gui_debug" - use GTK debugger gui (sdl, sdl2, x) / Win32 debugger gui (sdl,
+# sdl2, win32)
+# "hideIPS" - disable IPS output in status bar (rfb, sdl, sdl2, term, vncsrv,
+# win32, wx, x)
+# "nokeyrepeat" - turn off host keyboard repeat (sdl, sdl2, win32, x)
+# "timeout" - time (in seconds) to wait for client (rfb, vncsrv)
#
# See the examples below for other currently supported options.
+# Setting up options without specifying display library is also supported.
#=======================================================================
#display_library: amigaos
#display_library: carbon
#display_library: macintosh
#display_library: nogui
-#display_library: rfb, options="timeout=60" # time to wait for client
-#display_library: sdl, options="fullscreen" # startup in fullscreen mode
+#display_library: rfb
+#display_library: sdl
+#display_library: sdl2
#display_library: term
-#display_library: win32
+#display_library: vncsrv
+# "traphotkeys" - system hotkeys not handled by host OS, but sent to guest
+# (win32 in mouse capture and fullscreen mode: alt-tab, win,
+# alt-space, alt-esc, ctrl-esc)
+# "autoscale" - scale small simulation window by factor 2, 4 or 8 depending
+# on desktop window size
+#display_library: win32, options="traphotkeys, autoscale"
#display_library: wx
#display_library: x
#=======================================================================
-# ROMIMAGE:
-# The ROM BIOS controls what the PC does when it first powers on.
-# Normally, you can use a precompiled BIOS in the source or binary
-# distribution called BIOS-bochs-latest. The ROM BIOS is usually loaded
-# starting at address 0xf0000, and it is exactly 64k long. Another option
-# is 128k BIOS which is loaded at address 0xe0000.
-# You can also use the environment variable $BXSHARE to specify the
-# location of the BIOS.
-# The usage of external large BIOS images (up to 512k) at memory top is
-# now supported, but we still recommend to use the BIOS distributed with
-# Bochs. The start address optional, since it can be calculated from image size.
-#=======================================================================
-#romimage: file=$BXSHARE/BIOS-bochs-latest
-#romimage: file=bios/seabios-1.6.3.bin
-#romimage: file=mybios.bin, address=0xfff80000 # 512k at memory top
-romimage: file=bochs/bios/BIOS-bochs-latest
-
-#=======================================================================
# CPU:
# This defines cpu-related parameters inside Bochs:
#
# MODEL:
# Selects CPU configuration to emulate from pre-defined list of all
-# supported configurations. When this option is used, the CPUID option
-# has no effect anymore.
+# supported configurations. When this option is used and the value
+# is different from 'bx_generic', the parameters of the CPUID option
+# have no effect anymore.
#
# CPU configurations that can be selected:
# -----------------------------------------------------------------
+# pentium Intel Pentium (P54C)
# pentium_mmx Intel Pentium MMX
# amd_k6_2_chomper AMD-K6(tm) 3D processor (Chomper)
# p2_klamath Intel Pentium II (Klamath)
@@ -117,23 +121,28 @@ romimage: file=bochs/bios/BIOS-bochs-latest
# p4_willamette Intel(R) Pentium(R) 4 (Willamette)
# core_duo_t2400_yonah Intel(R) Core(TM) Duo CPU T2400 (Yonah)
# atom_n270 Intel(R) Atom(TM) CPU N270
+# p4_prescott_celeron_336 Intel(R) Celeron(R) 336 (Prescott)
# athlon64_clawhammer AMD Athlon(tm) 64 Processor 2800+ (Clawhammer)
# athlon64_venice AMD Athlon(tm) 64 Processor 3000+ (Venice)
# turion64_tyler AMD Turion(tm) 64 X2 Mobile TL-60 (Tyler)
# phenom_8650_toliman AMD Phenom X3 8650 (Toliman)
-# p4_prescott_celeron_336 Intel(R) Celeron(R) 336 (Prescott)
# core2_penryn_t9600 Intel Mobile Core 2 Duo T9600 (Penryn)
# corei5_lynnfield_750 Intel(R) Core(TM) i5 750 (Lynnfield)
# corei5_arrandale_m520 Intel(R) Core(TM) i5 M 520 (Arrandale)
# corei7_sandy_bridge_2600k Intel(R) Core(TM) i7-2600K (Sandy Bridge)
+# zambezi AMD FX(tm)-4100 Quad-Core Processor (Zambezi)
+# trinity_apu AMD A8-5600K APU (Trinity)
+# ryzen AMD Ryzen 7 1700
# corei7_ivy_bridge_3770k Intel(R) Core(TM) i7-3770K CPU (Ivy Bridge)
+# corei7_haswell_4770 Intel(R) Core(TM) i7-4770 CPU (Haswell)
+# broadwell_ult Intel(R) Processor 5Y70 CPU (Broadwell)
#
# COUNT:
-# Set the number of processors:cores per processor:threads per core
-# when Bochs is compiled for SMP emulation.
-# Bochs currently supports up to 8 threads running simultaniosly.
-# If Bochs is compiled without SMP support, it won't accept values
-# different from 1.
+# Set the number of processors:cores per processor:threads per core when
+# Bochs is compiled for SMP emulation. Bochs currently supports up to
+# 14 threads (legacy APIC) or 254 threads (xAPIC or higher) running
+# simultaniosly. If Bochs is compiled without SMP support, it won't accept
+# values different from 1.
#
# QUANTUM:
# Maximum amount of instructions allowed to execute by processor before
@@ -156,7 +165,7 @@ romimage: file=bochs/bios/BIOS-bochs-latest
# IGNORE_BAD_MSRS:
# Ignore MSR references that Bochs does not understand; print a warning
# message instead of generating #GP exception. This option is enabled
-# by default but will not be avaiable if configurable MSRs are enabled.
+# by default but will not be available if configurable MSRs are enabled.
#
# MWAIT_IS_NOP:
# When this option is enabled MWAIT will not put the CPU into a sleep state.
@@ -205,23 +214,38 @@ cpu: cpuid_limit_winnt=0
# Select SYSENTER/SYSEXIT instruction set support.
# This option exists only if Bochs compiled with BX_CPU_LEVEL >= 6.
#
-# SSE:
-# Select SSE instruction set support.
-# Any of NONE/SSE/SSE2/SSE3/SSSE3/SSE4_1/SSE4_2 could be selected.
+# SIMD:
+# Select SIMD instructions support.
+# Any of NONE/SSE/SSE2/SSE3/SSSE3/SSE4_1/SSE4_2/AVX/AVX2/AVX512
+# could be selected.
+#
# This option exists only if Bochs compiled with BX_CPU_LEVEL >= 6.
+# The AVX choises exists only if Bochs compiled with --enable-avx option.
#
# SSE4A:
# Select AMD SSE4A instructions support.
# This option exists only if Bochs compiled with BX_CPU_LEVEL >= 6.
#
+# MISALIGNED_SSE:
+# Select AMD Misaligned SSE mode support.
+# This option exists only if Bochs compiled with BX_CPU_LEVEL >= 6.
+#
# AES:
# Select AES instruction set support.
# This option exists only if Bochs compiled with BX_CPU_LEVEL >= 6.
#
+# SHA:
+# Select SHA instruction set support.
+# This option exists only if Bochs compiled with BX_CPU_LEVEL >= 6.
+#
# MOVBE:
# Select MOVBE Intel(R) Atom instruction support.
# This option exists only if Bochs compiled with BX_CPU_LEVEL >= 6.
#
+# ADX:
+# Select ADCX/ADOX instructions support.
+# This option exists only if Bochs compiled with BX_CPU_LEVEL >= 6.
+#
# XSAVE:
# Select XSAVE extensions support.
# This option exists only if Bochs compiled with BX_CPU_LEVEL >= 6.
@@ -230,10 +254,6 @@ cpu: cpuid_limit_winnt=0
# Select XSAVEOPT instruction support.
# This option exists only if Bochs compiled with BX_CPU_LEVEL >= 6.
#
-# AVX:
-# Select AVX/AVX2 instruction set support.
-# This option exists only if Bochs compiled with --enable-avx option.
-#
# AVX_F16C:
# Select AVX float16 convert instructions support.
# This option exists only if Bochs compiled with --enable-avx option.
@@ -278,6 +298,10 @@ cpu: cpuid_limit_winnt=0
# Enable Supervisor Mode Execution Protection (SMEP) support.
# This option exists only if Bochs compiled with BX_CPU_LEVEL >= 6.
#
+# SMAP:
+# Enable Supervisor Mode Access Prevention (SMAP) support.
+# This option exists only if Bochs compiled with BX_CPU_LEVEL >= 6.
+#
# MWAIT:
# Select MONITOR/MWAIT instructions support.
# This option exists only if Bochs compiled with --enable-monitor-mwait.
@@ -286,6 +310,10 @@ cpu: cpuid_limit_winnt=0
# Select VMX extensions emulation support.
# This option exists only if Bochs compiled with --enable-vmx option.
#
+# SVM:
+# Select AMD SVM (Secure Virtual Machine) extensions emulation support.
+# This option exists only if Bochs compiled with --enable-svm option.
+#
# VENDOR_STRING:
# Set the CPUID vendor string returned by CPUID(0x0). This should be a
# twelve-character ASCII string.
@@ -294,6 +322,12 @@ cpu: cpuid_limit_winnt=0
# Set the CPUID vendor string returned by CPUID(0x80000002 .. 0x80000004).
# This should be at most a forty-eight-character ASCII string.
#
+# LEVEL:
+# Set emulated CPU level information returned by CPUID. Default value is
+# determined by configure option --enable-cpu-level. Currently supported
+# values are 5 (for Pentium and similar processors) and 6 (for P6 and
+# later processors).
+#
# FAMILY:
# Set model information returned by CPUID. Default family value determined
# by configure option --enable-cpu-level.
@@ -304,7 +338,7 @@ cpu: cpuid_limit_winnt=0
# STEPPING:
# Set stepping information returned by CPUID. Default stepping value is 3.
#=======================================================================
-#cpuid: x86_64=1, mmx=1, sep=1, sse=sse4_2, apic=xapic, aes=1, movbe=1, xsave=1
+#cpuid: x86_64=1, mmx=1, sep=1, simd=sse4_2, apic=xapic, aes=1, movbe=1, xsave=1
#cpuid: family=6, model=0x1a, stepping=5
#=======================================================================
@@ -327,6 +361,37 @@ cpu: cpuid_limit_winnt=0
memory: guest=512, host=256
#=======================================================================
+# ROMIMAGE:
+# The ROM BIOS controls what the PC does when it first powers on.
+# Normally, you can use a precompiled BIOS in the source or binary
+# distribution called BIOS-bochs-latest. The default ROM BIOS is usually loaded
+# starting at address 0xfffe0000, and it is exactly 128k long. The legacy
+# version of the Bochs BIOS is usually loaded starting at address 0xffff0000,
+# and it is exactly 64k long.
+# You can use the environment variable $BXSHARE to specify the location
+# of the BIOS.
+# The usage of external large BIOS images (up to 512k) at memory top is
+# now supported, but we still recommend to use the BIOS distributed with Bochs.
+# The start address is optional, since it can be calculated from image size.
+# The Bochs BIOS currently supports only the option "fastboot" to skip the
+# boot menu delay.
+#=======================================================================
+#romimage: file=$BXSHARE/BIOS-bochs-latest, options=fastboot
+#romimage: file=$BXSHARE/bios.bin-1.13.0 # http://www.seabios.org/SeaBIOS
+#romimage: file=mybios.bin, address=0xfff80000 # 512k at memory top
+romimage: file=bochs/bios/BIOS-bochs-latest
+
+#=======================================================================
+# VGAROMIMAGE
+# You now need to load a VGA ROM BIOS into C0000.
+#=======================================================================
+#vgaromimage: file=$BXSHARE/VGABIOS-lgpl-latest
+#vgaromimage: file=bios/VGABIOS-lgpl-latest-cirrus
+#vgaromimage: file=$BXSHARE/vgabios-cirrus.bin-1.13.0 # http://www.seabios.org/SeaVGABIOS
+#vgaromimage: file=bios/VGABIOS-elpin-2.40
+vgaromimage: file=bochs/bios/VGABIOS-lgpl-latest
+
+#=======================================================================
# OPTROMIMAGE[1-4]:
# You may now load up to 4 optional ROM images. Be sure to use a
# read-only area, typically between C8000 and EFFFF. These optional
@@ -349,35 +414,233 @@ optromimage1: file=../../src/bin/intel.rom, address=0xcb000
#optramimage4: file=/path/file4.img, address=0x0040000
#=======================================================================
-# VGAROMIMAGE
-# You now need to load a VGA ROM BIOS into C0000.
-#=======================================================================
-#vgaromimage: file=bios/VGABIOS-elpin-2.40
-#vgaromimage: file=$BXSHARE/VGABIOS-lgpl-latest
-#vgaromimage: file=bios/VGABIOS-lgpl-latest-cirrus
-vgaromimage: file=bochs/bios/VGABIOS-lgpl-latest
-
-#=======================================================================
# VGA:
# This defines parameters related to the VGA display
#
# EXTENSION
# Here you can specify the display extension to be used. With the value
# 'none' you can use standard VGA with no extension. Other supported
-# values are 'vbe' for Bochs VBE and 'cirrus' for Cirrus SVGA support.
+# values are 'vbe' for Bochs VBE, 'cirrus' for Cirrus SVGA support and
+# 'voodoo' for Voodoo Graphics support (see 'voodoo' option).
#
# UPDATE_FREQ
-# The VGA update frequency is based on the emulated clock and the default
-# value is 5. Keep in mind that you must tweak the 'cpu: ips=N' directive
-# to be as close to the number of emulated instructions-per-second your
-# workstation can do, for this to be accurate. If the realtime sync is
-# enabled with the 'clock' option, the value is based on the real time.
-# This parameter can be changed at runtime.
+# This parameter specifies the number of display updates per second.
+# The VGA update timer by default uses the realtime engine with a value
+# of 5. This parameter can be changed at runtime.
+#
+# REALTIME
+# If set to 1 (default), the VGA timer is based on realtime, otherwise it
+# is driven by the cpu and depends on the ips setting. If the host is slow
+# (low ips, update_freq) and the guest uses HLT appropriately, setting this
+# to 0 and "clock: sync=none" may improve the responsiveness of the guest
+# GUI when the guest is otherwise idle.
+#
+# DDC
+# This parameter defines the behaviour of the DDC emulation that returns
+# the monitor EDID data. By default the 'builtin' values for 'Bochs Screen'
+# are used. Other choices are 'disabled' (no DDC emulation) and 'file'
+# (read monitor EDID from file / path name separated with a colon).
+# Examples:
+# vga: extension=cirrus, update_freq=10, ddc=builtin
+#=======================================================================
+#vga: extension=vbe, update_freq=5, realtime=1, ddc=file:monitor.bin
+
+#=======================================================================
+# VOODOO:
+# This defines the Voodoo Graphics emulation (experimental). Currently
+# supported models are 'voodoo1', 'voodoo2', 'banshee' and 'voodoo3'. The
+# Voodoo2 support is not yet complete, but almost usable. The Banshee and
+# Voodoo3 support is under construction, but basically usable. The 2D/3D cards
+# require an external VGA BIOS the vga extension option to be set to 'voodoo'.
+# If the i440BX PCI chipset is selected, they can be assigned to AGP (slot #5).
+# The gui screen update timing for all models is controlled by the related 'vga'
+# options.
#
# Examples:
-# vga: extension=cirrus, update_freq=10
+# voodoo: enabled=1, model=voodoo2
+#=======================================================================
+#voodoo: enabled=1, model=voodoo1
+
#=======================================================================
-#vga: extension=vbe, update_freq=5
+# KEYBOARD:
+# This defines parameters related to the emulated keyboard
+#
+# TYPE:
+# Type of keyboard return by a "identify keyboard" command to the
+# keyboard controller. It must be one of "xt", "at" or "mf".
+# Defaults to "mf". It should be ok for almost everybody. A known
+# exception is french macs, that do have a "at"-like keyboard.
+#
+# SERIAL_DELAY:
+# Approximate time in microseconds that it takes one character to
+# be transferred from the keyboard to controller over the serial path.
+#
+# PASTE_DELAY:
+# Approximate time in microseconds between attempts to paste
+# characters to the keyboard controller. This leaves time for the
+# guest os to deal with the flow of characters. The ideal setting
+# depends on how your operating system processes characters. The
+# default of 100000 usec (.1 seconds) was chosen because it works
+# consistently in Windows.
+# If your OS is losing characters during a paste, increase the paste
+# delay until it stops losing characters.
+#
+# KEYMAP:
+# This enables a remap of a physical localized keyboard to a
+# virtualized us keyboard, as the PC architecture expects.
+#
+# USER_SHORTCUT:
+# This defines the keyboard shortcut to be sent when you press the "user"
+# button in the headerbar. The shortcut string is a combination of maximum
+# 3 key names (listed below) separated with a '-' character.
+# Valid key names:
+# "alt", "bksl", "bksp", "ctrl", "del", "down", "end", "enter", "esc",
+# "f1", ... "f12", "home", "ins", "left", "menu", "minus", "pgdwn", "pgup",
+# "plus", "power", "print", "right", "scrlck", "shift", "space", "tab", "up"
+# and "win".
+
+# Examples:
+# keyboard: type=mf, serial_delay=200, paste_delay=100000
+# keyboard: keymap=gui/keymaps/x11-pc-de.map
+# keyboard: user_shortcut=ctrl-alt-del
+#=======================================================================
+#keyboard: type=mf, serial_delay=250
+
+#=======================================================================
+# MOUSE:
+# This defines parameters for the emulated mouse type, the initial status
+# of the mouse capture and the runtime method to toggle it.
+#
+# TYPE:
+# With the mouse type option you can select the type of mouse to emulate.
+# The default value is 'ps2'. The other choices are 'imps2' (wheel mouse
+# on PS/2), 'serial', 'serial_wheel', 'serial_msys' (one com port requires
+# setting 'mode=mouse') 'inport' and 'bus' (if present). To connect a mouse
+# to a USB port, see the 'usb_uhci', 'usb_ohci', 'usb_ehci' or 'usb_xhci'
+# options (requires PCI and USB support).
+#
+# ENABLED:
+# The Bochs gui creates mouse "events" unless the 'enabled' option is
+# set to 0. The hardware emulation itself is not disabled by this.
+# Unless you have a particular reason for enabling the mouse by default,
+# it is recommended that you leave it off. You can also toggle the mouse
+# usage at runtime (RFB, SDL, Win32, wxWidgets and X11 - see below).
+#
+# TOGGLE:
+# The default method to toggle the mouse capture at runtime is to press the
+# CTRL key and the middle mouse button ('ctrl+mbutton'). This option allows
+# to change the method to 'ctrl+f10' (like DOSBox), 'ctrl+alt' (like QEMU)
+# or 'f12'.
+#
+# Examples:
+# mouse: enabled=1
+# mouse: type=imps2, enabled=1
+# mouse: type=serial, enabled=1
+# mouse: enabled=0, toggle=ctrl+f10
+#=======================================================================
+mouse: enabled=0
+
+#=======================================================================
+# PCI:
+# This defines the parameters to set up the Bochs PCI emulation:
+#
+# ENABLED:
+# If Bochs is compiled with PCI support, it is enabled by default.
+#
+# CHIPSET:
+# Currently the chipsets i430FX, i440FX and i440BX (limited) are supported and
+# the default is i440FX.
+#
+# SLOTx:
+# It is possible to specify the devices connected to PCI slots. Up to 5 slots
+# are available. For combined PCI/ISA devices assigning to slot is mandatory
+# if the PCI model should be emulated (cirrus, ne2k and pcivga). Setting up
+# slot for PCI-only devices is also supported, but they are auto-assigned if
+# not specified (e1000, es1370, pcidev, pcipnic, usb_ehci, usb_ohci, usb_xhci,
+# voodoo). All device models except the network devices ne2k and e1000 can be
+# used only once in the slot configuration. In case of the i440BX chipset, the
+# slot #5 is the AGP slot. Currently only the 'voodoo' device can be assigned
+# to AGP.
+#
+# ADVOPTS:
+# With the advanced PCI options it is possible to control the behaviour of the
+# PCI chipset. These options can be specified as comma-separated values.
+# By default the "Bochs i440FX" chipset enables the ACPI and HPET devices, but
+# original i440FX doesn't support them. The options 'noacpi' and 'nohpet' make
+# it possible to disable them.
+#
+# Example:
+# pci: enabled=1, chipset=i440fx, slot1=pcivga, slot2=ne2k, advopts=noacpi
+#=======================================================================
+pci: enabled=1, chipset=i440fx
+
+#=======================================================================
+# CLOCK:
+# This defines the parameters of the clock inside Bochs:
+#
+# SYNC:
+# This defines the method how to synchronize the Bochs internal time
+# with realtime. With the value 'none' the Bochs time relies on the IPS
+# value and no host time synchronization is used. The 'slowdown' method
+# sacrifices performance to preserve reproducibility while allowing host
+# time correlation. The 'realtime' method sacrifices reproducibility to
+# preserve performance and host-time correlation.
+# It is possible to enable both synchronization methods.
+#
+# RTC_SYNC:
+# If this option is enabled together with the realtime synchronization,
+# the RTC runs at realtime speed. This feature is disabled by default.
+#
+# TIME0:
+# Specifies the start (boot) time of the virtual machine. Use a time
+# value as returned by the time(2) system call or a string as returned
+# by the ctime(3) system call. If no time0 value is set or if time0
+# equal to 1 (special case) or if time0 equal 'local', the simulation
+# will be started at the current local host time. If time0 equal to 2
+# (special case) or if time0 equal 'utc', the simulation will be started
+# at the current utc time.
+#
+# Syntax:
+# clock: sync=[none|slowdown|realtime|both], time0=[timeValue|local|utc]
+#
+# Example:
+# clock: sync=none, time0=local # Now (localtime)
+# clock: sync=slowdown, time0=315529200 # Tue Jan 1 00:00:00 1980
+# clock: sync=none, time0="Mon Jan 1 00:00:00 1990" # 631148400
+# clock: sync=realtime, time0=938581955 # Wed Sep 29 07:12:35 1999
+# clock: sync=realtime, time0="Sat Jan 1 00:00:00 2000" # 946681200
+# clock: sync=none, time0=1 # Now (localtime)
+# clock: sync=none, time0=utc # Now (utc/gmt)
+#
+# Default value are sync=none, rtc_sync=0, time0=local
+#=======================================================================
+#clock: sync=none, time0=local
+
+#=======================================================================
+# CMOSIMAGE:
+# This defines a binary image file with size 128 bytes that can be loaded into
+# the CMOS RAM at startup. The rtc_init parameter controls whether initialize
+# the RTC with values stored in the image. By default the time0 argument given
+# to the clock option is used. With 'rtc_init=image' the image is the source
+# for the initial time.
+#
+# Example:
+# cmosimage: file=cmos.img, rtc_init=image
+#=======================================================================
+#cmosimage: file=cmos.img, rtc_init=time0
+
+#=======================================================================
+# private_colormap: Request that the GUI create and use it's own
+# non-shared colormap. This colormap will be used
+# when in the bochs window. If not enabled, a
+# shared colormap scheme may be used. Not implemented
+# on all GUI's.
+#
+# Examples:
+# private_colormap: enabled=1
+# private_colormap: enabled=0
+#=======================================================================
+private_colormap: enabled=0
#=======================================================================
# FLOPPYA:
@@ -450,14 +713,14 @@ ata3: enabled=0, ioaddr1=0x168, ioaddr2=0x360, irq=9
#
# This defines the type and characteristics of all attached ata devices:
# type= type of attached device [disk|cdrom]
-# mode= only valid for disks [flat|concat|external|dll|sparse|vmware3]
-# mode= only valid for disks [undoable|growing|volatile|vvfat]
+# mode= only valid for disks [flat|concat|dll|sparse|vmware3|vmware4]
+# [undoable|growing|volatile|vpc|vbox|vvfat]
# path= path of the image / directory
# cylinders= only valid for disks
# heads= only valid for disks
# spt= only valid for disks
# status= only valid for cdroms [inserted|ejected]
-# biosdetect= type of biosdetection [none|auto], only for disks on ata0 [cmos]
+# biosdetect= type of biosdetection [auto|cmos|none]
# translation=type of translation of the bios, only for disks [none|lba|large|rechs|auto]
# model= string returned by identify device command
# journal= optional filename of the redolog for undoable, volatile and vvfat disks
@@ -520,48 +783,6 @@ ata3: enabled=0, ioaddr1=0x168, ioaddr2=0x360, irq=9
boot: network, floppy
#=======================================================================
-# CLOCK:
-# This defines the parameters of the clock inside Bochs:
-#
-# SYNC:
-# This defines the method how to synchronize the Bochs internal time
-# with realtime. With the value 'none' the Bochs time relies on the IPS
-# value and no host time synchronization is used. The 'slowdown' method
-# sacrifices performance to preserve reproducibility while allowing host
-# time correlation. The 'realtime' method sacrifices reproducibility to
-# preserve performance and host-time correlation.
-# It is possible to enable both synchronization methods.
-#
-# RTC_SYNC:
-# If this option is enabled together with the realtime synchronization,
-# the RTC runs at realtime speed. This feature is disabled by default.
-#
-# TIME0:
-# Specifies the start (boot) time of the virtual machine. Use a time
-# value as returned by the time(2) system call. If no time0 value is
-# set or if time0 equal to 1 (special case) or if time0 equal 'local',
-# the simulation will be started at the current local host time.
-# If time0 equal to 2 (special case) or if time0 equal 'utc',
-# the simulation will be started at the current utc time.
-#
-# Syntax:
-# clock: sync=[none|slowdown|realtime|both], time0=[timeValue|local|utc]
-#
-# Example:
-# clock: sync=none, time0=local # Now (localtime)
-# clock: sync=slowdown, time0=315529200 # Tue Jan 1 00:00:00 1980
-# clock: sync=none, time0=631148400 # Mon Jan 1 00:00:00 1990
-# clock: sync=realtime, time0=938581955 # Wed Sep 29 07:12:35 1999
-# clock: sync=realtime, time0=946681200 # Sat Jan 1 00:00:00 2000
-# clock: sync=none, time0=1 # Now (localtime)
-# clock: sync=none, time0=utc # Now (utc/gmt)
-#
-# Default value are sync=none, time0=local
-#=======================================================================
-#clock: sync=none, time0=local
-
-
-#=======================================================================
# FLOPPY_BOOTSIG_CHECK: disabled=[0|1]
# Enables or disables the 0xaa55 signature check on boot floppies
# Defaults to disabled=0
@@ -613,9 +834,11 @@ log: bochsout.txt
# debug: messages useful only when debugging the code. This may
# spit out thousands per second.
#
-# For events of each level, you can choose to exit Bochs ('fatal'), 'report'
-# or 'ignore'. On some guis you have the additional choice 'ask'. A gui dialog
-# appears asks how to proceed.
+# For events of each level, you can choose to exit Bochs ('fatal'), 'ask',
+# 'warn', 'report' or 'ignore'. The choices 'ask' and 'warn' are not supported
+# by all guis, since they should bring up a dialog box. The 'warn' dialog is
+# designed to confirm errors and the 'ask' dialog is usually used for panics
+# and asks the user how to proceed.
#
# It is also possible to specify the 'action' to do for each Bochs facility
# separately (e.g. crash on panics from everything except the cdrom, and only
@@ -646,10 +869,10 @@ debugger_log: -
#=======================================================================
# COM1, COM2, COM3, COM4:
-# This defines a serial port (UART type 16550A). In the 'term' you can specify
-# a device to use as com1. This can be a real serial line, or a pty. To use
-# a pty (under X/Unix), create two windows (xterms, usually). One of them will
-# run bochs, and the other will act as com1. Find out the tty the com1
+# This defines a serial port (UART type 16550A). In the 'term' mode you can
+# specify a device to use as com1. This can be a real serial line, or a pty.
+# To use a pty (under X/Unix), create two windows (xterms, usually). One of
+# them will run bochs, and the other will act as com1. Find out the tty the com1
# window using the `tty' command, and use that as the `dev' parameter.
# Then do `sleep 1000000' in the com1 window to keep the shell from
# messing with things, and run bochs in the other window. Serial I/O to
@@ -660,13 +883,13 @@ debugger_log: -
# opens socket/named pipe and waits until a client application connects to it
# before starting simulation. This mode is useful for remote debugging (e.g.
# with gdb's "target remote host:port" command or windbg's command line option
-# -k com:pipe,port=\\.\pipe\pipename). Note: 'socket' is a shorthand for
-# 'socket-client' and 'pipe' for 'pipe-client'. Socket modes use simple TCP
-# communication, pipe modes use duplex byte mode pipes.
+# -k com:pipe,port=\\.\pipe\pipename). Socket modes use simple TCP communication,
+# pipe modes use duplex byte mode pipes.
# Other serial modes are 'null' (no input/output), 'file' (output to a file
-# specified as the 'dev' parameter), 'raw' (use the real serial port - under
-# construction for win32), 'mouse' (standard serial mouse - requires
-# mouse option setting 'type=serial', 'type=serial_wheel' or 'type=serial_msys').
+# specified as the 'dev' parameter and changeable at runtime), 'raw' (use the
+# real serial port - partly implemented on win32), 'mouse' (standard serial
+# mouse - requires mouse option setting 'type=serial', 'type=serial_wheel' or
+# 'type=serial_msys').
#
# Examples:
# com1: enabled=1, mode=null
@@ -687,7 +910,7 @@ debugger_log: -
# defined the emulated printer port sends characters printed by the guest OS
# into the output file. On some platforms a device filename can be used to
# send the data to the real parallel port (e.g. "/dev/lp0" on Linux, "lpt1" on
-# win32 platforms).
+# win32 platforms). The output file can be changed at runtime.
#
# Examples:
# parport1: enabled=1, file="parport.out"
@@ -697,28 +920,76 @@ debugger_log: -
parport1: enabled=1, file="parport.out"
#=======================================================================
+# SOUND:
+# This defines the lowlevel sound driver(s) for the wave (PCM) input / output
+# and the MIDI output feature and (if necessary) the devices to be used.
+# It can have several of the following properties.
+# All properties are in the format sound: property=value
+#
+# waveoutdrv:
+# This defines the driver to be used for the waveout feature.
+# Possible values are 'file' (all wave data sent to file), 'dummy' (no
+# output) and the platform-dependant drivers 'alsa', 'oss', 'osx', 'sdl'
+# and 'win'.
+# waveout:
+# This defines the device to be used for wave output (if necessary) or
+# the output file for the 'file' driver.
+# waveindrv:
+# This defines the driver to be used for the wavein feature.
+# Possible values are 'dummy' (recording silence) and platform-dependent
+# drivers 'alsa', 'oss', 'sdl' and 'win'.
+# wavein:
+# This defines the device to be used for wave input (if necessary).
+# midioutdrv:
+# This defines the driver to be used for the MIDI output feature.
+# Possible values are 'file' (all MIDI data sent to file), 'dummy' (no
+# output) and platform-dependent drivers 'alsa', 'oss', 'osx' and 'win'.
+# midiout:
+# This defines the device to be used for MIDI output (if necessary).
+# driver:
+# This defines the driver to be used for all sound features with one
+# property. Possible values are 'default' (platform default) and all
+# other choices described above. Overriding one or more settings with
+# the specific driver parameter is possible.
+#
+# Example for different drivers:
+# sound: waveoutdrv=sdl, waveindrv=alsa, midioutdrv=dummy
+#=======================================================================
+#sound: driver=default, waveout=/dev/dsp. wavein=, midiout=
+
+#=======================================================================
+# SPEAKER:
+# This defines the PC speaker output mode. In the 'sound' mode the beep
+# is generated by the square wave generator which is a part of the
+# lowlevel sound support. In this mode the 'volume' parameter can be used
+# to set the output volume (0 - 15). The 'system' mode is only available on
+# Linux and Windows. On Linux /dev/console is used for output and on Windows
+# the Beep() function. The 'gui' mode forwards the beep to the related
+# gui methods (currently only used by the Carbon gui).
+#=======================================================================
+speaker: enabled=1, mode=system
+
+#=======================================================================
# SB16:
# This defines the SB16 sound emulation. It can have several of the
# following properties.
# All properties are in the format sb16: property=value
+#
# enabled:
# This optional property controls the presence of the SB16 emulation.
# The emulation is turned on unless this property is used and set to 0.
-# midi: The filename is where the midi data is sent. This can be a
-# device or just a file if you want to record the midi data.
-# midimode:
-# 0=no data
-# 1=output to device (system dependent. midi denotes the device driver)
-# 2=SMF file output, including headers
-# 3=output the midi data stream to the file (no midi headers and no
-# delta times, just command and data bytes)
-# wave: This is the device/file where wave output is stored
-# wavemode:
-# 0=no data
-# 1=output to device (system dependent. wave denotes the device driver)
-# 2=VOC file output, incl. headers
-# 3=output the raw wave stream to the file
-# log: The file to write the sb16 emulator messages to.
+# midimode: This parameter specifies what to do with the MIDI output.
+# 0 = no output
+# 1 = output to device specified with the sound option (system dependent)
+# 2 = MIDI or raw data output to file (depends on file name extension)
+# 3 = dual output (mode 1 and 2 at the same time)
+# midifile: This is the file where the midi output is stored (midimode 2 or 3).
+# wavemode: This parameter specifies what to do with the PCM output.
+# 0 = no output
+# 1 = output to device specified with the sound option (system dependent)
+# 2 = VOC, WAV or raw data output to file (depends on file name extension)
+# 3 = dual output (mode 1 and 2 at the same time)
+# wavefile: This is the file where the wave output is stored (wavemode 2 or 3).
# loglevel:
# 0=no log
# 1=resource changes, midi program and bank changes
@@ -726,125 +997,50 @@ parport1: enabled=1, file="parport.out"
# 3=all errors
# 4=all errors plus all port accesses
# 5=all errors and port accesses plus a lot of extra info
+# log: The file to write the sb16 emulator messages to.
# dmatimer:
# microseconds per second for a DMA cycle. Make it smaller to fix
# non-continuous sound. 750000 is usually a good value. This needs a
# reasonably correct setting for the IPS parameter of the CPU option.
#
-# Examples for output devices:
-# sb16: midimode=1, midi="", wavemode=1, wave="" # win32
-# sb16: midimode=1, midi=alsa:128:0, wavemode=1, wave=alsa # Linux with ALSA
+# Examples for output modes:
+# sb16: midimode=2, midifile="output.mid", wavemode=1 # MIDI to file
+# sb16: midimode=1, wavemode=3, wavefile="output.wav" # wave to file and device
#=======================================================================
-#sb16: midimode=1, midi=/dev/midi00, wavemode=1, wave=/dev/dsp, loglevel=2, log=sb16.log, dmatimer=600000
+#sb16: midimode=1, wavemode=1, loglevel=2, log=sb16.log, dmatimer=600000
#=======================================================================
# ES1370:
-# This defines the ES1370 sound emulation. The parameter 'enabled' controls the
-# presence of the device. In addition to this, it must be loaded with 'plugin_ctrl'
-# and assigned to a PCI slot. The 'wavedev' parameter is similar to the 'wave'
-# parameter of the SB16 soundcard. The emulation supports recording and playback
-# (except DAC1+DAC2 output at the same time).
-#
-# Examples:
-# es1370: enabled=1, wavedev="" # win32
-# es1370: enabled=1, wavedev=alsa # Linux with ALSA
-#=======================================================================
-#es1370: enabled=1, wavedev=alsa
-
-#=======================================================================
-# KEYBOARD_SERIAL_DELAY:
-# Approximate time in microseconds that it takes one character to
-# be transfered from the keyboard to controller over the serial path.
-# Examples:
-# keyboard_serial_delay: 200
-#=======================================================================
-keyboard_serial_delay: 250
-
-#=======================================================================
-# KEYBOARD_PASTE_DELAY:
-# Approximate time in microseconds between attempts to paste
-# characters to the keyboard controller. This leaves time for the
-# guest os to deal with the flow of characters. The ideal setting
-# depends on how your operating system processes characters. The
-# default of 100000 usec (.1 seconds) was chosen because it works
-# consistently in Windows.
-#
-# If your OS is losing characters during a paste, increase the paste
-# delay until it stops losing characters.
-#
-# Examples:
-# keyboard_paste_delay: 100000
-#=======================================================================
-keyboard_paste_delay: 100000
-
-#=======================================================================
-# MOUSE:
-# This defines parameters for the emulated mouse type, the initial status
-# of the mouse capture and the runtime method to toggle it.
-#
-# TYPE:
-# With the mouse type option you can select the type of mouse to emulate.
-# The default value is 'ps2'. The other choices are 'imps2' (wheel mouse
-# on PS/2), 'serial', 'serial_wheel' and 'serial_msys' (one com port requires
-# setting 'mode=mouse'). To connect a mouse to an USB port, see the 'usb_uhci',
-# 'usb_ohci' or 'usb_xhci' options (requires PCI and USB support).
-#
-# ENABLED:
-# The Bochs gui creates mouse "events" unless the 'enabled' option is
-# set to 0. The hardware emulation itself is not disabled by this.
-# Unless you have a particular reason for enabling the mouse by default,
-# it is recommended that you leave it off. You can also toggle the mouse
-# usage at runtime (RFB, SDL, Win32, wxWidgets and X11 - see below).
-#
-# TOGGLE:
-# The default method to toggle the mouse capture at runtime is to press the
-# CTRL key and the middle mouse button ('ctrl+mbutton'). This option allows
-# to change the method to 'ctrl+f10' (like DOSBox), 'ctrl+alt' (like QEMU)
-# or 'f12' (replaces win32 'legacyF12' option).
-#
-# Examples:
-# mouse: enabled=1
-# mouse: type=imps2, enabled=1
-# mouse: type=serial, enabled=1
-# mouse: enabled=0, toggle=ctrl+f10
-#=======================================================================
-mouse: enabled=0
-
-#=======================================================================
-# private_colormap: Request that the GUI create and use it's own
-# non-shared colormap. This colormap will be used
-# when in the bochs window. If not enabled, a
-# shared colormap scheme may be used. Not implemented
-# on all GUI's.
-#
-# Examples:
-# private_colormap: enabled=1
-# private_colormap: enabled=0
-#=======================================================================
-private_colormap: enabled=0
-
-#=======================================================================
-# fullscreen: ONLY IMPLEMENTED ON AMIGA
-# Request that Bochs occupy the entire screen instead of a
-# window.
+# This defines the ES1370 sound emulation (recording and playback - except
+# DAC1+DAC2 output at the same time). The parameter 'enabled' controls the
+# presence of the device. The wave and MIDI output can be sent to device, file
+# or both using the parameters 'wavemode', 'wavefile', 'midimode' and
+# 'midifile'. See the description of these parameters at the SB16 directive.
#
# Examples:
-# fullscreen: enabled=0
-# fullscreen: enabled=1
+# es1370: enabled=1, wavemode=1 # use 'sound' parameters
+# es1370: enabled=1, wavemode=2, wavefile=output.voc # send output to file
#=======================================================================
-#fullscreen: enabled=0
-#screenmode: name="sample"
+#es1370: enabled=1, wavemode=1
#=======================================================================
# ne2k: NE2000 compatible ethernet adapter
#
# Format:
-# ne2k: enabled=1, ioaddr=IOADDR, irq=IRQ, mac=MACADDR, ethmod=MODULE,
-# ethdev=DEVICE, script=SCRIPT, bootrom=BOOTROM
+# ne2k: card=CARD, enabled=1, type=TYPE, ioaddr=IOADDR, irq=IRQ, mac=MACADDR,
+# ethmod=MODULE, ethdev=DEVICE, script=SCRIPT, bootrom=BOOTROM
+#
+# CARD: This is the zero-based card number to configure with this ne2k config
+# line. Up to 4 devices are supported now (0...3). If not specified, the
+# following parameters apply to card #0.
+#
+# TYPE: This is the card type to emulate ("isa" or "pci"). If not specified,
+# card #0 defaults to "pci" if assigned to a pci slot. For the additional cards
+# the type parameter should be set up.
#
# IOADDR, IRQ: You probably won't need to change ioaddr and irq, unless there
# are IRQ conflicts. These arguments are ignored when assign the ne2k to a
-# PCI slot.
+# PCI slot or set the type to 'pci'.
#
# MAC: The MAC address MUST NOT match the address of any machine on the net.
# Also, the first byte must be an even number (bit 0 set means a multicast
@@ -857,6 +1053,8 @@ private_colormap: enabled=0
# Windows machines, you must run niclist to get the name of the ethdev.
# Niclist source code is in misc/niclist.c and it is included in Windows
# binary releases.
+# The 'socket' module uses this parameter to specify the UDP port for
+# receiving packets and (optional) the host to connect.
#
# SCRIPT: The script value is optional, and is the name of a script that
# is executed after bochs initialize the network interface. You can use
@@ -864,6 +1062,10 @@ private_colormap: enabled=0
# This is mainly useful for the tun/tap devices that only exist during
# Bochs execution. The network interface name is supplied to the script
# as first parameter.
+# The 'slirp' module uses this parameter to specify a config file for
+# setting up an alternative IP configuration or additional features.
+# The 'vnet' module also uses this parameter to specify a config file similar
+# to slirp, but with only a few settings.
#
# BOOTROM: The bootrom value is optional, and is the name of the ROM image
# to load. Note that this feature is only implemented for the PCI version of
@@ -873,11 +1075,14 @@ private_colormap: enabled=0
# you can use the following 'ethmod's to simulate a virtual network.
# null: All packets are discarded, but logged to a few files.
# vde: Virtual Distributed Ethernet
-# vnet: ARP, ICMP-echo(ping), DHCP and read/write TFTP are simulated.
+# vnet: ARP, ICMP-echo(ping), DHCP, DNS, FTP and TFTP are simulated.
# The virtual host uses 192.168.10.1.
-# DHCP assigns 192.168.10.2 to the guest.
-# TFTP uses the 'ethdev' value for the root directory and doesn't
-# overwrite files.
+# DHCP assigns 192.168.10.15 to the guest.
+# FTP/TFTP using the 'ethdev' value for the root directory.
+# TFTP doesn't overwrite files, DNS for server and client only.
+# socket: Connect up to 6 Bochs instances with external program 'bxhub'
+# (simulating an ethernet hub). It provides the same services as the
+# 'vnet' module and assigns IP addresses like 'slirp' (10.0.2.x).
#
#=======================================================================
# ne2k: ioaddr=0x300, irq=9, mac=fe:fd:00:00:00:01, ethmod=fbsd, ethdev=en0 #macosx
@@ -889,111 +1094,62 @@ private_colormap: enabled=0
# ne2k: ioaddr=0x300, irq=9, mac=b0:c4:20:00:00:01, ethmod=null, ethdev=eth0
# ne2k: ioaddr=0x300, irq=9, mac=b0:c4:20:00:00:01, ethmod=vde, ethdev="/tmp/vde.ctl"
# ne2k: ioaddr=0x300, irq=9, mac=b0:c4:20:00:00:01, ethmod=vnet, ethdev="c:/temp"
-# ne2k: mac=b0:c4:20:00:00:01, ethmod=slirp, script=/usr/local/bin/slirp, bootrom=ne2k_pci.rom
+# ne2k: mac=b0:c4:20:00:00:01, ethmod=socket, ethdev=40000 # use localhost
+# ne2k: mac=b0:c4:20:00:00:01, ethmod=socket, ethdev=mymachine:40000
+# ne2k: mac=b0:c4:20:00:00:01, ethmod=slirp, script=slirp.conf, bootrom=ne2k_pci.rom
#=======================================================================
-# pnic: Bochs/Etherboot pseudo-NIC
+# pcipnic: Bochs/Etherboot pseudo-NIC
#
# Format:
-# pnic: enabled=1, mac=MACADDR, ethmod=MODULE, ethdev=DEVICE, script=SCRIPT,
-# bootrom=BOOTROM
+# pcipnic: enabled=1, mac=MACADDR, ethmod=MODULE, ethdev=DEVICE, script=SCRIPT,
+# bootrom=BOOTROM
#
# The pseudo-NIC accepts the same syntax (for mac, ethmod, ethdev, script,
# bootrom) and supports the same networking modules as the NE2000 adapter.
-# In addition to this, it must be loaded with 'plugin_ctrl' and assigned
-# to a PCI slot.
#=======================================================================
-#pnic: enabled=1, mac=b0:c4:20:00:00:00, ethmod=vnet
+#pcipnic: enabled=1, mac=b0:c4:20:00:00:00, ethmod=vnet
#=======================================================================
# e1000: Intel(R) 82540EM Gigabit Ethernet adapter
#
# Format:
-# e1000: enabled=1, mac=MACADDR, ethmod=MODULE, ethdev=DEVICE, script=SCRIPT
-# bootrom=BOOTROM
+# e1000: card=CARD, enabled=1, mac=MACADDR, ethmod=MODULE, ethdev=DEVICE,
+# script=SCRIPT, bootrom=BOOTROM
#
-# The E1000 accepts the same syntax (for mac, ethmod, ethdev, script, bootrom)
-# and supports the same networking modules as the NE2000 adapter. In addition
-# to this, it must be loaded with 'plugin_ctrl' and assigned to a PCI slot.
+# The E1000 accepts the same syntax (for card, mac, ethmod, ethdev, script,
+# bootrom) and supports the same networking modules as the NE2000 adapter.
+# It also supports up to 4 devices selected with the card parameter.
#=======================================================================
-#e1000: enabled=1, mac=52:54:00:12:34:56, ethmod=slirp, script=/usr/local/bin/slirp
+#e1000: enabled=1, mac=52:54:00:12:34:56, ethmod=slirp, script=slirp.conf
e1000: enabled=1, mac=52:54:00:12:34:56, ethmod=tuntap, ethdev=/dev/net/tun:tap0
#=======================================================================
-# KEYBOARD_MAPPING:
-# This enables a remap of a physical localized keyboard to a
-# virtualized us keyboard, as the PC architecture expects.
-# If enabled, the keymap file must be specified.
-#
-# Examples:
-# keyboard_mapping: enabled=1, map=gui/keymaps/x11-pc-de.map
-#=======================================================================
-keyboard_mapping: enabled=0, map=
-
-#=======================================================================
-# KEYBOARD_TYPE:
-# Type of keyboard return by a "identify keyboard" command to the
-# keyboard controler. It must be one of "xt", "at" or "mf".
-# Defaults to "mf". It should be ok for almost everybody. A known
-# exception is french macs, that do have a "at"-like keyboard.
-#
-# Examples:
-# keyboard_type: mf
-#=======================================================================
-#keyboard_type: mf
-
-#=======================================================================
-# USER_SHORTCUT:
-# This defines the keyboard shortcut to be sent when you press the "user"
-# button in the headerbar. The shortcut string is a combination of maximum
-# 3 key names (listed below) separated with a '-' character.
-# Valid key names:
-# "alt", "bksl", "bksp", "ctrl", "del", "down", "end", "enter", "esc",
-# "f1", ... "f12", "home", "ins", "left", "menu", "minus", "pgdwn", "pgup",
-# "plus", "right", "shift", "space", "tab", "up", "win", "print" and "power".
-#
-# Example:
-# user_shortcut: keys=ctrl-alt-del
-#=======================================================================
-#user_shortcut: keys=ctrl-alt-del
-
-#=======================================================================
-# PCI:
-# This option controls the presence of a PCI chipset in Bochs. Currently it only
-# supports the i440FX chipset. You can also specify the devices connected to
-# PCI slots. Up to 5 slots are available. These devices are currently supported:
-# cirrus, e1000, es1370, ne2k, pcivga, pcidev, pcipnic, usb_ohci and usb_xhci.
-#
-# Example:
-# pci: enabled=1, chipset=i440fx, slot1=pcivga, slot2=ne2k
-#=======================================================================
-pci: enabled=1, chipset=i440fx, slot1=e1000
-
-#=======================================================================
# USB_UHCI:
# This option controls the presence of the USB root hub which is a part
# of the i440FX PCI chipset. With the portX parameter you can connect devices
-# to the hub (currently supported: 'mouse', 'tablet', 'keypad', 'disk', 'cdrom'
-# 'hub' and 'printer'). NOTE: UHCI must be loaded with 'plugin_ctrl'.
-#
-# The optionsX parameter can be used to assign specific options to the device
-# connected to the corresponding USB port. Currently this feature is only used
-# to set the speed reported by device and by the 'disk' device to specify
-# an alternative redolog file of some image modes.
+# to the hub (currently supported: 'mouse', 'tablet', 'keypad', 'keyboard',
+# 'disk', 'cdrom', 'floppy', 'hub' and 'printer').
#
# If you connect the mouse or tablet to one of the ports, Bochs forwards the
# mouse movement data to the USB device instead of the selected mouse type.
# When connecting the keypad to one of the ports, Bochs forwards the input of
-# the numeric keypad to the USB device instead of the PS/2 keyboard.
+# the numeric keypad to the USB device instead of the PS/2 keyboard. If the
+# keyboard is selected, all key events are sent to the USB device.
#
-# To connect a 'flat' mode image as an USB hardisk you can use the 'disk' device
+# To connect a 'flat' mode image as a USB hardisk you can use the 'disk' device
# with the path to the image separated with a colon. To use other disk image modes
# similar to ATA disks the syntax 'disk:mode:filename' must be used (see below).
#
-# To emulate an USB cdrom you can use the 'cdrom' device name and the path to
+# To emulate a USB cdrom you can use the 'cdrom' device name and the path to
# an ISO image or raw device name also separated with a colon. An option to
# insert/eject media is available in the runtime configuration.
#
+# To emulate a USB floppy you can use the 'floppy' device with the path to the
+# image separated with a colon. To use the VVFAT image mode similar to the
+# legacy floppy the syntax 'floppy:vvfat:directory' must be used (see below).
+# An option to insert/eject media is available in the runtime configuration.
+#
# The device name 'hub' connects an external hub with max. 8 ports (default: 4)
# to the root hub. To specify the number of ports you have to add the value
# separated with a colon. Connecting devices to the external hub ports is only
@@ -1001,45 +1157,77 @@ pci: enabled=1, chipset=i440fx, slot1=e1000
#
# The device 'printer' emulates the HP Deskjet 920C printer. The PCL data is
# sent to a file specified in bochsrc.txt. The current code appends the PCL
-# code to the file if the file already existed. It would probably be nice to
-# overwrite the file instead, asking user first.
+# code to the file if the file already existed. The output file can be
+# changed at runtime.
+#
+# The optionsX parameter can be used to assign specific options to the device
+# connected to the corresponding USB port. Currently this feature is used to
+# set the speed reported by device ('low', 'full', 'high' or 'super'). The
+# available speed choices depend on both HC and device. The option 'debug' turns
+# on debug output for the device at connection time.
+# For the USB 'disk' device the optionsX parameter can be used to specify an
+# alternative redolog file (journal) of some image modes. For 'vvfat' mode USB
+# disks the optionsX parameter can be used to specify the disk size (range
+# 128M ... 128G). If the size is not specified, it defaults to 504M.
+# For the USB 'floppy' device the optionsX parameter can be used to specify an
+# alternative device ID to be reported. Currently only the model "teac" is
+# supported (can fix hw detection in some guest OS). The USB floppy also
+# accepts the parameter "write_protected" with valid values 0 and 1 to select
+# the access mode (default is 0).
#=======================================================================
#usb_uhci: enabled=1
#usb_uhci: enabled=1, port1=mouse, port2=disk:usbstick.img
#usb_uhci: enabled=1, port1=hub:7, port2=disk:growing:usbdisk.img
-#usb_uhci: enabled=1, port2=disk:undoable:usbdisk.img, options1=journal:redo.log
+#usb_uhci: enabled=1, port2=disk:undoable:usbdisk.img, options2=journal:redo.log
+#usb_uhci: enabled=1, port2=disk:usbdisk2.img, options2=sect_size:1024
+#usb_uhci: enabled=1, port2=disk:vvfat:vvfat, options2="debug,speed:full"
#usb_uhci: enabled=1, port1=printer:printdata.bin, port2=cdrom:image.iso
+#usb_uhci: enabled=1, port2=floppy:vvfat:diskette, options2="model:teac"
#=======================================================================
# USB_OHCI:
# This option controls the presence of the USB OHCI host controller with a
-# 2-port hub. The portX option accepts the same device types with the same
-# syntax as the UHCI controller (see above). The OHCI HC must be assigned to
-# a PCI slot and loaded with 'plugin_ctrl'.
+# 2-port hub. The portX parameter accepts the same device types with the same
+# syntax as the UHCI controller (see above). The optionsX parameter is also
+# available on OHCI.
#=======================================================================
#usb_ohci: enabled=1
#usb_ohci: enabled=1, port1=printer:usbprinter.bin
#=======================================================================
+# USB_EHCI:
+# This option controls the presence of the USB EHCI host controller with a
+# 6-port hub. The portX parameter accepts the same device types with the
+# same syntax as the UHCI controller (see above). The optionsX parameter is
+# also available on EHCI.
+#=======================================================================
+#usb_ehci: enabled=1
+
+#=======================================================================
# USB_XHCI:
-# This option controls the presence of the experimental USB xHCI host controller
-# with a 4-port hub. The portX option accepts the same device types with the
-# same syntax as the UHCI controller (see above). The xHCI HC must be assigned
-# to a PCI slot and loaded with 'plugin_ctrl'.
+# This option controls the presence of the USB xHCI host controller with a
+# 4-port hub. The portX parameter accepts the same device types with the
+# same syntax as the UHCI controller (see above). The optionsX parameter is
+# also available on xHCI. NOTE: port 1 and 2 are USB3 and only support
+# super-speed devices, but port 3 and 4 are USB2 and support speed settings
+# low, full and high.
#=======================================================================
#usb_xhci: enabled=1
#=======================================================================
-# CMOSIMAGE:
-# This defines image file that can be loaded into the CMOS RAM at startup.
-# The rtc_init parameter controls whether initialize the RTC with values stored
-# in the image. By default the time0 argument given to the clock option is used.
-# With 'rtc_init=image' the image is the source for the initial time.
-#
-# Example:
-# cmosimage: file=cmos.img, rtc_init=image
+# PCIDEV:
+# PCI host device mapping
+# WARNING: This Bochs feature is not maintained yet and may fail.
#=======================================================================
-#cmosimage: file=cmos.img, rtc_init=time0
+#pcidev: vendor=0x1234, device=0x5678
+
+#=======================================================================
+# GDBSTUB:
+# Enable GDB stub. See user documentation for details.
+# Default value is enabled=0.
+# WARNING: This Bochs feature is not maintained yet and may fail.
+#=======================================================================
+#gdbstub: enabled=0, port=1234, text_base=0, data_base=0, bss_base=0
#=======================================================================
# MAGIC_BREAK:
@@ -1050,25 +1238,9 @@ pci: enabled=1, chipset=i440fx, slot1=e1000
# Example:
# magic_break: enabled=1
#=======================================================================
-#magic_break: enabled=1
magic_break: enabled=1
#=======================================================================
-# PORT_E9_HACK:
-# The 0xE9 port doesn't exists in normal ISA architecture. However, we
-# define a convention here, to display on the console of the system running
-# Bochs anything that is written to it. The idea is to provide debug output
-# very early when writing BIOS or OS code for example, without having to
-# bother with setting up a serial port or etc. Reading from port 0xE9 will
-# will return 0xe9 to let you know if the feature is available.
-# Leave this 0 unless you have a reason to use it.
-#
-# Example:
-# port_e9_hack: enabled=1
-#=======================================================================
-port_e9_hack: enabled=1
-
-#=======================================================================
# DEBUG_SYMBOLS:
# This loads symbols from the specified file for use in Bochs' internal
# debugger. Symbols are loaded into global context. This is equivalent to
@@ -1080,32 +1252,34 @@ port_e9_hack: enabled=1
#=======================================================================
#debug_symbols: file="kernel.sym"
-#=======================================================================
-# other stuff
-#=======================================================================
-#load32bitOSImage: os=nullkernel, path=../kernel.img, iolog=../vga_io.log
-#load32bitOSImage: os=linux, path=../linux.img, iolog=../vga_io.log, initrd=../initrd.img
#print_timestamps: enabled=1
-#-------------------------
-# PCI host device mapping
-#-------------------------
-#pcidev: vendor=0x1234, device=0x5678
-
#=======================================================================
-# GDBSTUB:
-# Enable GDB stub. See user documentation for details.
-# Default value is enabled=0.
+# PORT_E9_HACK:
+# The 0xE9 port doesn't exists in normal ISA architecture. However, we
+# define a convention here, to display on the console of the system running
+# Bochs anything that is written to it. The idea is to provide debug output
+# very early when writing BIOS or OS code for example, without having to
+# bother with setting up a serial port or etc. Reading from port 0xE9 will
+# will return 0xe9 to let you know if the feature is available.
+# Leave this 0 unless you have a reason to use it.
+#
+# Example:
+# port_e9_hack: enabled=1
#=======================================================================
-#gdbstub: enabled=0, port=1234, text_base=0, data_base=0, bss_base=0
+port_e9_hack: enabled=1
#=======================================================================
-# USER_PLUGIN:
-# Load user-defined plugin. This option is available only if Bochs is
-# compiled with plugin support. Maximum 8 different plugins are supported.
-# See the example in the Bochs sources how to write a plugin device.
+# fullscreen: ONLY IMPLEMENTED ON AMIGA
+# Request that Bochs occupy the entire screen instead of a
+# window.
+#
+# Examples:
+# fullscreen: enabled=0
+# fullscreen: enabled=1
#=======================================================================
-#user_plugin: name=testdev
+#fullscreen: enabled=0
+#screenmode: name="sample"
#=======================================================================
# for Macintosh, use the style of pathnames in the following
diff --git a/src/Makefile b/src/Makefile
index 758db7e1f..69139dc11 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -10,6 +10,7 @@ LDFLAGS :=
HOST_CFLAGS :=
MAKEDEPS := Makefile
CROSS_COMPILE ?= $(CROSS)
+SYMBOL_PREFIX :=
###############################################################################
#
@@ -48,7 +49,6 @@ ELF2EFI32 := ./util/elf2efi32
ELF2EFI64 := ./util/elf2efi64
EFIROM := ./util/efirom
EFIFATBIN := ./util/efifatbin
-ICCFIX := ./util/iccfix
EINFO := ./util/einfo
GENKEYMAP := ./util/genkeymap.pl
DOXYGEN := doxygen
diff --git a/src/Makefile.efi b/src/Makefile.efi
index 10f3fe74b..11e29dd58 100644
--- a/src/Makefile.efi
+++ b/src/Makefile.efi
@@ -43,12 +43,12 @@ $(BIN)/%.drv.efi : $(BIN)/%.efidrv
$(BIN)/%.efirom : $(BIN)/%.efidrv $(EFIROM)
$(QM)$(ECHO) " [FINISH] $@"
- $(Q)$(EFIROM) -v $(TGT_PCI_VENDOR) -d $(TGT_PCI_DEVICE) $< $@
+ $(Q)$(EFIROM) -v $(TGT_PCI_VENDOR) -d $(TGT_PCI_DEVICE) -c $< $@
$(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) $<
+$(BIN)/%.iso $(BIN)/%.usb : $(BIN)/%.efi util/genfsimg
+ $(QM)$(ECHO) " [GENFSIMG] $@"
+ $(Q)util/genfsimg -o $@ $<
diff --git a/src/Makefile.housekeeping b/src/Makefile.housekeeping
index 134becd50..e017c656b 100644
--- a/src/Makefile.housekeeping
+++ b/src/Makefile.housekeeping
@@ -76,9 +76,7 @@ CCDEFS := $(shell $(CC) -E -x c -c /dev/null -dM | cut -d" " -f2)
ccdefs:
@$(ECHO) $(CCDEFS)
-ifeq ($(filter __ICC,$(CCDEFS)),__ICC)
-CCTYPE := icc
-else
+ifeq ($(filter __GNUC__,$(CCDEFS)),__GNUC__)
CCTYPE := gcc
endif
cctype:
@@ -113,6 +111,13 @@ $(warning Use GNU ld instead)
$(error Unsuitable build environment found)
endif
+OBJCOPY_ETC_BANNER := $(shell $(OBJCOPY) --version | grep 'elftoolchain')
+ifneq ($(OBJCOPY_ETC_BANNER),)
+$(warning The elftoolchain objcopy is unsuitable for building iPXE)
+$(warning Use binutils objcopy instead)
+$(error Unsuitable build environment found)
+endif
+
###############################################################################
#
# Check if $(eval ...) is available to use
@@ -342,7 +347,7 @@ arch :
# Determine build platform
DEFAULT_PLATFORM := pcbios
PLATFORM := $(firstword $(BIN_PLATFORM) $(DEFAULT_PLATFORM))
-CFLAGS += -DPLATFORM=$(PLATFORM)
+CFLAGS += -DPLATFORM=$(PLATFORM) -DPLATFORM_$(PLATFORM)
platform :
@$(ECHO) $(PLATFORM)
@@ -369,6 +374,43 @@ endif
###############################################################################
#
+# Especially ugly workarounds
+
+# Some widespread patched versions of gcc include -fPIE -Wl,-pie by
+# default. Note that gcc will exit *successfully* if it fails to
+# recognise an option that starts with "no", so we have to test for
+# output on stderr instead of checking the exit status.
+#
+# Current versions of gcc require -no-pie; older versions require
+# -nopie. We therefore test for both.
+#
+# This workaround must be determined only after the
+# architecture-specific Makefile has been included, since some
+# platforms (e.g. bin-x86_64-efi) will explicitly require the use of
+# -fpie.
+#
+ifeq ($(filter -fpie,$(CFLAGS)),)
+ifeq ($(CCTYPE),gcc)
+PIE_TEST = [ -z "`$(CC) -fno-PIE -no-pie -x c -c /dev/null -o /dev/null 2>&1`" ]
+PIE_FLAGS := $(shell $(PIE_TEST) && $(ECHO) '-fno-PIE -no-pie')
+PIE_TEST2 = [ -z "`$(CC) -fno-PIE -nopie -x c -c /dev/null -o /dev/null 2>&1`" ]
+PIE_FLAGS2 := $(shell $(PIE_TEST2) && $(ECHO) '-fno-PIE -nopie')
+WORKAROUND_CFLAGS += $(PIE_FLAGS) $(PIE_FLAGS2)
+endif
+endif
+
+# Some widespread patched versions of gcc include -fcf-protection=full
+# by default.
+#
+ifeq ($(CCTYPE),gcc)
+CFP_TEST = $(CC) -fcf-protection=none -x c -c /dev/null -o /dev/null \
+ >/dev/null 2>&1
+CFP_FLAGS := $(shell $(CFP_TEST) && $(ECHO) '-fcf-protection=none')
+WORKAROUND_CFLAGS += $(CFP_FLAGS)
+endif
+
+###############################################################################
+#
# Source file handling
# Exclude known-insecure files from Secure Boot builds
@@ -422,32 +464,6 @@ CFLAGS += -fcommon
CFLAGS += -Wall -W -Wformat-nonliteral
HOST_CFLAGS += -Wall -W -Wformat-nonliteral
endif
-ifeq ($(CCTYPE),icc)
-CFLAGS += -fno-builtin
-CFLAGS += -no-ip
-CFLAGS += -no-gcc
-CFLAGS += -diag-disable 111 # Unreachable code
-CFLAGS += -diag-disable 128 # Unreachable loop
-CFLAGS += -diag-disable 170 # Array boundary checks
-CFLAGS += -diag-disable 177 # Unused functions
-CFLAGS += -diag-disable 181 # printf() format checks
-CFLAGS += -diag-disable 188 # enum strictness
-CFLAGS += -diag-disable 193 # Undefined preprocessor identifiers
-CFLAGS += -diag-disable 280 # switch ( constant )
-CFLAGS += -diag-disable 310 # K&R parameter lists
-CFLAGS += -diag-disable 424 # Extra semicolon
-CFLAGS += -diag-disable 589 # Declarations mid-code
-CFLAGS += -diag-disable 593 # Unused variables
-CFLAGS += -diag-disable 810 # Casting ints to smaller ints
-CFLAGS += -diag-disable 981 # Sequence point violations
-CFLAGS += -diag-disable 1292 # Ignored attributes
-CFLAGS += -diag-disable 1338 # void pointer arithmetic
-CFLAGS += -diag-disable 1361 # Variable-length arrays
-CFLAGS += -diag-disable 1418 # Missing prototypes
-CFLAGS += -diag-disable 1419 # Missing prototypes
-CFLAGS += -diag-disable 1599 # Hidden variables
-CFLAGS += -Wall -Wmissing-declarations
-endif
CFLAGS += $(WORKAROUND_CFLAGS) $(EXTRA_CFLAGS)
ASFLAGS += $(WORKAROUND_ASFLAGS) $(EXTRA_ASFLAGS)
LDFLAGS += $(WORKAROUND_LDFLAGS) $(EXTRA_LDFLAGS)
@@ -461,35 +477,6 @@ ASFLAGS += --fatal-warnings
HOST_CFLAGS += -Werror
endif
-# Function trace recorder state in the last build. This is needed
-# in order to correctly rebuild whenever the function recorder is
-# enabled/disabled.
-#
-FNREC_STATE := $(BIN)/.fnrec.state
-ifeq ($(wildcard $(FNREC_STATE)),)
-FNREC_OLD := <invalid>
-else
-FNREC_OLD := $(shell cat $(FNREC_STATE))
-endif
-ifeq ($(FNREC_OLD),$(FNREC))
-$(FNREC_STATE) :
-else
-$(FNREC_STATE) : clean
-$(shell $(ECHO) "$(FNREC)" > $(FNREC_STATE))
-endif
-
-VERYCLEANUP += $(FNREC_STATE)
-MAKEDEPS += $(FNREC_STATE)
-
-ifeq ($(FNREC),1)
-# Enabling -finstrument-functions affects gcc's analysis and leads to spurious
-# warnings about use of uninitialised variables.
-#
-CFLAGS += -Wno-uninitialized
-CFLAGS += -finstrument-functions
-CFLAGS += -finstrument-functions-exclude-file-list=core/fnrec.c
-endif
-
# Enable per-item sections and section garbage collection. Note that
# some older versions of gcc support -fdata-sections but treat it as
# implying -fno-common, which would break our build. Some other older
@@ -540,16 +527,6 @@ OBJ_CFLAGS = $(CFLAGS_$(OBJECT)) -DOBJECT=$(subst -,_,$(OBJECT))
$(BIN)/%.flags :
@$(ECHO) $(OBJ_CFLAGS)
-# ICC requires postprocessing objects to fix up table alignments
-#
-ifeq ($(CCTYPE),icc)
-POST_O = && $(ICCFIX) $@
-POST_O_DEPS := $(ICCFIX)
-else
-POST_O :=
-POST_O_DEPS :=
-endif
-
# Debug level calculations
#
DBGLVL_MAX = -DDBGLVL_MAX=$(firstword $(subst ., ,$(1)))
@@ -559,9 +536,9 @@ DBGLVL = $(call DBGLVL_MAX,$(1)) $(call DBGLVL_DFLT,$(1))
# Rules for specific object types.
#
COMPILE_c = $(CC) $(CFLAGS) $(CFLAGS_c) $(OBJ_CFLAGS)
-RULE_c = $(Q)$(COMPILE_c) -c $< -o $@ $(POST_O)
+RULE_c = $(Q)$(COMPILE_c) -c $< -o $@
RULE_c_to_ids.o = $(Q)$(ECHO_E) '$(OBJ_IDS_ASM_NL)' | $(ASSEMBLE_S) -o $@
-RULE_c_to_dbg%.o= $(Q)$(COMPILE_c) $(call DBGLVL,$*) -c $< -o $@ $(POST_O)
+RULE_c_to_dbg%.o= $(Q)$(COMPILE_c) $(call DBGLVL,$*) -c $< -o $@
RULE_c_to_c = $(Q)$(COMPILE_c) -E -c $< > $@
RULE_c_to_s = $(Q)$(COMPILE_c) -S -g0 -c $< -o $@
@@ -801,6 +778,38 @@ include/ipxe/profile.h : $(PROFILE_LIST)
.PRECIOUS : include/ipxe/profile.h
+# (Single-element) list of function recorder configuration
+#
+FNREC_LIST := $(BIN)/.fnrec.list
+ifeq ($(wildcard $(FNREC_LIST)),)
+FNREC_OLD := <invalid>
+else
+FNREC_OLD := $(shell cat $(FNREC_LIST))
+endif
+ifneq ($(FNREC_OLD),$(FNREC))
+$(shell $(ECHO) "$(FNREC)" > $(FNREC_LIST))
+endif
+
+$(FNREC_LIST) : $(MAKEDEPS)
+
+VERYCLEANUP += $(FNREC_LIST)
+
+# Function recorder configuration
+#
+ifeq ($(FNREC),1)
+# Enabling -finstrument-functions affects gcc's analysis and leads to spurious
+# warnings about use of uninitialised variables.
+#
+CFLAGS += -Wno-uninitialized
+CFLAGS += -finstrument-functions
+CFLAGS += -finstrument-functions-exclude-file-list=core/fnrec.c
+endif
+
+include/compiler.h : $(FNREC_LIST)
+ $(Q)$(TOUCH) $@
+
+.PRECIOUS : include/compiler.h
+
# These files use .incbin inline assembly to include a binary file.
# Unfortunately ccache does not detect this dependency and caches
# builds even when the binary file has changed.
@@ -872,7 +881,7 @@ endef
# $(3) is the source base name (e.g. "rtl8139")
#
define rules_template_parts
-$$(BIN)/$(3).o : $(1) $$(MAKEDEPS) $$(POST_O_DEPS) $$($(3)_DEPS)
+$$(BIN)/$(3).o : $(1) $$(MAKEDEPS) $$($(3)_DEPS)
$$(QM)$(ECHO) " [BUILD] $$@"
$$(RULE_$(2))
BOBJS += $$(BIN)/$(3).o
@@ -887,7 +896,7 @@ endef
# $(4) is the destination type (e.g. "dbg%.o")
#
define rules_template_target
-$$(BIN)/$(3).$(4) : $(1) $$(MAKEDEPS) $$(POST_O_DEPS) $$($(3)_DEPS)
+$$(BIN)/$(3).$(4) : $(1) $$(MAKEDEPS) $$($(3)_DEPS)
$$(QM)$(ECHO) " [BUILD] $$@"
$$(RULE_$(2)_to_$(4))
$(TGT)_OBJS += $$(BIN)/$(3).$(4)
@@ -1093,9 +1102,10 @@ TGT_LD_ENTRY = _$(TGT_PREFIX)_start
#
TGT_LD_FLAGS = $(foreach SYM,$(TGT_LD_ENTRY) $(TGT_LD_DRIVERS) \
$(TGT_LD_DEVLIST) obj_config obj_config_$(PLATFORM),\
- -u $(SYM) --defsym check_$(SYM)=$(SYM) ) \
+ -u $(SYMBOL_PREFIX)$(SYM) \
+ --defsym check_$(SYM)=$(SYMBOL_PREFIX)$(SYM) ) \
$(patsubst %,--defsym %,$(TGT_LD_IDS)) \
- -e $(TGT_LD_ENTRY)
+ -e $(SYMBOL_PREFIX)$(TGT_LD_ENTRY)
# Calculate list of debugging versions of objects to be included in
# the target.
@@ -1156,18 +1166,37 @@ BLIB = $(BIN)/blib.a
$(BLIB) : $(BLIB_OBJS) $(BLIB_LIST) $(MAKEDEPS)
$(Q)$(RM) $(BLIB)
$(QM)$(ECHO) " [AR] $@"
- $(Q)$(AR) r $@ $(sort $(BLIB_OBJS))
- $(Q)$(RANLIB) $@
+ $(Q)$(AR) rD $@ $(sort $(BLIB_OBJS))
+ $(Q)$(OBJCOPY) --prefix-symbols=$(SYMBOL_PREFIX) $@
+ $(Q)$(RANLIB) -D $@
blib : $(BLIB)
# Command to generate build ID. Must be unique for each $(BIN)/%.tmp,
# even within the same build run.
#
-BUILD_ID_CMD := perl -e 'printf "0x%08x", int ( rand ( 0xffffffff ) );'
+# The build ID is supposed to be collision-free across all ROMs that
+# might ever end up installed in the same system. It doesn't just
+# disambiguate targets within a single build; it also disambiguates
+# different builds (such as builds for multiple ROMs all built from
+# the same blib.a).
+#
+BUILD_ID_CMD = cat $^ | cksum | awk '{print $$1}'
# Build timestamp
#
+# Used as a means to automatically select the newest version of iPXE
+# if multiple iPXE drivers are loaded concurrently in a UEFI system.
+#
+# It gets rounded down to the nearest minute when used for this
+# purpose.
+#
+ifdef SOURCE_DATE_EPOCH
+BUILD_TIMESTAMP := $(SOURCE_DATE_EPOCH)
+else ifdef GITVERSION
+BUILD_TIMESTAMP := $(shell git log -1 --pretty=%ct)
+else
BUILD_TIMESTAMP := $(shell date +%s)
+endif
# Build version
#
@@ -1180,6 +1209,7 @@ $(BIN)/version.%.o : core/version.c $(MAKEDEPS) $(GIT_INDEX)
-DVERSION_PATCH=$(VERSION_PATCH) \
-DVERSION="\"$(VERSION)\"" \
-c $< -o $@
+ $(Q)$(OBJCOPY) --prefix-symbols=$(SYMBOL_PREFIX) $@
# Build an intermediate object file from the objects required for the
# specified target.
@@ -1187,7 +1217,7 @@ $(BIN)/version.%.o : core/version.c $(MAKEDEPS) $(GIT_INDEX)
$(BIN)/%.tmp : $(BIN)/version.%.o $(BLIB) $(MAKEDEPS) $(LDSCRIPT)
$(QM)$(ECHO) " [LD] $@"
$(Q)$(LD) $(LDFLAGS) -T $(LDSCRIPT) $(TGT_LD_FLAGS) $< $(BLIB) -o $@ \
- --defsym _build_id=`$(BUILD_ID_CMD)` \
+ --defsym _build_id=$(shell $(BUILD_ID_CMD)) \
--defsym _build_timestamp=$(BUILD_TIMESTAMP) \
-Map $(BIN)/$*.tmp.map
$(Q)$(OBJDUMP) -ht $@ | $(PERL) $(SORTOBJDUMP) >> $(BIN)/$*.tmp.map
@@ -1398,7 +1428,7 @@ $(ELF2EFI64) : util/elf2efi.c $(MAKEDEPS)
$(Q)$(HOST_CC) $(HOST_CFLAGS) -idirafter include -DEFI_TARGET64 $< -o $@
CLEANUP += $(ELF2EFI64)
-$(EFIROM) : util/efirom.c $(MAKEDEPS)
+$(EFIROM) : util/efirom.c util/eficompress.c $(MAKEDEPS)
$(QM)$(ECHO) " [HOSTCC] $@"
$(Q)$(HOST_CC) $(HOST_CFLAGS) -idirafter include -o $@ $<
CLEANUP += $(EFIROM)
@@ -1410,15 +1440,6 @@ CLEANUP += $(EFIFATBIN)
###############################################################################
#
-# The ICC fixup utility
-#
-$(ICCFIX) : util/iccfix.c $(MAKEDEPS)
- $(QM)$(ECHO) " [HOSTCC] $@"
- $(Q)$(HOST_CC) $(HOST_CFLAGS) -idirafter include -o $@ $<
-CLEANUP += $(ICCFIX)
-
-###############################################################################
-#
# The error usage information utility
#
$(EINFO) : util/einfo.c $(MAKEDEPS)
@@ -1556,13 +1577,14 @@ hci/keymap/keymap_%.c :
#
ifeq ($(NUM_BINS),0)
-ALLBINS := bin{,-*}
-CLEANUP := $(patsubst $(BIN)/%,$(ALLBINS)/%,$(CLEANUP))
-VERYCLEANUP := $(patsubst $(BIN)/%,$(ALLBINS)/%,$(VERYCLEANUP))
+ALLBINS := bin bin-*
+ALLBIN = $(foreach B,$(ALLBINS),$(patsubst $(BIN)/%,$(B)/%,$(1)))
+CLEANUP := $(foreach C,$(CLEANUP),$(call ALLBIN,$(C)))
+VERYCLEANUP := $(foreach V,$(VERYCLEANUP),$(call ALLBIN,$(V)))
endif
clean :
- $(RM) $(CLEANUP)
+ $(RM) -r $(CLEANUP)
veryclean : clean
$(RM) -r $(VERYCLEANUP)
diff --git a/src/Makefile.linux b/src/Makefile.linux
new file mode 100644
index 000000000..85d9c6438
--- /dev/null
+++ b/src/Makefile.linux
@@ -0,0 +1,51 @@
+# -*- makefile -*- : Force emacs to use Makefile mode
+
+# Prefix all iPXE symbols to avoid collisions with platform libraries
+#
+SYMBOL_PREFIX = _ipxe__
+
+# Enable valgrind
+#
+CFLAGS += -UNVALGRIND
+
+# Use a two-stage link
+#
+LDFLAGS += -r -d
+
+# Source directories
+#
+SRCDIRS += drivers/linux
+SRCDIRS += interface/linux
+NON_AUTO_SRCS += interface/linux/linux_api.c
+
+# Media types
+#
+NON_AUTO_MEDIA = linux
+
+# Compiler flags for building host API wrapper
+#
+LINUX_CFLAGS += -Os -idirafter include -DSYMBOL_PREFIX=$(SYMBOL_PREFIX)
+
+# Check for libslirp
+#
+LIBSLIRP_TEST = $(CC) $(LINUX_CFLAGS) -x c /dev/null -nostartfiles \
+ -include slirp/libslirp.h -lslirp \
+ -o /dev/null >/dev/null 2>&1
+WITH_LIBSLIRP := $(shell $(LIBSLIRP_TEST) && $(ECHO) yes)
+ifneq ($(WITH_LIBSLIRP),)
+LINUX_CFLAGS += -DHAVE_LIBSLIRP
+LINUX_LIBS += -lslirp
+endif
+
+# Host API wrapper
+#
+$(BIN)/linux_api.o : interface/linux/linux_api.c include/ipxe/linux_api.h \
+ include/ipxe/slirp.h $(MAKEDEPS)
+ $(QM)$(ECHO) " [BUILD] $@"
+ $(Q)$(CC) $(LINUX_CFLAGS) $(WORKAROUND_CFLAGS) -o $@ -c $<
+
+# Rule to generate final binary
+#
+$(BIN)/%.linux : $(BIN)/%.linux.tmp $(BIN)/linux_api.o
+ $(QM)$(ECHO) " [FINISH] $@"
+ $(Q)$(CC) $(LINUX_CFLAGS) $(WORKAROUND_CFLAGS) -o $@ $^ $(LINUX_LIBS)
diff --git a/src/arch/arm64/Makefile.efi b/src/arch/arm64/Makefile.efi
index eb04c0e2f..998a64d03 100644
--- a/src/arch/arm64/Makefile.efi
+++ b/src/arch/arm64/Makefile.efi
@@ -1,9 +1,5 @@
# -*- makefile -*- : Force emacs to use Makefile mode
-# Avoid untranslatable relocations
-#
-CFLAGS += -fno-pic
-
# Specify EFI image builder
#
ELF2EFI = $(ELF2EFI64)
diff --git a/src/arch/i386/Makefile b/src/arch/i386/Makefile
index b7c2792d9..e59f05fc8 100644
--- a/src/arch/i386/Makefile
+++ b/src/arch/i386/Makefile
@@ -69,22 +69,6 @@ CFLAGS += -fshort-wchar
#
CFLAGS += -Ui386
-# Some widespread patched versions of gcc include -fPIE -Wl,-pie by
-# default. Note that gcc will exit *successfully* if it fails to
-# recognise an option that starts with "no", so we have to test for
-# output on stderr instead of checking the exit status.
-#
-# Current versions of gcc require -no-pie; older versions require
-# -nopie. We therefore test for both.
-#
-ifeq ($(CCTYPE),gcc)
-PIE_TEST = [ -z "`$(CC) -fno-PIE -no-pie -x c -c /dev/null -o /dev/null 2>&1`" ]
-PIE_FLAGS := $(shell $(PIE_TEST) && $(ECHO) '-fno-PIE -no-pie')
-PIE_TEST2 = [ -z "`$(CC) -fno-PIE -nopie -x c -c /dev/null -o /dev/null 2>&1`" ]
-PIE_FLAGS2 := $(shell $(PIE_TEST2) && $(ECHO) '-fno-PIE -nopie')
-WORKAROUND_CFLAGS += $(PIE_FLAGS) $(PIE_FLAGS2)
-endif
-
# i386-specific directories containing source files
#
SRCDIRS += arch/i386/core
diff --git a/src/arch/i386/Makefile.linux b/src/arch/i386/Makefile.linux
index 46328c83b..fe4229e94 100644
--- a/src/arch/i386/Makefile.linux
+++ b/src/arch/i386/Makefile.linux
@@ -1,6 +1,14 @@
+# -*- makefile -*- : Force emacs to use Makefile mode
+
+# Linker script
+#
LDSCRIPT = arch/i386/scripts/linux.lds
-SRCDIRS += arch/i386/core/linux
+# Compiler flags for building host API wrapper
+#
+LINUX_CFLAGS += -m32
+# Include generic Linux Makefile
+#
MAKEDEPS += arch/x86/Makefile.linux
include arch/x86/Makefile.linux
diff --git a/src/arch/i386/core/linux/linux_syscall.S b/src/arch/i386/core/linux/linux_syscall.S
deleted file mode 100644
index 38a3e74bd..000000000
--- a/src/arch/i386/core/linux/linux_syscall.S
+++ /dev/null
@@ -1,45 +0,0 @@
-
- .section ".data"
- .globl linux_errno
-
-linux_errno: .int 0
-
- .section ".text"
- .code32
- .globl linux_syscall
- .type linux_syscall, @function
-
-linux_syscall:
- /* Save registers */
- pushl %ebx
- pushl %esi
- pushl %edi
- pushl %ebp
-
- movl 20(%esp), %eax // C arg1 -> syscall number
- movl 24(%esp), %ebx // C arg2 -> syscall arg1
- movl 28(%esp), %ecx // C arg3 -> syscall arg2
- movl 32(%esp), %edx // C arg4 -> syscall arg3
- movl 36(%esp), %esi // C arg5 -> syscall arg4
- movl 40(%esp), %edi // C arg6 -> syscall arg5
- movl 44(%esp), %ebp // C arg7 -> syscall arg6
-
- int $0x80
-
- /* Restore registers */
- popl %ebp
- popl %edi
- popl %esi
- popl %ebx
-
- cmpl $-4095, %eax
- jae 1f
- ret
-
-1:
- negl %eax
- movl %eax, linux_errno
- movl $-1, %eax
- ret
-
- .size linux_syscall, . - linux_syscall
diff --git a/src/arch/i386/core/linux/linuxprefix.S b/src/arch/i386/core/linux/linuxprefix.S
deleted file mode 100644
index 398d3cb21..000000000
--- a/src/arch/i386/core/linux/linuxprefix.S
+++ /dev/null
@@ -1,28 +0,0 @@
-#include <linux/unistd.h>
-
- .section ".text"
- .code32
- .globl _linux_start
- .type _linux_start, @function
-
-_linux_start:
- xorl %ebp, %ebp
-
- popl %esi // save argc
- movl %esp, %edi // save argv
-
- andl $~15, %esp // 16-byte align the stack
-
- pushl %edi // argv -> C arg2
- pushl %esi // argc -> C arg1
-
- call save_args
-
- /* Our main doesn't use any arguments */
- call main
-
- movl %eax, %ebx // rc -> syscall arg1
- movl $__NR_exit, %eax
- int $0x80
-
- .size _linux_start, . - _linux_start
diff --git a/src/arch/i386/include/bits/compiler.h b/src/arch/i386/include/bits/compiler.h
index 7c4a09396..87201135f 100644
--- a/src/arch/i386/include/bits/compiler.h
+++ b/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/src/arch/i386/include/bits/linux_api.h b/src/arch/i386/include/bits/linux_api.h
deleted file mode 100644
index dc6e7416e..000000000
--- a/src/arch/i386/include/bits/linux_api.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef _I386_LINUX_API_H
-#define _I386_LINUX_API_H
-
-#define __SYSCALL_mmap __NR_mmap2
-
-#endif /* _I386_LINUX_API_H */
diff --git a/src/arch/x86/Makefile.linux b/src/arch/x86/Makefile.linux
index 1faf84753..b60065567 100644
--- a/src/arch/x86/Makefile.linux
+++ b/src/arch/x86/Makefile.linux
@@ -1,13 +1,10 @@
-MEDIA = linux
-
-# enable valgrind
-CFLAGS += -UNVALGRIND
+# -*- makefile -*- : Force emacs to use Makefile mode
+# Include x86 Linux headers
+#
INCDIRS += arch/x86/include/linux
-SRCDIRS += interface/linux
-SRCDIRS += drivers/linux
-SRCDIRS += arch/x86/core/linux
-$(BIN)/%.linux : $(BIN)/%.linux.tmp
- $(QM)$(ECHO) " [FINISH] $@"
- $(Q)$(CP) $< $@
+# Include generic Linux Makefile
+#
+MAKEDEPS += Makefile.linux
+include Makefile.linux
diff --git a/src/arch/x86/Makefile.pcbios b/src/arch/x86/Makefile.pcbios
index c44eefc1f..ed8d554a7 100644
--- a/src/arch/x86/Makefile.pcbios
+++ b/src/arch/x86/Makefile.pcbios
@@ -4,18 +4,15 @@
#
SRCDIRS += arch/x86/drivers/net
-# The i386 linker script
+# The linker scripts
#
LDSCRIPT = arch/x86/scripts/pcbios.lds
+LDSCRIPT_PREFIX = arch/x86/scripts/prefixonly.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
@@ -57,46 +54,11 @@ 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
+# ISO or FAT filesystem images
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 $@ $<
+$(BIN)/%.iso $(BIN)/%.sdsk: $(BIN)/%.lkrn util/genfsimg
+ $(QM)$(ECHO) " [GENFSIMG] $@"
+ $(Q)util/genfsimg -o $@ $<
# rule to write disk images to /dev/fd0
NON_AUTO_MEDIA += fd0
@@ -108,12 +70,12 @@ NON_AUTO_MEDIA += fd0
# Special target for building Master Boot Record binary
$(BIN)/mbr.tmp : $(BIN)/mbr.o
$(QM)$(ECHO) " [LD] $@"
- $(Q)$(LD) $(LDFLAGS) -o $@ -e mbr $<
+ $(Q)$(LD) $(LDFLAGS) -T $(LDSCRIPT_PREFIX) -o $@ -e mbr $<
# rule to make a USB disk image
$(BIN)/usbdisk.tmp : $(BIN)/usbdisk.o
$(QM)$(ECHO) " [LD] $@"
- $(Q)$(LD) $(LDFLAGS) -o $@ -e mbr $<
+ $(Q)$(LD) $(LDFLAGS) -T $(LDSCRIPT_PREFIX) -o $@ -e mbr $<
NON_AUTO_MEDIA += usb
%usb: $(BIN)/usbdisk.bin %hd
diff --git a/src/arch/x86/core/linux/linux_api.c b/src/arch/x86/core/linux/linux_api.c
deleted file mode 100644
index 17b1f3fd4..000000000
--- a/src/arch/x86/core/linux/linux_api.c
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * Copyright (C) 2010 Piotr Jaroszyński <p.jaroszynski@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 St, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-FILE_LICENCE ( GPL2_OR_LATER );
-
-/** @file
- *
- * Implementation of most of the linux API.
- */
-
-#include <linux_api.h>
-
-#include <stdarg.h>
-#include <asm/unistd.h>
-#include <string.h>
-
-int linux_open ( const char *pathname, int flags ) {
- return linux_syscall ( __NR_open, pathname, flags );
-}
-
-int linux_close ( int fd ) {
- return linux_syscall ( __NR_close, fd );
-}
-
-off_t linux_lseek ( int fd, off_t offset, int whence ) {
- return linux_syscall ( __NR_lseek, fd, offset, whence );
-}
-
-__kernel_ssize_t linux_read ( int fd, void *buf, __kernel_size_t count ) {
- return linux_syscall ( __NR_read, fd, buf, count );
-}
-
-__kernel_ssize_t linux_write ( int fd, const void *buf,
- __kernel_size_t count ) {
- return linux_syscall ( __NR_write, fd, buf, count );
-}
-
-int linux_fcntl ( int fd, int cmd, ... ) {
- long arg;
- va_list list;
-
- va_start ( list, cmd );
- arg = va_arg ( list, long );
- va_end ( list );
-
- return linux_syscall ( __NR_fcntl, fd, cmd, arg );
-}
-
-int linux_ioctl ( int fd, int request, ... ) {
- void *arg;
- va_list list;
-
- va_start ( list, request );
- arg = va_arg ( list, void * );
- va_end ( list );
-
- return linux_syscall ( __NR_ioctl, fd, request, arg );
-}
-
-int linux_poll ( struct pollfd *fds, nfds_t nfds, int timeout ) {
- return linux_syscall ( __NR_poll, fds, nfds, timeout );
-}
-
-int linux_nanosleep ( const struct timespec *req, struct timespec *rem ) {
- return linux_syscall ( __NR_nanosleep, req, rem );
-}
-
-int linux_usleep ( useconds_t usec ) {
- struct timespec ts = {
- .tv_sec = ( ( long ) ( usec / 1000000 ) ),
- .tv_nsec = ( ( long ) ( usec % 1000000 ) * 1000UL ),
- };
-
- return linux_nanosleep ( &ts, NULL );
-}
-
-int linux_gettimeofday ( struct timeval *tv, struct timezone *tz ) {
- return linux_syscall ( __NR_gettimeofday, tv, tz );
-}
-
-void * linux_mmap ( void *addr, __kernel_size_t length, int prot, int flags,
- int fd, __kernel_off_t offset ) {
- return ( void * ) linux_syscall ( __SYSCALL_mmap, addr, length, prot,
- flags, fd, offset );
-}
-
-void * linux_mremap ( void *old_address, __kernel_size_t old_size,
- __kernel_size_t new_size, int flags ) {
- return ( void * ) linux_syscall ( __NR_mremap, old_address, old_size,
- new_size, flags );
-}
-
-int linux_munmap ( void *addr, __kernel_size_t length ) {
- return linux_syscall ( __NR_munmap, addr, length );
-}
-
-int linux_socket ( int domain, int type_, int protocol ) {
-#ifdef __NR_socket
- return linux_syscall ( __NR_socket, domain, type_, protocol );
-#else
-#ifndef SOCKOP_socket
-# define SOCKOP_socket 1
-#endif
- unsigned long sc_args[] = { domain, type_, protocol };
- return linux_syscall ( __NR_socketcall, SOCKOP_socket, sc_args );
-#endif
-}
-
-int linux_bind ( int fd, const struct sockaddr *addr, socklen_t addrlen ) {
-#ifdef __NR_bind
- return linux_syscall ( __NR_bind, fd, addr, addrlen );
-#else
-#ifndef SOCKOP_bind
-# define SOCKOP_bind 2
-#endif
- unsigned long sc_args[] = { fd, (unsigned long)addr, addrlen };
- return linux_syscall ( __NR_socketcall, SOCKOP_bind, sc_args );
-#endif
-}
-
-ssize_t linux_sendto ( int fd, const void *buf, size_t len, int flags,
- const struct sockaddr *daddr, socklen_t addrlen ) {
-#ifdef __NR_sendto
- return linux_syscall ( __NR_sendto, fd, buf, len, flags,
- daddr, addrlen );
-#else
-#ifndef SOCKOP_sendto
-# define SOCKOP_sendto 11
-#endif
- unsigned long sc_args[] = { fd, (unsigned long)buf, len,
- flags, (unsigned long)daddr, addrlen };
- return linux_syscall ( __NR_socketcall, SOCKOP_sendto, sc_args );
-#endif
-}
diff --git a/src/arch/x86/core/linux/linux_strerror.c b/src/arch/x86/core/linux/linux_strerror.c
deleted file mode 100644
index 24c9b7738..000000000
--- a/src/arch/x86/core/linux/linux_strerror.c
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * Copyright (C) 2010 Piotr Jaroszyński <p.jaroszynski@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 St, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-FILE_LICENCE(GPL2_OR_LATER);
-
-/** @file
- *
- * linux_strerror implementation
- */
-
-#include <linux_api.h>
-#include <stdio.h>
-
-/** Error names from glibc */
-static const char *errors[] = {
- "Success",
- "Operation not permitted",
- "No such file or directory",
- "No such process",
- "Interrupted system call",
- "Input/output error",
- "No such device or address",
- "Argument list too long",
- "Exec format error",
- "Bad file descriptor",
- "No child processes",
- "Resource temporarily unavailable",
- "Cannot allocate memory",
- "Permission denied",
- "Bad address",
- "Block device required",
- "Device or resource busy",
- "File exists",
- "Invalid cross-device link",
- "No such device",
- "Not a directory",
- "Is a directory",
- "Invalid argument",
- "Too many open files in system",
- "Too many open files",
- "Inappropriate ioctl for device",
- "Text file busy",
- "File too large",
- "No space left on device",
- "Illegal seek",
- "Read-only file system",
- "Too many links",
- "Broken pipe",
- "Numerical argument out of domain",
- "Numerical result out of range",
- "Resource deadlock avoided",
- "File name too long",
- "No locks available",
- "Function not implemented",
- "Directory not empty",
- "Too many levels of symbolic links",
- "",
- "No message of desired type",
- "Identifier removed",
- "Channel number out of range",
- "Level 2 not synchronized",
- "Level 3 halted",
- "Level 3 reset",
- "Link number out of range",
- "Protocol driver not attached",
- "No CSI structure available",
- "Level 2 halted",
- "Invalid exchange",
- "Invalid request descriptor",
- "Exchange full",
- "No anode",
- "Invalid request code",
- "Invalid slot",
- "",
- "Bad font file format",
- "Device not a stream",
- "No data available",
- "Timer expired",
- "Out of streams resources",
- "Machine is not on the network",
- "Package not installed",
- "Object is remote",
- "Link has been severed",
- "Advertise error",
- "Srmount error",
- "Communication error on send",
- "Protocol error",
- "Multihop attempted",
- "RFS specific error",
- "Bad message",
- "Value too large for defined data type",
- "Name not unique on network",
- "File descriptor in bad state",
- "Remote address changed",
- "Can not access a needed shared library",
- "Accessing a corrupted shared library",
- ".lib section in a.out corrupted",
- "Attempting to link in too many shared libraries",
- "Cannot exec a shared library directly",
- "Invalid or incomplete multibyte or wide character",
- "Interrupted system call should be restarted",
- "Streams pipe error",
- "Too many users",
- "Socket operation on non-socket",
- "Destination address required",
- "Message too long",
- "Protocol wrong type for socket",
- "Protocol not available",
- "Protocol not supported",
- "Socket type not supported",
- "Operation not supported",
- "Protocol family not supported",
- "Address family not supported by protocol",
- "Address already in use",
- "Cannot assign requested address",
- "Network is down",
- "Network is unreachable",
- "Network dropped connection on reset",
- "Software caused connection abort",
- "Connection reset by peer",
- "No buffer space available",
- "Transport endpoint is already connected",
- "Transport endpoint is not connected",
- "Cannot send after transport endpoint shutdown",
- "Too many references: cannot splice",
- "Connection timed out",
- "Connection refused",
- "Host is down",
- "No route to host",
- "Operation already in progress",
- "Operation now in progress",
- "Stale NFS file handle",
- "Structure needs cleaning",
- "Not a XENIX named type file",
- "No XENIX semaphores available",
- "Is a named type file",
- "Remote I/O error",
- "Disk quota exceeded",
- "No medium found",
- "Wrong medium type",
-};
-
-const char *linux_strerror(int errnum)
-{
- static char errbuf[64];
- static int errors_size = sizeof(errors) / sizeof(*errors);
-
- if (errnum >= errors_size || errnum < 0) {
- snprintf(errbuf, sizeof(errbuf), "Error %#08x", errnum);
- return errbuf;
- } else {
- return errors[errnum];
- }
-}
diff --git a/src/arch/x86/core/pcidirect.c b/src/arch/x86/core/pcidirect.c
index 0d09be84b..9b8226fea 100644
--- a/src/arch/x86/core/pcidirect.c
+++ b/src/arch/x86/core/pcidirect.c
@@ -52,3 +52,4 @@ PROVIDE_PCIAPI_INLINE ( direct, pci_read_config_dword );
PROVIDE_PCIAPI_INLINE ( direct, pci_write_config_byte );
PROVIDE_PCIAPI_INLINE ( direct, pci_write_config_word );
PROVIDE_PCIAPI_INLINE ( direct, pci_write_config_dword );
+PROVIDE_PCIAPI_INLINE ( direct, pci_ioremap );
diff --git a/src/arch/x86/core/runtime.c b/src/arch/x86/core/runtime.c
index f96b23af4..02072b5bf 100644
--- a/src/arch/x86/core/runtime.c
+++ b/src/arch/x86/core/runtime.c
@@ -38,7 +38,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <ipxe/init.h>
#include <ipxe/image.h>
#include <ipxe/script.h>
-#include <ipxe/umalloc.h>
#include <realmode.h>
/** Command line physical address
@@ -180,7 +179,6 @@ static int cmdline_init ( void ) {
*/
static int initrd_init ( void ) {
struct image *image;
- int rc;
/* Do nothing if no initrd was specified */
if ( ! initrd_phys ) {
@@ -194,53 +192,18 @@ static int initrd_init ( void ) {
DBGC ( colour, "RUNTIME found initrd at [%x,%x)\n",
initrd_phys, ( initrd_phys + initrd_len ) );
- /* Allocate image */
- image = alloc_image ( NULL );
+ /* Create initrd image */
+ image = image_memory ( "<INITRD>", phys_to_user ( initrd_phys ),
+ initrd_len );
if ( ! image ) {
- DBGC ( colour, "RUNTIME could not allocate image for "
- "initrd\n" );
- rc = -ENOMEM;
- goto err_alloc_image;
- }
- if ( ( rc = image_set_name ( image, "<INITRD>" ) ) != 0 ) {
- DBGC ( colour, "RUNTIME could not set image name: %s\n",
- strerror ( rc ) );
- goto err_set_name;
+ DBGC ( colour, "RUNTIME could not create initrd image\n" );
+ return -ENOMEM;
}
- /* Allocate and copy initrd content */
- image->data = umalloc ( initrd_len );
- if ( ! image->data ) {
- DBGC ( colour, "RUNTIME could not allocate %d bytes for "
- "initrd\n", initrd_len );
- rc = -ENOMEM;
- goto err_umalloc;
- }
- image->len = initrd_len;
- memcpy_user ( image->data, 0, phys_to_user ( initrd_phys ), 0,
- initrd_len );
-
/* Mark initrd as consumed */
initrd_phys = 0;
- /* Register image */
- if ( ( rc = register_image ( image ) ) != 0 ) {
- DBGC ( colour, "RUNTIME could not register initrd: %s\n",
- strerror ( rc ) );
- goto err_register_image;
- }
-
- /* Drop our reference to the image */
- image_put ( image );
-
return 0;
-
- err_register_image:
- err_umalloc:
- err_set_name:
- image_put ( image );
- err_alloc_image:
- return rc;
}
/**
diff --git a/src/arch/x86/core/stack.S b/src/arch/x86/core/stack.S
index 995c397ca..baa19ff84 100644
--- a/src/arch/x86/core/stack.S
+++ b/src/arch/x86/core/stack.S
@@ -13,7 +13,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
****************************************************************************
*/
.section ".stack", "aw", @nobits
- .align 8
+ .balign 8
.globl _stack
_stack:
.space STACK_SIZE
diff --git a/src/arch/x86/core/stack16.S b/src/arch/x86/core/stack16.S
index 4bc6f081a..ad67e4f2d 100644
--- a/src/arch/x86/core/stack16.S
+++ b/src/arch/x86/core/stack16.S
@@ -7,7 +7,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
****************************************************************************
*/
.section ".stack16", "aw", @nobits
- .align 8
+ .balign 8
.globl _stack16
_stack16:
.space 4096
diff --git a/src/arch/x86/drivers/hyperv/hyperv.c b/src/arch/x86/drivers/hyperv/hyperv.c
index 1903d1db2..9d3a42da0 100644
--- a/src/arch/x86/drivers/hyperv/hyperv.c
+++ b/src/arch/x86/drivers/hyperv/hyperv.c
@@ -83,7 +83,7 @@ hv_alloc_pages ( struct hv_hypervisor *hv, ... ) {
/* Allocate and zero pages */
va_start ( args, hv );
for ( i = 0 ; ( ( page = va_arg ( args, void ** ) ) != NULL ); i++ ) {
- *page = malloc_dma ( PAGE_SIZE, PAGE_SIZE );
+ *page = malloc_phys ( PAGE_SIZE, PAGE_SIZE );
if ( ! *page )
goto err_alloc;
memset ( *page, 0, PAGE_SIZE );
@@ -97,7 +97,7 @@ hv_alloc_pages ( struct hv_hypervisor *hv, ... ) {
va_start ( args, hv );
for ( ; i >= 0 ; i-- ) {
page = va_arg ( args, void ** );
- free_dma ( *page, PAGE_SIZE );
+ free_phys ( *page, PAGE_SIZE );
}
va_end ( args );
return -ENOMEM;
@@ -116,7 +116,7 @@ hv_free_pages ( struct hv_hypervisor *hv, ... ) {
va_start ( args, hv );
while ( ( page = va_arg ( args, void * ) ) != NULL )
- free_dma ( page, PAGE_SIZE );
+ free_phys ( page, PAGE_SIZE );
va_end ( args );
}
@@ -131,8 +131,8 @@ static int hv_alloc_message ( struct hv_hypervisor *hv ) {
/* Allocate buffer. Must be aligned to at least 8 bytes and
* must not cross a page boundary, so align on its own size.
*/
- hv->message = malloc_dma ( sizeof ( *hv->message ),
- sizeof ( *hv->message ) );
+ hv->message = malloc_phys ( sizeof ( *hv->message ),
+ sizeof ( *hv->message ) );
if ( ! hv->message )
return -ENOMEM;
@@ -147,7 +147,7 @@ static int hv_alloc_message ( struct hv_hypervisor *hv ) {
static void hv_free_message ( struct hv_hypervisor *hv ) {
/* Free buffer */
- free_dma ( hv->message, sizeof ( *hv->message ) );
+ free_phys ( hv->message, sizeof ( *hv->message ) );
}
/**
diff --git a/src/arch/x86/drivers/xen/hvm.c b/src/arch/x86/drivers/xen/hvm.c
index 57196f555..b77cdd14c 100644
--- a/src/arch/x86/drivers/xen/hvm.c
+++ b/src/arch/x86/drivers/xen/hvm.c
@@ -106,7 +106,7 @@ static int hvm_map_hypercall ( struct hvm_device *hvm ) {
/* Allocate pages */
hvm->hypercall_len = ( pages * PAGE_SIZE );
- hvm->xen.hypercall = malloc_dma ( hvm->hypercall_len, PAGE_SIZE );
+ hvm->xen.hypercall = malloc_phys ( hvm->hypercall_len, PAGE_SIZE );
if ( ! hvm->xen.hypercall ) {
DBGC ( hvm, "HVM could not allocate %d hypercall page(s)\n",
pages );
@@ -141,7 +141,7 @@ static int hvm_map_hypercall ( struct hvm_device *hvm ) {
static void hvm_unmap_hypercall ( struct hvm_device *hvm ) {
/* Free pages */
- free_dma ( hvm->xen.hypercall, hvm->hypercall_len );
+ free_phys ( hvm->xen.hypercall, hvm->hypercall_len );
}
/**
@@ -175,7 +175,7 @@ static void * hvm_ioremap ( struct hvm_device *hvm, unsigned int space,
}
/* Map this space */
- mmio = ioremap ( ( hvm->mmio + hvm->mmio_offset ), len );
+ mmio = pci_ioremap ( hvm->pci, ( hvm->mmio + hvm->mmio_offset ), len );
if ( ! mmio ) {
DBGC ( hvm, "HVM could not map MMIO space [%08lx,%08lx)\n",
( hvm->mmio + hvm->mmio_offset ),
@@ -371,7 +371,8 @@ static int hvm_map_xenstore ( struct hvm_device *hvm ) {
xenstore_phys = ( xenstore_pfn * PAGE_SIZE );
/* Map XenStore */
- hvm->xen.store.intf = ioremap ( xenstore_phys, PAGE_SIZE );
+ hvm->xen.store.intf = pci_ioremap ( hvm->pci, xenstore_phys,
+ PAGE_SIZE );
if ( ! hvm->xen.store.intf ) {
DBGC ( hvm, "HVM could not map XenStore at [%08lx,%08lx)\n",
xenstore_phys, ( xenstore_phys + PAGE_SIZE ) );
@@ -420,6 +421,7 @@ static int hvm_probe ( struct pci_device *pci ) {
rc = -ENOMEM;
goto err_alloc;
}
+ hvm->pci = pci;
hvm->mmio = pci_bar_start ( pci, HVM_MMIO_BAR );
hvm->mmio_len = pci_bar_size ( pci, HVM_MMIO_BAR );
DBGC2 ( hvm, "HVM has MMIO space [%08lx,%08lx)\n",
diff --git a/src/arch/x86/drivers/xen/hvm.h b/src/arch/x86/drivers/xen/hvm.h
index 72ed94f6d..88e490815 100644
--- a/src/arch/x86/drivers/xen/hvm.h
+++ b/src/arch/x86/drivers/xen/hvm.h
@@ -39,6 +39,8 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
struct hvm_device {
/** Xen hypervisor */
struct xen_hypervisor xen;
+ /** PCI device */
+ struct pci_device *pci;
/** CPUID base */
uint32_t cpuid_base;
/** Length of hypercall table */
diff --git a/src/arch/x86/image/initrd.c b/src/arch/x86/image/initrd.c
index 8f6366d3d..49b959a91 100644
--- a/src/arch/x86/image/initrd.c
+++ b/src/arch/x86/image/initrd.c
@@ -175,18 +175,18 @@ static int initrd_swap_any ( userptr_t free, size_t free_len ) {
/* Search for adjacent image */
for_each_image ( high ) {
- /* If we have found the adjacent image, swap and exit */
- if ( high->data == adjacent ) {
- initrd_swap ( low, high, free, free_len );
- return 1;
- }
-
/* Stop search if all remaining potential
* adjacent images are already in the correct
* order.
*/
if ( high == low )
break;
+
+ /* If we have found the adjacent image, swap and exit */
+ if ( high->data == adjacent ) {
+ initrd_swap ( low, high, free, free_len );
+ return 1;
+ }
}
}
diff --git a/src/arch/x86/include/bits/bitops.h b/src/arch/x86/include/bits/bitops.h
index 17dcf1024..f697b8c8f 100644
--- a/src/arch/x86/include/bits/bitops.h
+++ b/src/arch/x86/include/bits/bitops.h
@@ -29,7 +29,7 @@ set_bit ( unsigned int bit, volatile void *bits ) {
uint8_t byte[ ( bit / 8 ) + 1 ];
} *bytes = bits;
- __asm__ __volatile__ ( "lock bts %1, %0"
+ __asm__ __volatile__ ( "lock btsl %k1, %0"
: "+m" ( *bytes ) : "Ir" ( bit ) );
}
@@ -45,7 +45,7 @@ clear_bit ( unsigned int bit, volatile void *bits ) {
uint8_t byte[ ( bit / 8 ) + 1 ];
} *bytes = bits;
- __asm__ __volatile__ ( "lock btr %1, %0"
+ __asm__ __volatile__ ( "lock btrl %k1, %0"
: "+m" ( *bytes ) : "Ir" ( bit ) );
}
@@ -63,7 +63,7 @@ test_and_set_bit ( unsigned int bit, volatile void *bits ) {
} *bytes = bits;
int old;
- __asm__ __volatile__ ( "lock bts %2, %0\n\t"
+ __asm__ __volatile__ ( "lock btsl %k2, %0\n\t"
"sbb %1, %1\n\t"
: "+m" ( *bytes ), "=r" ( old )
: "Ir" ( bit ) );
@@ -84,7 +84,7 @@ test_and_clear_bit ( unsigned int bit, volatile void *bits ) {
} *bytes = bits;
int old;
- __asm__ __volatile__ ( "lock btr %2, %0\n\t"
+ __asm__ __volatile__ ( "lock btrl %k2, %0\n\t"
"sbb %1, %1\n\t"
: "+m" ( *bytes ), "=r" ( old )
: "Ir" ( bit ) );
diff --git a/src/arch/x86/include/bits/linux_api_platform.h b/src/arch/x86/include/bits/linux_api_platform.h
deleted file mode 100644
index 4a9ced5e2..000000000
--- a/src/arch/x86/include/bits/linux_api_platform.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef _LINUX_API_PLATFORM_H
-#define _LINUX_API_PLATFORM_H
-
-extern int linux_errno;
-
-#endif /* _LINUX_API_PLATFORM_H */
diff --git a/src/arch/x86/include/ipxe/cpuid.h b/src/arch/x86/include/ipxe/cpuid.h
index 0ae572da4..b5403bd9d 100644
--- a/src/arch/x86/include/ipxe/cpuid.h
+++ b/src/arch/x86/include/ipxe/cpuid.h
@@ -42,6 +42,9 @@ struct x86_features {
/** Hypervisor is present */
#define CPUID_FEATURES_INTEL_ECX_HYPERVISOR 0x80000000UL
+/** FXSAVE and FXRSTOR are supported */
+#define CPUID_FEATURES_INTEL_EDX_FXSR 0x01000000UL
+
/** Get largest extended function */
#define CPUID_AMD_MAX_FN 0x80000000UL
diff --git a/src/arch/x86/include/ipxe/pcibios.h b/src/arch/x86/include/ipxe/pcibios.h
index 7e1bcd814..bae4eede1 100644
--- a/src/arch/x86/include/ipxe/pcibios.h
+++ b/src/arch/x86/include/ipxe/pcibios.h
@@ -132,4 +132,17 @@ PCIAPI_INLINE ( pcbios, pci_write_config_dword ) ( struct pci_device *pci,
return pcibios_write ( pci, PCIBIOS_WRITE_CONFIG_DWORD | where, value);
}
+/**
+ * Map PCI bus address as an I/O address
+ *
+ * @v bus_addr PCI bus address
+ * @v len Length of region
+ * @ret io_addr I/O address, or NULL on error
+ */
+static inline __always_inline void *
+PCIAPI_INLINE ( pcbios, pci_ioremap ) ( struct pci_device *pci __unused,
+ unsigned long bus_addr, size_t len ) {
+ return ioremap ( bus_addr, len );
+}
+
#endif /* _IPXE_PCIBIOS_H */
diff --git a/src/arch/x86/include/ipxe/pcidirect.h b/src/arch/x86/include/ipxe/pcidirect.h
index d924f2f20..9570fd7d6 100644
--- a/src/arch/x86/include/ipxe/pcidirect.h
+++ b/src/arch/x86/include/ipxe/pcidirect.h
@@ -138,4 +138,17 @@ PCIAPI_INLINE ( direct, pci_write_config_dword ) ( struct pci_device *pci,
return 0;
}
+/**
+ * Map PCI bus address as an I/O address
+ *
+ * @v bus_addr PCI bus address
+ * @v len Length of region
+ * @ret io_addr I/O address, or NULL on error
+ */
+static inline __always_inline void *
+PCIAPI_INLINE ( direct, pci_ioremap ) ( struct pci_device *pci __unused,
+ unsigned long bus_addr, size_t len ) {
+ return ioremap ( bus_addr, len );
+}
+
#endif /* _PCIDIRECT_H */
diff --git a/src/arch/x86/include/ipxe/rsdp.h b/src/arch/x86/include/ipxe/rsdp.h
index 7e32c0011..14afcd774 100644
--- a/src/arch/x86/include/ipxe/rsdp.h
+++ b/src/arch/x86/include/ipxe/rsdp.h
@@ -15,4 +15,17 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#define ACPI_PREFIX_rsdp __rsdp_
#endif
+/**
+ * Locate ACPI table
+ *
+ * @v signature Requested table signature
+ * @v index Requested index of table with this signature
+ * @ret table Table, or UNULL if not found
+ */
+static inline __attribute__ (( always_inline )) userptr_t
+ACPI_INLINE ( rsdp, acpi_find ) ( uint32_t signature, unsigned int index ) {
+
+ return acpi_find_via_rsdt ( signature, index );
+}
+
#endif /* _IPXE_RSDP_H */
diff --git a/src/arch/x86/interface/pcbios/bios_cachedhcp.c b/src/arch/x86/interface/pcbios/bios_cachedhcp.c
new file mode 100644
index 000000000..3d38699f7
--- /dev/null
+++ b/src/arch/x86/interface/pcbios/bios_cachedhcp.c
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2013 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 <ipxe/init.h>
+#include <ipxe/cachedhcp.h>
+#include <realmode.h>
+#include <pxe_api.h>
+
+/** @file
+ *
+ * Cached DHCP packet
+ *
+ */
+
+/** Cached DHCPACK physical address
+ *
+ * This can be set by the prefix.
+ */
+uint32_t __bss16 ( cached_dhcpack_phys );
+#define cached_dhcpack_phys __use_data16 ( cached_dhcpack_phys )
+
+/** Colour for debug messages */
+#define colour &cached_dhcpack_phys
+
+/**
+ * Cached DHCPACK initialisation function
+ *
+ */
+static void cachedhcp_init ( void ) {
+ int rc;
+
+ /* Do nothing if no cached DHCPACK is present */
+ if ( ! cached_dhcpack_phys ) {
+ DBGC ( colour, "CACHEDHCP found no cached DHCPACK\n" );
+ return;
+ }
+
+ /* Record cached DHCPACK */
+ if ( ( rc = cachedhcp_record ( phys_to_user ( cached_dhcpack_phys ),
+ sizeof ( BOOTPLAYER_t ) ) ) != 0 ) {
+ DBGC ( colour, "CACHEDHCP could not record DHCPACK: %s\n",
+ strerror ( rc ) );
+ return;
+ }
+
+ /* Mark as consumed */
+ cached_dhcpack_phys = 0;
+}
+
+/** Cached DHCPACK initialisation function */
+struct init_fn cachedhcp_init_fn __init_fn ( INIT_NORMAL ) = {
+ .initialise = cachedhcp_init,
+};
diff --git a/src/arch/x86/interface/pcbios/bios_console.c b/src/arch/x86/interface/pcbios/bios_console.c
index 52a02fba5..80ebf330e 100644
--- a/src/arch/x86/interface/pcbios/bios_console.c
+++ b/src/arch/x86/interface/pcbios/bios_console.c
@@ -443,7 +443,7 @@ struct console_driver bios_console __console_driver = {
*
* @v ix86 Registers as passed to INT 16
*/
-static __asmcall void bios_inject ( struct i386_all_regs *ix86 ) {
+static __asmcall __used void bios_inject ( struct i386_all_regs *ix86 ) {
unsigned int discard_a;
unsigned int scancode;
unsigned int i;
diff --git a/src/arch/x86/interface/pcbios/e820mangler.S b/src/arch/x86/interface/pcbios/e820mangler.S
index d5d97b482..296a6488b 100644
--- a/src/arch/x86/interface/pcbios/e820mangler.S
+++ b/src/arch/x86/interface/pcbios/e820mangler.S
@@ -67,7 +67,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
****************************************************************************
*/
.section ".data16", "aw", @progbits
- .align 16
+ .balign 16
.globl hidemem_base
.globl hidemem_umalloc
.globl hidemem_textdata
diff --git a/src/arch/x86/interface/pcbios/int13.c b/src/arch/x86/interface/pcbios/int13.c
index ca789a0d1..30530e197 100644
--- a/src/arch/x86/interface/pcbios/int13.c
+++ b/src/arch/x86/interface/pcbios/int13.c
@@ -1064,7 +1064,7 @@ static int int13_cdrom_read_boot_catalog ( struct san_device *sandev,
* INT 13 handler
*
*/
-static __asmcall void int13 ( struct i386_all_regs *ix86 ) {
+static __asmcall __used void int13 ( struct i386_all_regs *ix86 ) {
int command = ix86->regs.ah;
unsigned int bios_drive = ix86->regs.dl;
struct san_device *sandev;
diff --git a/src/arch/x86/interface/pcbios/pcibios.c b/src/arch/x86/interface/pcbios/pcibios.c
index 07ac0c18d..bf812f77f 100644
--- a/src/arch/x86/interface/pcbios/pcibios.c
+++ b/src/arch/x86/interface/pcbios/pcibios.c
@@ -121,3 +121,4 @@ PROVIDE_PCIAPI_INLINE ( pcbios, pci_read_config_dword );
PROVIDE_PCIAPI_INLINE ( pcbios, pci_write_config_byte );
PROVIDE_PCIAPI_INLINE ( pcbios, pci_write_config_word );
PROVIDE_PCIAPI_INLINE ( pcbios, pci_write_config_dword );
+PROVIDE_PCIAPI_INLINE ( pcbios, pci_ioremap );
diff --git a/src/arch/x86/interface/pcbios/rsdp.c b/src/arch/x86/interface/pcbios/rsdp.c
index 8da0b5588..3c67b7525 100644
--- a/src/arch/x86/interface/pcbios/rsdp.c
+++ b/src/arch/x86/interface/pcbios/rsdp.c
@@ -123,3 +123,4 @@ static userptr_t rsdp_find_rsdt ( void ) {
}
PROVIDE_ACPI ( rsdp, acpi_find_rsdt, rsdp_find_rsdt );
+PROVIDE_ACPI_INLINE ( rsdp, acpi_find );
diff --git a/src/arch/x86/interface/pxe/pxe_entry.S b/src/arch/x86/interface/pxe/pxe_entry.S
index 663aa842e..3a5a100e3 100644
--- a/src/arch/x86/interface/pxe/pxe_entry.S
+++ b/src/arch/x86/interface/pxe/pxe_entry.S
@@ -34,7 +34,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
*/
.section ".text16.data", "aw", @progbits
.globl ppxe
- .align 16
+ .balign 16
ppxe:
.ascii "!PXE" /* Signature */
.byte pxe_length /* StructLength */
@@ -72,7 +72,7 @@ undiheader:
*/
.section ".text16.data", "aw", @progbits
.globl pxenv
- .align 16
+ .balign 16
pxenv:
.ascii "PXENV+" /* Signature */
.word 0x0201 /* Version */
diff --git a/src/arch/x86/interface/syslinux/comboot_call.c b/src/arch/x86/interface/syslinux/comboot_call.c
index e70f200e3..dc308dafe 100644
--- a/src/arch/x86/interface/syslinux/comboot_call.c
+++ b/src/arch/x86/interface/syslinux/comboot_call.c
@@ -220,7 +220,7 @@ static int comboot_fetch_kernel ( char *kernel_file, char *cmdline ) {
/**
* Terminate program interrupt handler
*/
-static __asmcall void int20 ( struct i386_all_regs *ix86 __unused ) {
+static __asmcall __used void int20 ( struct i386_all_regs *ix86 __unused ) {
rmlongjmp ( comboot_return, COMBOOT_EXIT );
}
@@ -228,7 +228,7 @@ static __asmcall void int20 ( struct i386_all_regs *ix86 __unused ) {
/**
* DOS-compatible API
*/
-static __asmcall void int21 ( struct i386_all_regs *ix86 ) {
+static __asmcall __used void int21 ( struct i386_all_regs *ix86 ) {
ix86->flags |= CF;
switch ( ix86->regs.ah ) {
@@ -311,7 +311,7 @@ __weak int pxe_api_call_weak ( struct i386_all_regs *ix86 __unused ) {
/**
* SYSLINUX API
*/
-static __asmcall void int22 ( struct i386_all_regs *ix86 ) {
+static __asmcall __used void int22 ( struct i386_all_regs *ix86 ) {
ix86->flags |= CF;
switch ( ix86->regs.ax ) {
diff --git a/src/arch/x86/prefix/exeprefix.S b/src/arch/x86/prefix/exeprefix.S
index c351456e2..0eab8c12a 100644
--- a/src/arch/x86/prefix/exeprefix.S
+++ b/src/arch/x86/prefix/exeprefix.S
@@ -110,7 +110,7 @@ overlay:
/* Overlay number */
.word 0
- .align 16, 0
+ .balign 16, 0
.globl _exe_start
_exe_start:
diff --git a/src/arch/x86/prefix/mromprefix.S b/src/arch/x86/prefix/mromprefix.S
index 2b5c6bf64..d08284d7a 100644
--- a/src/arch/x86/prefix/mromprefix.S
+++ b/src/arch/x86/prefix/mromprefix.S
@@ -492,7 +492,7 @@ mromheader:
.word 0
.size mromheader, . - mromheader
- .align 4
+ .balign 4
mpciheader:
.ascii "PCIR" /* Signature */
.word pci_vendor_id /* Vendor identification */
diff --git a/src/arch/x86/prefix/rawprefix.S b/src/arch/x86/prefix/rawprefix.S
new file mode 100644
index 000000000..4cf5f391e
--- /dev/null
+++ b/src/arch/x86/prefix/rawprefix.S
@@ -0,0 +1,53 @@
+/*
+ * Raw binary prefix
+ *
+ * Assumes that entire image is already loaded as a contiguous block
+ * on a paragraph boundary and entered in real mode.
+ *
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
+
+ .text
+ .arch i386
+ .org 0
+ .code16
+
+#include <librm.h>
+
+ .section ".prefix", "ax", @progbits
+ .globl _raw_start
+_raw_start:
+
+ /* Adjust %cs so that %cs:0000 is the start of the image */
+ movw %cs, %ax
+ call 1f
+1: popw %bx
+ subw $1b, %bx
+ shrw $4, %bx
+ addw %bx, %ax
+ pushw %ax
+ pushw $2f
+ lret
+2:
+ /* Install iPXE */
+ call install
+
+ /* Set up real-mode stack */
+ movw %bx, %ss
+ movw $_estack16, %sp
+
+ /* Jump to .text16 segment */
+ pushw %ax
+ pushw $1f
+ lret
+ .section ".text16", "awx", @progbits
+1:
+ /* Run iPXE */
+ virtcall main
+
+ /* Uninstall iPXE */
+ call uninstall
+
+ /* Boot next device */
+ int $0x18
diff --git a/src/arch/x86/prefix/romprefix.S b/src/arch/x86/prefix/romprefix.S
index 3abef0eaf..a9934a725 100644
--- a/src/arch/x86/prefix/romprefix.S
+++ b/src/arch/x86/prefix/romprefix.S
@@ -88,7 +88,7 @@ checksum:
.previous
.ifeqs BUSTYPE, "PCIR"
- .align 4
+ .balign 4
pciheader:
.ascii "PCIR" /* Signature */
.word pci_vendor_id /* Vendor identification */
@@ -136,7 +136,7 @@ pci_devlist_end:
* BIOSes will scan on 16-byte boundaries rather than using
* the offset stored at 0x1a
*/
- .align 16
+ .balign 16
pnpheader:
.ascii "$PnP" /* Signature */
.byte 0x01 /* Structure revision */
@@ -184,7 +184,7 @@ prodstr_pci_id:
.globl undiheader
.weak undiloader
- .align 4
+ .balign 4
undiheader:
.ascii "UNDI" /* Signature */
.byte undiheader_len /* Length of structure */
@@ -199,7 +199,7 @@ undiheader:
.equ undiheader_len, . - undiheader
.size undiheader, . - undiheader
- .align 4
+ .balign 4
ipxeheader:
.ascii "iPXE" /* Signature */
.byte ipxeheader_len /* Length of structure */
diff --git a/src/arch/x86/prefix/unlzma.S b/src/arch/x86/prefix/unlzma.S
index ce18c756f..956eeb24c 100644
--- a/src/arch/x86/prefix/unlzma.S
+++ b/src/arch/x86/prefix/unlzma.S
@@ -231,7 +231,7 @@ rep_len_dec: .space sizeof__lzma_len_dec
literal: .rept ( ( 1 << LZMA_LC ) * 0x300 )
.word 0
.endr
- .align 4
+ .balign 4
.equ sizeof__lzma_dec, . - lzma_dec
.previous
diff --git a/src/arch/x86/scripts/pcbios.lds b/src/arch/x86/scripts/pcbios.lds
index c9a91c02b..de59adca9 100644
--- a/src/arch/x86/scripts/pcbios.lds
+++ b/src/arch/x86/scripts/pcbios.lds
@@ -58,11 +58,12 @@ SECTIONS {
*(SORT(.pci_devlist.*))
*(.prefix.*)
_mprefix = .;
- } .bss.prefix (NOLOAD) : AT ( _end_lma ) {
+ } .bss.prefix (NOLOAD) : AT ( _bss_prefix_lma ) {
_eprefix = .;
}
_prefix_filesz = ABSOLUTE ( _mprefix ) - ABSOLUTE ( _prefix );
_prefix_memsz = ABSOLUTE ( _eprefix ) - ABSOLUTE ( _prefix );
+ _prefix_padsz = ABSOLUTE ( _eprefix ) - ABSOLUTE ( _mprefix );
/*
* The 16-bit (real-mode) code section
@@ -82,7 +83,7 @@ SECTIONS {
*(.text16)
*(.text16.*)
_mtext16 = .;
- } .bss.text16 (NOLOAD) : AT ( _end_lma ) {
+ } .bss.text16 (NOLOAD) : AT ( _bss_text16_lma ) {
_etext16 = .;
}
_text16_early_filesz = ABSOLUTE ( _etext16_early ) - ABSOLUTE ( _text16 );
@@ -90,6 +91,7 @@ SECTIONS {
_text16_late_filesz = ABSOLUTE ( _mtext16 ) - ABSOLUTE ( _text16_late );
_text16_late_memsz = ABSOLUTE ( _etext16 ) - ABSOLUTE ( _text16_late );
_text16_memsz = ABSOLUTE ( _etext16 ) - ABSOLUTE ( _text16 );
+ _text16_padsz = ABSOLUTE ( _etext16 ) - ABSOLUTE ( _mtext16 );
/*
* The 16-bit (real-mode) data section
@@ -104,7 +106,7 @@ SECTIONS {
*(.data16)
*(.data16.*)
_mdata16 = .;
- } .bss.data16 (NOLOAD) : AT ( _end_lma ) {
+ } .bss.data16 (NOLOAD) : AT ( _bss_data16_lma ) {
*(.bss16)
*(.bss16.*)
*(.stack16)
@@ -114,6 +116,7 @@ SECTIONS {
}
_data16_filesz = ABSOLUTE ( _mdata16 ) - ABSOLUTE ( _data16 );
_data16_memsz = ABSOLUTE ( _edata16 ) - ABSOLUTE ( _data16 );
+ _data16_padsz = ABSOLUTE ( _edata16 ) - ABSOLUTE ( _mdata16 );
/*
* The 32-bit sections
@@ -135,7 +138,7 @@ SECTIONS {
KEEP(*(.provided))
KEEP(*(.provided.*))
_mtextdata = .;
- } .bss.textdata (NOLOAD) : AT ( _end_lma ) {
+ } .bss.textdata (NOLOAD) : AT ( _bss_textdata_lma ) {
*(.bss)
*(.bss.*)
*(COMMON)
@@ -157,6 +160,7 @@ SECTIONS {
}
_textdata_filesz = ABSOLUTE ( _mtextdata ) - ABSOLUTE ( _textdata );
_textdata_memsz = ABSOLUTE ( _etextdata ) - ABSOLUTE ( _textdata );
+ _textdata_padsz = ABSOLUTE ( _etextdata ) - ABSOLUTE ( _mtextdata );
/*
* Payload prefix
@@ -169,11 +173,12 @@ SECTIONS {
KEEP(*(.pprefix))
KEEP(*(.pprefix.*))
_mpprefix = .;
- } .bss.pprefix (NOLOAD) : AT ( _end_lma ) {
+ } .bss.pprefix (NOLOAD) : AT ( _bss_pprefix_lma ) {
_epprefix = .;
}
_pprefix_filesz = ABSOLUTE ( _mpprefix ) - ABSOLUTE ( _pprefix );
_pprefix_memsz = ABSOLUTE ( _epprefix ) - ABSOLUTE ( _pprefix );
+ _pprefix_padsz = ABSOLUTE ( _epprefix ) - ABSOLUTE ( _mpprefix );
/*
* Compressor information block
@@ -185,11 +190,12 @@ SECTIONS {
KEEP(*(.zinfo))
KEEP(*(.zinfo.*))
_mzinfo = .;
- } .bss.zinfo (NOLOAD) : AT ( _end_lma ) {
+ } .bss.zinfo (NOLOAD) : AT ( _bss_zinfo_lma ) {
_ezinfo = .;
}
_zinfo_filesz = ABSOLUTE ( _mzinfo ) - ABSOLUTE ( _zinfo );
_zinfo_memsz = ABSOLUTE ( _ezinfo ) - ABSOLUTE ( _zinfo );
+ _zinfo_padsz = ABSOLUTE ( _ezinfo ) - ABSOLUTE ( _mzinfo );
/*
* Weak symbols that need zero values if not otherwise defined
@@ -235,36 +241,65 @@ SECTIONS {
. = ALIGN ( _max_align );
_prefix_lma = .;
- . += _prefix_filesz;
+ . += ABSOLUTE ( _prefix_filesz );
. = ALIGN ( _max_align );
_text16_early_lma = .;
- . += _text16_early_filesz;
+ . += ABSOLUTE ( _text16_early_filesz );
. = ALIGN ( _max_align );
. = ALIGN ( _payload_align );
_pprefix_lma = .;
- . += _pprefix_filesz;
+ . += ABSOLUTE ( _pprefix_filesz );
. = ALIGN ( _max_align );
_payload_lma = .;
_pprefix_skip = ABSOLUTE ( _payload_lma ) - ABSOLUTE ( _pprefix_lma );
_text16_late_lma = .;
- . += _text16_late_filesz;
+ . += ABSOLUTE ( _text16_late_filesz );
. = ALIGN ( _max_align );
_data16_lma = .;
- . += _data16_filesz;
+ . += ABSOLUTE ( _data16_filesz );
. = ALIGN ( _max_align );
_textdata_lma = .;
- . += _textdata_filesz;
+ . += ABSOLUTE ( _textdata_filesz );
- _filesz = .; /* Do not include zinfo block in file size */
+ _filesz = .; /* Do not include .bss.* or .zinfo in file size */
+
+ /*
+ * Dummy load addresses for .bss.* and .zinfo sections
+ *
+ */
+
+ . = ALIGN ( _max_align );
+ _bss_prefix_lma = .;
+ . += ABSOLUTE ( _prefix_padsz );
+
+ . = ALIGN ( _max_align );
+ _bss_text16_lma = .;
+ . += ABSOLUTE ( _text16_padsz );
+
+ . = ALIGN ( _max_align );
+ _bss_data16_lma = .;
+ . += ABSOLUTE ( _data16_padsz );
+
+ . = ALIGN ( _max_align );
+ _bss_textdata_lma = .;
+ . += ABSOLUTE ( _textdata_padsz );
+
+ . = ALIGN ( _max_align );
+ _bss_pprefix_lma = .;
+ . += ABSOLUTE ( _pprefix_padsz );
+
+ . = ALIGN ( _max_align );
+ _bss_zinfo_lma = .;
+ . += ABSOLUTE ( _zinfo_padsz );
. = ALIGN ( _max_align );
_zinfo_lma = .;
- . += _zinfo_filesz;
+ . += ABSOLUTE ( _zinfo_filesz );
. = ALIGN ( _max_align );
_end_lma = .;
diff --git a/src/arch/x86/scripts/prefixonly.lds b/src/arch/x86/scripts/prefixonly.lds
new file mode 100644
index 000000000..dce0930b5
--- /dev/null
+++ b/src/arch/x86/scripts/prefixonly.lds
@@ -0,0 +1,29 @@
+/* -*- ld-script -*- */
+
+/*
+ * Linker script for prefix-only binaries (e.g. USB disk MBR)
+ *
+ */
+
+SECTIONS {
+
+ .prefix 0x0 : AT ( 0x0 ) {
+ *(.prefix)
+ }
+
+ /DISCARD/ : {
+ *(.comment)
+ *(.comment.*)
+ *(.note)
+ *(.note.*)
+ *(.eh_frame)
+ *(.eh_frame.*)
+ *(.rel)
+ *(.rel.*)
+ *(.einfo)
+ *(.einfo.*)
+ *(.discard)
+ *(.discard.*)
+ }
+
+}
diff --git a/src/arch/x86/transitions/liba20.S b/src/arch/x86/transitions/liba20.S
index 6c1e1f62f..57603353e 100644
--- a/src/arch/x86/transitions/liba20.S
+++ b/src/arch/x86/transitions/liba20.S
@@ -285,7 +285,7 @@ enable_a20:
ret
.section ".text16.early.data", "aw", @progbits
- .align 2
+ .balign 2
enable_a20_method:
.word 0
.size enable_a20_method, . - enable_a20_method
diff --git a/src/arch/x86/transitions/librm.S b/src/arch/x86/transitions/librm.S
index 9d3eff954..5dacb9b04 100644
--- a/src/arch/x86/transitions/librm.S
+++ b/src/arch/x86/transitions/librm.S
@@ -99,7 +99,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
****************************************************************************
*/
.section ".data16.gdt", "aw", @progbits
- .align 16
+ .balign 16
gdt:
gdtr: /* The first GDT entry is unused, the GDTR can fit here. */
gdt_limit: .word gdt_length - 1
@@ -210,9 +210,7 @@ VC_TMP_CR3: .space 4
VC_TMP_CR4: .space 4
VC_TMP_EMER: .space 8
.endif
-#ifdef TIVOLI_VMM_WORKAROUND
VC_TMP_FXSAVE: .space 512
-#endif
VC_TMP_END:
.previous
@@ -224,7 +222,7 @@ RC_TMP_END:
/* Shared temporary static buffer */
.section ".bss16.rm_tmpbuf", "aw", @nobits
- .align 16
+ .balign 16
rm_tmpbuf:
.space VC_TMP_END
.size rm_tmpbuf, . - rm_tmpbuf
@@ -350,6 +348,13 @@ init_librm_rmode:
/* Initialise IDT */
virtcall init_idt
+#ifdef TIVOLI_VMM_WORKAROUND
+ /* Check for FXSAVE/FXRSTOR */
+ clc
+ virtcall check_fxsr
+ setnc fxsr_supported
+#endif
+
/* Restore registers */
popl %edi
popl %ebx
@@ -366,6 +371,10 @@ set_seg_base:
roll $16, %eax
ret
+ .section ".data16.fxsr_supported", "awx", @progbits
+fxsr_supported: /* FXSAVE/FXRSTOR instructions supported */
+ .byte 0
+
/****************************************************************************
* real_to_prot (real-mode near call, 32-bit virtual return address)
*
@@ -1007,10 +1016,11 @@ virt_call:
cli
movw %cs:rm_ds, %ds
-#ifdef TIVOLI_VMM_WORKAROUND
/* Preserve FPU, MMX and SSE state in temporary static buffer */
+ testb $0xff, fxsr_supported
+ jz 1f
fxsave ( rm_tmpbuf + VC_TMP_FXSAVE )
-#endif
+1:
/* Preserve GDT and IDT in temporary static buffer */
sidt ( rm_tmpbuf + VC_TMP_IDT )
sgdt ( rm_tmpbuf + VC_TMP_GDT )
@@ -1077,10 +1087,11 @@ vc_rmode:
wrmsr
.endif
-#ifdef TIVOLI_VMM_WORKAROUND
/* Restore FPU, MMX and SSE state from temporary static buffer */
+ testb $0xff, fxsr_supported
+ jz 1f
fxrstor ( rm_tmpbuf + VC_TMP_FXSAVE )
-#endif
+1:
/* Restore registers and flags and return */
popl %eax /* skip %cs and %ss */
popw %ds
@@ -1470,7 +1481,7 @@ interrupt_wrapper:
****************************************************************************
*/
.section ".pages", "aw", @nobits
- .align SIZEOF_PT
+ .balign SIZEOF_PT
/* Page map level 4 entries (PML4Es)
*
diff --git a/src/arch/x86/transitions/librm_mgmt.c b/src/arch/x86/transitions/librm_mgmt.c
index f9e1d261a..da221e8b1 100644
--- a/src/arch/x86/transitions/librm_mgmt.c
+++ b/src/arch/x86/transitions/librm_mgmt.c
@@ -14,6 +14,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <realmode.h>
#include <pic8259.h>
#include <ipxe/shell.h>
+#include <ipxe/cpuid.h>
/*
* This file provides functions for managing librm.
@@ -118,7 +119,7 @@ void set_interrupt_vector ( unsigned int intr, void *vector ) {
* Initialise interrupt descriptor table
*
*/
-void init_idt ( void ) {
+__asmcall void init_idt ( void ) {
struct interrupt_vector *vec;
unsigned int intr;
@@ -386,6 +387,21 @@ static void iounmap_pages ( volatile const void *io_addr ) {
io_addr, first, i );
}
+/**
+ * Check for FXSAVE/FXRSTOR instruction support
+ *
+ */
+__asmcall void check_fxsr ( struct i386_all_regs *regs ) {
+ struct x86_features features;
+
+ /* Check for FXSR bit */
+ x86_features ( &features );
+ if ( ! ( features.intel.edx & CPUID_FEATURES_INTEL_EDX_FXSR ) )
+ regs->flags |= CF;
+ DBGC ( &features, "FXSAVE/FXRSTOR is%s supported\n",
+ ( ( regs->flags & CF ) ? " not" : "" ) );
+}
+
PROVIDE_UACCESS_INLINE ( librm, phys_to_user );
PROVIDE_UACCESS_INLINE ( librm, user_to_phys );
PROVIDE_UACCESS_INLINE ( librm, virt_to_user );
diff --git a/src/arch/x86/transitions/librm_test.c b/src/arch/x86/transitions/librm_test.c
index 77cf8022c..347d86a15 100644
--- a/src/arch/x86/transitions/librm_test.c
+++ b/src/arch/x86/transitions/librm_test.c
@@ -58,7 +58,8 @@ static struct profiler virt_call_profiler __profiler = { .name = "virt_call" };
/**
* Dummy function for profiling tests
*/
-static __asmcall void librm_test_call ( struct i386_all_regs *ix86 __unused ) {
+static __asmcall __used void
+librm_test_call ( struct i386_all_regs *ix86 __unused ) {
/* Do nothing */
}
diff --git a/src/arch/x86_64/Makefile.linux b/src/arch/x86_64/Makefile.linux
index 154f9d40d..c41ee49df 100644
--- a/src/arch/x86_64/Makefile.linux
+++ b/src/arch/x86_64/Makefile.linux
@@ -1,6 +1,10 @@
-LDSCRIPT = arch/x86_64/scripts/linux.lds
+# -*- makefile -*- : Force emacs to use Makefile mode
-SRCDIRS += arch/x86_64/core/linux
+# Linker script
+#
+LDSCRIPT = arch/x86_64/scripts/linux.lds
+# Include generic Linux Makefile
+#
MAKEDEPS += arch/x86/Makefile.linux
include arch/x86/Makefile.linux
diff --git a/src/arch/x86_64/core/linux/linux_syscall.S b/src/arch/x86_64/core/linux/linux_syscall.S
deleted file mode 100644
index d2805f94c..000000000
--- a/src/arch/x86_64/core/linux/linux_syscall.S
+++ /dev/null
@@ -1,33 +0,0 @@
-
- .section ".data"
- .globl linux_errno
-
-linux_errno: .int 0
-
- .section ".text"
- .code64
- .globl linux_syscall
- .type linux_syscall, @function
-
-linux_syscall:
- movq %rdi, %rax // C arg1 -> syscall number
- movq %rsi, %rdi // C arg2 -> syscall arg1
- movq %rdx, %rsi // C arg3 -> syscall arg2
- movq %rcx, %rdx // C arg4 -> syscall arg3
- movq %r8, %r10 // C arg5 -> syscall arg4
- movq %r9, %r8 // C arg6 -> syscall arg5
- movq 8(%rsp), %r9 // C arg7 -> syscall arg6
-
- syscall
-
- cmpq $-4095, %rax
- jae 1f
- ret
-
-1:
- negq %rax
- movl %eax, linux_errno
- movq $-1, %rax
- ret
-
- .size linux_syscall, . - linux_syscall
diff --git a/src/arch/x86_64/core/linux/linuxprefix.S b/src/arch/x86_64/core/linux/linuxprefix.S
deleted file mode 100644
index ec8a9decd..000000000
--- a/src/arch/x86_64/core/linux/linuxprefix.S
+++ /dev/null
@@ -1,25 +0,0 @@
-#include <linux/unistd.h>
-
- .section ".text"
- .code64
- .globl _linux_start
- .type _linux_start, @function
-
-_linux_start:
- xorq %rbp, %rbp
-
- popq %rdi // argc -> C arg1
- movq %rsp, %rsi // argv -> C arg2
-
- andq $~15, %rsp // 16-byte align the stack
-
- call save_args
-
- /* Our main doesn't use any arguments */
- call main
-
- movq %rax, %rdi // rc -> syscall arg1
- movq $__NR_exit, %rax
- syscall
-
- .size _linux_start, . - _linux_start
diff --git a/src/arch/x86_64/include/bits/compiler.h b/src/arch/x86_64/include/bits/compiler.h
index 46985da3e..5129f90d0 100644
--- a/src/arch/x86_64/include/bits/compiler.h
+++ b/src/arch/x86_64/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, regparm(0) ))
+#define __asmcall __attribute__ (( regparm(0) ))
/** Declare a function with libgcc implicit linkage */
#define __libgcc
diff --git a/src/arch/x86_64/include/bits/linux_api.h b/src/arch/x86_64/include/bits/linux_api.h
deleted file mode 100644
index 589fb5808..000000000
--- a/src/arch/x86_64/include/bits/linux_api.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef _X86_64_LINUX_API_H
-#define _X86_64_LINUX_API_H
-
-#define __SYSCALL_mmap __NR_mmap
-
-#endif /* _X86_64_LINUX_API_H */
diff --git a/src/config/cloud/console.h b/src/config/cloud/console.h
index dae18e556..83318dd30 100644
--- a/src/config/cloud/console.h
+++ b/src/config/cloud/console.h
@@ -18,8 +18,13 @@
* 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.
+ *
+ * Enable only for non-EFI builds, on the assumption that the standard
+ * EFI firmware is likely to already be logging to the serial port.
*/
+#ifndef PLATFORM_efi
#define CONSOLE_SERIAL
+#endif
/* Log to partition on local disk
*
diff --git a/src/config/cloud/general.h b/src/config/cloud/general.h
index 99028c147..38799fd8e 100644
--- a/src/config/cloud/general.h
+++ b/src/config/cloud/general.h
@@ -1,3 +1,7 @@
+/* Enable IPv6 and HTTPS */
+#define NET_PROTO_IPV6
+#define DOWNLOAD_PROTO_HTTPS
+
/* Allow retrieval of metadata (such as an iPXE boot script) from
* Google Compute Engine metadata server.
*/
diff --git a/src/config/cloud/ioapi.h b/src/config/cloud/ioapi.h
new file mode 100644
index 000000000..c7c917f2e
--- /dev/null
+++ b/src/config/cloud/ioapi.h
@@ -0,0 +1,7 @@
+/* Work around missing PCI BIOS calls in the cut-down SeaBIOS found in
+ * some AWS EC2 instances.
+ */
+#ifdef PLATFORM_pcbios
+#undef PCIAPI_PCBIOS
+#define PCIAPI_DIRECT
+#endif
diff --git a/src/config/config.c b/src/config/config.c
index 2ca05dff7..5e7a3ecfd 100644
--- a/src/config/config.c
+++ b/src/config/config.c
@@ -281,6 +281,9 @@ REQUIRE_OBJECT ( ntp_cmd );
#ifdef CERT_CMD
REQUIRE_OBJECT ( cert_cmd );
#endif
+#ifdef IMAGE_MEM_CMD
+REQUIRE_OBJECT ( image_mem_cmd );
+#endif
/*
* Drag in miscellaneous objects
diff --git a/src/config/config_ethernet.c b/src/config/config_ethernet.c
index b5f7ddc9d..8a663c923 100644
--- a/src/config/config_ethernet.c
+++ b/src/config/config_ethernet.c
@@ -46,3 +46,6 @@ REQUIRE_OBJECT ( stp );
#ifdef NET_PROTO_LACP
REQUIRE_OBJECT ( eth_slow );
#endif
+#ifdef NET_PROTO_EAPOL
+REQUIRE_OBJECT ( eapol );
+#endif
diff --git a/src/config/config_usb.c b/src/config/config_usb.c
index 17296d277..b679aeb27 100644
--- a/src/config/config_usb.c
+++ b/src/config/config_usb.c
@@ -53,6 +53,9 @@ REQUIRE_OBJECT ( usbio );
#ifdef USB_KEYBOARD
REQUIRE_OBJECT ( usbkbd );
#endif
+#ifdef USB_BLOCK
+REQUIRE_OBJECT ( usbblk );
+#endif
/*
* Drag in USB external interfaces
diff --git a/src/config/defaults/efi.h b/src/config/defaults/efi.h
index e707dfa6a..9ef34ab62 100644
--- a/src/config/defaults/efi.h
+++ b/src/config/defaults/efi.h
@@ -12,6 +12,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#define UACCESS_EFI
#define IOMAP_VIRT
#define PCIAPI_EFI
+#define DMAAPI_OP
#define CONSOLE_EFI
#define TIMER_EFI
#define UMALLOC_EFI
@@ -24,6 +25,8 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#define ACPI_EFI
#define FDT_EFI
+#define NET_PROTO_IPV6 /* IPv6 protocol */
+
#define DOWNLOAD_PROTO_FILE /* Local filesystem access */
#define IMAGE_EFI /* EFI image support */
@@ -39,6 +42,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#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 USB_BLOCK /* USB block devices */
#define REBOOT_CMD /* Reboot command */
diff --git a/src/config/defaults/linux.h b/src/config/defaults/linux.h
index 75fd617f9..5c4106d30 100644
--- a/src/config/defaults/linux.h
+++ b/src/config/defaults/linux.h
@@ -20,6 +20,8 @@ FILE_LICENCE ( GPL2_OR_LATER );
#define TIME_LINUX
#define REBOOT_NULL
#define PCIAPI_LINUX
+#define DMAAPI_FLAT
+#define ACPI_LINUX
#define DRIVERS_LINUX
diff --git a/src/config/defaults/pcbios.h b/src/config/defaults/pcbios.h
index 21821c95c..83835805a 100644
--- a/src/config/defaults/pcbios.h
+++ b/src/config/defaults/pcbios.h
@@ -12,6 +12,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#define UACCESS_LIBRM
#define IOAPI_X86
#define PCIAPI_PCBIOS
+#define DMAAPI_FLAT
#define TIMER_PCBIOS
#define CONSOLE_PCBIOS
#define NAP_PCBIOS
@@ -48,6 +49,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#define USB_HCD_EHCI /* EHCI USB host controller */
#define USB_HCD_UHCI /* UHCI USB host controller */
#define USB_KEYBOARD /* USB keyboards */
+#define USB_BLOCK /* USB block devices */
#define REBOOT_CMD /* Reboot command */
#define CPUID_CMD /* x86 CPU feature detection command */
diff --git a/src/config/dhcp.h b/src/config/dhcp.h
index bff5b56d6..adfa74a15 100644
--- a/src/config/dhcp.h
+++ b/src/config/dhcp.h
@@ -28,7 +28,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
* Maximum number of discovery deferrals due to blocked links
* (e.g. from non-forwarding STP ports)
*/
-#define DHCP_DISC_MAX_DEFERRALS 60
+#define DHCP_DISC_MAX_DEFERRALS 180
/*
* ProxyDHCP offers are given precedence by continue to wait for them
diff --git a/src/config/general.h b/src/config/general.h
index 3c14a2cd0..9b21f1271 100644
--- a/src/config/general.h
+++ b/src/config/general.h
@@ -35,10 +35,11 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
*/
#define NET_PROTO_IPV4 /* IPv4 protocol */
-#undef NET_PROTO_IPV6 /* IPv6 protocol */
+//#define 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 */
+#define NET_PROTO_EAPOL /* EAP over LAN protocol */
/*
* PXE support
@@ -154,6 +155,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
//#define PROFSTAT_CMD /* Profiling commands */
//#define NTP_CMD /* NTP commands */
//#define CERT_CMD /* Certificate management commands */
+//#define IMAGE_MEM_CMD /* Read memory command */
/*
* ROM-specific options
diff --git a/src/config/ioapi.h b/src/config/ioapi.h
index abe5a50ce..a1498482d 100644
--- a/src/config/ioapi.h
+++ b/src/config/ioapi.h
@@ -14,6 +14,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
//#undef PCIAPI_PCBIOS /* Access via PCI BIOS */
//#define PCIAPI_DIRECT /* Direct access via Type 1 accesses */
+#include <config/named.h>
+#include NAMED_CONFIG(ioapi.h)
#include <config/local/ioapi.h>
+#include LOCAL_NAMED_CONFIG(ioapi.h)
#endif /* CONFIG_IOAPI_H */
diff --git a/src/config/qemu/ioapi.h b/src/config/qemu/ioapi.h
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/config/qemu/ioapi.h
diff --git a/src/config/rpi/ioapi.h b/src/config/rpi/ioapi.h
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/config/rpi/ioapi.h
diff --git a/src/config/usb.h b/src/config/usb.h
index d2519d877..4252ec229 100644
--- a/src/config/usb.h
+++ b/src/config/usb.h
@@ -25,6 +25,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
*
*/
//#undef USB_KEYBOARD /* USB keyboards */
+//#undef USB_BLOCK /* USB block devices */
/*
* USB external interfaces
diff --git a/src/config/vbox/ioapi.h b/src/config/vbox/ioapi.h
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/config/vbox/ioapi.h
diff --git a/src/core/acpi.c b/src/core/acpi.c
index e6912afa2..52eb63a04 100644
--- a/src/core/acpi.c
+++ b/src/core/acpi.c
@@ -35,6 +35,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
*
*/
+/** Colour for debug messages */
+#define colour FADT_SIGNATURE
+
/******************************************************************************
*
* Utility functions
@@ -80,13 +83,13 @@ void acpi_fix_checksum ( struct acpi_header *acpi ) {
}
/**
- * Locate ACPI table
+ * Locate ACPI table via RSDT
*
* @v signature Requested table signature
* @v index Requested index of table with this signature
* @ret table Table, or UNULL if not found
*/
-userptr_t acpi_find ( uint32_t signature, unsigned int index ) {
+userptr_t acpi_find_via_rsdt ( uint32_t signature, unsigned int index ) {
struct acpi_header acpi;
struct acpi_rsdt *rsdtab;
typeof ( rsdtab->entry[0] ) entry;
@@ -106,17 +109,17 @@ userptr_t acpi_find ( uint32_t signature, unsigned int index ) {
/* Read RSDT header */
copy_from_user ( &acpi, rsdt, 0, sizeof ( acpi ) );
if ( acpi.signature != cpu_to_le32 ( RSDT_SIGNATURE ) ) {
- DBGC ( rsdt, "RSDT %#08lx has invalid signature:\n",
+ DBGC ( colour, "RSDT %#08lx has invalid signature:\n",
user_to_phys ( rsdt, 0 ) );
- DBGC_HDA ( rsdt, user_to_phys ( rsdt, 0 ), &acpi,
+ DBGC_HDA ( colour, user_to_phys ( rsdt, 0 ), &acpi,
sizeof ( acpi ) );
return UNULL;
}
len = le32_to_cpu ( acpi.length );
if ( len < sizeof ( rsdtab->acpi ) ) {
- DBGC ( rsdt, "RSDT %#08lx has invalid length:\n",
+ DBGC ( colour, "RSDT %#08lx has invalid length:\n",
user_to_phys ( rsdt, 0 ) );
- DBGC_HDA ( rsdt, user_to_phys ( rsdt, 0 ), &acpi,
+ DBGC_HDA ( colour, user_to_phys ( rsdt, 0 ), &acpi,
sizeof ( acpi ) );
return UNULL;
}
@@ -147,20 +150,20 @@ userptr_t acpi_find ( uint32_t signature, unsigned int index ) {
/* Check table integrity */
if ( acpi_checksum ( table ) != 0 ) {
- DBGC ( rsdt, "RSDT %#08lx found %s with bad checksum "
- "at %08lx\n", user_to_phys ( rsdt, 0 ),
+ DBGC ( colour, "RSDT %#08lx found %s with bad "
+ "checksum at %08lx\n", user_to_phys ( rsdt, 0 ),
acpi_name ( signature ),
user_to_phys ( table, 0 ) );
break;
}
- DBGC ( rsdt, "RSDT %#08lx found %s at %08lx\n",
+ DBGC ( colour, "RSDT %#08lx found %s at %08lx\n",
user_to_phys ( rsdt, 0 ), acpi_name ( signature ),
user_to_phys ( table, 0 ) );
return table;
}
- DBGC ( rsdt, "RSDT %#08lx could not find %s\n",
+ DBGC ( colour, "RSDT %#08lx could not find %s\n",
user_to_phys ( rsdt, 0 ), acpi_name ( signature ) );
return UNULL;
}
@@ -256,20 +259,12 @@ static int acpi_sx_zsdt ( userptr_t zsdt, uint32_t signature ) {
*/
int acpi_sx ( uint32_t signature ) {
struct acpi_fadt fadtab;
- userptr_t rsdt;
userptr_t fadt;
userptr_t dsdt;
userptr_t ssdt;
unsigned int i;
int sx;
- /* Locate RSDT */
- rsdt = acpi_find_rsdt();
- if ( ! rsdt ) {
- DBG ( "RSDT not found\n" );
- return -ENOENT;
- }
-
/* Try DSDT first */
fadt = acpi_find ( FADT_SIGNATURE, 0 );
if ( fadt ) {
@@ -288,8 +283,8 @@ int acpi_sx ( uint32_t signature ) {
return sx;
}
- DBGC ( rsdt, "RSDT %#08lx could not find \\_Sx \"%s\"\n",
- user_to_phys ( rsdt, 0 ), acpi_name ( signature ) );
+ DBGC ( colour, "ACPI could not find \\_Sx \"%s\"\n",
+ acpi_name ( signature ) );
return -ENOENT;
}
diff --git a/src/core/blocktrans.c b/src/core/blocktrans.c
index 3f32f9cf8..f9dcb95d2 100644
--- a/src/core/blocktrans.c
+++ b/src/core/blocktrans.c
@@ -242,9 +242,7 @@ int block_translate ( struct interface *block, userptr_t buffer, size_t size ) {
}
/* Attach to interfaces, mortalise self, and return */
- assert ( block->dest != &null_intf );
- intf_plug_plug ( &blktrans->xfer, block->dest );
- intf_plug_plug ( &blktrans->block, block );
+ intf_insert ( block, &blktrans->block, &blktrans->xfer );
ref_put ( &blktrans->refcnt );
DBGC2 ( blktrans, "BLKTRANS %p created", blktrans );
diff --git a/src/arch/x86/core/cachedhcp.c b/src/core/cachedhcp.c
index dffafe3c9..0e7da4bf2 100644
--- a/src/arch/x86/core/cachedhcp.c
+++ b/src/core/cachedhcp.c
@@ -25,11 +25,11 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <stdint.h>
#include <stdlib.h>
+#include <errno.h>
#include <ipxe/dhcppkt.h>
#include <ipxe/init.h>
#include <ipxe/netdevice.h>
-#include <realmode.h>
-#include <pxe_api.h>
+#include <ipxe/cachedhcp.h>
/** @file
*
@@ -37,50 +37,33 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
*
*/
-/** Cached DHCPACK physical address
- *
- * This can be set by the prefix.
- */
-uint32_t __bss16 ( cached_dhcpack_phys );
-#define cached_dhcpack_phys __use_data16 ( cached_dhcpack_phys )
-
-/** Colour for debug messages */
-#define colour &cached_dhcpack_phys
-
/** Cached DHCPACK */
static struct dhcp_packet *cached_dhcpack;
+/** Colour for debug messages */
+#define colour &cached_dhcpack
+
/**
- * Cached DHCPACK startup function
+ * Record cached DHCPACK
*
+ * @v data DHCPACK packet buffer
+ * @v max_len Maximum possible length
+ * @ret rc Return status code
*/
-static void cachedhcp_init ( void ) {
+int cachedhcp_record ( userptr_t data, size_t max_len ) {
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 */
- if ( ! cached_dhcpack_phys ) {
- DBGC ( colour, "CACHEDHCP found no cached DHCPACK\n" );
- return;
- }
-
- /* No reliable way to determine length before parsing packet;
- * start by assuming maximum length permitted by PXE.
- */
- max_len = sizeof ( BOOTPLAYER_t );
-
/* Allocate and populate DHCP packet */
dhcppkt = zalloc ( sizeof ( *dhcppkt ) + max_len );
if ( ! dhcppkt ) {
DBGC ( colour, "CACHEDHCP could not allocate copy\n" );
- return;
+ return -ENOMEM;
}
dhcphdr = ( ( ( void * ) dhcppkt ) + sizeof ( *dhcppkt ) );
- copy_from_user ( dhcphdr, phys_to_user ( cached_dhcpack_phys ), 0,
- max_len );
+ copy_from_user ( dhcphdr, data, 0, max_len );
dhcppkt_init ( dhcppkt, dhcphdr, max_len );
/* Shrink packet to required length. If reallocation fails,
@@ -98,10 +81,11 @@ static void cachedhcp_init ( void ) {
dhcppkt_init ( dhcppkt, dhcphdr, len );
/* Store as cached DHCPACK, and mark original copy as consumed */
- DBGC ( colour, "CACHEDHCP found cached DHCPACK at %08x+%zx\n",
- cached_dhcpack_phys, len );
+ DBGC ( colour, "CACHEDHCP found cached DHCPACK at %#08lx+%#zx/%#zx\n",
+ user_to_phys ( data, 0 ), len, max_len );
cached_dhcpack = dhcppkt;
- cached_dhcpack_phys = 0;
+
+ return 0;
}
/**
@@ -120,11 +104,6 @@ static void cachedhcp_startup ( void ) {
}
}
-/** Cached DHCPACK initialisation function */
-struct init_fn cachedhcp_init_fn __init_fn ( INIT_NORMAL ) = {
- .initialise = cachedhcp_init,
-};
-
/** Cached DHCPACK startup function */
struct startup_fn cachedhcp_startup_fn __startup_fn ( STARTUP_LATE ) = {
.name = "cachedhcp",
diff --git a/src/core/dma.c b/src/core/dma.c
new file mode 100644
index 000000000..5d6868216
--- /dev/null
+++ b/src/core/dma.c
@@ -0,0 +1,179 @@
+/*
+ * Copyright (C) 2020 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 <assert.h>
+#include <errno.h>
+#include <ipxe/dma.h>
+
+/** @file
+ *
+ * DMA mappings
+ *
+ */
+
+/******************************************************************************
+ *
+ * Flat address space DMA API
+ *
+ ******************************************************************************
+ */
+
+PROVIDE_DMAAPI_INLINE ( flat, dma_map );
+PROVIDE_DMAAPI_INLINE ( flat, dma_unmap );
+PROVIDE_DMAAPI_INLINE ( flat, dma_alloc );
+PROVIDE_DMAAPI_INLINE ( flat, dma_free );
+PROVIDE_DMAAPI_INLINE ( flat, dma_umalloc );
+PROVIDE_DMAAPI_INLINE ( flat, dma_ufree );
+PROVIDE_DMAAPI_INLINE ( flat, dma_set_mask );
+PROVIDE_DMAAPI_INLINE ( flat, dma_phys );
+
+/******************************************************************************
+ *
+ * Operations-based DMA API
+ *
+ ******************************************************************************
+ */
+
+/**
+ * Map buffer for DMA
+ *
+ * @v dma DMA device
+ * @v map DMA mapping to fill in
+ * @v addr Buffer address
+ * @v len Length of buffer
+ * @v flags Mapping flags
+ * @ret rc Return status code
+ */
+static int dma_op_map ( struct dma_device *dma, struct dma_mapping *map,
+ physaddr_t addr, size_t len, int flags ) {
+ struct dma_operations *op = dma->op;
+
+ if ( ! op )
+ return -ENODEV;
+ return op->map ( dma, map, addr, len, flags );
+}
+
+/**
+ * Unmap buffer
+ *
+ * @v map DMA mapping
+ */
+static void dma_op_unmap ( struct dma_mapping *map ) {
+ struct dma_device *dma = map->dma;
+
+ assert ( dma != NULL );
+ assert ( dma->op != NULL );
+ dma->op->unmap ( dma, map );
+}
+
+/**
+ * Allocate and map DMA-coherent buffer
+ *
+ * @v dma DMA device
+ * @v map DMA mapping to fill in
+ * @v len Length of buffer
+ * @v align Physical alignment
+ * @ret addr Buffer address, or NULL on error
+ */
+static void * dma_op_alloc ( struct dma_device *dma, struct dma_mapping *map,
+ size_t len, size_t align ) {
+ struct dma_operations *op = dma->op;
+
+ if ( ! op )
+ return NULL;
+ return op->alloc ( dma, map, len, align );
+}
+
+/**
+ * Unmap and free DMA-coherent buffer
+ *
+ * @v map DMA mapping
+ * @v addr Buffer address
+ * @v len Length of buffer
+ */
+static void dma_op_free ( struct dma_mapping *map, void *addr, size_t len ) {
+ struct dma_device *dma = map->dma;
+
+ assert ( dma != NULL );
+ assert ( dma->op != NULL );
+ dma->op->free ( dma, map, addr, len );
+}
+
+/**
+ * Allocate and map DMA-coherent buffer from external (user) memory
+ *
+ * @v dma DMA device
+ * @v map DMA mapping to fill in
+ * @v len Length of buffer
+ * @v align Physical alignment
+ * @ret addr Buffer address, or NULL on error
+ */
+static userptr_t dma_op_umalloc ( struct dma_device *dma,
+ struct dma_mapping *map,
+ size_t len, size_t align ) {
+ struct dma_operations *op = dma->op;
+
+ if ( ! op )
+ return UNULL;
+ return op->umalloc ( dma, map, len, align );
+}
+
+/**
+ * Unmap and free DMA-coherent buffer from external (user) memory
+ *
+ * @v map DMA mapping
+ * @v addr Buffer address
+ * @v len Length of buffer
+ */
+static void dma_op_ufree ( struct dma_mapping *map, userptr_t addr,
+ size_t len ) {
+ struct dma_device *dma = map->dma;
+
+ assert ( dma != NULL );
+ assert ( dma->op != NULL );
+ dma->op->ufree ( dma, map, addr, len );
+}
+
+/**
+ * Set addressable space mask
+ *
+ * @v dma DMA device
+ * @v mask Addressable space mask
+ */
+static void dma_op_set_mask ( struct dma_device *dma, physaddr_t mask ) {
+ struct dma_operations *op = dma->op;
+
+ if ( op )
+ op->set_mask ( dma, mask );
+}
+
+PROVIDE_DMAAPI ( op, dma_map, dma_op_map );
+PROVIDE_DMAAPI ( op, dma_unmap, dma_op_unmap );
+PROVIDE_DMAAPI ( op, dma_alloc, dma_op_alloc );
+PROVIDE_DMAAPI ( op, dma_free, dma_op_free );
+PROVIDE_DMAAPI ( op, dma_umalloc, dma_op_umalloc );
+PROVIDE_DMAAPI ( op, dma_ufree, dma_op_ufree );
+PROVIDE_DMAAPI ( op, dma_set_mask, dma_op_set_mask );
+PROVIDE_DMAAPI_INLINE ( op, dma_phys );
diff --git a/src/core/image.c b/src/core/image.c
index 078ce1bb9..9fe77c54c 100644
--- a/src/core/image.c
+++ b/src/core/image.c
@@ -176,6 +176,30 @@ int image_set_cmdline ( struct image *image, const char *cmdline ) {
}
/**
+ * Set image data
+ *
+ * @v image Image
+ * @v data Image data
+ * @v len Length of image data
+ * @ret rc Return status code
+ */
+int image_set_data ( struct image *image, userptr_t data, size_t len ) {
+ userptr_t new;
+
+ /* (Re)allocate image data */
+ new = urealloc ( image->data, len );
+ if ( ! new )
+ return -ENOMEM;
+ image->data = new;
+
+ /* Copy in new image data */
+ memcpy_user ( image->data, 0, data, 0, len );
+ image->len = len;
+
+ return 0;
+}
+
+/**
* Determine image type
*
* @v image Executable image
@@ -481,3 +505,47 @@ int image_set_trust ( int require_trusted, int permanent ) {
return 0;
}
+
+/**
+ * Create registered image from block of memory
+ *
+ * @v name Name
+ * @v data Image data
+ * @v len Length
+ * @ret image Image, or NULL on error
+ */
+struct image * image_memory ( const char *name, userptr_t data, size_t len ) {
+ struct image *image;
+ int rc;
+
+ /* Allocate image */
+ image = alloc_image ( NULL );
+ if ( ! image ) {
+ rc = -ENOMEM;
+ goto err_alloc_image;
+ }
+
+ /* Set name */
+ if ( ( rc = image_set_name ( image, name ) ) != 0 )
+ goto err_set_name;
+
+ /* Set data */
+ if ( ( rc = image_set_data ( image, data, len ) ) != 0 )
+ goto err_set_data;
+
+ /* Register image */
+ if ( ( rc = register_image ( image ) ) != 0 )
+ goto err_register;
+
+ /* Drop local reference to image */
+ image_put ( image );
+
+ return image;
+
+ err_register:
+ err_set_data:
+ err_set_name:
+ image_put ( image );
+ err_alloc_image:
+ return NULL;
+}
diff --git a/src/core/interface.c b/src/core/interface.c
index 402aa4541..34a4180a5 100644
--- a/src/core/interface.c
+++ b/src/core/interface.c
@@ -81,9 +81,14 @@ struct interface null_intf = INTF_INIT ( null_intf_desc );
* interface is updated to point to the new destination interface.
*/
void intf_plug ( struct interface *intf, struct interface *dest ) {
+
+ if ( intf == &null_intf )
+ return;
+
DBGC ( INTF_COL ( intf ),
"INTF " INTF_INTF_FMT " replug to " INTF_FMT "\n",
INTF_INTF_DBG ( intf, intf->dest ), INTF_DBG ( dest ) );
+
intf_get ( dest );
intf_put ( intf->dest );
intf->dest = dest;
@@ -386,6 +391,23 @@ void intfs_restart ( int rc, ... ) {
}
/**
+ * Insert a filter interface
+ *
+ * @v intf Object interface
+ * @v upper Upper end of filter
+ * @v lower Lower end of filter
+ */
+void intf_insert ( struct interface *intf, struct interface *upper,
+ struct interface *lower ) {
+ struct interface *dest = intf->dest;
+
+ intf_get ( dest );
+ intf_plug_plug ( intf, upper );
+ intf_plug_plug ( lower, dest );
+ intf_put ( dest );
+}
+
+/**
* Poke an object interface
*
* @v intf Object interface
diff --git a/src/core/iobuf.c b/src/core/iobuf.c
index 0ee53e038..c9970bc76 100644
--- a/src/core/iobuf.c
+++ b/src/core/iobuf.c
@@ -88,8 +88,8 @@ struct io_buffer * alloc_iob_raw ( size_t len, size_t align, size_t offset ) {
len += ( ( - len - offset ) & ( __alignof__ ( *iobuf ) - 1 ) );
/* Allocate memory for buffer plus descriptor */
- data = malloc_dma_offset ( len + sizeof ( *iobuf ), align,
- offset );
+ data = malloc_phys_offset ( len + sizeof ( *iobuf ), align,
+ offset );
if ( ! data )
return NULL;
iobuf = ( data + len );
@@ -97,19 +97,20 @@ struct io_buffer * alloc_iob_raw ( size_t len, size_t align, size_t offset ) {
} else {
/* Allocate memory for buffer */
- data = malloc_dma_offset ( len, align, offset );
+ data = malloc_phys_offset ( len, align, offset );
if ( ! data )
return NULL;
/* Allocate memory for descriptor */
iobuf = malloc ( sizeof ( *iobuf ) );
if ( ! iobuf ) {
- free_dma ( data, len );
+ free_phys ( data, len );
return NULL;
}
}
/* Populate descriptor */
+ memset ( &iobuf->map, 0, sizeof ( iobuf->map ) );
iobuf->head = iobuf->data = iobuf->tail = data;
iobuf->end = ( data + len );
@@ -153,23 +154,67 @@ void free_iob ( struct io_buffer *iobuf ) {
assert ( iobuf->head <= iobuf->data );
assert ( iobuf->data <= iobuf->tail );
assert ( iobuf->tail <= iobuf->end );
+ assert ( ! dma_mapped ( &iobuf->map ) );
/* Free buffer */
len = ( iobuf->end - iobuf->head );
if ( iobuf->end == iobuf ) {
/* Descriptor is inline */
- free_dma ( iobuf->head, ( len + sizeof ( *iobuf ) ) );
+ free_phys ( iobuf->head, ( len + sizeof ( *iobuf ) ) );
} else {
/* Descriptor is detached */
- free_dma ( iobuf->head, len );
+ free_phys ( iobuf->head, len );
free ( iobuf );
}
}
/**
+ * Allocate and map I/O buffer for receive DMA
+ *
+ * @v len Length of I/O buffer
+ * @v dma DMA device
+ * @ret iobuf I/O buffer, or NULL on error
+ */
+struct io_buffer * alloc_rx_iob ( size_t len, struct dma_device *dma ) {
+ struct io_buffer *iobuf;
+ int rc;
+
+ /* Allocate I/O buffer */
+ iobuf = alloc_iob ( len );
+ if ( ! iobuf )
+ goto err_alloc;
+
+ /* Map I/O buffer */
+ if ( ( rc = iob_map_rx ( iobuf, dma ) ) != 0 )
+ goto err_map;
+
+ return iobuf;
+
+ iob_unmap ( iobuf );
+ err_map:
+ free_iob ( iobuf );
+ err_alloc:
+ return NULL;
+}
+
+/**
+ * Unmap and free I/O buffer for receive DMA
+ *
+ * @v iobuf I/O buffer
+ */
+void free_rx_iob ( struct io_buffer *iobuf ) {
+
+ /* Unmap I/O buffer */
+ iob_unmap ( iobuf );
+
+ /* Free I/O buffer */
+ free_iob ( iobuf );
+}
+
+/**
* Ensure I/O buffer has sufficient headroom
*
* @v iobuf I/O buffer
diff --git a/src/core/malloc.c b/src/core/malloc.c
index 0a7843a14..8499ab45a 100644
--- a/src/core/malloc.c
+++ b/src/core/malloc.c
@@ -596,8 +596,8 @@ void * malloc ( size_t size ) {
*
* @v ptr Memory allocated by malloc(), or NULL
*
- * Memory allocated with malloc_dma() cannot be freed with free(); it
- * must be freed with free_dma() instead.
+ * Memory allocated with malloc_phys() cannot be freed with free(); it
+ * must be freed with free_phys() instead.
*
* If @c ptr is NULL, no action is taken.
*/
diff --git a/src/core/null_acpi.c b/src/core/null_acpi.c
index 90c784855..acca37872 100644
--- a/src/core/null_acpi.c
+++ b/src/core/null_acpi.c
@@ -1,3 +1,3 @@
#include <ipxe/acpi.h>
-PROVIDE_ACPI_INLINE ( null, acpi_find_rsdt );
+PROVIDE_ACPI_INLINE ( null, acpi_find );
diff --git a/src/crypto/certstore.c b/src/crypto/certstore.c
index cdf6fb4dd..2676c7e1e 100644
--- a/src/crypto/certstore.c
+++ b/src/crypto/certstore.c
@@ -116,13 +116,13 @@ struct x509_certificate * certstore_find ( struct asn1_cursor *raw ) {
* @v key Private key
* @ret cert X.509 certificate, or NULL if not found
*/
-struct x509_certificate * certstore_find_key ( struct asn1_cursor *key ) {
+struct x509_certificate * certstore_find_key ( struct private_key *key ) {
struct x509_certificate *cert;
/* Search for certificate within store */
list_for_each_entry ( cert, &certstore.links, store.list ) {
if ( pubkey_match ( cert->signature_algorithm->pubkey,
- key->data, key->len,
+ key->builder.data, key->builder.len,
cert->subject.public_key.raw.data,
cert->subject.public_key.raw.len ) == 0 )
return certstore_found ( cert );
diff --git a/src/crypto/cms.c b/src/crypto/cms.c
index bc2148e8a..9511cec8a 100644
--- a/src/crypto/cms.c
+++ b/src/crypto/cms.c
@@ -76,7 +76,7 @@ static uint8_t oid_signeddata[] = { ASN1_OID_SIGNEDDATA };
/** "pkcs7-signedData" object identifier cursor */
static struct asn1_cursor oid_signeddata_cursor =
- ASN1_OID_CURSOR ( oid_signeddata );
+ ASN1_CURSOR ( oid_signeddata );
/**
* Parse CMS signature content type
diff --git a/src/crypto/mishmash/oid_md4.c b/src/crypto/mishmash/oid_md4.c
index 1054a79be..d42f2df19 100644
--- a/src/crypto/mishmash/oid_md4.c
+++ b/src/crypto/mishmash/oid_md4.c
@@ -33,5 +33,5 @@ static uint8_t oid_md4[] = { ASN1_OID_MD4 };
struct asn1_algorithm oid_md4_algorithm __asn1_algorithm = {
.name = "md4",
.digest = &md4_algorithm,
- .oid = ASN1_OID_CURSOR ( oid_md4 ),
+ .oid = ASN1_CURSOR ( oid_md4 ),
};
diff --git a/src/crypto/mishmash/oid_md5.c b/src/crypto/mishmash/oid_md5.c
index 96149d096..f56dd8b8d 100644
--- a/src/crypto/mishmash/oid_md5.c
+++ b/src/crypto/mishmash/oid_md5.c
@@ -33,5 +33,5 @@ static uint8_t oid_md5[] = { ASN1_OID_MD5 };
struct asn1_algorithm oid_md5_algorithm __asn1_algorithm = {
.name = "md5",
.digest = &md5_algorithm,
- .oid = ASN1_OID_CURSOR ( oid_md5 ),
+ .oid = ASN1_CURSOR ( oid_md5 ),
};
diff --git a/src/crypto/mishmash/oid_rsa.c b/src/crypto/mishmash/oid_rsa.c
index 1360c3117..582022628 100644
--- a/src/crypto/mishmash/oid_rsa.c
+++ b/src/crypto/mishmash/oid_rsa.c
@@ -34,5 +34,5 @@ struct asn1_algorithm rsa_encryption_algorithm __asn1_algorithm = {
.name = "rsaEncryption",
.pubkey = &rsa_algorithm,
.digest = NULL,
- .oid = ASN1_OID_CURSOR ( oid_rsa_encryption ),
+ .oid = ASN1_CURSOR ( oid_rsa_encryption ),
};
diff --git a/src/crypto/mishmash/oid_sha1.c b/src/crypto/mishmash/oid_sha1.c
index 0ab3bac61..5dae6d27c 100644
--- a/src/crypto/mishmash/oid_sha1.c
+++ b/src/crypto/mishmash/oid_sha1.c
@@ -33,5 +33,5 @@ static uint8_t oid_sha1[] = { ASN1_OID_SHA1 };
struct asn1_algorithm oid_sha1_algorithm __asn1_algorithm = {
.name = "sha1",
.digest = &sha1_algorithm,
- .oid = ASN1_OID_CURSOR ( oid_sha1 ),
+ .oid = ASN1_CURSOR ( oid_sha1 ),
};
diff --git a/src/crypto/mishmash/oid_sha224.c b/src/crypto/mishmash/oid_sha224.c
index 1ff6884a4..ee7ed22e4 100644
--- a/src/crypto/mishmash/oid_sha224.c
+++ b/src/crypto/mishmash/oid_sha224.c
@@ -33,5 +33,5 @@ static uint8_t oid_sha224[] = { ASN1_OID_SHA224 };
struct asn1_algorithm oid_sha224_algorithm __asn1_algorithm = {
.name = "sha224",
.digest = &sha224_algorithm,
- .oid = ASN1_OID_CURSOR ( oid_sha224 ),
+ .oid = ASN1_CURSOR ( oid_sha224 ),
};
diff --git a/src/crypto/mishmash/oid_sha256.c b/src/crypto/mishmash/oid_sha256.c
index 51ea585c5..963fddb63 100644
--- a/src/crypto/mishmash/oid_sha256.c
+++ b/src/crypto/mishmash/oid_sha256.c
@@ -33,5 +33,5 @@ static uint8_t oid_sha256[] = { ASN1_OID_SHA256 };
struct asn1_algorithm oid_sha256_algorithm __asn1_algorithm = {
.name = "sha256",
.digest = &sha256_algorithm,
- .oid = ASN1_OID_CURSOR ( oid_sha256 ),
+ .oid = ASN1_CURSOR ( oid_sha256 ),
};
diff --git a/src/crypto/mishmash/oid_sha384.c b/src/crypto/mishmash/oid_sha384.c
index 5ba4d60a4..81ff48bbf 100644
--- a/src/crypto/mishmash/oid_sha384.c
+++ b/src/crypto/mishmash/oid_sha384.c
@@ -33,5 +33,5 @@ static uint8_t oid_sha384[] = { ASN1_OID_SHA384 };
struct asn1_algorithm oid_sha384_algorithm __asn1_algorithm = {
.name = "sha384",
.digest = &sha384_algorithm,
- .oid = ASN1_OID_CURSOR ( oid_sha384 ),
+ .oid = ASN1_CURSOR ( oid_sha384 ),
};
diff --git a/src/crypto/mishmash/oid_sha512.c b/src/crypto/mishmash/oid_sha512.c
index 38e3c1a3d..78bae48b4 100644
--- a/src/crypto/mishmash/oid_sha512.c
+++ b/src/crypto/mishmash/oid_sha512.c
@@ -33,5 +33,5 @@ static uint8_t oid_sha512[] = { ASN1_OID_SHA512 };
struct asn1_algorithm oid_sha512_algorithm __asn1_algorithm = {
.name = "sha512",
.digest = &sha512_algorithm,
- .oid = ASN1_OID_CURSOR ( oid_sha512 ),
+ .oid = ASN1_CURSOR ( oid_sha512 ),
};
diff --git a/src/crypto/mishmash/oid_sha512_224.c b/src/crypto/mishmash/oid_sha512_224.c
index 2300dad66..6f61f9cac 100644
--- a/src/crypto/mishmash/oid_sha512_224.c
+++ b/src/crypto/mishmash/oid_sha512_224.c
@@ -33,5 +33,5 @@ static uint8_t oid_sha512_224[] = { ASN1_OID_SHA512_224 };
struct asn1_algorithm oid_sha512_224_algorithm __asn1_algorithm = {
.name = "sha512/224",
.digest = &sha512_224_algorithm,
- .oid = ASN1_OID_CURSOR ( oid_sha512_224 ),
+ .oid = ASN1_CURSOR ( oid_sha512_224 ),
};
diff --git a/src/crypto/mishmash/oid_sha512_256.c b/src/crypto/mishmash/oid_sha512_256.c
index 6af61fea9..bce4762e4 100644
--- a/src/crypto/mishmash/oid_sha512_256.c
+++ b/src/crypto/mishmash/oid_sha512_256.c
@@ -33,5 +33,5 @@ static uint8_t oid_sha512_256[] = { ASN1_OID_SHA512_256 };
struct asn1_algorithm oid_sha512_256_algorithm __asn1_algorithm = {
.name = "sha512/256",
.digest = &sha512_256_algorithm,
- .oid = ASN1_OID_CURSOR ( oid_sha512_256 ),
+ .oid = ASN1_CURSOR ( oid_sha512_256 ),
};
diff --git a/src/crypto/mishmash/rsa_md5.c b/src/crypto/mishmash/rsa_md5.c
index ac828ac11..051afe264 100644
--- a/src/crypto/mishmash/rsa_md5.c
+++ b/src/crypto/mishmash/rsa_md5.c
@@ -36,7 +36,7 @@ struct asn1_algorithm md5_with_rsa_encryption_algorithm __asn1_algorithm = {
.name = "md5WithRSAEncryption",
.pubkey = &rsa_algorithm,
.digest = &md5_algorithm,
- .oid = ASN1_OID_CURSOR ( oid_md5_with_rsa_encryption ),
+ .oid = ASN1_CURSOR ( oid_md5_with_rsa_encryption ),
};
/** MD5 digestInfo prefix */
diff --git a/src/crypto/mishmash/rsa_sha1.c b/src/crypto/mishmash/rsa_sha1.c
index 39424bf2d..264f871f1 100644
--- a/src/crypto/mishmash/rsa_sha1.c
+++ b/src/crypto/mishmash/rsa_sha1.c
@@ -37,7 +37,7 @@ struct asn1_algorithm sha1_with_rsa_encryption_algorithm __asn1_algorithm = {
.name = "sha1WithRSAEncryption",
.pubkey = &rsa_algorithm,
.digest = &sha1_algorithm,
- .oid = ASN1_OID_CURSOR ( oid_sha1_with_rsa_encryption ),
+ .oid = ASN1_CURSOR ( oid_sha1_with_rsa_encryption ),
};
/** SHA-1 digestInfo prefix */
diff --git a/src/crypto/mishmash/rsa_sha224.c b/src/crypto/mishmash/rsa_sha224.c
index 5e8755aab..1465a033d 100644
--- a/src/crypto/mishmash/rsa_sha224.c
+++ b/src/crypto/mishmash/rsa_sha224.c
@@ -37,7 +37,7 @@ struct asn1_algorithm sha224_with_rsa_encryption_algorithm __asn1_algorithm = {
.name = "sha224WithRSAEncryption",
.pubkey = &rsa_algorithm,
.digest = &sha224_algorithm,
- .oid = ASN1_OID_CURSOR ( oid_sha224_with_rsa_encryption ),
+ .oid = ASN1_CURSOR ( oid_sha224_with_rsa_encryption ),
};
/** SHA-224 digestInfo prefix */
diff --git a/src/crypto/mishmash/rsa_sha256.c b/src/crypto/mishmash/rsa_sha256.c
index b44af5f19..7283c3e29 100644
--- a/src/crypto/mishmash/rsa_sha256.c
+++ b/src/crypto/mishmash/rsa_sha256.c
@@ -37,7 +37,7 @@ struct asn1_algorithm sha256_with_rsa_encryption_algorithm __asn1_algorithm = {
.name = "sha256WithRSAEncryption",
.pubkey = &rsa_algorithm,
.digest = &sha256_algorithm,
- .oid = ASN1_OID_CURSOR ( oid_sha256_with_rsa_encryption ),
+ .oid = ASN1_CURSOR ( oid_sha256_with_rsa_encryption ),
};
/** SHA-256 digestInfo prefix */
diff --git a/src/crypto/mishmash/rsa_sha384.c b/src/crypto/mishmash/rsa_sha384.c
index af22a2bf0..6f8c29b29 100644
--- a/src/crypto/mishmash/rsa_sha384.c
+++ b/src/crypto/mishmash/rsa_sha384.c
@@ -37,7 +37,7 @@ struct asn1_algorithm sha384_with_rsa_encryption_algorithm __asn1_algorithm = {
.name = "sha384WithRSAEncryption",
.pubkey = &rsa_algorithm,
.digest = &sha384_algorithm,
- .oid = ASN1_OID_CURSOR ( oid_sha384_with_rsa_encryption ),
+ .oid = ASN1_CURSOR ( oid_sha384_with_rsa_encryption ),
};
/** SHA-384 digestInfo prefix */
diff --git a/src/crypto/mishmash/rsa_sha512.c b/src/crypto/mishmash/rsa_sha512.c
index 29ee15493..bb4463a5a 100644
--- a/src/crypto/mishmash/rsa_sha512.c
+++ b/src/crypto/mishmash/rsa_sha512.c
@@ -37,7 +37,7 @@ struct asn1_algorithm sha512_with_rsa_encryption_algorithm __asn1_algorithm = {
.name = "sha512WithRSAEncryption",
.pubkey = &rsa_algorithm,
.digest = &sha512_algorithm,
- .oid = ASN1_OID_CURSOR ( oid_sha512_with_rsa_encryption ),
+ .oid = ASN1_CURSOR ( oid_sha512_with_rsa_encryption ),
};
/** SHA-512 digestInfo prefix */
diff --git a/src/crypto/ocsp.c b/src/crypto/ocsp.c
index 9ced59ea3..cc957b40c 100644
--- a/src/crypto/ocsp.c
+++ b/src/crypto/ocsp.c
@@ -116,7 +116,7 @@ static const uint8_t oid_basic_response_type[] = { ASN1_OID_OCSP_BASIC };
/** OCSP basic response type cursor */
static struct asn1_cursor oid_basic_response_type_cursor =
- ASN1_OID_CURSOR ( oid_basic_response_type );
+ ASN1_CURSOR ( oid_basic_response_type );
/**
* Free OCSP check
@@ -284,7 +284,7 @@ int ocsp_check ( struct x509_certificate *cert,
/* Sanity checks */
assert ( cert != NULL );
assert ( issuer != NULL );
- assert ( x509_is_valid ( issuer ) );
+ assert ( issuer->root != NULL );
/* Allocate and initialise check */
*ocsp = zalloc ( sizeof ( **ocsp ) );
@@ -833,18 +833,6 @@ int ocsp_response ( struct ocsp_check *ocsp, const void *data, size_t len ) {
}
/**
- * OCSP dummy root certificate store
- *
- * OCSP validation uses no root certificates, since it takes place
- * only when there already exists a validated issuer certificate.
- */
-static struct x509_root ocsp_root = {
- .digest = &ocsp_digest_algorithm,
- .count = 0,
- .fingerprints = NULL,
-};
-
-/**
* Check OCSP response signature
*
* @v ocsp OCSP check
@@ -927,7 +915,7 @@ int ocsp_validate ( struct ocsp_check *ocsp, time_t time ) {
*/
x509_invalidate ( signer );
if ( ( rc = x509_validate ( signer, ocsp->issuer, time,
- &ocsp_root ) ) != 0 ) {
+ ocsp->issuer->root ) ) != 0 ) {
DBGC ( ocsp, "OCSP %p \"%s\" could not validate ",
ocsp, x509_name ( ocsp->cert ) );
DBGC ( ocsp, "signer \"%s\": %s\n",
@@ -973,7 +961,7 @@ int ocsp_validate ( struct ocsp_check *ocsp, time_t time ) {
/* Validate certificate against issuer */
if ( ( rc = x509_validate ( ocsp->cert, ocsp->issuer, time,
- &ocsp_root ) ) != 0 ) {
+ ocsp->issuer->root ) ) != 0 ) {
DBGC ( ocsp, "OCSP %p \"%s\" could not validate certificate: "
"%s\n", ocsp, x509_name ( ocsp->cert ), strerror ( rc ));
return rc;
diff --git a/src/crypto/privkey.c b/src/crypto/privkey.c
index 7ef04880f..c15edf130 100644
--- a/src/crypto/privkey.c
+++ b/src/crypto/privkey.c
@@ -64,9 +64,12 @@ __asm__ ( ".section \".rodata\", \"a\", " PROGBITS "\n\t"
".previous\n\t" );
/** Private key */
-struct asn1_cursor private_key = {
- .data = private_key_data,
- .len = ( ( size_t ) private_key_len ),
+struct private_key private_key = {
+ .refcnt = REF_INIT ( ref_no_free ),
+ .builder = {
+ .data = private_key_data,
+ .len = ( ( size_t ) private_key_len ),
+ },
};
/** Default private key */
@@ -84,6 +87,19 @@ static struct setting privkey_setting __setting ( SETTING_CRYPTO, privkey ) = {
};
/**
+ * Free private key
+ *
+ * @v refcnt Reference counter
+ */
+void privkey_free ( struct refcnt *refcnt ) {
+ struct private_key *key =
+ container_of ( refcnt, struct private_key, refcnt );
+
+ free ( key->builder.data );
+ free ( key );
+}
+
+/**
* Apply private key configuration settings
*
* @ret rc Return status code
@@ -98,23 +114,24 @@ static int privkey_apply_settings ( void ) {
if ( ALLOW_KEY_OVERRIDE ) {
/* Restore default private key */
- memcpy ( &private_key, &default_private_key,
- sizeof ( private_key ) );
+ memcpy ( &private_key.builder, &default_private_key,
+ sizeof ( private_key.builder ) );
/* Fetch new private key, if any */
free ( key_data );
if ( ( len = fetch_raw_setting_copy ( NULL, &privkey_setting,
&key_data ) ) >= 0 ) {
- private_key.data = key_data;
- private_key.len = len;
+ private_key.builder.data = key_data;
+ private_key.builder.len = len;
}
}
/* Debug */
- if ( private_key.len ) {
+ if ( private_key.builder.len ) {
DBGC ( &private_key, "PRIVKEY using %s private key:\n",
( key_data ? "external" : "built-in" ) );
- DBGC_HDA ( &private_key, 0, private_key.data, private_key.len );
+ DBGC_HDA ( &private_key, 0, private_key.builder.data,
+ private_key.builder.len );
} else {
DBGC ( &private_key, "PRIVKEY has no private key\n" );
}
diff --git a/src/crypto/rootcert.c b/src/crypto/rootcert.c
index 867ff50e8..0835ff071 100644
--- a/src/crypto/rootcert.c
+++ b/src/crypto/rootcert.c
@@ -71,6 +71,7 @@ static struct setting trust_setting __setting ( SETTING_CRYPTO, trust ) = {
/** Root certificates */
struct x509_root root_certificates = {
+ .refcnt = REF_INIT ( ref_no_free ),
.digest = &sha256_algorithm,
.count = ( sizeof ( fingerprints ) / FINGERPRINT_LEN ),
.fingerprints = fingerprints,
diff --git a/src/crypto/x509.c b/src/crypto/x509.c
index feb7e4a0a..17d8c7a43 100644
--- a/src/crypto/x509.c
+++ b/src/crypto/x509.c
@@ -123,6 +123,19 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
__einfo_uniqify ( EINFO_EACCES, 0x0b, "No usable certificates" )
/**
+ * Free X.509 certificate
+ *
+ * @v refcnt Reference count
+ */
+static void x509_free ( struct refcnt *refcnt ) {
+ struct x509_certificate *cert =
+ container_of ( refcnt, struct x509_certificate, refcnt );
+
+ x509_root_put ( cert->root );
+ free ( cert );
+}
+
+/**
* Get X.509 certificate display name
*
* @v cert X.509 certificate
@@ -156,7 +169,7 @@ static uint8_t oid_common_name[] = { ASN1_OID_COMMON_NAME };
/** "commonName" object identifier cursor */
static struct asn1_cursor oid_common_name_cursor =
- ASN1_OID_CURSOR ( oid_common_name );
+ ASN1_CURSOR ( oid_common_name );
/**
* Parse X.509 certificate version
@@ -523,12 +536,12 @@ static struct x509_key_purpose x509_key_purposes[] = {
{
.name = "codeSigning",
.bits = X509_CODE_SIGNING,
- .oid = ASN1_OID_CURSOR ( oid_code_signing ),
+ .oid = ASN1_CURSOR ( oid_code_signing ),
},
{
.name = "ocspSigning",
.bits = X509_OCSP_SIGNING,
- .oid = ASN1_OID_CURSOR ( oid_ocsp_signing ),
+ .oid = ASN1_CURSOR ( oid_ocsp_signing ),
},
};
@@ -631,7 +644,7 @@ static uint8_t oid_ad_ocsp[] = { ASN1_OID_OCSP };
static struct x509_access_method x509_access_methods[] = {
{
.name = "OCSP",
- .oid = ASN1_OID_CURSOR ( oid_ad_ocsp ),
+ .oid = ASN1_CURSOR ( oid_ad_ocsp ),
.parse = x509_parse_ocsp,
},
};
@@ -768,27 +781,27 @@ static uint8_t oid_ce_subject_alt_name[] =
static struct x509_extension x509_extensions[] = {
{
.name = "basicConstraints",
- .oid = ASN1_OID_CURSOR ( oid_ce_basic_constraints ),
+ .oid = ASN1_CURSOR ( oid_ce_basic_constraints ),
.parse = x509_parse_basic_constraints,
},
{
.name = "keyUsage",
- .oid = ASN1_OID_CURSOR ( oid_ce_key_usage ),
+ .oid = ASN1_CURSOR ( oid_ce_key_usage ),
.parse = x509_parse_key_usage,
},
{
.name = "extKeyUsage",
- .oid = ASN1_OID_CURSOR ( oid_ce_ext_key_usage ),
+ .oid = ASN1_CURSOR ( oid_ce_ext_key_usage ),
.parse = x509_parse_extended_key_usage,
},
{
.name = "authorityInfoAccess",
- .oid = ASN1_OID_CURSOR ( oid_pe_authority_info_access ),
+ .oid = ASN1_CURSOR ( oid_pe_authority_info_access ),
.parse = x509_parse_authority_info_access,
},
{
.name = "subjectAltName",
- .oid = ASN1_OID_CURSOR ( oid_ce_subject_alt_name ),
+ .oid = ASN1_CURSOR ( oid_ce_subject_alt_name ),
.parse = x509_parse_subject_alt_name,
},
};
@@ -1075,7 +1088,7 @@ int x509_certificate ( const void *data, size_t len,
*cert = zalloc ( sizeof ( **cert ) + cursor.len );
if ( ! *cert )
return -ENOMEM;
- ref_init ( &(*cert)->refcnt, NULL );
+ ref_init ( &(*cert)->refcnt, x509_free );
raw = ( *cert + 1 );
/* Copy raw data */
@@ -1296,6 +1309,50 @@ int x509_check_time ( struct x509_certificate *cert, time_t time ) {
}
/**
+ * Check if X.509 certificate is valid
+ *
+ * @v cert X.509 certificate
+ * @v root Root certificate list, or NULL to use default
+ */
+int x509_is_valid ( struct x509_certificate *cert, struct x509_root *root ) {
+
+ /* Use default root certificate store if none specified */
+ if ( ! root )
+ root = &root_certificates;
+
+ return ( cert->root == root );
+}
+
+/**
+ * Set X.509 certificate as validated
+ *
+ * @v cert X.509 certificate
+ * @v issuer Issuing X.509 certificate (or NULL)
+ * @v root Root certificate list
+ */
+static void x509_set_valid ( struct x509_certificate *cert,
+ struct x509_certificate *issuer,
+ struct x509_root *root ) {
+ unsigned int max_path_remaining;
+
+ /* Sanity checks */
+ assert ( root != NULL );
+ assert ( ( issuer == NULL ) || ( issuer->path_remaining >= 1 ) );
+
+ /* Record validation root */
+ x509_root_put ( cert->root );
+ cert->root = x509_root_get ( root );
+
+ /* Calculate effective path length */
+ cert->path_remaining = ( cert->extensions.basic.path_len + 1 );
+ if ( issuer ) {
+ max_path_remaining = ( issuer->path_remaining - 1 );
+ if ( cert->path_remaining > max_path_remaining )
+ cert->path_remaining = max_path_remaining;
+ }
+}
+
+/**
* Validate X.509 certificate
*
* @v cert X.509 certificate
@@ -1313,7 +1370,6 @@ int x509_check_time ( struct x509_certificate *cert, time_t time ) {
int x509_validate ( struct x509_certificate *cert,
struct x509_certificate *issuer,
time_t time, struct x509_root *root ) {
- unsigned int max_path_remaining;
int rc;
/* Use default root certificate store if none specified */
@@ -1321,7 +1377,7 @@ int x509_validate ( struct x509_certificate *cert,
root = &root_certificates;
/* Return success if certificate has already been validated */
- if ( x509_is_valid ( cert ) )
+ if ( x509_is_valid ( cert, root ) )
return 0;
/* Fail if certificate is invalid at specified time */
@@ -1330,20 +1386,19 @@ int x509_validate ( struct x509_certificate *cert,
/* Succeed if certificate is a trusted root certificate */
if ( x509_check_root ( cert, root ) == 0 ) {
- cert->flags |= X509_FL_VALIDATED;
- cert->path_remaining = ( cert->extensions.basic.path_len + 1 );
+ x509_set_valid ( cert, NULL, root );
return 0;
}
/* Fail unless we have an issuer */
if ( ! issuer ) {
- DBGC2 ( cert, "X509 %p \"%s\" has no issuer\n",
+ DBGC2 ( cert, "X509 %p \"%s\" has no trusted issuer\n",
cert, x509_name ( cert ) );
return -EACCES_UNTRUSTED;
}
/* Fail unless issuer has already been validated */
- if ( ! x509_is_valid ( issuer ) ) {
+ if ( ! x509_is_valid ( issuer, root ) ) {
DBGC ( cert, "X509 %p \"%s\" ", cert, x509_name ( cert ) );
DBGC ( cert, "issuer %p \"%s\" has not yet been validated\n",
issuer, x509_name ( issuer ) );
@@ -1369,14 +1424,8 @@ int x509_validate ( struct x509_certificate *cert,
return -EACCES_OCSP_REQUIRED;
}
- /* Calculate effective path length */
- cert->path_remaining = ( issuer->path_remaining - 1 );
- max_path_remaining = ( cert->extensions.basic.path_len + 1 );
- if ( cert->path_remaining > max_path_remaining )
- cert->path_remaining = max_path_remaining;
-
/* Mark certificate as valid */
- cert->flags |= X509_FL_VALIDATED;
+ x509_set_valid ( cert, issuer, root );
DBGC ( cert, "X509 %p \"%s\" successfully validated using ",
cert, x509_name ( cert ) );
diff --git a/src/drivers/block/ibft.c b/src/drivers/block/ibft.c
index f9918363a..ca5fad9ff 100644
--- a/src/drivers/block/ibft.c
+++ b/src/drivers/block/ibft.c
@@ -48,11 +48,15 @@ FILE_LICENCE ( BSD2 );
*
* iSCSI boot firmware table
*
- * The information in this file is derived from the document "iSCSI
- * Boot Firmware Table (iBFT)" as published by IBM at
+ * The information in this file is originally derived from the document "iSCSI
+ * Boot Firmware Table (iBFT)" as published by IBM at:
*
* ftp://ftp.software.ibm.com/systems/support/system_x_pdf/ibm_iscsi_boot_firmware_table_v1.02.pdf
*
+ * That file is no longer available, but a more recent version is available:
+ *
+ * ftp://ftp.software.ibm.com/systems/support/bladecenter/iscsi_boot_firmware_table_v1.03.pdf
+ *
*/
/**
diff --git a/src/drivers/bus/isa.c b/src/drivers/bus/isa.c
index da0c43c60..94d4ce99b 100644
--- a/src/drivers/bus/isa.c
+++ b/src/drivers/bus/isa.c
@@ -5,6 +5,7 @@
#include <errno.h>
#include <ipxe/io.h>
#include <ipxe/isa.h>
+#include <config/isa.h>
FILE_LICENCE ( GPL2_OR_LATER );
@@ -94,7 +95,7 @@ static void isa_remove ( struct isa_device *isa ) {
static int isabus_probe ( struct root_device *rootdev ) {
struct isa_device *isa = NULL;
struct isa_driver *driver;
- int ioidx;
+ long ioidx;
int rc;
for_each_table_entry ( driver, ISA_DRIVERS ) {
diff --git a/src/drivers/bus/pcimsix.c b/src/drivers/bus/pcimsix.c
index 80893c418..eb0450d91 100644
--- a/src/drivers/bus/pcimsix.c
+++ b/src/drivers/bus/pcimsix.c
@@ -84,7 +84,7 @@ static void * pci_msix_ioremap ( struct pci_device *pci, struct pci_msix *msix,
msix, pci_msix_name ( cfg ), base, bar, offset );
/* Map BAR portion */
- io = ioremap ( ( start + offset ), PCI_MSIX_LEN );
+ io = pci_ioremap ( pci, ( start + offset ), PCI_MSIX_LEN );
if ( ! io ) {
DBGC ( msix, "MSI-X %p %s could not map %#08lx\n",
msix, pci_msix_name ( cfg ), base );
diff --git a/src/drivers/bus/usb.c b/src/drivers/bus/usb.c
index a7b687528..428ae26c1 100644
--- a/src/drivers/bus/usb.c
+++ b/src/drivers/bus/usb.c
@@ -363,6 +363,35 @@ static int usb_endpoint_clear_tt ( struct usb_endpoint *ep ) {
}
/**
+ * Clear endpoint halt (if applicable)
+ *
+ * @v ep USB endpoint
+ * @ret rc Return status code
+ */
+int usb_endpoint_clear_halt ( struct usb_endpoint *ep ) {
+ struct usb_device *usb = ep->usb;
+ unsigned int type;
+ int rc;
+
+ /* Clear transaction translator, if applicable */
+ if ( ( rc = usb_endpoint_clear_tt ( ep ) ) != 0 )
+ return rc;
+
+ /* Clear endpoint halt (if applicable) */
+ type = ( ep->attributes & USB_ENDPOINT_ATTR_TYPE_MASK );
+ if ( ( type != USB_ENDPOINT_ATTR_CONTROL ) &&
+ ( ( rc = usb_clear_feature ( usb, USB_RECIP_ENDPOINT,
+ USB_ENDPOINT_HALT,
+ ep->address ) ) != 0 ) ) {
+ DBGC ( usb, "USB %s %s could not clear endpoint halt: %s\n",
+ usb->name, usb_endpoint_name ( ep ), strerror ( rc ) );
+ return rc;
+ }
+
+ return 0;
+}
+
+/**
* Close USB endpoint
*
* @v ep USB endpoint
@@ -399,26 +428,14 @@ void usb_endpoint_close ( struct usb_endpoint *ep ) {
*/
static int usb_endpoint_reset ( struct usb_endpoint *ep ) {
struct usb_device *usb = ep->usb;
- unsigned int type;
int rc;
/* Sanity check */
assert ( ! list_empty ( &ep->halted ) );
- /* Clear transaction translator, if applicable */
- if ( ( rc = usb_endpoint_clear_tt ( ep ) ) != 0 )
- return rc;
-
- /* Clear endpoint halt, if applicable */
- type = ( ep->attributes & USB_ENDPOINT_ATTR_TYPE_MASK );
- if ( ( type != USB_ENDPOINT_ATTR_CONTROL ) &&
- ( ( rc = usb_clear_feature ( usb, USB_RECIP_ENDPOINT,
- USB_ENDPOINT_HALT,
- ep->address ) ) != 0 ) ) {
- DBGC ( usb, "USB %s %s could not clear endpoint halt: %s\n",
- usb->name, usb_endpoint_name ( ep ), strerror ( rc ) );
+ /* Clear device halt, if applicable */
+ if ( ( rc = usb_endpoint_clear_halt ( ep ) ) != 0 )
return rc;
- }
/* Reset endpoint */
if ( ( rc = ep->host->reset ( ep ) ) != 0 ) {
@@ -634,12 +651,13 @@ int usb_prefill ( struct usb_endpoint *ep ) {
}
/**
- * Refill endpoint
+ * Refill endpoint up to specified limit
*
* @v ep USB endpoint
+ * @v max Fill limit
* @ret rc Return status code
*/
-int usb_refill ( struct usb_endpoint *ep ) {
+int usb_refill_limit ( struct usb_endpoint *ep, unsigned int max ) {
struct io_buffer *iobuf;
size_t reserve = ep->reserve;
size_t len = ( ep->len ? ep->len : ep->mtu );
@@ -650,7 +668,9 @@ int usb_refill ( struct usb_endpoint *ep ) {
assert ( ep->max > 0 );
/* Refill endpoint */
- while ( ep->fill < ep->max ) {
+ if ( max > ep->max )
+ max = ep->max;
+ while ( ep->fill < max ) {
/* Get or allocate buffer */
if ( list_empty ( &ep->recycled ) ) {
@@ -682,6 +702,16 @@ int usb_refill ( struct usb_endpoint *ep ) {
}
/**
+ * Refill endpoint
+ *
+ * @v ep USB endpoint
+ * @ret rc Return status code
+ */
+int usb_refill ( struct usb_endpoint *ep ) {
+ return usb_refill_limit ( ep, ep->max );
+}
+
+/**
* Discard endpoint recycled buffer list
*
* @v ep USB endpoint
@@ -818,6 +848,7 @@ int usb_control ( struct usb_device *usb, unsigned int request,
"failed: %s\n", usb->name, request,
value, index, strerror ( rc ) );
free_iob ( cmplt );
+ usb_endpoint_reset ( ep );
return rc;
}
@@ -912,9 +943,15 @@ int usb_get_string_descriptor ( struct usb_device *usb, unsigned int index,
sizeof ( *desc ) ) ) != 0 )
goto err_get_descriptor;
- /* Copy to buffer */
+ /* Calculate string length */
+ if ( desc->header.len < sizeof ( desc->header ) ) {
+ rc = -EINVAL;
+ goto err_len;
+ }
actual = ( ( desc->header.len - sizeof ( desc->header ) ) /
sizeof ( desc->character[0] ) );
+
+ /* Copy to buffer */
for ( i = 0 ; ( ( i < actual ) && ( i < max ) ) ; i++ )
buf[i] = le16_to_cpu ( desc->character[i] );
if ( len )
@@ -925,6 +962,7 @@ int usb_get_string_descriptor ( struct usb_device *usb, unsigned int index,
return actual;
+ err_len:
err_get_descriptor:
free ( desc );
err_alloc:
@@ -1636,6 +1674,11 @@ static void unregister_usb ( struct usb_device *usb ) {
struct io_buffer *iobuf;
struct io_buffer *tmp;
+ DBGC ( usb, "USB %s addr %d %04x:%04x class %d:%d:%d removed\n",
+ usb->name, usb->address, le16_to_cpu ( usb->device.vendor ),
+ le16_to_cpu ( usb->device.product ), usb->device.class.class,
+ usb->device.class.subclass, usb->device.class.protocol );
+
/* Sanity checks */
assert ( port->usb == usb );
@@ -2235,23 +2278,6 @@ unsigned int usb_route_string ( struct usb_device *usb ) {
}
/**
- * Get USB depth
- *
- * @v usb USB device
- * @ret depth Hub depth
- */
-unsigned int usb_depth ( struct usb_device *usb ) {
- struct usb_device *parent;
- unsigned int depth;
-
- /* Navigate up to root hub, constructing depth as we go */
- for ( depth = 0 ; ( parent = usb->port->hub->usb ) ; usb = parent )
- depth++;
-
- return depth;
-}
-
-/**
* Get USB root hub port
*
* @v usb USB device
diff --git a/src/drivers/bus/virtio-pci.c b/src/drivers/bus/virtio-pci.c
index 402bf4f12..5d2d62750 100644
--- a/src/drivers/bus/virtio-pci.c
+++ b/src/drivers/bus/virtio-pci.c
@@ -321,7 +321,7 @@ int virtio_pci_map_capability(struct pci_device *pci, int cap, size_t minlen,
region->flags = VIRTIO_PCI_REGION_PORT;
} else {
/* Region mapped into memory space */
- region->base = ioremap(base + offset, length);
+ region->base = pci_ioremap(pci, base + offset, length);
region->flags = VIRTIO_PCI_REGION_MEMORY;
}
}
diff --git a/src/drivers/infiniband/MT25218_PRM.h b/src/drivers/infiniband/MT25218_PRM.h
index 4011bd0ba..c4dc3316b 100644
--- a/src/drivers/infiniband/MT25218_PRM.h
+++ b/src/drivers/infiniband/MT25218_PRM.h
@@ -73,7 +73,7 @@ struct arbelprm_ud_address_vector_st { /* Little Endian */
/* -------------- */
pseudo_bit_t rgid_31_0[0x00020]; /* Remote GID[31:0] if G bit is set. Must be set to 0x2 if G bit is cleared. */
/* -------------- */
-};
+};
/* Send doorbell */
@@ -88,7 +88,7 @@ struct arbelprm_send_doorbell_st { /* Little Endian */
pseudo_bit_t reserved1[0x00002];
pseudo_bit_t qpn[0x00018]; /* QP number this doorbell is rung on */
/* -------------- */
-};
+};
/* ACCESS_LAM_inject_errors_input_modifier */
@@ -102,7 +102,7 @@ struct arbelprm_access_lam_inject_errors_input_modifier_st { /* Little Endian */
pseudo_bit_t index0[0x00007];
pseudo_bit_t q0[0x00001];
/* -------------- */
-};
+};
/* ACCESS_LAM_inject_errors_input_parameter */
@@ -114,7 +114,7 @@ struct arbelprm_access_lam_inject_errors_input_parameter_st { /* Little Endian *
pseudo_bit_t ra[0x00010]; /* Row Address */
pseudo_bit_t ca[0x00010]; /* Column Address */
/* -------------- */
-};
+};
/* */
@@ -127,7 +127,7 @@ struct arbelprm_recv_wqe_segment_next_st { /* Little Endian */
*/
pseudo_bit_t reserved1[0x0001a];
/* -------------- */
-};
+};
/* Send wqe segment data inline */
@@ -141,7 +141,7 @@ struct arbelprm_wqe_segment_data_inline_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved2[0x00040];
/* -------------- */
-};
+};
/* Send wqe segment data ptr */
@@ -155,7 +155,7 @@ struct arbelprm_wqe_segment_data_ptr_st { /* Little Endian */
/* -------------- */
pseudo_bit_t local_address_l[0x00020];
/* -------------- */
-};
+};
/* Send wqe segment rd */
@@ -167,7 +167,7 @@ struct arbelprm_local_invalidate_segment_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved2[0x000a0];
/* -------------- */
-};
+};
/* Fast_Registration_Segment */
@@ -197,7 +197,7 @@ struct arbelprm_fast_registration_segment_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reg_len_l[0x00020]; /* Region Length[31:0] */
/* -------------- */
-};
+};
/* Send wqe segment atomic */
@@ -210,7 +210,7 @@ struct arbelprm_wqe_segment_atomic_st { /* Little Endian */
/* -------------- */
pseudo_bit_t compare_l[0x00020];
/* -------------- */
-};
+};
/* Send wqe segment remote address */
@@ -223,7 +223,7 @@ struct arbelprm_wqe_segment_remote_address_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved0[0x00020];
/* -------------- */
-};
+};
/* end wqe segment bind */
@@ -253,7 +253,7 @@ struct arbelprm_wqe_segment_bind_st { /* Little Endian */
/* -------------- */
pseudo_bit_t length_l[0x00020];
/* -------------- */
-};
+};
/* Send wqe segment ud */
@@ -267,7 +267,7 @@ struct arbelprm_wqe_segment_ud_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved1[0x00040];
/* -------------- */
-};
+};
/* Send wqe segment rd */
@@ -279,7 +279,7 @@ struct arbelprm_wqe_segment_rd_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved1[0x00040];
/* -------------- */
-};
+};
/* Send wqe segment ctrl */
@@ -296,7 +296,7 @@ struct arbelprm_wqe_segment_ctrl_send_st { /* Little Endian */
/* -------------- */
pseudo_bit_t immediate[0x00020]; /* If the OpCode encodes an operation with Immediate (RDMA-write/SEND), This field will hold the Immediate data to be sent. If the OpCode encodes send and invalidate operations, this field holds the Invalidation key to be inserted into the packet; otherwise, this field is reserved. */
/* -------------- */
-};
+};
/* Send wqe segment next */
@@ -338,7 +338,7 @@ struct arbelprm_wqe_segment_next_st { /* Little Endian */
pseudo_bit_t always1[0x00001];
pseudo_bit_t reserved1[0x00018];
/* -------------- */
-};
+};
/* Address Path */
@@ -384,7 +384,7 @@ struct arbelprm_address_path_st { /* Little Endian */
/* -------------- */
pseudo_bit_t rgid_31_0[0x00020]; /* Remote GID[31:0] */
/* -------------- */
-};
+};
/* HCA Command Register (HCR) */
@@ -414,7 +414,7 @@ struct arbelprm_hca_command_register_st { /* Little Endian */
pseudo_bit_t status[0x00008]; /* Command execution status report. Valid only if command interface in under SW ownership (Go bit is cleared)
0 - command completed without error. If different than zero, command execution completed with error. Syndrom encoding is depended on command executed and is defined for each command */
/* -------------- */
-};
+};
/* CQ Doorbell */
@@ -435,7 +435,7 @@ struct arbelprm_cq_cmd_doorbell_st { /* Little Endian */
/* -------------- */
pseudo_bit_t cq_param[0x00020]; /* parameter to be used by CQ command */
/* -------------- */
-};
+};
/* RD-send doorbell */
@@ -449,7 +449,7 @@ struct arbelprm_rd_send_doorbell_st { /* Little Endian */
/* -------------- */
struct arbelprm_send_doorbell_st send_doorbell;/* Send Parameters */
/* -------------- */
-};
+};
/* Multicast Group Member QP */
@@ -458,7 +458,7 @@ struct arbelprm_mgmqp_st { /* Little Endian */
pseudo_bit_t reserved0[0x00007];
pseudo_bit_t qi[0x00001]; /* Qi: QPN_i is valid */
/* -------------- */
-};
+};
/* vsd */
@@ -575,7 +575,7 @@ struct arbelprm_vsd_st { /* Little Endian */
/* -------------- */
pseudo_bit_t vsd_dw55[0x00020];
/* -------------- */
-};
+};
/* ACCESS_LAM_inject_errors */
@@ -586,7 +586,7 @@ struct arbelprm_access_lam_inject_errors_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved0[0x00020];
/* -------------- */
-};
+};
/* Logical DIMM Information */
@@ -626,7 +626,7 @@ struct arbelprm_dimminfo_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved4[0x00040];
/* -------------- */
-};
+};
/* UAR Parameters */
@@ -661,7 +661,7 @@ struct arbelprm_uar_params_st { /* Little Endian */
Number of entries in table is 2^log_max_uars.
Table must be aligned to its size. */
/* -------------- */
-};
+};
/* Translation and Protection Tables Parameters */
@@ -695,7 +695,7 @@ struct arbelprm_tptparams_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved3[0x00040];
/* -------------- */
-};
+};
/* Multicast Support Parameters */
@@ -729,7 +729,7 @@ struct arbelprm_multicastparam_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved5[0x00020];
/* -------------- */
-};
+};
/* QPC/EEC/CQC/EQC/RDB Parameters */
@@ -821,7 +821,7 @@ struct arbelprm_qpcbaseaddr_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved10[0x00040];
/* -------------- */
-};
+};
/* Header_Log_Register */
@@ -830,7 +830,7 @@ struct arbelprm_header_log_register_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved0[0x00060];
/* -------------- */
-};
+};
/* Performance Monitors */
@@ -862,7 +862,7 @@ struct arbelprm_performance_monitors_st { /* Little Endian */
/* -------------- */
pseudo_bit_t event_counter2[0x00020];/* Read/write event counter, counting events specified by EvCntl and EvCnt2 fields repsectively. When the event counter reaches is maximum value of 0xFFFFFF, the next event will cause it to roll over to zero, set F1 or F2 bit respectively and generate interrupt by I1 I2 bit respectively. */
/* -------------- */
-};
+};
/* Receive segment format */
@@ -876,7 +876,7 @@ struct arbelprm_wqe_segment_ctrl_recv_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved4[0x00020];
/* -------------- */
-};
+};
/* MLX WQE segment format */
@@ -895,7 +895,7 @@ struct arbelprm_wqe_segment_ctrl_mlx_st { /* Little Endian */
pseudo_bit_t vcrc[0x00010]; /* Packet's VCRC (if not 0 - otherwise computed by HW) */
pseudo_bit_t rlid[0x00010]; /* Destination LID (must match given headers) */
/* -------------- */
-};
+};
/* Send WQE segment format */
@@ -926,7 +926,7 @@ struct arbelprm_send_wqe_segment_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved1[0x00200];
/* -------------- */
-};
+};
/* QP and EE Context Entry */
@@ -1118,7 +1118,7 @@ struct arbelprm_queue_pair_ee_context_entry_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved33[0x00040];
/* -------------- */
-};
+};
/* Clear Interrupt [63:0] */
@@ -1132,7 +1132,7 @@ struct arbelprm_clr_int_st { /* Little Endian */
Write transactions to this register will clear (de-assert) the virtual interrupt output pins of InfiniHost-III-EX. The value to be written in this register is obtained by executing QUERY_ADAPTER command on command interface after system boot.
This register is write-only. Reading from this register will cause undefined result */
/* -------------- */
-};
+};
/* EQ_Arm_DB_Region */
@@ -1143,7 +1143,7 @@ struct arbelprm_eq_arm_db_region_st { /* Little Endian */
pseudo_bit_t eq_x_arm_l[0x00020]; /* EQ[31:0] X state.
This register is used to Arm EQs when setting the appropriate bits. */
/* -------------- */
-};
+};
/* EQ Set CI DBs Table */
@@ -1404,7 +1404,7 @@ struct arbelprm_eq_set_ci_table_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved63[0x00020];
/* -------------- */
-};
+};
/* InfiniHost-III-EX Configuration Registers */
@@ -1415,7 +1415,7 @@ struct arbelprm_configuration_registers_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved1[0x3fcb20];
/* -------------- */
-};
+};
/* QP_DB_Record */
@@ -1429,7 +1429,7 @@ struct arbelprm_qp_db_record_st { /* Little Endian */
0x5 for SRQ */
pseudo_bit_t qp_number[0x00018]; /* QP number */
/* -------------- */
-};
+};
/* CQ_ARM_DB_Record */
@@ -1445,7 +1445,7 @@ struct arbelprm_cq_arm_db_record_st { /* Little Endian */
pseudo_bit_t res[0x00003]; /* Must be 0x2 */
pseudo_bit_t cq_number[0x00018]; /* CQ number */
/* -------------- */
-};
+};
/* CQ_CI_DB_Record */
@@ -1456,7 +1456,7 @@ struct arbelprm_cq_ci_db_record_st { /* Little Endian */
pseudo_bit_t res[0x00003]; /* Must be 0x1 */
pseudo_bit_t cq_number[0x00018]; /* CQ number */
/* -------------- */
-};
+};
/* Virtual_Physical_Mapping */
@@ -1472,7 +1472,7 @@ struct arbelprm_virtual_physical_mapping_st { /* Little Endian */
pseudo_bit_t reserved1[0x00006];
pseudo_bit_t pa_l[0x00014]; /* Physical Address[31:12] */
/* -------------- */
-};
+};
/* MOD_STAT_CFG */
@@ -1485,7 +1485,7 @@ struct arbelprm_mod_stat_cfg_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved2[0x007e0];
/* -------------- */
-};
+};
/* SRQ Context */
@@ -1528,7 +1528,7 @@ struct arbelprm_srq_context_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved4[0x00060];
/* -------------- */
-};
+};
/* PBL */
@@ -1549,7 +1549,7 @@ struct arbelprm_pbl_st { /* Little Endian */
/* -------------- */
pseudo_bit_t mtt_3_l[0x00020]; /* Fourth MTT[31:0] */
/* -------------- */
-};
+};
/* Performance Counters */
@@ -1580,7 +1580,7 @@ struct arbelprm_performance_counters_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved3[0x00620];
/* -------------- */
-};
+};
/* Transport and CI Error Counters */
@@ -1724,7 +1724,7 @@ struct arbelprm_transport_and_ci_error_counters_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved12[0x002a0];
/* -------------- */
-};
+};
/* Event_data Field - HCR Completion Event */
@@ -1743,7 +1743,7 @@ struct arbelprm_hcr_completion_event_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved3[0x00020];
/* -------------- */
-};
+};
/* Completion with Error CQE */
@@ -1791,7 +1791,7 @@ struct arbelprm_completion_with_error_st { /* Little Endian */
0xFE - For completion with error on Receive Queues
0xFF - For completion with error on Send Queues */
/* -------------- */
-};
+};
/* Resize CQ Input Mailbox */
@@ -1814,7 +1814,7 @@ struct arbelprm_resize_cq_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved4[0x00100];
/* -------------- */
-};
+};
/* MAD_IFC Input Modifier */
@@ -1826,7 +1826,7 @@ struct arbelprm_mad_ifc_input_modifier_st { /* Little Endian */
pseudo_bit_t rlid[0x00010]; /* Remote (source) LID from the received MAD.
This field is required for trap generation upon MKey/BKey validation. */
/* -------------- */
-};
+};
/* MAD_IFC Input Mailbox */
@@ -1863,7 +1863,7 @@ struct arbelprm_mad_ifc_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved5[0x004c0];
/* -------------- */
-};
+};
/* Query Debug Message */
@@ -1924,7 +1924,7 @@ struct arbelprm_query_debug_msg_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved3[0x00400];
/* -------------- */
-};
+};
/* User Access Region */
@@ -1939,7 +1939,7 @@ struct arbelprm_uar_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved1[0x03ec0];
/* -------------- */
-};
+};
/* Receive doorbell */
@@ -1953,7 +1953,7 @@ struct arbelprm_receive_doorbell_st { /* Little Endian */
pseudo_bit_t reserved3[0x00002];
pseudo_bit_t qpn[0x00018]; /* QP number or SRQ number this doorbell is rung on */
/* -------------- */
-};
+};
/* SET_IB Parameters */
@@ -1974,7 +1974,7 @@ struct arbelprm_set_ib_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved2[0x00180];
/* -------------- */
-};
+};
/* Multicast Group Member */
@@ -2014,7 +2014,7 @@ struct arbelprm_mgm_entry_st { /* Little Endian */
/* -------------- */
struct arbelprm_mgmqp_st mgmqp_7; /* Multicast Group Member QP */
/* -------------- */
-};
+};
/* INIT_IB Parameters */
@@ -2068,7 +2068,7 @@ struct arbelprm_init_ib_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved5[0x006c0];
/* -------------- */
-};
+};
/* Query Device Limitations */
@@ -2285,7 +2285,7 @@ struct arbelprm_query_dev_lim_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved41[0x002c0];
/* -------------- */
-};
+};
/* QUERY_ADAPTER Parameters Block */
@@ -2299,7 +2299,7 @@ struct arbelprm_query_adapter_st { /* Little Endian */
/* -------------- */
struct arbelprm_vsd_st vsd;
/* -------------- */
-};
+};
/* QUERY_FW Parameters Block */
@@ -2375,7 +2375,7 @@ struct arbelprm_query_fw_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved6[0x004c0];
/* -------------- */
-};
+};
/* ACCESS_LAM */
@@ -2384,7 +2384,7 @@ struct arbelprm_access_lam_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved0[0x00080];
/* -------------- */
-};
+};
/* ENABLE_LAM Parameters Block */
@@ -2418,7 +2418,7 @@ struct arbelprm_enable_lam_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved2[0x00400];
/* -------------- */
-};
+};
/* Memory Access Parameters for UD Address Vector Table */
@@ -2430,7 +2430,7 @@ struct arbelprm_udavtable_memory_parameters_st { /* Little Endian */
pseudo_bit_t xlation_en[0x00001]; /* When cleared, address is physical address and no translation will be done. When set, address is virtual. */
pseudo_bit_t reserved1[0x00002];
/* -------------- */
-};
+};
/* INIT_HCA & QUERY_HCA Parameters Block */
@@ -2495,7 +2495,7 @@ struct arbelprm_init_hca_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved11[0x00600];
/* -------------- */
-};
+};
/* Event Queue Context Table Entry */
@@ -2555,7 +2555,7 @@ struct arbelprm_eqc_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved9[0x00080];
/* -------------- */
-};
+};
/* Memory Translation Table (MTT) Entry */
@@ -2566,7 +2566,7 @@ struct arbelprm_mtt_st { /* Little Endian */
pseudo_bit_t reserved0[0x0000b];
pseudo_bit_t ptag_l[0x00014]; /* Low-order bits of Physical tag. The size of the field depends on the page size of the region. Maximum PTAG size is 52 bits. */
/* -------------- */
-};
+};
/* Memory Protection Table (MPT) Entry */
@@ -2641,7 +2641,7 @@ struct arbelprm_mpt_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved8[0x00040];
/* -------------- */
-};
+};
/* Completion Queue Context Table Entry */
@@ -2719,7 +2719,7 @@ struct arbelprm_completion_queue_context_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved8[0x00020];
/* -------------- */
-};
+};
/* GPIO_event_data */
@@ -2732,7 +2732,7 @@ struct arbelprm_gpio_event_data_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved1[0x00020];
/* -------------- */
-};
+};
/* Event_data Field - QP/EE Events */
@@ -2749,7 +2749,7 @@ struct arbelprm_qp_ee_event_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved4[0x00060];
/* -------------- */
-};
+};
/* InfiniHost-III-EX Type0 Configuration Header */
@@ -2947,7 +2947,7 @@ struct arbelprm_mt25208_type0_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved13[0x006a0];
/* -------------- */
-};
+};
/* Event Data Field - Performance Monitor */
@@ -2965,7 +2965,7 @@ struct arbelprm_performance_monitor_event_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved1[0x00040];
/* -------------- */
-};
+};
/* Event_data Field - Page Faults */
@@ -2989,7 +2989,7 @@ struct arbelprm_page_fault_event_data_st { /* Little Endian */
/* -------------- */
pseudo_bit_t prefetch_len[0x00020]; /* Indicates how many subsequent pages in the same memory region/window will be accessed by the following transaction after this page fault is resolved. measured in bytes. SW can use this information in order to page-in the subsequent pages if they are not present. */
/* -------------- */
-};
+};
/* WQE segments format */
@@ -3006,7 +3006,7 @@ struct arbelprm_wqe_segment_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved2[0x00080];
/* -------------- */
-};
+};
/* Event_data Field - Port State Change */
@@ -3019,7 +3019,7 @@ struct arbelprm_port_state_change_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved3[0x00060];
/* -------------- */
-};
+};
/* Event_data Field - Completion Queue Error */
@@ -3036,7 +3036,7 @@ struct arbelprm_completion_queue_error_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved3[0x00060];
/* -------------- */
-};
+};
/* Event_data Field - Completion Event */
@@ -3046,7 +3046,7 @@ struct arbelprm_completion_event_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved1[0x000a0];
/* -------------- */
-};
+};
/* Event Queue Entry */
@@ -3065,7 +3065,7 @@ struct arbelprm_event_queue_entry_st { /* Little Endian */
1 HW */
pseudo_bit_t reserved3[0x00018];
/* -------------- */
-};
+};
/* QP/EE State Transitions Command Parameters */
@@ -3078,7 +3078,7 @@ struct arbelprm_qp_ee_state_transitions_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved1[0x009c0];
/* -------------- */
-};
+};
/* Completion Queue Entry Format */
@@ -3131,7 +3131,7 @@ struct arbelprm_completion_queue_entry_st { /* Little Endian */
0xFE - For completion with error on Receive Queues
0xFF - For completion with error on Send Queues */
/* -------------- */
-};
+};
/* */
@@ -3152,7 +3152,7 @@ struct arbelprm_ecc_detect_event_data_st { /* Little Endian */
pseudo_bit_t err_ra[0x00010];
pseudo_bit_t err_ca[0x00010];
/* -------------- */
-};
+};
/* Event_data Field - ECC Detection Event */
@@ -3177,7 +3177,7 @@ struct arbelprm_scrubbing_event_st { /* Little Endian */
pseudo_bit_t err_ra[0x00010]; /* Error row address */
pseudo_bit_t err_ca[0x00010]; /* Error column address */
/* -------------- */
-};
+};
/* Miscellaneous Counters */
@@ -3186,28 +3186,28 @@ struct arbelprm_misc_counters_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved0[0x007e0];
/* -------------- */
-};
+};
/* LAM_EN Output Parameter */
struct arbelprm_lam_en_out_param_st { /* Little Endian */
pseudo_bit_t reserved0[0x00040];
/* -------------- */
-};
+};
/* Extended_Completion_Queue_Entry */
struct arbelprm_extended_completion_queue_entry_st { /* Little Endian */
pseudo_bit_t reserved0[0x00020];
/* -------------- */
-};
+};
/* */
struct arbelprm_eq_cmd_doorbell_st { /* Little Endian */
pseudo_bit_t reserved0[0x00020];
/* -------------- */
-};
+};
/* 0 */
@@ -3456,5 +3456,5 @@ struct arbelprm_arbel_prm_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved59[0xffcfc0];
/* -------------- */
-};
+};
#endif /* H_prefix_arbelprm_bits_fixnames_MT25218_PRM_csp_H */
diff --git a/src/drivers/infiniband/MT25408_PRM.h b/src/drivers/infiniband/MT25408_PRM.h
index cc248daf9..f8c19ce72 100644
--- a/src/drivers/infiniband/MT25408_PRM.h
+++ b/src/drivers/infiniband/MT25408_PRM.h
@@ -47,7 +47,7 @@ struct hermonprm_ud_address_vector_st { /* Little Endian */
pseudo_bit_t reserved1[0x00008];
/* -------------- */
pseudo_bit_t hop_limit[0x00008]; /* IPv6 hop limit */
- pseudo_bit_t max_stat_rate[0x00004];/* Maximum static rate control.
+ pseudo_bit_t max_stat_rate[0x00004];/* Maximum static rate control.
0 - 4X injection rate
1 - 1X injection rate
other - reserved
@@ -72,7 +72,7 @@ struct hermonprm_ud_address_vector_st { /* Little Endian */
/* -------------- */
pseudo_bit_t rgid_31_0[0x00020]; /* Remote GID[31:0] if G bit is set. Must be set to 0x2 if G bit is cleared. */
/* -------------- */
-};
+};
/* Send doorbell */
@@ -87,7 +87,7 @@ struct hermonprm_send_doorbell_st { /* Little Endian */
pseudo_bit_t reserved1[0x00002];
pseudo_bit_t qpn[0x00018]; /* QP number this doorbell is rung on */
/* -------------- */
-};
+};
/* Send wqe segment data inline */
@@ -101,7 +101,7 @@ struct hermonprm_wqe_segment_data_inline_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved2[0x00040];
/* -------------- */
-};
+};
/* Send wqe segment data ptr */
@@ -115,7 +115,7 @@ struct hermonprm_wqe_segment_data_ptr_st { /* Little Endian */
/* -------------- */
pseudo_bit_t local_address_l[0x00020];
/* -------------- */
-};
+};
/* Send wqe segment rd */
@@ -127,7 +127,7 @@ struct hermonprm_local_invalidate_segment_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved2[0x000a0];
/* -------------- */
-};
+};
/* Fast_Registration_Segment ####michal - doesn't match PRM (fields were added, see below) new table size in bytes - 0x30 */
@@ -157,7 +157,7 @@ struct hermonprm_fast_registration_segment_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reg_len_l[0x00020]; /* Region Length[31:0] */
/* -------------- */
-};
+};
/* Send wqe segment atomic */
@@ -170,7 +170,7 @@ struct hermonprm_wqe_segment_atomic_st { /* Little Endian */
/* -------------- */
pseudo_bit_t compare_l[0x00020];
/* -------------- */
-};
+};
/* Send wqe segment remote address */
@@ -183,7 +183,7 @@ struct hermonprm_wqe_segment_remote_address_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved0[0x00020];
/* -------------- */
-};
+};
/* end wqe segment bind */
@@ -213,7 +213,7 @@ struct hermonprm_wqe_segment_bind_st { /* Little Endian */
/* -------------- */
pseudo_bit_t length_l[0x00020];
/* -------------- */
-};
+};
/* Send wqe segment ud */
@@ -227,7 +227,7 @@ struct hermonprm_wqe_segment_ud_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved1[0x00040];
/* -------------- */
-};
+};
/* Send wqe segment rd */
@@ -239,7 +239,7 @@ struct hermonprm_wqe_segment_rd_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved1[0x00040];
/* -------------- */
-};
+};
/* Send wqe segment ctrl */
@@ -263,7 +263,7 @@ struct hermonprm_wqe_segment_ctrl_send_st { /* Little Endian */
/* -------------- */
pseudo_bit_t immediate[0x00020]; /* If the OpCode encodes an operation with Immediate (RDMA-write/SEND), This field will hold the Immediate data to be sent. If the OpCode encodes send and invalidate operations, this field holds the Invalidation key to be inserted into the packet; otherwise, this field is reserved. */
/* -------------- */
-};
+};
/* Address Path # ###michal - match to PRM */
@@ -280,19 +280,19 @@ struct hermonprm_address_path_st { /* Little Endian */
pseudo_bit_t reserved1[0x00008];
/* -------------- */
pseudo_bit_t hop_limit[0x00008]; /* IPv6 hop limit */
- pseudo_bit_t max_stat_rate[0x00004];/* Maximum static rate control.
- 0 - 100% injection rate
+ pseudo_bit_t max_stat_rate[0x00004];/* Maximum static rate control.
+ 0 - 100% injection rate
1 - 25% injection rate
2 - 12.5% injection rate
3 - 50% injection rate
- 7: 2.5 Gb/s.
- 8: 10 Gb/s.
- 9: 30 Gb/s.
- 10: 5 Gb/s.
+ 7: 2.5 Gb/s.
+ 8: 10 Gb/s.
+ 9: 30 Gb/s.
+ 10: 5 Gb/s.
11: 20 Gb/s.
- 12: 40 Gb/s.
- 13: 60 Gb/s.
- 14: 80 Gb/s.
+ 12: 40 Gb/s.
+ 13: 60 Gb/s.
+ 14: 80 Gb/s.
15: 120 Gb/s. */
pseudo_bit_t reserved2[0x00004];
pseudo_bit_t mgid_index[0x00007]; /* Index to port GID table */
@@ -328,7 +328,7 @@ struct hermonprm_address_path_st { /* Little Endian */
/* -------------- */
pseudo_bit_t dmac_31_0[0x00020];
/* -------------- */
-};
+};
/* HCA Command Register (HCR) #### michal - match PRM */
@@ -359,7 +359,7 @@ struct hermonprm_hca_command_register_st { /* Little Endian */
pseudo_bit_t status[0x00008]; /* Command execution status report. Valid only if command interface in under SW ownership (Go bit is cleared)
0 - command completed without error. If different than zero, command execution completed with error. Syndrom encoding is depended on command executed and is defined for each command */
/* -------------- */
-};
+};
/* CQ Doorbell */
@@ -373,14 +373,14 @@ struct hermonprm_cq_cmd_doorbell_st { /* Little Endian */
Other - Reserved */
pseudo_bit_t reserved0[0x00001];
pseudo_bit_t cmd_sn[0x00002]; /* Command Sequence Number - This field should be incremented upon receiving completion notification of the respective CQ.
- This transition is done by ringing Request notification for next Solicited, Request notification for next Solicited or Unsolicited
+ This transition is done by ringing Request notification for next Solicited, Request notification for next Solicited or Unsolicited
completion or Request notification for multiple completions doorbells after receiving completion notification.
This field is initialized to Zero */
pseudo_bit_t reserved1[0x00002];
/* -------------- */
pseudo_bit_t cq_param[0x00020]; /* parameter to be used by CQ command */
/* -------------- */
-};
+};
/* RD-send doorbell */
@@ -394,7 +394,7 @@ struct hermonprm_rd_send_doorbell_st { /* Little Endian */
/* -------------- */
struct hermonprm_send_doorbell_st send_doorbell;/* Send Parameters */
/* -------------- */
-};
+};
/* Multicast Group Member QP #### michal - match PRM */
@@ -404,7 +404,7 @@ struct hermonprm_mgmqp_st { /* Little Endian */
pseudo_bit_t blck_lb[0x00001]; /* Block self-loopback messages arriving to this qp */
pseudo_bit_t qi[0x00001]; /* Qi: QPN_i is valid */
/* -------------- */
-};
+};
/* vsd */
@@ -521,7 +521,7 @@ struct hermonprm_vsd_st { /* Little Endian */
/* -------------- */
pseudo_bit_t vsd_dw55[0x00020];
/* -------------- */
-};
+};
/* UAR Parameters */
@@ -535,7 +535,7 @@ struct hermonprm_uar_params_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved2[0x000a0];
/* -------------- */
-};
+};
/* Translation and Protection Tables Parameters */
@@ -552,7 +552,7 @@ struct hermonprm_tptparams_st { /* Little Endian */
/* -------------- */
pseudo_bit_t log_dmpt_sz[0x00006]; /* Log (base 2) of the number of region/windows entries in the dMPT table. */
pseudo_bit_t reserved0[0x00002];
- pseudo_bit_t pfto[0x00005]; /* Page Fault RNR Timeout -
+ pseudo_bit_t pfto[0x00005]; /* Page Fault RNR Timeout -
The field returned in RNR Naks generated when a page fault is detected.
It has no effect when on-demand-paging is not used. */
pseudo_bit_t reserved1[0x00013];
@@ -575,7 +575,7 @@ struct hermonprm_tptparams_st { /* Little Endian */
Entry size is 64 bytes.
Table must be aligned to its size. */
/* -------------- */
-};
+};
/* Multicast Support Parameters #### michal - match PRM */
@@ -584,14 +584,14 @@ struct hermonprm_multicastparam_st { /* Little Endian */
The base address must be aligned to the entry size.
Address may be set to 0xFFFFFFFF if multicast is not supported. */
/* -------------- */
- pseudo_bit_t mc_base_addr_l[0x00020];/* Base Address of the Multicast Table [31:0].
+ pseudo_bit_t mc_base_addr_l[0x00020];/* Base Address of the Multicast Table [31:0].
The base address must be aligned to the entry size.
Address may be set to 0xFFFFFFFF if multicast is not supported. */
/* -------------- */
pseudo_bit_t reserved0[0x00040];
/* -------------- */
pseudo_bit_t log_mc_table_entry_sz[0x00005];/* Log2 of the Size of multicast group member (MGM) entry.
- Must be greater than 5 (to allow CTRL and GID sections).
+ Must be greater than 5 (to allow CTRL and GID sections).
That implies the number of QPs per MC table entry. */
pseudo_bit_t reserved1[0x0000b];
pseudo_bit_t reserved2[0x00010];
@@ -611,7 +611,7 @@ struct hermonprm_multicastparam_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved6[0x00020];
/* -------------- */
-};
+};
/* QPC/EEC/CQC/EQC/RDB Parameters #### michal - doesn't match PRM (field name are differs. see below) */
@@ -679,12 +679,12 @@ struct hermonprm_qpcbaseaddr_st { /* Little Endian */
/* -------------- */
pseudo_bit_t log_num_rd[0x00003]; /* Log (base 2) of the maximum number of RdmaRdC entries per QP. This denotes the maximum number of outstanding reads/atomics as a responder. */
pseudo_bit_t reserved7[0x00002];
- pseudo_bit_t rdmardc_base_addr_l[0x0001b];/* rdmardc_base_addr_l: Base address of table that holds remote read and remote atomic requests [31:0].
+ pseudo_bit_t rdmardc_base_addr_l[0x0001b];/* rdmardc_base_addr_l: Base address of table that holds remote read and remote atomic requests [31:0].
Table must be aligned to RDB entry size (32 bytes). */
/* -------------- */
pseudo_bit_t reserved8[0x00040];
/* -------------- */
-};
+};
/* Header_Log_Register */
@@ -693,7 +693,7 @@ struct hermonprm_header_log_register_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved0[0x00060];
/* -------------- */
-};
+};
/* Performance Monitors */
@@ -725,7 +725,7 @@ struct hermonprm_performance_monitors_st { /* Little Endian */
/* -------------- */
pseudo_bit_t event_counter2[0x00020];/* Read/write event counter, counting events specified by EvCntl and EvCnt2 fields repsectively. When the event counter reaches is maximum value of 0xFFFFFF, the next event will cause it to roll over to zero, set F1 or F2 bit respectively and generate interrupt by I1 I2 bit respectively. */
/* -------------- */
-};
+};
/* MLX WQE segment format */
@@ -751,7 +751,7 @@ struct hermonprm_wqe_segment_ctrl_mlx_st { /* Little Endian */
pseudo_bit_t reserved5[0x00010];
pseudo_bit_t rlid[0x00010]; /* Destination LID (must match given headers) */
/* -------------- */
-};
+};
/* Send WQE segment format */
@@ -780,7 +780,7 @@ struct hermonprm_send_wqe_segment_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved1[0x00200];
/* -------------- */
-};
+};
/* QP and EE Context Entry */
@@ -833,7 +833,7 @@ struct hermonprm_queue_pair_ee_context_entry_st { /* Little Endian */
0x3 - 1024
0x4 - 2048
other - reserved
-
+
Should be configured to 0x4 for UD and MLX QPs. */
/* -------------- */
pseudo_bit_t usr_page[0x00018]; /* UAR number to ring doorbells for this QP (aliased to doorbell and Blue Flame pages) */
@@ -883,7 +883,7 @@ struct hermonprm_queue_pair_ee_context_entry_st { /* Little Endian */
pseudo_bit_t reserved24[0x00008];
/* -------------- */
pseudo_bit_t reserved25[0x00004];
- pseudo_bit_t ric[0x00001]; /* Invalid Credits.
+ pseudo_bit_t ric[0x00001]; /* Invalid Credits.
1 - place "Invalid Credits" to ACKs sent from this queue.
0 - ACKs report the actual number of end to end credits on the connection.
Not valid (reserved) in EE context.
@@ -895,12 +895,12 @@ struct hermonprm_queue_pair_ee_context_entry_st { /* Little Endian */
pseudo_bit_t rwe[0x00001]; /* If set - RDMA - write enabled on receive queue. Not valid (reserved) in EE context. */
pseudo_bit_t rre[0x00001]; /* If set - RDMA - read enabled on receive queue. Not valid (reserved) in EE context. */
pseudo_bit_t reserved28[0x00005];
- pseudo_bit_t rra_max[0x00003]; /* Maximum number of outstanding RDMA-read/Atomic operations allowed on receive queue is 2^RRA_Max.
+ pseudo_bit_t rra_max[0x00003]; /* Maximum number of outstanding RDMA-read/Atomic operations allowed on receive queue is 2^RRA_Max.
Must be 0 for EE context. */
pseudo_bit_t physical_function[0x00008];
/* -------------- */
pseudo_bit_t next_rcv_psn[0x00018]; /* Next (expected) PSN on receive */
- pseudo_bit_t min_rnr_nak[0x00005]; /* Minimum RNR NAK timer value (TTTTT field encoding according to the IB spec Vol1 9.7.5.2.8).
+ pseudo_bit_t min_rnr_nak[0x00005]; /* Minimum RNR NAK timer value (TTTTT field encoding according to the IB spec Vol1 9.7.5.2.8).
Not valid (reserved) in EE context. */
pseudo_bit_t reserved30[0x00003];
/* -------------- */
@@ -919,7 +919,7 @@ struct hermonprm_queue_pair_ee_context_entry_st { /* Little Endian */
On send datagrams, if Q_Key[31] specified in the WQE is set, then this Q_Key will be transmitted in the outgoing message.
Not valid (reserved) in EE context. */
/* -------------- */
- pseudo_bit_t srqn[0x00018]; /* SRQN - Shared Receive Queue Number - specifies the SRQ number from which the QP dequeues receive descriptors.
+ pseudo_bit_t srqn[0x00018]; /* SRQN - Shared Receive Queue Number - specifies the SRQ number from which the QP dequeues receive descriptors.
SRQN is valid only if SRQ bit is set. Not valid (reserved) in EE context. */
pseudo_bit_t srq[0x00001]; /* SRQ - Shared Receive Queue. If this bit is set, then the QP is associated with a SRQ. Not valid (reserved) in EE context. */
pseudo_bit_t reserved34[0x00007];
@@ -983,7 +983,7 @@ struct hermonprm_queue_pair_ee_context_entry_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved48[0x000c0];
/* -------------- */
-};
+};
/* */
@@ -993,21 +993,21 @@ struct hermonprm_mcg_qp_dw_st { /* Little Endian */
pseudo_bit_t blck_lb[0x00001];
pseudo_bit_t reserved1[0x00001];
/* -------------- */
-};
+};
/* Clear Interrupt [63:0] #### michal - match to PRM */
struct hermonprm_clr_int_st { /* Little Endian */
pseudo_bit_t clr_int_h[0x00020]; /* Clear Interrupt [63:32]
- Write transactions to this register will clear (de-assert) the virtual interrupt output pins of InfiniHost-III-EX. The value to be written in this register is obtained by executing QUERY_ADAPTER command on command interface after system boot.
+ Write transactions to this register will clear (de-assert) the virtual interrupt output pins of InfiniHost-III-EX. The value to be written in this register is obtained by executing QUERY_ADAPTER command on command interface after system boot.
This register is write-only. Reading from this register will cause undefined result
*/
/* -------------- */
pseudo_bit_t clr_int_l[0x00020]; /* Clear Interrupt [31:0]
- Write transactions to this register will clear (de-assert) the virtual interrupt output pins of InfiniHost-III-EX. The value to be written in this register is obtained by executing QUERY_ADAPTER command on command interface after system boot.
+ Write transactions to this register will clear (de-assert) the virtual interrupt output pins of InfiniHost-III-EX. The value to be written in this register is obtained by executing QUERY_ADAPTER command on command interface after system boot.
This register is write-only. Reading from this register will cause undefined result */
/* -------------- */
-};
+};
/* EQ Set CI DBs Table */
@@ -1268,7 +1268,7 @@ struct hermonprm_eq_set_ci_table_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved63[0x00020];
/* -------------- */
-};
+};
/* InfiniHost-III-EX Configuration Registers #### michal - match to PRM */
@@ -1279,7 +1279,7 @@ struct hermonprm_configuration_registers_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved1[0x3fcb20];
/* -------------- */
-};
+};
/* QP_DB_Record ### michal = gdror fixed */
@@ -1287,7 +1287,7 @@ struct hermonprm_qp_db_record_st { /* Little Endian */
pseudo_bit_t receive_wqe_counter[0x00010];/* Modulo-64K counter of WQEs posted to the QP since its creation. Should be initialized to zero. */
pseudo_bit_t reserved0[0x00010];
/* -------------- */
-};
+};
/* CQ_ARM_DB_Record */
@@ -1303,7 +1303,7 @@ struct hermonprm_cq_arm_db_record_st { /* Little Endian */
pseudo_bit_t res[0x00003]; /* Must be 0x2 */
pseudo_bit_t cq_number[0x00018]; /* CQ number */
/* -------------- */
-};
+};
/* CQ_CI_DB_Record */
@@ -1314,7 +1314,7 @@ struct hermonprm_cq_ci_db_record_st { /* Little Endian */
pseudo_bit_t res[0x00003]; /* Must be 0x1 */
pseudo_bit_t cq_number[0x00018]; /* CQ number */
/* -------------- */
-};
+};
/* Virtual_Physical_Mapping */
@@ -1330,7 +1330,7 @@ struct hermonprm_virtual_physical_mapping_st { /* Little Endian */
pseudo_bit_t reserved1[0x00006];
pseudo_bit_t pa_l[0x00014]; /* Physical Address[31:12] */
/* -------------- */
-};
+};
/* MOD_STAT_CFG #### michal - gdror fix */
@@ -1518,7 +1518,7 @@ struct hermonprm_srq_context_st { /* Little Endian */
pseudo_bit_t reserved10[0x00002];
pseudo_bit_t db_record_addr_l[0x0001e];/* SRQ DB Record physical address [31:2] */
/* -------------- */
-};
+};
/* PBL */
@@ -1539,7 +1539,7 @@ struct hermonprm_pbl_st { /* Little Endian */
/* -------------- */
pseudo_bit_t mtt_3_l[0x00020]; /* Fourth MTT[31:0] */
/* -------------- */
-};
+};
/* Performance Counters #### michal - gdror fixed */
@@ -1554,7 +1554,7 @@ struct hermonprm_performance_counters_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved4[0x00620];
/* -------------- */
-};
+};
/* Transport and CI Error Counters */
@@ -1575,10 +1575,10 @@ struct hermonprm_transport_and_ci_error_counters_st { /* Little Endian */
/* -------------- */
pseudo_bit_t sq_num_lpe[0x00020]; /* Requester - number of local protection errors */
/* -------------- */
- pseudo_bit_t rq_num_wrfe[0x00020]; /* Responder - number of CQEs with error.
+ pseudo_bit_t rq_num_wrfe[0x00020]; /* Responder - number of CQEs with error.
Incremented each time a CQE with error is generated */
/* -------------- */
- pseudo_bit_t sq_num_wrfe[0x00020]; /* Requester - number of CQEs with error.
+ pseudo_bit_t sq_num_wrfe[0x00020]; /* Requester - number of CQEs with error.
Incremented each time a CQE with error is generated */
/* -------------- */
pseudo_bit_t reserved0[0x00020];
@@ -1698,7 +1698,7 @@ struct hermonprm_transport_and_ci_error_counters_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved12[0x002a0];
/* -------------- */
-};
+};
/* Event_data Field - HCR Completion Event #### michal - match PRM */
@@ -1717,7 +1717,7 @@ struct hermonprm_hcr_completion_event_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved3[0x00020];
/* -------------- */
-};
+};
/* Completion with Error CQE #### michal - gdror fixed */
@@ -1732,7 +1732,7 @@ struct hermonprm_completion_with_error_st { /* Little Endian */
0x02 - Local QP Operation Error
0x03 - Local EE Context Operation Error
0x04 - Local Protection Error
- 0x05 - Work Request Flushed Error
+ 0x05 - Work Request Flushed Error
0x06 - Memory Window Bind Error
0x10 - Bad Response Error
0x11 - Local Access Error
@@ -1752,7 +1752,7 @@ struct hermonprm_completion_with_error_st { /* Little Endian */
pseudo_bit_t wqe_counter[0x00010];
/* -------------- */
pseudo_bit_t opcode[0x00005]; /* The opcode of WQE completion is reported for.
-
+
The following values are reported in case of completion with error:
0xFE - For completion with error on Receive Queues
0xFF - For completion with error on Send Queues */
@@ -1761,7 +1761,7 @@ struct hermonprm_completion_with_error_st { /* Little Endian */
pseudo_bit_t owner[0x00001]; /* HW Flips this bit for every CQ warp around. Initialized to Zero. */
pseudo_bit_t reserved3[0x00018];
/* -------------- */
-};
+};
/* Resize CQ Input Mailbox */
@@ -1790,7 +1790,7 @@ struct hermonprm_resize_cq_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved10[0x00100];
/* -------------- */
-};
+};
/* MAD_IFC Input Modifier */
@@ -1802,14 +1802,14 @@ struct hermonprm_mad_ifc_input_modifier_st { /* Little Endian */
pseudo_bit_t rlid[0x00010]; /* Remote (source) LID from the received MAD.
This field is required for trap generation upon MKey/BKey validation. */
/* -------------- */
-};
+};
/* MAD_IFC Input Mailbox ###michal -gdror fixed */
struct hermonprm_mad_ifc_st { /* Little Endian */
pseudo_bit_t request_mad_packet[64][0x00020];/* Request MAD Packet (256bytes) */
/* -------------- */
- pseudo_bit_t my_qpn[0x00018]; /* Destination QP number from the received MAD.
+ pseudo_bit_t my_qpn[0x00018]; /* Destination QP number from the received MAD.
This field is reserved if Mad_extended_info indication in the input modifier is clear. */
pseudo_bit_t reserved0[0x00008];
/* -------------- */
@@ -1822,25 +1822,25 @@ struct hermonprm_mad_ifc_st { /* Little Endian */
pseudo_bit_t reserved3[0x00010];
pseudo_bit_t ml_path[0x00007]; /* My (destination) LID path bits from the received MAD.
This field is reserved if Mad_extended_info indication in the input modifier is clear. */
- pseudo_bit_t g[0x00001]; /* If set, the GRH field in valid.
+ pseudo_bit_t g[0x00001]; /* If set, the GRH field in valid.
This field is reserved if Mad_extended_info indication in the input modifier is clear. */
pseudo_bit_t reserved4[0x00004];
pseudo_bit_t sl[0x00004]; /* Service Level of the received MAD.
This field is reserved if Mad_extended_info indication in the input modifier is clear. */
/* -------------- */
- pseudo_bit_t pkey_indx[0x00010]; /* Index in PKey table that matches PKey of the received MAD.
+ pseudo_bit_t pkey_indx[0x00010]; /* Index in PKey table that matches PKey of the received MAD.
This field is reserved if Mad_extended_info indication in the input modifier is clear. */
pseudo_bit_t reserved5[0x00010];
/* -------------- */
pseudo_bit_t reserved6[0x00160];
/* -------------- */
- pseudo_bit_t grh[10][0x00020]; /* The GRH field of the MAD packet that was scattered to the first 40 bytes pointed to by the scatter list.
- Valid if Mad_extended_info bit (in the input modifier) and g bit are set.
+ pseudo_bit_t grh[10][0x00020]; /* The GRH field of the MAD packet that was scattered to the first 40 bytes pointed to by the scatter list.
+ Valid if Mad_extended_info bit (in the input modifier) and g bit are set.
Otherwise this field is reserved. */
/* -------------- */
pseudo_bit_t reserved7[0x004c0];
/* -------------- */
-};
+};
/* Query Debug Message #### michal - gdror fixed */
@@ -1899,7 +1899,7 @@ struct hermonprm_query_debug_msg_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved4[0x003c0];
/* -------------- */
-};
+};
/* User Access Region */
@@ -1914,7 +1914,7 @@ struct hermonprm_uar_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved1[0x03ec0];
/* -------------- */
-};
+};
/* Receive doorbell */
@@ -1928,7 +1928,7 @@ struct hermonprm_receive_doorbell_st { /* Little Endian */
pseudo_bit_t reserved3[0x00002];
pseudo_bit_t qpn[0x00018]; /* QP number or SRQ number this doorbell is rung on */
/* -------------- */
-};
+};
/* SET_IB Parameters */
@@ -1949,7 +1949,7 @@ struct hermonprm_set_ib_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved2[0x00180];
/* -------------- */
-};
+};
/* Multicast Group Member #### michal - gdror fixed */
@@ -1989,7 +1989,7 @@ struct hermonprm_mgm_entry_st { /* Little Endian */
/* -------------- */
struct hermonprm_mgmqp_st mgmqp_7; /* Multicast Group Member QP */
/* -------------- */
-};
+};
/* INIT_PORT Parameters #### michal - match PRM */
@@ -2041,7 +2041,7 @@ struct hermonprm_init_port_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved5[0x006c0];
/* -------------- */
-};
+};
/* Query Device Capablities #### michal - gdror fixed */
@@ -2267,7 +2267,7 @@ struct hermonprm_query_dev_cap_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved46[0x002c0];
/* -------------- */
-};
+};
/* QUERY_ADAPTER Parameters Block #### michal - gdror fixed */
@@ -2281,7 +2281,7 @@ struct hermonprm_query_adapter_st { /* Little Endian */
/* -------------- */
struct hermonprm_vsd_st vsd; /* ###michal- this field was replaced by 2 fields : vsd .1664; vsd(continued/psid .128; */
/* -------------- */
-};
+};
/* QUERY_FW Parameters Block #### michal - doesn't match PRM */
@@ -2298,7 +2298,7 @@ struct hermonprm_query_fw_st { /* Little Endian */
pseudo_bit_t log_max_outstanding_cmd[0x00008];/* Log2 of the maximum number of commands the HCR can support simultaneously */
pseudo_bit_t reserved1[0x00017];
pseudo_bit_t dt[0x00001]; /* Debug Trace Support
- 0 - Debug trace is not supported
+ 0 - Debug trace is not supported
1 - Debug trace is supported */
/* -------------- */
pseudo_bit_t reserved2[0x00001];
@@ -2346,7 +2346,7 @@ struct hermonprm_query_fw_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved8[0x00600];
/* -------------- */
-};
+};
/* Memory Access Parameters for UD Address Vector Table */
@@ -2358,7 +2358,7 @@ struct hermonprm_udavtable_memory_parameters_st { /* Little Endian */
pseudo_bit_t xlation_en[0x00001]; /* When cleared, address is physical address and no translation will be done. When set, address is virtual. */
pseudo_bit_t reserved1[0x00002];
/* -------------- */
-};
+};
/* INIT_HCA & QUERY_HCA Parameters Block ####michal-doesn't match PRM (see differs below) new size in bytes:0x300 */
@@ -2407,7 +2407,7 @@ struct hermonprm_init_hca_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved10[0x00600];
/* -------------- */
-};
+};
/* Event Queue Context Table Entry #### michal - gdror fixed */
@@ -2454,19 +2454,19 @@ struct hermonprm_eqc_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved12[0x00040];
/* -------------- */
- pseudo_bit_t consumer_counter[0x00018];/* Consumer counter. The counter is incremented for each EQE polled from the EQ.
- Must be 0x0 in EQ initialization.
+ pseudo_bit_t consumer_counter[0x00018];/* Consumer counter. The counter is incremented for each EQE polled from the EQ.
+ Must be 0x0 in EQ initialization.
Maintained by HW (valid for the QUERY_EQ command only). */
pseudo_bit_t reserved13[0x00008];
/* -------------- */
- pseudo_bit_t producer_counter[0x00018];/* Producer Coutner. The counter is incremented for each EQE that is written by the HW to the EQ.
+ pseudo_bit_t producer_counter[0x00018];/* Producer Coutner. The counter is incremented for each EQE that is written by the HW to the EQ.
EQ overrun is reported if Producer_counter + 1 equals to Consumer_counter and a EQE needs to be added.
Maintained by HW (valid for the QUERY_EQ command only) */
pseudo_bit_t reserved14[0x00008];
/* -------------- */
pseudo_bit_t reserved15[0x00080];
/* -------------- */
-};
+};
/* Memory Translation Table (MTT) Entry #### michal - match to PRM */
@@ -2477,7 +2477,7 @@ struct hermonprm_mtt_st { /* Little Endian */
pseudo_bit_t reserved0[0x00002];
pseudo_bit_t ptag_l[0x0001d]; /* Low-order bits of Physical tag. The size of the field depends on the page size of the region. Maximum PTAG size is 52 bits. */
/* -------------- */
-};
+};
/* Memory Protection Table (MPT) Entry ### doesn't match PRM (new fields were added). new size in bytes : 0x54 */
@@ -2547,7 +2547,7 @@ struct hermonprm_mpt_st { /* Little Endian */
pseudo_bit_t mtt_fbo[0x00015]; /* First byte offset in the zero-based region - the first byte within the first block/page start address refers to. When mtt_rep is being used, fbo points within the replicated block (i.e. block-size x 2^mtt_rep) */
pseudo_bit_t reserved10[0x0000b];
/* -------------- */
-};
+};
/* Completion Queue Context Table Entry #### michal - match PRM */
@@ -2559,7 +2559,7 @@ struct hermonprm_completion_queue_context_st { /* Little Endian */
0x6 - ARMED SOLICITED (Request Solicited Notification)
0xA - FIRED
other - reserved
-
+
Must be 0x0 in CQ initialization.
Valid for the QUERY_CQ and HW2SW_CQ commands only. */
pseudo_bit_t reserved1[0x00005];
@@ -2605,7 +2605,7 @@ struct hermonprm_completion_queue_context_st { /* Little Endian */
pseudo_bit_t reserved11[0x00008];
/* -------------- */
pseudo_bit_t solicit_producer_indx[0x00018];/* Maintained by HW.
- Valid for QUERY_CQ and HW2SW_CQ commands only.
+ Valid for QUERY_CQ and HW2SW_CQ commands only.
*/
pseudo_bit_t reserved12[0x00008];
/* -------------- */
@@ -2627,7 +2627,7 @@ struct hermonprm_completion_queue_context_st { /* Little Endian */
pseudo_bit_t reserved17[0x00003];
pseudo_bit_t db_record_addr_l[0x0001d];/* CQ DB Record physical address [31:3] */
/* -------------- */
-};
+};
/* GPIO_event_data #### michal - gdror fixed */
@@ -2640,7 +2640,7 @@ struct hermonprm_gpio_event_data_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved1[0x00020];
/* -------------- */
-};
+};
/* Event_data Field - QP/EE Events #### michal - doesn't match PRM */
@@ -2657,7 +2657,7 @@ struct hermonprm_qp_ee_event_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved4[0x00060];
/* -------------- */
-};
+};
/* InfiniHost-III-EX Type0 Configuration Header ####michal - doesn't match PRM (new fields added, see below) */
@@ -2803,19 +2803,19 @@ struct hermonprm_mt25208_type0_st { /* Little Endian */
/* -------------- */
pseudo_bit_t uncorrectable_error_status_register[0x00020];/* 0 Training Error Status
4 Data Link Protocol Error Status
- 12 Poisoned TLP Status
- 13 Flow Control Protocol Error Status
- 14 Completion Timeout Status
- 15 Completer Abort Status
- 16 Unexpected Completion Status
- 17 Receiver Overflow Status
- 18 Malformed TLP Status
- 19 ECRC Error Status
+ 12 Poisoned TLP Status
+ 13 Flow Control Protocol Error Status
+ 14 Completion Timeout Status
+ 15 Completer Abort Status
+ 16 Unexpected Completion Status
+ 17 Receiver Overflow Status
+ 18 Malformed TLP Status
+ 19 ECRC Error Status
20 Unsupported Request Error Status */
/* -------------- */
pseudo_bit_t uncorrectable_error_mask_register[0x00020];/* 0 Training Error Mask
4 Data Link Protocol Error Mask
- 12 Poisoned TLP Mask
+ 12 Poisoned TLP Mask
13 Flow Control Protocol Error Mask
14 Completion Timeout Mask
15 Completer Abort Mask
@@ -2855,7 +2855,7 @@ struct hermonprm_mt25208_type0_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved13[0x006a0];
/* -------------- */
-};
+};
/* Event Data Field - Performance Monitor */
@@ -2873,7 +2873,7 @@ struct hermonprm_performance_monitor_event_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved1[0x00040];
/* -------------- */
-};
+};
/* Event_data Field - Page Faults */
@@ -2897,7 +2897,7 @@ struct hermonprm_page_fault_event_data_st { /* Little Endian */
/* -------------- */
pseudo_bit_t prefetch_len[0x00020]; /* Indicates how many subsequent pages in the same memory region/window will be accessed by the following transaction after this page fault is resolved. measured in bytes. SW can use this information in order to page-in the subsequent pages if they are not present. */
/* -------------- */
-};
+};
/* WQE segments format */
@@ -2914,7 +2914,7 @@ struct hermonprm_wqe_segment_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved2[0x00080];
/* -------------- */
-};
+};
/* Event_data Field - Port State Change #### michal - match PRM */
@@ -2927,7 +2927,7 @@ struct hermonprm_port_state_change_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved3[0x00060];
/* -------------- */
-};
+};
/* Event_data Field - Completion Queue Error #### michal - match PRM */
@@ -2944,7 +2944,7 @@ struct hermonprm_completion_queue_error_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved3[0x00060];
/* -------------- */
-};
+};
/* Event_data Field - Completion Event #### michal - match PRM */
@@ -2954,12 +2954,12 @@ struct hermonprm_completion_event_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved1[0x000a0];
/* -------------- */
-};
+};
/* Event Queue Entry #### michal - match to PRM */
struct hermonprm_event_queue_entry_st { /* Little Endian */
- pseudo_bit_t event_sub_type[0x00008];/* Event Sub Type.
+ pseudo_bit_t event_sub_type[0x00008];/* Event Sub Type.
Defined for events which have sub types, zero elsewhere. */
pseudo_bit_t reserved0[0x00008];
pseudo_bit_t event_type[0x00008]; /* Event Type */
@@ -2968,12 +2968,12 @@ struct hermonprm_event_queue_entry_st { /* Little Endian */
pseudo_bit_t event_data[6][0x00020];/* Delivers auxilary data to handle event. */
/* -------------- */
pseudo_bit_t reserved2[0x00007];
- pseudo_bit_t owner[0x00001]; /* Owner of the entry
- 0 SW
+ pseudo_bit_t owner[0x00001]; /* Owner of the entry
+ 0 SW
1 HW */
pseudo_bit_t reserved3[0x00018];
/* -------------- */
-};
+};
/* QP/EE State Transitions Command Parameters ###michal - doesn't match PRM (field name changed) */
@@ -2986,7 +2986,7 @@ struct hermonprm_qp_ee_state_transitions_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved1[0x00800];
/* -------------- */
-};
+};
/* Completion Queue Entry Format #### michal - fixed by gdror */
@@ -3010,7 +3010,7 @@ struct hermonprm_completion_queue_entry_st { /* Little Endian */
For IPoIB (UD) and RawEth CQEs this field contains the RSS hash function value.
Otherwise, this field is reserved. */
/* -------------- */
- pseudo_bit_t srq_rqpn[0x00018]; /* For Responder UD QPs, Remote (source) QP number.
+ pseudo_bit_t srq_rqpn[0x00018]; /* For Responder UD QPs, Remote (source) QP number.
For Responder SRC QPs, SRQ number.
Otherwise, this field is reserved. */
pseudo_bit_t ml_path_mac_index[0x00007];/* For responder UD over IB CQE: These are the lower LMC bits of the DLID in an incoming UD packet, higher bits of this field, that are not part of the LMC bits are zeroed by HW. Invalid if incoming message DLID is the permissive LID or incoming message is multicast.
@@ -3028,17 +3028,17 @@ struct hermonprm_completion_queue_entry_st { /* Little Endian */
For responder UD over Ethernet and RawEth - it is VLAN-header[15:12]
Otherwise, this field is reserved. */
/* -------------- */
- pseudo_bit_t smac31_0_rawether_ipoib_status[0x00020];/* For responder UD over Ethernet - source MAC[31:0] of the packet.
- For responder RawEth and UD over IB - RawEth-IPoIB status {3 reserved, ipok,udp,tcp,ipv4opt,ipv6,ipv4vf,ipv4,rht(6),ipv6extmask(6),reserved(2),l2am,reserved(2),bfcs,reserved(2),enc}
+ pseudo_bit_t smac31_0_rawether_ipoib_status[0x00020];/* For responder UD over Ethernet - source MAC[31:0] of the packet.
+ For responder RawEth and UD over IB - RawEth-IPoIB status {3 reserved, ipok,udp,tcp,ipv4opt,ipv6,ipv4vf,ipv4,rht(6),ipv6extmask(6),reserved(2),l2am,reserved(2),bfcs,reserved(2),enc}
Otherwise, this field is reserved. */
/* -------------- */
- pseudo_bit_t byte_cnt[0x00020]; /* Byte count of data transferred. Applicable for RDMA-read, Atomic and all receive operations. completions.
+ pseudo_bit_t byte_cnt[0x00020]; /* Byte count of data transferred. Applicable for RDMA-read, Atomic and all receive operations. completions.
For Receive Queue that is subject for headers. separation, byte_cnt[31:24] specify number of bytes scattered to the first scatter entry (headers. length). Byte_cnt[23:0] specify total byte count received (including headers). */
/* -------------- */
pseudo_bit_t checksum[0x00010]; /* Valid for RawEth and IPoIB only. */
pseudo_bit_t wqe_counter[0x00010];
/* -------------- */
- pseudo_bit_t opcode[0x00005]; /* Send completions - same encoding as WQE.
+ pseudo_bit_t opcode[0x00005]; /* Send completions - same encoding as WQE.
Error coding is 0x1F
Receive:
0x0 - RDMA-Write with Immediate
@@ -3052,14 +3052,14 @@ struct hermonprm_completion_queue_entry_st { /* Little Endian */
pseudo_bit_t reserved1[0x00010];
pseudo_bit_t reserved2[0x00008];
/* -------------- */
-};
+};
/* */
struct hermonprm_mcg_qps_st { /* Little Endian */
struct hermonprm_mcg_qp_dw_st dw[128];
/* -------------- */
-};
+};
/* */
@@ -3084,7 +3084,7 @@ struct hermonprm_mcg_hdr_st { /* Little Endian */
/* -------------- */
pseudo_bit_t gid0[0x00020];
/* -------------- */
-};
+};
/* */
@@ -3096,7 +3096,7 @@ struct hermonprm_sched_queue_context_st { /* Little Endian */
pseudo_bit_t reserved0[0x00006];
pseudo_bit_t weight[0x00010]; /* Weight of this SchQ */
/* -------------- */
-};
+};
/* */
@@ -3117,7 +3117,7 @@ struct hermonprm_ecc_detect_event_data_st { /* Little Endian */
pseudo_bit_t err_ra[0x00010];
pseudo_bit_t err_ca[0x00010];
/* -------------- */
-};
+};
/* Event_data Field - ECC Detection Event */
@@ -3142,14 +3142,14 @@ struct hermonprm_scrubbing_event_st { /* Little Endian */
pseudo_bit_t err_ra[0x00010]; /* Error row address */
pseudo_bit_t err_ca[0x00010]; /* Error column address */
/* -------------- */
-};
+};
/* */
struct hermonprm_eq_cmd_doorbell_st { /* Little Endian */
pseudo_bit_t reserved0[0x00020];
/* -------------- */
-};
+};
/* 0 */
@@ -3400,5 +3400,5 @@ struct hermonprm_hermon_prm_st { /* Little Endian */
/* -------------- */
pseudo_bit_t reserved64[0xffcfc0];
/* -------------- */
-};
+};
#endif /* H_prefix_hermonprm_bits_fixnames_MT25408_PRM_csp_H */
diff --git a/src/drivers/infiniband/arbel.c b/src/drivers/infiniband/arbel.c
index 98a2b6010..fbef3f8a6 100644
--- a/src/drivers/infiniband/arbel.c
+++ b/src/drivers/infiniband/arbel.c
@@ -639,8 +639,8 @@ static int arbel_create_cq ( struct ib_device *ibdev,
/* Allocate completion queue itself */
arbel_cq->cqe_size = ( cq->num_cqes * sizeof ( arbel_cq->cqe[0] ) );
- arbel_cq->cqe = malloc_dma ( arbel_cq->cqe_size,
- sizeof ( arbel_cq->cqe[0] ) );
+ arbel_cq->cqe = malloc_phys ( arbel_cq->cqe_size,
+ sizeof ( arbel_cq->cqe[0] ) );
if ( ! arbel_cq->cqe ) {
rc = -ENOMEM;
goto err_cqe;
@@ -697,7 +697,7 @@ static int arbel_create_cq ( struct ib_device *ibdev,
err_sw2hw_cq:
MLX_FILL_1 ( ci_db_rec, 1, res, ARBEL_UAR_RES_NONE );
MLX_FILL_1 ( arm_db_rec, 1, res, ARBEL_UAR_RES_NONE );
- free_dma ( arbel_cq->cqe, arbel_cq->cqe_size );
+ free_phys ( arbel_cq->cqe, arbel_cq->cqe_size );
err_cqe:
free ( arbel_cq );
err_arbel_cq:
@@ -737,7 +737,7 @@ static void arbel_destroy_cq ( struct ib_device *ibdev,
MLX_FILL_1 ( arm_db_rec, 1, res, ARBEL_UAR_RES_NONE );
/* Free memory */
- free_dma ( arbel_cq->cqe, arbel_cq->cqe_size );
+ free_phys ( arbel_cq->cqe, arbel_cq->cqe_size );
free ( arbel_cq );
/* Mark queue number as free */
@@ -873,8 +873,8 @@ static int arbel_create_send_wq ( struct arbel_send_work_queue *arbel_send_wq,
/* Allocate work queue */
arbel_send_wq->wqe_size = ( num_wqes *
sizeof ( arbel_send_wq->wqe[0] ) );
- arbel_send_wq->wqe = malloc_dma ( arbel_send_wq->wqe_size,
- sizeof ( arbel_send_wq->wqe[0] ) );
+ arbel_send_wq->wqe = malloc_phys ( arbel_send_wq->wqe_size,
+ sizeof ( arbel_send_wq->wqe[0] ) );
if ( ! arbel_send_wq->wqe )
return -ENOMEM;
memset ( arbel_send_wq->wqe, 0, arbel_send_wq->wqe_size );
@@ -914,8 +914,8 @@ static int arbel_create_recv_wq ( struct arbel_recv_work_queue *arbel_recv_wq,
/* 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] ) );
+ arbel_recv_wq->wqe = malloc_phys ( arbel_recv_wq->wqe_size,
+ sizeof ( arbel_recv_wq->wqe[0] ) );
if ( ! arbel_recv_wq->wqe ) {
rc = -ENOMEM;
goto err_alloc_wqe;
@@ -927,8 +927,8 @@ static int arbel_create_recv_wq ( struct arbel_recv_work_queue *arbel_recv_wq,
( 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 * ) );
+ arbel_recv_wq->grh = malloc_phys ( arbel_recv_wq->grh_size,
+ sizeof ( void * ) );
if ( ! arbel_recv_wq->grh ) {
rc = -ENOMEM;
goto err_alloc_grh;
@@ -954,9 +954,9 @@ 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 );
+ free_phys ( arbel_recv_wq->grh, arbel_recv_wq->grh_size );
err_alloc_grh:
- free_dma ( arbel_recv_wq->wqe, arbel_recv_wq->wqe_size );
+ free_phys ( arbel_recv_wq->wqe, arbel_recv_wq->wqe_size );
err_alloc_wqe:
return rc;
}
@@ -1102,10 +1102,10 @@ 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 );
+ free_phys ( arbel_qp->recv.grh, arbel_qp->recv.grh_size );
+ free_phys ( arbel_qp->recv.wqe, arbel_qp->recv.wqe_size );
err_create_recv_wq:
- free_dma ( arbel_qp->send.wqe, arbel_qp->send.wqe_size );
+ free_phys ( arbel_qp->send.wqe, arbel_qp->send.wqe_size );
err_create_send_wq:
free ( arbel_qp );
err_arbel_qp:
@@ -1231,9 +1231,9 @@ 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_phys ( arbel_qp->recv.grh, arbel_qp->recv.grh_size );
+ free_phys ( arbel_qp->recv.wqe, arbel_qp->recv.wqe_size );
+ free_phys ( arbel_qp->send.wqe, arbel_qp->send.wqe_size );
free ( arbel_qp );
/* Mark queue number as free */
@@ -1758,8 +1758,8 @@ static int arbel_create_eq ( struct arbel *arbel ) {
/* Allocate event queue itself */
arbel_eq->eqe_size =
( ARBEL_NUM_EQES * sizeof ( arbel_eq->eqe[0] ) );
- arbel_eq->eqe = malloc_dma ( arbel_eq->eqe_size,
- sizeof ( arbel_eq->eqe[0] ) );
+ arbel_eq->eqe = malloc_phys ( arbel_eq->eqe_size,
+ sizeof ( arbel_eq->eqe[0] ) );
if ( ! arbel_eq->eqe ) {
rc = -ENOMEM;
goto err_eqe;
@@ -1806,7 +1806,7 @@ static int arbel_create_eq ( struct arbel *arbel ) {
err_map_eq:
arbel_cmd_hw2sw_eq ( arbel, arbel_eq->eqn, &eqctx );
err_sw2hw_eq:
- free_dma ( arbel_eq->eqe, arbel_eq->eqe_size );
+ free_phys ( arbel_eq->eqe, arbel_eq->eqe_size );
err_eqe:
memset ( arbel_eq, 0, sizeof ( *arbel_eq ) );
return rc;
@@ -1844,7 +1844,7 @@ static void arbel_destroy_eq ( struct arbel *arbel ) {
}
/* Free memory */
- free_dma ( arbel_eq->eqe, arbel_eq->eqe_size );
+ free_phys ( arbel_eq->eqe, arbel_eq->eqe_size );
memset ( arbel_eq, 0, sizeof ( *arbel_eq ) );
}
@@ -2059,7 +2059,8 @@ static int arbel_start_firmware ( struct arbel *arbel ) {
eq_set_ci_base_addr =
( ( (uint64_t) MLX_GET ( &fw, eq_set_ci_base_addr_h ) << 32 ) |
( (uint64_t) MLX_GET ( &fw, eq_set_ci_base_addr_l ) ) );
- arbel->eq_ci_doorbells = ioremap ( eq_set_ci_base_addr, 0x200 );
+ arbel->eq_ci_doorbells = pci_ioremap ( arbel->pci, eq_set_ci_base_addr,
+ 0x200 );
/* Enable locally-attached memory. Ignore failure; there may
* be no attached memory.
@@ -2454,7 +2455,7 @@ static int arbel_alloc_icm ( struct arbel *arbel,
icm_phys = user_to_phys ( arbel->icm, 0 );
/* Allocate doorbell UAR */
- arbel->db_rec = malloc_dma ( ARBEL_PAGE_SIZE, ARBEL_PAGE_SIZE );
+ arbel->db_rec = malloc_phys ( ARBEL_PAGE_SIZE, ARBEL_PAGE_SIZE );
if ( ! arbel->db_rec ) {
rc = -ENOMEM;
goto err_alloc_doorbell;
@@ -2512,7 +2513,7 @@ static int arbel_alloc_icm ( struct arbel *arbel,
err_map_icm:
arbel_cmd_unmap_icm_aux ( arbel );
err_map_icm_aux:
- free_dma ( arbel->db_rec, ARBEL_PAGE_SIZE );
+ free_phys ( arbel->db_rec, ARBEL_PAGE_SIZE );
arbel->db_rec= NULL;
err_alloc_doorbell:
err_alloc_icm:
@@ -2535,7 +2536,7 @@ static void arbel_free_icm ( struct arbel *arbel ) {
arbel_cmd_unmap_icm ( arbel, ( arbel->icm_len / ARBEL_PAGE_SIZE ),
&unmap_icm );
arbel_cmd_unmap_icm_aux ( arbel );
- free_dma ( arbel->db_rec, ARBEL_PAGE_SIZE );
+ free_phys ( arbel->db_rec, ARBEL_PAGE_SIZE );
arbel->db_rec = NULL;
}
@@ -2983,18 +2984,18 @@ static struct arbel * arbel_alloc ( void ) {
goto err_arbel;
/* Allocate space for mailboxes */
- arbel->mailbox_in = malloc_dma ( ARBEL_MBOX_SIZE, ARBEL_MBOX_ALIGN );
+ arbel->mailbox_in = malloc_phys ( ARBEL_MBOX_SIZE, ARBEL_MBOX_ALIGN );
if ( ! arbel->mailbox_in )
goto err_mailbox_in;
- arbel->mailbox_out = malloc_dma ( ARBEL_MBOX_SIZE, ARBEL_MBOX_ALIGN );
+ arbel->mailbox_out = malloc_phys ( ARBEL_MBOX_SIZE, ARBEL_MBOX_ALIGN );
if ( ! arbel->mailbox_out )
goto err_mailbox_out;
return arbel;
- free_dma ( arbel->mailbox_out, ARBEL_MBOX_SIZE );
+ free_phys ( arbel->mailbox_out, ARBEL_MBOX_SIZE );
err_mailbox_out:
- free_dma ( arbel->mailbox_in, ARBEL_MBOX_SIZE );
+ free_phys ( arbel->mailbox_in, ARBEL_MBOX_SIZE );
err_mailbox_in:
free ( arbel );
err_arbel:
@@ -3010,8 +3011,8 @@ static void arbel_free ( struct arbel *arbel ) {
ufree ( arbel->icm );
ufree ( arbel->firmware_area );
- free_dma ( arbel->mailbox_out, ARBEL_MBOX_SIZE );
- free_dma ( arbel->mailbox_in, ARBEL_MBOX_SIZE );
+ free_phys ( arbel->mailbox_out, ARBEL_MBOX_SIZE );
+ free_phys ( arbel->mailbox_in, ARBEL_MBOX_SIZE );
free ( arbel );
}
@@ -3025,6 +3026,8 @@ static void arbel_free ( struct arbel *arbel ) {
static int arbel_probe ( struct pci_device *pci ) {
struct arbel *arbel;
struct ib_device *ibdev;
+ unsigned long config;
+ unsigned long uar;
int i;
int rc;
@@ -3041,11 +3044,11 @@ static int arbel_probe ( struct pci_device *pci ) {
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 );
+ config = pci_bar_start ( pci, ARBEL_PCI_CONFIG_BAR );
+ arbel->config = pci_ioremap ( pci, config, ARBEL_PCI_CONFIG_BAR_SIZE );
+ uar = ( pci_bar_start ( pci, ARBEL_PCI_UAR_BAR ) +
+ ARBEL_PCI_UAR_IDX * ARBEL_PCI_UAR_SIZE );
+ arbel->uar = pci_ioremap ( pci, uar, ARBEL_PCI_UAR_SIZE );
/* Allocate Infiniband devices */
for ( i = 0 ; i < ARBEL_NUM_PORTS ; i++ ) {
@@ -3058,6 +3061,7 @@ static int arbel_probe ( struct pci_device *pci ) {
ibdev->op = &arbel_ib_operations;
ibdev->dev = &pci->dev;
ibdev->port = ( ARBEL_PORT_BASE + i );
+ ibdev->ports = ARBEL_NUM_PORTS;
ib_set_drvdata ( ibdev, arbel );
}
diff --git a/src/drivers/infiniband/flexboot_nodnic.c b/src/drivers/infiniband/flexboot_nodnic.c
index 7d039fffc..c6e19b955 100644
--- a/src/drivers/infiniband/flexboot_nodnic.c
+++ b/src/drivers/infiniband/flexboot_nodnic.c
@@ -1165,6 +1165,7 @@ flexboot_nodnic_allocate_infiniband_devices( struct flexboot_nodnic *flexboot_no
ibdev->op = &flexboot_nodnic_ib_operations;
ibdev->dev = &pci->dev;
ibdev->port = ( FLEXBOOT_NODNIC_PORT_BASE + i);
+ ibdev->ports = device_priv->device_cap.num_ports;
ib_set_drvdata(ibdev, flexboot_nodnic_priv);
}
return status;
@@ -1461,7 +1462,7 @@ static int flexboot_nodnic_alloc_uar ( struct flexboot_nodnic *flexboot_nodnic )
return -EINVAL;
}
uar->phys = ( pci_bar_start ( pci, FLEXBOOT_NODNIC_HCA_BAR ) + (mlx_uint32)uar->offset );
- uar->virt = ( void * )( ioremap ( uar->phys, FLEXBOOT_NODNIC_PAGE_SIZE ) );
+ uar->virt = ( void * )( pci_ioremap ( pci, uar->phys, FLEXBOOT_NODNIC_PAGE_SIZE ) );
return status;
}
diff --git a/src/drivers/infiniband/golan.c b/src/drivers/infiniband/golan.c
index e96ba2698..2f1ab2357 100755
--- a/src/drivers/infiniband/golan.c
+++ b/src/drivers/infiniband/golan.c
@@ -585,9 +585,9 @@ static inline int golan_set_access_reg ( struct golan *golan __attribute__ (( un
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);
+ free_phys(golan->mboxes.outbox, GOLAN_PAGE_SIZE);
+ free_phys(golan->mboxes.inbox, GOLAN_PAGE_SIZE);
+ free_phys(golan->cmd.addr, GOLAN_PAGE_SIZE);
}
/**
@@ -602,17 +602,17 @@ 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))) {
+ if (!(golan->cmd.addr = malloc_phys(GOLAN_PAGE_SIZE , GOLAN_PAGE_SIZE))) {
rc = -ENOMEM;
- goto malloc_dma_failed;
+ goto malloc_phys_failed;
}
- if (!(golan->mboxes.inbox = malloc_dma(GOLAN_PAGE_SIZE , GOLAN_PAGE_SIZE))) {
+ if (!(golan->mboxes.inbox = malloc_phys(GOLAN_PAGE_SIZE , GOLAN_PAGE_SIZE))) {
rc = -ENOMEM;
- goto malloc_dma_inbox_failed;
+ goto malloc_phys_inbox_failed;
}
- if (!(golan->mboxes.outbox = malloc_dma(GOLAN_PAGE_SIZE , GOLAN_PAGE_SIZE))) {
+ if (!(golan->mboxes.outbox = malloc_phys(GOLAN_PAGE_SIZE , GOLAN_PAGE_SIZE))) {
rc = -ENOMEM;
- goto malloc_dma_outbox_failed;
+ goto malloc_phys_outbox_failed;
}
addr_l_sz = be32_to_cpu(readl(&golan->iseg->cmdq_addr_l_sz));
@@ -629,11 +629,11 @@ static inline int golan_cmd_init ( struct golan *golan )
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:
+malloc_phys_outbox_failed:
+ free_phys(golan->mboxes.inbox, GOLAN_PAGE_SIZE);
+malloc_phys_inbox_failed:
+ free_phys(golan->cmd.addr, GOLAN_PAGE_SIZE);
+malloc_phys_failed:
DBGC (golan ,"%s Failed to initialize command interface (rc = 0x%x)\n",
__FUNCTION__, rc);
return rc;
@@ -693,7 +693,7 @@ static inline int golan_alloc_uar(struct golan *golan)
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));
+ uar->virt = (void *)(pci_ioremap(golan->pci, uar->phys, GOLAN_PAGE_SIZE));
DBGC( golan , "%s: UAR allocated with index 0x%x\n", __FUNCTION__, uar->index);
return 0;
@@ -743,7 +743,7 @@ static int golan_create_eq(struct golan *golan)
eq->cons_index = 0;
eq->size = GOLAN_NUM_EQES * sizeof(eq->eqes[0]);
- eq->eqes = malloc_dma ( GOLAN_PAGE_SIZE, GOLAN_PAGE_SIZE );
+ eq->eqes = malloc_phys ( GOLAN_PAGE_SIZE, GOLAN_PAGE_SIZE );
if (!eq->eqes) {
rc = -ENOMEM;
goto err_create_eq_eqe_alloc;
@@ -781,7 +781,7 @@ static int golan_create_eq(struct golan *golan)
return 0;
err_create_eq_cmd:
- free_dma ( eq->eqes , GOLAN_PAGE_SIZE );
+ free_phys ( eq->eqes , GOLAN_PAGE_SIZE );
err_create_eq_eqe_alloc:
DBGC (golan ,"%s [%d] out\n", __FUNCTION__, rc);
return rc;
@@ -806,7 +806,7 @@ static void golan_destory_eq(struct golan *golan)
rc = send_command_and_wait(golan, DEF_CMD_IDX, NO_MBOX, NO_MBOX, __FUNCTION__);
GOLAN_PRINT_RC_AND_CMD_STATUS;
- free_dma ( golan->eq.eqes , GOLAN_PAGE_SIZE );
+ free_phys ( golan->eq.eqes , GOLAN_PAGE_SIZE );
golan->eq.eqn = 0;
DBGC( golan, "%s Event queue (0x%x) was destroyed\n", __FUNCTION__, eqn);
@@ -922,8 +922,8 @@ static inline void golan_pci_init(struct golan *golan)
adjust_pci_device ( pci );
/* Get HCA BAR */
- golan->iseg = ioremap ( pci_bar_start ( pci, GOLAN_HCA_BAR),
- GOLAN_PCI_CONFIG_BAR_SIZE );
+ golan->iseg = pci_ioremap ( pci, pci_bar_start ( pci, GOLAN_HCA_BAR),
+ GOLAN_PCI_CONFIG_BAR_SIZE );
}
static inline struct golan *golan_alloc()
@@ -962,14 +962,14 @@ static int golan_create_cq(struct ib_device *ibdev,
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->doorbell_record = malloc_phys(GOLAN_CQ_DB_RECORD_SIZE,
GOLAN_CQ_DB_RECORD_SIZE);
if (!golan_cq->doorbell_record) {
rc = -ENOMEM;
goto err_create_cq_db_alloc;
}
- golan_cq->cqes = malloc_dma ( GOLAN_PAGE_SIZE, GOLAN_PAGE_SIZE );
+ golan_cq->cqes = malloc_phys ( GOLAN_PAGE_SIZE, GOLAN_PAGE_SIZE );
if (!golan_cq->cqes) {
rc = -ENOMEM;
goto err_create_cq_cqe_alloc;
@@ -1008,9 +1008,9 @@ static int golan_create_cq(struct ib_device *ibdev,
return 0;
err_create_cq_cmd:
- free_dma( golan_cq->cqes , GOLAN_PAGE_SIZE );
+ free_phys( golan_cq->cqes , GOLAN_PAGE_SIZE );
err_create_cq_cqe_alloc:
- free_dma(golan_cq->doorbell_record, GOLAN_CQ_DB_RECORD_SIZE);
+ free_phys(golan_cq->doorbell_record, GOLAN_CQ_DB_RECORD_SIZE);
err_create_cq_db_alloc:
free ( golan_cq );
err_create_cq:
@@ -1045,8 +1045,8 @@ static void golan_destroy_cq(struct ib_device *ibdev,
cq->cqn = 0;
ib_cq_set_drvdata(cq, NULL);
- free_dma ( golan_cq->cqes , GOLAN_PAGE_SIZE );
- free_dma(golan_cq->doorbell_record, GOLAN_CQ_DB_RECORD_SIZE);
+ free_phys ( golan_cq->cqes , GOLAN_PAGE_SIZE );
+ free_phys(golan_cq->doorbell_record, GOLAN_CQ_DB_RECORD_SIZE);
free(golan_cq);
DBGC (golan, "%s CQ number 0x%x was destroyed\n", __FUNCTION__, cqn);
@@ -1138,7 +1138,7 @@ static int golan_create_qp_aux(struct ib_device *ibdev,
golan_qp->size = golan_qp->sq.size + golan_qp->rq.size;
/* allocate dma memory for WQEs (1 page is enough) - should change it */
- golan_qp->wqes = malloc_dma ( GOLAN_PAGE_SIZE, GOLAN_PAGE_SIZE );
+ golan_qp->wqes = malloc_phys ( GOLAN_PAGE_SIZE, GOLAN_PAGE_SIZE );
if (!golan_qp->wqes) {
rc = -ENOMEM;
goto err_create_qp_wqe_alloc;
@@ -1160,7 +1160,7 @@ static int golan_create_qp_aux(struct ib_device *ibdev,
data++;
}
- golan_qp->doorbell_record = malloc_dma(sizeof(struct golan_qp_db),
+ golan_qp->doorbell_record = malloc_phys(sizeof(struct golan_qp_db),
sizeof(struct golan_qp_db));
if (!golan_qp->doorbell_record) {
rc = -ENOMEM;
@@ -1213,9 +1213,9 @@ static int golan_create_qp_aux(struct ib_device *ibdev,
return 0;
err_create_qp_cmd:
- free_dma(golan_qp->doorbell_record, sizeof(struct golan_qp_db));
+ free_phys(golan_qp->doorbell_record, sizeof(struct golan_qp_db));
err_create_qp_db_alloc:
- free_dma ( golan_qp->wqes, GOLAN_PAGE_SIZE );
+ free_phys ( golan_qp->wqes, GOLAN_PAGE_SIZE );
err_create_qp_wqe_alloc:
err_create_qp_sq_size:
err_create_qp_sq_wqe_size:
@@ -1422,8 +1422,8 @@ static void golan_destroy_qp(struct ib_device *ibdev,
qp->qpn = 0;
ib_qp_set_drvdata(qp, NULL);
- free_dma(golan_qp->doorbell_record, sizeof(struct golan_qp_db));
- free_dma ( golan_qp->wqes, GOLAN_PAGE_SIZE );
+ free_phys(golan_qp->doorbell_record, sizeof(struct golan_qp_db));
+ free_phys ( golan_qp->wqes, GOLAN_PAGE_SIZE );
free(golan_qp);
DBGC( golan ,"%s QP 0x%lx was destroyed\n", __FUNCTION__, qpn);
@@ -2386,6 +2386,7 @@ static int golan_probe_normal ( struct pci_device *pci ) {
ibdev->op = &golan_ib_operations;
ibdev->dev = &pci->dev;
ibdev->port = (GOLAN_PORT_BASE + i);
+ ibdev->ports = golan->caps.num_ports;
ib_set_drvdata( ibdev, golan );
}
@@ -2642,7 +2643,10 @@ static struct pci_device_id golan_nics[] = {
PCI_ROM ( 0x15b3, 0x1019, "ConnectX-5EX", "ConnectX-5EX HCA driver, DevID 4121", 0 ),
PCI_ROM ( 0x15b3, 0x101b, "ConnectX-6", "ConnectX-6 HCA driver, DevID 4123", 0 ),
PCI_ROM ( 0x15b3, 0x101d, "ConnectX-6DX", "ConnectX-6DX HCA driver, DevID 4125", 0 ),
+ PCI_ROM ( 0x15b3, 0x101f, "ConnectX-6Lx", "ConnectX-6LX HCA driver, DevID 4127", 0 ),
+ PCI_ROM ( 0x15b3, 0x1021, "ConnectX-7", "ConnectX-7 HCA driver, DevID 4129", 0 ),
PCI_ROM ( 0x15b3, 0xa2d2, "BlueField", "BlueField integrated ConnectX-5 network controller HCA driver, DevID 41682", 0 ),
+ PCI_ROM ( 0x15b3, 0xa2d6, "BlueField-2", "BlueField-2 network controller HCA driver, DevID 41686", 0 ),
};
struct pci_driver golan_driver __pci_driver = {
diff --git a/src/drivers/infiniband/hermon.c b/src/drivers/infiniband/hermon.c
index 9675c156b..2afaaf991 100644
--- a/src/drivers/infiniband/hermon.c
+++ b/src/drivers/infiniband/hermon.c
@@ -137,13 +137,13 @@ static int hermon_cmd_wait ( struct hermon *hermon,
struct hermonprm_hca_command_register *hcr ) {
unsigned int wait;
- for ( wait = HERMON_HCR_MAX_WAIT_MS ; wait ; wait-- ) {
+ for ( wait = ( 100 * HERMON_HCR_MAX_WAIT_MS ) ; wait ; wait-- ) {
hcr->u.dwords[6] =
readl ( hermon->config + HERMON_HCR_REG ( 6 ) );
if ( ( MLX_GET ( hcr, go ) == 0 ) &&
( MLX_GET ( hcr, t ) == hermon->toggle ) )
return 0;
- mdelay ( 1 );
+ udelay ( 10 );
}
return -EBUSY;
}
@@ -175,7 +175,7 @@ static int hermon_cmd ( struct hermon *hermon, unsigned long command,
assert ( in_len <= HERMON_MBOX_SIZE );
assert ( out_len <= HERMON_MBOX_SIZE );
- DBGC2 ( hermon, "Hermon %p command %02x in %zx%s out %zx%s\n",
+ DBGC2 ( hermon, "Hermon %p command %04x in %zx%s out %zx%s\n",
hermon, opcode, in_len,
( ( command & HERMON_HCR_IN_MBOX ) ? "(mbox)" : "" ), out_len,
( ( command & HERMON_HCR_OUT_MBOX ) ? "(mbox)" : "" ) );
@@ -214,8 +214,6 @@ static int hermon_cmd ( struct hermon *hermon, unsigned long command,
opcode_modifier, op_mod,
go, 1,
t, hermon->toggle );
- DBGC ( hermon, "Hermon %p issuing command %04x\n",
- hermon, opcode );
DBGC2_HDA ( hermon, virt_to_phys ( hermon->config + HERMON_HCR_BASE ),
&hcr, sizeof ( hcr ) );
if ( in_len && ( command & HERMON_HCR_IN_MBOX ) ) {
@@ -234,8 +232,8 @@ static int hermon_cmd ( struct hermon *hermon, unsigned long command,
/* Wait for command completion */
if ( ( rc = hermon_cmd_wait ( hermon, &hcr ) ) != 0 ) {
- DBGC ( hermon, "Hermon %p timed out waiting for command:\n",
- hermon );
+ DBGC ( hermon, "Hermon %p timed out waiting for command "
+ "%04x:\n", hermon, opcode );
DBGC_HDA ( hermon,
virt_to_phys ( hermon->config + HERMON_HCR_BASE ),
&hcr, sizeof ( hcr ) );
@@ -245,8 +243,8 @@ static int hermon_cmd ( struct hermon *hermon, unsigned long command,
/* Check command status */
status = MLX_GET ( &hcr, status );
if ( status != 0 ) {
- DBGC ( hermon, "Hermon %p command failed with status %02x:\n",
- hermon, status );
+ DBGC ( hermon, "Hermon %p command %04x failed with status "
+ "%02x:\n", hermon, opcode, status );
DBGC_HDA ( hermon,
virt_to_phys ( hermon->config + HERMON_HCR_BASE ),
&hcr, sizeof ( hcr ) );
@@ -334,6 +332,13 @@ hermon_cmd_sw2hw_mpt ( struct hermon *hermon, unsigned int index,
}
static inline int
+hermon_cmd_hw2sw_mpt ( struct hermon *hermon, unsigned int index ) {
+ return hermon_cmd ( hermon,
+ HERMON_HCR_VOID_CMD ( HERMON_HCR_HW2SW_MPT ),
+ 0, NULL, index, NULL );
+}
+
+static inline int
hermon_cmd_write_mtt ( struct hermon *hermon,
const struct hermonprm_write_mtt *write_mtt ) {
return hermon_cmd ( hermon,
@@ -638,9 +643,9 @@ static int hermon_alloc_mtt ( struct hermon *hermon,
mtt_offset = hermon_bitmask_alloc ( hermon->mtt_inuse, HERMON_MAX_MTTS,
num_pages );
if ( mtt_offset < 0 ) {
- DBGC ( hermon, "Hermon %p could not allocate %d MTT entries\n",
- hermon, num_pages );
rc = mtt_offset;
+ DBGC ( hermon, "Hermon %p could not allocate %d MTT entries: "
+ "%s\n", hermon, num_pages, strerror ( rc ) );
goto err_mtt_offset;
}
mtt_base_addr = ( ( hermon->cap.reserved_mtts + mtt_offset ) *
@@ -664,8 +669,9 @@ static int hermon_alloc_mtt ( struct hermon *hermon,
ptag_l, ( addr >> 3 ) );
if ( ( rc = hermon_cmd_write_mtt ( hermon,
&write_mtt ) ) != 0 ) {
- DBGC ( hermon, "Hermon %p could not write MTT at %x\n",
- hermon, mtt_base_addr );
+ DBGC ( hermon, "Hermon %p could not write MTT at %x: "
+ "%s\n", hermon, mtt_base_addr,
+ strerror ( rc ) );
goto err_write_mtt;
}
addr += HERMON_PAGE_SIZE;
@@ -817,6 +823,11 @@ hermon_dump_cqctx ( struct hermon *hermon, struct ib_completion_queue *cq ) {
struct hermonprm_completion_queue_context cqctx;
int rc;
+ /* Do nothing unless debugging is enabled */
+ if ( ! DBG_LOG )
+ return 0;
+
+ /* Dump completion queue context */
memset ( &cqctx, 0, sizeof ( cqctx ) );
if ( ( rc = hermon_cmd_query_cq ( hermon, cq->cqn, &cqctx ) ) != 0 ) {
DBGC ( hermon, "Hermon %p CQN %#lx QUERY_CQ failed: %s\n",
@@ -859,14 +870,18 @@ static int hermon_create_cq ( struct ib_device *ibdev,
/* Allocate control structures */
hermon_cq = zalloc ( sizeof ( *hermon_cq ) );
if ( ! hermon_cq ) {
+ DBGC ( hermon, "Hermon %p CQN %#lx could not allocate CQ\n",
+ hermon, cq->cqn );
rc = -ENOMEM;
goto err_hermon_cq;
}
/* Allocate doorbell */
- hermon_cq->doorbell = malloc_dma ( sizeof ( hermon_cq->doorbell[0] ),
- sizeof ( hermon_cq->doorbell[0] ) );
+ hermon_cq->doorbell = malloc_phys ( sizeof ( hermon_cq->doorbell[0] ),
+ sizeof ( hermon_cq->doorbell[0] ) );
if ( ! hermon_cq->doorbell ) {
+ DBGC ( hermon, "Hermon %p CQN %#lx could not allocate "
+ "doorbell\n", hermon, cq->cqn );
rc = -ENOMEM;
goto err_doorbell;
}
@@ -874,9 +889,11 @@ static int hermon_create_cq ( struct ib_device *ibdev,
/* Allocate completion queue itself */
hermon_cq->cqe_size = ( cq->num_cqes * sizeof ( hermon_cq->cqe[0] ) );
- hermon_cq->cqe = malloc_dma ( hermon_cq->cqe_size,
- sizeof ( hermon_cq->cqe[0] ) );
+ hermon_cq->cqe = malloc_phys ( hermon_cq->cqe_size,
+ sizeof ( hermon_cq->cqe[0] ) );
if ( ! hermon_cq->cqe ) {
+ DBGC ( hermon, "Hermon %p CQN %#lx could not allocate CQEs\n",
+ hermon, cq->cqn );
rc = -ENOMEM;
goto err_cqe;
}
@@ -889,8 +906,11 @@ static int hermon_create_cq ( struct ib_device *ibdev,
/* Allocate MTT entries */
if ( ( rc = hermon_alloc_mtt ( hermon, hermon_cq->cqe,
hermon_cq->cqe_size,
- &hermon_cq->mtt ) ) != 0 )
+ &hermon_cq->mtt ) ) != 0 ) {
+ DBGC ( hermon, "Hermon %p CQN %#lx could not allocate MTTs: "
+ "%s\n", hermon, cq->cqn, strerror ( rc ) );
goto err_alloc_mtt;
+ }
/* Hand queue over to hardware */
memset ( &cqctx, 0, sizeof ( cqctx ) );
@@ -925,9 +945,9 @@ static int hermon_create_cq ( struct ib_device *ibdev,
err_sw2hw_cq:
hermon_free_mtt ( hermon, &hermon_cq->mtt );
err_alloc_mtt:
- free_dma ( hermon_cq->cqe, hermon_cq->cqe_size );
+ free_phys ( hermon_cq->cqe, hermon_cq->cqe_size );
err_cqe:
- free_dma ( hermon_cq->doorbell, sizeof ( hermon_cq->doorbell[0] ) );
+ free_phys ( hermon_cq->doorbell, sizeof ( hermon_cq->doorbell[0] ) );
err_doorbell:
free ( hermon_cq );
err_hermon_cq:
@@ -962,8 +982,8 @@ static void hermon_destroy_cq ( struct ib_device *ibdev,
hermon_free_mtt ( hermon, &hermon_cq->mtt );
/* Free memory */
- free_dma ( hermon_cq->cqe, hermon_cq->cqe_size );
- free_dma ( hermon_cq->doorbell, sizeof ( hermon_cq->doorbell[0] ) );
+ free_phys ( hermon_cq->cqe, hermon_cq->cqe_size );
+ free_phys ( hermon_cq->doorbell, sizeof ( hermon_cq->doorbell[0] ) );
free ( hermon_cq );
/* Mark queue number as free */
@@ -1084,16 +1104,30 @@ static uint8_t hermon_qp_st[] = {
*/
static __attribute__ (( unused )) int
hermon_dump_qpctx ( struct hermon *hermon, struct ib_queue_pair *qp ) {
+ struct hermon_queue_pair *hermon_qp = ib_qp_get_drvdata ( qp );
struct hermonprm_qp_ee_state_transitions qpctx;
+ unsigned int state;
int rc;
+ /* Do nothing unless debugging is enabled */
+ if ( ! DBG_LOG )
+ return 0;
+
+ /* Dump queue pair context */
memset ( &qpctx, 0, sizeof ( qpctx ) );
if ( ( rc = hermon_cmd_query_qp ( hermon, qp->qpn, &qpctx ) ) != 0 ) {
DBGC ( hermon, "Hermon %p QPN %#lx QUERY_QP failed: %s\n",
hermon, qp->qpn, strerror ( rc ) );
return rc;
}
- DBGC ( hermon, "Hermon %p QPN %#lx context:\n", hermon, qp->qpn );
+ state = MLX_GET ( &qpctx, qpc_eec_data.state );
+ if ( state != hermon_qp->state ) {
+ DBGC ( hermon, "Hermon %p QPN %#lx state %d unexpected "
+ "(should be %d)\n",
+ hermon, qp->qpn, state, hermon_qp->state );
+ }
+ DBGC ( hermon, "Hermon %p QPN %#lx state %d context:\n",
+ hermon, qp->qpn, state );
DBGC_HDA ( hermon, 0, &qpctx.u.dwords[2], ( sizeof ( qpctx ) - 8 ) );
return 0;
@@ -1122,15 +1156,19 @@ static int hermon_create_qp ( struct ib_device *ibdev,
/* Allocate control structures */
hermon_qp = zalloc ( sizeof ( *hermon_qp ) );
if ( ! hermon_qp ) {
+ DBGC ( hermon, "Hermon %p QPN %#lx could not allocate QP\n",
+ hermon, qp->qpn );
rc = -ENOMEM;
goto err_hermon_qp;
}
/* Allocate doorbells */
hermon_qp->recv.doorbell =
- malloc_dma ( sizeof ( hermon_qp->recv.doorbell[0] ),
- sizeof ( hermon_qp->recv.doorbell[0] ) );
+ malloc_phys ( sizeof ( hermon_qp->recv.doorbell[0] ),
+ sizeof ( hermon_qp->recv.doorbell[0] ) );
if ( ! hermon_qp->recv.doorbell ) {
+ DBGC ( hermon, "Hermon %p QPN %#lx could not allocate "
+ "doorbell\n", hermon, qp->qpn );
rc = -ENOMEM;
goto err_recv_doorbell;
}
@@ -1157,9 +1195,11 @@ static int hermon_create_qp ( struct ib_device *ibdev,
hermon_qp->wqe_size = ( hermon_qp->send.wqe_size +
hermon_qp->recv.wqe_size +
hermon_qp->recv.grh_size );
- hermon_qp->wqe = malloc_dma ( hermon_qp->wqe_size,
- sizeof ( hermon_qp->send.wqe[0] ) );
+ hermon_qp->wqe = malloc_phys ( hermon_qp->wqe_size,
+ sizeof ( hermon_qp->send.wqe[0] ) );
if ( ! hermon_qp->wqe ) {
+ DBGC ( hermon, "Hermon %p QPN %#lx could not allocate WQEs\n",
+ hermon, qp->qpn );
rc = -ENOMEM;
goto err_alloc_wqe;
}
@@ -1184,6 +1224,8 @@ static int hermon_create_qp ( struct ib_device *ibdev,
if ( ( rc = hermon_alloc_mtt ( hermon, hermon_qp->wqe,
hermon_qp->wqe_size,
&hermon_qp->mtt ) ) != 0 ) {
+ DBGC ( hermon, "Hermon %p QPN %#lx could not allocate MTTs: "
+ "%s\n", hermon, qp->qpn, strerror ( rc ) );
goto err_alloc_mtt;
}
@@ -1248,10 +1290,10 @@ static int hermon_create_qp ( struct ib_device *ibdev,
err_rst2init_qp:
hermon_free_mtt ( hermon, &hermon_qp->mtt );
err_alloc_mtt:
- free_dma ( hermon_qp->wqe, hermon_qp->wqe_size );
+ free_phys ( hermon_qp->wqe, hermon_qp->wqe_size );
err_alloc_wqe:
- free_dma ( hermon_qp->recv.doorbell,
- sizeof ( hermon_qp->recv.doorbell[0] ) );
+ free_phys ( hermon_qp->recv.doorbell,
+ sizeof ( hermon_qp->recv.doorbell[0] ) );
err_recv_doorbell:
free ( hermon_qp );
err_hermon_qp:
@@ -1363,9 +1405,9 @@ static void hermon_destroy_qp ( struct ib_device *ibdev,
hermon_free_mtt ( hermon, &hermon_qp->mtt );
/* Free memory */
- free_dma ( hermon_qp->wqe, hermon_qp->wqe_size );
- free_dma ( hermon_qp->recv.doorbell,
- sizeof ( hermon_qp->recv.doorbell[0] ) );
+ free_phys ( hermon_qp->wqe, hermon_qp->wqe_size );
+ free_phys ( hermon_qp->recv.doorbell,
+ sizeof ( hermon_qp->recv.doorbell[0] ) );
free ( hermon_qp );
/* Mark queue number as free */
@@ -1766,6 +1808,11 @@ static int hermon_complete ( struct ib_device *ibdev,
if ( is_send ) {
/* Hand off to completion handler */
ib_complete_send ( ibdev, qp, iobuf, rc );
+ } else if ( rc != 0 ) {
+ /* Dump queue state (for debugging) */
+ hermon_dump_qpctx ( hermon, qp );
+ /* Hand off to completion handler */
+ ib_complete_recv ( ibdev, qp, NULL, NULL, iobuf, rc );
} else {
/* Set received length */
len = MLX_GET ( &cqe->normal, byte_cnt );
@@ -1808,7 +1855,7 @@ static int hermon_complete ( struct ib_device *ibdev,
assert ( len <= iob_tailroom ( iobuf ) );
iob_put ( iobuf, len );
/* Hand off to completion handler */
- ib_complete_recv ( ibdev, qp, &recv_dest, source, iobuf, rc );
+ ib_complete_recv ( ibdev, qp, &recv_dest, source, iobuf, 0 );
}
return rc;
@@ -1863,6 +1910,89 @@ static void hermon_poll_cq ( struct ib_device *ibdev,
*/
/**
+ * Dump event queue context (for debugging only)
+ *
+ * @v hermon Hermon device
+ * @v hermon_eq Event queue
+ * @ret rc Return status code
+ */
+static __attribute__ (( unused )) int
+hermon_dump_eqctx ( struct hermon *hermon,
+ struct hermon_event_queue *hermon_eq ) {
+ struct hermonprm_eqc eqctx;
+ int rc;
+
+ /* Do nothing unless debugging is enabled */
+ if ( ! DBG_LOG )
+ return 0;
+
+ /* Dump event queue context */
+ memset ( &eqctx, 0, sizeof ( eqctx ) );
+ if ( ( rc = hermon_cmd_query_eq ( hermon, hermon_eq->eqn,
+ &eqctx ) ) != 0 ) {
+ DBGC ( hermon, "Hermon %p EQN %#lx QUERY_EQ failed: %s\n",
+ hermon, hermon_eq->eqn, strerror ( rc ) );
+ return rc;
+ }
+ DBGC ( hermon, "Hermon %p EQN %#lx context:\n",
+ hermon, hermon_eq->eqn );
+ DBGC_HDA ( hermon, 0, &eqctx, sizeof ( eqctx ) );
+
+ return 0;
+}
+
+/**
+ * Dump unconsumed event queue entries (for debugging only)
+ *
+ * @v hermon Hermon device
+ * @v hermon_eq Event queue
+ * @ret rc Return status code
+ */
+static __attribute__ (( unused )) int
+hermon_dump_eqes ( struct hermon *hermon,
+ struct hermon_event_queue *hermon_eq ) {
+ struct hermonprm_eqc eqctx;
+ union hermonprm_event_entry *eqe;
+ unsigned int mask;
+ unsigned int prod;
+ unsigned int cons;
+ unsigned int idx;
+ int rc;
+
+ /* Do nothing unless debugging is enabled */
+ if ( ! DBG_LOG )
+ return 0;
+
+ /* Dump event queue entries */
+ memset ( &eqctx, 0, sizeof ( eqctx ) );
+ if ( ( rc = hermon_cmd_query_eq ( hermon, hermon_eq->eqn,
+ &eqctx ) ) != 0 ) {
+ DBGC ( hermon, "Hermon %p EQN %#lx QUERY_EQ failed: %s\n",
+ hermon, hermon_eq->eqn, strerror ( rc ) );
+ return rc;
+ }
+ mask = ( HERMON_NUM_EQES - 1 );
+ prod = MLX_GET ( &eqctx, producer_counter ) & mask;
+ cons = MLX_GET ( &eqctx, consumer_counter ) & mask;
+ idx = hermon_eq->next_idx;
+ if ( ( idx & mask ) != ( cons & mask ) ) {
+ DBGC ( hermon, "Hermon %p EQN %#lx mismatch: SW %#x != HW "
+ "%#x\n", hermon, hermon_eq->eqn, idx, cons );
+ }
+ for ( ; ( idx & mask ) != ( prod & mask ) ; idx++ ) {
+ eqe = &hermon_eq->eqe[idx & mask];
+ DBGC ( hermon, "Hermon %p EQN %#lx event %#x owner %d type "
+ "%#02x:%#02x\n", hermon, hermon_eq->eqn, idx,
+ MLX_GET ( &eqe->generic, owner ),
+ MLX_GET ( &eqe->generic, event_type ),
+ MLX_GET ( &eqe->generic, event_sub_type ) );
+ DBGC_HDA ( hermon, 0, eqe, sizeof ( *eqe ) );
+ }
+
+ return 0;
+}
+
+/**
* Create event queue
*
* @v hermon Hermon device
@@ -1887,9 +2017,11 @@ static int hermon_create_eq ( struct hermon *hermon ) {
/* Allocate event queue itself */
hermon_eq->eqe_size =
( HERMON_NUM_EQES * sizeof ( hermon_eq->eqe[0] ) );
- hermon_eq->eqe = malloc_dma ( hermon_eq->eqe_size,
- sizeof ( hermon_eq->eqe[0] ) );
+ hermon_eq->eqe = malloc_phys ( hermon_eq->eqe_size,
+ sizeof ( hermon_eq->eqe[0] ) );
if ( ! hermon_eq->eqe ) {
+ DBGC ( hermon, "Hermon %p EQN %#lx could not allocate EQEs\n",
+ hermon, hermon_eq->eqn );
rc = -ENOMEM;
goto err_eqe;
}
@@ -1902,8 +2034,11 @@ static int hermon_create_eq ( struct hermon *hermon ) {
/* Allocate MTT entries */
if ( ( rc = hermon_alloc_mtt ( hermon, hermon_eq->eqe,
hermon_eq->eqe_size,
- &hermon_eq->mtt ) ) != 0 )
+ &hermon_eq->mtt ) ) != 0 ) {
+ DBGC ( hermon, "Hermon %p EQN %#lx could not allocate MTTs: "
+ "%s\n", hermon, hermon_eq->eqn, strerror ( rc ) );
goto err_alloc_mtt;
+ }
/* Hand queue over to hardware */
memset ( &eqctx, 0, sizeof ( eqctx ) );
@@ -1946,7 +2081,7 @@ static int hermon_create_eq ( struct hermon *hermon ) {
err_sw2hw_eq:
hermon_free_mtt ( hermon, &hermon_eq->mtt );
err_alloc_mtt:
- free_dma ( hermon_eq->eqe, hermon_eq->eqe_size );
+ free_phys ( hermon_eq->eqe, hermon_eq->eqe_size );
err_eqe:
memset ( hermon_eq, 0, sizeof ( *hermon_eq ) );
return rc;
@@ -1986,7 +2121,7 @@ static void hermon_destroy_eq ( struct hermon *hermon ) {
hermon_free_mtt ( hermon, &hermon_eq->mtt );
/* Free memory */
- free_dma ( hermon_eq->eqe, hermon_eq->eqe_size );
+ free_phys ( hermon_eq->eqe, hermon_eq->eqe_size );
memset ( hermon_eq, 0, sizeof ( *hermon_eq ) );
}
@@ -2020,6 +2155,32 @@ static void hermon_event_port_state_change ( struct hermon *hermon,
}
/**
+ * Handle port management event
+ *
+ * @v hermon Hermon device
+ * @v eqe Port management change event queue entry
+ */
+static void hermon_event_port_mgmnt_change ( struct hermon *hermon,
+ union hermonprm_event_entry *eqe){
+ unsigned int port;
+
+ /* Get port */
+ port = ( MLX_GET ( &eqe->port_mgmnt_change, port ) - 1 );
+ DBGC ( hermon, "Hermon %p port %d management change\n",
+ hermon, ( port + 1 ) );
+
+ /* Sanity check */
+ if ( port >= hermon->cap.num_ports ) {
+ DBGC ( hermon, "Hermon %p port %d does not exist!\n",
+ hermon, ( port + 1 ) );
+ return;
+ }
+
+ /* Update MAD parameters */
+ ib_smc_update ( hermon->port[port].ibdev, hermon_mad );
+}
+
+/**
* Poll event queue
*
* @v ibdev Infiniband device
@@ -2029,6 +2190,8 @@ static void hermon_poll_eq ( struct ib_device *ibdev ) {
struct hermon_event_queue *hermon_eq = &hermon->eq;
union hermonprm_event_entry *eqe;
union hermonprm_doorbell_register db_reg;
+ unsigned long now;
+ unsigned long elapsed;
unsigned int eqe_idx_mask;
unsigned int event_type;
@@ -2037,7 +2200,12 @@ static void hermon_poll_eq ( struct ib_device *ibdev ) {
*/
if ( ib_is_open ( ibdev ) &&
( ibdev->port_state == IB_PORT_STATE_DOWN ) ) {
- ib_smc_update ( ibdev, hermon_mad );
+ now = currticks();
+ elapsed = ( now - hermon->last_poll );
+ if ( elapsed >= HERMON_LINK_POLL_INTERVAL ) {
+ hermon->last_poll = now;
+ ib_smc_update ( ibdev, hermon_mad );
+ }
}
/* Poll event queue */
@@ -2061,10 +2229,14 @@ static void hermon_poll_eq ( struct ib_device *ibdev ) {
case HERMON_EV_PORT_STATE_CHANGE:
hermon_event_port_state_change ( hermon, eqe );
break;
+ case HERMON_EV_PORT_MGMNT_CHANGE:
+ hermon_event_port_mgmnt_change ( hermon, eqe );
+ break;
default:
DBGC ( hermon, "Hermon %p EQN %#lx unrecognised event "
- "type %#x:\n",
- hermon, hermon_eq->eqn, event_type );
+ "type %#02x:%#02x\n",
+ hermon, hermon_eq->eqn, event_type,
+ MLX_GET ( &eqe->generic, event_sub_type ) );
DBGC_HDA ( hermon, virt_to_phys ( eqe ),
eqe, sizeof ( *eqe ) );
break;
@@ -2202,6 +2374,8 @@ static int hermon_start_firmware ( struct hermon *hermon ) {
hermon->firmware_len = fw_len;
hermon->firmware_area = umalloc ( hermon->firmware_len );
if ( ! hermon->firmware_area ) {
+ DBGC ( hermon, "Hermon %p could not allocate firmware "
+ "area\n", hermon );
rc = -ENOMEM;
goto err_alloc_fa;
}
@@ -2569,6 +2743,8 @@ static int hermon_map_icm ( struct hermon *hermon,
hermon->icm_aux_len = icm_aux_len;
hermon->icm = umalloc ( hermon->icm_aux_len + hermon->icm_len );
if ( ! hermon->icm ) {
+ DBGC ( hermon, "Hermon %p could not allocate ICM\n",
+ hermon );
rc = -ENOMEM;
goto err_alloc;
}
@@ -2650,22 +2826,45 @@ static void hermon_unmap_icm ( struct hermon *hermon ) {
* Reset device
*
* @v hermon Hermon device
+ * @ret rc Return status code
*/
-static void hermon_reset ( struct hermon *hermon ) {
+static int hermon_reset ( struct hermon *hermon ) {
struct pci_device *pci = hermon->pci;
struct pci_config_backup backup;
static const uint8_t backup_exclude[] =
PCI_CONFIG_BACKUP_EXCLUDE ( 0x58, 0x5c );
+ uint16_t vendor;
+ unsigned int i;
+
+ /* Reset command interface toggle */
+ hermon->toggle = 0;
/* Perform device reset and preserve PCI configuration */
pci_backup ( pci, &backup, backup_exclude );
writel ( HERMON_RESET_MAGIC,
( hermon->config + HERMON_RESET_OFFSET ) );
- mdelay ( HERMON_RESET_WAIT_TIME_MS );
- pci_restore ( pci, &backup, backup_exclude );
- /* Reset command interface toggle */
- hermon->toggle = 0;
+ /* Wait until device starts responding to configuration cycles */
+ for ( i = 0 ; i < HERMON_RESET_MAX_WAIT_MS ; i++ ) {
+
+ /* Read PCI vendor ID */
+ pci_read_config_word ( pci, PCI_VENDOR_ID, &vendor );
+ if ( vendor == pci->vendor ) {
+
+ /* Restore PCI configuration */
+ pci_restore ( pci, &backup, backup_exclude );
+
+ DBGC ( hermon, "Hermon %p reset after %dms\n",
+ hermon, i );
+ return 0;
+ }
+
+ /* Delay */
+ mdelay ( 1 );
+ }
+
+ DBGC ( hermon, "Hermon %p timed out waiting for reset\n", hermon );
+ return -ETIMEDOUT;
}
/**
@@ -2709,6 +2908,25 @@ static int hermon_setup_mpt ( struct hermon *hermon ) {
}
/**
+ * Unmap memory protection table
+ *
+ * @v hermon Hermon device
+ * @ret rc Return status code
+ */
+static int hermon_unmap_mpt ( struct hermon *hermon ) {
+ int rc;
+
+ if ( ( rc = hermon_cmd_hw2sw_mpt ( hermon,
+ hermon->cap.reserved_mrws ) ) != 0 ){
+ DBGC ( hermon, "Hermon %p could not unmap MPT: %s\n",
+ hermon, strerror ( rc ) );
+ return rc;
+ }
+
+ return 0;
+}
+
+/**
* Configure special queue pairs
*
* @v hermon Hermon device
@@ -2784,11 +3002,13 @@ static int hermon_start ( struct hermon *hermon, int running ) {
if ( ( rc = hermon_configure_special_qps ( hermon ) ) != 0 )
goto err_conf_special_qps;
+ DBGC ( hermon, "Hermon %p device started\n", hermon );
return 0;
err_conf_special_qps:
hermon_destroy_eq ( hermon );
err_create_eq:
+ hermon_unmap_mpt ( hermon );
err_setup_mpt:
hermon_cmd_close_hca ( hermon );
err_init_hca:
@@ -2806,6 +3026,7 @@ static int hermon_start ( struct hermon *hermon, int running ) {
*/
static void hermon_stop ( struct hermon *hermon ) {
hermon_destroy_eq ( hermon );
+ hermon_unmap_mpt ( hermon );
hermon_cmd_close_hca ( hermon );
hermon_unmap_icm ( hermon );
hermon_stop_firmware ( hermon );
@@ -3080,6 +3301,9 @@ static int hermon_register_ibdev ( struct hermon *hermon,
struct ib_device *ibdev = port->ibdev;
int rc;
+ /* Use Ethernet MAC as eIPoIB local EMAC */
+ memcpy ( ibdev->lemac, port->eth_mac.raw, ETH_ALEN );
+
/* Initialise parameters using SMC */
ib_smc_init ( ibdev, hermon_mad );
@@ -3137,13 +3361,13 @@ static struct hermon_port_type hermon_port_type_ib = {
*/
/** Number of Hermon Ethernet send work queue entries */
-#define HERMON_ETH_NUM_SEND_WQES 2
+#define HERMON_ETH_NUM_SEND_WQES 16
/** Number of Hermon Ethernet receive work queue entries */
-#define HERMON_ETH_NUM_RECV_WQES 4
+#define HERMON_ETH_NUM_RECV_WQES 8
/** Number of Hermon Ethernet completion entries */
-#define HERMON_ETH_NUM_CQES 8
+#define HERMON_ETH_NUM_CQES 32
/**
* Transmit packet via Hermon Ethernet device
@@ -3396,24 +3620,10 @@ static int hermon_register_netdev ( struct hermon *hermon,
struct hermon_port *port ) {
struct net_device *netdev = port->netdev;
struct ib_device *ibdev = port->ibdev;
- struct hermonprm_query_port_cap query_port;
- union {
- uint8_t bytes[8];
- uint32_t dwords[2];
- } mac;
int rc;
- /* Retrieve MAC address */
- if ( ( rc = hermon_cmd_query_port ( hermon, ibdev->port,
- &query_port ) ) != 0 ) {
- DBGC ( hermon, "Hermon %p port %d could not query port: %s\n",
- hermon, ibdev->port, strerror ( rc ) );
- goto err_query_port;
- }
- mac.dwords[0] = htonl ( MLX_GET ( &query_port, mac_47_32 ) );
- mac.dwords[1] = htonl ( MLX_GET ( &query_port, mac_31_0 ) );
- memcpy ( netdev->hw_addr,
- &mac.bytes[ sizeof ( mac.bytes ) - ETH_ALEN ], ETH_ALEN );
+ /* Set MAC address */
+ memcpy ( netdev->hw_addr, port->eth_mac.raw, ETH_ALEN );
/* Register network device */
if ( ( rc = register_netdev ( netdev ) ) != 0 ) {
@@ -3437,7 +3647,6 @@ static int hermon_register_netdev ( struct hermon *hermon,
err_register_nvo:
unregister_netdev ( netdev );
err_register_netdev:
- err_query_port:
return rc;
}
@@ -3575,6 +3784,10 @@ static int hermon_set_port_type ( struct hermon *hermon,
( ( ib_supported && eth_supported ) ? " and" : "" ),
( eth_supported ? " Ethernet" : "" ) );
+ /* Record Ethernet MAC address */
+ port->eth_mac.part.h = htons ( MLX_GET ( &query_port, mac_47_32 ) );
+ port->eth_mac.part.l = htonl ( MLX_GET ( &query_port, mac_31_0 ) );
+
/* Sense network, if applicable */
if ( ib_supported && eth_supported ) {
@@ -3587,6 +3800,9 @@ static int hermon_set_port_type ( struct hermon *hermon,
rc = port_type;
return rc;
}
+
+ /* Avoid spamming debug output */
+ mdelay ( 50 );
} while ( ( port_type == HERMON_PORT_TYPE_UNKNOWN ) &&
( ( elapsed = ( currticks() - start ) ) <
HERMON_SENSE_PORT_TIMEOUT ) );
@@ -3736,20 +3952,20 @@ static struct hermon * hermon_alloc ( void ) {
goto err_hermon;
/* Allocate space for mailboxes */
- hermon->mailbox_in = malloc_dma ( HERMON_MBOX_SIZE,
- HERMON_MBOX_ALIGN );
+ hermon->mailbox_in = malloc_phys ( HERMON_MBOX_SIZE,
+ HERMON_MBOX_ALIGN );
if ( ! hermon->mailbox_in )
goto err_mailbox_in;
- hermon->mailbox_out = malloc_dma ( HERMON_MBOX_SIZE,
- HERMON_MBOX_ALIGN );
+ hermon->mailbox_out = malloc_phys ( HERMON_MBOX_SIZE,
+ HERMON_MBOX_ALIGN );
if ( ! hermon->mailbox_out )
goto err_mailbox_out;
return hermon;
- free_dma ( hermon->mailbox_out, HERMON_MBOX_SIZE );
+ free_phys ( hermon->mailbox_out, HERMON_MBOX_SIZE );
err_mailbox_out:
- free_dma ( hermon->mailbox_in, HERMON_MBOX_SIZE );
+ free_phys ( hermon->mailbox_in, HERMON_MBOX_SIZE );
err_mailbox_in:
free ( hermon );
err_hermon:
@@ -3765,8 +3981,8 @@ static void hermon_free ( struct hermon *hermon ) {
ufree ( hermon->icm );
ufree ( hermon->firmware_area );
- free_dma ( hermon->mailbox_out, HERMON_MBOX_SIZE );
- free_dma ( hermon->mailbox_in, HERMON_MBOX_SIZE );
+ free_phys ( hermon->mailbox_out, HERMON_MBOX_SIZE );
+ free_phys ( hermon->mailbox_in, HERMON_MBOX_SIZE );
free ( hermon );
}
@@ -3782,6 +3998,8 @@ static int hermon_probe ( struct pci_device *pci ) {
struct ib_device *ibdev;
struct net_device *netdev;
struct hermon_port *port;
+ unsigned long config;
+ unsigned long uar;
unsigned int i;
int rc;
@@ -3798,13 +4016,16 @@ static int hermon_probe ( struct pci_device *pci ) {
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 );
+ config = pci_bar_start ( pci, HERMON_PCI_CONFIG_BAR );
+ hermon->config = pci_ioremap ( pci, config,
+ HERMON_PCI_CONFIG_BAR_SIZE );
+ uar = pci_bar_start ( pci, HERMON_PCI_UAR_BAR );
+ hermon->uar = pci_ioremap ( pci, uar,
+ HERMON_UAR_NON_EQ_PAGE * HERMON_PAGE_SIZE );
/* Reset device */
- hermon_reset ( hermon );
+ if ( ( rc = hermon_reset ( hermon ) ) != 0 )
+ goto err_reset;
/* Start firmware */
if ( ( rc = hermon_start_firmware ( hermon ) ) != 0 )
@@ -3816,7 +4037,7 @@ static int hermon_probe ( struct pci_device *pci ) {
/* Allocate Infiniband devices */
for ( i = 0 ; i < hermon->cap.num_ports ; i++ ) {
- ibdev = alloc_ibdev ( 0 );
+ ibdev = alloc_ibdev ( 0 );
if ( ! ibdev ) {
rc = -ENOMEM;
goto err_alloc_ibdev;
@@ -3825,6 +4046,7 @@ static int hermon_probe ( struct pci_device *pci ) {
ibdev->op = &hermon_ib_operations;
ibdev->dev = &pci->dev;
ibdev->port = ( HERMON_PORT_BASE + i );
+ ibdev->ports = hermon->cap.num_ports;
ib_set_drvdata ( ibdev, hermon );
}
@@ -3896,6 +4118,7 @@ static int hermon_probe ( struct pci_device *pci ) {
err_get_cap:
hermon_stop_firmware ( hermon );
err_start_firmware:
+ err_reset:
iounmap ( hermon->uar );
iounmap ( hermon->config );
hermon_free ( hermon );
@@ -3937,6 +4160,7 @@ static void hermon_remove ( struct pci_device *pci ) {
*/
static int hermon_bofm_probe ( struct pci_device *pci ) {
struct hermon *hermon;
+ unsigned long config;
int rc;
/* Allocate Hermon device */
@@ -3952,8 +4176,9 @@ static int hermon_bofm_probe ( struct pci_device *pci ) {
adjust_pci_device ( pci );
/* Map PCI BAR */
- hermon->config = ioremap ( pci_bar_start ( pci, HERMON_PCI_CONFIG_BAR ),
- HERMON_PCI_CONFIG_BAR_SIZE );
+ config = pci_bar_start ( pci, HERMON_PCI_CONFIG_BAR );
+ hermon->config = pci_ioremap ( pci, config,
+ HERMON_PCI_CONFIG_BAR_SIZE );
/* Initialise BOFM device */
bofm_init ( &hermon->bofm, pci, &hermon_bofm_operations );
@@ -3988,18 +4213,29 @@ static void hermon_bofm_remove ( struct pci_device *pci ) {
}
static struct pci_device_id hermon_nics[] = {
+ /* Mellanox ConnectX VPI (ethernet + infiniband) */
PCI_ROM ( 0x15b3, 0x6340, "mt25408", "MT25408 HCA driver", 0 ),
PCI_ROM ( 0x15b3, 0x634a, "mt25418", "MT25418 HCA driver", 0 ),
+
+ /* Mellanox ConnectX EN (ethernet only) */
+ PCI_ROM ( 0x15b3, 0x6368, "mt25448", "MT25448 HCA driver", 0 ),
+ PCI_ROM ( 0x15b3, 0x6372, "mt25458", "MT25458 HCA driver", 0 ),
+
+ /* Mellanox ConnectX-2 VPI (ethernet + infiniband) */
PCI_ROM ( 0x15b3, 0x6732, "mt26418", "MT26418 HCA driver", 0 ),
PCI_ROM ( 0x15b3, 0x673c, "mt26428", "MT26428 HCA driver", 0 ),
PCI_ROM ( 0x15b3, 0x6746, "mt26438", "MT26438 HCA driver", 0 ),
PCI_ROM ( 0x15b3, 0x6778, "mt26488", "MT26488 HCA driver", 0 ),
- PCI_ROM ( 0x15b3, 0x6368, "mt25448", "MT25448 HCA driver", 0 ),
+
+ /* Mellanox ConnectX-2 EN (ethernet only) */
PCI_ROM ( 0x15b3, 0x6750, "mt26448", "MT26448 HCA driver", 0 ),
- PCI_ROM ( 0x15b3, 0x6372, "mt25458", "MT25458 HCA driver", 0 ),
PCI_ROM ( 0x15b3, 0x675a, "mt26458", "MT26458 HCA driver", 0 ),
PCI_ROM ( 0x15b3, 0x6764, "mt26468", "MT26468 HCA driver", 0 ),
PCI_ROM ( 0x15b3, 0x676e, "mt26478", "MT26478 HCA driver", 0 ),
+
+ /* Mellanox ConnectX-3 VPI (ethernet + infiniband) */
+ PCI_ROM ( 0x15b3, 0x1003, "mt4099", "ConnectX-3 HCA driver", 0 ),
+ PCI_ROM ( 0x15b3, 0x1007, "mt4103", "ConnectX-3 Pro HCA driver", 0 ),
};
struct pci_driver hermon_driver __pci_driver = {
diff --git a/src/drivers/infiniband/hermon.h b/src/drivers/infiniband/hermon.h
index 61e285781..a952bbd81 100644
--- a/src/drivers/infiniband/hermon.h
+++ b/src/drivers/infiniband/hermon.h
@@ -34,8 +34,8 @@ FILE_LICENCE ( GPL2_OR_LATER );
/* Device reset */
#define HERMON_RESET_OFFSET 0x0f0010
-#define HERMON_RESET_MAGIC 0x01000000UL
-#define HERMON_RESET_WAIT_TIME_MS 1000
+#define HERMON_RESET_MAGIC 0x01000001UL
+#define HERMON_RESET_MAX_WAIT_MS 1000
/* Work queue entry and completion queue entry opcodes */
#define HERMON_OPCODE_NOP 0x00
@@ -52,6 +52,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
#define HERMON_HCR_CLOSE_PORT 0x000a
#define HERMON_HCR_SET_PORT 0x000c
#define HERMON_HCR_SW2HW_MPT 0x000d
+#define HERMON_HCR_HW2SW_MPT 0x000f
#define HERMON_HCR_WRITE_MTT 0x0011
#define HERMON_HCR_MAP_EQ 0x0012
#define HERMON_HCR_SW2HW_EQ 0x0013
@@ -122,6 +123,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
#define HERMON_SET_PORT_GID_TABLE 0x0500
#define HERMON_EV_PORT_STATE_CHANGE 0x09
+#define HERMON_EV_PORT_MGMNT_CHANGE 0x1d
#define HERMON_SCHED_QP0 0x3f
#define HERMON_SCHED_DEFAULT 0x83
@@ -216,6 +218,13 @@ struct hermonprm_port_state_change_event_st {
struct hermonprm_port_state_change_st data;
} __attribute__ (( packed ));
+struct hermonprm_port_mgmnt_change_event_st {
+ pseudo_bit_t reserved[0x00020];
+/* -------------- */
+ pseudo_bit_t port[0x00008];
+ pseudo_bit_t reserved0[0x00018];
+} __attribute__ (( packed ));
+
struct hermonprm_sense_port_st {
pseudo_bit_t reserved0[0x00020];
/* -------------- */
@@ -459,6 +468,7 @@ struct MLX_DECLARE_STRUCT ( hermonprm_mod_stat_cfg_input_mod );
struct MLX_DECLARE_STRUCT ( hermonprm_mpt );
struct MLX_DECLARE_STRUCT ( hermonprm_mtt );
struct MLX_DECLARE_STRUCT ( hermonprm_port_state_change_event );
+struct MLX_DECLARE_STRUCT ( hermonprm_port_mgmnt_change_event );
struct MLX_DECLARE_STRUCT ( hermonprm_qp_db_record );
struct MLX_DECLARE_STRUCT ( hermonprm_qp_ee_state_transitions );
struct MLX_DECLARE_STRUCT ( hermonprm_query_dev_cap );
@@ -529,6 +539,7 @@ union hermonprm_completion_entry {
union hermonprm_event_entry {
struct hermonprm_event_queue_entry generic;
struct hermonprm_port_state_change_event port_state_change;
+ struct hermonprm_port_mgmnt_change_event port_mgmnt_change;
} __attribute__ (( packed ));
union hermonprm_doorbell_register {
@@ -822,6 +833,15 @@ struct hermon_port_type {
struct hermon_port *port );
};
+/** A Hermon port Ethernet MAC address */
+union hermon_port_mac {
+ struct {
+ uint16_t h;
+ uint32_t l;
+ } __attribute__ (( packed )) part;
+ uint8_t raw[ETH_ALEN];
+};
+
/** A Hermon port */
struct hermon_port {
/** Infiniband device */
@@ -832,6 +852,8 @@ struct hermon_port {
struct ib_completion_queue *eth_cq;
/** Ethernet queue pair */
struct ib_queue_pair *eth_qp;
+ /** Ethernet MAC */
+ union hermon_port_mac eth_mac;
/** Port type */
struct hermon_port_type *type;
/** Non-volatile option storage */
@@ -882,6 +904,8 @@ struct hermon {
/** Event queue */
struct hermon_event_queue eq;
+ /** Last unsolicited link state poll */
+ unsigned long last_poll;
/** Unrestricted LKey
*
* Used to get unrestricted memory access.
@@ -918,6 +942,13 @@ struct hermon {
/** Memory key prefix */
#define HERMON_MKEY_PREFIX 0x77000000UL
+/** Link poll interval
+ *
+ * Used when we need to poll for link state (rather than relying upon
+ * receiving an event).
+ */
+#define HERMON_LINK_POLL_INTERVAL ( TICKS_PER_SEC / 2 )
+
/*
* HCA commands
*
@@ -925,7 +956,7 @@ struct hermon {
#define HERMON_HCR_BASE 0x80680
#define HERMON_HCR_REG(x) ( HERMON_HCR_BASE + 4 * (x) )
-#define HERMON_HCR_MAX_WAIT_MS 2000
+#define HERMON_HCR_MAX_WAIT_MS 10000
#define HERMON_MBOX_ALIGN 4096
#define HERMON_MBOX_SIZE 1024
diff --git a/src/drivers/infiniband/linda.c b/src/drivers/infiniband/linda.c
index e8d61c865..8c5912660 100644
--- a/src/drivers/infiniband/linda.c
+++ b/src/drivers/infiniband/linda.c
@@ -531,8 +531,8 @@ static int linda_init_send ( struct linda *linda ) {
linda->send_buf[i] = i;
/* Allocate space for the SendBufAvail array */
- linda->sendbufavail = malloc_dma ( sizeof ( *linda->sendbufavail ),
- LINDA_SENDBUFAVAIL_ALIGN );
+ linda->sendbufavail = malloc_phys ( sizeof ( *linda->sendbufavail ),
+ LINDA_SENDBUFAVAIL_ALIGN );
if ( ! linda->sendbufavail ) {
rc = -ENOMEM;
goto err_alloc_sendbufavail;
@@ -555,7 +555,7 @@ static int linda_init_send ( struct linda *linda ) {
return 0;
- free_dma ( linda->sendbufavail, sizeof ( *linda->sendbufavail ) );
+ free_phys ( linda->sendbufavail, sizeof ( *linda->sendbufavail ) );
err_alloc_sendbufavail:
return rc;
}
@@ -576,7 +576,7 @@ static void linda_fini_send ( struct linda *linda ) {
/* Ensure hardware has seen this disable */
linda_readq ( linda, &sendctrl, QIB_7220_SendCtrl_offset );
- free_dma ( linda->sendbufavail, sizeof ( *linda->sendbufavail ) );
+ free_phys ( linda->sendbufavail, sizeof ( *linda->sendbufavail ) );
}
/***************************************************************************
@@ -613,8 +613,8 @@ static int linda_create_recv_wq ( struct linda *linda,
linda_wq->eager_cons = 0;
/* Allocate receive header buffer */
- linda_wq->header = malloc_dma ( LINDA_RECV_HEADERS_SIZE,
- LINDA_RECV_HEADERS_ALIGN );
+ linda_wq->header = malloc_phys ( LINDA_RECV_HEADERS_SIZE,
+ LINDA_RECV_HEADERS_ALIGN );
if ( ! linda_wq->header ) {
rc = -ENOMEM;
goto err_alloc_header;
@@ -650,7 +650,7 @@ static int linda_create_recv_wq ( struct linda *linda,
virt_to_bus ( &linda_wq->header_prod ) );
return 0;
- free_dma ( linda_wq->header, LINDA_RECV_HEADERS_SIZE );
+ free_phys ( linda_wq->header, LINDA_RECV_HEADERS_SIZE );
err_alloc_header:
return rc;
}
@@ -679,7 +679,7 @@ static void linda_destroy_recv_wq ( struct linda *linda,
mb();
/* Free headers ring */
- free_dma ( linda_wq->header, LINDA_RECV_HEADERS_SIZE );
+ free_phys ( linda_wq->header, LINDA_RECV_HEADERS_SIZE );
/* Free context */
linda_free_ctx ( linda, ctx );
@@ -2330,12 +2330,13 @@ static int linda_probe ( struct pci_device *pci ) {
ibdev->op = &linda_ib_operations;
ibdev->dev = &pci->dev;
ibdev->port = 1;
+ ibdev->ports = 1;
/* Fix up PCI device */
adjust_pci_device ( pci );
/* Map PCI BARs */
- linda->regs = ioremap ( pci->membase, LINDA_BAR0_SIZE );
+ linda->regs = pci_ioremap ( pci, pci->membase, LINDA_BAR0_SIZE );
DBGC2 ( linda, "Linda %p has BAR at %08lx\n", linda, pci->membase );
/* Print some general data */
diff --git a/src/drivers/infiniband/mlx_utils_flexboot/src/mlx_memory_priv.c b/src/drivers/infiniband/mlx_utils_flexboot/src/mlx_memory_priv.c
index cb9e759bf..e368d459b 100644
--- a/src/drivers/infiniband/mlx_utils_flexboot/src/mlx_memory_priv.c
+++ b/src/drivers/infiniband/mlx_utils_flexboot/src/mlx_memory_priv.c
@@ -61,7 +61,7 @@ mlx_memory_alloc_dma_priv(
)
{
mlx_status status = MLX_SUCCESS;
- *ptr = malloc_dma(size, align);
+ *ptr = malloc_phys(size, align);
if (*ptr == NULL) {
status = MLX_OUT_OF_RESOURCES;
} else {
@@ -78,7 +78,7 @@ mlx_memory_free_dma_priv(
)
{
mlx_status status = MLX_SUCCESS;
- free_dma(ptr, size);
+ free_phys(ptr, size);
return status;
}
mlx_status
diff --git a/src/drivers/infiniband/mlx_utils_flexboot/src/mlx_pci_priv.c b/src/drivers/infiniband/mlx_utils_flexboot/src/mlx_pci_priv.c
index b474a4a63..6b42bcafc 100644
--- a/src/drivers/infiniband/mlx_utils_flexboot/src/mlx_pci_priv.c
+++ b/src/drivers/infiniband/mlx_utils_flexboot/src/mlx_pci_priv.c
@@ -115,7 +115,7 @@ mlx_pci_init_priv(
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),
+ utils->config = pci_ioremap ( utils->pci, pci_bar_start ( utils->pci, PCI_BASE_ADDRESS_0),
0x100000 );
#endif
return status;
diff --git a/src/drivers/infiniband/nodnic_prm.h b/src/drivers/infiniband/nodnic_prm.h
index 5e0fa9890..a962c821c 100644
--- a/src/drivers/infiniband/nodnic_prm.h
+++ b/src/drivers/infiniband/nodnic_prm.h
@@ -38,10 +38,10 @@ struct nodnic_wqe_segment_data_ptr_st { /* Little Endian */
struct MLX_DECLARE_STRUCT ( nodnic_wqe_segment_data_ptr );
-#define HERMON_MAX_SCATTER 1
+#define NODNIC_MAX_SCATTER 1
struct nodnic_recv_wqe {
- struct nodnic_wqe_segment_data_ptr data[HERMON_MAX_SCATTER];
+ struct nodnic_wqe_segment_data_ptr data[NODNIC_MAX_SCATTER];
} __attribute__ (( packed ));
#endif /* SRC_DRIVERS_INFINIBAND_MLX_NODNIC_INCLUDE_PRM_NODNIC_PRM_H_ */
diff --git a/src/drivers/infiniband/qib7322.c b/src/drivers/infiniband/qib7322.c
index 18011c19a..a4b51db05 100644
--- a/src/drivers/infiniband/qib7322.c
+++ b/src/drivers/infiniband/qib7322.c
@@ -669,8 +669,8 @@ static int qib7322_init_send ( struct qib7322 *qib7322 ) {
}
/* Allocate space for the SendBufAvail array */
- qib7322->sendbufavail = malloc_dma ( sizeof ( *qib7322->sendbufavail ),
- QIB7322_SENDBUFAVAIL_ALIGN );
+ qib7322->sendbufavail = malloc_phys ( sizeof ( *qib7322->sendbufavail ),
+ QIB7322_SENDBUFAVAIL_ALIGN );
if ( ! qib7322->sendbufavail ) {
rc = -ENOMEM;
goto err_alloc_sendbufavail;
@@ -697,7 +697,7 @@ static int qib7322_init_send ( struct qib7322 *qib7322 ) {
return 0;
- free_dma ( qib7322->sendbufavail, sizeof ( *qib7322->sendbufavail ) );
+ free_phys ( qib7322->sendbufavail, sizeof ( *qib7322->sendbufavail ) );
err_alloc_sendbufavail:
qib7322_destroy_send_bufs ( qib7322, qib7322->send_bufs_vl15_port1 );
err_create_send_bufs_vl15_port1:
@@ -724,7 +724,7 @@ static void qib7322_fini_send ( struct qib7322 *qib7322 ) {
/* Ensure hardware has seen this disable */
qib7322_readq ( qib7322, &sendctrl, QIB_7322_SendCtrl_offset );
- free_dma ( qib7322->sendbufavail, sizeof ( *qib7322->sendbufavail ) );
+ free_phys ( qib7322->sendbufavail, sizeof ( *qib7322->sendbufavail ) );
qib7322_destroy_send_bufs ( qib7322, qib7322->send_bufs_vl15_port1 );
qib7322_destroy_send_bufs ( qib7322, qib7322->send_bufs_vl15_port0 );
qib7322_destroy_send_bufs ( qib7322, qib7322->send_bufs_small );
@@ -767,8 +767,8 @@ static int qib7322_create_recv_wq ( struct ib_device *ibdev,
qib7322_wq->eager_cons = 0;
/* Allocate receive header buffer */
- qib7322_wq->header = malloc_dma ( QIB7322_RECV_HEADERS_SIZE,
- QIB7322_RECV_HEADERS_ALIGN );
+ qib7322_wq->header = malloc_phys ( QIB7322_RECV_HEADERS_SIZE,
+ QIB7322_RECV_HEADERS_ALIGN );
if ( ! qib7322_wq->header ) {
rc = -ENOMEM;
goto err_alloc_header;
@@ -810,7 +810,7 @@ static int qib7322_create_recv_wq ( struct ib_device *ibdev,
virt_to_bus ( &qib7322_wq->header_prod ) );
return 0;
- free_dma ( qib7322_wq->header, QIB7322_RECV_HEADERS_SIZE );
+ free_phys ( qib7322_wq->header, QIB7322_RECV_HEADERS_SIZE );
err_alloc_header:
return rc;
}
@@ -846,7 +846,7 @@ static void qib7322_destroy_recv_wq ( struct ib_device *ibdev,
mb();
/* Free headers ring */
- free_dma ( qib7322_wq->header, QIB7322_RECV_HEADERS_SIZE );
+ free_phys ( qib7322_wq->header, QIB7322_RECV_HEADERS_SIZE );
}
/**
@@ -2297,7 +2297,7 @@ static int qib7322_probe ( struct pci_device *pci ) {
adjust_pci_device ( pci );
/* Map PCI BARs */
- qib7322->regs = ioremap ( pci->membase, QIB7322_BAR0_SIZE );
+ qib7322->regs = pci_ioremap ( pci, pci->membase, QIB7322_BAR0_SIZE );
DBGC2 ( qib7322, "QIB7322 %p has BAR at %08lx\n",
qib7322, pci->membase );
@@ -2348,6 +2348,7 @@ static int qib7322_probe ( struct pci_device *pci ) {
ibdev->dev = &pci->dev;
ibdev->op = &qib7322_ib_operations;
ibdev->port = ( QIB7322_PORT_BASE + i );
+ ibdev->ports = QIB7322_MAX_PORTS;
ibdev->link_width_enabled = ibdev->link_width_supported =
IB_LINK_WIDTH_4X; /* 1x does not work */
ibdev->link_speed_enabled = ibdev->link_speed_supported =
diff --git a/src/drivers/linux/af_packet.c b/src/drivers/linux/af_packet.c
index 65aafc5b1..9fa6ef2a5 100644
--- a/src/drivers/linux/af_packet.c
+++ b/src/drivers/linux/af_packet.c
@@ -19,7 +19,7 @@
#include <errno.h>
#include <string.h>
#include <stdio.h>
-#include <linux_api.h>
+#include <ipxe/linux_api.h>
#include <ipxe/list.h>
#include <ipxe/linux.h>
#include <ipxe/malloc.h>
diff --git a/src/drivers/linux/linux.c b/src/drivers/linux/linux.c
index 83546b27e..898f50024 100644
--- a/src/drivers/linux/linux.c
+++ b/src/drivers/linux/linux.c
@@ -130,24 +130,48 @@ struct linux_setting *linux_find_setting(char *name, struct list_head *settings)
return result;
}
-void linux_apply_settings(struct list_head *new_settings, struct settings *settings_block)
-{
- struct linux_setting *setting;
+/**
+ * Apply Linux command-line settings
+ *
+ * @v list List of command-line settings
+ * @v settings Settings block
+ */
+void linux_apply_settings ( struct list_head *list,
+ struct settings *settings ) {
+ struct linux_setting *lsetting;
+ struct settings *ignore;
+ struct setting setting;
int rc;
- list_for_each_entry(setting, new_settings, list) {
+ list_for_each_entry ( lsetting, list, list ) {
+
/* Skip already applied settings */
- if (setting->applied)
+ if ( lsetting->applied )
continue;
- struct setting *s = find_setting(setting->name);
- if (s) {
- rc = storef_setting(settings_block, find_setting(setting->name), setting->value);
- if (rc != 0)
- DBG("linux storing setting '%s' = '%s' failed\n", setting->name, setting->value);
- setting->applied = 1;
- } else {
- DBG("linux unknown setting '%s'\n", setting->name);
+ /* Parse setting name */
+ if ( ( rc = parse_setting_name ( lsetting->name,
+ find_child_settings, &ignore,
+ &setting ) ) != 0 ) {
+ DBGC ( settings, "Linux cannot parse %s: %s\n",
+ lsetting->name, strerror ( rc ) );
+ continue;
+ }
+
+ /* Apply default type if not specified */
+ if ( ! setting.type )
+ setting.type = &setting_type_string;
+
+ /* Store setting */
+ if ( ( rc = storef_setting ( settings, &setting,
+ lsetting->value ) ) != 0 ) {
+ DBGC ( settings, "Linux cannot set %s=\"%s\": %s\n",
+ lsetting->name, lsetting->value,
+ strerror ( rc ) );
+ continue;
}
+
+ /* Mark setting as applied */
+ lsetting->applied = 1;
}
}
diff --git a/src/drivers/linux/slirp.c b/src/drivers/linux/slirp.c
new file mode 100644
index 000000000..8341c9676
--- /dev/null
+++ b/src/drivers/linux/slirp.c
@@ -0,0 +1,552 @@
+/*
+ * Copyright (C) 2021 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.
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <ipxe/netdevice.h>
+#include <ipxe/ethernet.h>
+#include <ipxe/if_ether.h>
+#include <ipxe/in.h>
+#include <ipxe/timer.h>
+#include <ipxe/retry.h>
+#include <ipxe/linux.h>
+#include <ipxe/linux_api.h>
+#include <ipxe/slirp.h>
+
+/** @file
+ *
+ * Linux Slirp network driver
+ *
+ */
+
+/** Maximum number of open file descriptors */
+#define SLIRP_MAX_FDS 128
+
+/** A Slirp network interface */
+struct slirp_nic {
+ /** The libslirp device object */
+ struct Slirp *slirp;
+ /** Polling file descriptor list */
+ struct pollfd pollfds[SLIRP_MAX_FDS];
+ /** Number of file descriptors */
+ unsigned int numfds;
+};
+
+/** A Slirp alarm timer */
+struct slirp_alarm {
+ /** Slirp network interface */
+ struct slirp_nic *slirp;
+ /** Retry timer */
+ struct retry_timer timer;
+ /** Callback function */
+ void ( __asmcall * callback ) ( void *opaque );
+ /** Opaque value for callback function */
+ void *opaque;
+};
+
+/** Default MAC address */
+static const uint8_t slirp_default_mac[ETH_ALEN] =
+ { 0x52, 0x54, 0x00, 0x12, 0x34, 0x56 };
+
+/******************************************************************************
+ *
+ * Slirp interface
+ *
+ ******************************************************************************
+ */
+
+/**
+ * Send packet
+ *
+ * @v buf Data buffer
+ * @v len Length of data
+ * @v device Device opaque pointer
+ * @ret len Consumed length (or negative on error)
+ */
+static ssize_t __asmcall slirp_send_packet ( const void *buf, size_t len,
+ void *device ) {
+ struct net_device *netdev = device;
+ struct io_buffer *iobuf;
+
+ /* Allocate I/O buffer */
+ iobuf = alloc_iob ( len );
+ if ( ! iobuf )
+ return -1;
+
+ /* Populate I/O buffer */
+ memcpy ( iob_put ( iobuf, len ), buf, len );
+
+ /* Hand off to network stack */
+ netdev_rx ( netdev, iobuf );
+
+ return len;
+}
+
+/**
+ * Print an error message
+ *
+ * @v msg Error message
+ * @v device Device opaque pointer
+ */
+static void __asmcall slirp_guest_error ( const char *msg, void *device ) {
+ struct net_device *netdev = device;
+ struct slirp_nic *slirp = netdev->priv;
+
+ DBGC ( slirp, "SLIRP %p error: %s\n", slirp, msg );
+}
+
+/**
+ * Get virtual clock
+ *
+ * @v device Device opaque pointer
+ * @ret clock_ns Clock time in nanoseconds
+ */
+static int64_t __asmcall slirp_clock_get_ns ( void *device __unused ) {
+ int64_t time;
+
+ time = currticks();
+ return ( time * ( 1000000 / TICKS_PER_MS ) );
+}
+
+/**
+ * Handle timer expiry
+ *
+ * @v timer Retry timer
+ * @v over Failure indicator
+ */
+static void slirp_expired ( struct retry_timer *timer, int over __unused ) {
+ struct slirp_alarm *alarm =
+ container_of ( timer, struct slirp_alarm, timer );
+ struct slirp_nic *slirp = alarm->slirp;
+
+ /* Notify callback */
+ DBGC ( slirp, "SLIRP %p timer fired\n", slirp );
+ alarm->callback ( alarm->opaque );
+}
+
+/**
+ * Create a new timer
+ *
+ * @v callback Timer callback
+ * @v opaque Timer opaque pointer
+ * @v device Device opaque pointer
+ * @ret timer Timer
+ */
+static void * __asmcall
+slirp_timer_new ( void ( __asmcall * callback ) ( void *opaque ),
+ void *opaque, void *device ) {
+ struct net_device *netdev = device;
+ struct slirp_nic *slirp = netdev->priv;
+ struct slirp_alarm *alarm;
+
+ /* Allocate timer */
+ alarm = malloc ( sizeof ( *alarm ) );
+ if ( ! alarm ) {
+ DBGC ( slirp, "SLIRP %p could not allocate timer\n", slirp );
+ return NULL;
+ }
+
+ /* Initialise timer */
+ memset ( alarm, 0, sizeof ( *alarm ) );
+ alarm->slirp = slirp;
+ timer_init ( &alarm->timer, slirp_expired, NULL );
+ alarm->callback = callback;
+ alarm->opaque = opaque;
+ DBGC ( slirp, "SLIRP %p timer %p has callback %p (%p)\n",
+ slirp, alarm, alarm->callback, alarm->opaque );
+
+ return alarm;
+}
+
+/**
+ * Delete a timer
+ *
+ * @v timer Timer
+ * @v device Device opaque pointer
+ */
+static void __asmcall slirp_timer_free ( void *timer, void *device ) {
+ struct net_device *netdev = device;
+ struct slirp_nic *slirp = netdev->priv;
+ struct slirp_alarm *alarm = timer;
+
+ /* Ignore timers that failed to allocate */
+ if ( ! alarm )
+ return;
+
+ /* Stop timer */
+ stop_timer ( &alarm->timer );
+
+ /* Free timer */
+ free ( alarm );
+ DBGC ( slirp, "SLIRP %p timer %p freed\n", slirp, alarm );
+}
+
+/**
+ * Set timer expiry time
+ *
+ * @v timer Timer
+ * @v expire Expiry time
+ * @v device Device opaque pointer
+ */
+static void __asmcall slirp_timer_mod ( void *timer, int64_t expire,
+ void *device ) {
+ struct net_device *netdev = device;
+ struct slirp_nic *slirp = netdev->priv;
+ struct slirp_alarm *alarm = timer;
+ int64_t timeout_ms;
+ unsigned long timeout;
+
+ /* Ignore timers that failed to allocate */
+ if ( ! alarm )
+ return;
+
+ /* (Re)start timer */
+ timeout_ms = ( expire - ( currticks() / TICKS_PER_MS ) );
+ if ( timeout_ms < 0 )
+ timeout_ms = 0;
+ timeout = ( timeout_ms * TICKS_PER_MS );
+ start_timer_fixed ( &alarm->timer, timeout );
+ DBGC ( slirp, "SLIRP %p timer %p set for %ld ticks\n",
+ slirp, alarm, timeout );
+}
+
+/**
+ * Register file descriptor for polling
+ *
+ * @v fd File descriptor
+ * @v device Device opaque pointer
+ */
+static void __asmcall slirp_register_poll_fd ( int fd, void *device ) {
+ struct net_device *netdev = device;
+ struct slirp_nic *slirp = netdev->priv;
+
+ DBGC ( slirp, "SLIRP %p registered FD %d\n", slirp, fd );
+}
+
+/**
+ * Unregister file descriptor
+ *
+ * @v fd File descriptor
+ * @v device Device opaque pointer
+ */
+static void __asmcall slirp_unregister_poll_fd ( int fd, void *device ) {
+ struct net_device *netdev = device;
+ struct slirp_nic *slirp = netdev->priv;
+
+ DBGC ( slirp, "SLIRP %p unregistered FD %d\n", slirp, fd );
+}
+
+/**
+ * Notify that new events are ready
+ *
+ * @v device Device opaque pointer
+ */
+static void __asmcall slirp_notify ( void *device ) {
+ struct net_device *netdev = device;
+ struct slirp_nic *slirp = netdev->priv;
+
+ DBGC2 ( slirp, "SLIRP %p notified\n", slirp );
+}
+
+/** Slirp callbacks */
+static struct slirp_callbacks slirp_callbacks = {
+ .send_packet = slirp_send_packet,
+ .guest_error = slirp_guest_error,
+ .clock_get_ns = slirp_clock_get_ns,
+ .timer_new = slirp_timer_new,
+ .timer_free = slirp_timer_free,
+ .timer_mod = slirp_timer_mod,
+ .register_poll_fd = slirp_register_poll_fd,
+ .unregister_poll_fd = slirp_unregister_poll_fd,
+ .notify = slirp_notify,
+};
+
+/******************************************************************************
+ *
+ * Network device interface
+ *
+ ******************************************************************************
+ */
+
+/**
+ * Open network device
+ *
+ * @v netdev Network device
+ * @ret rc Return status code
+ */
+static int slirp_open ( struct net_device *netdev ) {
+ struct slirp_nic *slirp = netdev->priv;
+
+ /* Nothing to do */
+ DBGC ( slirp, "SLIRP %p opened\n", slirp );
+
+ return 0;
+}
+
+/**
+ * Close network device
+ *
+ * @v netdev Network device
+ */
+static void slirp_close ( struct net_device *netdev ) {
+ struct slirp_nic *slirp = netdev->priv;
+
+ /* Nothing to do */
+ DBGC ( slirp, "SLIRP %p closed\n", slirp );
+}
+
+/**
+ * Transmit packet
+ *
+ * @v netdev Network device
+ * @v iobuf I/O buffer
+ * @ret rc Return status code
+ */
+static int slirp_transmit ( struct net_device *netdev,
+ struct io_buffer *iobuf ) {
+ struct slirp_nic *slirp = netdev->priv;
+
+ /* Transmit packet */
+ linux_slirp_input ( slirp->slirp, iobuf->data, iob_len ( iobuf ) );
+ netdev_tx_complete ( netdev, iobuf );
+
+ return 0;
+}
+
+/**
+ * Add polling file descriptor
+ *
+ * @v fd File descriptor
+ * @v events Events of interest
+ * @v device Device opaque pointer
+ * @ret index File descriptor index
+ */
+static int __asmcall slirp_add_poll ( int fd, int events, void *device ) {
+ struct net_device *netdev = device;
+ struct slirp_nic *slirp = netdev->priv;
+ struct pollfd *pollfd;
+ unsigned int index;
+
+ /* Fail if too many descriptors are registered */
+ if ( slirp->numfds >= SLIRP_MAX_FDS ) {
+ DBGC ( slirp, "SLIRP %p too many file descriptors\n", slirp );
+ return -1;
+ }
+
+ /* Populate polling file descriptor */
+ index = slirp->numfds++;
+ pollfd = &slirp->pollfds[index];
+ pollfd->fd = fd;
+ pollfd->events = 0;
+ if ( events & SLIRP_EVENT_IN )
+ pollfd->events |= POLLIN;
+ if ( events & SLIRP_EVENT_OUT )
+ pollfd->events |= POLLOUT;
+ if ( events & SLIRP_EVENT_PRI )
+ pollfd->events |= POLLPRI;
+ if ( events & SLIRP_EVENT_ERR )
+ pollfd->events |= POLLERR;
+ if ( events & SLIRP_EVENT_HUP )
+ pollfd->events |= ( POLLHUP | POLLRDHUP );
+ DBGCP ( slirp, "SLIRP %p polling FD %d event mask %#04x(%#04x)\n",
+ slirp, fd, events, pollfd->events );
+
+ return index;
+}
+
+/**
+ * Get returned events for a file descriptor
+ *
+ * @v index File descriptor index
+ * @v device Device opaque pointer
+ * @ret events Returned events
+ */
+static int __asmcall slirp_get_revents ( int index, void *device ) {
+ struct net_device *netdev = device;
+ struct slirp_nic *slirp = netdev->priv;
+ int revents;
+ int events;
+
+ /* Ignore failed descriptors */
+ if ( index < 0 )
+ return 0;
+
+ /* Collect events */
+ revents = slirp->pollfds[index].revents;
+ events = 0;
+ if ( revents & POLLIN )
+ events |= SLIRP_EVENT_IN;
+ if ( revents & POLLOUT )
+ events |= SLIRP_EVENT_OUT;
+ if ( revents & POLLPRI )
+ events |= SLIRP_EVENT_PRI;
+ if ( revents & POLLERR )
+ events |= SLIRP_EVENT_ERR;
+ if ( revents & ( POLLHUP | POLLRDHUP ) )
+ events |= SLIRP_EVENT_HUP;
+ if ( events ) {
+ DBGC2 ( slirp, "SLIRP %p polled FD %d events %#04x(%#04x)\n",
+ slirp, slirp->pollfds[index].fd, events, revents );
+ }
+
+ return events;
+}
+
+/**
+ * Poll for completed and received packets
+ *
+ * @v netdev Network device
+ */
+static void slirp_poll ( struct net_device *netdev ) {
+ struct slirp_nic *slirp = netdev->priv;
+ uint32_t timeout = 0;
+ int ready;
+ int error;
+
+ /* Rebuild polling file descriptor list */
+ slirp->numfds = 0;
+ linux_slirp_pollfds_fill ( slirp->slirp, &timeout,
+ slirp_add_poll, netdev );
+
+ /* Poll descriptors */
+ ready = linux_poll ( slirp->pollfds, slirp->numfds, 0 );
+ error = ( ready == -1 );
+ linux_slirp_pollfds_poll ( slirp->slirp, error, slirp_get_revents,
+ netdev );
+
+ /* Record polling errors */
+ if ( error ) {
+ DBGC ( slirp, "SLIRP %p poll failed: %s\n",
+ slirp, linux_strerror ( linux_errno ) );
+ netdev_rx_err ( netdev, NULL, -ELINUX ( linux_errno ) );
+ }
+}
+
+/** Network device operations */
+static struct net_device_operations slirp_operations = {
+ .open = slirp_open,
+ .close = slirp_close,
+ .transmit = slirp_transmit,
+ .poll = slirp_poll,
+};
+
+/******************************************************************************
+ *
+ * Linux driver interface
+ *
+ ******************************************************************************
+ */
+
+/**
+ * Probe device
+ *
+ * @v linux Linux device
+ * @v request Device creation request
+ * @ret rc Return status code
+ */
+static int slirp_probe ( struct linux_device *linux,
+ struct linux_device_request *request ) {
+ struct net_device *netdev;
+ struct slirp_nic *slirp;
+ struct slirp_config config;
+ int rc;
+
+ /* Allocate device */
+ netdev = alloc_etherdev ( sizeof ( *slirp ) );
+ if ( ! netdev ) {
+ rc = -ENOMEM;
+ goto err_alloc;
+ }
+ netdev_init ( netdev, &slirp_operations );
+ linux_set_drvdata ( linux, netdev );
+ snprintf ( linux->dev.name, sizeof ( linux->dev.name ), "host" );
+ netdev->dev = &linux->dev;
+ memcpy ( netdev->hw_addr, slirp_default_mac, ETH_ALEN );
+ slirp = netdev->priv;
+ memset ( slirp, 0, sizeof ( *slirp ) );
+
+ /* Apply requested settings */
+ linux_apply_settings ( &request->settings,
+ netdev_settings ( netdev ) );
+
+ /* Initialise default configuration (matching qemu) */
+ memset ( &config, 0, sizeof ( config ) );
+ config.version = 1;
+ config.in_enabled = true;
+ config.vnetwork.s_addr = htonl ( 0x0a000200 ); /* 10.0.2.0 */
+ config.vnetmask.s_addr = htonl ( 0xffffff00 ); /* 255.255.255.0 */
+ config.vhost.s_addr = htonl ( 0x0a000202 ); /* 10.0.2.2 */
+ config.in6_enabled = true;
+ config.vdhcp_start.s_addr = htonl ( 0x0a00020f ); /* 10.0.2.15 */
+ config.vnameserver.s_addr = htonl ( 0x0a000203 ); /* 10.0.2.3 */
+
+ /* Instantiate device */
+ slirp->slirp = linux_slirp_new ( &config, &slirp_callbacks, netdev );
+ if ( ! slirp->slirp ) {
+ DBGC ( slirp, "SLIRP could not instantiate\n" );
+ rc = -ENODEV;
+ goto err_new;
+ }
+
+ /* Register network device */
+ if ( ( rc = register_netdev ( netdev ) ) != 0 )
+ goto err_register;
+
+ /* Set link up since there is no concept of link state */
+ netdev_link_up ( netdev );
+
+ return 0;
+
+ unregister_netdev ( netdev );
+ err_register:
+ linux_slirp_cleanup ( slirp->slirp );
+ err_new:
+ netdev_nullify ( netdev );
+ netdev_put ( netdev );
+ err_alloc:
+ return rc;
+}
+
+/**
+ * Remove device
+ *
+ * @v linux Linux device
+ */
+static void slirp_remove ( struct linux_device *linux ) {
+ struct net_device *netdev = linux_get_drvdata ( linux );
+ struct slirp_nic *slirp = netdev->priv;
+
+ /* Unregister network device */
+ unregister_netdev ( netdev );
+
+ /* Shut down device */
+ linux_slirp_cleanup ( slirp->slirp );
+
+ /* Free network device */
+ netdev_nullify ( netdev );
+ netdev_put ( netdev );
+}
+
+/** Slirp driver */
+struct linux_driver slirp_driver __linux_driver = {
+ .name = "slirp",
+ .probe = slirp_probe,
+ .remove = slirp_remove,
+ .can_probe = 1,
+};
diff --git a/src/drivers/linux/tap.c b/src/drivers/linux/tap.c
index db3b7955b..ff1e08bdb 100644
--- a/src/drivers/linux/tap.c
+++ b/src/drivers/linux/tap.c
@@ -19,7 +19,7 @@
#include <errno.h>
#include <string.h>
#include <stdio.h>
-#include <linux_api.h>
+#include <ipxe/linux_api.h>
#include <ipxe/list.h>
#include <ipxe/linux.h>
#include <ipxe/malloc.h>
diff --git a/src/drivers/net/3c90x.c b/src/drivers/net/3c90x.c
index 853de2b52..63e07777f 100644
--- a/src/drivers/net/3c90x.c
+++ b/src/drivers/net/3c90x.c
@@ -249,7 +249,7 @@ static int a3c90x_setup_tx_ring(struct INF_3C90X *p)
{
DBGP("a3c90x_setup_tx_ring\n");
p->tx_ring =
- malloc_dma(TX_RING_SIZE * sizeof(struct TXD), TX_RING_ALIGN);
+ malloc_phys(TX_RING_SIZE * sizeof(struct TXD), TX_RING_ALIGN);
if (!p->tx_ring) {
DBG("Could not allocate TX-ring\n");
@@ -304,7 +304,7 @@ static void a3c90x_free_tx_ring(struct INF_3C90X *p)
{
DBGP("a3c90x_free_tx_ring\n");
- free_dma(p->tx_ring, TX_RING_SIZE * sizeof(struct TXD));
+ free_phys(p->tx_ring, TX_RING_SIZE * sizeof(struct TXD));
p->tx_ring = NULL;
/* io_buffers are free()ed by netdev_tx_complete[,_err]() */
}
@@ -461,7 +461,7 @@ static int a3c90x_setup_rx_ring(struct INF_3C90X *p)
DBGP("a3c90x_setup_rx_ring\n");
p->rx_ring =
- malloc_dma(RX_RING_SIZE * sizeof(struct RXD), RX_RING_ALIGN);
+ malloc_phys(RX_RING_SIZE * sizeof(struct RXD), RX_RING_ALIGN);
if (!p->rx_ring) {
DBG("Could not allocate RX-ring\n");
@@ -491,7 +491,7 @@ static void a3c90x_free_rx_ring(struct INF_3C90X *p)
{
DBGP("a3c90x_free_rx_ring\n");
- free_dma(p->rx_ring, RX_RING_SIZE * sizeof(struct RXD));
+ free_phys(p->rx_ring, RX_RING_SIZE * sizeof(struct RXD));
p->rx_ring = NULL;
}
diff --git a/src/drivers/net/amd8111e.c b/src/drivers/net/amd8111e.c
index 693d77d1d..babd12d3c 100644
--- a/src/drivers/net/amd8111e.c
+++ b/src/drivers/net/amd8111e.c
@@ -664,7 +664,7 @@ static int amd8111e_probe(struct nic *nic, struct pci_device *pdev)
memset(lp, 0, sizeof(*lp));
lp->pdev = pdev;
lp->nic = nic;
- lp->mmio = ioremap(mmio_start, mmio_len);
+ lp->mmio = pci_ioremap(pdev, mmio_start, mmio_len);
lp->opened = 1;
adjust_pci_device(pdev);
diff --git a/src/drivers/net/ath/ath5k/ath5k.c b/src/drivers/net/ath/ath5k/ath5k.c
index a500175a7..e43eb0aaf 100644
--- a/src/drivers/net/ath/ath5k/ath5k.c
+++ b/src/drivers/net/ath/ath5k/ath5k.c
@@ -280,7 +280,7 @@ static int ath5k_probe(struct pci_device *pdev)
*/
pci_write_config_byte(pdev, 0x41, 0);
- mem = ioremap(pdev->membase, 0x10000);
+ mem = pci_ioremap(pdev, pdev->membase, 0x10000);
if (!mem) {
DBG("ath5k: cannot remap PCI memory region\n");
ret = -EIO;
@@ -877,7 +877,7 @@ ath5k_desc_alloc(struct ath5k_softc *sc)
/* allocate descriptors */
sc->desc_len = sizeof(struct ath5k_desc) * (ATH_TXBUF + ATH_RXBUF + 1);
- sc->desc = malloc_dma(sc->desc_len, ATH5K_DESC_ALIGN);
+ sc->desc = malloc_phys(sc->desc_len, ATH5K_DESC_ALIGN);
if (sc->desc == NULL) {
DBG("ath5k: can't allocate descriptors\n");
ret = -ENOMEM;
@@ -915,7 +915,7 @@ ath5k_desc_alloc(struct ath5k_softc *sc)
return 0;
err_free:
- free_dma(sc->desc, sc->desc_len);
+ free_phys(sc->desc, sc->desc_len);
err:
sc->desc = NULL;
return ret;
@@ -932,7 +932,7 @@ ath5k_desc_free(struct ath5k_softc *sc)
ath5k_rxbuf_free(sc, bf);
/* Free memory associated with all descriptors */
- free_dma(sc->desc, sc->desc_len);
+ free_phys(sc->desc, sc->desc_len);
free(sc->bufptr);
sc->bufptr = NULL;
diff --git a/src/drivers/net/ath/ath5k/ath5k_eeprom.c b/src/drivers/net/ath/ath5k/ath5k_eeprom.c
index 983d206b7..12519bc59 100644
--- a/src/drivers/net/ath/ath5k/ath5k_eeprom.c
+++ b/src/drivers/net/ath/ath5k/ath5k_eeprom.c
@@ -416,6 +416,7 @@ ath5k_eeprom_read_turbo_modes(struct ath5k_hw *ah,
if (ee->ee_version < AR5K_EEPROM_VERSION_5_0)
return 0;
+ AR5K_EEPROM_READ(o++, val);
switch (mode){
case AR5K_EEPROM_MODE_11A:
ee->ee_switch_settling_turbo[mode] = (val >> 6) & 0x7f;
diff --git a/src/drivers/net/ath/ath9k/ath9k.c b/src/drivers/net/ath/ath9k/ath9k.c
index 183aa65f6..98b7ecd5a 100644
--- a/src/drivers/net/ath/ath9k/ath9k.c
+++ b/src/drivers/net/ath/ath9k/ath9k.c
@@ -138,7 +138,7 @@ static int ath_pci_probe(struct pci_device *pdev)
if ((val & 0x0000ff00) != 0)
pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
- mem = ioremap(pdev->membase, 0x10000);
+ mem = pci_ioremap(pdev, pdev->membase, 0x10000);
if (!mem) {
DBG("ath9K: PCI memory map error\n") ;
ret = -EIO;
diff --git a/src/drivers/net/ath/ath9k/ath9k_init.c b/src/drivers/net/ath/ath9k/ath9k_init.c
index 98a0d6d59..05ed3336a 100644
--- a/src/drivers/net/ath/ath9k/ath9k_init.c
+++ b/src/drivers/net/ath/ath9k/ath9k_init.c
@@ -223,7 +223,7 @@ int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
}
/* allocate descriptors */
- dd->dd_desc = malloc_dma(dd->dd_desc_len, 16);
+ dd->dd_desc = malloc_phys(dd->dd_desc_len, 16);
if (dd->dd_desc == NULL) {
error = -ENOMEM;
goto fail;
@@ -264,7 +264,7 @@ int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
}
return 0;
fail2:
- free_dma(dd->dd_desc, dd->dd_desc_len);
+ free_phys(dd->dd_desc, dd->dd_desc_len);
fail:
memset(dd, 0, sizeof(*dd));
return error;
@@ -588,7 +588,7 @@ void ath_descdma_cleanup(struct ath_softc *sc __unused,
struct ath_descdma *dd,
struct list_head *head)
{
- free_dma(dd->dd_desc, dd->dd_desc_len);
+ free_phys(dd->dd_desc, dd->dd_desc_len);
INIT_LIST_HEAD(head);
free(dd->dd_bufptr);
diff --git a/src/drivers/net/atl1e.c b/src/drivers/net/atl1e.c
index d010d8c4a..0f0df5326 100644
--- a/src/drivers/net/atl1e.c
+++ b/src/drivers/net/atl1e.c
@@ -370,7 +370,7 @@ static void atl1e_free_ring_resources(struct atl1e_adapter *adapter)
atl1e_clean_rx_ring(adapter);
if (adapter->ring_vir_addr) {
- free_dma(adapter->ring_vir_addr, adapter->ring_size);
+ free_phys(adapter->ring_vir_addr, adapter->ring_size);
adapter->ring_vir_addr = NULL;
adapter->ring_dma = 0;
}
@@ -405,7 +405,7 @@ static int atl1e_setup_ring_resources(struct atl1e_adapter *adapter)
/* real ring DMA buffer */
size = adapter->ring_size;
- adapter->ring_vir_addr = malloc_dma(adapter->ring_size, 32);
+ adapter->ring_vir_addr = malloc_phys(adapter->ring_size, 32);
if (adapter->ring_vir_addr == NULL) {
DBG("atl1e: out of memory allocating %d bytes for %s ring\n",
diff --git a/src/drivers/net/b44.c b/src/drivers/net/b44.c
index d9aeb1b4b..eaf6d35ce 100644
--- a/src/drivers/net/b44.c
+++ b/src/drivers/net/b44.c
@@ -436,7 +436,7 @@ static void b44_free_rx_ring(struct b44_private *bp)
free_iob(bp->rx_iobuf[i]);
bp->rx_iobuf[i] = NULL;
}
- free_dma(bp->rx, B44_RX_RING_LEN_BYTES);
+ free_phys(bp->rx, B44_RX_RING_LEN_BYTES);
bp->rx = NULL;
}
}
@@ -446,11 +446,11 @@ static int b44_init_rx_ring(struct b44_private *bp)
{
b44_free_rx_ring(bp);
- bp->rx = malloc_dma(B44_RX_RING_LEN_BYTES, B44_DMA_ALIGNMENT);
+ bp->rx = malloc_phys(B44_RX_RING_LEN_BYTES, B44_DMA_ALIGNMENT);
if (!bp->rx)
return -ENOMEM;
if (!b44_address_ok(bp->rx)) {
- free_dma(bp->rx, B44_RX_RING_LEN_BYTES);
+ free_phys(bp->rx, B44_RX_RING_LEN_BYTES);
return -ENOTSUP;
}
@@ -468,7 +468,7 @@ static int b44_init_rx_ring(struct b44_private *bp)
static void b44_free_tx_ring(struct b44_private *bp)
{
if (bp->tx) {
- free_dma(bp->tx, B44_TX_RING_LEN_BYTES);
+ free_phys(bp->tx, B44_TX_RING_LEN_BYTES);
bp->tx = NULL;
}
}
@@ -478,11 +478,11 @@ static int b44_init_tx_ring(struct b44_private *bp)
{
b44_free_tx_ring(bp);
- bp->tx = malloc_dma(B44_TX_RING_LEN_BYTES, B44_DMA_ALIGNMENT);
+ bp->tx = malloc_phys(B44_TX_RING_LEN_BYTES, B44_DMA_ALIGNMENT);
if (!bp->tx)
return -ENOMEM;
if (!b44_address_ok(bp->tx)) {
- free_dma(bp->tx, B44_TX_RING_LEN_BYTES);
+ free_phys(bp->tx, B44_TX_RING_LEN_BYTES);
return -ENOTSUP;
}
@@ -673,7 +673,7 @@ static int b44_probe(struct pci_device *pci)
bp->pci = pci;
/* Map device registers */
- bp->regs = ioremap(pci->membase, B44_REGS_SIZE);
+ bp->regs = pci_ioremap(pci, pci->membase, B44_REGS_SIZE);
if (!bp->regs) {
netdev_put(netdev);
return -ENOMEM;
diff --git a/src/drivers/net/bnx2.c b/src/drivers/net/bnx2.c
index 4ebcc52a9..d5783ff99 100644
--- a/src/drivers/net/bnx2.c
+++ b/src/drivers/net/bnx2.c
@@ -2152,7 +2152,7 @@ bnx2_init_board(struct pci_device *pdev, struct nic *nic)
bnx2reg_base = pci_bar_start(pdev, PCI_BASE_ADDRESS_0);
bnx2reg_len = MB_GET_CID_ADDR(17);
- bp->regview = ioremap(bnx2reg_base, bnx2reg_len);
+ bp->regview = pci_ioremap(pdev, bnx2reg_base, bnx2reg_len);
if (!bp->regview) {
printf("Cannot map register space, aborting.\n");
diff --git a/src/drivers/net/bnxt/bnxt.c b/src/drivers/net/bnxt/bnxt.c
index e6bceb970..b8663c00a 100644
--- a/src/drivers/net/bnxt/bnxt.c
+++ b/src/drivers/net/bnxt/bnxt.c
@@ -60,7 +60,7 @@ static void *bnxt_pci_base ( struct pci_device *pdev, unsigned int reg )
reg_base = pci_bar_start ( pdev, reg );
reg_size = pci_bar_size ( pdev, reg );
- return ioremap ( reg_base, reg_size );
+ return pci_ioremap ( pdev, reg_base, reg_size );
}
static int bnxt_get_pci_info ( struct bnxt *bp )
@@ -495,39 +495,39 @@ void bnxt_free_mem ( struct bnxt *bp )
{
DBGP ( "%s\n", __func__ );
if ( bp->nq.bd_virt ) {
- free_dma ( bp->nq.bd_virt, NQ_RING_BUFFER_SIZE );
+ free_phys ( bp->nq.bd_virt, NQ_RING_BUFFER_SIZE );
bp->nq.bd_virt = NULL;
}
if ( bp->cq.bd_virt ) {
- free_dma ( bp->cq.bd_virt, CQ_RING_BUFFER_SIZE );
+ free_phys ( bp->cq.bd_virt, CQ_RING_BUFFER_SIZE );
bp->cq.bd_virt = NULL;
}
if ( bp->rx.bd_virt ) {
- free_dma ( bp->rx.bd_virt, RX_RING_BUFFER_SIZE );
+ free_phys ( bp->rx.bd_virt, RX_RING_BUFFER_SIZE );
bp->rx.bd_virt = NULL;
}
if ( bp->tx.bd_virt ) {
- free_dma ( bp->tx.bd_virt, TX_RING_BUFFER_SIZE );
+ free_phys ( bp->tx.bd_virt, TX_RING_BUFFER_SIZE );
bp->tx.bd_virt = NULL;
}
if ( bp->hwrm_addr_dma ) {
- free_dma ( bp->hwrm_addr_dma, DMA_BUFFER_SIZE );
+ free_phys ( bp->hwrm_addr_dma, DMA_BUFFER_SIZE );
bp->dma_addr_mapping = 0;
bp->hwrm_addr_dma = NULL;
}
if ( bp->hwrm_addr_resp ) {
- free_dma ( bp->hwrm_addr_resp, RESP_BUFFER_SIZE );
+ free_phys ( bp->hwrm_addr_resp, RESP_BUFFER_SIZE );
bp->resp_addr_mapping = 0;
bp->hwrm_addr_resp = NULL;
}
if ( bp->hwrm_addr_req ) {
- free_dma ( bp->hwrm_addr_req, REQ_BUFFER_SIZE );
+ free_phys ( bp->hwrm_addr_req, REQ_BUFFER_SIZE );
bp->req_addr_mapping = 0;
bp->hwrm_addr_req = NULL;
}
@@ -537,14 +537,14 @@ void bnxt_free_mem ( struct bnxt *bp )
int bnxt_alloc_mem ( struct bnxt *bp )
{
DBGP ( "%s\n", __func__ );
- bp->hwrm_addr_req = malloc_dma ( REQ_BUFFER_SIZE, BNXT_DMA_ALIGNMENT );
- bp->hwrm_addr_resp = malloc_dma ( RESP_BUFFER_SIZE,
- BNXT_DMA_ALIGNMENT );
- bp->hwrm_addr_dma = malloc_dma ( DMA_BUFFER_SIZE, BNXT_DMA_ALIGNMENT );
- bp->tx.bd_virt = malloc_dma ( TX_RING_BUFFER_SIZE, DMA_ALIGN_4K );
- bp->rx.bd_virt = malloc_dma ( RX_RING_BUFFER_SIZE, DMA_ALIGN_4K );
- bp->cq.bd_virt = malloc_dma ( CQ_RING_BUFFER_SIZE, BNXT_DMA_ALIGNMENT );
- bp->nq.bd_virt = malloc_dma ( NQ_RING_BUFFER_SIZE, BNXT_DMA_ALIGNMENT );
+ bp->hwrm_addr_req = malloc_phys ( REQ_BUFFER_SIZE, BNXT_DMA_ALIGNMENT );
+ bp->hwrm_addr_resp = malloc_phys ( RESP_BUFFER_SIZE,
+ BNXT_DMA_ALIGNMENT );
+ bp->hwrm_addr_dma = malloc_phys ( DMA_BUFFER_SIZE, BNXT_DMA_ALIGNMENT );
+ bp->tx.bd_virt = malloc_phys ( TX_RING_BUFFER_SIZE, DMA_ALIGN_4K );
+ bp->rx.bd_virt = malloc_phys ( RX_RING_BUFFER_SIZE, DMA_ALIGN_4K );
+ bp->cq.bd_virt = malloc_phys ( CQ_RING_BUFFER_SIZE, BNXT_DMA_ALIGNMENT );
+ bp->nq.bd_virt = malloc_phys ( NQ_RING_BUFFER_SIZE, BNXT_DMA_ALIGNMENT );
test_if ( bp->hwrm_addr_req &&
bp->hwrm_addr_resp &&
bp->hwrm_addr_dma &&
diff --git a/src/drivers/net/eepro100.c b/src/drivers/net/eepro100.c
index 1046cda39..1a802b590 100644
--- a/src/drivers/net/eepro100.c
+++ b/src/drivers/net/eepro100.c
@@ -93,7 +93,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
/*
* Debugging levels:
- * - DBG() is for any errors, i.e. failed alloc_iob(), malloc_dma(),
+ * - DBG() is for any errors, i.e. failed alloc_iob(), malloc_phys(),
* TX overflow, corrupted packets, ...
* - DBG2() is for successful events, like packet received,
* packet transmitted, and other general notifications.
@@ -335,7 +335,7 @@ static int ifec_net_open ( struct net_device *netdev )
ifec_mdio_setup ( netdev, options );
/* Prepare MAC address w/ Individual Address Setup (ias) command.*/
- ias = malloc_dma ( sizeof ( *ias ), CB_ALIGN );
+ ias = malloc_phys ( sizeof ( *ias ), CB_ALIGN );
if ( !ias ) {
rc = -ENOMEM;
goto error;
@@ -345,7 +345,7 @@ static int ifec_net_open ( struct net_device *netdev )
memcpy ( ias->ia, netdev->ll_addr, ETH_ALEN );
/* Prepare operating parameters w/ a configure command. */
- cfg = malloc_dma ( sizeof ( *cfg ), CB_ALIGN );
+ cfg = malloc_phys ( sizeof ( *cfg ), CB_ALIGN );
if ( !cfg ) {
rc = -ENOMEM;
goto error;
@@ -367,8 +367,8 @@ static int ifec_net_open ( struct net_device *netdev )
DBG ( "Failed to initiate!\n" );
goto error;
}
- free_dma ( ias, sizeof ( *ias ) );
- free_dma ( cfg, sizeof ( *cfg ) );
+ free_phys ( ias, sizeof ( *ias ) );
+ free_phys ( cfg, sizeof ( *cfg ) );
DBG2 ( "cfg " );
/* Enable rx by sending ring address to card */
@@ -381,8 +381,8 @@ static int ifec_net_open ( struct net_device *netdev )
return 0;
error:
- free_dma ( cfg, sizeof ( *cfg ) );
- free_dma ( ias, sizeof ( *ias ) );
+ free_phys ( cfg, sizeof ( *cfg ) );
+ free_phys ( ias, sizeof ( *ias ) );
ifec_free ( netdev );
ifec_reset ( netdev );
return rc;
@@ -703,7 +703,7 @@ static void ifec_free ( struct net_device *netdev )
}
/* free TX ring buffer */
- free_dma ( priv->tcbs, TX_RING_BYTES );
+ free_phys ( priv->tcbs, TX_RING_BYTES );
priv->tcbs = NULL;
}
@@ -1025,7 +1025,7 @@ static int ifec_tx_setup ( struct net_device *netdev )
DBGP ( "ifec_tx_setup\n" );
/* allocate tx ring */
- priv->tcbs = malloc_dma ( TX_RING_BYTES, CB_ALIGN );
+ priv->tcbs = malloc_phys ( TX_RING_BYTES, CB_ALIGN );
if ( !priv->tcbs ) {
DBG ( "TX-ring allocation failed\n" );
return -ENOMEM;
diff --git a/src/drivers/net/efi/nii.c b/src/drivers/net/efi/nii.c
index 2d87e0c63..b9f34650e 100644
--- a/src/drivers/net/efi/nii.c
+++ b/src/drivers/net/efi/nii.c
@@ -789,6 +789,20 @@ static int nii_initialise_flags ( struct nii_nic *nii, unsigned int flags ) {
}
/**
+ * Initialise UNDI with cable detection
+ *
+ * @v nii NII NIC
+ * @ret rc Return status code
+ */
+static int nii_initialise_cable ( struct nii_nic *nii ) {
+ unsigned int flags;
+
+ /* Initialise UNDI */
+ flags = PXE_OPFLAGS_INITIALIZE_DETECT_CABLE;
+ return nii_initialise_flags ( nii, flags );
+}
+
+/**
* Initialise UNDI
*
* @v nii NII NIC
@@ -961,9 +975,8 @@ static int nii_transmit ( struct net_device *netdev,
/* Construct parameter block */
memset ( &cpb, 0, sizeof ( cpb ) );
- cpb.FrameAddr = virt_to_bus ( iobuf->data );
+ cpb.FrameAddr = ( ( intptr_t ) iobuf->data );
cpb.DataLen = iob_len ( iobuf );
- cpb.MediaheaderLen = netdev->ll_protocol->ll_header_len;
/* Transmit packet */
op = NII_OP ( PXE_OPCODE_TRANSMIT,
@@ -1030,7 +1043,7 @@ static void nii_poll_rx ( struct net_device *netdev ) {
/* Construct parameter block */
memset ( &cpb, 0, sizeof ( cpb ) );
- cpb.BufferAddr = virt_to_bus ( nii->rxbuf->data );
+ cpb.BufferAddr = ( ( intptr_t ) nii->rxbuf->data );
cpb.BufferLen = iob_tailroom ( nii->rxbuf );
/* Issue command */
@@ -1122,7 +1135,6 @@ static void nii_poll ( struct net_device *netdev ) {
*/
static int nii_open ( struct net_device *netdev ) {
struct nii_nic *nii = netdev->priv;
- unsigned int flags;
int rc;
/* Initialise NIC
@@ -1140,15 +1152,21 @@ static int nii_open ( struct net_device *netdev ) {
* presence during initialisation on links that are physically
* slow to reach link-up.
*
- * Attempt to work around both of these problems by requesting
- * cable detection at this point if any only if the driver is
- * not capable of reporting link status changes at runtime via
- * PXE_OPCODE_GET_STATUS.
+ * Attempt to work around both of these problems by first
+ * attempting to initialise with cable presence detection,
+ * then falling back to initialising without cable presence
+ * detection.
*/
- flags = ( nii->media ? PXE_OPFLAGS_INITIALIZE_DO_NOT_DETECT_CABLE
- : PXE_OPFLAGS_INITIALIZE_DETECT_CABLE );
- if ( ( rc = nii_initialise_flags ( nii, flags ) ) != 0 )
- goto err_initialise;
+ if ( ( rc = nii_initialise_cable ( nii ) ) != 0 ) {
+ DBGC ( nii, "NII %s could not initialise with cable "
+ "detection: %s\n", nii->dev.name, strerror ( rc ) );
+ if ( ( rc = nii_initialise ( nii ) ) != 0 ) {
+ DBGC ( nii, "NII %s could not initialise without "
+ "cable detection: %s\n",
+ nii->dev.name, strerror ( rc ) );
+ goto err_initialise;
+ }
+ }
/* Attempt to set station address */
if ( ( rc = nii_set_station_address ( nii, netdev ) ) != 0 ) {
diff --git a/src/drivers/net/ena.c b/src/drivers/net/ena.c
index 0f25c0beb..85da1c090 100644
--- a/src/drivers/net/ena.c
+++ b/src/drivers/net/ena.c
@@ -65,35 +65,59 @@ static const char * ena_direction ( unsigned int direction ) {
*/
/**
- * Reset hardware
+ * Wait for reset operation to be acknowledged
*
* @v ena ENA device
+ * @v expected Expected reset state
* @ret rc Return status code
*/
-static int ena_reset ( struct ena_nic *ena ) {
+static int ena_reset_wait ( struct ena_nic *ena, uint32_t expected ) {
uint32_t stat;
unsigned int i;
- /* Trigger reset */
- writel ( ENA_CTRL_RESET, ( ena->regs + ENA_CTRL ) );
-
/* Wait for reset to complete */
for ( i = 0 ; i < ENA_RESET_MAX_WAIT_MS ; i++ ) {
/* Check if device is ready */
stat = readl ( ena->regs + ENA_STAT );
- if ( stat & ENA_STAT_READY )
+ if ( ( stat & ENA_STAT_RESET ) == expected )
return 0;
/* Delay */
mdelay ( 1 );
}
- DBGC ( ena, "ENA %p timed out waiting for reset (status %#08x)\n",
- ena, stat );
+ DBGC ( ena, "ENA %p timed out waiting for reset status %#08x "
+ "(got %#08x)\n", ena, expected, stat );
return -ETIMEDOUT;
}
+/**
+ * Reset hardware
+ *
+ * @v ena ENA device
+ * @ret rc Return status code
+ */
+static int ena_reset ( struct ena_nic *ena ) {
+ int rc;
+
+ /* Trigger reset */
+ writel ( ENA_CTRL_RESET, ( ena->regs + ENA_CTRL ) );
+
+ /* Wait for reset to take effect */
+ if ( ( rc = ena_reset_wait ( ena, ENA_STAT_RESET ) ) != 0 )
+ return rc;
+
+ /* Clear reset */
+ writel ( 0, ( ena->regs + ENA_CTRL ) );
+
+ /* Wait for reset to clear */
+ if ( ( rc = ena_reset_wait ( ena, 0 ) ) != 0 )
+ return rc;
+
+ return 0;
+}
+
/******************************************************************************
*
* Admin queue
@@ -164,7 +188,7 @@ static int ena_create_admin ( struct ena_nic *ena ) {
int rc;
/* Allocate admin completion queue */
- ena->acq.rsp = malloc_dma ( acq_len, acq_len );
+ ena->acq.rsp = malloc_phys ( acq_len, acq_len );
if ( ! ena->acq.rsp ) {
rc = -ENOMEM;
goto err_alloc_acq;
@@ -172,7 +196,7 @@ static int ena_create_admin ( struct ena_nic *ena ) {
memset ( ena->acq.rsp, 0, acq_len );
/* Allocate admin queue */
- ena->aq.req = malloc_dma ( aq_len, aq_len );
+ ena->aq.req = malloc_phys ( aq_len, aq_len );
if ( ! ena->aq.req ) {
rc = -ENOMEM;
goto err_alloc_aq;
@@ -196,9 +220,9 @@ static int ena_create_admin ( struct ena_nic *ena ) {
ena_clear_caps ( ena, ENA_AQ_CAPS );
ena_clear_caps ( ena, ENA_ACQ_CAPS );
- free_dma ( ena->aq.req, aq_len );
+ free_phys ( ena->aq.req, aq_len );
err_alloc_aq:
- free_dma ( ena->acq.rsp, acq_len );
+ free_phys ( ena->acq.rsp, acq_len );
err_alloc_acq:
return rc;
}
@@ -218,8 +242,8 @@ static void ena_destroy_admin ( struct ena_nic *ena ) {
wmb();
/* Free queues */
- free_dma ( ena->aq.req, aq_len );
- free_dma ( ena->acq.rsp, acq_len );
+ free_phys ( ena->aq.req, aq_len );
+ free_phys ( ena->acq.rsp, acq_len );
DBGC ( ena, "ENA %p AQ and ACQ destroyed\n", ena );
}
@@ -338,7 +362,7 @@ static int ena_create_sq ( struct ena_nic *ena, struct ena_sq *sq,
int rc;
/* Allocate submission queue entries */
- sq->sqe.raw = malloc_dma ( sq->len, ENA_ALIGN );
+ sq->sqe.raw = malloc_phys ( sq->len, ENA_ALIGN );
if ( ! sq->sqe.raw ) {
rc = -ENOMEM;
goto err_alloc;
@@ -375,7 +399,7 @@ static int ena_create_sq ( struct ena_nic *ena, struct ena_sq *sq,
return 0;
err_admin:
- free_dma ( sq->sqe.raw, sq->len );
+ free_phys ( sq->sqe.raw, sq->len );
err_alloc:
return rc;
}
@@ -403,7 +427,7 @@ static int ena_destroy_sq ( struct ena_nic *ena, struct ena_sq *sq ) {
return rc;
/* Free submission queue entries */
- free_dma ( sq->sqe.raw, sq->len );
+ free_phys ( sq->sqe.raw, sq->len );
DBGC ( ena, "ENA %p %s SQ%d destroyed\n",
ena, ena_direction ( sq->direction ), sq->id );
@@ -423,7 +447,7 @@ static int ena_create_cq ( struct ena_nic *ena, struct ena_cq *cq ) {
int rc;
/* Allocate completion queue entries */
- cq->cqe.raw = malloc_dma ( cq->len, ENA_ALIGN );
+ cq->cqe.raw = malloc_phys ( cq->len, ENA_ALIGN );
if ( ! cq->cqe.raw ) {
rc = -ENOMEM;
goto err_alloc;
@@ -461,7 +485,7 @@ static int ena_create_cq ( struct ena_nic *ena, struct ena_cq *cq ) {
return 0;
err_admin:
- free_dma ( cq->cqe.raw, cq->len );
+ free_phys ( cq->cqe.raw, cq->len );
err_alloc:
return rc;
}
@@ -488,7 +512,7 @@ static int ena_destroy_cq ( struct ena_nic *ena, struct ena_cq *cq ) {
return rc;
/* Free completion queue entries */
- free_dma ( cq->cqe.raw, cq->len );
+ free_phys ( cq->cqe.raw, cq->len );
DBGC ( ena, "ENA %p CQ%d destroyed\n", ena, cq->id );
return 0;
@@ -933,7 +957,7 @@ static int ena_probe ( struct pci_device *pci ) {
adjust_pci_device ( pci );
/* Map registers */
- ena->regs = ioremap ( pci->membase, ENA_BAR_SIZE );
+ ena->regs = pci_ioremap ( pci, pci->membase, ENA_BAR_SIZE );
if ( ! ena->regs ) {
rc = -ENODEV;
goto err_ioremap;
diff --git a/src/drivers/net/ena.h b/src/drivers/net/ena.h
index 0496fc6bd..676c5b878 100644
--- a/src/drivers/net/ena.h
+++ b/src/drivers/net/ena.h
@@ -66,7 +66,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** Device status register */
#define ENA_STAT 0x58
-#define ENA_STAT_READY 0x00000001UL /**< Ready */
+#define ENA_STAT_RESET 0x00000008UL /**< Reset in progress */
/** Admin queue entry header */
struct ena_aq_header {
diff --git a/src/drivers/net/etherfabric.c b/src/drivers/net/etherfabric.c
index 2cd41d4ca..e43d4336e 100644
--- a/src/drivers/net/etherfabric.c
+++ b/src/drivers/net/etherfabric.c
@@ -3025,7 +3025,7 @@ falcon_free_special_buffer ( void *p )
{
/* We don't bother cleaning up the buffer table entries -
* we're hardly limited */
- free_dma ( p, EFAB_BUF_ALIGN );
+ free_phys ( p, EFAB_BUF_ALIGN );
}
static void*
@@ -3038,7 +3038,7 @@ falcon_alloc_special_buffer ( struct efab_nic *efab, int bytes,
unsigned long dma_addr;
/* Allocate the buffer, aligned on a buffer address boundary */
- buffer = malloc_dma ( bytes, EFAB_BUF_ALIGN );
+ buffer = malloc_phys ( bytes, EFAB_BUF_ALIGN );
if ( ! buffer )
return NULL;
@@ -4150,7 +4150,7 @@ efab_probe ( struct pci_device *pci )
/* Get iobase/membase */
mmio_start = pci_bar_start ( pci, PCI_BASE_ADDRESS_2 );
mmio_len = pci_bar_size ( pci, PCI_BASE_ADDRESS_2 );
- efab->membase = ioremap ( mmio_start, mmio_len );
+ efab->membase = pci_ioremap ( pci, mmio_start, mmio_len );
EFAB_TRACE ( "BAR of %lx bytes at phys %lx mapped at %p\n",
mmio_len, mmio_start, efab->membase );
diff --git a/src/drivers/net/exanic.c b/src/drivers/net/exanic.c
index 287e14e8d..aaa6a28a1 100644
--- a/src/drivers/net/exanic.c
+++ b/src/drivers/net/exanic.c
@@ -800,7 +800,7 @@ static int exanic_probe ( struct pci_device *pci ) {
/* Map registers */
regs_bar_start = pci_bar_start ( pci, EXANIC_REGS_BAR );
- exanic->regs = ioremap ( regs_bar_start, EXANIC_REGS_LEN );
+ exanic->regs = pci_ioremap ( pci, regs_bar_start, EXANIC_REGS_LEN );
if ( ! exanic->regs ) {
rc = -ENODEV;
goto err_ioremap_regs;
@@ -824,14 +824,14 @@ static int exanic_probe ( struct pci_device *pci ) {
/* Map transmit region */
tx_bar_start = pci_bar_start ( pci, EXANIC_TX_BAR );
tx_bar_len = pci_bar_size ( pci, EXANIC_TX_BAR );
- exanic->tx = ioremap ( tx_bar_start, tx_bar_len );
+ exanic->tx = pci_ioremap ( pci, tx_bar_start, tx_bar_len );
if ( ! exanic->tx ) {
rc = -ENODEV;
goto err_ioremap_tx;
}
/* Allocate transmit feedback region (shared between all ports) */
- exanic->txf = malloc_dma ( EXANIC_TXF_LEN, EXANIC_ALIGN );
+ exanic->txf = malloc_phys ( EXANIC_TXF_LEN, EXANIC_ALIGN );
if ( ! exanic->txf ) {
rc = -ENOMEM;
goto err_alloc_txf;
@@ -853,7 +853,7 @@ static int exanic_probe ( struct pci_device *pci ) {
for ( i-- ; i >= 0 ; i-- )
exanic_remove_port ( exanic, i );
exanic_reset ( exanic );
- free_dma ( exanic->txf, EXANIC_TXF_LEN );
+ free_phys ( exanic->txf, EXANIC_TXF_LEN );
err_alloc_txf:
iounmap ( exanic->tx );
err_ioremap_tx:
@@ -882,7 +882,7 @@ static void exanic_remove ( struct pci_device *pci ) {
exanic_reset ( exanic );
/* Free transmit feedback region */
- free_dma ( exanic->txf, EXANIC_TXF_LEN );
+ free_phys ( exanic->txf, EXANIC_TXF_LEN );
/* Unmap transmit region */
iounmap ( exanic->tx );
diff --git a/src/drivers/net/forcedeth.c b/src/drivers/net/forcedeth.c
index 7f044b192..7fba08a08 100644
--- a/src/drivers/net/forcedeth.c
+++ b/src/drivers/net/forcedeth.c
@@ -267,7 +267,7 @@ nv_init_rings ( struct forcedeth_private *priv )
/* Allocate ring for both TX and RX */
priv->rx_ring =
- malloc_dma ( sizeof(struct ring_desc) * RXTX_RING_SIZE, 32 );
+ malloc_phys ( sizeof(struct ring_desc) * RXTX_RING_SIZE, 32 );
if ( ! priv->rx_ring )
goto err_malloc;
priv->tx_ring = &priv->rx_ring[RX_RING_SIZE];
@@ -308,7 +308,7 @@ nv_free_rxtx_resources ( struct forcedeth_private *priv )
DBGP ( "nv_free_rxtx_resources\n" );
- free_dma ( priv->rx_ring, sizeof(struct ring_desc) * RXTX_RING_SIZE );
+ free_phys ( priv->rx_ring, sizeof(struct ring_desc) * RXTX_RING_SIZE );
for ( i = 0; i < RX_RING_SIZE; i++ ) {
free_iob ( priv->rx_iobuf[i] );
@@ -1762,7 +1762,7 @@ forcedeth_map_regs ( struct forcedeth_private *priv )
}
rc = -ENOMEM;
- ioaddr = ioremap ( addr, register_size );
+ ioaddr = pci_ioremap ( priv->pci_dev, addr, register_size );
if ( ! ioaddr ) {
DBG ( "Cannot remap MMIO\n" );
goto err_ioremap;
diff --git a/src/drivers/net/icplus.c b/src/drivers/net/icplus.c
index 4bed92427..acd2e2363 100644
--- a/src/drivers/net/icplus.c
+++ b/src/drivers/net/icplus.c
@@ -343,7 +343,7 @@ static int icplus_create_ring ( struct icplus_nic *icp, struct icplus_ring *ring
struct icplus_descriptor *next;
/* Allocate descriptor ring */
- ring->entry = malloc_dma ( len, ICP_ALIGN );
+ ring->entry = malloc_phys ( len, ICP_ALIGN );
if ( ! ring->entry ) {
rc = -ENOMEM;
goto err_alloc;
@@ -369,7 +369,7 @@ static int icplus_create_ring ( struct icplus_nic *icp, struct icplus_ring *ring
( virt_to_bus ( ring->entry ) + len ) );
return 0;
- free_dma ( ring->entry, len );
+ free_phys ( ring->entry, len );
ring->entry = NULL;
err_alloc:
return rc;
@@ -386,7 +386,7 @@ static void icplus_destroy_ring ( struct icplus_nic *icp __unused,
size_t len = ( sizeof ( ring->entry[0] ) * ICP_NUM_DESC );
/* Free descriptor ring */
- free_dma ( ring->entry, len );
+ free_phys ( ring->entry, len );
ring->entry = NULL;
}
@@ -726,7 +726,7 @@ static int icplus_probe ( struct pci_device *pci ) {
adjust_pci_device ( pci );
/* Map registers */
- icp->regs = ioremap ( pci->membase, ICP_BAR_SIZE );
+ icp->regs = pci_ioremap ( pci, pci->membase, ICP_BAR_SIZE );
if ( ! icp->regs ) {
rc = -ENODEV;
goto err_ioremap;
diff --git a/src/drivers/net/igbvf/igbvf_main.c b/src/drivers/net/igbvf/igbvf_main.c
index fc7021c38..a5ed0c451 100644
--- a/src/drivers/net/igbvf/igbvf_main.c
+++ b/src/drivers/net/igbvf/igbvf_main.c
@@ -46,7 +46,7 @@ int igbvf_setup_tx_resources ( struct igbvf_adapter *adapter )
/* Allocate transmit descriptor ring memory.
It must not cross a 64K boundary because of hardware errata #23
- so we use malloc_dma() requesting a 128 byte block that is
+ so we use malloc_phys() requesting a 128 byte block that is
128 byte aligned. This should guarantee that the memory
allocated will not cross a 64K boundary, because 128 is an
even multiple of 65536 ( 65536 / 128 == 512 ), so all possible
@@ -55,7 +55,7 @@ int igbvf_setup_tx_resources ( struct igbvf_adapter *adapter )
*/
adapter->tx_base =
- malloc_dma ( adapter->tx_ring_size, adapter->tx_ring_size );
+ malloc_phys ( adapter->tx_ring_size, adapter->tx_ring_size );
if ( ! adapter->tx_base ) {
return -ENOMEM;
@@ -78,7 +78,7 @@ void igbvf_free_tx_resources ( struct igbvf_adapter *adapter )
{
DBG ( "igbvf_free_tx_resources\n" );
- free_dma ( adapter->tx_base, adapter->tx_ring_size );
+ free_phys ( adapter->tx_base, adapter->tx_ring_size );
}
/**
@@ -93,7 +93,7 @@ void igbvf_free_rx_resources ( struct igbvf_adapter *adapter )
DBG ( "igbvf_free_rx_resources\n" );
- free_dma ( adapter->rx_base, adapter->rx_ring_size );
+ free_phys ( adapter->rx_base, adapter->rx_ring_size );
for ( i = 0; i < NUM_RX_DESC; i++ ) {
free_iob ( adapter->rx_iobuf[i] );
@@ -574,7 +574,7 @@ int igbvf_setup_rx_resources ( struct igbvf_adapter *adapter )
*/
adapter->rx_base =
- malloc_dma ( adapter->rx_ring_size, adapter->rx_ring_size );
+ malloc_phys ( adapter->rx_ring_size, adapter->rx_ring_size );
if ( ! adapter->rx_base ) {
return -ENOMEM;
@@ -843,7 +843,7 @@ int igbvf_probe ( struct pci_device *pdev )
DBG ( "mmio_start: %#08lx\n", mmio_start );
DBG ( "mmio_len: %#08lx\n", mmio_len );
- adapter->hw.hw_addr = ioremap ( mmio_start, mmio_len );
+ adapter->hw.hw_addr = pci_ioremap ( pdev, mmio_start, mmio_len );
DBG ( "adapter->hw.hw_addr: %p\n", adapter->hw.hw_addr );
if ( ! adapter->hw.hw_addr ) {
diff --git a/src/drivers/net/intel.c b/src/drivers/net/intel.c
index d9b8b46b7..83492961f 100644
--- a/src/drivers/net/intel.c
+++ b/src/drivers/net/intel.c
@@ -32,7 +32,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <ipxe/ethernet.h>
#include <ipxe/if_ether.h>
#include <ipxe/iobuf.h>
-#include <ipxe/malloc.h>
+#include <ipxe/dma.h>
#include <ipxe/pci.h>
#include <ipxe/profile.h>
#include "intel.h"
@@ -504,7 +504,8 @@ int intel_create_ring ( struct intel_nic *intel, struct intel_ring *ring ) {
* prevent any possible page-crossing errors due to hardware
* errata.
*/
- ring->desc = malloc_dma ( ring->len, ring->len );
+ ring->desc = dma_alloc ( intel->dma, &ring->map, ring->len,
+ ring->len );
if ( ! ring->desc )
return -ENOMEM;
@@ -512,7 +513,7 @@ int intel_create_ring ( struct intel_nic *intel, struct intel_ring *ring ) {
memset ( ring->desc, 0, ring->len );
/* Program ring address */
- address = virt_to_bus ( ring->desc );
+ address = dma ( &ring->map, ring->desc );
writel ( ( address & 0xffffffffUL ),
( intel->regs + ring->reg + INTEL_xDBAL ) );
if ( sizeof ( physaddr_t ) > sizeof ( uint32_t ) ) {
@@ -534,9 +535,9 @@ int intel_create_ring ( struct intel_nic *intel, struct intel_ring *ring ) {
dctl |= INTEL_xDCTL_ENABLE;
writel ( dctl, intel->regs + ring->reg + INTEL_xDCTL );
- DBGC ( intel, "INTEL %p ring %05x is at [%08llx,%08llx)\n",
- intel, ring->reg, ( ( unsigned long long ) address ),
- ( ( unsigned long long ) address + ring->len ) );
+ DBGC ( intel, "INTEL %p ring %05x is at [%08lx,%08lx)\n",
+ intel, ring->reg, virt_to_phys ( ring->desc ),
+ ( virt_to_phys ( ring->desc ) + ring->len ) );
return 0;
}
@@ -553,7 +554,7 @@ void intel_destroy_ring ( struct intel_nic *intel, struct intel_ring *ring ) {
intel_reset_ring ( intel, ring->reg );
/* Free descriptor ring */
- free_dma ( ring->desc, ring->len );
+ dma_free ( &ring->map, ring->desc, ring->len );
ring->desc = NULL;
ring->prod = 0;
ring->cons = 0;
@@ -569,14 +570,13 @@ void intel_refill_rx ( struct intel_nic *intel ) {
struct io_buffer *iobuf;
unsigned int rx_idx;
unsigned int rx_tail;
- physaddr_t address;
unsigned int refilled = 0;
/* Refill ring */
while ( ( intel->rx.prod - intel->rx.cons ) < INTEL_RX_FILL ) {
/* Allocate I/O buffer */
- iobuf = alloc_iob ( INTEL_RX_MAX_LEN );
+ iobuf = alloc_rx_iob ( INTEL_RX_MAX_LEN, intel->dma );
if ( ! iobuf ) {
/* Wait for next refill */
break;
@@ -587,16 +587,15 @@ void intel_refill_rx ( struct intel_nic *intel ) {
rx = &intel->rx.desc[rx_idx];
/* Populate receive descriptor */
- address = virt_to_bus ( iobuf->data );
- intel->rx.describe ( rx, address, 0 );
+ intel->rx.describe ( rx, iob_dma ( iobuf ), 0 );
/* Record I/O buffer */
assert ( intel->rx_iobuf[rx_idx] == NULL );
intel->rx_iobuf[rx_idx] = iobuf;
- DBGC2 ( intel, "INTEL %p RX %d is [%llx,%llx)\n", intel, rx_idx,
- ( ( unsigned long long ) address ),
- ( ( unsigned long long ) address + INTEL_RX_MAX_LEN ) );
+ DBGC2 ( intel, "INTEL %p RX %d is [%lx,%lx)\n",
+ intel, rx_idx, virt_to_phys ( iobuf->data ),
+ ( virt_to_phys ( iobuf->data ) + INTEL_RX_MAX_LEN ) );
refilled++;
}
@@ -619,9 +618,10 @@ void intel_refill_rx ( struct intel_nic *intel ) {
void intel_empty_rx ( struct intel_nic *intel ) {
unsigned int i;
+ /* Discard unused receive buffers */
for ( i = 0 ; i < INTEL_NUM_RX_DESC ; i++ ) {
if ( intel->rx_iobuf[i] )
- free_iob ( intel->rx_iobuf[i] );
+ free_rx_iob ( intel->rx_iobuf[i] );
intel->rx_iobuf[i] = NULL;
}
}
@@ -742,7 +742,6 @@ int intel_transmit ( struct net_device *netdev, struct io_buffer *iobuf ) {
struct intel_descriptor *tx;
unsigned int tx_idx;
unsigned int tx_tail;
- physaddr_t address;
size_t len;
/* Get next transmit descriptor */
@@ -755,9 +754,8 @@ int intel_transmit ( struct net_device *netdev, struct io_buffer *iobuf ) {
tx = &intel->tx.desc[tx_idx];
/* Populate transmit descriptor */
- address = virt_to_bus ( iobuf->data );
len = iob_len ( iobuf );
- intel->tx.describe ( tx, address, len );
+ intel->tx.describe ( tx, iob_dma ( iobuf ), len );
wmb();
/* Notify card that there are packets ready to transmit */
@@ -766,9 +764,9 @@ int intel_transmit ( struct net_device *netdev, struct io_buffer *iobuf ) {
profile_stop ( &intel_vm_tx_profiler );
profile_exclude ( &intel_vm_tx_profiler );
- DBGC2 ( intel, "INTEL %p TX %d is [%llx,%llx)\n", intel, tx_idx,
- ( ( unsigned long long ) address ),
- ( ( unsigned long long ) address + len ) );
+ DBGC2 ( intel, "INTEL %p TX %d is [%lx,%lx)\n",
+ intel, tx_idx, virt_to_phys ( iobuf->data ),
+ ( virt_to_phys ( iobuf->data ) + len ) );
return 0;
}
@@ -959,12 +957,17 @@ static int intel_probe ( struct pci_device *pci ) {
adjust_pci_device ( pci );
/* Map registers */
- intel->regs = ioremap ( pci->membase, INTEL_BAR_SIZE );
+ intel->regs = pci_ioremap ( pci, pci->membase, INTEL_BAR_SIZE );
if ( ! intel->regs ) {
rc = -ENODEV;
goto err_ioremap;
}
+ /* Configure DMA */
+ intel->dma = &pci->dma;
+ dma_set_mask_64bit ( intel->dma );
+ netdev->dma = intel->dma;
+
/* Reset the NIC */
if ( ( rc = intel_reset ( intel ) ) != 0 )
goto err_reset;
diff --git a/src/drivers/net/intel.h b/src/drivers/net/intel.h
index 9d740efc3..4f51a80f6 100644
--- a/src/drivers/net/intel.h
+++ b/src/drivers/net/intel.h
@@ -12,6 +12,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <stdint.h>
#include <ipxe/if_ether.h>
#include <ipxe/nvs.h>
+#include <ipxe/dma.h>
/** Intel BAR size */
#define INTEL_BAR_SIZE ( 128 * 1024 )
@@ -212,6 +213,8 @@ union intel_receive_address {
struct intel_ring {
/** Descriptors */
struct intel_descriptor *desc;
+ /** Descriptor ring DMA mapping */
+ struct dma_mapping map;
/** Producer index */
unsigned int prod;
/** Consumer index */
@@ -277,6 +280,8 @@ intel_init_mbox ( struct intel_mailbox *mbox, unsigned int ctrl,
struct intel_nic {
/** Registers */
void *regs;
+ /** DMA device */
+ struct dma_device *dma;
/** Port number (for multi-port devices) */
unsigned int port;
/** Flags */
diff --git a/src/drivers/net/intelx.c b/src/drivers/net/intelx.c
index 91fb7955f..ccf6b0648 100644
--- a/src/drivers/net/intelx.c
+++ b/src/drivers/net/intelx.c
@@ -32,7 +32,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <ipxe/ethernet.h>
#include <ipxe/if_ether.h>
#include <ipxe/iobuf.h>
-#include <ipxe/malloc.h>
#include <ipxe/pci.h>
#include "intelx.h"
@@ -405,12 +404,17 @@ static int intelx_probe ( struct pci_device *pci ) {
adjust_pci_device ( pci );
/* Map registers */
- intel->regs = ioremap ( pci->membase, INTEL_BAR_SIZE );
+ intel->regs = pci_ioremap ( pci, pci->membase, INTEL_BAR_SIZE );
if ( ! intel->regs ) {
rc = -ENODEV;
goto err_ioremap;
}
+ /* Configure DMA */
+ intel->dma = &pci->dma;
+ dma_set_mask_64bit ( intel->dma );
+ netdev->dma = intel->dma;
+
/* Reset the NIC */
if ( ( rc = intelx_reset ( intel ) ) != 0 )
goto err_reset;
diff --git a/src/drivers/net/intelxl.c b/src/drivers/net/intelxl.c
index c98ba265c..ac9e37c5a 100644
--- a/src/drivers/net/intelxl.c
+++ b/src/drivers/net/intelxl.c
@@ -34,7 +34,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <ipxe/if_ether.h>
#include <ipxe/vlan.h>
#include <ipxe/iobuf.h>
-#include <ipxe/malloc.h>
#include <ipxe/pci.h>
#include <ipxe/version.h>
#include "intelxl.h"
@@ -87,15 +86,16 @@ static int intelxl_reset ( struct intelxl_nic *intelxl ) {
static int intelxl_fetch_mac ( struct intelxl_nic *intelxl,
struct net_device *netdev ) {
union intelxl_receive_address mac;
- uint32_t prtgl_sal;
+ uint32_t prtpm_sal;
+ uint32_t prtpm_sah;
uint32_t prtgl_sah;
size_t mfs;
/* Read NVM-loaded address */
- prtgl_sal = readl ( intelxl->regs + INTELXL_PRTGL_SAL );
- prtgl_sah = readl ( intelxl->regs + INTELXL_PRTGL_SAH );
- mac.reg.low = cpu_to_le32 ( prtgl_sal );
- mac.reg.high = cpu_to_le32 ( prtgl_sah );
+ prtpm_sal = readl ( intelxl->regs + INTELXL_PRTPM_SAL );
+ prtpm_sah = readl ( intelxl->regs + INTELXL_PRTPM_SAH );
+ mac.reg.low = cpu_to_le32 ( prtpm_sal );
+ mac.reg.high = cpu_to_le32 ( prtpm_sah );
/* Check that address is valid */
if ( ! is_valid_ether_addr ( mac.raw ) ) {
@@ -110,6 +110,7 @@ static int intelxl_fetch_mac ( struct intelxl_nic *intelxl,
memcpy ( netdev->hw_addr, mac.raw, ETH_ALEN );
/* Get maximum frame size */
+ prtgl_sah = readl ( intelxl->regs + INTELXL_PRTGL_SAH );
mfs = INTELXL_PRTGL_SAH_MFS_GET ( prtgl_sah );
netdev->max_pkt_len = ( mfs - 4 /* CRC */ );
@@ -134,20 +135,36 @@ int intelxl_msix_enable ( struct intelxl_nic *intelxl,
struct pci_device *pci ) {
int rc;
+ /* Map dummy target location */
+ if ( ( rc = dma_map ( intelxl->dma, &intelxl->msix.map,
+ virt_to_phys ( &intelxl->msix.msg ),
+ sizeof ( intelxl->msix.msg ), DMA_RX ) ) != 0 ) {
+ DBGC ( intelxl, "INTELXL %p could not map MSI-X target: %s\n",
+ intelxl, strerror ( rc ) );
+ goto err_map;
+ }
+
/* Enable MSI-X capability */
- if ( ( rc = pci_msix_enable ( pci, &intelxl->msix ) ) != 0 ) {
+ if ( ( rc = pci_msix_enable ( pci, &intelxl->msix.cap ) ) != 0 ) {
DBGC ( intelxl, "INTELXL %p could not enable MSI-X: %s\n",
intelxl, strerror ( rc ) );
- return rc;
+ goto err_enable;
}
/* Configure interrupt zero to write to dummy location */
- pci_msix_map ( &intelxl->msix, 0, virt_to_bus ( &intelxl->msg ), 0 );
+ pci_msix_map ( &intelxl->msix.cap, 0,
+ dma ( &intelxl->msix.map, &intelxl->msix.msg ), 0 );
/* Enable dummy interrupt zero */
- pci_msix_unmask ( &intelxl->msix, 0 );
+ pci_msix_unmask ( &intelxl->msix.cap, 0 );
return 0;
+
+ pci_msix_disable ( pci, &intelxl->msix.cap );
+ err_enable:
+ dma_unmap ( &intelxl->msix.map );
+ err_map:
+ return rc;
}
/**
@@ -160,10 +177,13 @@ void intelxl_msix_disable ( struct intelxl_nic *intelxl,
struct pci_device *pci ) {
/* Disable dummy interrupt zero */
- pci_msix_mask ( &intelxl->msix, 0 );
+ pci_msix_mask ( &intelxl->msix.cap, 0 );
/* Disable MSI-X capability */
- pci_msix_disable ( pci, &intelxl->msix );
+ pci_msix_disable ( pci, &intelxl->msix.cap );
+
+ /* Unmap dummy target location */
+ dma_unmap ( &intelxl->msix.map );
}
/******************************************************************************
@@ -195,19 +215,19 @@ static int intelxl_alloc_admin ( struct intelxl_nic *intelxl,
size_t len = ( sizeof ( admin->desc[0] ) * INTELXL_ADMIN_NUM_DESC );
/* Allocate admin queue */
- admin->buf = malloc_dma ( ( buf_len + len ), INTELXL_ALIGN );
+ admin->buf = dma_alloc ( intelxl->dma, &admin->map, ( buf_len + len ),
+ INTELXL_ALIGN );
if ( ! admin->buf )
return -ENOMEM;
admin->desc = ( ( ( void * ) admin->buf ) + buf_len );
- DBGC ( intelxl, "INTELXL %p A%cQ is at [%08llx,%08llx) buf "
- "[%08llx,%08llx)\n", intelxl,
+ DBGC ( intelxl, "INTELXL %p A%cQ is at [%08lx,%08lx) buf "
+ "[%08lx,%08lx)\n", intelxl,
( ( admin == &intelxl->command ) ? 'T' : 'R' ),
- ( ( unsigned long long ) virt_to_bus ( admin->desc ) ),
- ( ( unsigned long long ) ( virt_to_bus ( admin->desc ) + len ) ),
- ( ( unsigned long long ) virt_to_bus ( admin->buf ) ),
- ( ( unsigned long long ) ( virt_to_bus ( admin->buf ) +
- buf_len ) ) );
+ virt_to_phys ( admin->desc ),
+ ( virt_to_phys ( admin->desc ) + len ),
+ virt_to_phys ( admin->buf ),
+ ( virt_to_phys ( admin->buf ) + buf_len ) );
return 0;
}
@@ -235,7 +255,7 @@ static void intelxl_enable_admin ( struct intelxl_nic *intelxl,
admin->index = 0;
/* Program queue address */
- address = virt_to_bus ( admin->desc );
+ address = dma ( &admin->map, admin->desc );
writel ( ( address & 0xffffffffUL ), admin_regs + regs->bal );
if ( sizeof ( physaddr_t ) > sizeof ( uint32_t ) ) {
writel ( ( ( ( uint64_t ) address ) >> 32 ),
@@ -277,7 +297,7 @@ static void intelxl_free_admin ( struct intelxl_nic *intelxl __unused,
size_t len = ( sizeof ( admin->desc[0] ) * INTELXL_ADMIN_NUM_DESC );
/* Free queue */
- free_dma ( admin->buf, ( buf_len + len ) );
+ dma_free ( &admin->map, admin->buf, ( buf_len + len ) );
}
/**
@@ -330,7 +350,7 @@ static void intelxl_admin_event_init ( struct intelxl_nic *intelxl,
/* Initialise descriptor */
evt = &admin->desc[ index % INTELXL_ADMIN_NUM_DESC ];
buf = &admin->buf[ index % INTELXL_ADMIN_NUM_DESC ];
- address = virt_to_bus ( buf );
+ address = dma ( &admin->map, buf );
evt->flags = cpu_to_le16 ( INTELXL_ADMIN_FL_BUF );
evt->len = cpu_to_le16 ( sizeof ( *buf ) );
evt->params.buffer.high = cpu_to_le32 ( address >> 32 );
@@ -375,7 +395,7 @@ int intelxl_admin_command ( struct intelxl_nic *intelxl ) {
/* Populate data buffer address if applicable */
if ( cmd->flags & cpu_to_le16 ( INTELXL_ADMIN_FL_BUF ) ) {
- address = virt_to_bus ( buf );
+ address = dma ( &admin->map, buf );
cmd->params.buffer.high = cpu_to_le32 ( address >> 32 );
cmd->params.buffer.low = cpu_to_le32 ( address & 0xffffffffUL );
}
@@ -922,16 +942,15 @@ void intelxl_close_admin ( struct intelxl_nic *intelxl ) {
*/
int intelxl_alloc_ring ( struct intelxl_nic *intelxl,
struct intelxl_ring *ring ) {
- physaddr_t address;
int rc;
/* Allocate descriptor ring */
- ring->desc.raw = malloc_dma ( ring->len, INTELXL_ALIGN );
+ ring->desc.raw = dma_alloc ( intelxl->dma, &ring->map, ring->len,
+ INTELXL_ALIGN );
if ( ! ring->desc.raw ) {
rc = -ENOMEM;
goto err_alloc;
}
- address = virt_to_bus ( ring->desc.raw );
/* Initialise descriptor ring */
memset ( ring->desc.raw, 0, ring->len );
@@ -943,14 +962,14 @@ int intelxl_alloc_ring ( struct intelxl_nic *intelxl,
ring->prod = 0;
ring->cons = 0;
- DBGC ( intelxl, "INTELXL %p ring %06x is at [%08llx,%08llx)\n",
+ DBGC ( intelxl, "INTELXL %p ring %06x is at [%08lx,%08lx)\n",
intelxl, ( ring->reg + ring->tail ),
- ( ( unsigned long long ) address ),
- ( ( unsigned long long ) address + ring->len ) );
+ virt_to_phys ( ring->desc.raw ),
+ ( virt_to_phys ( ring->desc.raw ) + ring->len ) );
return 0;
- free_dma ( ring->desc.raw, ring->len );
+ dma_free ( &ring->map, ring->desc.raw, ring->len );
err_alloc:
return rc;
}
@@ -965,7 +984,7 @@ void intelxl_free_ring ( struct intelxl_nic *intelxl __unused,
struct intelxl_ring *ring ) {
/* Free descriptor ring */
- free_dma ( ring->desc.raw, ring->len );
+ dma_free ( &ring->map, ring->desc.raw, ring->len );
ring->desc.raw = NULL;
}
@@ -1241,7 +1260,7 @@ static int intelxl_create_ring ( struct intelxl_nic *intelxl,
goto err_alloc;
/* Program queue context */
- address = virt_to_bus ( ring->desc.raw );
+ address = dma ( &ring->map, ring->desc.raw );
if ( ( rc = ring->context ( intelxl, address ) ) != 0 )
goto err_context;
@@ -1289,14 +1308,13 @@ static void intelxl_refill_rx ( struct intelxl_nic *intelxl ) {
struct io_buffer *iobuf;
unsigned int rx_idx;
unsigned int rx_tail;
- physaddr_t address;
unsigned int refilled = 0;
/* Refill ring */
while ( ( intelxl->rx.prod - intelxl->rx.cons ) < INTELXL_RX_FILL ) {
/* Allocate I/O buffer */
- iobuf = alloc_iob ( intelxl->mfs );
+ iobuf = alloc_rx_iob ( intelxl->mfs, intelxl->dma );
if ( ! iobuf ) {
/* Wait for next refill */
break;
@@ -1307,17 +1325,16 @@ static void intelxl_refill_rx ( struct intelxl_nic *intelxl ) {
rx = &intelxl->rx.desc.rx[rx_idx].data;
/* Populate receive descriptor */
- address = virt_to_bus ( iobuf->data );
- rx->address = cpu_to_le64 ( address );
+ rx->address = cpu_to_le64 ( iob_dma ( iobuf ) );
rx->flags = 0;
/* Record I/O buffer */
assert ( intelxl->rx_iobuf[rx_idx] == NULL );
intelxl->rx_iobuf[rx_idx] = iobuf;
- DBGC2 ( intelxl, "INTELXL %p RX %d is [%llx,%llx)\n", intelxl,
- rx_idx, ( ( unsigned long long ) address ),
- ( ( unsigned long long ) address + intelxl->mfs ) );
+ DBGC2 ( intelxl, "INTELXL %p RX %d is [%08lx,%08lx)\n",
+ intelxl, rx_idx, virt_to_phys ( iobuf->data ),
+ ( virt_to_phys ( iobuf->data ) + intelxl->mfs ) );
refilled++;
}
@@ -1340,7 +1357,7 @@ void intelxl_empty_rx ( struct intelxl_nic *intelxl ) {
/* Discard any unused receive buffers */
for ( i = 0 ; i < INTELXL_RX_NUM_DESC ; i++ ) {
if ( intelxl->rx_iobuf[i] )
- free_iob ( intelxl->rx_iobuf[i] );
+ free_rx_iob ( intelxl->rx_iobuf[i] );
intelxl->rx_iobuf[i] = NULL;
}
}
@@ -1467,7 +1484,6 @@ int intelxl_transmit ( struct net_device *netdev, struct io_buffer *iobuf ) {
struct intelxl_tx_data_descriptor *tx;
unsigned int tx_idx;
unsigned int tx_tail;
- physaddr_t address;
size_t len;
/* Get next transmit descriptor */
@@ -1481,9 +1497,8 @@ int intelxl_transmit ( struct net_device *netdev, struct io_buffer *iobuf ) {
tx = &intelxl->tx.desc.tx[tx_idx].data;
/* Populate transmit descriptor */
- address = virt_to_bus ( iobuf->data );
len = iob_len ( iobuf );
- tx->address = cpu_to_le64 ( address );
+ tx->address = cpu_to_le64 ( iob_dma ( iobuf ) );
tx->len = cpu_to_le32 ( INTELXL_TX_DATA_LEN ( len ) );
tx->flags = cpu_to_le32 ( INTELXL_TX_DATA_DTYP | INTELXL_TX_DATA_EOP |
INTELXL_TX_DATA_RS | INTELXL_TX_DATA_JFDI );
@@ -1492,9 +1507,9 @@ int intelxl_transmit ( struct net_device *netdev, struct io_buffer *iobuf ) {
/* Notify card that there are packets ready to transmit */
writel ( tx_tail, ( intelxl->regs + intelxl->tx.tail ) );
- DBGC2 ( intelxl, "INTELXL %p TX %d is [%llx,%llx)\n", intelxl, tx_idx,
- ( ( unsigned long long ) address ),
- ( ( unsigned long long ) address + len ) );
+ DBGC2 ( intelxl, "INTELXL %p TX %d is [%08lx,%08lx)\n",
+ intelxl, tx_idx, virt_to_phys ( iobuf->data ),
+ ( virt_to_phys ( iobuf->data ) + len ) );
return 0;
}
@@ -1641,6 +1656,7 @@ static struct net_device_operations intelxl_operations = {
static int intelxl_probe ( struct pci_device *pci ) {
struct net_device *netdev;
struct intelxl_nic *intelxl;
+ uint32_t pffunc_rid;
uint32_t pfgen_portnum;
uint32_t pflan_qalloc;
int rc;
@@ -1656,7 +1672,6 @@ static int intelxl_probe ( struct pci_device *pci ) {
pci_set_drvdata ( pci, netdev );
netdev->dev = &pci->dev;
memset ( intelxl, 0, sizeof ( *intelxl ) );
- intelxl->pf = PCI_FUNC ( pci->busdevfn );
intelxl->intr = INTELXL_PFINT_DYN_CTL0;
intelxl_init_admin ( &intelxl->command, INTELXL_ADMIN_CMD,
&intelxl_admin_offsets );
@@ -1673,17 +1688,24 @@ static int intelxl_probe ( struct pci_device *pci ) {
adjust_pci_device ( pci );
/* Map registers */
- intelxl->regs = ioremap ( pci->membase, INTELXL_BAR_SIZE );
+ intelxl->regs = pci_ioremap ( pci, pci->membase, INTELXL_BAR_SIZE );
if ( ! intelxl->regs ) {
rc = -ENODEV;
goto err_ioremap;
}
+ /* Configure DMA */
+ intelxl->dma = &pci->dma;
+ dma_set_mask_64bit ( intelxl->dma );
+ netdev->dma = intelxl->dma;
+
/* Reset the NIC */
if ( ( rc = intelxl_reset ( intelxl ) ) != 0 )
goto err_reset;
- /* Get port number and base queue number */
+ /* Get function number, port number and base queue number */
+ pffunc_rid = readl ( intelxl->regs + INTELXL_PFFUNC_RID );
+ intelxl->pf = INTELXL_PFFUNC_RID_FUNC_NUM ( pffunc_rid );
pfgen_portnum = readl ( intelxl->regs + INTELXL_PFGEN_PORTNUM );
intelxl->port = INTELXL_PFGEN_PORTNUM_PORT_NUM ( pfgen_portnum );
pflan_qalloc = readl ( intelxl->regs + INTELXL_PFLAN_QALLOC );
diff --git a/src/drivers/net/intelxl.h b/src/drivers/net/intelxl.h
index 80586cef0..a4a776d28 100644
--- a/src/drivers/net/intelxl.h
+++ b/src/drivers/net/intelxl.h
@@ -12,6 +12,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <stdint.h>
#include <ipxe/if_ether.h>
#include <ipxe/pcimsix.h>
+#include <ipxe/dma.h>
struct intelxl_nic;
@@ -562,6 +563,8 @@ struct intelxl_admin {
struct intelxl_admin_descriptor *desc;
/** Data buffers */
union intelxl_admin_buffer *buf;
+ /** DMA mapping */
+ struct dma_mapping map;
/** Queue index */
unsigned int index;
@@ -866,6 +869,8 @@ struct intelxl_ring {
/** Raw data */
void *raw;
} desc;
+ /** Descriptor ring DMA mapping */
+ struct dma_mapping map;
/** Producer index */
unsigned int prod;
/** Consumer index */
@@ -985,6 +990,11 @@ intelxl_init_ring ( struct intelxl_ring *ring, unsigned int count, size_t len,
/** Time to delay for device reset, in milliseconds */
#define INTELXL_RESET_DELAY_MS 100
+/** Function Requester ID Information Register */
+#define INTELXL_PFFUNC_RID 0x09c000
+#define INTELXL_PFFUNC_RID_FUNC_NUM(x) \
+ ( ( (x) >> 0 ) & 0x3 ) /**< Function number */
+
/** PF Queue Allocation Register */
#define INTELXL_PFLAN_QALLOC 0x1c0400
#define INTELXL_PFLAN_QALLOC_FIRSTQ(x) \
@@ -1005,6 +1015,12 @@ intelxl_init_ring ( struct intelxl_ring *ring, unsigned int count, size_t len,
#define INTELXL_PRTGL_SAH_MFS_GET(x) ( (x) >> 16 ) /**< Max frame size */
#define INTELXL_PRTGL_SAH_MFS_SET(x) ( (x) << 16 ) /**< Max frame size */
+/** Physical Function MAC Address Low Register */
+#define INTELXL_PRTPM_SAL 0x1e4440
+
+/** Physical Function MAC Address High Register */
+#define INTELXL_PRTPM_SAH 0x1e44c0
+
/** Receive address */
union intelxl_receive_address {
struct {
@@ -1014,10 +1030,22 @@ union intelxl_receive_address {
uint8_t raw[ETH_ALEN];
};
+/** MSI-X interrupt */
+struct intelxl_msix {
+ /** PCI capability */
+ struct pci_msix cap;
+ /** MSI-X dummy interrupt target */
+ uint32_t msg;
+ /** DMA mapping for dummy interrupt target */
+ struct dma_mapping map;
+};
+
/** An Intel 40Gigabit network card */
struct intelxl_nic {
/** Registers */
void *regs;
+ /** DMA device */
+ struct dma_device *dma;
/** Maximum frame size */
size_t mfs;
@@ -1035,12 +1063,10 @@ struct intelxl_nic {
unsigned int qset;
/** Interrupt control register */
unsigned int intr;
- /** MSI-X capability */
- struct pci_msix msix;
- /** MSI-X dummy interrupt target */
- uint32_t msg;
/** PCI Express capability offset */
unsigned int exp;
+ /** MSI-X interrupt */
+ struct intelxl_msix msix;
/** Admin command queue */
struct intelxl_admin command;
diff --git a/src/drivers/net/intelxlvf.c b/src/drivers/net/intelxlvf.c
index 8f76daf3d..752de7815 100644
--- a/src/drivers/net/intelxlvf.c
+++ b/src/drivers/net/intelxlvf.c
@@ -298,9 +298,9 @@ void intelxlvf_admin_event ( struct net_device *netdev,
if ( intelxl->vret != 0 ) {
DBGC ( intelxl, "INTELXL %p admin VF command %#x "
"error %d\n", intelxl, vopcode, intelxl->vret );
- DBGC_HDA ( intelxl, virt_to_bus ( evt ), evt,
+ DBGC_HDA ( intelxl, virt_to_phys ( evt ), evt,
sizeof ( *evt ) );
- DBGC_HDA ( intelxl, virt_to_bus ( buf ), buf,
+ DBGC_HDA ( intelxl, virt_to_phys ( buf ), buf,
le16_to_cpu ( evt->len ) );
}
return;
@@ -314,8 +314,10 @@ void intelxlvf_admin_event ( struct net_device *netdev,
default:
DBGC ( intelxl, "INTELXL %p unrecognised VF event %#x:\n",
intelxl, vopcode );
- DBGC_HDA ( intelxl, 0, evt, sizeof ( *evt ) );
- DBGC_HDA ( intelxl, 0, buf, le16_to_cpu ( evt->len ) );
+ DBGC_HDA ( intelxl, virt_to_phys ( evt ), evt,
+ sizeof ( *evt ) );
+ DBGC_HDA ( intelxl, virt_to_phys ( buf ), buf,
+ le16_to_cpu ( evt->len ) );
break;
}
}
@@ -378,12 +380,14 @@ static int intelxlvf_admin_configure ( struct net_device *netdev ) {
buf->cfg.count = cpu_to_le16 ( 1 );
buf->cfg.tx.vsi = cpu_to_le16 ( intelxl->vsi );
buf->cfg.tx.count = cpu_to_le16 ( INTELXL_TX_NUM_DESC );
- buf->cfg.tx.base = cpu_to_le64 ( virt_to_bus ( intelxl->tx.desc.raw ) );
+ buf->cfg.tx.base = cpu_to_le64 ( dma ( &intelxl->tx.map,
+ intelxl->tx.desc.raw ) );
buf->cfg.rx.vsi = cpu_to_le16 ( intelxl->vsi );
buf->cfg.rx.count = cpu_to_le32 ( INTELXL_RX_NUM_DESC );
buf->cfg.rx.len = cpu_to_le32 ( intelxl->mfs );
buf->cfg.rx.mfs = cpu_to_le32 ( intelxl->mfs );
- buf->cfg.rx.base = cpu_to_le64 ( virt_to_bus ( intelxl->rx.desc.raw ) );
+ buf->cfg.rx.base = cpu_to_le64 ( dma ( &intelxl->rx.map,
+ intelxl->rx.desc.raw ) );
/* Issue command */
if ( ( rc = intelxlvf_admin_command ( netdev ) ) != 0 )
@@ -612,12 +616,17 @@ static int intelxlvf_probe ( struct pci_device *pci ) {
adjust_pci_device ( pci );
/* Map registers */
- intelxl->regs = ioremap ( pci->membase, INTELXLVF_BAR_SIZE );
+ intelxl->regs = pci_ioremap ( pci, pci->membase, INTELXLVF_BAR_SIZE );
if ( ! intelxl->regs ) {
rc = -ENODEV;
goto err_ioremap;
}
+ /* Configure DMA */
+ intelxl->dma = &pci->dma;
+ dma_set_mask_64bit ( intelxl->dma );
+ netdev->dma = intelxl->dma;
+
/* Locate PCI Express capability */
intelxl->exp = pci_find_capability ( pci, PCI_CAP_ID_EXP );
if ( ! intelxl->exp ) {
diff --git a/src/drivers/net/intelxvf.c b/src/drivers/net/intelxvf.c
index 2caeec27e..f0ba091d5 100644
--- a/src/drivers/net/intelxvf.c
+++ b/src/drivers/net/intelxvf.c
@@ -456,12 +456,17 @@ static int intelxvf_probe ( struct pci_device *pci ) {
adjust_pci_device ( pci );
/* Map registers */
- intel->regs = ioremap ( pci->membase, INTELVF_BAR_SIZE );
+ intel->regs = pci_ioremap ( pci, pci->membase, INTELVF_BAR_SIZE );
if ( ! intel->regs ) {
rc = -ENODEV;
goto err_ioremap;
}
+ /* Configure DMA */
+ intel->dma = &pci->dma;
+ dma_set_mask_64bit ( intel->dma );
+ netdev->dma = intel->dma;
+
/* Reset the function */
intelxvf_reset ( intel );
diff --git a/src/drivers/net/iphone.c b/src/drivers/net/iphone.c
new file mode 100644
index 000000000..7d0eb4b64
--- /dev/null
+++ b/src/drivers/net/iphone.c
@@ -0,0 +1,2268 @@
+/*
+ * Copyright (C) 2020 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 <stdio.h>
+#include <errno.h>
+#include <ipxe/netdevice.h>
+#include <ipxe/ethernet.h>
+#include <ipxe/if_ether.h>
+#include <ipxe/profile.h>
+#include <ipxe/base64.h>
+#include <ipxe/sha256.h>
+#include <ipxe/rsa.h>
+#include <ipxe/x509.h>
+#include <ipxe/pem.h>
+#include <ipxe/xfer.h>
+#include <ipxe/tls.h>
+#include <ipxe/usb.h>
+#include "iphone.h"
+
+/** @file
+ *
+ * iPhone USB Ethernet driver
+ *
+ */
+
+/* Disambiguate the various error causes */
+#define EPIPE_NO_MUX __einfo_error ( EINFO_EPIPE_NO_MUX )
+#define EINFO_EPIPE_NO_MUX \
+ __einfo_uniqify ( EINFO_EPIPE, 0x01, \
+ "No USB multiplexer" )
+#define EINPROGRESS_PAIRING __einfo_error ( EINFO_EINPROGRESS_PAIRING )
+#define EINFO_EINPROGRESS_PAIRING \
+ __einfo_uniqify ( EINFO_EINPROGRESS, 0x01, \
+ "Pairing in progress" )
+#define ENOTCONN_DISABLED __einfo_error ( EINFO_ENOTCONN_DISABLED )
+#define EINFO_ENOTCONN_DISABLED \
+ __einfo_uniqify ( EINFO_ENOTCONN, IPHONE_LINK_DISABLED, \
+ "Personal Hotspot disabled" )
+#define ENOTCONN_STATUS( status ) \
+ EUNIQ ( EINFO_ENOTCONN, ( (status) & 0x1f ), \
+ ENOTCONN_DISABLED )
+
+static int ipair_create ( struct interface *xfer, unsigned int flags );
+
+/** Bulk IN completion profiler */
+static struct profiler iphone_in_profiler __profiler =
+ { .name = "iphone.in" };
+
+/** Bulk OUT profiler */
+static struct profiler iphone_out_profiler __profiler =
+ { .name = "iphone.out" };
+
+/** List of USB multiplexers */
+static LIST_HEAD ( imuxes );
+
+/** List of iPhone network devices */
+static LIST_HEAD ( iphones );
+
+/******************************************************************************
+ *
+ * iPhone pairing certificates
+ *
+ ******************************************************************************
+ */
+
+/** iPhone root certificate fingerprint */
+static uint8_t icert_root_fingerprint[SHA256_DIGEST_SIZE];
+
+/** Root of trust for iPhone certificates */
+static struct x509_root icert_root = {
+ .refcnt = REF_INIT ( ref_no_free ),
+ .digest = &sha256_algorithm,
+ .count = 1,
+ .fingerprints = icert_root_fingerprint,
+};
+
+/** Single zero byte used in constructed certificates */
+static const uint8_t icert_nul[] = { 0x00 };
+
+/** "RSA algorithm" identifier used in constructed certificates */
+static const uint8_t icert_rsa[] = {
+ /* algorithm */
+ ASN1_SHORT ( ASN1_SEQUENCE,
+ ASN1_SHORT ( ASN1_OID, ASN1_OID_RSAENCRYPTION ),
+ ASN1_NULL, 0x00 )
+};
+
+/** "SHA-256 with RSA algorithm" identifier used in constructed certificates */
+static const uint8_t icert_sha256_rsa[] = {
+ ASN1_SHORT ( ASN1_SEQUENCE,
+ ASN1_SHORT ( ASN1_OID, ASN1_OID_SHA256WITHRSAENCRYPTION ),
+ ASN1_NULL, 0x00 ),
+};
+
+/** Extensions used in constructed root certificate */
+static const uint8_t icert_root_exts_data[] = {
+ /* extensions */
+ ASN1_SHORT ( ASN1_EXPLICIT_TAG ( 3 ), ASN1_SHORT ( ASN1_SEQUENCE,
+ /* basicConstraints */
+ ASN1_SHORT ( ASN1_SEQUENCE,
+ /* extnID */
+ ASN1_SHORT ( ASN1_OID, ASN1_OID_BASICCONSTRAINTS ),
+ /* critical */
+ ASN1_SHORT ( ASN1_BOOLEAN, 0xff ),
+ /* extnValue */
+ ASN1_SHORT ( ASN1_OCTET_STRING,
+ ASN1_SHORT ( ASN1_SEQUENCE,
+ ASN1_SHORT ( ASN1_BOOLEAN,
+ 0xff ) ) ) ) ) )
+};
+
+/** Extensions used in constructed root certificate */
+static struct asn1_cursor icert_root_exts =
+ ASN1_CURSOR ( icert_root_exts_data );
+
+/** Extensions used in constructed leaf certificates */
+static const uint8_t icert_leaf_exts_data[] = {
+ /* extensions */
+ ASN1_SHORT ( ASN1_EXPLICIT_TAG ( 3 ), ASN1_SHORT ( ASN1_SEQUENCE,
+ /* basicConstraints */
+ ASN1_SHORT ( ASN1_SEQUENCE,
+ /* extnID */
+ ASN1_SHORT ( ASN1_OID, ASN1_OID_BASICCONSTRAINTS ),
+ /* critical */
+ ASN1_SHORT ( ASN1_BOOLEAN, 0xff ),
+ /* extnValue */
+ ASN1_SHORT ( ASN1_OCTET_STRING,
+ ASN1_SHORT ( ASN1_SEQUENCE,
+ ASN1_SHORT ( ASN1_BOOLEAN,
+ 0x00 ) ) ) ),
+ /* keyUsage */
+ ASN1_SHORT ( ASN1_SEQUENCE,
+ /* extnID */
+ ASN1_SHORT ( ASN1_OID, ASN1_OID_KEYUSAGE ),
+ /* critical */
+ ASN1_SHORT ( ASN1_BOOLEAN, 0xff ),
+ /* extnValue */
+ ASN1_SHORT ( ASN1_OCTET_STRING,
+ ASN1_SHORT ( ASN1_BIT_STRING, 0x07,
+ ( X509_DIGITAL_SIGNATURE |
+ X509_KEY_ENCIPHERMENT ),
+ 0x00 ) ) ) ) )
+};
+
+/** Extensions used in constructed leaf certificates */
+static struct asn1_cursor icert_leaf_exts =
+ ASN1_CURSOR ( icert_leaf_exts_data );
+
+/** "TBSCertificate" prefix in constructed certificates */
+static const uint8_t icert_tbs_prefix[] = {
+ /* version */
+ ASN1_SHORT ( ASN1_EXPLICIT_TAG ( 0 ), ASN1_SHORT ( ASN1_INTEGER, 2 ) ),
+ /* serialNumber */
+ ASN1_SHORT ( ASN1_INTEGER, 0 ),
+ /* signature */
+ ASN1_SHORT ( ASN1_SEQUENCE,
+ ASN1_SHORT ( ASN1_OID, ASN1_OID_SHA256WITHRSAENCRYPTION ),
+ ASN1_NULL, 0x00 )
+};
+
+/** Validity period in constructed certificates */
+static const uint8_t icert_validity[] = {
+ /* validity */
+ ASN1_SHORT ( ASN1_SEQUENCE,
+ /* notBefore */
+ ASN1_SHORT ( ASN1_GENERALIZED_TIME,
+ '1', '9', '7', '8', '1', '2', '1', '0',
+ '2', '2', '0', '0', '0', '0', 'Z' ),
+ /* notAfter */
+ ASN1_SHORT ( ASN1_GENERALIZED_TIME,
+ '2', '9', '9', '9', '0', '1', '0', '1',
+ '0', '0', '0', '0', '0', '0', 'Z' ) )
+};
+
+/** "Root" subject name */
+static const uint8_t icert_name_root_data[] = {
+ ASN1_SHORT ( ASN1_SEQUENCE, ASN1_SHORT ( ASN1_SET,
+ ASN1_SHORT ( ASN1_SEQUENCE,
+ ASN1_SHORT ( ASN1_OID, ASN1_OID_COMMON_NAME ),
+ ASN1_SHORT ( ASN1_UTF8_STRING, 'R', 'o', 'o', 't' ) ) ) )
+};
+
+/** "Root" subject name */
+static struct asn1_cursor icert_name_root =
+ ASN1_CURSOR ( icert_name_root_data );
+
+/** "iPXE" subject name */
+static const uint8_t icert_name_ipxe_data[] = {
+ ASN1_SHORT ( ASN1_SEQUENCE, ASN1_SHORT ( ASN1_SET,
+ ASN1_SHORT ( ASN1_SEQUENCE,
+ ASN1_SHORT ( ASN1_OID, ASN1_OID_COMMON_NAME ),
+ ASN1_SHORT ( ASN1_UTF8_STRING, 'i', 'P', 'X', 'E' ) ) ) )
+};
+
+/** "iPXE" subject name */
+static struct asn1_cursor icert_name_ipxe =
+ ASN1_CURSOR ( icert_name_ipxe_data );
+
+/** "iPhone" subject name */
+static const uint8_t icert_name_iphone_data[] = {
+ ASN1_SHORT ( ASN1_SEQUENCE, ASN1_SHORT ( ASN1_SET,
+ ASN1_SHORT ( ASN1_SEQUENCE,
+ ASN1_SHORT ( ASN1_OID, ASN1_OID_COMMON_NAME ),
+ ASN1_SHORT ( ASN1_UTF8_STRING,
+ 'i', 'P', 'h', 'o', 'n', 'e' ) ) ) )
+};
+
+/** "iPhone" subject name */
+static struct asn1_cursor icert_name_iphone =
+ ASN1_CURSOR ( icert_name_iphone_data );
+
+/** Public key(s) used for pairing */
+static const uint8_t icert_public_a[] __unused = {
+ 0x02, 0x81, 0x81, 0x00, 0xc9, 0xc0, 0xdd, 0xa6, 0xd5, 0xf9, 0x05, 0x3e,
+ 0x1d, 0xcb, 0x67, 0x08, 0xa8, 0x50, 0x27, 0x63, 0x95, 0x87, 0x42, 0x7e,
+ 0xfb, 0xff, 0x55, 0x55, 0xb8, 0xc0, 0x6f, 0x13, 0xcb, 0xf7, 0xc5, 0x1b,
+ 0xda, 0x44, 0x3c, 0xbc, 0x1a, 0xe1, 0x15, 0x1e, 0xab, 0x56, 0x74, 0x02,
+ 0x8b, 0xb3, 0xcd, 0x42, 0x56, 0xcd, 0x9c, 0xc3, 0x15, 0xe2, 0x33, 0x97,
+ 0x6d, 0x77, 0xdd, 0x20, 0x3a, 0x74, 0xb1, 0x4c, 0xee, 0xeb, 0xe8, 0xaa,
+ 0x20, 0x71, 0x5a, 0xa2, 0x5b, 0xf8, 0x1a, 0xcb, 0xd2, 0x7b, 0x96, 0xb6,
+ 0x42, 0xb4, 0x7c, 0x7a, 0x13, 0xec, 0x55, 0xd3, 0x36, 0x8b, 0xe3, 0x17,
+ 0xc5, 0xc4, 0xcc, 0xe0, 0x27, 0x8c, 0xed, 0xa1, 0x4c, 0x8a, 0x50, 0x4a,
+ 0x1c, 0xc4, 0x58, 0xf6, 0xcd, 0xcc, 0xc3, 0x5f, 0xe6, 0x3c, 0xff, 0x97,
+ 0x51, 0xed, 0xf5, 0xaa, 0x89, 0xcc, 0x3f, 0x63, 0x67, 0x46, 0x9f, 0xbf,
+ 0x02, 0x03, 0x01, 0x00, 0x01
+};
+static const uint8_t icert_public_b[] __unused = {
+ 0x02, 0x81, 0x81, 0x00, 0xcd, 0x96, 0x81, 0x78, 0xbb, 0x2e, 0x64, 0xda,
+ 0xd3, 0x7e, 0xd7, 0x3a, 0xac, 0x3f, 0x00, 0xe5, 0x41, 0x65, 0x56, 0xac,
+ 0x2d, 0x77, 0xc0, 0x1a, 0xad, 0x32, 0xca, 0x0c, 0x72, 0xae, 0xdb, 0x57,
+ 0xc1, 0xc7, 0x79, 0xef, 0xc6, 0x71, 0x9f, 0xad, 0x82, 0x14, 0x94, 0x4b,
+ 0xf9, 0xd8, 0x78, 0xf1, 0xca, 0x99, 0xf5, 0x71, 0x07, 0x88, 0xd7, 0x55,
+ 0xc7, 0xcb, 0x36, 0x5d, 0xdb, 0x84, 0x46, 0xac, 0x05, 0xea, 0xf1, 0xe1,
+ 0xbe, 0x91, 0x50, 0x85, 0x1e, 0x64, 0xab, 0x02, 0x82, 0xab, 0xba, 0x42,
+ 0x06, 0x5a, 0xe3, 0xc3, 0x25, 0xd0, 0x95, 0x04, 0x54, 0xb4, 0x44, 0x40,
+ 0x5a, 0x42, 0x06, 0x04, 0x7d, 0x3b, 0x9e, 0xaf, 0x2e, 0xe9, 0xc8, 0xad,
+ 0x46, 0x3a, 0xff, 0xe2, 0x39, 0xc8, 0x48, 0x0a, 0x49, 0xaa, 0xfe, 0x1f,
+ 0x6c, 0x91, 0x5d, 0x1d, 0xd6, 0xb0, 0x04, 0xd1, 0x6c, 0xb2, 0x43, 0xaf,
+ 0x02, 0x03, 0x01, 0x00, 0x01
+};
+
+/**
+ * "Private" key(s) used for pairing
+ *
+ * Yes, this publicly visible "private" key completely obviates any
+ * nominal security provided by the pairing process. Looked at
+ * another way, this modifies the iPhone to behave like every other
+ * USB tethering device: if the cable is physically connected and
+ * tethering is enabled then the device will Just Work.
+ *
+ * Unlike Android, the iPhone seems to have no meaningful permissions
+ * model: any device that is trusted to use the phone for tethering
+ * seems to also be trusted to use the iPhone for any other purpose
+ * (e.g. accessing files, reading messages, etc). Apple should
+ * probably fix this at some point, e.g. via defining extended key
+ * usages in the root and host certificates.
+ */
+static const uint8_t icert_private_a[] __unused = {
+ 0x02, 0x81, 0x80, 0x1d, 0x60, 0xb7, 0x25, 0xdf, 0x0c, 0x76, 0xc5, 0xf7,
+ 0xc2, 0xb1, 0x8b, 0x22, 0x2f, 0x21, 0xbd, 0x2f, 0x7d, 0xd5, 0xa1, 0xf6,
+ 0x01, 0xd5, 0x24, 0x39, 0x55, 0xd4, 0x16, 0xd6, 0xe1, 0x8a, 0x53, 0x26,
+ 0xf2, 0x3e, 0xc1, 0xc9, 0x4c, 0x33, 0x2e, 0x17, 0x16, 0xec, 0xa7, 0x9e,
+ 0x3e, 0x1d, 0x4a, 0x66, 0xa7, 0x64, 0x07, 0x48, 0x3d, 0x7a, 0xf3, 0xb6,
+ 0xdd, 0xf8, 0x56, 0x04, 0x0d, 0x0f, 0xef, 0xf8, 0xbd, 0xbc, 0x73, 0xe2,
+ 0xc2, 0xae, 0x1b, 0x87, 0x90, 0x18, 0x2a, 0x68, 0xff, 0xae, 0x49, 0xdf,
+ 0x7c, 0xff, 0xe8, 0x44, 0xa8, 0x3e, 0x4e, 0x4f, 0xf5, 0xfa, 0x51, 0x96,
+ 0xb8, 0x08, 0xf3, 0x18, 0xd6, 0x52, 0xdf, 0x3a, 0x8a, 0xed, 0xda, 0xcd,
+ 0xb4, 0x06, 0x99, 0x41, 0xcb, 0x23, 0x17, 0xaf, 0xc3, 0x3e, 0xfe, 0xdf,
+ 0x97, 0xf3, 0xd6, 0x18, 0x7e, 0x03, 0xaf, 0x62, 0xb2, 0xc8, 0xc9
+};
+static const uint8_t icert_private_b[] __unused = {
+ 0x02, 0x81, 0x80, 0x45, 0xbd, 0xc0, 0xbe, 0x0c, 0x01, 0x79, 0x05, 0x22,
+ 0xa9, 0xec, 0xa9, 0x62, 0xb5, 0x1c, 0xc0, 0xa8, 0xa6, 0x8f, 0xf8, 0x68,
+ 0x94, 0x2e, 0xfe, 0xdd, 0xb2, 0x55, 0x08, 0x53, 0xff, 0x2d, 0x39, 0x5f,
+ 0xeb, 0x23, 0x5a, 0x4b, 0x9f, 0x4f, 0xe3, 0xb4, 0x34, 0xf6, 0xf9, 0xaf,
+ 0x0f, 0xd8, 0x37, 0x6d, 0xdb, 0x3c, 0x7f, 0xd3, 0x66, 0x80, 0x66, 0x01,
+ 0x18, 0xd6, 0xa0, 0x90, 0x4f, 0x17, 0x09, 0xb8, 0x68, 0x44, 0xf0, 0xde,
+ 0x16, 0x4a, 0x8a, 0x0d, 0xa7, 0x5f, 0xb5, 0x4c, 0x53, 0xcc, 0x21, 0xdd,
+ 0x4f, 0x05, 0x64, 0xa5, 0xc5, 0xac, 0x2c, 0xd8, 0x0a, 0x7b, 0xf5, 0xa4,
+ 0x63, 0x32, 0xb0, 0x2c, 0xf8, 0xef, 0x8c, 0xf8, 0x2c, 0xba, 0x1c, 0x2c,
+ 0xc7, 0x0a, 0xf3, 0xe9, 0x8f, 0xfb, 0x0a, 0x61, 0x1b, 0x3a, 0xdd, 0x9f,
+ 0x74, 0x7d, 0xb3, 0x42, 0x59, 0x52, 0x07, 0x59, 0x8e, 0xb7, 0x41
+};
+
+/** Key pair selection
+ *
+ * This exists only to allow for testing of the process for handling a
+ * failed TLS negotiation.
+ */
+#define icert_key_suffix a
+#define icert_key_variable( prefix ) _C2 ( prefix, icert_key_suffix )
+#define icert_public icert_key_variable ( icert_public_ )
+#define icert_private icert_key_variable ( icert_private_ )
+
+/** PEM certificate prefix */
+static const char icert_begin[] = "-----BEGIN CERTIFICATE-----\n";
+
+/** PEM certificate suffix */
+static const char icert_end[] = "\n-----END CERTIFICATE-----\n";
+
+/**
+ * Free pairing certificates
+ *
+ * @v icert Pairing certificates
+ */
+static void icert_free ( struct icert *icert ) {
+
+ privkey_put ( icert->key );
+ x509_put ( icert->root );
+ x509_put ( icert->host );
+ x509_put ( icert->device );
+ memset ( icert, 0, sizeof ( *icert ) );
+}
+
+/**
+ * Construct certificate
+ *
+ * @v icert Pairing certificates
+ * @v subject Subject name
+ * @v issuer Issuer name
+ * @v private Private key
+ * @v public Public key
+ * @v exts Certificate extensions
+ * @v cert Certificate to fill in
+ * @ret rc Return status code
+ *
+ * On success, the caller is responsible for eventually calling
+ * x509_put() on the allocated encoded certificate.
+ */
+static int icert_cert ( struct icert *icert, struct asn1_cursor *subject,
+ struct asn1_cursor *issuer, struct asn1_cursor *private,
+ struct asn1_cursor *public, struct asn1_cursor *exts,
+ struct x509_certificate **cert ) {
+ struct digest_algorithm *digest = &sha256_algorithm;
+ struct pubkey_algorithm *pubkey = &rsa_algorithm;
+ struct asn1_builder spki = { NULL, 0 };
+ struct asn1_builder tbs = { NULL, 0 };
+ struct asn1_builder raw = { NULL, 0 };
+ uint8_t digest_ctx[SHA256_CTX_SIZE];
+ uint8_t digest_out[SHA256_DIGEST_SIZE];
+ uint8_t pubkey_ctx[RSA_CTX_SIZE];
+ int len;
+ int rc;
+
+ /* Initialise "private" key */
+ if ( ( rc = pubkey_init ( pubkey, pubkey_ctx, private->data,
+ private->len ) ) != 0 ) {
+ DBGC ( icert, "ICERT %p could not initialise private key: "
+ "%s\n", icert, strerror ( rc ) );
+ goto err_pubkey_init;
+ }
+
+ /* Construct subjectPublicKeyInfo */
+ if ( ( rc = ( asn1_prepend_raw ( &spki, public->data, public->len ),
+ asn1_prepend_raw ( &spki, icert_nul,
+ sizeof ( icert_nul ) ),
+ asn1_wrap ( &spki, ASN1_BIT_STRING ),
+ asn1_prepend_raw ( &spki, icert_rsa,
+ sizeof ( icert_rsa ) ),
+ asn1_wrap ( &spki, ASN1_SEQUENCE ) ) ) != 0 ) {
+ DBGC ( icert, "ICERT %p could not build subjectPublicKeyInfo: "
+ "%s\n", icert, strerror ( rc ) );
+ goto err_spki;
+ }
+
+ /* Construct tbsCertificate */
+ if ( ( rc = ( asn1_prepend_raw ( &tbs, exts->data, exts->len ),
+ asn1_prepend_raw ( &tbs, spki.data, spki.len ),
+ asn1_prepend_raw ( &tbs, subject->data, subject->len ),
+ asn1_prepend_raw ( &tbs, icert_validity,
+ sizeof ( icert_validity ) ),
+ asn1_prepend_raw ( &tbs, issuer->data, issuer->len ),
+ asn1_prepend_raw ( &tbs, icert_tbs_prefix,
+ sizeof ( icert_tbs_prefix ) ),
+ asn1_wrap ( &tbs, ASN1_SEQUENCE ) ) ) != 0 ) {
+ DBGC ( icert, "ICERT %p could not build tbsCertificate: %s\n",
+ icert, strerror ( rc ) );
+ goto err_tbs;
+ }
+
+ /* Calculate certificate digest */
+ digest_init ( digest, digest_ctx );
+ digest_update ( digest, digest_ctx, tbs.data, tbs.len );
+ digest_final ( digest, digest_ctx, digest_out );
+
+ /* Construct signature */
+ if ( ( rc = asn1_grow ( &raw, pubkey_max_len ( pubkey,
+ pubkey_ctx ) ) ) != 0 ) {
+ DBGC ( icert, "ICERT %p could not build signature: %s\n",
+ icert, strerror ( rc ) );
+ goto err_grow;
+ }
+ if ( ( len = pubkey_sign ( pubkey, pubkey_ctx, digest, digest_out,
+ raw.data ) ) < 0 ) {
+ rc = len;
+ DBGC ( icert, "ICERT %p could not sign: %s\n",
+ icert, strerror ( rc ) );
+ goto err_pubkey_sign;
+ }
+ assert ( ( ( size_t ) len ) == raw.len );
+
+ /* Construct raw certificate data */
+ if ( ( rc = ( asn1_prepend_raw ( &raw, icert_nul,
+ sizeof ( icert_nul ) ),
+ asn1_wrap ( &raw, ASN1_BIT_STRING ),
+ asn1_prepend_raw ( &raw, icert_sha256_rsa,
+ sizeof ( icert_sha256_rsa ) ),
+ asn1_prepend_raw ( &raw, tbs.data, tbs.len ),
+ asn1_wrap ( &raw, ASN1_SEQUENCE ) ) ) != 0 ) {
+ DBGC ( icert, "ICERT %p could not build certificate: %s\n",
+ icert, strerror ( rc ) );
+ goto err_raw;
+ }
+
+ /* Parse certificate */
+ if ( ( rc = x509_certificate ( raw.data, raw.len, cert ) ) != 0 ) {
+ DBGC ( icert, "ICERT %p invalid certificate: %s\n",
+ icert, strerror ( rc ) );
+ DBGC_HDA ( icert, 0, raw.data, raw.len );
+ goto err_x509;
+ }
+
+ err_x509:
+ err_raw:
+ err_pubkey_sign:
+ free ( raw.data );
+ err_grow:
+ free ( tbs.data );
+ err_tbs:
+ free ( spki.data );
+ err_spki:
+ pubkey_final ( pubkey, pubkey_ctx );
+ err_pubkey_init:
+ return rc;
+}
+
+/**
+ * Construct certificates
+ *
+ * @v icert Certificate set
+ * @v pubkey Device public key
+ * @ret rc Return status code
+ */
+static int icert_certs ( struct icert *icert, struct asn1_cursor *key ) {
+ struct digest_algorithm *digest = icert_root.digest;
+ struct asn1_builder public = { NULL, 0 };
+ struct asn1_builder *private;
+ int rc;
+
+ /* Free any existing key and certificates */
+ icert_free ( icert );
+
+ /* Allocate "private" key */
+ icert->key = zalloc ( sizeof ( *icert->key ) );
+ if ( ! icert->key ) {
+ rc = -ENOMEM;
+ goto error;
+ }
+ privkey_init ( icert->key );
+ private = &icert->key->builder;
+
+ /* Construct our "private" key */
+ if ( ( rc = ( asn1_prepend_raw ( private, icert_private,
+ sizeof ( icert_private ) ),
+ asn1_prepend_raw ( private, icert_public,
+ sizeof ( icert_public ) ),
+ asn1_prepend ( private, ASN1_INTEGER, icert_nul,
+ sizeof ( icert_nul ) ),
+ asn1_wrap ( private, ASN1_SEQUENCE ) ) ) != 0 ) {
+ DBGC ( icert, "ICERT %p could not build private key: %s\n",
+ icert, strerror ( rc ) );
+ goto error;
+ }
+
+ /* Construct our own public key */
+ if ( ( rc = ( asn1_prepend_raw ( &public, icert_public,
+ sizeof ( icert_public ) ),
+ asn1_wrap ( &public, ASN1_SEQUENCE ) ) ) != 0 ) {
+ DBGC ( icert, "ICERT %p could not build public key: %s\n",
+ icert, strerror ( rc ) );
+ goto error;
+ }
+
+ /* Construct root certificate */
+ if ( ( rc = icert_cert ( icert, &icert_name_root, &icert_name_root,
+ asn1_built ( private ), asn1_built ( &public ),
+ &icert_root_exts, &icert->root ) ) != 0 )
+ goto error;
+
+ /* Construct host certificate */
+ if ( ( rc = icert_cert ( icert, &icert_name_ipxe, &icert_name_root,
+ asn1_built ( private ), asn1_built ( &public ),
+ &icert_leaf_exts, &icert->host ) ) != 0 )
+ goto error;
+
+ /* Construct device certificate */
+ if ( ( rc = icert_cert ( icert, &icert_name_iphone, &icert_name_root,
+ asn1_built ( private ), key,
+ &icert_leaf_exts, &icert->device ) ) != 0 )
+ goto error;
+
+ /* Construct root of trust */
+ assert ( digest->digestsize == sizeof ( icert_root_fingerprint ) );
+ x509_fingerprint ( icert->root, digest, icert_root_fingerprint );
+
+ /* Free constructed keys */
+ free ( public.data );
+ return 0;
+
+ error:
+ icert_free ( icert );
+ free ( public.data );
+ return rc;
+}
+
+/**
+ * Construct doubly base64-encoded certificate
+ *
+ * @v icert Pairing certificates
+ * @v cert X.509 certificate
+ * @v encenc Doubly base64-encoded certificate to construct
+ * @ret rc Return status code
+ *
+ * On success, the caller is responsible for eventually calling free()
+ * on the allocated doubly encoded encoded certificate.
+ */
+static int icert_encode ( struct icert *icert, struct x509_certificate *cert,
+ char **encenc ) {
+ size_t encencoded_len;
+ size_t encoded_len;
+ size_t pem_len;
+ char *pem;
+ int rc;
+
+ /* Sanity check */
+ assert ( cert != NULL );
+
+ /* Create PEM */
+ encoded_len = ( base64_encoded_len ( cert->raw.len ) + 1 /* NUL */ );
+ pem_len = ( ( sizeof ( icert_begin ) - 1 /* NUL */ ) +
+ ( encoded_len - 1 /* NUL */ ) +
+ ( sizeof ( icert_end ) - 1 /* NUL */ ) +
+ 1 /* NUL */ );
+ pem = malloc ( pem_len );
+ if ( ! pem ) {
+ rc = -ENOMEM;
+ goto err_alloc_pem;
+ }
+ strcpy ( pem, icert_begin );
+ base64_encode ( cert->raw.data, cert->raw.len,
+ ( pem + sizeof ( icert_begin ) - 1 /* NUL */ ),
+ encoded_len );
+ strcpy ( ( pem +
+ ( sizeof ( icert_begin ) - 1 /* NUL */ ) +
+ ( encoded_len - 1 /* NUL */ ) ), icert_end );
+ DBGC2 ( icert, "ICERT %p \"%s\" certificate:\n%s",
+ icert, x509_name ( cert ), pem );
+
+ /* Base64-encode the PEM (sic) */
+ encencoded_len = ( base64_encoded_len ( pem_len - 1 /* NUL */ )
+ + 1 /* NUL */ );
+ *encenc = malloc ( encencoded_len );
+ if ( ! *encenc ) {
+ rc = -ENOMEM;
+ goto err_alloc_encenc;
+ }
+ base64_encode ( pem, ( pem_len - 1 /* NUL */ ), *encenc,
+ encencoded_len );
+
+ /* Success */
+ rc = 0;
+
+ err_alloc_encenc:
+ free ( pem );
+ err_alloc_pem:
+ return rc;
+}
+
+/******************************************************************************
+ *
+ * iPhone USB multiplexer
+ *
+ ******************************************************************************
+ *
+ * The iPhone USB multiplexer speaks a protocol that is almost, but
+ * not quite, entirely unlike TCP.
+ *
+ */
+
+/**
+ * Transmit message
+ *
+ * @v imux USB multiplexer
+ * @v iobuf I/O buffer
+ * @ret rc Return status code
+ */
+static int imux_tx ( struct imux *imux, struct io_buffer *iobuf ) {
+ struct imux_header *hdr = iobuf->data;
+ size_t len = iob_len ( iobuf );
+ int rc;
+
+ /* Populate header */
+ assert ( len >= sizeof ( *hdr ) );
+ hdr->len = htonl ( len );
+ hdr->in_seq = htons ( imux->in_seq );
+ hdr->out_seq = htons ( imux->out_seq );
+ DBGCP ( imux, "IMUX %p transmitting:\n", imux );
+ DBGCP_HDA ( imux, 0, hdr, len );
+
+ /* Transmit message */
+ if ( ( rc = usb_stream ( &imux->usbnet.out, iobuf, 1 ) ) != 0 )
+ goto err;
+
+ /* Increment sequence number */
+ imux->out_seq++;
+
+ return 0;
+
+ err:
+ free_iob ( iobuf );
+ return rc;
+}
+
+/**
+ * Transmit version message
+ *
+ * @v imux USB multiplexer
+ * @ret rc Return status code
+ */
+static int imux_tx_version ( struct imux *imux ) {
+ struct io_buffer *iobuf;
+ struct imux_header_version *vers;
+ int rc;
+
+ /* Allocate I/O buffer */
+ iobuf = alloc_iob ( sizeof ( *vers ) );
+ if ( ! iobuf )
+ return -ENOMEM;
+ vers = iob_put ( iobuf, sizeof ( *vers ) );
+
+ /* Construct version message */
+ memset ( vers, 0, sizeof ( *vers ) );
+ vers->hdr.protocol = htonl ( IMUX_VERSION );
+
+ /* Transmit message */
+ if ( ( rc = imux_tx ( imux, iob_disown ( iobuf ) ) ) != 0 )
+ return rc;
+
+ return 0;
+}
+
+/**
+ * Transmit pseudo-TCP message
+ *
+ * @v imux USB multiplexer
+ * @v iobuf I/O buffer
+ * @ret rc Return status code
+ */
+static int imux_tx_tcp ( struct imux *imux, struct io_buffer *iobuf ) {
+ struct imux_header_tcp *tcp = iobuf->data;
+ size_t len = iob_len ( iobuf );
+ int rc;
+
+ /* Populate TCP header */
+ assert ( len >= sizeof ( *tcp ) );
+ tcp->hdr.protocol = htonl ( IMUX_TCP );
+ tcp->tcp.src = htons ( imux->port );
+ tcp->tcp.dest = htons ( IMUX_PORT_LOCKDOWND );
+ tcp->tcp.seq = htonl ( imux->tcp_seq );
+ tcp->tcp.ack = htonl ( imux->tcp_ack );
+ tcp->tcp.hlen = ( ( sizeof ( tcp->tcp ) / 4 ) << 4 );
+ tcp->tcp.win = htons ( IMUX_WINDOW );
+
+ /* Transmit message */
+ if ( ( rc = imux_tx ( imux, iob_disown ( iobuf ) ) ) != 0 )
+ return rc;
+
+ /* Update TCP sequence */
+ imux->tcp_seq += ( len - sizeof ( *tcp ) );
+
+ return 0;
+}
+
+/**
+ * Transmit pseudo-TCP SYN
+ *
+ * @v imux USB multiplexer
+ * @ret rc Return status code
+ */
+static int imux_tx_syn ( struct imux *imux ) {
+ struct io_buffer *iobuf;
+ struct imux_header_tcp *syn;
+ int rc;
+
+ /* Allocate I/O buffer */
+ iobuf = alloc_iob ( sizeof ( *syn ) );
+ if ( ! iobuf )
+ return -ENOMEM;
+ syn = iob_put ( iobuf, sizeof ( *syn ) );
+
+ /* Construct TCP SYN message */
+ memset ( syn, 0, sizeof ( *syn ) );
+ syn->tcp.flags = TCP_SYN;
+
+ /* Transmit message */
+ if ( ( rc = imux_tx_tcp ( imux, iob_disown ( iobuf ) ) ) != 0 )
+ return rc;
+
+ /* Increment TCP sequence to compensate for SYN */
+ imux->tcp_seq++;
+
+ return 0;
+}
+
+/**
+ * Open pairing client
+ *
+ * @v imux USB multiplexer
+ * @ret rc Return status code
+ */
+static int imux_start_pair ( struct imux *imux ) {
+ int rc;
+
+ /* Disconnect any existing pairing client */
+ intf_restart ( &imux->tcp, -EPIPE );
+
+ /* Create pairing client */
+ if ( ( rc = ipair_create ( &imux->tcp, imux->flags ) ) != 0 )
+ return rc;
+
+ return 0;
+}
+
+/**
+ * Receive version message
+ *
+ * @v imux USB multiplexer
+ */
+static void imux_rx_version ( struct imux *imux ) {
+
+ /* Reset output sequence */
+ imux->out_seq = 0;
+
+ /* Send TCP SYN */
+ imux->action = imux_tx_syn;
+}
+
+/**
+ * Receive log message
+ *
+ * @v imux USB multiplexer
+ * @v hdr Message header
+ * @v len Length of message
+ */
+static void imux_rx_log ( struct imux *imux, struct imux_header *hdr,
+ size_t len ) {
+ struct imux_header_log *log =
+ container_of ( hdr, struct imux_header_log, hdr );
+ unsigned int level;
+ size_t msg_len;
+ char *tmp;
+
+ /* Sanity check */
+ if ( len < sizeof ( *log ) ) {
+ DBGC ( imux, "IMUX %p malformed log message:\n", imux );
+ DBGC_HDA ( imux, 0, log, len );
+ return;
+ }
+
+ /* First byte is the log level, followed by a printable
+ * message with no NUL terminator. Extract the log level,
+ * then shuffle the message down within the buffer and append
+ * a NUL terminator.
+ */
+ msg_len = ( len - sizeof ( *hdr ) );
+ level = log->level;
+ tmp = ( ( void * ) &log->level );
+ memmove ( tmp, &log->msg, msg_len );
+ tmp[msg_len] = '\0';
+
+ /* Print log message */
+ DBGC ( imux, "IMUX %p <%d>: %s\n", imux, level, tmp );
+}
+
+/**
+ * Receive pseudo-TCP SYN+ACK
+ *
+ * @v imux USB multiplexer
+ */
+static void imux_rx_syn ( struct imux *imux ) {
+
+ /* Increment TCP acknowledgement to compensate for SYN */
+ imux->tcp_ack++;
+
+ /* Start pairing client */
+ imux->action = imux_start_pair;
+}
+
+/**
+ * Receive pseudo-TCP message
+ *
+ * @v imux USB multiplexer
+ * @v iobuf I/O buffer
+ */
+static void imux_rx_tcp ( struct imux *imux, struct io_buffer *iobuf ) {
+ struct imux_header_tcp *tcp = iobuf->data;
+ size_t len = iob_len ( iobuf );
+ int rc;
+
+ /* Sanity check */
+ if ( len < sizeof ( *tcp ) ) {
+ DBGC ( imux, "IMUX %p malformed TCP message:\n", imux );
+ DBGC_HDA ( imux, 0, tcp, len );
+ goto error;
+ }
+
+ /* Ignore unexpected packets */
+ if ( tcp->tcp.dest != htons ( imux->port ) ) {
+ DBGC ( imux, "IMUX %p ignoring unexpected TCP port %d:\n",
+ imux, ntohs ( tcp->tcp.dest ) );
+ DBGC_HDA ( imux, 0, tcp, len );
+ goto error;
+ }
+
+ /* Ignore resets */
+ if ( tcp->tcp.flags & TCP_RST ) {
+ DBGC ( imux, "IMUX %p ignoring TCP RST\n", imux );
+ DBGC2_HDA ( imux, 0, tcp, len );
+ goto error;
+ }
+
+ /* Record ACK number */
+ imux->tcp_ack = ( ntohl ( tcp->tcp.seq ) + len - sizeof ( *tcp ) );
+
+ /* Handle received message */
+ if ( tcp->tcp.flags & TCP_SYN ) {
+
+ /* Received SYN+ACK */
+ imux_rx_syn ( imux );
+
+ } else {
+
+ /* Strip header */
+ iob_pull ( iobuf, sizeof ( *tcp ) );
+
+ /* Deliver via socket */
+ if ( ( rc = xfer_deliver_iob ( &imux->tcp,
+ iob_disown ( iobuf ) ) ) != 0 )
+ goto error;
+ }
+
+ error:
+ free_iob ( iobuf );
+}
+
+/**
+ * Complete bulk IN transfer
+ *
+ * @v ep USB endpoint
+ * @v iobuf I/O buffer
+ * @v rc Completion status code
+ */
+static void imux_in_complete ( struct usb_endpoint *ep,
+ struct io_buffer *iobuf, int rc ) {
+ struct imux *imux = container_of ( ep, struct imux, usbnet.in );
+ struct imux_header *hdr = iobuf->data;
+ size_t len = iob_len ( iobuf );
+
+ /* Ignore packets cancelled when the endpoint closes */
+ if ( ! ep->open )
+ goto drop;
+
+ /* Report USB errors */
+ if ( rc != 0 ) {
+ DBGC ( imux, "IMUX %p bulk IN failed: %s\n",
+ imux, strerror ( rc ) );
+ goto drop;
+ }
+
+ /* Sanity check */
+ if ( len < sizeof ( *hdr ) ) {
+ DBGC ( imux, "IMUX %p malformed message:\n", imux );
+ DBGC_HDA ( imux, 0, hdr, len );
+ goto drop;
+ }
+
+ /* Record input sequence */
+ imux->in_seq = ntohs ( hdr->in_seq );
+
+ /* Handle according to protocol */
+ DBGCP ( imux, "IMUX %p received:\n", imux );
+ DBGCP_HDA ( imux, 0, hdr, len );
+ switch ( hdr->protocol ) {
+ case htonl ( IMUX_VERSION ):
+ imux_rx_version ( imux );
+ break;
+ case htonl ( IMUX_LOG ):
+ imux_rx_log ( imux, hdr, len );
+ break;
+ case htonl ( IMUX_TCP ):
+ imux_rx_tcp ( imux, iob_disown ( iobuf ) );
+ break;
+ default:
+ DBGC ( imux, "IMUX %p unknown message type %d:\n",
+ imux, ntohl ( hdr->protocol ) );
+ DBGC_HDA ( imux, 0, hdr, len );
+ break;
+ }
+
+ drop:
+ free_iob ( iobuf );
+}
+
+/** Bulk IN endpoint operations */
+static struct usb_endpoint_driver_operations imux_in_operations = {
+ .complete = imux_in_complete,
+};
+
+/**
+ * Complete bulk OUT transfer
+ *
+ * @v ep USB endpoint
+ * @v iobuf I/O buffer
+ * @v rc Completion status code
+ */
+static void imux_out_complete ( struct usb_endpoint *ep,
+ struct io_buffer *iobuf, int rc ) {
+ struct imux *imux = container_of ( ep, struct imux, usbnet.out );
+
+ /* Report USB errors */
+ if ( rc != 0 ) {
+ DBGC ( imux, "IMUX %p bulk OUT failed: %s\n",
+ imux, strerror ( rc ) );
+ goto error;
+ }
+
+ error:
+ free_iob ( iobuf );
+}
+
+/** Bulk OUT endpoint operations */
+static struct usb_endpoint_driver_operations imux_out_operations = {
+ .complete = imux_out_complete,
+};
+
+/**
+ * Shut down USB multiplexer
+ *
+ * @v imux USB multiplexer
+ */
+static void imux_shutdown ( struct imux *imux ) {
+
+ /* Shut down interfaces */
+ intf_shutdown ( &imux->tcp, -ECANCELED );
+
+ /* Close USB network device, if open */
+ if ( process_running ( &imux->process ) ) {
+ process_del ( &imux->process );
+ usbnet_close ( &imux->usbnet );
+ }
+}
+
+/**
+ * Close USB multiplexer
+ *
+ * @v imux USB multiplexer
+ * @v rc Reason for close
+ */
+static void imux_close ( struct imux *imux, int rc ) {
+ struct iphone *iphone;
+
+ /* Restart interfaces */
+ intf_restart ( &imux->tcp, rc );
+
+ /* Record pairing status */
+ imux->rc = rc;
+
+ /* Trigger link check on any associated iPhones */
+ list_for_each_entry ( iphone, &iphones, list ) {
+ if ( iphone->usb == imux->usb )
+ start_timer_nodelay ( &iphone->timer );
+ }
+
+ /* Retry pairing on any error */
+ if ( rc != 0 ) {
+
+ /* Increment port number */
+ imux->port++;
+
+ /* Request pairing on any retry attempt */
+ imux->flags = IPAIR_REQUEST;
+
+ /* Send new pseudo-TCP SYN */
+ imux->action = imux_tx_syn;
+
+ DBGC ( imux, "IMUX %p retrying pairing: %s\n",
+ imux, strerror ( rc ) );
+ return;
+ }
+
+ /* Shut down multiplexer on pairing success */
+ imux_shutdown ( imux );
+}
+
+/**
+ * Allocate I/O buffer for pseudo-TCP socket
+ *
+ * @v imux USB multiplexer
+ * @v len I/O buffer payload length
+ * @ret iobuf I/O buffer
+ */
+static struct io_buffer * imux_alloc_iob ( struct imux *imux __unused,
+ size_t len ) {
+ struct imux_header_tcp *tcp;
+ struct io_buffer *iobuf;
+
+ /* Allocate I/O buffer */
+ iobuf = alloc_iob ( sizeof ( *tcp ) + len );
+ if ( ! iobuf )
+ return NULL;
+
+ /* Reserve space for pseudo-TCP message header */
+ iob_reserve ( iobuf, sizeof ( *tcp ) );
+
+ return iobuf;
+}
+
+/**
+ * Transmit packet via pseudo-TCP socket
+ *
+ * @v imux USB multiplexer
+ * @v iobuf I/O buffer
+ * @v meta Data transfer metadata
+ * @ret rc Return status code
+ */
+static int imux_deliver ( struct imux *imux, struct io_buffer *iobuf,
+ struct xfer_metadata *meta __unused ) {
+ struct imux_header_tcp *tcp;
+
+ /* Prepend pseudo-TCP header */
+ tcp = iob_push ( iobuf, sizeof ( *tcp ) );
+ memset ( tcp, 0, sizeof ( *tcp ) );
+ tcp->tcp.flags = TCP_ACK;
+
+ /* Transmit pseudo-TCP packet */
+ return imux_tx_tcp ( imux, iob_disown ( iobuf ) );
+}
+
+/** Pseudo-TCP socket interface operations */
+static struct interface_operation imux_tcp_operations[] = {
+ INTF_OP ( xfer_deliver, struct imux *, imux_deliver ),
+ INTF_OP ( xfer_alloc_iob, struct imux *, imux_alloc_iob ),
+ INTF_OP ( intf_close, struct imux *, imux_close ),
+};
+
+/** Pseudo-TCP socket interface descriptor */
+static struct interface_descriptor imux_tcp_desc =
+ INTF_DESC ( struct imux, tcp, imux_tcp_operations );
+
+/**
+ * Multiplexer process
+ *
+ * @v imux USB multiplexer
+ */
+static void imux_step ( struct imux *imux ) {
+ int rc;
+
+ /* Poll USB bus */
+ usb_poll ( imux->bus );
+
+ /* Do nothing more if multiplexer has been closed */
+ if ( ! process_running ( &imux->process ) )
+ return;
+
+ /* Refill endpoints */
+ if ( ( rc = usbnet_refill ( &imux->usbnet ) ) != 0 ) {
+ /* Wait for next poll */
+ return;
+ }
+
+ /* Perform pending action, if any */
+ if ( imux->action ) {
+ if ( ( rc = imux->action ( imux ) ) != 0 )
+ imux_close ( imux, rc );
+ imux->action = NULL;
+ }
+}
+
+/** Multiplexer process descriptor */
+static struct process_descriptor imux_process_desc =
+ PROC_DESC ( struct imux, process, imux_step );
+
+/**
+ * Probe device
+ *
+ * @v func USB function
+ * @v config Configuration descriptor
+ * @ret rc Return status code
+ */
+static int imux_probe ( struct usb_function *func,
+ struct usb_configuration_descriptor *config ) {
+ struct usb_device *usb = func->usb;
+ struct imux *imux;
+ int rc;
+
+ /* Allocate and initialise structure */
+ imux = zalloc ( sizeof ( *imux ) );
+ if ( ! imux ) {
+ rc = -ENOMEM;
+ goto err_alloc;
+ }
+ ref_init ( &imux->refcnt, NULL );
+ imux->usb = usb;
+ imux->bus = usb->port->hub->bus;
+ usbnet_init ( &imux->usbnet, func, NULL, &imux_in_operations,
+ &imux_out_operations );
+ usb_refill_init ( &imux->usbnet.in, 0, IMUX_IN_MTU, IMUX_IN_MAX_FILL );
+ process_init ( &imux->process, &imux_process_desc, &imux->refcnt );
+ imux->action = imux_tx_version;
+ imux->port = IMUX_PORT_LOCAL;
+ intf_init ( &imux->tcp, &imux_tcp_desc, &imux->refcnt );
+ imux->rc = -EINPROGRESS_PAIRING;
+
+ /* Describe USB network device */
+ if ( ( rc = usbnet_describe ( &imux->usbnet, config ) ) != 0 ) {
+ DBGC ( imux, "IMUX %p could not describe: %s\n",
+ imux, strerror ( rc ) );
+ goto err_describe;
+ }
+
+ /* Open USB network device */
+ if ( ( rc = usbnet_open ( &imux->usbnet ) ) != 0 ) {
+ DBGC ( imux, "IMUX %p could not open: %s\n",
+ imux, strerror ( rc ) );
+ goto err_open;
+ }
+
+ /* Start polling process */
+ process_add ( &imux->process );
+
+ /* Add to list of multiplexers */
+ list_add ( &imux->list, &imuxes );
+
+ usb_func_set_drvdata ( func, imux );
+ return 0;
+
+ list_del ( &imux->list );
+ imux_shutdown ( imux );
+ err_open:
+ err_describe:
+ ref_put ( &imux->refcnt );
+ err_alloc:
+ return rc;
+}
+
+/**
+ * Remove device
+ *
+ * @v func USB function
+ */
+static void imux_remove ( struct usb_function *func ) {
+ struct imux *imux = usb_func_get_drvdata ( func );
+
+ list_del ( &imux->list );
+ imux_shutdown ( imux );
+ ref_put ( &imux->refcnt );
+}
+
+/** USB multiplexer device IDs */
+static struct usb_device_id imux_ids[] = {
+ {
+ .name = "imux",
+ .vendor = 0x05ac,
+ .product = USB_ANY_ID,
+ },
+};
+
+/** USB multiplexer driver */
+struct usb_driver imux_driver __usb_driver = {
+ .ids = imux_ids,
+ .id_count = ( sizeof ( imux_ids ) / sizeof ( imux_ids[0] ) ),
+ .class = USB_CLASS_ID ( 0xff, 0xfe, 0x02 ),
+ .score = USB_SCORE_NORMAL,
+ .probe = imux_probe,
+ .remove = imux_remove,
+};
+
+/******************************************************************************
+ *
+ * iPhone pairing client
+ *
+ ******************************************************************************
+ */
+
+/** Common prefix for all pairing messages */
+static const char ipair_prefix[] =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" "
+ "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
+ "<plist version=\"1.0\">\n"
+ "<dict>\n"
+ "<key>Label</key>\n"
+ "<string>iPXE</string>\n"
+ "<key>Request</key>\n";
+
+/** Common suffix for all pairing messages */
+static const char ipair_suffix[] =
+ "</dict>\n"
+ "</plist>\n";
+
+/** Arbitrary system BUID used for pairing */
+static const char ipair_system_buid[] = "E4DB92D2-248A-469A-AC34-92045D07E695";
+
+/** Arbitrary host ID used for pairing */
+static const char ipair_host_id[] = "93CEBC27-8457-4804-9108-F42549DF6143";
+
+static int ipair_tx_pubkey ( struct ipair *ipair );
+static int ipair_rx_pubkey ( struct ipair *ipair, char *msg );
+static int ipair_tx_pair ( struct ipair *ipair );
+static int ipair_rx_pair ( struct ipair *ipair, char *msg );
+static int ipair_tx_session ( struct ipair *ipair );
+static int ipair_rx_session ( struct ipair *ipair, char *msg );
+
+/**
+ * Free pairing client
+ *
+ * @v refcnt Reference counter
+ */
+static void ipair_free ( struct refcnt *refcnt ) {
+ struct ipair *ipair = container_of ( refcnt, struct ipair, refcnt );
+
+ icert_free ( &ipair->icert );
+ free ( ipair );
+}
+
+/**
+ * Shut down pairing client
+ *
+ * @v ipair Pairing client
+ * @v rc Reason for close
+ */
+static void ipair_close ( struct ipair *ipair, int rc ) {
+
+ /* Shut down interfaces */
+ intf_shutdown ( &ipair->xfer, rc );
+
+ /* Stop timer */
+ stop_timer ( &ipair->timer );
+}
+
+/**
+ * Transmit XML message
+ *
+ * @v ipair Pairing client
+ * @v fmt Format string
+ * @v ... Arguments
+ * @ret rc Return status code
+ */
+static int __attribute__ (( format ( printf, 2, 3 ) ))
+ipair_tx ( struct ipair *ipair, const char *fmt, ... ) {
+ struct io_buffer *iobuf;
+ struct ipair_header *hdr;
+ va_list args;
+ size_t len;
+ char *msg;
+ int rc;
+
+ /* Calculate length of formatted string */
+ va_start ( args, fmt );
+ len = ( vsnprintf ( NULL, 0, fmt, args ) + 1 /* NUL */ );
+ va_end ( args );
+
+ /* Allocate I/O buffer */
+ iobuf = xfer_alloc_iob ( &ipair->xfer, ( sizeof ( *hdr ) + len ) );
+ if ( ! iobuf )
+ return -ENOMEM;
+ hdr = iob_put ( iobuf, sizeof ( *hdr ) );
+
+ /* Construct XML message */
+ memset ( hdr, 0, sizeof ( *hdr ) );
+ hdr->len = htonl ( len );
+ msg = iob_put ( iobuf, len );
+ vsnprintf ( msg, len, fmt, args );
+ DBGC2 ( ipair, "IPAIR %p transmitting:\n%s\n", ipair, msg );
+
+ /* Transmit message */
+ if ( ( rc = xfer_deliver_iob ( &ipair->xfer,
+ iob_disown ( iobuf ) ) ) != 0 )
+ return rc;
+
+ return 0;
+}
+
+/**
+ * Receive XML message payload
+ *
+ * @v ipair Pairing client
+ * @v msg Message payload
+ * @v len Length of message
+ * @ret rc Return status code
+ */
+static int ipair_rx ( struct ipair *ipair, char *msg, size_t len ) {
+ int ( * rx ) ( struct ipair *ipair, char *msg );
+ int rc;
+
+ /* Ignore empty messages */
+ if ( ! len )
+ return 0;
+
+ /* Sanity check */
+ if ( ( msg[ len - 1 ] != '\0' ) && ( msg[ len - 1 ] != '\n' ) ) {
+ DBGC ( ipair, "IPAIR %p malformed XML:\n", ipair );
+ DBGC_HDA ( ipair, 0, msg, len );
+ return -EPROTO;
+ }
+
+ /* Add NUL terminator (potentially overwriting final newline) */
+ msg[ len - 1 ] = '\0';
+ DBGC2 ( ipair, "IPAIR %p received:\n%s\n\n", ipair, msg );
+
+ /* Handle according to current state */
+ rx = ipair->rx;
+ if ( ! rx ) {
+ DBGC ( ipair, "IPAIR %p unexpected XML:\n%s\n", ipair, msg );
+ return -EPROTO;
+ }
+ ipair->rx = NULL;
+ if ( ( rc = rx ( ipair, msg ) ) != 0 )
+ return rc;
+
+ return 0;
+}
+
+/**
+ * Locate XML tag
+ *
+ * @v ipair Pairing client
+ * @v msg XML message
+ * @v tag Tag name
+ * @ret start Start of tag content
+ * @ret end End of tag content
+ * @ret rc Return status code
+ */
+static int ipair_tag ( struct ipair *ipair, const char *msg, const char *tag,
+ char **start, char **end ) {
+ char buf[ 2 /* "</" */ + strlen ( tag ) + 1 /* ">" */ + 1 /* NUL */ ];
+
+ /* Locate opening tag */
+ sprintf ( buf, "<%s>", tag );
+ *start = strstr ( msg, buf );
+ if ( ! *start )
+ return -ENOENT;
+ *start += strlen ( buf );
+
+ /* Locate closing tag */
+ sprintf ( buf, "</%s>", tag );
+ *end = strstr ( *start, buf );
+ if ( ! *end ) {
+ DBGC ( ipair, "IPAIR %p missing closing tag %s in:\n%s\n",
+ ipair, buf, msg );
+ return -ENOENT;
+ }
+
+ return 0;
+}
+
+/**
+ * Locate XML property list dictionary value
+ *
+ * @v ipair Pairing client
+ * @v msg XML message
+ * @v key Key name
+ * @v type Key type
+ * @ret start Start of value content
+ * @ret end End of value content
+ * @ret rc Return status code
+ */
+static int ipair_key ( struct ipair *ipair, const char *msg, const char *key,
+ const char *type, char **start, char **end ) {
+ int rc;
+
+ /* Iterate over keys */
+ while ( 1 ) {
+
+ /* Locate key */
+ if ( ( rc = ipair_tag ( ipair, msg, "key", start,
+ end ) ) != 0 )
+ return rc;
+ msg = *end;
+
+ /* Check key name */
+ if ( memcmp ( *start, key, ( *end - *start ) ) != 0 )
+ continue;
+
+ /* Locate value */
+ return ipair_tag ( ipair, msg, type, start, end );
+ }
+}
+
+/**
+ * Transmit DevicePublicKey message
+ *
+ * @v ipair Pairing client
+ * @ret rc Return status code
+ */
+static int ipair_tx_pubkey ( struct ipair *ipair ) {
+ int rc;
+
+ /* Transmit message */
+ if ( ( rc = ipair_tx ( ipair,
+ "%s"
+ "<string>GetValue</string>\n"
+ "<key>Key</key>\n"
+ "<string>DevicePublicKey</string>\n"
+ "%s",
+ ipair_prefix, ipair_suffix ) ) != 0 )
+ return rc;
+
+ return 0;
+}
+
+/**
+ * Receive DevicePublicKey message
+ *
+ * @v ipair Pairing client
+ * @v msg XML message
+ * @ret rc Return status code
+ */
+static int ipair_rx_pubkey ( struct ipair *ipair, char *msg ) {
+ struct asn1_cursor *key;
+ char *data;
+ char *end;
+ char *decoded;
+ size_t max_len;
+ int len;
+ int next;
+ int rc;
+
+ /* Locate "Value" value */
+ if ( ( rc = ipair_key ( ipair, msg, "Value", "data", &data,
+ &end ) ) != 0 ) {
+ DBGC ( ipair, "IPAIR %p unexpected public key message:\n%s\n",
+ ipair, msg );
+ goto err_tag;
+ }
+ *end = '\0';
+
+ /* Decode outer layer of Base64 */
+ max_len = base64_decoded_max_len ( data );
+ decoded = malloc ( max_len );
+ if ( ! decoded ) {
+ rc = -ENOMEM;
+ goto err_alloc;
+ }
+ len = base64_decode ( data, decoded, max_len );
+ if ( len < 0 ) {
+ rc = len;
+ DBGC ( ipair, "IPAIR %p invalid outer public key:\n%s\n",
+ ipair, data );
+ goto err_decode;
+ }
+
+ /* Decode inner layer of Base64 */
+ next = pem_asn1 ( virt_to_user ( decoded ), len, 0, &key );
+ if ( next < 0 ) {
+ rc = next;
+ DBGC ( ipair, "IPAIR %p invalid inner public key:\n%s\n",
+ ipair, decoded );
+ goto err_asn1;
+ }
+ DBGC ( ipair, "IPAIR %p received public key\n", ipair );
+ DBGC2_HDA ( ipair, 0, key->data, key->len );
+
+ /* Construct certificates */
+ if ( ( rc = icert_certs ( &ipair->icert, key ) ) != 0 )
+ goto err_certs;
+
+ /* Send session request or pair request as applicable */
+ if ( ipair->flags & IPAIR_REQUEST ) {
+ ipair->tx = ipair_tx_pair;
+ ipair->rx = ipair_rx_pair;
+ } else {
+ ipair->tx = ipair_tx_session;
+ ipair->rx = ipair_rx_session;
+ }
+ start_timer_nodelay ( &ipair->timer );
+
+ /* Free key */
+ free ( key );
+
+ /* Free intermediate Base64 */
+ free ( decoded );
+
+ return 0;
+
+ err_certs:
+ free ( key );
+ err_asn1:
+ err_decode:
+ free ( decoded );
+ err_alloc:
+ err_tag:
+ return rc;
+}
+
+/**
+ * Transmit Pair message
+ *
+ * @v ipair Pairing client
+ * @ret rc Return status code
+ */
+static int ipair_tx_pair ( struct ipair *ipair ) {
+ char *root;
+ char *host;
+ char *device;
+ int rc;
+
+ /* Construct doubly encoded certificates */
+ if ( ( rc = icert_encode ( &ipair->icert, ipair->icert.root,
+ &root ) ) != 0 )
+ goto err_root;
+ if ( ( rc = icert_encode ( &ipair->icert, ipair->icert.host,
+ &host ) ) != 0 )
+ goto err_host;
+ if ( ( rc = icert_encode ( &ipair->icert, ipair->icert.device,
+ &device ) ) != 0 )
+ goto err_device;
+
+ /* Transmit message */
+ if ( ( rc = ipair_tx ( ipair,
+ "%s"
+ "<string>Pair</string>\n"
+ "<key>PairRecord</key>\n"
+ "<dict>\n"
+ "<key>RootCertificate</key>\n"
+ "<data>%s</data>\n"
+ "<key>HostCertificate</key>\n"
+ "<data>%s</data>\n"
+ "<key>DeviceCertificate</key>\n"
+ "<data>%s</data>\n"
+ "<key>SystemBUID</key>\n"
+ "<string>%s</string>\n"
+ "<key>HostID</key>\n"
+ "<string>%s</string>\n"
+ "</dict>\n"
+ "<key>ProtocolVersion</key>\n"
+ "<string>2</string>\n"
+ "<key>PairingOptions</key>\n"
+ "<dict>\n"
+ "<key>ExtendedPairingErrors</key>\n"
+ "<true/>\n"
+ "</dict>\n"
+ "%s",
+ ipair_prefix, root, host, device,
+ ipair_system_buid, ipair_host_id,
+ ipair_suffix
+ ) ) != 0 )
+ goto err_tx;
+
+ err_tx:
+ free ( device );
+ err_device:
+ free ( host );
+ err_host:
+ free ( root );
+ err_root:
+ return rc;
+}
+
+/**
+ * Receive Pair message error
+ *
+ * @v ipair Pairing client
+ * @v error Pairing error
+ * @ret rc Return status code
+ */
+static int ipair_rx_pair_error ( struct ipair *ipair, char *error ) {
+
+ /* Check for actual errors */
+ if ( strcmp ( error, "PairingDialogResponsePending" ) != 0 ) {
+ DBGC ( ipair, "IPAIR %p pairing error \"%s\"\n", ipair, error );
+ return -EPERM;
+ }
+
+ /* Retransmit pairing request */
+ ipair->tx = ipair_tx_pair;
+ ipair->rx = ipair_rx_pair;
+ start_timer_fixed ( &ipair->timer, IPAIR_RETRY_DELAY );
+
+ DBGC ( ipair, "IPAIR %p waiting for pairing dialog\n", ipair );
+ return 0;
+}
+
+/**
+ * Receive Pair message
+ *
+ * @v ipair Pairing client
+ * @v msg XML message
+ * @ret rc Return status code
+ */
+static int ipair_rx_pair ( struct ipair *ipair, char *msg ) {
+ char *error;
+ char *escrow;
+ char *end;
+ int rc;
+
+ /* Check for pairing errors */
+ if ( ( rc = ipair_key ( ipair, msg, "Error", "string", &error,
+ &end ) ) == 0 ) {
+ *end = '\0';
+ return ipair_rx_pair_error ( ipair, error );
+ }
+
+ /* Get EscrowBag */
+ if ( ( rc = ipair_key ( ipair, msg, "EscrowBag", "data", &escrow,
+ &end ) ) != 0 ) {
+ DBGC ( ipair, "IPAIR %p unexpected pairing response:\n%s\n",
+ ipair, msg );
+ return rc;
+ }
+ DBGC ( ipair, "IPAIR %p pairing successful\n", ipair );
+
+ /* Send session request */
+ ipair->tx = ipair_tx_session;
+ ipair->rx = ipair_rx_session;
+ start_timer_nodelay ( &ipair->timer );
+
+ return 0;
+}
+
+/**
+ * Transmit StartSession message
+ *
+ * @v ipair Pairing client
+ * @ret rc Return status code
+ */
+static int ipair_tx_session ( struct ipair *ipair ) {
+ int rc;
+
+ /* Transmit message */
+ if ( ( rc = ipair_tx ( ipair,
+ "%s"
+ "<string>StartSession</string>\n"
+ "<key>SystemBUID</key>\n"
+ "<string>%s</string>\n"
+ "<key>HostID</key>\n"
+ "<string>%s</string>\n"
+ "%s",
+ ipair_prefix, ipair_system_buid,
+ ipair_host_id, ipair_suffix
+ ) ) != 0 )
+ return rc;
+
+ return 0;
+}
+
+/**
+ * Receive StartSession message error
+ *
+ * @v ipair Pairing client
+ * @v error Pairing error
+ * @ret rc Return status code
+ */
+static int ipair_rx_session_error ( struct ipair *ipair, char *error ) {
+
+ /* Check for actual errors */
+ if ( strcmp ( error, "InvalidHostID" ) != 0 ) {
+ DBGC ( ipair, "IPAIR %p session error \"%s\"\n", ipair, error );
+ return -EPERM;
+ }
+
+ /* Transmit pairing request */
+ ipair->tx = ipair_tx_pair;
+ ipair->rx = ipair_rx_pair;
+ start_timer_nodelay ( &ipair->timer );
+
+ DBGC ( ipair, "IPAIR %p unknown host: requesting pairing\n", ipair );
+ return 0;
+}
+
+/**
+ * Receive StartSession message
+ *
+ * @v ipair Pairing client
+ * @v msg XML message
+ * @ret rc Return status code
+ */
+static int ipair_rx_session ( struct ipair *ipair, char *msg ) {
+ char *error;
+ char *session;
+ char *end;
+ int rc;
+
+ /* Check for session errors */
+ if ( ( rc = ipair_key ( ipair, msg, "Error", "string", &error,
+ &end ) ) == 0 ) {
+ *end = '\0';
+ return ipair_rx_session_error ( ipair, error );
+ }
+
+ /* Check for session ID */
+ if ( ( rc = ipair_key ( ipair, msg, "SessionID", "string", &session,
+ &end ) ) != 0 ) {
+ DBGC ( ipair, "IPAIR %p unexpected session response:\n%s\n",
+ ipair, msg );
+ return rc;
+ }
+ *end = '\0';
+ DBGC ( ipair, "IPAIR %p starting session \"%s\"\n", ipair, session );
+
+ /* Start TLS */
+ if ( ( rc = add_tls ( &ipair->xfer, "iPhone", &icert_root,
+ ipair->icert.key ) ) != 0 ) {
+ DBGC ( ipair, "IPAIR %p could not start TLS: %s\n",
+ ipair, strerror ( rc ) );
+ return rc;
+ }
+
+ /* Record that TLS has been started */
+ ipair->flags |= IPAIR_TLS;
+
+ return 0;
+}
+
+/**
+ * Handle window change notification
+ *
+ * @v ipair Pairing client
+ */
+static void ipair_window_changed ( struct ipair *ipair ) {
+
+ /* Report pairing as complete once TLS session has been established */
+ if ( ( ipair->flags & IPAIR_TLS ) && xfer_window ( &ipair->xfer ) ) {
+
+ /* Sanity checks */
+ assert ( x509_is_valid ( ipair->icert.root, &icert_root ) );
+ assert ( x509_is_valid ( ipair->icert.device, &icert_root ) );
+ assert ( ! x509_is_valid ( ipair->icert.root, NULL ) );
+ assert ( ! x509_is_valid ( ipair->icert.host, NULL ) );
+ assert ( ! x509_is_valid ( ipair->icert.device, NULL ) );
+
+ /* Report pairing as complete */
+ DBGC ( ipair, "IPAIR %p established TLS session\n", ipair );
+ ipair_close ( ipair, 0 );
+ return;
+ }
+}
+
+/**
+ * Handle received data
+ *
+ * @v ipair Pairing client
+ * @v iobuf I/O buffer
+ * @v meta Data transfer metadata
+ * @ret rc Return status code
+ */
+static int ipair_deliver ( struct ipair *ipair, struct io_buffer *iobuf,
+ struct xfer_metadata *meta __unused ) {
+ struct ipair_header *hdr;
+ int rc;
+
+ /* Strip header (which may appear in a separate packet) */
+ if ( ( ! ( ipair->flags & IPAIR_RX_LEN ) ) &&
+ ( iob_len ( iobuf ) >= sizeof ( *hdr ) ) ) {
+ iob_pull ( iobuf, sizeof ( *hdr ) );
+ ipair->flags |= IPAIR_RX_LEN;
+ }
+
+ /* Clear received header flag if we have a message */
+ if ( iob_len ( iobuf ) )
+ ipair->flags &= ~IPAIR_RX_LEN;
+
+ /* Receive message */
+ if ( ( rc = ipair_rx ( ipair, iobuf->data, iob_len ( iobuf ) ) ) != 0 )
+ goto error;
+
+ /* Free I/O buffer */
+ free_iob ( iobuf );
+
+ return 0;
+
+ error:
+ ipair_close ( ipair, rc );
+ free_iob ( iobuf );
+ return rc;
+}
+
+/**
+ * Pairing transmission timer
+ *
+ * @v timer Retransmission timer
+ * @v over Failure indicator
+ */
+static void ipair_expired ( struct retry_timer *timer, int over __unused ) {
+ struct ipair *ipair = container_of ( timer, struct ipair, timer );
+ int ( * tx ) ( struct ipair *ipair );
+ int rc;
+
+ /* Sanity check */
+ tx = ipair->tx;
+ assert ( tx != NULL );
+
+ /* Clear pending transmission */
+ ipair->tx = NULL;
+
+ /* Transmit data, if applicable */
+ if ( ( rc = tx ( ipair ) ) != 0 )
+ ipair_close ( ipair, rc );
+}
+
+/** Pairing client interface operations */
+static struct interface_operation ipair_xfer_operations[] = {
+ INTF_OP ( xfer_deliver, struct ipair *, ipair_deliver ),
+ INTF_OP ( xfer_window_changed, struct ipair *, ipair_window_changed ),
+ INTF_OP ( intf_close, struct ipair *, ipair_close ),
+};
+
+/** Pairing client interface descriptor */
+static struct interface_descriptor ipair_xfer_desc =
+ INTF_DESC ( struct ipair, xfer, ipair_xfer_operations );
+
+/**
+ * Create a pairing client
+ *
+ * @v xfer Data transfer interface
+ * @v flags Initial state flags
+ * @ret rc Return status code
+ */
+static int ipair_create ( struct interface *xfer, unsigned int flags ) {
+ struct ipair *ipair;
+ int rc;
+
+ /* Allocate and initialise structure */
+ ipair = zalloc ( sizeof ( *ipair ) );
+ if ( ! ipair ) {
+ rc = -ENOMEM;
+ goto err_alloc;
+ }
+ ref_init ( &ipair->refcnt, ipair_free );
+ intf_init ( &ipair->xfer, &ipair_xfer_desc, &ipair->refcnt );
+ timer_init ( &ipair->timer, ipair_expired, &ipair->refcnt );
+ ipair->tx = ipair_tx_pubkey;
+ ipair->rx = ipair_rx_pubkey;
+ ipair->flags = flags;
+
+ /* Schedule initial transmission */
+ start_timer_nodelay ( &ipair->timer );
+
+ /* Attach to parent interface, mortalise self, and return */
+ intf_plug_plug ( &ipair->xfer, xfer );
+ ref_put ( &ipair->refcnt );
+ return 0;
+
+ ref_put ( &ipair->refcnt );
+ err_alloc:
+ return rc;
+}
+
+/******************************************************************************
+ *
+ * iPhone USB networking
+ *
+ ******************************************************************************
+ */
+
+/**
+ * Complete bulk IN transfer
+ *
+ * @v ep USB endpoint
+ * @v iobuf I/O buffer
+ * @v rc Completion status code
+ */
+static void iphone_in_complete ( struct usb_endpoint *ep,
+ struct io_buffer *iobuf, int rc ) {
+ struct iphone *iphone = container_of ( ep, struct iphone, usbnet.in );
+ struct net_device *netdev = iphone->netdev;
+
+ /* Profile receive completions */
+ profile_start ( &iphone_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 ( iphone, "IPHONE %p bulk IN failed: %s\n",
+ iphone, strerror ( rc ) );
+ goto error;
+ }
+
+ /* Strip padding */
+ if ( iob_len ( iobuf ) < IPHONE_IN_PAD ) {
+ DBGC ( iphone, "IPHONE %p malformed bulk IN:\n", iphone );
+ DBGC_HDA ( iphone, 0, iobuf->data, iob_len ( iobuf ) );
+ rc = -EINVAL;
+ goto error;
+ }
+ iob_pull ( iobuf, IPHONE_IN_PAD );
+
+ /* Hand off to network stack */
+ netdev_rx ( netdev, iob_disown ( iobuf ) );
+
+ profile_stop ( &iphone_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 iphone_in_operations = {
+ .complete = iphone_in_complete,
+};
+
+/**
+ * Transmit packet
+ *
+ * @v iphone iPhone device
+ * @v iobuf I/O buffer
+ * @ret rc Return status code
+ */
+static int iphone_out_transmit ( struct iphone *iphone,
+ struct io_buffer *iobuf ) {
+ int rc;
+
+ /* Profile transmissions */
+ profile_start ( &iphone_out_profiler );
+
+ /* Enqueue I/O buffer */
+ if ( ( rc = usb_stream ( &iphone->usbnet.out, iobuf, 1 ) ) != 0 )
+ return rc;
+
+ profile_stop ( &iphone_out_profiler );
+ return 0;
+}
+
+/**
+ * Complete bulk OUT transfer
+ *
+ * @v ep USB endpoint
+ * @v iobuf I/O buffer
+ * @v rc Completion status code
+ */
+static void iphone_out_complete ( struct usb_endpoint *ep,
+ struct io_buffer *iobuf, int rc ) {
+ struct iphone *iphone = container_of ( ep, struct iphone, usbnet.out );
+ struct net_device *netdev = iphone->netdev;
+
+ /* Report TX completion */
+ netdev_tx_complete_err ( netdev, iobuf, rc );
+}
+
+/** Bulk OUT endpoint operations */
+static struct usb_endpoint_driver_operations iphone_out_operations = {
+ .complete = iphone_out_complete,
+};
+
+/**
+ * Check pairing status
+ *
+ * @v iphone iPhone device
+ * @ret rc Return status code
+ */
+static int iphone_check_pair ( struct iphone *iphone ) {
+ struct imux *imux;
+
+ /* Find corresponding USB multiplexer */
+ list_for_each_entry ( imux, &imuxes, list ) {
+ if ( imux->usb == iphone->usb )
+ return imux->rc;
+ }
+
+ return -EPIPE_NO_MUX;
+}
+
+/**
+ * Check link status
+ *
+ * @v netdev Network device
+ */
+static void iphone_check_link ( struct net_device *netdev ) {
+ struct iphone *iphone = netdev->priv;
+ struct usb_device *usb = iphone->usb;
+ uint8_t status;
+ int rc;
+
+ /* Check pairing status */
+ if ( ( rc = iphone_check_pair ( iphone ) ) != 0 )
+ goto err_pair;
+
+ /* Get link status */
+ if ( ( rc = usb_control ( usb, IPHONE_GET_LINK, 0, 0, &status,
+ sizeof ( status ) ) ) != 0 ) {
+ DBGC ( iphone, "IPHONE %p could not get link status: %s\n",
+ iphone, strerror ( rc ) );
+ goto err_control;
+ }
+
+ /* Check link status */
+ if ( status != IPHONE_LINK_UP ) {
+ rc = -ENOTCONN_STATUS ( status );
+ goto err_status;
+ }
+
+ /* Success */
+ rc = 0;
+
+ err_status:
+ err_control:
+ err_pair:
+ /* Report link status. Since we have to check the link
+ * periodically (due to an absence of an interrupt endpoint),
+ * do this only if the link status has actually changed.
+ */
+ if ( rc != netdev->link_rc ) {
+ if ( rc == 0 ) {
+ DBGC ( iphone, "IPHONE %p link up\n", iphone );
+ } else {
+ DBGC ( iphone, "IPHONE %p link down: %s\n",
+ iphone, strerror ( rc ) );
+ }
+ netdev_link_err ( netdev, rc );
+ }
+}
+
+/**
+ * Periodically update link status
+ *
+ * @v timer Link status timer
+ * @v over Failure indicator
+ */
+static void iphone_expired ( struct retry_timer *timer, int over __unused ) {
+ struct iphone *iphone = container_of ( timer, struct iphone, timer );
+ struct net_device *netdev = iphone->netdev;
+
+ /* Check link status */
+ iphone_check_link ( netdev );
+
+ /* Restart timer, if device is open */
+ if ( netdev_is_open ( netdev ) )
+ start_timer_fixed ( timer, IPHONE_LINK_CHECK_INTERVAL );
+}
+
+/**
+ * Open network device
+ *
+ * @v netdev Network device
+ * @ret rc Return status code
+ */
+static int iphone_open ( struct net_device *netdev ) {
+ struct iphone *iphone = netdev->priv;
+ int rc;
+
+ /* Open USB network device */
+ if ( ( rc = usbnet_open ( &iphone->usbnet ) ) != 0 ) {
+ DBGC ( iphone, "IPHONE %p could not open: %s\n",
+ iphone, strerror ( rc ) );
+ goto err_open;
+ }
+
+ /* Start the link status check timer */
+ start_timer_nodelay ( &iphone->timer );
+
+ return 0;
+
+ usbnet_close ( &iphone->usbnet );
+ err_open:
+ return rc;
+}
+
+/**
+ * Close network device
+ *
+ * @v netdev Network device
+ */
+static void iphone_close ( struct net_device *netdev ) {
+ struct iphone *iphone = netdev->priv;
+
+ /* Stop the link status check timer */
+ stop_timer ( &iphone->timer );
+
+ /* Close USB network device */
+ usbnet_close ( &iphone->usbnet );
+}
+
+/**
+ * Transmit packet
+ *
+ * @v netdev Network device
+ * @v iobuf I/O buffer
+ * @ret rc Return status code
+ */
+static int iphone_transmit ( struct net_device *netdev,
+ struct io_buffer *iobuf ) {
+ struct iphone *iphone = netdev->priv;
+ int rc;
+
+ /* Transmit packet */
+ if ( ( rc = iphone_out_transmit ( iphone, iobuf ) ) != 0 )
+ return rc;
+
+ return 0;
+}
+
+/**
+ * Poll for completed and received packets
+ *
+ * @v netdev Network device
+ */
+static void iphone_poll ( struct net_device *netdev ) {
+ struct iphone *iphone = netdev->priv;
+ int rc;
+
+ /* Poll USB bus */
+ usb_poll ( iphone->bus );
+
+ /* Refill endpoints */
+ if ( ( rc = usbnet_refill ( &iphone->usbnet ) ) != 0 )
+ netdev_rx_err ( netdev, NULL, rc );
+}
+
+/** iPhone network device operations */
+static struct net_device_operations iphone_operations = {
+ .open = iphone_open,
+ .close = iphone_close,
+ .transmit = iphone_transmit,
+ .poll = iphone_poll,
+};
+
+/**
+ * Probe device
+ *
+ * @v func USB function
+ * @v config Configuration descriptor
+ * @ret rc Return status code
+ */
+static int iphone_probe ( struct usb_function *func,
+ struct usb_configuration_descriptor *config ) {
+ struct usb_device *usb = func->usb;
+ struct net_device *netdev;
+ struct iphone *iphone;
+ int rc;
+
+ /* Allocate and initialise structure */
+ netdev = alloc_etherdev ( sizeof ( *iphone ) );
+ if ( ! netdev ) {
+ rc = -ENOMEM;
+ goto err_alloc;
+ }
+ netdev_init ( netdev, &iphone_operations );
+ netdev->dev = &func->dev;
+ iphone = netdev->priv;
+ memset ( iphone, 0, sizeof ( *iphone ) );
+ iphone->usb = usb;
+ iphone->bus = usb->port->hub->bus;
+ iphone->netdev = netdev;
+ usbnet_init ( &iphone->usbnet, func, NULL, &iphone_in_operations,
+ &iphone_out_operations );
+ usb_refill_init ( &iphone->usbnet.in, 0, IPHONE_IN_MTU,
+ IPHONE_IN_MAX_FILL );
+ timer_init ( &iphone->timer, iphone_expired, &netdev->refcnt );
+ DBGC ( iphone, "IPHONE %p on %s\n", iphone, func->name );
+
+ /* Describe USB network device */
+ if ( ( rc = usbnet_describe ( &iphone->usbnet, config ) ) != 0 ) {
+ DBGC ( iphone, "IPHONE %p could not describe: %s\n",
+ iphone, strerror ( rc ) );
+ goto err_describe;
+ }
+
+ /* Fetch MAC address */
+ if ( ( rc = usb_control ( usb, IPHONE_GET_MAC, 0, 0, netdev->hw_addr,
+ ETH_ALEN ) ) != 0 ) {
+ DBGC ( iphone, "IPHONE %p could not fetch MAC address: %s\n",
+ iphone, strerror ( rc ) );
+ goto err_fetch_mac;
+ }
+
+ /* Register network device */
+ if ( ( rc = register_netdev ( netdev ) ) != 0 )
+ goto err_register;
+
+ /* Set initial link status */
+ iphone_check_link ( netdev );
+
+ /* Add to list of iPhone network devices */
+ list_add ( &iphone->list, &iphones );
+
+ usb_func_set_drvdata ( func, iphone );
+ return 0;
+
+ list_del ( &iphone->list );
+ unregister_netdev ( netdev );
+ err_register:
+ err_fetch_mac:
+ err_describe:
+ netdev_nullify ( netdev );
+ netdev_put ( netdev );
+ err_alloc:
+ return rc;
+}
+
+/**
+ * Remove device
+ *
+ * @v func USB function
+ */
+static void iphone_remove ( struct usb_function *func ) {
+ struct iphone *iphone = usb_func_get_drvdata ( func );
+ struct net_device *netdev = iphone->netdev;
+
+ list_del ( &iphone->list );
+ unregister_netdev ( netdev );
+ netdev_nullify ( netdev );
+ netdev_put ( netdev );
+}
+
+/** iPhone device IDs */
+static struct usb_device_id iphone_ids[] = {
+ {
+ .name = "iphone",
+ .vendor = 0x05ac,
+ .product = USB_ANY_ID,
+ },
+};
+
+/** iPhone driver */
+struct usb_driver iphone_driver __usb_driver = {
+ .ids = iphone_ids,
+ .id_count = ( sizeof ( iphone_ids ) / sizeof ( iphone_ids[0] ) ),
+ .class = USB_CLASS_ID ( 0xff, 0xfd, 0x01 ),
+ .score = USB_SCORE_NORMAL,
+ .probe = iphone_probe,
+ .remove = iphone_remove,
+};
+
+/* Drag in objects via iphone_driver */
+REQUIRING_SYMBOL ( iphone_driver );
+
+/* Drag in RSA-with-SHA256 OID prefixes */
+REQUIRE_OBJECT ( rsa_sha256 );
diff --git a/src/drivers/net/iphone.h b/src/drivers/net/iphone.h
new file mode 100644
index 000000000..2db6da7bd
--- /dev/null
+++ b/src/drivers/net/iphone.h
@@ -0,0 +1,291 @@
+#ifndef _IPHONE_H
+#define _IPHONE_H
+
+/** @file
+ *
+ * iPhone USB Ethernet driver
+ *
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+#include <stdint.h>
+#include <ipxe/usb.h>
+#include <ipxe/usbnet.h>
+#include <ipxe/process.h>
+#include <ipxe/timer.h>
+#include <ipxe/retry.h>
+#include <ipxe/tcp.h>
+#include <ipxe/x509.h>
+#include <ipxe/privkey.h>
+
+/******************************************************************************
+ *
+ * iPhone pairing certificates
+ *
+ ******************************************************************************
+ */
+
+/** An iPhone pairing certificate set */
+struct icert {
+ /** "Private" key */
+ struct private_key *key;
+ /** Root certificate */
+ struct x509_certificate *root;
+ /** Host certificate */
+ struct x509_certificate *host;
+ /** Device certificate */
+ struct x509_certificate *device;
+};
+
+/******************************************************************************
+ *
+ * iPhone USB multiplexer
+ *
+ ******************************************************************************
+ */
+
+/** An iPhone USB multiplexed packet header */
+struct imux_header {
+ /** Protocol */
+ uint32_t protocol;
+ /** Length (including this header) */
+ uint32_t len;
+ /** Reserved */
+ uint32_t reserved;
+ /** Output sequence number */
+ uint16_t out_seq;
+ /** Input sequence number */
+ uint16_t in_seq;
+} __attribute__ (( packed ));
+
+/** iPhone USB multiplexer protocols */
+enum imux_protocol {
+ /** Version number */
+ IMUX_VERSION = 0,
+ /** Log message */
+ IMUX_LOG = 1,
+ /** TCP packet */
+ IMUX_TCP = IP_TCP,
+};
+
+/** An iPhone USB multiplexed version message header */
+struct imux_header_version {
+ /** Multiplexed packet header */
+ struct imux_header hdr;
+ /** Reserved */
+ uint32_t reserved;
+} __attribute__ (( packed ));
+
+/** An iPhone USB multiplexed log message header */
+struct imux_header_log {
+ /** Multiplexed packet header */
+ struct imux_header hdr;
+ /** Log level */
+ uint8_t level;
+ /** Message */
+ char msg[0];
+} __attribute__ (( packed ));
+
+/** An iPhone USB multiplexed pseudo-TCP message header */
+struct imux_header_tcp {
+ /** Multiplexed packet header */
+ struct imux_header hdr;
+ /** Pseudo-TCP header */
+ struct tcp_header tcp;
+} __attribute__ (( packed ));
+
+/** Local port number
+ *
+ * This is a policy decision.
+ */
+#define IMUX_PORT_LOCAL 0x18ae
+
+/** Lockdown daemon port number */
+#define IMUX_PORT_LOCKDOWND 62078
+
+/** Advertised TCP window
+ *
+ * This is a policy decision.
+ */
+#define IMUX_WINDOW 0x0200
+
+/** An iPhone USB multiplexer */
+struct imux {
+ /** Reference counter */
+ struct refcnt refcnt;
+ /** USB device */
+ struct usb_device *usb;
+ /** USB bus */
+ struct usb_bus *bus;
+ /** USB network device */
+ struct usbnet_device usbnet;
+ /** List of USB multiplexers */
+ struct list_head list;
+
+ /** Polling process */
+ struct process process;
+ /** Pending action
+ *
+ * @v imux USB multiplexer
+ * @ret rc Return status code
+ */
+ int ( * action ) ( struct imux *imux );
+
+ /** Input sequence */
+ uint16_t in_seq;
+ /** Output sequence */
+ uint16_t out_seq;
+ /** Pseudo-TCP sequence number */
+ uint32_t tcp_seq;
+ /** Pseudo-TCP acknowledgement number */
+ uint32_t tcp_ack;
+ /** Pseudo-TCP local port number */
+ uint16_t port;
+
+ /** Pseudo-TCP lockdown socket interface */
+ struct interface tcp;
+ /** Pairing flags */
+ unsigned int flags;
+ /** Pairing status */
+ int rc;
+};
+
+/** Multiplexer bulk IN maximum fill level
+ *
+ * This is a policy decision.
+ */
+#define IMUX_IN_MAX_FILL 1
+
+/** Multiplexer bulk IN buffer size
+ *
+ * This is a policy decision.
+ */
+#define IMUX_IN_MTU 4096
+
+/******************************************************************************
+ *
+ * iPhone pairing client
+ *
+ ******************************************************************************
+ */
+
+/** An iPhone USB multiplexed pseudo-TCP XML message header */
+struct ipair_header {
+ /** Message length */
+ uint32_t len;
+ /** Message */
+ char msg[0];
+} __attribute__ (( packed ));
+
+/** An iPhone pairing client */
+struct ipair {
+ /** Reference counter */
+ struct refcnt refcnt;
+ /** Data transfer interface */
+ struct interface xfer;
+
+ /** Pairing timer */
+ struct retry_timer timer;
+ /** Transmit message
+ *
+ * @v ipair Pairing client
+ * @ret rc Return status code
+ */
+ int ( * tx ) ( struct ipair *ipair );
+ /** Receive message
+ *
+ * @v ipair Pairing client
+ * @v msg XML message
+ * @ret rc Return status code
+ */
+ int ( * rx ) ( struct ipair *ipair, char *msg );
+ /** State flags */
+ unsigned int flags;
+
+ /** Pairing certificates */
+ struct icert icert;
+};
+
+/** Pairing client state flags */
+enum ipair_flags {
+ /** Request a new pairing */
+ IPAIR_REQUEST = 0x0001,
+ /** Standalone length has been received */
+ IPAIR_RX_LEN = 0x0002,
+ /** TLS session has been started */
+ IPAIR_TLS = 0x0004,
+};
+
+/** Pairing retry delay
+ *
+ * This is a policy decision.
+ */
+#define IPAIR_RETRY_DELAY ( 1 * TICKS_PER_SEC )
+
+/******************************************************************************
+ *
+ * iPhone USB networking
+ *
+ ******************************************************************************
+ */
+
+/** Get MAC address */
+#define IPHONE_GET_MAC \
+ ( USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE | \
+ USB_REQUEST_TYPE ( 0x00 ) )
+
+/** Get link status */
+#define IPHONE_GET_LINK \
+ ( USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE | \
+ USB_REQUEST_TYPE ( 0x45 ) )
+
+/** An iPhone link status */
+enum iphone_link_status {
+ /** Personal Hotspot is disabled */
+ IPHONE_LINK_DISABLED = 0x03,
+ /** Link up */
+ IPHONE_LINK_UP = 0x04,
+ /** Link not yet determined */
+ IPHONE_LINK_UNKNOWN = -1U,
+};
+
+/** An iPhone network device */
+struct iphone {
+ /** 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;
+
+ /** List of iPhone network devices */
+ struct list_head list;
+ /** Link status check timer */
+ struct retry_timer timer;
+};
+
+/** Bulk IN padding */
+#define IPHONE_IN_PAD 2
+
+/** Bulk IN buffer size
+ *
+ * This is a policy decision.
+ */
+#define IPHONE_IN_MTU ( ETH_FRAME_LEN + IPHONE_IN_PAD )
+
+/** Bulk IN maximum fill level
+ *
+ * This is a policy decision.
+ */
+#define IPHONE_IN_MAX_FILL 8
+
+/** Link check interval
+ *
+ * This is a policy decision.
+ */
+#define IPHONE_LINK_CHECK_INTERVAL ( 5 * TICKS_PER_SEC )
+
+#endif /* _IPHONE_H */
diff --git a/src/drivers/net/jme.c b/src/drivers/net/jme.c
index 29694b699..c7307728d 100644
--- a/src/drivers/net/jme.c
+++ b/src/drivers/net/jme.c
@@ -262,7 +262,7 @@ jme_free_tx_resources(struct jme_adapter *jme)
sizeof(struct io_buffer *) * jme->tx_ring_size);
free(txring->bufinf);
}
- free_dma(txring->desc, jme->tx_ring_size * TX_DESC_SIZE);
+ free_phys(txring->desc, jme->tx_ring_size * TX_DESC_SIZE);
txring->desc = NULL;
txring->dma = 0;
txring->bufinf = NULL;
@@ -277,7 +277,7 @@ jme_alloc_tx_resources(struct jme_adapter *jme)
{
struct jme_ring *txring = &jme->txring;
- txring->desc = malloc_dma(jme->tx_ring_size * TX_DESC_SIZE,
+ txring->desc = malloc_phys(jme->tx_ring_size * TX_DESC_SIZE,
RING_DESC_ALIGN);
if (!txring->desc) {
DBG("Can not allocate transmit ring descriptors.\n");
@@ -442,7 +442,7 @@ jme_free_rx_resources(struct jme_adapter *jme)
free(rxring->bufinf);
}
- free_dma(rxring->desc, jme->rx_ring_size * RX_DESC_SIZE);
+ free_phys(rxring->desc, jme->rx_ring_size * RX_DESC_SIZE);
rxring->desc = NULL;
rxring->dma = 0;
rxring->bufinf = NULL;
@@ -458,7 +458,7 @@ jme_alloc_rx_resources(struct jme_adapter *jme)
struct jme_ring *rxring = &jme->rxring;
struct io_buffer **bufinf;
- rxring->desc = malloc_dma(jme->rx_ring_size * RX_DESC_SIZE,
+ rxring->desc = malloc_phys(jme->rx_ring_size * RX_DESC_SIZE,
RING_DESC_ALIGN);
if (!rxring->desc) {
DBG("Can not allocate receive ring descriptors.\n");
@@ -1191,7 +1191,7 @@ jme_probe(struct pci_device *pci)
jme = netdev->priv;
pci_set_drvdata(pci, netdev);
netdev->dev = &pci->dev;
- jme->regs = ioremap(pci->membase, JME_REGS_SIZE);
+ jme->regs = pci_ioremap(pci, pci->membase, JME_REGS_SIZE);
if (!(jme->regs)) {
DBG("Mapping PCI resource region error.\n");
rc = -ENOMEM;
diff --git a/src/drivers/net/myri10ge.c b/src/drivers/net/myri10ge.c
index ae6b6c21e..6d0f723f2 100644
--- a/src/drivers/net/myri10ge.c
+++ b/src/drivers/net/myri10ge.c
@@ -66,7 +66,7 @@ FILE_LICENCE ( GPL2_ONLY );
/*
* Debugging levels:
- * - DBG() is for any errors, i.e. failed alloc_iob(), malloc_dma(),
+ * - DBG() is for any errors, i.e. failed alloc_iob(), malloc_phys(),
* TX overflow, corrupted packets, ...
* - DBG2() is for successful events, like packet received,
* packet transmitted, and other general notifications.
@@ -918,7 +918,7 @@ static void myri10ge_net_close ( struct net_device *netdev )
/* Release DMAable memory. */
- free_dma ( priv->dma, sizeof ( *priv->dma ) );
+ free_phys ( priv->dma, sizeof ( *priv->dma ) );
/* Erase all state from the open. */
@@ -988,7 +988,7 @@ static int myri10ge_net_open ( struct net_device *netdev )
/* Allocate cleared DMAable buffers. */
- priv->dma = malloc_dma ( sizeof ( *priv->dma ) , 128 );
+ priv->dma = malloc_phys ( sizeof ( *priv->dma ) , 128 );
if ( !priv->dma ) {
rc = -ENOMEM;
dbg = "DMA";
@@ -1152,7 +1152,7 @@ abort_with_receives_posted:
free_iob ( priv->receive_iob[priv->receives_posted] );
abort_with_dma:
/* Because the link is not up, we don't have to reset the NIC here. */
- free_dma ( priv->dma, sizeof ( *priv->dma ) );
+ free_phys ( priv->dma, sizeof ( *priv->dma ) );
abort_with_nothing:
/* Erase all signs of the failed open. */
memset ( priv, 0, sizeof ( *priv ) );
diff --git a/src/drivers/net/myson.c b/src/drivers/net/myson.c
index 84a550596..4ab2bf345 100644
--- a/src/drivers/net/myson.c
+++ b/src/drivers/net/myson.c
@@ -165,7 +165,7 @@ static int myson_create_ring ( struct myson_nic *myson,
int rc;
/* Allocate descriptor ring */
- ring->desc = malloc_dma ( len, MYSON_RING_ALIGN );
+ ring->desc = malloc_phys ( len, MYSON_RING_ALIGN );
if ( ! ring->desc ) {
rc = -ENOMEM;
goto err_alloc;
@@ -197,7 +197,7 @@ static int myson_create_ring ( struct myson_nic *myson,
return 0;
err_64bit:
- free_dma ( ring->desc, len );
+ free_phys ( ring->desc, len );
ring->desc = NULL;
err_alloc:
return rc;
@@ -217,7 +217,7 @@ static void myson_destroy_ring ( struct myson_nic *myson,
writel ( 0, myson->regs + ring->reg );
/* Free descriptor ring */
- free_dma ( ring->desc, len );
+ free_phys ( ring->desc, len );
ring->desc = NULL;
ring->prod = 0;
ring->cons = 0;
@@ -606,7 +606,7 @@ static int myson_probe ( struct pci_device *pci ) {
adjust_pci_device ( pci );
/* Map registers */
- myson->regs = ioremap ( pci->membase, MYSON_BAR_SIZE );
+ myson->regs = pci_ioremap ( pci, pci->membase, MYSON_BAR_SIZE );
if ( ! myson->regs ) {
rc = -ENODEV;
goto err_ioremap;
diff --git a/src/drivers/net/natsemi.c b/src/drivers/net/natsemi.c
index 9f2c3029c..ba99bc2fe 100644
--- a/src/drivers/net/natsemi.c
+++ b/src/drivers/net/natsemi.c
@@ -408,7 +408,7 @@ static int natsemi_create_ring ( struct natsemi_nic *natsemi,
* ensure that it can't possibly cross the boundary of 32-bit
* address space.
*/
- ring->desc = malloc_dma ( len, len );
+ ring->desc = malloc_phys ( len, len );
if ( ! ring->desc ) {
rc = -ENOMEM;
goto err_alloc;
@@ -454,7 +454,7 @@ static int natsemi_create_ring ( struct natsemi_nic *natsemi,
return 0;
err_64bit:
- free_dma ( ring->desc, len );
+ free_phys ( ring->desc, len );
ring->desc = NULL;
err_alloc:
return rc;
@@ -476,7 +476,7 @@ static void natsemi_destroy_ring ( struct natsemi_nic *natsemi,
writel ( 0, natsemi->regs + ring->reg + 4 );
/* Free descriptor ring */
- free_dma ( ring->desc, len );
+ free_phys ( ring->desc, len );
ring->desc = NULL;
ring->prod = 0;
ring->cons = 0;
@@ -853,7 +853,7 @@ static int natsemi_probe ( struct pci_device *pci ) {
adjust_pci_device ( pci );
/* Map registers */
- natsemi->regs = ioremap ( pci->membase, NATSEMI_BAR_SIZE );
+ natsemi->regs = pci_ioremap ( pci, pci->membase, NATSEMI_BAR_SIZE );
if ( ! natsemi->regs ) {
rc = -ENODEV;
goto err_ioremap;
diff --git a/src/drivers/net/ncm.c b/src/drivers/net/ncm.c
index 1837291f7..cc07a4388 100644
--- a/src/drivers/net/ncm.c
+++ b/src/drivers/net/ncm.c
@@ -558,6 +558,8 @@ static int ncm_probe ( struct usb_function *func,
struct usb_interface_descriptor *comms;
struct ecm_ethernet_descriptor *ethernet;
struct ncm_ntb_parameters params;
+ unsigned int remainder;
+ unsigned int divisor;
int rc;
/* Allocate and initialise structure */
@@ -616,14 +618,15 @@ static int ncm_probe ( struct usb_function *func,
DBGC2 ( ncm, "NCM %p maximum IN size is %zd bytes\n", ncm, ncm->mtu );
/* Calculate transmit padding */
- ncm->padding = ( ( le16_to_cpu ( params.out.remainder ) -
- sizeof ( struct ncm_ntb_header ) - ETH_HLEN ) &
- ( le16_to_cpu ( params.out.divisor ) - 1 ) );
+ divisor = ( params.out.divisor ?
+ le16_to_cpu ( params.out.divisor ) : 1 );
+ remainder = le16_to_cpu ( params.out.remainder );
+ ncm->padding = ( ( remainder - sizeof ( struct ncm_ntb_header ) -
+ ETH_HLEN ) & ( divisor - 1 ) );
DBGC2 ( ncm, "NCM %p using %zd-byte transmit padding\n",
ncm, ncm->padding );
assert ( ( ( sizeof ( struct ncm_ntb_header ) + ncm->padding +
- ETH_HLEN ) % le16_to_cpu ( params.out.divisor ) ) ==
- le16_to_cpu ( params.out.remainder ) );
+ ETH_HLEN ) % divisor ) == remainder );
/* Register network device */
if ( ( rc = register_netdev ( netdev ) ) != 0 )
diff --git a/src/drivers/net/netfront.c b/src/drivers/net/netfront.c
index b6205542b..be210850a 100644
--- a/src/drivers/net/netfront.c
+++ b/src/drivers/net/netfront.c
@@ -338,7 +338,7 @@ static int netfront_create_ring ( struct netfront_nic *netfront,
ring->id_cons = 0;
/* Allocate and initialise shared ring */
- ring->sring.raw = malloc_dma ( PAGE_SIZE, PAGE_SIZE );
+ ring->sring.raw = malloc_phys ( PAGE_SIZE, PAGE_SIZE );
if ( ! ring->sring.raw ) {
rc = -ENOMEM;
goto err_alloc;
@@ -368,7 +368,7 @@ static int netfront_create_ring ( struct netfront_nic *netfront,
err_write_num:
xengrant_invalidate ( xen, ring->ref );
err_permit_access:
- free_dma ( ring->sring.raw, PAGE_SIZE );
+ free_phys ( ring->sring.raw, PAGE_SIZE );
err_alloc:
return rc;
}
@@ -490,7 +490,7 @@ static void netfront_destroy_ring ( struct netfront_nic *netfront,
xengrant_invalidate ( xen, ring->ref );
/* Free page */
- free_dma ( ring->sring.raw, PAGE_SIZE );
+ free_phys ( ring->sring.raw, PAGE_SIZE );
ring->sring.raw = NULL;
}
diff --git a/src/drivers/net/pcnet32.c b/src/drivers/net/pcnet32.c
index 2635aaca2..c0dea86a8 100644
--- a/src/drivers/net/pcnet32.c
+++ b/src/drivers/net/pcnet32.c
@@ -246,7 +246,7 @@ pcnet32_setup_rx_resources ( struct pcnet32_private *priv )
{
DBGP ( "pcnet32_setup_rx_resources\n" );
- priv->rx_base = malloc_dma ( RX_RING_BYTES, RX_RING_ALIGN );
+ priv->rx_base = malloc_phys ( RX_RING_BYTES, RX_RING_ALIGN );
DBG ( "priv->rx_base = %#08lx\n", virt_to_bus ( priv->rx_base ) );
@@ -270,7 +270,7 @@ pcnet32_free_rx_resources ( struct pcnet32_private *priv )
DBGP ( "pcnet32_free_rx_resources\n" );
- free_dma ( priv->rx_base, RX_RING_BYTES );
+ free_phys ( priv->rx_base, RX_RING_BYTES );
for ( i = 0; i < RX_RING_SIZE; i++ ) {
free_iob ( priv->rx_iobuf[i] );
@@ -290,7 +290,7 @@ pcnet32_setup_tx_resources ( struct pcnet32_private *priv )
{
DBGP ( "pcnet32_setup_tx_resources\n" );
- priv->tx_base = malloc_dma ( TX_RING_BYTES, TX_RING_ALIGN );
+ priv->tx_base = malloc_phys ( TX_RING_BYTES, TX_RING_ALIGN );
if ( ! priv->tx_base ) {
return -ENOMEM;
@@ -312,7 +312,7 @@ pcnet32_free_tx_resources ( struct pcnet32_private *priv )
{
DBGP ( "pcnet32_free_tx_resources\n" );
- free_dma ( priv->tx_base, TX_RING_BYTES );
+ free_phys ( priv->tx_base, TX_RING_BYTES );
}
static int
diff --git a/src/drivers/net/phantom/phantom.c b/src/drivers/net/phantom/phantom.c
index 781049ff4..843459059 100644
--- a/src/drivers/net/phantom/phantom.c
+++ b/src/drivers/net/phantom/phantom.c
@@ -640,7 +640,7 @@ static int phantom_create_rx_ctx ( struct phantom_nic *phantom ) {
int rc;
/* Allocate context creation buffer */
- buf = malloc_dma ( sizeof ( *buf ), UNM_DMA_BUFFER_ALIGN );
+ buf = malloc_phys ( sizeof ( *buf ), UNM_DMA_BUFFER_ALIGN );
if ( ! buf ) {
rc = -ENOMEM;
goto out;
@@ -716,7 +716,7 @@ static int phantom_create_rx_ctx ( struct phantom_nic *phantom ) {
phantom, phantom->sds_irq_mask_crb );
out:
- free_dma ( buf, sizeof ( *buf ) );
+ free_phys ( buf, sizeof ( *buf ) );
return rc;
}
@@ -765,7 +765,7 @@ static int phantom_create_tx_ctx ( struct phantom_nic *phantom ) {
int rc;
/* Allocate context creation buffer */
- buf = malloc_dma ( sizeof ( *buf ), UNM_DMA_BUFFER_ALIGN );
+ buf = malloc_phys ( sizeof ( *buf ), UNM_DMA_BUFFER_ALIGN );
if ( ! buf ) {
rc = -ENOMEM;
goto out;
@@ -821,7 +821,7 @@ static int phantom_create_tx_ctx ( struct phantom_nic *phantom ) {
phantom, phantom->cds_producer_crb );
out:
- free_dma ( buf, sizeof ( *buf ) );
+ free_phys ( buf, sizeof ( *buf ) );
return rc;
}
@@ -1164,8 +1164,8 @@ static int phantom_open ( struct net_device *netdev ) {
int rc;
/* Allocate and zero descriptor rings */
- phantom->desc = malloc_dma ( sizeof ( *(phantom->desc) ),
- UNM_DMA_BUFFER_ALIGN );
+ phantom->desc = malloc_phys ( sizeof ( *(phantom->desc) ),
+ UNM_DMA_BUFFER_ALIGN );
if ( ! phantom->desc ) {
rc = -ENOMEM;
goto err_alloc_desc;
@@ -1208,7 +1208,7 @@ static int phantom_open ( struct net_device *netdev ) {
err_create_tx_ctx:
phantom_destroy_rx_ctx ( phantom );
err_create_rx_ctx:
- free_dma ( phantom->desc, sizeof ( *(phantom->desc) ) );
+ free_phys ( phantom->desc, sizeof ( *(phantom->desc) ) );
phantom->desc = NULL;
err_alloc_desc:
return rc;
@@ -1229,7 +1229,7 @@ static void phantom_close ( struct net_device *netdev ) {
phantom_del_macaddr ( phantom, netdev->ll_broadcast );
phantom_destroy_tx_ctx ( phantom );
phantom_destroy_rx_ctx ( phantom );
- free_dma ( phantom->desc, sizeof ( *(phantom->desc) ) );
+ free_phys ( phantom->desc, sizeof ( *(phantom->desc) ) );
phantom->desc = NULL;
/* Flush any uncompleted descriptors */
@@ -1837,7 +1837,7 @@ static int phantom_map_crb ( struct phantom_nic *phantom,
return -EINVAL;
}
- phantom->bar0 = ioremap ( bar0_start, bar0_size );
+ phantom->bar0 = pci_ioremap ( pci, bar0_start, bar0_size );
if ( ! phantom->bar0 ) {
DBGC ( phantom, "Phantom %p could not map BAR0\n", phantom );
return -EIO;
diff --git a/src/drivers/net/prism2_pci.c b/src/drivers/net/prism2_pci.c
index 69ddf0fb0..2feb69522 100644
--- a/src/drivers/net/prism2_pci.c
+++ b/src/drivers/net/prism2_pci.c
@@ -36,7 +36,7 @@ static int prism2_pci_probe ( struct nic *nic, struct pci_device *pci ) {
hfa384x_t *hw = &hw_global;
printf ( "Prism2.5 has registers at %#lx\n", pci->membase );
- hw->membase = ioremap ( pci->membase, 0x100 );
+ hw->membase = pci_ioremap ( pci, pci->membase, 0x100 );
nic->ioaddr = pci->membase;
nic->irqno = 0;
diff --git a/src/drivers/net/realtek.c b/src/drivers/net/realtek.c
index 310b9f96a..0af3416d5 100644
--- a/src/drivers/net/realtek.c
+++ b/src/drivers/net/realtek.c
@@ -36,6 +36,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <ipxe/iobuf.h>
#include <ipxe/malloc.h>
#include <ipxe/pci.h>
+#include <ipxe/dma.h>
#include <ipxe/nvs.h>
#include <ipxe/threewire.h>
#include <ipxe/bitbash.h>
@@ -505,44 +506,27 @@ static void realtek_check_link ( struct net_device *netdev ) {
* @ret rc Return status code
*/
static int realtek_create_buffer ( struct realtek_nic *rtl ) {
+ struct realtek_rx_buffer *rxbuf = &rtl->rxbuf;
size_t len = ( RTL_RXBUF_LEN + RTL_RXBUF_PAD );
- physaddr_t address;
- int rc;
/* Do nothing unless in legacy mode */
if ( ! rtl->legacy )
return 0;
/* Allocate buffer */
- rtl->rx_buffer = malloc_dma ( len, RTL_RXBUF_ALIGN );
- if ( ! rtl->rx_buffer ) {
- rc = -ENOMEM;
- goto err_alloc;
- }
- address = virt_to_bus ( rtl->rx_buffer );
-
- /* Check that card can support address */
- if ( address & ~0xffffffffULL ) {
- DBGC ( rtl, "REALTEK %p cannot support 64-bit RX buffer "
- "address\n", rtl );
- rc = -ENOTSUP;
- goto err_64bit;
- }
+ rxbuf->data = dma_alloc ( rtl->dma, &rxbuf->map, len,
+ RTL_RXBUF_ALIGN );
+ if ( ! rxbuf->data )
+ return -ENOMEM;
/* Program buffer address */
- writel ( address, rtl->regs + RTL_RBSTART );
- DBGC ( rtl, "REALTEK %p receive buffer is at [%08llx,%08llx,%08llx)\n",
- rtl, ( ( unsigned long long ) address ),
- ( ( unsigned long long ) address + RTL_RXBUF_LEN ),
- ( ( unsigned long long ) address + len ) );
+ writel ( dma ( &rxbuf->map, rxbuf->data ), rtl->regs + RTL_RBSTART );
+ DBGC ( rtl, "REALTEK %p receive buffer is at [%08lx,%08lx,%08lx)\n",
+ rtl, virt_to_phys ( rxbuf->data ),
+ ( virt_to_phys ( rxbuf->data ) + RTL_RXBUF_LEN ),
+ ( virt_to_phys ( rxbuf->data ) + len ) );
return 0;
-
- err_64bit:
- free_dma ( rtl->rx_buffer, len );
- rtl->rx_buffer = NULL;
- err_alloc:
- return rc;
}
/**
@@ -551,6 +535,7 @@ static int realtek_create_buffer ( struct realtek_nic *rtl ) {
* @v rtl Realtek device
*/
static void realtek_destroy_buffer ( struct realtek_nic *rtl ) {
+ struct realtek_rx_buffer *rxbuf = &rtl->rxbuf;
size_t len = ( RTL_RXBUF_LEN + RTL_RXBUF_PAD );
/* Do nothing unless in legacy mode */
@@ -561,9 +546,9 @@ static void realtek_destroy_buffer ( struct realtek_nic *rtl ) {
writel ( 0, rtl->regs + RTL_RBSTART );
/* Free buffer */
- free_dma ( rtl->rx_buffer, len );
- rtl->rx_buffer = NULL;
- rtl->rx_offset = 0;
+ dma_free ( &rxbuf->map, rxbuf->data, len );
+ rxbuf->data = NULL;
+ rxbuf->offset = 0;
}
/**
@@ -582,7 +567,8 @@ static int realtek_create_ring ( struct realtek_nic *rtl,
return 0;
/* Allocate descriptor ring */
- ring->desc = malloc_dma ( ring->len, RTL_RING_ALIGN );
+ ring->desc = dma_alloc ( rtl->dma, &ring->map, ring->len,
+ RTL_RING_ALIGN );
if ( ! ring->desc )
return -ENOMEM;
@@ -590,13 +576,13 @@ static int realtek_create_ring ( struct realtek_nic *rtl,
memset ( ring->desc, 0, ring->len );
/* Program ring address */
- address = virt_to_bus ( ring->desc );
+ address = dma ( &ring->map, ring->desc );
writel ( ( ( ( uint64_t ) address ) >> 32 ),
rtl->regs + ring->reg + 4 );
writel ( ( address & 0xffffffffUL ), rtl->regs + ring->reg );
- DBGC ( rtl, "REALTEK %p ring %02x is at [%08llx,%08llx)\n",
- rtl, ring->reg, ( ( unsigned long long ) address ),
- ( ( unsigned long long ) address + ring->len ) );
+ DBGC ( rtl, "REALTEK %p ring %02x is at [%08lx,%08lx)\n",
+ rtl, ring->reg, virt_to_phys ( ring->desc ),
+ ( virt_to_phys ( ring->desc ) + ring->len ) );
return 0;
}
@@ -623,7 +609,7 @@ static void realtek_destroy_ring ( struct realtek_nic *rtl,
writel ( 0, rtl->regs + ring->reg + 4 );
/* Free descriptor ring */
- free_dma ( ring->desc, ring->len );
+ dma_free ( &ring->map, ring->desc, ring->len );
ring->desc = NULL;
}
@@ -636,7 +622,6 @@ static void realtek_refill_rx ( struct realtek_nic *rtl ) {
struct realtek_descriptor *rx;
struct io_buffer *iobuf;
unsigned int rx_idx;
- physaddr_t address;
int is_last;
/* Do nothing in legacy mode */
@@ -646,7 +631,7 @@ static void realtek_refill_rx ( struct realtek_nic *rtl ) {
while ( ( rtl->rx.prod - rtl->rx.cons ) < RTL_NUM_RX_DESC ) {
/* Allocate I/O buffer */
- iobuf = alloc_iob ( RTL_RX_MAX_LEN );
+ iobuf = alloc_rx_iob ( RTL_RX_MAX_LEN, rtl->dma );
if ( ! iobuf ) {
/* Wait for next refill */
return;
@@ -658,8 +643,7 @@ static void realtek_refill_rx ( struct realtek_nic *rtl ) {
rx = &rtl->rx.desc[rx_idx];
/* Populate receive descriptor */
- address = virt_to_bus ( iobuf->data );
- rx->address = cpu_to_le64 ( address );
+ rx->address = cpu_to_le64 ( iob_dma ( iobuf ) );
rx->length = cpu_to_le16 ( RTL_RX_MAX_LEN );
wmb();
rx->flags = ( cpu_to_le16 ( RTL_DESC_OWN ) |
@@ -670,9 +654,9 @@ static void realtek_refill_rx ( struct realtek_nic *rtl ) {
assert ( rtl->rx_iobuf[rx_idx] == NULL );
rtl->rx_iobuf[rx_idx] = iobuf;
- DBGC2 ( rtl, "REALTEK %p RX %d is [%llx,%llx)\n", rtl, rx_idx,
- ( ( unsigned long long ) address ),
- ( ( unsigned long long ) address + RTL_RX_MAX_LEN ) );
+ DBGC2 ( rtl, "REALTEK %p RX %d is [%lx,%lx)\n",
+ rtl, rx_idx, virt_to_phys ( iobuf->data ),
+ ( virt_to_phys ( iobuf->data ) + RTL_RX_MAX_LEN ) );
}
}
@@ -762,12 +746,16 @@ static void realtek_close ( struct net_device *netdev ) {
/* Discard any unused receive buffers */
for ( i = 0 ; i < RTL_NUM_RX_DESC ; i++ ) {
if ( rtl->rx_iobuf[i] )
- free_iob ( rtl->rx_iobuf[i] );
+ free_rx_iob ( rtl->rx_iobuf[i] );
rtl->rx_iobuf[i] = NULL;
}
/* Destroy transmit descriptor ring */
realtek_destroy_ring ( rtl, &rtl->tx );
+
+ /* Reset legacy transmit descriptor index, if applicable */
+ if ( rtl->legacy )
+ realtek_reset ( rtl );
}
/**
@@ -782,42 +770,41 @@ static int realtek_transmit ( struct net_device *netdev,
struct realtek_nic *rtl = netdev->priv;
struct realtek_descriptor *tx;
unsigned int tx_idx;
- physaddr_t address;
int is_last;
+ int rc;
/* Get next transmit descriptor */
if ( ( rtl->tx.prod - rtl->tx.cons ) >= RTL_NUM_TX_DESC ) {
netdev_tx_defer ( netdev, iobuf );
return 0;
}
- tx_idx = ( rtl->tx.prod++ % RTL_NUM_TX_DESC );
+ tx_idx = ( rtl->tx.prod % RTL_NUM_TX_DESC );
- /* Transmit packet */
- if ( rtl->legacy ) {
-
- /* Pad and align packet */
+ /* Pad and align packet, if needed */
+ if ( rtl->legacy )
iob_pad ( iobuf, ETH_ZLEN );
- address = virt_to_bus ( iobuf->data );
- /* Check that card can support address */
- if ( address & ~0xffffffffULL ) {
- DBGC ( rtl, "REALTEK %p cannot support 64-bit TX "
- "buffer address\n", rtl );
- return -ENOTSUP;
- }
+ /* Map I/O buffer */
+ if ( ( rc = iob_map_tx ( iobuf, rtl->dma ) ) != 0 )
+ return rc;
+
+ /* Update producer index */
+ rtl->tx.prod++;
+
+ /* Transmit packet */
+ if ( rtl->legacy ) {
/* Add to transmit ring */
- writel ( address, rtl->regs + RTL_TSAD ( tx_idx ) );
+ writel ( iob_dma ( iobuf ), rtl->regs + RTL_TSAD ( tx_idx ) );
writel ( ( RTL_TSD_ERTXTH_DEFAULT | iob_len ( iobuf ) ),
rtl->regs + RTL_TSD ( tx_idx ) );
} else {
/* Populate transmit descriptor */
- address = virt_to_bus ( iobuf->data );
is_last = ( tx_idx == ( RTL_NUM_TX_DESC - 1 ) );
tx = &rtl->tx.desc[tx_idx];
- tx->address = cpu_to_le64 ( address );
+ tx->address = cpu_to_le64 ( iob_dma ( iobuf ) );
tx->length = cpu_to_le16 ( iob_len ( iobuf ) );
wmb();
tx->flags = ( cpu_to_le16 ( RTL_DESC_OWN | RTL_DESC_FS |
@@ -829,10 +816,9 @@ static int realtek_transmit ( struct net_device *netdev,
writeb ( RTL_TPPOLL_NPQ, rtl->regs + rtl->tppoll );
}
- DBGC2 ( rtl, "REALTEK %p TX %d is [%llx,%llx)\n", rtl, tx_idx,
- ( ( unsigned long long ) virt_to_bus ( iobuf->data ) ),
- ( ( ( unsigned long long ) virt_to_bus ( iobuf->data ) ) +
- iob_len ( iobuf ) ) );
+ DBGC2 ( rtl, "REALTEK %p TX %d is [%lx,%lx)\n",
+ rtl, tx_idx, virt_to_phys ( iobuf->data ),
+ virt_to_phys ( iobuf->data ) + iob_len ( iobuf ) );
return 0;
}
@@ -892,12 +878,12 @@ static void realtek_legacy_poll_rx ( struct net_device *netdev ) {
while ( ! ( readb ( rtl->regs + RTL_CR ) & RTL_CR_BUFE ) ) {
/* Extract packet from receive buffer */
- rx = ( rtl->rx_buffer + rtl->rx_offset );
+ rx = ( rtl->rxbuf.data + rtl->rxbuf.offset );
len = le16_to_cpu ( rx->length );
if ( rx->status & cpu_to_le16 ( RTL_STAT_ROK ) ) {
DBGC2 ( rtl, "REALTEK %p RX offset %x+%zx\n",
- rtl, rtl->rx_offset, len );
+ rtl, rtl->rxbuf.offset, len );
/* Allocate I/O buffer */
iobuf = alloc_iob ( len );
@@ -917,16 +903,16 @@ static void realtek_legacy_poll_rx ( struct net_device *netdev ) {
} else {
DBGC ( rtl, "REALTEK %p RX offset %x+%zx error %04x\n",
- rtl, rtl->rx_offset, len,
+ rtl, rtl->rxbuf.offset, len,
le16_to_cpu ( rx->status ) );
netdev_rx_err ( netdev, NULL, -EIO );
}
/* Update buffer offset */
- rtl->rx_offset = ( rtl->rx_offset + sizeof ( *rx ) + len );
- rtl->rx_offset = ( ( rtl->rx_offset + 3 ) & ~3 );
- rtl->rx_offset = ( rtl->rx_offset % RTL_RXBUF_LEN );
- writew ( ( rtl->rx_offset - 16 ), rtl->regs + RTL_CAPR );
+ rtl->rxbuf.offset += ( sizeof ( *rx ) + len );
+ rtl->rxbuf.offset = ( ( rtl->rxbuf.offset + 3 ) & ~3 );
+ rtl->rxbuf.offset = ( rtl->rxbuf.offset % RTL_RXBUF_LEN );
+ writew ( ( rtl->rxbuf.offset - 16 ), rtl->regs + RTL_CAPR );
/* Give chip time to react before rechecking RTL_CR */
readw ( rtl->regs + RTL_CAPR );
@@ -1084,11 +1070,13 @@ static void realtek_detect ( struct realtek_nic *rtl ) {
DBGC ( rtl, "REALTEK %p appears to be an RTL8169\n", rtl );
rtl->have_phy_regs = 1;
rtl->tppoll = RTL_TPPOLL_8169;
+ dma_set_mask_64bit ( rtl->dma );
} else {
if ( ( check_cpcr == cpcr ) && ( cpcr != 0xffff ) ) {
DBGC ( rtl, "REALTEK %p appears to be an RTL8139C+\n",
rtl );
rtl->tppoll = RTL_TPPOLL_8139CP;
+ dma_set_mask_64bit ( rtl->dma );
} else {
DBGC ( rtl, "REALTEK %p appears to be an RTL8139\n",
rtl );
@@ -1128,12 +1116,15 @@ static int realtek_probe ( struct pci_device *pci ) {
adjust_pci_device ( pci );
/* Map registers */
- rtl->regs = ioremap ( pci->membase, RTL_BAR_SIZE );
+ rtl->regs = pci_ioremap ( pci, pci->membase, RTL_BAR_SIZE );
if ( ! rtl->regs ) {
rc = -ENODEV;
goto err_ioremap;
}
+ /* Configure DMA */
+ rtl->dma = &pci->dma;
+
/* Reset the NIC */
if ( ( rc = realtek_reset ( rtl ) ) != 0 )
goto err_reset;
diff --git a/src/drivers/net/realtek.h b/src/drivers/net/realtek.h
index 4d13784c4..d4642fd76 100644
--- a/src/drivers/net/realtek.h
+++ b/src/drivers/net/realtek.h
@@ -247,6 +247,8 @@ enum realtek_legacy_status {
struct realtek_ring {
/** Descriptors */
struct realtek_descriptor *desc;
+ /** Descriptor ring DMA mapping */
+ struct dma_mapping map;
/** Producer index */
unsigned int prod;
/** Consumer index */
@@ -272,10 +274,22 @@ realtek_init_ring ( struct realtek_ring *ring, unsigned int count,
ring->reg = reg;
}
+/** Receive buffer (legacy mode *) */
+struct realtek_rx_buffer {
+ /** Buffer */
+ void *data;
+ /** Buffer DMA mapping */
+ struct dma_mapping map;
+ /** Offset within buffer */
+ unsigned int offset;
+};
+
/** A Realtek network card */
struct realtek_nic {
/** Registers */
void *regs;
+ /** DMA device */
+ struct dma_device *dma;
/** SPI bit-bashing interface */
struct spi_bit_basher spibit;
/** EEPROM */
@@ -301,9 +315,7 @@ struct realtek_nic {
/** Receive I/O buffers */
struct io_buffer *rx_iobuf[RTL_NUM_RX_DESC];
/** Receive buffer (legacy mode) */
- void *rx_buffer;
- /** Offset within receive buffer (legacy mode) */
- unsigned int rx_offset;
+ struct realtek_rx_buffer rxbuf;
};
#endif /* _REALTEK_H */
diff --git a/src/drivers/net/rhine.c b/src/drivers/net/rhine.c
index a1dc58725..f4d3a2580 100644
--- a/src/drivers/net/rhine.c
+++ b/src/drivers/net/rhine.c
@@ -292,7 +292,7 @@ static int rhine_create_ring ( struct rhine_nic *rhn,
unsigned int i;
/* Allocate descriptors */
- ring->desc = malloc_dma ( len, RHINE_RING_ALIGN );
+ ring->desc = malloc_phys ( len, RHINE_RING_ALIGN );
if ( ! ring->desc )
return -ENOMEM;
@@ -328,7 +328,7 @@ static void rhine_destroy_ring ( struct rhine_nic *rhn,
writel ( 0, rhn->regs + ring->reg );
/* Free descriptor ring */
- free_dma ( ring->desc, len );
+ free_phys ( ring->desc, len );
ring->desc = NULL;
ring->prod = 0;
ring->cons = 0;
@@ -700,7 +700,7 @@ static int rhine_probe ( struct pci_device *pci ) {
adjust_pci_device ( pci );
/* Map registers */
- rhn->regs = ioremap ( pci->membase, RHINE_BAR_SIZE );
+ rhn->regs = pci_ioremap ( pci, pci->membase, RHINE_BAR_SIZE );
rhn->ioaddr = pci->ioaddr;
DBGC ( rhn, "RHINE %p regs at %08lx, I/O at %04lx\n", rhn,
pci->membase, pci->ioaddr );
diff --git a/src/drivers/net/rtl818x/rtl818x.c b/src/drivers/net/rtl818x/rtl818x.c
index f5082084e..599d36fad 100644
--- a/src/drivers/net/rtl818x/rtl818x.c
+++ b/src/drivers/net/rtl818x/rtl818x.c
@@ -328,8 +328,8 @@ static int rtl818x_init_rx_ring(struct net80211_device *dev)
struct rtl818x_rx_desc *entry;
int i;
- priv->rx_ring = malloc_dma(sizeof(*priv->rx_ring) * RTL818X_RX_RING_SIZE,
- RTL818X_RING_ALIGN);
+ priv->rx_ring = malloc_phys(sizeof(*priv->rx_ring) * RTL818X_RX_RING_SIZE,
+ RTL818X_RING_ALIGN);
priv->rx_ring_dma = virt_to_bus(priv->rx_ring);
if (!priv->rx_ring) {
DBG("rtl818x %s: cannot allocate RX ring\n", dev->netdev->name);
@@ -364,7 +364,7 @@ static void rtl818x_free_rx_ring(struct net80211_device *dev)
priv->rx_buf[i] = NULL;
}
- free_dma(priv->rx_ring, sizeof(*priv->rx_ring) * RTL818X_RX_RING_SIZE);
+ free_phys(priv->rx_ring, sizeof(*priv->rx_ring) * RTL818X_RX_RING_SIZE);
priv->rx_ring = NULL;
}
@@ -373,8 +373,8 @@ static int rtl818x_init_tx_ring(struct net80211_device *dev)
struct rtl818x_priv *priv = dev->priv;
int i;
- priv->tx_ring = malloc_dma(sizeof(*priv->tx_ring) * RTL818X_TX_RING_SIZE,
- RTL818X_RING_ALIGN);
+ priv->tx_ring = malloc_phys(sizeof(*priv->tx_ring) * RTL818X_TX_RING_SIZE,
+ RTL818X_RING_ALIGN);
priv->tx_ring_dma = virt_to_bus(priv->tx_ring);
if (!priv->tx_ring) {
DBG("rtl818x %s: cannot allocate TX ring\n", dev->netdev->name);
@@ -402,7 +402,7 @@ static void rtl818x_free_tx_ring(struct net80211_device *dev)
priv->tx_buf[i] = NULL;
}
- free_dma(priv->tx_ring, sizeof(*priv->tx_ring) * RTL818X_TX_RING_SIZE);
+ free_phys(priv->tx_ring, sizeof(*priv->tx_ring) * RTL818X_TX_RING_SIZE);
priv->tx_ring = NULL;
}
diff --git a/src/drivers/net/sfc/efx_common.c b/src/drivers/net/sfc/efx_common.c
index 403887707..ad572b1da 100644
--- a/src/drivers/net/sfc/efx_common.c
+++ b/src/drivers/net/sfc/efx_common.c
@@ -2,11 +2,12 @@
*
* Driver datapath common code for Solarflare network cards
*
- * Written by Shradha Shah <sshah@solarflare.com>
+ * Written by Shradha Shah, maintained by <pre-boot-drivers@xilinx.com>
*
* Copyright Fen Systems Ltd. 2005
* Copyright Level 5 Networks Inc. 2005
- * Copyright 2006-2017 Solarflare Communications Inc.
+ * Copyright 2006-2019 Solarflare Communications Inc.
+ * Copyright 2019-2020 Xilinx Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -85,7 +86,7 @@ void efx_probe(struct net_device *netdev, enum efx_revision revision)
efx->mmio_start = pci_bar_start(pci, reg);
efx->mmio_len = pci_bar_size(pci, reg);
- efx->membase = ioremap(efx->mmio_start, efx->mmio_len);
+ efx->membase = pci_ioremap(pci, efx->mmio_start, efx->mmio_len);
DBGCP(efx, "BAR of %lx bytes at phys %lx mapped at %p\n",
efx->mmio_len, efx->mmio_start, efx->membase);
diff --git a/src/drivers/net/sfc/efx_hunt.c b/src/drivers/net/sfc/efx_hunt.c
index 07dd7dfea..0bce3e45a 100644
--- a/src/drivers/net/sfc/efx_hunt.c
+++ b/src/drivers/net/sfc/efx_hunt.c
@@ -2,9 +2,10 @@
*
* Driver datapath for Solarflare network cards
*
- * Written by Shradha Shah <sshah@solarflare.com>
+ * Written by Shradha Shah, maintained by <pre-boot-drivers@xilinx.com>
*
- * Copyright 2012-2017 Solarflare Communications Inc.
+ * Copyright 2012-2019 Solarflare Communications Inc.
+ * Copyright 2019-2020 Xilinx Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -37,7 +38,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
void efx_hunt_free_special_buffer(void *buf, int bytes)
{
- free_dma(buf, bytes);
+ free_phys(buf, bytes);
}
static void *efx_hunt_alloc_special_buffer(int bytes,
@@ -50,7 +51,7 @@ static void *efx_hunt_alloc_special_buffer(int bytes,
* buffer will be passed into an MC_CMD_INIT_*Q command to setup the
* appropriate type of queue via MCDI.
*/
- buffer = malloc_dma(bytes, EFX_BUF_ALIGN);
+ buffer = malloc_phys(bytes, EFX_BUF_ALIGN);
if (!buffer)
return NULL;
diff --git a/src/drivers/net/sfc/efx_hunt.h b/src/drivers/net/sfc/efx_hunt.h
index b8377bf20..d6bb4659f 100644
--- a/src/drivers/net/sfc/efx_hunt.h
+++ b/src/drivers/net/sfc/efx_hunt.h
@@ -2,9 +2,10 @@
*
* GPL net driver for Solarflare network cards
*
- * Written by Shradha Shah <sshah@solarflare.com>
+ * Written by Shradha Shah, maintained by <pre-boot-drivers@xilinx.com>
*
- * Copyright 2012-2017 Solarflare Communications Inc.
+ * Copyright 2012-2019 Solarflare Communications Inc.
+ * Copyright 2019-2020 Xilinx Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
diff --git a/src/drivers/net/sfc/mcdi.h b/src/drivers/net/sfc/mcdi.h
index 19c62021a..2d26cded3 100644
--- a/src/drivers/net/sfc/mcdi.h
+++ b/src/drivers/net/sfc/mcdi.h
@@ -1,9 +1,11 @@
/****************************************************************************
* Driver for Solarflare network controllers and boards
*
- * Written by Martin Habets <mhabets@solarflare.com>
+ * Written by Martin Habets <habetsm.xilinx@gmail.com>, maintained
+ * by <pre-boot-drivers@xilinx.com>
*
- * Copyright 2012-2017 Solarflare Communications Inc.
+ * Copyright 2012-2019 Solarflare Communications Inc.
+ * Copyright 2019-2020 Xilinx Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
diff --git a/src/drivers/net/sfc/sfc_hunt.c b/src/drivers/net/sfc/sfc_hunt.c
index 3c9a5fe38..a37670ae2 100644
--- a/src/drivers/net/sfc/sfc_hunt.c
+++ b/src/drivers/net/sfc/sfc_hunt.c
@@ -2,9 +2,10 @@
*
* Device driver for Solarflare Communications EF10 devices
*
- * Written by Shradha Shah <sshah@solarflare.com>
+ * Written by Shradha Shah, maintained by <pre-boot-drivers@xilinx.com>
*
- * Copyright 2012-2017 Solarflare Communications Inc.
+ * Copyright 2012-2019 Solarflare Communications Inc.
+ * Copyright 2019-2020 Xilinx Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
diff --git a/src/drivers/net/sis190.c b/src/drivers/net/sis190.c
index b92e95f2a..0e4f0762e 100644
--- a/src/drivers/net/sis190.c
+++ b/src/drivers/net/sis190.c
@@ -552,7 +552,7 @@ static int sis190_open(struct net_device *dev)
int rc;
/* Allocate TX ring */
- tp->TxDescRing = malloc_dma(TX_RING_BYTES, RING_ALIGNMENT);
+ tp->TxDescRing = malloc_phys(TX_RING_BYTES, RING_ALIGNMENT);
if (!tp->TxDescRing) {
DBG("sis190: TX ring allocation failed\n");
rc = -ENOMEM;
@@ -561,7 +561,7 @@ static int sis190_open(struct net_device *dev)
tp->tx_dma = cpu_to_le32(virt_to_bus(tp->TxDescRing));
/* Allocate RX ring */
- tp->RxDescRing = malloc_dma(RX_RING_BYTES, RING_ALIGNMENT);
+ tp->RxDescRing = malloc_phys(RX_RING_BYTES, RING_ALIGNMENT);
if (!tp->RxDescRing) {
DBG("sis190: RX ring allocation failed\n");
rc = -ENOMEM;
@@ -600,8 +600,8 @@ static void sis190_free(struct net_device *dev)
struct sis190_private *tp = netdev_priv(dev);
int i;
- free_dma(tp->TxDescRing, TX_RING_BYTES);
- free_dma(tp->RxDescRing, RX_RING_BYTES);
+ free_phys(tp->TxDescRing, TX_RING_BYTES);
+ free_phys(tp->RxDescRing, RX_RING_BYTES);
tp->TxDescRing = NULL;
tp->RxDescRing = NULL;
@@ -886,7 +886,7 @@ static int sis190_init_board(struct pci_device *pdev, struct net_device **netdev
adjust_pci_device(pdev);
- ioaddr = ioremap(pdev->membase, SIS190_REGS_SIZE);
+ ioaddr = pci_ioremap(pdev, pdev->membase, SIS190_REGS_SIZE);
if (!ioaddr) {
DBG("sis190: cannot remap MMIO, aborting\n");
rc = -EIO;
diff --git a/src/drivers/net/skeleton.c b/src/drivers/net/skeleton.c
index 0bae3089c..a76c6e3d9 100644
--- a/src/drivers/net/skeleton.c
+++ b/src/drivers/net/skeleton.c
@@ -195,7 +195,7 @@ static int skeleton_probe ( struct pci_device *pci ) {
adjust_pci_device ( pci );
/* Map registers */
- skel->regs = ioremap ( pci->membase, SKELETON_BAR_SIZE );
+ skel->regs = pci_ioremap ( pci, pci->membase, SKELETON_BAR_SIZE );
if ( ! skel->regs ) {
rc = -ENODEV;
goto err_ioremap;
diff --git a/src/drivers/net/skge.c b/src/drivers/net/skge.c
index c3264225b..5aa5e2a6a 100755
--- a/src/drivers/net/skge.c
+++ b/src/drivers/net/skge.c
@@ -1699,7 +1699,7 @@ void skge_free(struct net_device *dev)
free(skge->tx_ring.start);
skge->tx_ring.start = NULL;
- free_dma(skge->mem, RING_SIZE);
+ free_phys(skge->mem, RING_SIZE);
skge->mem = NULL;
skge->dma = 0;
}
@@ -1714,7 +1714,7 @@ static int skge_up(struct net_device *dev)
DBG2(PFX "%s: enabling interface\n", dev->name);
- skge->mem = malloc_dma(RING_SIZE, SKGE_RING_ALIGN);
+ skge->mem = malloc_phys(RING_SIZE, SKGE_RING_ALIGN);
skge->dma = virt_to_bus(skge->mem);
if (!skge->mem)
return -ENOMEM;
@@ -2346,8 +2346,9 @@ static int skge_probe(struct pci_device *pdev)
hw->pdev = pdev;
- hw->regs = (unsigned long)ioremap(pci_bar_start(pdev, PCI_BASE_ADDRESS_0),
- SKGE_REG_SIZE);
+ hw->regs = (unsigned long)pci_ioremap(pdev,
+ pci_bar_start(pdev, PCI_BASE_ADDRESS_0),
+ SKGE_REG_SIZE);
if (!hw->regs) {
DBG(PFX "cannot map device registers\n");
goto err_out_free_hw;
diff --git a/src/drivers/net/sky2.c b/src/drivers/net/sky2.c
index 211f22466..9d612c997 100644
--- a/src/drivers/net/sky2.c
+++ b/src/drivers/net/sky2.c
@@ -1112,10 +1112,10 @@ nomem:
/* Free the le and ring buffers */
static void sky2_free_rings(struct sky2_port *sky2)
{
- free_dma(sky2->rx_le, RX_LE_BYTES);
+ free_phys(sky2->rx_le, RX_LE_BYTES);
free(sky2->rx_ring);
- free_dma(sky2->tx_le, TX_RING_SIZE * sizeof(struct sky2_tx_le));
+ free_phys(sky2->tx_le, TX_RING_SIZE * sizeof(struct sky2_tx_le));
free(sky2->tx_ring);
sky2->tx_le = NULL;
@@ -1137,7 +1137,7 @@ static int sky2_up(struct net_device *dev)
netdev_link_down(dev);
/* must be power of 2 */
- sky2->tx_le = malloc_dma(TX_RING_SIZE * sizeof(struct sky2_tx_le), TX_RING_ALIGN);
+ sky2->tx_le = malloc_phys(TX_RING_SIZE * sizeof(struct sky2_tx_le), TX_RING_ALIGN);
sky2->tx_le_map = virt_to_bus(sky2->tx_le);
if (!sky2->tx_le)
goto err_out;
@@ -1149,7 +1149,7 @@ static int sky2_up(struct net_device *dev)
tx_init(sky2);
- sky2->rx_le = malloc_dma(RX_LE_BYTES, RX_RING_ALIGN);
+ sky2->rx_le = malloc_phys(RX_LE_BYTES, RX_RING_ALIGN);
sky2->rx_le_map = virt_to_bus(sky2->rx_le);
if (!sky2->rx_le)
goto err_out;
@@ -2278,14 +2278,14 @@ static int sky2_probe(struct pci_device *pdev)
hw->pdev = pdev;
- hw->regs = (unsigned long)ioremap(pci_bar_start(pdev, PCI_BASE_ADDRESS_0), 0x4000);
+ hw->regs = (unsigned long)pci_ioremap(pdev, pci_bar_start(pdev, PCI_BASE_ADDRESS_0), 0x4000);
if (!hw->regs) {
DBG(PFX "cannot map device registers\n");
goto err_out_free_hw;
}
/* ring for status responses */
- hw->st_le = malloc_dma(STATUS_LE_BYTES, STATUS_RING_ALIGN);
+ hw->st_le = malloc_phys(STATUS_LE_BYTES, STATUS_RING_ALIGN);
if (!hw->st_le)
goto err_out_iounmap;
hw->st_dma = virt_to_bus(hw->st_le);
@@ -2344,7 +2344,7 @@ err_out_free_netdev:
netdev_put(dev);
err_out_free_pci:
sky2_write8(hw, B0_CTST, CS_RST_SET);
- free_dma(hw->st_le, STATUS_LE_BYTES);
+ free_phys(hw->st_le, STATUS_LE_BYTES);
err_out_iounmap:
iounmap((void *)hw->regs);
err_out_free_hw:
@@ -2373,7 +2373,7 @@ static void sky2_remove(struct pci_device *pdev)
sky2_write8(hw, B0_CTST, CS_RST_SET);
sky2_read8(hw, B0_CTST);
- free_dma(hw->st_le, STATUS_LE_BYTES);
+ free_phys(hw->st_le, STATUS_LE_BYTES);
for (i = hw->ports-1; i >= 0; --i) {
netdev_nullify(hw->dev[i]);
diff --git a/src/drivers/net/tg3/tg3.c b/src/drivers/net/tg3/tg3.c
index 1bed06649..cec599c1c 100644
--- a/src/drivers/net/tg3/tg3.c
+++ b/src/drivers/net/tg3/tg3.c
@@ -42,7 +42,7 @@ void tg3_rx_prodring_fini(struct tg3_rx_prodring_set *tpr)
{ DBGP("%s\n", __func__);
if (tpr->rx_std) {
- free_dma(tpr->rx_std, TG3_RX_STD_RING_BYTES(tp));
+ free_phys(tpr->rx_std, TG3_RX_STD_RING_BYTES(tp));
tpr->rx_std = NULL;
}
}
@@ -55,7 +55,7 @@ static void tg3_free_consistent(struct tg3 *tp)
{ DBGP("%s\n", __func__);
if (tp->tx_ring) {
- free_dma(tp->tx_ring, TG3_TX_RING_BYTES);
+ free_phys(tp->tx_ring, TG3_TX_RING_BYTES);
tp->tx_ring = NULL;
}
@@ -63,7 +63,7 @@ static void tg3_free_consistent(struct tg3 *tp)
tp->tx_buffers = NULL;
if (tp->rx_rcb) {
- free_dma(tp->rx_rcb, TG3_RX_RCB_RING_BYTES(tp));
+ free_phys(tp->rx_rcb, TG3_RX_RCB_RING_BYTES(tp));
tp->rx_rcb_mapping = 0;
tp->rx_rcb = NULL;
}
@@ -71,7 +71,7 @@ static void tg3_free_consistent(struct tg3 *tp)
tg3_rx_prodring_fini(&tp->prodring);
if (tp->hw_status) {
- free_dma(tp->hw_status, TG3_HW_STATUS_SIZE);
+ free_phys(tp->hw_status, TG3_HW_STATUS_SIZE);
tp->status_mapping = 0;
tp->hw_status = NULL;
}
@@ -87,7 +87,7 @@ int tg3_alloc_consistent(struct tg3 *tp)
struct tg3_hw_status *sblk;
struct tg3_rx_prodring_set *tpr = &tp->prodring;
- tp->hw_status = malloc_dma(TG3_HW_STATUS_SIZE, TG3_DMA_ALIGNMENT);
+ tp->hw_status = malloc_phys(TG3_HW_STATUS_SIZE, TG3_DMA_ALIGNMENT);
if (!tp->hw_status) {
DBGC(tp->dev, "hw_status alloc failed\n");
goto err_out;
@@ -97,7 +97,7 @@ int tg3_alloc_consistent(struct tg3 *tp)
memset(tp->hw_status, 0, TG3_HW_STATUS_SIZE);
sblk = tp->hw_status;
- tpr->rx_std = malloc_dma(TG3_RX_STD_RING_BYTES(tp), TG3_DMA_ALIGNMENT);
+ tpr->rx_std = malloc_phys(TG3_RX_STD_RING_BYTES(tp), TG3_DMA_ALIGNMENT);
if (!tpr->rx_std) {
DBGC(tp->dev, "rx prodring alloc failed\n");
goto err_out;
@@ -109,7 +109,7 @@ int tg3_alloc_consistent(struct tg3 *tp)
if (!tp->tx_buffers)
goto err_out;
- tp->tx_ring = malloc_dma(TG3_TX_RING_BYTES, TG3_DMA_ALIGNMENT);
+ tp->tx_ring = malloc_phys(TG3_TX_RING_BYTES, TG3_DMA_ALIGNMENT);
if (!tp->tx_ring)
goto err_out;
tp->tx_desc_mapping = virt_to_bus(tp->tx_ring);
@@ -123,7 +123,7 @@ int tg3_alloc_consistent(struct tg3 *tp)
tp->rx_rcb_prod_idx = &sblk->idx[0].rx_producer;
- tp->rx_rcb = malloc_dma(TG3_RX_RCB_RING_BYTES(tp), TG3_DMA_ALIGNMENT);
+ tp->rx_rcb = malloc_phys(TG3_RX_RCB_RING_BYTES(tp), TG3_DMA_ALIGNMENT);
if (!tp->rx_rcb)
goto err_out;
tp->rx_rcb_mapping = virt_to_bus(tp->rx_rcb);
@@ -541,7 +541,7 @@ static int tg3_test_dma(struct tg3 *tp)
u32 *buf;
int ret = 0;
- buf = malloc_dma(TEST_BUFFER_SIZE, TG3_DMA_ALIGNMENT);
+ buf = malloc_phys(TEST_BUFFER_SIZE, TG3_DMA_ALIGNMENT);
if (!buf) {
ret = -ENOMEM;
goto out_nofree;
@@ -708,7 +708,7 @@ static int tg3_test_dma(struct tg3 *tp)
}
out:
- free_dma(buf, TEST_BUFFER_SIZE);
+ free_phys(buf, TEST_BUFFER_SIZE);
out_nofree:
return ret;
}
@@ -771,7 +771,7 @@ static int tg3_init_one(struct pci_device *pdev)
reg_base = pci_bar_start(pdev, PCI_BASE_ADDRESS_0);
reg_size = pci_bar_size(pdev, PCI_BASE_ADDRESS_0);
- tp->regs = ioremap(reg_base, reg_size);
+ tp->regs = pci_ioremap(pdev, reg_base, reg_size);
if (!tp->regs) {
DBGC(&pdev->dev, "Failed to remap device registers\n");
errno = -ENOENT;
diff --git a/src/drivers/net/thunderx.c b/src/drivers/net/thunderx.c
index 9ddb98ab8..1865a9b91 100644
--- a/src/drivers/net/thunderx.c
+++ b/src/drivers/net/thunderx.c
@@ -645,11 +645,11 @@ static void txnic_poll ( struct txnic *vnic ) {
/**
* Allocate virtual NIC
*
- * @v dev Underlying device
+ * @v pci Underlying PCI device
* @v membase Register base address
* @ret vnic Virtual NIC, or NULL on failure
*/
-static struct txnic * txnic_alloc ( struct device *dev,
+static struct txnic * txnic_alloc ( struct pci_device *pci,
unsigned long membase ) {
struct net_device *netdev;
struct txnic *vnic;
@@ -658,10 +658,10 @@ static struct txnic * txnic_alloc ( struct device *dev,
netdev = alloc_etherdev ( sizeof ( *vnic ) );
if ( ! netdev )
goto err_alloc_netdev;
- netdev->dev = dev;
+ netdev->dev = &pci->dev;
vnic = netdev->priv;
vnic->netdev = netdev;
- vnic->name = dev->name;
+ vnic->name = pci->dev.name;
/* Allow caller to reuse netdev->priv. (The generic virtual
* NIC code never assumes that netdev->priv==vnic.)
@@ -684,7 +684,7 @@ static struct txnic * txnic_alloc ( struct device *dev,
goto err_alloc_rq;
/* Map registers */
- vnic->regs = ioremap ( membase, TXNIC_VF_BAR_SIZE );
+ vnic->regs = pci_ioremap ( pci, membase, TXNIC_VF_BAR_SIZE );
if ( ! vnic->regs )
goto err_ioremap;
@@ -1103,7 +1103,7 @@ static int txnic_lmac_probe ( struct txnic_lmac *lmac ) {
membase = ( pf->vf_membase + ( lmac->idx * pf->vf_stride ) );
/* Allocate and initialise network device */
- vnic = txnic_alloc ( &bgx->pci->dev, membase );
+ vnic = txnic_alloc ( bgx->pci, membase );
if ( ! vnic ) {
rc = -ENOMEM;
goto err_alloc;
@@ -1275,7 +1275,7 @@ static int txnic_pf_probe ( struct pci_device *pci ) {
adjust_pci_device ( pci );
/* Map registers */
- pf->regs = ioremap ( membase, TXNIC_PF_BAR_SIZE );
+ pf->regs = pci_ioremap ( pci, membase, TXNIC_PF_BAR_SIZE );
if ( ! pf->regs ) {
rc = -ENODEV;
goto err_ioremap;
@@ -1633,7 +1633,7 @@ static int txnic_bgx_probe ( struct pci_device *pci ) {
adjust_pci_device ( pci );
/* Map registers */
- bgx->regs = ioremap ( membase, TXNIC_BGX_BAR_SIZE );
+ bgx->regs = pci_ioremap ( pci, membase, TXNIC_BGX_BAR_SIZE );
if ( ! bgx->regs ) {
rc = -ENODEV;
goto err_ioremap;
diff --git a/src/drivers/net/velocity.c b/src/drivers/net/velocity.c
index 0a2a3ac10..373714293 100644
--- a/src/drivers/net/velocity.c
+++ b/src/drivers/net/velocity.c
@@ -320,7 +320,8 @@ static int velocity_alloc_rings ( struct velocity_nic *vlc ) {
vlc->rx_prod = 0;
vlc->rx_cons = 0;
vlc->rx_commit = 0;
- vlc->rx_ring = malloc_dma ( VELOCITY_RXDESC_SIZE, VELOCITY_RING_ALIGN );
+ vlc->rx_ring = malloc_phys ( VELOCITY_RXDESC_SIZE,
+ VELOCITY_RING_ALIGN );
if ( ! vlc->rx_ring )
return -ENOMEM;
@@ -332,7 +333,8 @@ static int velocity_alloc_rings ( struct velocity_nic *vlc ) {
/* Allocate TX descriptor ring */
vlc->tx_prod = 0;
vlc->tx_cons = 0;
- vlc->tx_ring = malloc_dma ( VELOCITY_TXDESC_SIZE, VELOCITY_RING_ALIGN );
+ vlc->tx_ring = malloc_phys ( VELOCITY_TXDESC_SIZE,
+ VELOCITY_RING_ALIGN );
if ( ! vlc->tx_ring ) {
rc = -ENOMEM;
goto err_tx_alloc;
@@ -356,7 +358,7 @@ static int velocity_alloc_rings ( struct velocity_nic *vlc ) {
return 0;
err_tx_alloc:
- free_dma ( vlc->rx_ring, VELOCITY_RXDESC_SIZE );
+ free_phys ( vlc->rx_ring, VELOCITY_RXDESC_SIZE );
return rc;
}
@@ -482,7 +484,7 @@ static void velocity_close ( struct net_device *netdev ) {
writew ( 0, vlc->regs + VELOCITY_RXDESCNUM );
/* Destroy RX ring */
- free_dma ( vlc->rx_ring, VELOCITY_RXDESC_SIZE );
+ free_phys ( vlc->rx_ring, VELOCITY_RXDESC_SIZE );
vlc->rx_ring = NULL;
vlc->rx_prod = 0;
vlc->rx_cons = 0;
@@ -499,7 +501,7 @@ static void velocity_close ( struct net_device *netdev ) {
writew ( 0, vlc->regs + VELOCITY_TXDESCNUM );
/* Destroy TX ring */
- free_dma ( vlc->tx_ring, VELOCITY_TXDESC_SIZE );
+ free_phys ( vlc->tx_ring, VELOCITY_TXDESC_SIZE );
vlc->tx_ring = NULL;
vlc->tx_prod = 0;
vlc->tx_cons = 0;
@@ -731,7 +733,7 @@ static int velocity_probe ( struct pci_device *pci ) {
adjust_pci_device ( pci );
/* Map registers */
- vlc->regs = ioremap ( pci->membase, VELOCITY_BAR_SIZE );
+ vlc->regs = pci_ioremap ( pci, pci->membase, VELOCITY_BAR_SIZE );
vlc->netdev = netdev;
/* Reset the NIC */
diff --git a/src/drivers/net/vmxnet3.c b/src/drivers/net/vmxnet3.c
index 6a54dbf89..63bcf0e01 100644
--- a/src/drivers/net/vmxnet3.c
+++ b/src/drivers/net/vmxnet3.c
@@ -465,7 +465,8 @@ static int vmxnet3_open ( struct net_device *netdev ) {
int rc;
/* Allocate DMA areas */
- vmxnet->dma = malloc_dma ( sizeof ( *vmxnet->dma ), VMXNET3_DMA_ALIGN );
+ vmxnet->dma = malloc_phys ( sizeof ( *vmxnet->dma ),
+ VMXNET3_DMA_ALIGN );
if ( ! vmxnet->dma ) {
DBGC ( vmxnet, "VMXNET3 %p could not allocate DMA area\n",
vmxnet );
@@ -542,7 +543,7 @@ static int vmxnet3_open ( struct net_device *netdev ) {
err_activate:
vmxnet3_flush_tx ( netdev );
vmxnet3_flush_rx ( netdev );
- free_dma ( vmxnet->dma, sizeof ( *vmxnet->dma ) );
+ free_phys ( vmxnet->dma, sizeof ( *vmxnet->dma ) );
err_alloc_dma:
return rc;
}
@@ -559,7 +560,7 @@ static void vmxnet3_close ( struct net_device *netdev ) {
vmxnet3_command ( vmxnet, VMXNET3_CMD_RESET_DEV );
vmxnet3_flush_tx ( netdev );
vmxnet3_flush_rx ( netdev );
- free_dma ( vmxnet->dma, sizeof ( *vmxnet->dma ) );
+ free_phys ( vmxnet->dma, sizeof ( *vmxnet->dma ) );
}
/** vmxnet3 net device operations */
@@ -641,14 +642,14 @@ static int vmxnet3_probe ( struct pci_device *pci ) {
adjust_pci_device ( pci );
/* Map PCI BARs */
- vmxnet->pt = ioremap ( pci_bar_start ( pci, VMXNET3_PT_BAR ),
- VMXNET3_PT_LEN );
+ vmxnet->pt = pci_ioremap ( pci, pci_bar_start ( pci, VMXNET3_PT_BAR ),
+ VMXNET3_PT_LEN );
if ( ! vmxnet->pt ) {
rc = -ENODEV;
goto err_ioremap_pt;
}
- vmxnet->vd = ioremap ( pci_bar_start ( pci, VMXNET3_VD_BAR ),
- VMXNET3_VD_LEN );
+ vmxnet->vd = pci_ioremap ( pci, pci_bar_start ( pci, VMXNET3_VD_BAR ),
+ VMXNET3_VD_LEN );
if ( ! vmxnet->vd ) {
rc = -ENODEV;
goto err_ioremap_vd;
diff --git a/src/drivers/net/vxge/vxge_config.c b/src/drivers/net/vxge/vxge_config.c
index ba62b508e..f4d217097 100644
--- a/src/drivers/net/vxge/vxge_config.c
+++ b/src/drivers/net/vxge/vxge_config.c
@@ -624,10 +624,10 @@ __vxge_hw_ring_create(struct __vxge_hw_virtualpath *vpath,
hldev = vpath->hldev;
vp_id = vpath->vp_id;
- ring->rxdl = malloc_dma(sizeof(struct __vxge_hw_ring_block),
+ ring->rxdl = malloc_phys(sizeof(struct __vxge_hw_ring_block),
sizeof(struct __vxge_hw_ring_block));
if (!ring->rxdl) {
- vxge_debug(VXGE_ERR, "%s:%d malloc_dma error\n",
+ vxge_debug(VXGE_ERR, "%s:%d malloc_phys error\n",
__func__, __LINE__);
status = VXGE_HW_ERR_OUT_OF_MEMORY;
goto exit;
@@ -667,7 +667,7 @@ enum vxge_hw_status __vxge_hw_ring_delete(struct __vxge_hw_ring *ring)
}
if (ring->rxdl) {
- free_dma(ring->rxdl, sizeof(struct __vxge_hw_ring_block));
+ free_phys(ring->rxdl, sizeof(struct __vxge_hw_ring_block));
ring->rxdl = NULL;
}
ring->rxd_offset = 0;
@@ -826,10 +826,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_virtualpath *vpath,
fifo->tx_intr_num = (vpath->vp_id * VXGE_HW_MAX_INTR_PER_VP)
+ VXGE_HW_VPATH_INTR_TX;
- fifo->txdl = malloc_dma(sizeof(struct vxge_hw_fifo_txd)
+ fifo->txdl = malloc_phys(sizeof(struct vxge_hw_fifo_txd)
* fifo->depth, fifo->depth);
if (!fifo->txdl) {
- vxge_debug(VXGE_ERR, "%s:%d malloc_dma error\n",
+ vxge_debug(VXGE_ERR, "%s:%d malloc_phys error\n",
__func__, __LINE__);
return VXGE_HW_ERR_OUT_OF_MEMORY;
}
@@ -846,7 +846,7 @@ enum vxge_hw_status __vxge_hw_fifo_delete(struct __vxge_hw_fifo *fifo)
vxge_trace();
if (fifo->txdl)
- free_dma(fifo->txdl,
+ free_phys(fifo->txdl,
sizeof(struct vxge_hw_fifo_txd) * fifo->depth);
fifo->txdl = NULL;
diff --git a/src/drivers/net/vxge/vxge_main.c b/src/drivers/net/vxge/vxge_main.c
index 8b099c0e2..631928318 100644
--- a/src/drivers/net/vxge/vxge_main.c
+++ b/src/drivers/net/vxge/vxge_main.c
@@ -520,7 +520,7 @@ vxge_probe(struct pci_device *pdev)
/* sets the bus master */
adjust_pci_device(pdev);
- bar0 = ioremap(mmio_start, mmio_len);
+ bar0 = pci_ioremap(pdev, mmio_start, mmio_len);
if (!bar0) {
vxge_debug(VXGE_ERR,
"%s : cannot remap io memory bar0\n", __func__);
diff --git a/src/drivers/usb/ehci.c b/src/drivers/usb/ehci.c
index 29c32b356..77022a47d 100644
--- a/src/drivers/usb/ehci.c
+++ b/src/drivers/usb/ehci.c
@@ -565,8 +565,8 @@ static int ehci_ring_alloc ( struct ehci_device *ehci,
}
/* Allocate queue head */
- ring->head = malloc_dma ( sizeof ( *ring->head ),
- ehci_align ( sizeof ( *ring->head ) ) );
+ ring->head = malloc_phys ( sizeof ( *ring->head ),
+ ehci_align ( sizeof ( *ring->head ) ) );
if ( ! ring->head ) {
rc = -ENOMEM;
goto err_alloc_queue;
@@ -579,7 +579,7 @@ static int ehci_ring_alloc ( struct ehci_device *ehci,
/* Allocate transfer descriptors */
len = ( EHCI_RING_COUNT * sizeof ( ring->desc[0] ) );
- ring->desc = malloc_dma ( len, sizeof ( ring->desc[0] ) );
+ ring->desc = malloc_phys ( len, sizeof ( ring->desc[0] ) );
if ( ! ring->desc ) {
rc = -ENOMEM;
goto err_alloc_desc;
@@ -607,10 +607,10 @@ static int ehci_ring_alloc ( struct ehci_device *ehci,
return 0;
err_unreachable_desc:
- free_dma ( ring->desc, len );
+ free_phys ( ring->desc, len );
err_alloc_desc:
err_unreachable_queue:
- free_dma ( ring->head, sizeof ( *ring->head ) );
+ free_phys ( ring->head, sizeof ( *ring->head ) );
err_alloc_queue:
free ( ring->iobuf );
err_alloc_iobuf:
@@ -631,10 +631,11 @@ static void ehci_ring_free ( struct ehci_ring *ring ) {
assert ( ring->iobuf[i] == NULL );
/* Free transfer descriptors */
- free_dma ( ring->desc, ( EHCI_RING_COUNT * sizeof ( ring->desc[0] ) ) );
+ free_phys ( ring->desc, ( EHCI_RING_COUNT *
+ sizeof ( ring->desc[0] ) ) );
/* Free queue head */
- free_dma ( ring->head, sizeof ( *ring->head ) );
+ free_phys ( ring->head, sizeof ( *ring->head ) );
/* Free I/O buffers */
free ( ring->iobuf );
@@ -1787,8 +1788,8 @@ static int ehci_bus_open ( struct usb_bus *bus ) {
assert ( list_empty ( &ehci->periodic ) );
/* Allocate and initialise asynchronous queue head */
- ehci->head = malloc_dma ( sizeof ( *ehci->head ),
- ehci_align ( sizeof ( *ehci->head ) ) );
+ ehci->head = malloc_phys ( sizeof ( *ehci->head ),
+ ehci_align ( sizeof ( *ehci->head ) ) );
if ( ! ehci->head ) {
rc = -ENOMEM;
goto err_alloc_head;
@@ -1816,7 +1817,7 @@ static int ehci_bus_open ( struct usb_bus *bus ) {
/* Allocate periodic frame list */
frames = EHCI_PERIODIC_FRAMES ( ehci->flsize );
len = ( frames * sizeof ( ehci->frame[0] ) );
- ehci->frame = malloc_dma ( len, EHCI_PAGE_ALIGN );
+ ehci->frame = malloc_phys ( len, EHCI_PAGE_ALIGN );
if ( ! ehci->frame ) {
rc = -ENOMEM;
goto err_alloc_frame;
@@ -1836,10 +1837,10 @@ static int ehci_bus_open ( struct usb_bus *bus ) {
ehci_stop ( ehci );
err_unreachable_frame:
- free_dma ( ehci->frame, len );
+ free_phys ( ehci->frame, len );
err_alloc_frame:
err_ctrldssegment:
- free_dma ( ehci->head, sizeof ( *ehci->head ) );
+ free_phys ( ehci->head, sizeof ( *ehci->head ) );
err_alloc_head:
return rc;
}
@@ -1861,10 +1862,10 @@ static void ehci_bus_close ( struct usb_bus *bus ) {
ehci_stop ( ehci );
/* Free periodic frame list */
- free_dma ( ehci->frame, ( frames * sizeof ( ehci->frame[0] ) ) );
+ free_phys ( ehci->frame, ( frames * sizeof ( ehci->frame[0] ) ) );
/* Free asynchronous schedule */
- free_dma ( ehci->head, sizeof ( *ehci->head ) );
+ free_phys ( ehci->head, sizeof ( *ehci->head ) );
}
/**
@@ -1989,7 +1990,7 @@ static int ehci_probe ( struct pci_device *pci ) {
/* Map registers */
bar_start = pci_bar_start ( pci, EHCI_BAR );
bar_size = pci_bar_size ( pci, EHCI_BAR );
- ehci->regs = ioremap ( bar_start, bar_size );
+ ehci->regs = pci_ioremap ( pci, bar_start, bar_size );
if ( ! ehci->regs ) {
rc = -ENODEV;
goto err_ioremap;
diff --git a/src/drivers/usb/uhci.c b/src/drivers/usb/uhci.c
index ce2962d36..47474bdc7 100644
--- a/src/drivers/usb/uhci.c
+++ b/src/drivers/usb/uhci.c
@@ -179,7 +179,7 @@ static int uhci_ring_alloc ( struct uhci_ring *ring ) {
memset ( ring, 0, sizeof ( *ring ) );
/* Allocate queue head */
- ring->head = malloc_dma ( sizeof ( *ring->head ), UHCI_ALIGN );
+ ring->head = malloc_phys ( sizeof ( *ring->head ), UHCI_ALIGN );
if ( ! ring->head ) {
rc = -ENOMEM;
goto err_alloc;
@@ -194,7 +194,7 @@ static int uhci_ring_alloc ( struct uhci_ring *ring ) {
return 0;
err_unreachable:
- free_dma ( ring->head, sizeof ( *ring->head ) );
+ free_phys ( ring->head, sizeof ( *ring->head ) );
err_alloc:
return rc;
}
@@ -213,7 +213,7 @@ static void uhci_ring_free ( struct uhci_ring *ring ) {
assert ( ring->xfer[i] == NULL );
/* Free queue head */
- free_dma ( ring->head, sizeof ( *ring->head ) );
+ free_phys ( ring->head, sizeof ( *ring->head ) );
}
/**
@@ -263,7 +263,7 @@ static int uhci_enqueue ( struct uhci_ring *ring, struct io_buffer *iobuf,
/* Allocate transfer descriptors */
len = ( count * sizeof ( xfer->desc[0] ) );
- xfer->desc = malloc_dma ( len, UHCI_ALIGN );
+ xfer->desc = malloc_phys ( len, UHCI_ALIGN );
if ( ! xfer->desc ) {
rc = -ENOMEM;
goto err_alloc_desc;
@@ -299,7 +299,7 @@ static int uhci_enqueue ( struct uhci_ring *ring, struct io_buffer *iobuf,
return 0;
err_unreachable_desc:
- free_dma ( xfer->desc, len );
+ free_phys ( xfer->desc, len );
err_alloc_desc:
free ( xfer );
err_alloc_xfer:
@@ -377,7 +377,7 @@ static struct io_buffer * uhci_dequeue ( struct uhci_ring *ring ) {
/* Free transfer descriptors */
len = ( xfer->prod * sizeof ( xfer->desc[0] ) );
- free_dma ( xfer->desc, len );
+ free_phys ( xfer->desc, len );
/* Free transfer */
free ( xfer );
@@ -1312,7 +1312,7 @@ static int uhci_bus_open ( struct usb_bus *bus ) {
assert ( list_empty ( &uhci->periodic ) );
/* Allocate and initialise asynchronous queue head */
- uhci->head = malloc_dma ( sizeof ( *uhci->head ), UHCI_ALIGN );
+ uhci->head = malloc_phys ( sizeof ( *uhci->head ), UHCI_ALIGN );
if ( ! uhci->head ) {
rc = -ENOMEM;
goto err_alloc_head;
@@ -1324,8 +1324,8 @@ static int uhci_bus_open ( struct usb_bus *bus ) {
uhci_async_schedule ( uhci );
/* Allocate periodic frame list */
- uhci->frame = malloc_dma ( sizeof ( *uhci->frame ),
- sizeof ( *uhci->frame ) );
+ uhci->frame = malloc_phys ( sizeof ( *uhci->frame ),
+ sizeof ( *uhci->frame ) );
if ( ! uhci->frame ) {
rc = -ENOMEM;
goto err_alloc_frame;
@@ -1343,10 +1343,10 @@ static int uhci_bus_open ( struct usb_bus *bus ) {
uhci_stop ( uhci );
err_unreachable_frame:
- free_dma ( uhci->frame, sizeof ( *uhci->frame ) );
+ free_phys ( uhci->frame, sizeof ( *uhci->frame ) );
err_alloc_frame:
err_unreachable_head:
- free_dma ( uhci->head, sizeof ( *uhci->head ) );
+ free_phys ( uhci->head, sizeof ( *uhci->head ) );
err_alloc_head:
return rc;
}
@@ -1367,10 +1367,10 @@ static void uhci_bus_close ( struct usb_bus *bus ) {
uhci_stop ( uhci );
/* Free periodic frame list */
- free_dma ( uhci->frame, sizeof ( *uhci->frame ) );
+ free_phys ( uhci->frame, sizeof ( *uhci->frame ) );
/* Free asynchronous schedule */
- free_dma ( uhci->head, sizeof ( *uhci->head ) );
+ free_phys ( uhci->head, sizeof ( *uhci->head ) );
}
/**
diff --git a/src/drivers/usb/usbblk.c b/src/drivers/usb/usbblk.c
new file mode 100644
index 000000000..5a086d3f8
--- /dev/null
+++ b/src/drivers/usb/usbblk.c
@@ -0,0 +1,912 @@
+/*
+ * Copyright (C) 2020 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 <stdlib.h>
+#include <errno.h>
+#include <ipxe/usb.h>
+#include <ipxe/scsi.h>
+#include <ipxe/xfer.h>
+#include <ipxe/uri.h>
+#include <ipxe/open.h>
+#include <ipxe/efi/efi_path.h>
+#include "usbblk.h"
+
+/** @file
+ *
+ * USB mass storage driver
+ *
+ */
+
+static void usbblk_stop ( struct usbblk_device *usbblk, int rc );
+
+/** List of USB block devices */
+static LIST_HEAD ( usbblk_devices );
+
+/******************************************************************************
+ *
+ * Endpoint management
+ *
+ ******************************************************************************
+ */
+
+/**
+ * Open endpoints
+ *
+ * @v usbblk USB block device
+ * @ret rc Return status code
+ */
+static int usbblk_open ( struct usbblk_device *usbblk ) {
+ struct usb_device *usb = usbblk->func->usb;
+ unsigned int interface = usbblk->func->interface[0];
+ int rc;
+
+ /* Sanity checks */
+ assert ( ! usbblk->in.open );
+ assert ( ! usbblk->out.open );
+
+ /* Issue reset */
+ if ( ( rc = usb_control ( usb, USBBLK_RESET, 0, interface,
+ NULL, 0 ) ) != 0 ) {
+ DBGC ( usbblk, "USBBLK %s could not issue reset: %s\n",
+ usbblk->func->name, strerror ( rc ) );
+ goto err_reset;
+ }
+
+ /* Open bulk OUT endpoint */
+ if ( ( rc = usb_endpoint_open ( &usbblk->out ) ) != 0 ) {
+ DBGC ( usbblk, "USBBLK %s could not open bulk OUT: %s\n",
+ usbblk->func->name, strerror ( rc ) );
+ goto err_open_out;
+ }
+
+ /* Clear any bulk OUT halt condition */
+ if ( ( rc = usb_endpoint_clear_halt ( &usbblk->out ) ) != 0 ) {
+ DBGC ( usbblk, "USBBLK %s could not reset bulk OUT: %s\n",
+ usbblk->func->name, strerror ( rc ) );
+ goto err_clear_out;
+ }
+
+ /* Open bulk IN endpoint */
+ if ( ( rc = usb_endpoint_open ( &usbblk->in ) ) != 0 ) {
+ DBGC ( usbblk, "USBBLK %s could not open bulk IN: %s\n",
+ usbblk->func->name, strerror ( rc ) );
+ goto err_open_in;
+ }
+
+ /* Clear any bulk IN halt condition */
+ if ( ( rc = usb_endpoint_clear_halt ( &usbblk->in ) ) != 0 ) {
+ DBGC ( usbblk, "USBBLK %s could not reset bulk IN: %s\n",
+ usbblk->func->name, strerror ( rc ) );
+ goto err_clear_in;
+ }
+
+ return 0;
+
+ err_clear_in:
+ usb_endpoint_close ( &usbblk->in );
+ err_open_in:
+ err_clear_out:
+ usb_endpoint_close ( &usbblk->out );
+ err_open_out:
+ err_reset:
+ return rc;
+}
+
+/**
+ * Close endpoints
+ *
+ * @v usbblk USB block device
+ */
+static void usbblk_close ( struct usbblk_device *usbblk ) {
+
+ /* Close bulk OUT endpoint */
+ if ( usbblk->out.open )
+ usb_endpoint_close ( &usbblk->out );
+
+ /* Close bulk IN endpoint */
+ if ( usbblk->in.open )
+ usb_endpoint_close ( &usbblk->in );
+}
+
+/******************************************************************************
+ *
+ * Bulk OUT endpoint
+ *
+ ******************************************************************************
+ */
+
+/**
+ * Issue bulk OUT command
+ *
+ * @v usbblk USB block device
+ * @ret rc Return status code
+ */
+static int usbblk_out_command ( struct usbblk_device *usbblk ) {
+ struct usbblk_command *cmd = &usbblk->cmd;
+ struct usbblk_command_wrapper *wrapper;
+ struct io_buffer *iobuf;
+ int rc;
+
+ /* Sanity checks */
+ assert ( cmd->tag );
+ assert ( ! ( cmd->scsi.data_in_len && cmd->scsi.data_out_len ) );
+
+ /* Allocate I/O buffer */
+ iobuf = alloc_iob ( sizeof ( *wrapper ) );
+ if ( ! iobuf ) {
+ rc = -ENOMEM;
+ goto err_alloc;
+ }
+
+ /* Populate command */
+ wrapper = iob_put ( iobuf, sizeof ( *wrapper ) );
+ memset ( wrapper, 0, sizeof ( *wrapper ) );
+ wrapper->signature = cpu_to_le32 ( USBBLK_COMMAND_SIGNATURE );
+ wrapper->tag = cmd->tag; /* non-endian */
+ if ( cmd->scsi.data_out_len ) {
+ wrapper->len = cpu_to_le32 ( cmd->scsi.data_out_len );
+ } else {
+ wrapper->len = cpu_to_le32 ( cmd->scsi.data_in_len );
+ wrapper->flags = USB_DIR_IN;
+ }
+ wrapper->lun = ntohs ( cmd->scsi.lun.u16[0] );
+ wrapper->cblen = sizeof ( wrapper->cb );
+ memcpy ( wrapper->cb, &cmd->scsi.cdb, sizeof ( wrapper->cb ) );
+
+ /* Issue command */
+ if ( ( rc = usb_stream ( &usbblk->out, iobuf, 0 ) ) != 0 ) {
+ DBGC ( usbblk, "USBBLK %s bulk OUT could not issue command: "
+ "%s\n", usbblk->func->name, strerror ( rc ) );
+ goto err_stream;
+ }
+
+ return 0;
+
+ err_stream:
+ free_iob ( iobuf );
+ err_alloc:
+ return rc;
+}
+
+/**
+ * Send bulk OUT data block
+ *
+ * @v usbblk USB block device
+ * @ret rc Return status code
+ */
+static int usbblk_out_data ( struct usbblk_device *usbblk ) {
+ struct usbblk_command *cmd = &usbblk->cmd;
+ struct io_buffer *iobuf;
+ size_t len;
+ int rc;
+
+ /* Calculate length */
+ assert ( cmd->tag );
+ assert ( cmd->scsi.data_out != UNULL );
+ assert ( cmd->offset < cmd->scsi.data_out_len );
+ len = ( cmd->scsi.data_out_len - cmd->offset );
+ if ( len > USBBLK_MAX_LEN )
+ len = USBBLK_MAX_LEN;
+ assert ( ( len % usbblk->out.mtu ) == 0 );
+
+ /* Allocate I/O buffer */
+ iobuf = alloc_iob ( len );
+ if ( ! iobuf ) {
+ rc = -ENOMEM;
+ goto err_alloc;
+ }
+
+ /* Populate I/O buffer */
+ copy_from_user ( iob_put ( iobuf, len ), cmd->scsi.data_out,
+ cmd->offset, len );
+
+ /* Send data */
+ if ( ( rc = usb_stream ( &usbblk->out, iobuf, 0 ) ) != 0 ) {
+ DBGC ( usbblk, "USBBLK %s bulk OUT could not send data: %s\n",
+ usbblk->func->name, strerror ( rc ) );
+ goto err_stream;
+ }
+
+ /* Consume data */
+ cmd->offset += len;
+
+ return 0;
+
+ err_stream:
+ free_iob ( iobuf );
+ err_alloc:
+ return rc;
+}
+
+/**
+ * Refill bulk OUT endpoint
+ *
+ * @v usbblk USB block device
+ * @ret rc Return status code
+ */
+static int usbblk_out_refill ( struct usbblk_device *usbblk ) {
+ struct usbblk_command *cmd = &usbblk->cmd;
+ int rc;
+
+ /* Sanity checks */
+ assert ( cmd->tag );
+
+ /* Refill endpoint */
+ while ( ( cmd->offset < cmd->scsi.data_out_len ) &&
+ ( usbblk->out.fill < USBBLK_MAX_FILL ) ) {
+ if ( ( rc = usbblk_out_data ( usbblk ) ) != 0 )
+ return rc;
+ }
+
+ return 0;
+}
+
+/**
+ * Complete bulk OUT transfer
+ *
+ * @v ep USB endpoint
+ * @v iobuf I/O buffer
+ * @v rc Completion status code
+ */
+static void usbblk_out_complete ( struct usb_endpoint *ep,
+ struct io_buffer *iobuf, int rc ) {
+ struct usbblk_device *usbblk =
+ container_of ( ep, struct usbblk_device, out );
+ struct usbblk_command *cmd = &usbblk->cmd;
+
+ /* Ignore cancellations after closing endpoint */
+ if ( ! ep->open )
+ goto drop;
+
+ /* Sanity check */
+ assert ( cmd->tag );
+
+ /* Check for failures */
+ if ( rc != 0 ) {
+ DBGC ( usbblk, "USBBLK %s bulk OUT failed: %s\n",
+ usbblk->func->name, strerror ( rc ) );
+ goto err;
+ }
+
+ /* Trigger refill process, if applicable */
+ if ( cmd->offset < cmd->scsi.data_out_len )
+ process_add ( &usbblk->process );
+
+ drop:
+ /* Free I/O buffer */
+ free_iob ( iobuf );
+
+ return;
+
+ err:
+ free_iob ( iobuf );
+ usbblk_stop ( usbblk, rc );
+}
+
+/** Bulk OUT endpoint operations */
+static struct usb_endpoint_driver_operations usbblk_out_operations = {
+ .complete = usbblk_out_complete,
+};
+
+/******************************************************************************
+ *
+ * Bulk IN endpoint
+ *
+ ******************************************************************************
+ */
+
+/**
+ * Handle bulk IN data block
+ *
+ * @v usbblk USB block device
+ * @v data Data block
+ * @v len Length of data
+ * @ret rc Return status code
+ */
+static int usbblk_in_data ( struct usbblk_device *usbblk, const void *data,
+ size_t len ) {
+ struct usbblk_command *cmd = &usbblk->cmd;
+
+ /* Sanity checks */
+ assert ( cmd->tag );
+ assert ( cmd->scsi.data_in != UNULL );
+ assert ( cmd->offset <= cmd->scsi.data_in_len );
+ assert ( len <= ( cmd->scsi.data_in_len - cmd->offset ) );
+
+ /* Store data */
+ copy_to_user ( cmd->scsi.data_in, cmd->offset, data, len );
+ cmd->offset += len;
+
+ return 0;
+}
+
+/**
+ * Handle bulk IN status
+ *
+ * @v usbblk USB block device
+ * @v data Status data
+ * @v len Length of status data
+ * @ret rc Return status code
+ */
+static int usbblk_in_status ( struct usbblk_device *usbblk, const void *data,
+ size_t len ) {
+ struct usbblk_command *cmd = &usbblk->cmd;
+ const struct usbblk_status_wrapper *stat;
+
+ /* Sanity checks */
+ assert ( cmd->tag );
+
+ /* Validate length */
+ if ( len < sizeof ( *stat ) ) {
+ DBGC ( usbblk, "USBBLK %s bulk IN malformed status:\n",
+ usbblk->func->name );
+ DBGC_HDA ( usbblk, 0, data, len );
+ return -EIO;
+ }
+ stat = data;
+
+ /* Validate signature */
+ if ( stat->signature != cpu_to_le32 ( USBBLK_STATUS_SIGNATURE ) ) {
+ DBGC ( usbblk, "USBBLK %s bulk IN invalid signature %08x:\n",
+ usbblk->func->name, le32_to_cpu ( stat->signature ) );
+ DBGC_HDA ( usbblk, 0, stat, sizeof ( *stat ) );
+ return -EIO;
+ }
+
+ /* Validate tag */
+ if ( stat->tag != cmd->tag ) {
+ DBGC ( usbblk, "USBBLK %s bulk IN tag mismatch (got %08x, "
+ "expected %08x):\n",
+ usbblk->func->name, stat->tag, cmd->tag );
+ DBGC_HDA ( usbblk, 0, stat, sizeof ( *stat ) );
+ return -EIO;
+ }
+
+ /* Check status */
+ if ( stat->status ) {
+ DBGC ( usbblk, "USBBLK %s bulk IN status %02x:\n",
+ usbblk->func->name, stat->status );
+ DBGC_HDA ( usbblk, 0, stat, sizeof ( *stat ) );
+ return -EIO;
+ }
+
+ /* Check for residual data */
+ if ( stat->residue ) {
+ DBGC ( usbblk, "USBBLK %s bulk IN residue %#x:\n",
+ usbblk->func->name, le32_to_cpu ( stat->residue ) );
+ return -EIO;
+ }
+
+ /* Mark command as complete */
+ usbblk_stop ( usbblk, 0 );
+
+ return 0;
+}
+
+/**
+ * Refill bulk IN endpoint
+ *
+ * @v usbblk USB block device
+ * @ret rc Return status code
+ */
+static int usbblk_in_refill ( struct usbblk_device *usbblk ) {
+ struct usbblk_command *cmd = &usbblk->cmd;
+ struct usbblk_status_wrapper *stat;
+ size_t remaining;
+ unsigned int max;
+ int rc;
+
+ /* Sanity checks */
+ assert ( cmd->tag );
+
+ /* Calculate maximum required refill */
+ remaining = sizeof ( *stat );
+ if ( cmd->scsi.data_in_len ) {
+ assert ( cmd->offset <= cmd->scsi.data_in_len );
+ remaining += ( cmd->scsi.data_in_len - cmd->offset );
+ }
+ max = ( ( remaining + USBBLK_MAX_LEN - 1 ) / USBBLK_MAX_LEN );
+
+ /* Refill bulk IN endpoint */
+ if ( ( rc = usb_refill_limit ( &usbblk->in, max ) ) != 0 )
+ return rc;
+
+ return 0;
+}
+
+/**
+ * Complete bulk IN transfer
+ *
+ * @v ep USB endpoint
+ * @v iobuf I/O buffer
+ * @v rc Completion status code
+ */
+static void usbblk_in_complete ( struct usb_endpoint *ep,
+ struct io_buffer *iobuf, int rc ) {
+ struct usbblk_device *usbblk =
+ container_of ( ep, struct usbblk_device, in );
+ struct usbblk_command *cmd = &usbblk->cmd;
+ size_t remaining;
+ size_t len;
+
+ /* Ignore cancellations after closing endpoint */
+ if ( ! ep->open )
+ goto drop;
+
+ /* Sanity check */
+ assert ( cmd->tag );
+
+ /* Handle errors */
+ if ( rc != 0 ) {
+ DBGC ( usbblk, "USBBLK %s bulk IN failed: %s\n",
+ usbblk->func->name, strerror ( rc ) );
+ goto err;
+ }
+
+ /* Trigger refill process */
+ process_add ( &usbblk->process );
+
+ /* Handle data portion, if any */
+ if ( cmd->scsi.data_in_len ) {
+ assert ( cmd->offset <= cmd->scsi.data_in_len );
+ remaining = ( cmd->scsi.data_in_len - cmd->offset );
+ len = iob_len ( iobuf );
+ if ( len > remaining )
+ len = remaining;
+ if ( len ) {
+ if ( ( rc = usbblk_in_data ( usbblk, iobuf->data,
+ len ) ) != 0 )
+ goto err;
+ iob_pull ( iobuf, len );
+ }
+ }
+
+ /* Handle status portion, if any */
+ len = iob_len ( iobuf );
+ if ( len ) {
+ if ( ( rc = usbblk_in_status ( usbblk, iobuf->data,
+ len ) ) != 0 )
+ goto err;
+ }
+
+ drop:
+ /* Free I/O buffer */
+ free_iob ( iobuf );
+
+ return;
+
+ err:
+ free_iob ( iobuf );
+ usbblk_stop ( usbblk, rc );
+}
+
+/** Bulk IN endpoint operations */
+static struct usb_endpoint_driver_operations usbblk_in_operations = {
+ .complete = usbblk_in_complete,
+};
+
+/******************************************************************************
+ *
+ * Refill process
+ *
+ ******************************************************************************
+ */
+
+/**
+ * Refill endpoints
+ *
+ * @v usbblk USB block device
+ */
+static void usbblk_step ( struct usbblk_device *usbblk ) {
+
+ /* Refill bulk OUT endpoint */
+ usbblk_out_refill ( usbblk );
+
+ /* Refill bulk IN endpoint */
+ usbblk_in_refill ( usbblk );
+}
+
+/** Refill process descriptor */
+static struct process_descriptor usbblk_process_desc =
+ PROC_DESC ( struct usbblk_device, process, usbblk_step );
+
+/******************************************************************************
+ *
+ * SCSI command management
+ *
+ ******************************************************************************
+ */
+
+/** Next command tag */
+static uint16_t usbblk_tag;
+
+/**
+ * Stop SCSI command
+ *
+ * @v usbblk USB block device
+ * @v rc Reason for stop
+ */
+static void usbblk_stop ( struct usbblk_device *usbblk, int rc ) {
+
+ /* Stop process */
+ process_del ( &usbblk->process );
+
+ /* Reset command */
+ memset ( &usbblk->cmd, 0, sizeof ( usbblk->cmd ) );
+
+ /* Close endpoints if an error occurred */
+ if ( rc != 0 ) {
+ DBGC ( usbblk, "USBBLK %s closing for error recovery\n",
+ usbblk->func->name );
+ usbblk_close ( usbblk );
+ }
+
+ /* Terminate command */
+ intf_restart ( &usbblk->data, rc );
+}
+
+/**
+ * Start new SCSI command
+ *
+ * @v usbblk USB block device
+ * @v scsicmd SCSI command
+ * @ret rc Return status code
+ */
+static int usbblk_start ( struct usbblk_device *usbblk,
+ struct scsi_cmd *scsicmd ) {
+ struct usbblk_command *cmd = &usbblk->cmd;
+ int rc;
+
+ /* Fail if command is in progress */
+ if ( cmd->tag ) {
+ rc = -EBUSY;
+ DBGC ( usbblk, "USBBLK %s cannot support multiple commands\n",
+ usbblk->func->name );
+ goto err_busy;
+ }
+
+ /* Refuse bidirectional commands */
+ if ( scsicmd->data_in_len && scsicmd->data_out_len ) {
+ rc = -EOPNOTSUPP;
+ DBGC ( usbblk, "USBBLK %s cannot support bidirectional "
+ "commands\n", usbblk->func->name );
+ goto err_bidirectional;
+ }
+
+ /* Sanity checks */
+ assert ( ! process_running ( &usbblk->process ) );
+ assert ( cmd->offset == 0 );
+
+ /* Initialise command */
+ memcpy ( &cmd->scsi, scsicmd, sizeof ( cmd->scsi ) );
+ cmd->tag = ( USBBLK_TAG_MAGIC | ++usbblk_tag );
+
+ /* Issue bulk OUT command */
+ if ( ( rc = usbblk_out_command ( usbblk ) ) != 0 )
+ goto err_command;
+
+ /* Start refill process */
+ process_add ( &usbblk->process );
+
+ return 0;
+
+ err_command:
+ memset ( &usbblk->cmd, 0, sizeof ( usbblk->cmd ) );
+ err_bidirectional:
+ err_busy:
+ return rc;
+}
+
+/******************************************************************************
+ *
+ * SCSI interfaces
+ *
+ ******************************************************************************
+ */
+
+/** SCSI data interface operations */
+static struct interface_operation usbblk_data_operations[] = {
+ INTF_OP ( intf_close, struct usbblk_device *, usbblk_stop ),
+};
+
+/** SCSI data interface descriptor */
+static struct interface_descriptor usbblk_data_desc =
+ INTF_DESC ( struct usbblk_device, data, usbblk_data_operations );
+
+/**
+ * Check SCSI command flow-control window
+ *
+ * @v usbblk USB block device
+ * @ret len Length of window
+ */
+static size_t usbblk_scsi_window ( struct usbblk_device *usbblk ) {
+ struct usbblk_command *cmd = &usbblk->cmd;
+
+ /* Allow a single command if no command is currently in progress */
+ return ( cmd->tag ? 0 : 1 );
+}
+
+/**
+ * Issue SCSI command
+ *
+ * @v usbblk USB block device
+ * @v data SCSI data interface
+ * @v scsicmd SCSI command
+ * @ret tag Command tag, or negative error
+ */
+static int usbblk_scsi_command ( struct usbblk_device *usbblk,
+ struct interface *data,
+ struct scsi_cmd *scsicmd ) {
+ struct usbblk_command *cmd = &usbblk->cmd;
+ int rc;
+
+ /* (Re)open endpoints if needed */
+ if ( ( ! usbblk->in.open ) && ( ( rc = usbblk_open ( usbblk ) ) != 0 ) )
+ goto err_open;
+
+ /* Start new command */
+ if ( ( rc = usbblk_start ( usbblk, scsicmd ) ) != 0 )
+ goto err_start;
+
+ /* Attach to parent interface and return */
+ intf_plug_plug ( &usbblk->data, data );
+ return cmd->tag;
+
+ usbblk_stop ( usbblk, rc );
+ err_start:
+ usbblk_close ( usbblk );
+ err_open:
+ return rc;
+}
+
+/**
+ * Close SCSI interface
+ *
+ * @v usbblk USB block device
+ * @v rc Reason for close
+ */
+static void usbblk_scsi_close ( struct usbblk_device *usbblk, int rc ) {
+
+ /* Restart interfaces */
+ intfs_restart ( rc, &usbblk->scsi, &usbblk->data, NULL );
+
+ /* Stop any in-progress command */
+ usbblk_stop ( usbblk, rc );
+
+ /* Close endpoints */
+ usbblk_close ( usbblk );
+
+ /* Flag as closed */
+ usbblk->opened = 0;
+}
+
+/**
+ * Describe as an EFI device path
+ *
+ * @v usbblk USB block device
+ * @ret path EFI device path, or NULL on error
+ */
+static EFI_DEVICE_PATH_PROTOCOL *
+usbblk_efi_describe ( struct usbblk_device *usbblk ) {
+
+ return efi_usb_path ( usbblk->func );
+}
+
+/** SCSI command interface operations */
+static struct interface_operation usbblk_scsi_operations[] = {
+ INTF_OP ( scsi_command, struct usbblk_device *, usbblk_scsi_command ),
+ INTF_OP ( xfer_window, struct usbblk_device *, usbblk_scsi_window ),
+ INTF_OP ( intf_close, struct usbblk_device *, usbblk_scsi_close ),
+ EFI_INTF_OP ( efi_describe, struct usbblk_device *,
+ usbblk_efi_describe ),
+};
+
+/** SCSI command interface descriptor */
+static struct interface_descriptor usbblk_scsi_desc =
+ INTF_DESC ( struct usbblk_device, scsi, usbblk_scsi_operations );
+
+/******************************************************************************
+ *
+ * SAN device interface
+ *
+ ******************************************************************************
+ */
+
+/**
+ * Find USB block device
+ *
+ * @v name USB block device name
+ * @ret usbblk USB block device, or NULL
+ */
+static struct usbblk_device * usbblk_find ( const char *name ) {
+ struct usbblk_device *usbblk;
+
+ /* Look for matching device */
+ list_for_each_entry ( usbblk, &usbblk_devices, list ) {
+ if ( strcmp ( usbblk->func->name, name ) == 0 )
+ return usbblk;
+ }
+
+ return NULL;
+}
+
+/**
+ * Open USB block device URI
+ *
+ * @v parent Parent interface
+ * @v uri URI
+ * @ret rc Return status code
+ */
+static int usbblk_open_uri ( struct interface *parent, struct uri *uri ) {
+ static struct scsi_lun lun;
+ struct usbblk_device *usbblk;
+ int rc;
+
+ /* Sanity check */
+ if ( ! uri->opaque )
+ return -EINVAL;
+
+ /* Find matching device */
+ usbblk = usbblk_find ( uri->opaque );
+ if ( ! usbblk )
+ return -ENOENT;
+
+ /* Fail if device is already open */
+ if ( usbblk->opened )
+ return -EBUSY;
+
+ /* Open SCSI device */
+ if ( ( rc = scsi_open ( parent, &usbblk->scsi, &lun ) ) != 0 ) {
+ DBGC ( usbblk, "USBBLK %s could not open SCSI device: %s\n",
+ usbblk->func->name, strerror ( rc ) );
+ return rc;
+ }
+
+ /* Mark as opened */
+ usbblk->opened = 1;
+
+ return 0;
+}
+
+/** USB block device URI opener */
+struct uri_opener usbblk_uri_opener __uri_opener = {
+ .scheme = "usb",
+ .open = usbblk_open_uri,
+};
+
+/******************************************************************************
+ *
+ * USB interface
+ *
+ ******************************************************************************
+ */
+
+/**
+ * Probe device
+ *
+ * @v func USB function
+ * @v config Configuration descriptor
+ * @ret rc Return status code
+ */
+static int usbblk_probe ( struct usb_function *func,
+ struct usb_configuration_descriptor *config ) {
+ struct usb_device *usb = func->usb;
+ struct usbblk_device *usbblk;
+ struct usb_interface_descriptor *desc;
+ int rc;
+
+ /* Allocate and initialise structure */
+ usbblk = zalloc ( sizeof ( *usbblk ) );
+ if ( ! usbblk ) {
+ rc = -ENOMEM;
+ goto err_alloc;
+ }
+ usbblk->func = func;
+ usb_endpoint_init ( &usbblk->out, usb, &usbblk_out_operations );
+ usb_endpoint_init ( &usbblk->in, usb, &usbblk_in_operations );
+ usb_refill_init ( &usbblk->in, 0, USBBLK_MAX_LEN, USBBLK_MAX_FILL );
+ intf_init ( &usbblk->scsi, &usbblk_scsi_desc, &usbblk->refcnt );
+ intf_init ( &usbblk->data, &usbblk_data_desc, &usbblk->refcnt );
+ process_init_stopped ( &usbblk->process, &usbblk_process_desc,
+ &usbblk->refcnt );
+
+ /* Locate interface descriptor */
+ desc = usb_interface_descriptor ( config, func->interface[0], 0 );
+ if ( ! desc ) {
+ DBGC ( usbblk, "USBBLK %s missing interface descriptor\n",
+ usbblk->func->name );
+ rc = -ENOENT;
+ goto err_desc;
+ }
+
+ /* Describe endpoints */
+ if ( ( rc = usb_endpoint_described ( &usbblk->out, config, desc,
+ USB_BULK_OUT, 0 ) ) != 0 ) {
+ DBGC ( usbblk, "USBBLK %s could not describe bulk OUT: %s\n",
+ usbblk->func->name, strerror ( rc ) );
+ goto err_out;
+ }
+ if ( ( rc = usb_endpoint_described ( &usbblk->in, config, desc,
+ USB_BULK_IN, 0 ) ) != 0 ) {
+ DBGC ( usbblk, "USBBLK %s could not describe bulk IN: %s\n",
+ usbblk->func->name, strerror ( rc ) );
+ goto err_in;
+ }
+
+ /* Add to list of devices */
+ list_add_tail ( &usbblk->list, &usbblk_devices );
+
+ usb_func_set_drvdata ( func, usbblk );
+ return 0;
+
+ err_in:
+ err_out:
+ err_desc:
+ ref_put ( &usbblk->refcnt );
+ err_alloc:
+ return rc;
+}
+
+/**
+ * Remove device
+ *
+ * @v func USB function
+ */
+static void usbblk_remove ( struct usb_function *func ) {
+ struct usbblk_device *usbblk = usb_func_get_drvdata ( func );
+
+ /* Remove from list of devices */
+ list_del ( &usbblk->list );
+
+ /* Close all interfaces */
+ usbblk_scsi_close ( usbblk, -ENODEV );
+
+ /* Shut down interfaces */
+ intfs_shutdown ( -ENODEV, &usbblk->scsi, &usbblk->data, NULL );
+
+ /* Drop reference */
+ ref_put ( &usbblk->refcnt );
+}
+
+/** Mass storage class device IDs */
+static struct usb_device_id usbblk_ids[] = {
+ {
+ .name = "usbblk",
+ .vendor = USB_ANY_ID,
+ .product = USB_ANY_ID,
+ },
+};
+
+/** Mass storage driver */
+struct usb_driver usbblk_driver __usb_driver = {
+ .ids = usbblk_ids,
+ .id_count = ( sizeof ( usbblk_ids ) / sizeof ( usbblk_ids[0] ) ),
+ .class = USB_CLASS_ID ( USB_CLASS_MSC, USB_SUBCLASS_MSC_SCSI,
+ USB_PROTOCOL_MSC_BULK ),
+ .score = USB_SCORE_NORMAL,
+ .probe = usbblk_probe,
+ .remove = usbblk_remove,
+};
diff --git a/src/drivers/usb/usbblk.h b/src/drivers/usb/usbblk.h
new file mode 100644
index 000000000..65d0705e3
--- /dev/null
+++ b/src/drivers/usb/usbblk.h
@@ -0,0 +1,121 @@
+#ifndef _USBBLK_H
+#define _USBBLK_H
+
+/** @file
+ *
+ * USB mass storage driver
+ *
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+#include <stdint.h>
+#include <ipxe/usb.h>
+#include <ipxe/scsi.h>
+#include <ipxe/interface.h>
+
+/** Mass storage class code */
+#define USB_CLASS_MSC 0x08
+
+/** SCSI command set subclass code */
+#define USB_SUBCLASS_MSC_SCSI 0x06
+
+/** Bulk-only transport protocol */
+#define USB_PROTOCOL_MSC_BULK 0x50
+
+/** Mass storage reset command */
+#define USBBLK_RESET ( USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE | \
+ USB_REQUEST_TYPE ( 255 ) )
+
+/** Command block wrapper */
+struct usbblk_command_wrapper {
+ /** Signature */
+ uint32_t signature;
+ /** Tag */
+ uint32_t tag;
+ /** Data transfer length */
+ uint32_t len;
+ /** Flags */
+ uint8_t flags;
+ /** LUN */
+ uint8_t lun;
+ /** Command block length */
+ uint8_t cblen;
+ /** Command block */
+ uint8_t cb[16];
+} __attribute__ (( packed ));
+
+/** Command block wrapper signature */
+#define USBBLK_COMMAND_SIGNATURE 0x43425355UL
+
+/** Command status wrapper */
+struct usbblk_status_wrapper {
+ /** Signature */
+ uint32_t signature;
+ /** Tag */
+ uint32_t tag;
+ /** Data residue */
+ uint32_t residue;
+ /** Status */
+ uint8_t status;
+} __attribute__ (( packed ));
+
+/** Command status wrapper signature */
+#define USBBLK_STATUS_SIGNATURE 0x53425355UL
+
+/** A USB mass storage command */
+struct usbblk_command {
+ /** SCSI command */
+ struct scsi_cmd scsi;
+ /** Command tag (0 for no command in progress) */
+ uint32_t tag;
+ /** Offset within data buffer */
+ size_t offset;
+};
+
+/** A USB mass storage device */
+struct usbblk_device {
+ /** Reference count */
+ struct refcnt refcnt;
+ /** List of devices */
+ struct list_head list;
+
+ /** USB function */
+ struct usb_function *func;
+ /** Bulk OUT endpoint */
+ struct usb_endpoint out;
+ /** Bulk IN endpoint */
+ struct usb_endpoint in;
+
+ /** SCSI command-issuing interface */
+ struct interface scsi;
+ /** SCSI data interface */
+ struct interface data;
+ /** Command process */
+ struct process process;
+ /** Device opened flag */
+ int opened;
+
+ /** Current command (if any) */
+ struct usbblk_command cmd;
+};
+
+/** Command tag magic
+ *
+ * This is a policy decision.
+ */
+#define USBBLK_TAG_MAGIC 0x18ae0000
+
+/** Maximum length of USB data block
+ *
+ * This is a policy decision.
+ */
+#define USBBLK_MAX_LEN 2048
+
+/** Maximum endpoint fill level
+ *
+ * This is a policy decision.
+ */
+#define USBBLK_MAX_FILL 4
+
+#endif /* _USBBLK_H */
diff --git a/src/drivers/usb/usbio.c b/src/drivers/usb/usbio.c
index dfb93dab1..278b43cd3 100644
--- a/src/drivers/usb/usbio.c
+++ b/src/drivers/usb/usbio.c
@@ -29,6 +29,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <assert.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/efi_driver.h>
+#include <ipxe/efi/efi_path.h>
#include <ipxe/efi/efi_utils.h>
#include <ipxe/efi/Protocol/UsbIo.h>
#include <ipxe/usb.h>
@@ -206,7 +207,7 @@ static int usbio_open ( struct usbio_device *usbio, unsigned int interface ) {
path = usbio->path;
usbpath = usbio->usbpath;
usbpath->InterfaceNumber = interface;
- end = efi_devpath_end ( path );
+ end = efi_path_end ( path );
/* Locate handle for this endpoint's interface */
if ( ( efirc = bs->LocateDevicePath ( &efi_usb_io_protocol_guid, &path,
@@ -1503,7 +1504,7 @@ static int usbio_path ( struct usbio_device *usbio ) {
path = u.interface;
/* Locate end of device path and sanity check */
- len = efi_devpath_len ( path );
+ len = efi_path_len ( path );
if ( len < sizeof ( *usbpath ) ) {
DBGC ( usbio, "USBIO %s underlength device path\n",
efi_handle_name ( handle ) );
diff --git a/src/drivers/usb/xhci.c b/src/drivers/usb/xhci.c
index aa6ca73c4..cc48af033 100644
--- a/src/drivers/usb/xhci.c
+++ b/src/drivers/usb/xhci.c
@@ -31,7 +31,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <errno.h>
#include <byteswap.h>
#include <ipxe/malloc.h>
-#include <ipxe/umalloc.h>
#include <ipxe/pci.h>
#include <ipxe/usb.h>
#include <ipxe/init.h>
@@ -294,9 +293,9 @@ static void xhci_init ( struct xhci_device *xhci, void *regs ) {
/* Read structural parameters 2 */
hcsparams2 = readl ( xhci->cap + XHCI_CAP_HCSPARAMS2 );
- xhci->scratchpads = XHCI_HCSPARAMS2_SCRATCHPADS ( hcsparams2 );
+ xhci->scratch.count = XHCI_HCSPARAMS2_SCRATCHPADS ( hcsparams2 );
DBGC2 ( xhci, "XHCI %s needs %d scratchpads\n",
- xhci->name, xhci->scratchpads );
+ xhci->name, xhci->scratch.count );
/* Read capability parameters 1 */
hccparams1 = readl ( xhci->cap + XHCI_CAP_HCCPARAMS1 );
@@ -918,27 +917,29 @@ static int xhci_dcbaa_alloc ( struct xhci_device *xhci ) {
* align on its own size (rounded up to a power of two and
* with a minimum of 64 bytes).
*/
- len = ( ( xhci->slots + 1 ) * sizeof ( xhci->dcbaa[0] ) );
- xhci->dcbaa = malloc_dma ( len, xhci_align ( len ) );
- if ( ! xhci->dcbaa ) {
+ len = ( ( xhci->slots + 1 ) * sizeof ( xhci->dcbaa.context[0] ) );
+ xhci->dcbaa.context = dma_alloc ( xhci->dma, &xhci->dcbaa.map, len,
+ xhci_align ( len ) );
+ if ( ! xhci->dcbaa.context ) {
DBGC ( xhci, "XHCI %s could not allocate DCBAA\n", xhci->name );
rc = -ENOMEM;
goto err_alloc;
}
- memset ( xhci->dcbaa, 0, len );
+ memset ( xhci->dcbaa.context, 0, len );
/* Program DCBAA pointer */
- dcbaap = virt_to_phys ( xhci->dcbaa );
+ dcbaap = dma ( &xhci->dcbaa.map, xhci->dcbaa.context );
if ( ( rc = xhci_writeq ( xhci, dcbaap,
xhci->op + XHCI_OP_DCBAAP ) ) != 0 )
goto err_writeq;
- DBGC2 ( xhci, "XHCI %s DCBAA at [%08lx,%08lx)\n",
- xhci->name, dcbaap, ( dcbaap + len ) );
+ DBGC2 ( xhci, "XHCI %s DCBAA at [%08lx,%08lx)\n", xhci->name,
+ virt_to_phys ( xhci->dcbaa.context ),
+ ( virt_to_phys ( xhci->dcbaa.context ) + len ) );
return 0;
err_writeq:
- free_dma ( xhci->dcbaa, len );
+ dma_free ( &xhci->dcbaa.map, xhci->dcbaa.context, len );
err_alloc:
return rc;
}
@@ -954,14 +955,14 @@ static void xhci_dcbaa_free ( struct xhci_device *xhci ) {
/* Sanity check */
for ( i = 0 ; i <= xhci->slots ; i++ )
- assert ( xhci->dcbaa[i] == 0 );
+ assert ( xhci->dcbaa.context[i] == 0 );
/* Clear DCBAA pointer */
xhci_writeq ( xhci, 0, xhci->op + XHCI_OP_DCBAAP );
/* Free DCBAA */
- len = ( ( xhci->slots + 1 ) * sizeof ( xhci->dcbaa[0] ) );
- free_dma ( xhci->dcbaa, len );
+ len = ( ( xhci->slots + 1 ) * sizeof ( xhci->dcbaa.context[0] ) );
+ dma_free ( &xhci->dcbaa.map, xhci->dcbaa.context, len );
}
/******************************************************************************
@@ -978,32 +979,34 @@ static void xhci_dcbaa_free ( struct xhci_device *xhci ) {
* @ret rc Return status code
*/
static int xhci_scratchpad_alloc ( struct xhci_device *xhci ) {
+ struct xhci_scratchpad *scratch = &xhci->scratch;
+ size_t buffer_len;
size_t array_len;
- size_t len;
- physaddr_t phys;
+ physaddr_t addr;
unsigned int i;
int rc;
/* Do nothing if no scratchpad buffers are used */
- if ( ! xhci->scratchpads )
+ if ( ! scratch->count )
return 0;
- /* Allocate scratchpads */
- len = ( xhci->scratchpads * xhci->pagesize );
- xhci->scratchpad = umalloc ( len );
- if ( ! xhci->scratchpad ) {
+ /* Allocate scratchpad buffers */
+ buffer_len = ( scratch->count * xhci->pagesize );
+ scratch->buffer = dma_umalloc ( xhci->dma, &scratch->buffer_map,
+ buffer_len, xhci->pagesize );
+ if ( ! scratch->buffer ) {
DBGC ( xhci, "XHCI %s could not allocate scratchpad buffers\n",
xhci->name );
rc = -ENOMEM;
goto err_alloc;
}
- memset_user ( xhci->scratchpad, 0, 0, len );
+ memset_user ( scratch->buffer, 0, 0, buffer_len );
/* Allocate scratchpad array */
- array_len = ( xhci->scratchpads * sizeof ( xhci->scratchpad_array[0] ));
- xhci->scratchpad_array =
- malloc_dma ( array_len, xhci_align ( array_len ) );
- if ( ! xhci->scratchpad_array ) {
+ array_len = ( scratch->count * sizeof ( scratch->array[0] ) );
+ scratch->array = dma_alloc ( xhci->dma, &scratch->array_map,
+ array_len, xhci_align ( array_len ) );
+ if ( ! scratch->array ) {
DBGC ( xhci, "XHCI %s could not allocate scratchpad buffer "
"array\n", xhci->name );
rc = -ENOMEM;
@@ -1011,25 +1014,28 @@ static int xhci_scratchpad_alloc ( struct xhci_device *xhci ) {
}
/* Populate scratchpad array */
- for ( i = 0 ; i < xhci->scratchpads ; i++ ) {
- phys = user_to_phys ( xhci->scratchpad, ( i * xhci->pagesize ));
- xhci->scratchpad_array[i] = phys;
+ addr = dma_phys ( &scratch->buffer_map,
+ user_to_phys ( scratch->buffer, 0 ) );
+ for ( i = 0 ; i < scratch->count ; i++ ) {
+ scratch->array[i] = cpu_to_le64 ( addr );
+ addr += xhci->pagesize;
}
/* Set scratchpad array pointer */
- assert ( xhci->dcbaa != NULL );
- xhci->dcbaa[0] = cpu_to_le64 ( virt_to_phys ( xhci->scratchpad_array ));
+ assert ( xhci->dcbaa.context != NULL );
+ xhci->dcbaa.context[0] = cpu_to_le64 ( dma ( &scratch->array_map,
+ scratch->array ) );
DBGC2 ( xhci, "XHCI %s scratchpad [%08lx,%08lx) array [%08lx,%08lx)\n",
- xhci->name, user_to_phys ( xhci->scratchpad, 0 ),
- user_to_phys ( xhci->scratchpad, len ),
- virt_to_phys ( xhci->scratchpad_array ),
- ( virt_to_phys ( xhci->scratchpad_array ) + array_len ) );
+ xhci->name, user_to_phys ( scratch->buffer, 0 ),
+ user_to_phys ( scratch->buffer, buffer_len ),
+ virt_to_phys ( scratch->array ),
+ ( virt_to_phys ( scratch->array ) + array_len ) );
return 0;
- free_dma ( xhci->scratchpad_array, array_len );
+ dma_free ( &scratch->array_map, scratch->array, array_len );
err_alloc_array:
- ufree ( xhci->scratchpad );
+ dma_ufree ( &scratch->buffer_map, scratch->buffer, buffer_len );
err_alloc:
return rc;
}
@@ -1040,22 +1046,25 @@ static int xhci_scratchpad_alloc ( struct xhci_device *xhci ) {
* @v xhci xHCI device
*/
static void xhci_scratchpad_free ( struct xhci_device *xhci ) {
+ struct xhci_scratchpad *scratch = &xhci->scratch;
size_t array_len;
+ size_t buffer_len;
/* Do nothing if no scratchpad buffers are used */
- if ( ! xhci->scratchpads )
+ if ( ! scratch->count )
return;
/* Clear scratchpad array pointer */
- assert ( xhci->dcbaa != NULL );
- xhci->dcbaa[0] = 0;
+ assert ( xhci->dcbaa.context != NULL );
+ xhci->dcbaa.context[0] = 0;
/* Free scratchpad array */
- array_len = ( xhci->scratchpads * sizeof ( xhci->scratchpad_array[0] ));
- free_dma ( xhci->scratchpad_array, array_len );
+ array_len = ( scratch->count * sizeof ( scratch->array[0] ) );
+ dma_free ( &scratch->array_map, scratch->array, array_len );
- /* Free scratchpads */
- ufree ( xhci->scratchpad );
+ /* Free scratchpad buffers */
+ buffer_len = ( scratch->count * xhci->pagesize );
+ dma_ufree ( &scratch->buffer_map, scratch->buffer, buffer_len );
}
/******************************************************************************
@@ -1202,7 +1211,8 @@ static int xhci_ring_alloc ( struct xhci_device *xhci,
}
/* Allocate TRBs */
- ring->trb = malloc_dma ( ring->len, xhci_align ( ring->len ) );
+ ring->trb = dma_alloc ( xhci->dma, &ring->map, ring->len,
+ xhci_align ( ring->len ) );
if ( ! ring->trb ) {
rc = -ENOMEM;
goto err_alloc_trb;
@@ -1211,14 +1221,14 @@ static int xhci_ring_alloc ( struct xhci_device *xhci,
/* Initialise Link TRB */
link = &ring->trb[count].link;
- link->next = cpu_to_le64 ( virt_to_phys ( ring->trb ) );
+ link->next = cpu_to_le64 ( dma ( &ring->map, ring->trb ) );
link->flags = XHCI_TRB_TC;
link->type = XHCI_TRB_LINK;
ring->link = link;
return 0;
- free_dma ( ring->trb, ring->len );
+ dma_free ( &ring->map, ring->trb, ring->len );
err_alloc_trb:
free ( ring->iobuf );
err_alloc_iobuf:
@@ -1256,7 +1266,7 @@ static void xhci_ring_free ( struct xhci_trb_ring *ring ) {
assert ( ring->iobuf[i] == NULL );
/* Free TRBs */
- free_dma ( ring->trb, ring->len );
+ dma_free ( &ring->map, ring->trb, ring->len );
/* Free I/O buffers */
free ( ring->iobuf );
@@ -1422,13 +1432,14 @@ static int xhci_command_alloc ( struct xhci_device *xhci ) {
goto err_ring_alloc;
/* Program command ring control register */
- crp = virt_to_phys ( xhci->command.trb );
+ crp = dma ( &xhci->command.map, xhci->command.trb );
if ( ( rc = xhci_writeq ( xhci, ( crp | XHCI_CRCR_RCS ),
xhci->op + XHCI_OP_CRCR ) ) != 0 )
goto err_writeq;
- DBGC2 ( xhci, "XHCI %s CRCR at [%08lx,%08lx)\n",
- xhci->name, crp, ( crp + xhci->command.len ) );
+ DBGC2 ( xhci, "XHCI %s CRCR at [%08lx,%08lx)\n", xhci->name,
+ virt_to_phys ( xhci->command.trb ),
+ ( virt_to_phys ( xhci->command.trb ) + xhci->command.len ) );
return 0;
err_writeq:
@@ -1469,7 +1480,8 @@ static int xhci_event_alloc ( struct xhci_device *xhci ) {
/* Allocate event ring */
count = ( 1 << XHCI_EVENT_TRBS_LOG2 );
len = ( count * sizeof ( event->trb[0] ) );
- event->trb = malloc_dma ( len, xhci_align ( len ) );
+ event->trb = dma_alloc ( xhci->dma, &event->trb_map, len,
+ xhci_align ( len ) );
if ( ! event->trb ) {
rc = -ENOMEM;
goto err_alloc_trb;
@@ -1477,22 +1489,25 @@ static int xhci_event_alloc ( struct xhci_device *xhci ) {
memset ( event->trb, 0, len );
/* Allocate event ring segment table */
- event->segment = malloc_dma ( sizeof ( event->segment[0] ),
- xhci_align ( sizeof (event->segment[0])));
+ event->segment = dma_alloc ( xhci->dma, &event->segment_map,
+ sizeof ( event->segment[0] ),
+ xhci_align ( sizeof (event->segment[0])));
if ( ! event->segment ) {
rc = -ENOMEM;
goto err_alloc_segment;
}
memset ( event->segment, 0, sizeof ( event->segment[0] ) );
- event->segment[0].base = cpu_to_le64 ( virt_to_phys ( event->trb ) );
+ event->segment[0].base = cpu_to_le64 ( dma ( &event->trb_map,
+ event->trb ) );
event->segment[0].count = cpu_to_le32 ( count );
/* Program event ring registers */
writel ( 1, xhci->run + XHCI_RUN_ERSTSZ ( 0 ) );
- if ( ( rc = xhci_writeq ( xhci, virt_to_phys ( event->trb ),
+ if ( ( rc = xhci_writeq ( xhci, dma ( &event->trb_map, event->trb ),
xhci->run + XHCI_RUN_ERDP ( 0 ) ) ) != 0 )
goto err_writeq_erdp;
- if ( ( rc = xhci_writeq ( xhci, virt_to_phys ( event->segment ),
+ if ( ( rc = xhci_writeq ( xhci,
+ dma ( &event->segment_map, event->segment ),
xhci->run + XHCI_RUN_ERSTBA ( 0 ) ) ) != 0 )
goto err_writeq_erstba;
@@ -1501,16 +1516,17 @@ static int xhci_event_alloc ( struct xhci_device *xhci ) {
( virt_to_phys ( event->trb ) + len ),
virt_to_phys ( event->segment ),
( virt_to_phys ( event->segment ) +
- sizeof (event->segment[0] ) ) );
+ sizeof ( event->segment[0] ) ) );
return 0;
xhci_writeq ( xhci, 0, xhci->run + XHCI_RUN_ERSTBA ( 0 ) );
err_writeq_erstba:
xhci_writeq ( xhci, 0, xhci->run + XHCI_RUN_ERDP ( 0 ) );
err_writeq_erdp:
- free_dma ( event->trb, len );
+ dma_free ( &event->segment_map, event->segment,
+ sizeof ( event->segment[0] ) );
err_alloc_segment:
- free_dma ( event->segment, sizeof ( event->segment[0] ) );
+ dma_free ( &event->trb_map, event->trb, len );
err_alloc_trb:
return rc;
}
@@ -1531,12 +1547,13 @@ static void xhci_event_free ( struct xhci_device *xhci ) {
xhci_writeq ( xhci, 0, xhci->run + XHCI_RUN_ERDP ( 0 ) );
/* Free event ring segment table */
- free_dma ( event->segment, sizeof ( event->segment[0] ) );
+ dma_free ( &event->segment_map, event->segment,
+ sizeof ( event->segment[0] ) );
/* Free event ring */
count = ( 1 << XHCI_EVENT_TRBS_LOG2 );
len = ( count * sizeof ( event->trb[0] ) );
- free_dma ( event->trb, len );
+ dma_free ( &event->trb_map, event->trb, len );
}
/**
@@ -1577,6 +1594,9 @@ static void xhci_transfer ( struct xhci_device *xhci,
iobuf = xhci_dequeue_multi ( &endpoint->ring );
assert ( iobuf != NULL );
+ /* Unmap I/O buffer */
+ iob_unmap ( iobuf );
+
/* Check for errors */
if ( ! ( ( trb->code == XHCI_CMPLT_SUCCESS ) ||
( trb->code == XHCI_CMPLT_SHORT ) ) ) {
@@ -1745,7 +1765,7 @@ static void xhci_event_poll ( struct xhci_device *xhci ) {
/* Update dequeue pointer if applicable */
if ( consumed ) {
- xhci_writeq ( xhci, virt_to_phys ( trb ),
+ xhci_writeq ( xhci, dma ( &event->trb_map, trb ),
xhci->run + XHCI_RUN_ERDP ( 0 ) );
profile_stop ( &xhci_event_profiler );
}
@@ -1774,7 +1794,7 @@ static void xhci_abort ( struct xhci_device *xhci ) {
/* Reset the command ring control register */
xhci_ring_reset ( &xhci->command );
- crp = virt_to_phys ( xhci->command.trb );
+ crp = dma ( &xhci->command.map, xhci->command.trb );
xhci_writeq ( xhci, ( crp | XHCI_CRCR_RCS ), xhci->op + XHCI_OP_CRCR );
}
@@ -1793,6 +1813,13 @@ static int xhci_command ( struct xhci_device *xhci, union xhci_trb *trb ) {
unsigned int i;
int rc;
+ /* Sanity check */
+ if ( xhci->pending ) {
+ DBGC ( xhci, "XHCI %s command ring busy\n", xhci->name );
+ rc = -EBUSY;
+ goto err_pending;
+ }
+
/* Record the pending command */
xhci->pending = trb;
@@ -1835,6 +1862,7 @@ static int xhci_command ( struct xhci_device *xhci, union xhci_trb *trb ) {
err_enqueue:
xhci->pending = NULL;
+ err_pending:
return rc;
}
@@ -1855,9 +1883,13 @@ static inline int xhci_nop ( struct xhci_device *xhci ) {
nop->type = XHCI_TRB_NOP_CMD;
/* Issue command and wait for completion */
- if ( ( rc = xhci_command ( xhci, &trb ) ) != 0 )
+ if ( ( rc = xhci_command ( xhci, &trb ) ) != 0 ) {
+ DBGC ( xhci, "XHCI %s NOP failed: %s\n",
+ xhci->name, strerror ( rc ) );
return rc;
+ }
+ DBGC2 ( xhci, "XHCI %s NOP completed successfully\n", xhci->name );
return 0;
}
@@ -1942,13 +1974,15 @@ static int xhci_context ( struct xhci_device *xhci, struct xhci_slot *slot,
void *input ) ) {
union xhci_trb trb;
struct xhci_trb_context *context = &trb.context;
+ struct dma_mapping map;
size_t len;
void *input;
int rc;
/* Allocate an input context */
+ memset ( &map, 0, sizeof ( map ) );
len = xhci_input_context_offset ( xhci, XHCI_CTX_END );
- input = malloc_dma ( len, xhci_align ( len ) );
+ input = dma_alloc ( xhci->dma, &map, len, xhci_align ( len ) );
if ( ! input ) {
rc = -ENOMEM;
goto err_alloc;
@@ -1961,7 +1995,7 @@ static int xhci_context ( struct xhci_device *xhci, struct xhci_slot *slot,
/* Construct command */
memset ( context, 0, sizeof ( *context ) );
context->type = type;
- context->input = cpu_to_le64 ( virt_to_phys ( input ) );
+ context->input = cpu_to_le64 ( dma ( &map, input ) );
context->slot = slot->id;
/* Issue command and wait for completion */
@@ -1969,7 +2003,7 @@ static int xhci_context ( struct xhci_device *xhci, struct xhci_slot *slot,
goto err_command;
err_command:
- free_dma ( input, len );
+ dma_free ( &map, input, len );
err_alloc:
return rc;
}
@@ -1986,6 +2020,7 @@ static void xhci_address_device_input ( struct xhci_device *xhci,
struct xhci_slot *slot,
struct xhci_endpoint *endpoint,
void *input ) {
+ struct xhci_trb_ring *ring = &endpoint->ring;
struct xhci_control_context *control_ctx;
struct xhci_slot_context *slot_ctx;
struct xhci_endpoint_context *ep_ctx;
@@ -2011,7 +2046,7 @@ static void xhci_address_device_input ( struct xhci_device *xhci,
ep_ctx->type = XHCI_EP_TYPE_CONTROL;
ep_ctx->burst = endpoint->ep->burst;
ep_ctx->mtu = cpu_to_le16 ( endpoint->ep->mtu );
- ep_ctx->dequeue = cpu_to_le64 ( virt_to_phys ( endpoint->ring.trb ) |
+ ep_ctx->dequeue = cpu_to_le64 ( dma ( &ring->map, ring->trb ) |
XHCI_EP_DCS );
ep_ctx->trb_len = cpu_to_le16 ( XHCI_EP0_TRB_LEN );
}
@@ -2032,15 +2067,18 @@ static inline int xhci_address_device ( struct xhci_device *xhci,
/* Assign device address */
if ( ( rc = xhci_context ( xhci, slot, slot->endpoint[XHCI_CTX_EP0],
XHCI_TRB_ADDRESS_DEVICE,
- xhci_address_device_input ) ) != 0 )
+ xhci_address_device_input ) ) != 0 ) {
+ DBGC ( xhci, "XHCI %s slot %d could not assign address: %s\n",
+ xhci->name, slot->id, strerror ( rc ) );
return rc;
+ }
/* Get assigned address */
slot_ctx = ( slot->context +
xhci_device_context_offset ( xhci, XHCI_CTX_SLOT ) );
usb->address = slot_ctx->address;
- DBGC2 ( xhci, "XHCI %s assigned address %d to %s\n",
- xhci->name, usb->address, usb->name );
+ DBGC2 ( xhci, "XHCI %s slot %d assigned address %d to %s\n",
+ xhci->name, slot->id, usb->address, usb->name );
return 0;
}
@@ -2057,6 +2095,7 @@ static void xhci_configure_endpoint_input ( struct xhci_device *xhci,
struct xhci_slot *slot,
struct xhci_endpoint *endpoint,
void *input ) {
+ struct xhci_trb_ring *ring = &endpoint->ring;
struct xhci_control_context *control_ctx;
struct xhci_slot_context *slot_ctx;
struct xhci_endpoint_context *ep_ctx;
@@ -2079,7 +2118,7 @@ static void xhci_configure_endpoint_input ( struct xhci_device *xhci,
ep_ctx->type = endpoint->type;
ep_ctx->burst = endpoint->ep->burst;
ep_ctx->mtu = cpu_to_le16 ( endpoint->ep->mtu );
- ep_ctx->dequeue = cpu_to_le64 ( virt_to_phys ( endpoint->ring.trb ) |
+ ep_ctx->dequeue = cpu_to_le64 ( dma ( &ring->map, ring->trb ) |
XHCI_EP_DCS );
ep_ctx->trb_len = cpu_to_le16 ( endpoint->ep->mtu ); /* best guess */
}
@@ -2100,8 +2139,11 @@ static inline int xhci_configure_endpoint ( struct xhci_device *xhci,
/* Configure endpoint */
if ( ( rc = xhci_context ( xhci, slot, endpoint,
XHCI_TRB_CONFIGURE_ENDPOINT,
- xhci_configure_endpoint_input ) ) != 0 )
+ xhci_configure_endpoint_input ) ) != 0 ) {
+ DBGC ( xhci, "XHCI %s slot %d ctx %d could not configure: %s\n",
+ xhci->name, slot->id, endpoint->ctx, strerror ( rc ) );
return rc;
+ }
DBGC2 ( xhci, "XHCI %s slot %d ctx %d configured\n",
xhci->name, slot->id, endpoint->ctx );
@@ -2151,8 +2193,12 @@ static inline int xhci_deconfigure_endpoint ( struct xhci_device *xhci,
/* Deconfigure endpoint */
if ( ( rc = xhci_context ( xhci, slot, endpoint,
XHCI_TRB_CONFIGURE_ENDPOINT,
- xhci_deconfigure_endpoint_input ) ) != 0 )
+ xhci_deconfigure_endpoint_input ) ) != 0 ) {
+ DBGC ( xhci, "XHCI %s slot %d ctx %d could not deconfigure: "
+ "%s\n", xhci->name, slot->id, endpoint->ctx,
+ strerror ( rc ) );
return rc;
+ }
DBGC2 ( xhci, "XHCI %s slot %d ctx %d deconfigured\n",
xhci->name, slot->id, endpoint->ctx );
@@ -2206,8 +2252,12 @@ static inline int xhci_evaluate_context ( struct xhci_device *xhci,
/* Configure endpoint */
if ( ( rc = xhci_context ( xhci, slot, endpoint,
XHCI_TRB_EVALUATE_CONTEXT,
- xhci_evaluate_context_input ) ) != 0 )
+ xhci_evaluate_context_input ) ) != 0 ) {
+ DBGC ( xhci, "XHCI %s slot %d ctx %d could not (re-)evaluate: "
+ "%s\n", xhci->name, slot->id, endpoint->ctx,
+ strerror ( rc ) );
return rc;
+ }
DBGC2 ( xhci, "XHCI %s slot %d ctx %d (re-)evaluated\n",
xhci->name, slot->id, endpoint->ctx );
@@ -2297,6 +2347,7 @@ xhci_set_tr_dequeue_pointer ( struct xhci_device *xhci,
unsigned int mask;
unsigned int index;
unsigned int dcs;
+ physaddr_t addr;
int rc;
/* Construct command */
@@ -2305,8 +2356,8 @@ xhci_set_tr_dequeue_pointer ( struct xhci_device *xhci,
mask = ring->mask;
dcs = ( ( ~( cons >> ring->shift ) ) & XHCI_EP_DCS );
index = ( cons & mask );
- dequeue->dequeue =
- cpu_to_le64 ( virt_to_phys ( &ring->trb[index] ) | dcs );
+ addr = dma ( &ring->map, &ring->trb[index] );
+ dequeue->dequeue = cpu_to_le64 ( addr | dcs );
dequeue->slot = slot->id;
dequeue->endpoint = endpoint->ctx;
dequeue->type = XHCI_TRB_SET_TR_DEQUEUE_POINTER;
@@ -2425,6 +2476,7 @@ static void xhci_endpoint_close ( struct usb_endpoint *ep ) {
/* Cancel any incomplete transfers */
while ( xhci_ring_fill ( &endpoint->ring ) ) {
iobuf = xhci_dequeue_multi ( &endpoint->ring );
+ iob_unmap ( iobuf );
usb_complete_err ( ep, iobuf, -ECANCELED );
}
@@ -2491,6 +2543,7 @@ static int xhci_endpoint_mtu ( struct usb_endpoint *ep ) {
static int xhci_endpoint_message ( struct usb_endpoint *ep,
struct io_buffer *iobuf ) {
struct xhci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
+ struct xhci_device *xhci = endpoint->xhci;
struct usb_setup_packet *packet;
unsigned int input;
size_t len;
@@ -2520,10 +2573,15 @@ static int xhci_endpoint_message ( struct usb_endpoint *ep,
if ( len )
setup->direction = ( input ? XHCI_SETUP_IN : XHCI_SETUP_OUT );
+ /* Map I/O buffer */
+ if ( ( rc = iob_map ( iobuf, xhci->dma, len,
+ ( input ? DMA_RX : DMA_TX ) ) ) != 0 )
+ goto err_map;
+
/* Construct data stage TRB, if applicable */
if ( len ) {
data = &(trb++)->data;
- data->data = cpu_to_le64 ( virt_to_phys ( iobuf->data ) );
+ data->data = cpu_to_le64 ( iob_dma ( iobuf ) );
data->len = cpu_to_le32 ( len );
data->type = XHCI_TRB_DATA;
data->direction = ( input ? XHCI_DATA_IN : XHCI_DATA_OUT );
@@ -2539,13 +2597,18 @@ static int xhci_endpoint_message ( struct usb_endpoint *ep,
/* Enqueue TRBs */
if ( ( rc = xhci_enqueue_multi ( &endpoint->ring, iobuf, trbs,
( trb - trbs ) ) ) != 0 )
- return rc;
+ goto err_enqueue;
/* Ring the doorbell */
xhci_doorbell ( &endpoint->ring );
profile_stop ( &xhci_message_profiler );
return 0;
+
+ err_enqueue:
+ iob_unmap ( iobuf );
+ err_map:
+ return rc;
}
/**
@@ -2579,12 +2642,13 @@ static unsigned int xhci_endpoint_count ( size_t len, int zlp ) {
static int xhci_endpoint_stream ( struct usb_endpoint *ep,
struct io_buffer *iobuf, int zlp ) {
struct xhci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
- void *data = iobuf->data;
+ struct xhci_device *xhci = endpoint->xhci;
size_t len = iob_len ( iobuf );
unsigned int count = xhci_endpoint_count ( len, zlp );
union xhci_trb trbs[count];
union xhci_trb *trb = trbs;
struct xhci_trb_normal *normal;
+ physaddr_t data;
unsigned int i;
size_t trb_len;
int rc;
@@ -2592,6 +2656,13 @@ static int xhci_endpoint_stream ( struct usb_endpoint *ep,
/* Profile stream transfers */
profile_start ( &xhci_stream_profiler );
+ /* Map I/O buffer */
+ if ( ( rc = iob_map ( iobuf, xhci->dma, len,
+ ( ( ep->address & USB_DIR_IN ) ?
+ DMA_RX : DMA_TX ) ) ) != 0 )
+ goto err_map;
+ data = iob_dma ( iobuf );
+
/* Construct normal TRBs */
memset ( &trbs, 0, sizeof ( trbs ) );
for ( i = 0 ; i < count ; i ++ ) {
@@ -2603,7 +2674,7 @@ static int xhci_endpoint_stream ( struct usb_endpoint *ep,
/* Construct normal TRB */
normal = &trb->normal;
- normal->data = cpu_to_le64 ( virt_to_phys ( data ) );
+ normal->data = cpu_to_le64 ( data );
normal->len = cpu_to_le32 ( trb_len );
normal->type = XHCI_TRB_NORMAL;
normal->flags = XHCI_TRB_CH;
@@ -2624,13 +2695,18 @@ static int xhci_endpoint_stream ( struct usb_endpoint *ep,
/* Enqueue TRBs */
if ( ( rc = xhci_enqueue_multi ( &endpoint->ring, iobuf, trbs,
count ) ) != 0 )
- return rc;
+ goto err_enqueue;
/* Ring the doorbell */
xhci_doorbell ( &endpoint->ring );
profile_stop ( &xhci_stream_profiler );
return 0;
+
+ err_enqueue:
+ iob_unmap ( iobuf );
+ err_map:
+ return rc;
}
/******************************************************************************
@@ -2693,7 +2769,8 @@ static int xhci_device_open ( struct usb_device *usb ) {
/* Allocate a device context */
len = xhci_device_context_offset ( xhci, XHCI_CTX_END );
- slot->context = malloc_dma ( len, xhci_align ( len ) );
+ slot->context = dma_alloc ( xhci->dma, &slot->map, len,
+ xhci_align ( len ) );
if ( ! slot->context ) {
rc = -ENOMEM;
goto err_alloc_context;
@@ -2701,16 +2778,17 @@ static int xhci_device_open ( struct usb_device *usb ) {
memset ( slot->context, 0, len );
/* Set device context base address */
- assert ( xhci->dcbaa[id] == 0 );
- xhci->dcbaa[id] = cpu_to_le64 ( virt_to_phys ( slot->context ) );
+ assert ( xhci->dcbaa.context[id] == 0 );
+ xhci->dcbaa.context[id] = cpu_to_le64 ( dma ( &slot->map,
+ slot->context ) );
DBGC2 ( xhci, "XHCI %s slot %d device context [%08lx,%08lx) for %s\n",
xhci->name, slot->id, virt_to_phys ( slot->context ),
( virt_to_phys ( slot->context ) + len ), usb->name );
return 0;
- xhci->dcbaa[id] = 0;
- free_dma ( slot->context, len );
+ xhci->dcbaa.context[id] = 0;
+ dma_free ( &slot->map, slot->context, len );
err_alloc_context:
xhci->slot[id] = NULL;
free ( slot );
@@ -2750,8 +2828,8 @@ static void xhci_device_close ( struct usb_device *usb ) {
/* Free slot */
if ( slot->context ) {
- free_dma ( slot->context, len );
- xhci->dcbaa[id] = 0;
+ dma_free ( &slot->map, slot->context, len );
+ xhci->dcbaa.context[id] = 0;
}
xhci->slot[id] = NULL;
free ( slot );
@@ -3261,7 +3339,7 @@ static int xhci_probe ( struct pci_device *pci ) {
/* Map registers */
bar_start = pci_bar_start ( pci, XHCI_BAR );
bar_size = pci_bar_size ( pci, XHCI_BAR );
- xhci->regs = ioremap ( bar_start, bar_size );
+ xhci->regs = pci_ioremap ( pci, bar_start, bar_size );
if ( ! xhci->regs ) {
rc = -ENODEV;
goto err_ioremap;
@@ -3270,6 +3348,11 @@ static int xhci_probe ( struct pci_device *pci ) {
/* Initialise xHCI device */
xhci_init ( xhci, xhci->regs );
+ /* Configure DMA device */
+ xhci->dma = &pci->dma;
+ if ( xhci->addr64 )
+ dma_set_mask_64bit ( xhci->dma );
+
/* Initialise USB legacy support and claim ownership */
xhci_legacy_init ( xhci );
xhci_legacy_claim ( xhci );
diff --git a/src/drivers/usb/xhci.h b/src/drivers/usb/xhci.h
index e996363ea..6e02d70e0 100644
--- a/src/drivers/usb/xhci.h
+++ b/src/drivers/usb/xhci.h
@@ -854,6 +854,8 @@ struct xhci_trb_ring {
union xhci_trb *trb;
/** Length of transfer request blocks */
size_t len;
+ /** DMA mapping */
+ struct dma_mapping map;
/** Link TRB (if applicable) */
struct xhci_trb_link *link;
@@ -869,8 +871,12 @@ struct xhci_event_ring {
unsigned int cons;
/** Event ring segment table */
struct xhci_event_ring_segment *segment;
+ /** Event ring segment table DMA mapping */
+ struct dma_mapping segment_map;
/** Transfer request blocks */
union xhci_trb *trb;
+ /** Transfer request blocks DMA mapping */
+ struct dma_mapping trb_map;
};
/**
@@ -1035,10 +1041,34 @@ struct xhci_pch {
/** Invalid protocol speed ID values quirk */
#define XHCI_BAD_PSIV 0x0002
+/** Device context base address array */
+struct xhci_dcbaa {
+ /** Context base addresses */
+ uint64_t *context;
+ /** DMA mapping */
+ struct dma_mapping map;
+};
+
+/** Scratchpad buffer */
+struct xhci_scratchpad {
+ /** Number of page-sized scratchpad buffers */
+ unsigned int count;
+ /** Scratchpad buffer area */
+ userptr_t buffer;
+ /** Buffer DMA mapping */
+ struct dma_mapping buffer_map;
+ /** Scratchpad array */
+ uint64_t *array;
+ /** Array DMA mapping */
+ struct dma_mapping array_map;
+};
+
/** An xHCI device */
struct xhci_device {
/** Registers */
void *regs;
+ /** DMA device */
+ struct dma_device *dma;
/** Name */
const char *name;
/** Quirks */
@@ -1060,9 +1090,6 @@ struct xhci_device {
/** Number of ports */
unsigned int ports;
- /** Number of page-sized scratchpad buffers */
- unsigned int scratchpads;
-
/** 64-bit addressing capability */
int addr64;
/** Context size shift */
@@ -1077,12 +1104,10 @@ struct xhci_device {
unsigned int legacy;
/** Device context base address array */
- uint64_t *dcbaa;
+ struct xhci_dcbaa dcbaa;
- /** Scratchpad buffer area */
- userptr_t scratchpad;
- /** Scratchpad buffer array */
- uint64_t *scratchpad_array;
+ /** Scratchpad buffer */
+ struct xhci_scratchpad scratch;
/** Command ring */
struct xhci_trb_ring command;
@@ -1111,6 +1136,8 @@ struct xhci_slot {
unsigned int id;
/** Slot context */
struct xhci_slot_context *context;
+ /** DMA mapping */
+ struct dma_mapping map;
/** Route string */
unsigned int route;
/** Root hub port number */
diff --git a/src/hci/commands/ifmgmt_cmd.c b/src/hci/commands/ifmgmt_cmd.c
index 2e976d3fb..591cb3da8 100644
--- a/src/hci/commands/ifmgmt_cmd.c
+++ b/src/hci/commands/ifmgmt_cmd.c
@@ -250,6 +250,58 @@ int ifconf_exec ( int argc, char **argv ) {
return ifcommon_exec ( argc, argv, &ifconf_cmd );
}
+/** "iflinkwait" option list */
+struct iflinkwait_options {
+ /** Link timeout */
+ unsigned long timeout;
+};
+
+/** "iflinkwait" option list */
+static struct option_descriptor iflinkwait_opts[] = {
+ OPTION_DESC ( "timeout", 't', required_argument,
+ struct iflinkwait_options, timeout, parse_timeout ),
+};
+
+/**
+ * "iflinkwait" payload
+ *
+ * @v netdev Network device
+ * @v opts Command options
+ * @ret rc Return status code
+ */
+static int iflinkwait_payload ( struct net_device *netdev,
+ struct iflinkwait_options *opts ) {
+ int rc;
+
+ /* Wait for link-up */
+ if ( ( rc = iflinkwait ( netdev, opts->timeout, 1 ) ) != 0 ) {
+
+ /* Close device on failure, to avoid memory exhaustion */
+ netdev_close ( netdev );
+
+ return rc;
+ }
+
+ return 0;
+}
+
+/** "iflinkwait" command descriptor */
+static struct ifcommon_command_descriptor iflinkwait_cmd =
+ IFCOMMON_COMMAND_DESC ( struct iflinkwait_options, iflinkwait_opts,
+ 0, MAX_ARGUMENTS, "[<interface>...]",
+ iflinkwait_payload, 1 );
+
+/**
+ * The "iflinkwait" command
+ *
+ * @v argc Argument count
+ * @v argv Argument list
+ * @ret rc Return status code
+ */
+static int iflinkwait_exec ( int argc, char **argv ) {
+ return ifcommon_exec ( argc, argv, &iflinkwait_cmd );
+}
+
/** Interface management commands */
struct command ifmgmt_commands[] __command = {
{
@@ -268,4 +320,8 @@ struct command ifmgmt_commands[] __command = {
.name = "ifconf",
.exec = ifconf_exec,
},
+ {
+ .name = "iflinkwait",
+ .exec = iflinkwait_exec,
+ },
};
diff --git a/src/hci/commands/image_mem_cmd.c b/src/hci/commands/image_mem_cmd.c
new file mode 100644
index 000000000..c8bfab1ad
--- /dev/null
+++ b/src/hci/commands/image_mem_cmd.c
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2021 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 <getopt.h>
+#include <ipxe/command.h>
+#include <ipxe/parseopt.h>
+#include <usr/imgmgmt.h>
+
+/** @file
+ *
+ * Read memory command
+ *
+ */
+
+/** "imgmem" options */
+struct imgmem_options {
+ /** Image name */
+ char *name;
+};
+
+/** "imgmem" option list */
+static struct option_descriptor imgmem_opts[] = {
+ OPTION_DESC ( "name", 'n', required_argument,
+ struct imgmem_options, name, parse_string ),
+};
+
+/** "imgmem" command descriptor */
+static struct command_descriptor imgmem_cmd =
+ COMMAND_DESC ( struct imgmem_options, imgmem_opts, 2, 2,
+ "<address> <length>" );
+
+/**
+ * The "imgmem" command
+ *
+ * @v argc Argument count
+ * @v argv Argument list
+ * @ret rc Return status code
+ */
+static int imgmem_exec ( int argc, char **argv ) {
+ struct imgmem_options opts;
+ unsigned int data;
+ unsigned int len;
+ int rc;
+
+ /* Parse options */
+ if ( ( rc = parse_options ( argc, argv, &imgmem_cmd, &opts ) ) != 0 )
+ return rc;
+
+ /* Use start address as name if none specified */
+ if ( ! opts.name )
+ opts.name = argv[optind];
+
+ /* Parse address */
+ if ( ( rc = parse_integer ( argv[optind++], &data ) ) != 0 )
+ return rc;
+
+ /* Parse length */
+ if ( ( rc = parse_integer ( argv[optind++], &len ) ) != 0 )
+ return rc;
+
+ /* Create image */
+ if ( ( rc = imgmem ( opts.name, phys_to_user ( data ), len ) ) != 0 )
+ return rc;
+
+ return 0;
+}
+
+/** Read memory command */
+struct command imgmem_commands[] __command = {
+ {
+ .name = "imgmem",
+ .exec = imgmem_exec,
+ },
+};
diff --git a/src/hci/linux_args.c b/src/hci/linux_args.c
index 5f903e3b6..12020bd0b 100644
--- a/src/hci/linux_args.c
+++ b/src/hci/linux_args.c
@@ -18,7 +18,6 @@
FILE_LICENCE(GPL2_OR_LATER);
-#include <hci/linux_args.h>
#include <getopt.h>
#include <string.h>
#include <stdio.h>
@@ -27,21 +26,8 @@ FILE_LICENCE(GPL2_OR_LATER);
#include <ipxe/malloc.h>
#include <ipxe/init.h>
-/** Saved argc */
-static int saved_argc = 0;
-/** Saved argv */
-static char ** saved_argv;
-
-/**
- * Save argc and argv for later access.
- *
- * To be called by linuxprefix
- */
-__asmcall void save_args(int argc, char **argv)
-{
- saved_argc = argc;
- saved_argv = argv;
-}
+int linux_argc;
+char **linux_argv;
/** Supported command-line options */
static struct option options[] = {
@@ -138,7 +124,7 @@ void linux_args_parse()
while (1) {
int option_index = 0;
- c = getopt_long(saved_argc, saved_argv, "", options, &option_index);
+ c = getopt_long(linux_argc, linux_argv, "", options, &option_index);
if (c == -1)
break;
diff --git a/src/image/efi_image.c b/src/image/efi_image.c
index a112a8fcb..3c98decbf 100644
--- a/src/image/efi_image.c
+++ b/src/image/efi_image.c
@@ -26,10 +26,11 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <ipxe/efi/efi_snp.h>
#include <ipxe/efi/efi_download.h>
#include <ipxe/efi/efi_file.h>
-#include <ipxe/efi/efi_utils.h>
+#include <ipxe/efi/efi_path.h>
#include <ipxe/efi/efi_strings.h>
#include <ipxe/efi/efi_wrap.h>
#include <ipxe/efi/efi_pxe.h>
+#include <ipxe/efi/efi_driver.h>
#include <ipxe/image.h>
#include <ipxe/init.h>
#include <ipxe/features.h>
@@ -74,7 +75,7 @@ efi_image_path ( struct image *image, EFI_DEVICE_PATH_PROTOCOL *parent ) {
size_t len;
/* Calculate device path lengths */
- prefix_len = efi_devpath_len ( parent );
+ prefix_len = efi_path_len ( parent );
name_len = strlen ( image->name );
filepath_len = ( SIZE_OF_FILEPATH_DEVICE_PATH +
( name_len + 1 /* NUL */ ) * sizeof ( wchar_t ) );
@@ -140,6 +141,7 @@ static int efi_image_exec ( struct image *image ) {
void *interface;
} loaded;
EFI_HANDLE handle;
+ EFI_MEMORY_TYPE type;
wchar_t *cmdline;
EFI_STATUS efirc;
int rc;
@@ -231,6 +233,9 @@ static int efi_image_exec ( struct image *image ) {
assert ( loaded.image->LoadOptionsSize == 0 );
assert ( loaded.image->LoadOptions == NULL );
+ /* Record image code type */
+ type = loaded.image->ImageCodeType;
+
/* Set command line */
loaded.image->LoadOptions = cmdline;
loaded.image->LoadOptionsSize =
@@ -253,6 +258,12 @@ static int efi_image_exec ( struct image *image ) {
goto err_start_image;
}
+ /* If image was a driver, connect it up to anything available */
+ if ( type == EfiBootServicesCode ) {
+ DBGC ( image, "EFIIMAGE %p connecting drivers\n", image );
+ efi_driver_reconnect_all();
+ }
+
/* Success */
rc = 0;
diff --git a/src/image/embedded.c b/src/image/embedded.c
index 376e5d299..3c4bee655 100644
--- a/src/image/embedded.c
+++ b/src/image/embedded.c
@@ -83,6 +83,9 @@ static void embedded_init ( void ) {
image->name, strerror ( rc ) );
return;
}
+
+ /* Trust the selected image implicitly */
+ image_trust ( image );
}
/** Embedded image initialisation function */
diff --git a/src/include/errno.h b/src/include/errno.h
index 342384fa4..decde38ed 100644
--- a/src/include/errno.h
+++ b/src/include/errno.h
@@ -259,7 +259,7 @@ static inline void eplatform_discard ( int dummy __unused, ... ) {}
*/
#define __einfo_error( einfo ) ( { \
__asm__ ( ".section \".einfo\", \"\", " PROGBITS_OPS "\n\t" \
- ".align 8\n\t" \
+ ".balign 8\n\t" \
"\n1:\n\t" \
".long ( 4f - 1b )\n\t" \
".long %c0\n\t" \
@@ -268,7 +268,7 @@ static inline void eplatform_discard ( int dummy __unused, ... ) {}
".long %c1\n\t" \
"\n2:\t.asciz \"" __einfo_desc ( einfo ) "\"\n\t" \
"\n3:\t.asciz \"" __FILE__ "\"\n\t" \
- ".align 8\n\t" \
+ ".balign 8\n\t" \
"\n4:\n\t" \
".previous\n\t" : : \
"i" ( __einfo_errno ( einfo ) ), \
diff --git a/src/include/ipxe/acpi.h b/src/include/ipxe/acpi.h
index 78f402530..81ef7ff76 100644
--- a/src/include/ipxe/acpi.h
+++ b/src/include/ipxe/acpi.h
@@ -19,6 +19,141 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <ipxe/api.h>
#include <config/general.h>
+/** An ACPI small resource descriptor header */
+struct acpi_small_resource {
+ /** Tag byte */
+ uint8_t tag;
+} __attribute__ (( packed ));
+
+/** ACPI small resource length mask */
+#define ACPI_SMALL_LEN_MASK 0x03
+
+/** An ACPI end resource descriptor */
+#define ACPI_END_RESOURCE 0x78
+
+/** An ACPI end resource descriptor */
+struct acpi_end_resource {
+ /** Header */
+ struct acpi_small_resource hdr;
+ /** Checksum */
+ uint8_t checksum;
+} __attribute__ (( packed ));
+
+/** An ACPI large resource descriptor header */
+struct acpi_large_resource {
+ /** Tag byte */
+ uint8_t tag;
+ /** Length of data items */
+ uint16_t len;
+} __attribute__ (( packed ));
+
+/** ACPI large resource flag */
+#define ACPI_LARGE 0x80
+
+/** An ACPI QWORD address space resource descriptor */
+#define ACPI_QWORD_ADDRESS_SPACE_RESOURCE 0x8a
+
+/** An ACPI QWORD address space resource descriptor */
+struct acpi_qword_address_space_resource {
+ /** Header */
+ struct acpi_large_resource hdr;
+ /** Resource type */
+ uint8_t type;
+ /** General flags */
+ uint8_t general;
+ /** Type-specific flags */
+ uint8_t specific;
+ /** Granularity */
+ uint64_t granularity;
+ /** Minimum address */
+ uint64_t min;
+ /** Maximum address */
+ uint64_t max;
+ /** Translation offset */
+ uint64_t offset;
+ /** Length */
+ uint64_t len;
+} __attribute__ (( packed ));
+
+/** A memory address space type */
+#define ACPI_ADDRESS_TYPE_MEM 0x00
+
+/** A bus number address space type */
+#define ACPI_ADDRESS_TYPE_BUS 0x02
+
+/** An ACPI resource descriptor */
+union acpi_resource {
+ /** Tag byte */
+ uint8_t tag;
+ /** Small resource descriptor */
+ struct acpi_small_resource small;
+ /** End resource descriptor */
+ struct acpi_end_resource end;
+ /** Large resource descriptor */
+ struct acpi_large_resource large;
+ /** QWORD address space resource descriptor */
+ struct acpi_qword_address_space_resource qword;
+};
+
+/**
+ * Get ACPI resource tag
+ *
+ * @v res ACPI resource descriptor
+ * @ret tag Resource tag
+ */
+static inline unsigned int acpi_resource_tag ( union acpi_resource *res ) {
+
+ return ( ( res->tag & ACPI_LARGE ) ?
+ res->tag : ( res->tag & ~ACPI_SMALL_LEN_MASK ) );
+}
+
+/**
+ * Get length of ACPI small resource descriptor
+ *
+ * @v res Small resource descriptor
+ * @ret len Length of descriptor
+ */
+static inline size_t acpi_small_len ( struct acpi_small_resource *res ) {
+
+ return ( sizeof ( *res ) + ( res->tag & ACPI_SMALL_LEN_MASK ) );
+}
+
+/**
+ * Get length of ACPI large resource descriptor
+ *
+ * @v res Large resource descriptor
+ * @ret len Length of descriptor
+ */
+static inline size_t acpi_large_len ( struct acpi_large_resource *res ) {
+
+ return ( sizeof ( *res ) + le16_to_cpu ( res->len ) );
+}
+
+/**
+ * Get length of ACPI resource descriptor
+ *
+ * @v res ACPI resource descriptor
+ * @ret len Length of descriptor
+ */
+static inline size_t acpi_resource_len ( union acpi_resource *res ) {
+
+ return ( ( res->tag & ACPI_LARGE ) ?
+ acpi_large_len ( &res->large ) :
+ acpi_small_len ( &res->small ) );
+}
+
+/**
+ * Get next ACPI resource descriptor
+ *
+ * @v res ACPI resource descriptor
+ * @ret next Next ACPI resource descriptor
+ */
+static inline union acpi_resource *
+acpi_resource_next ( union acpi_resource *res ) {
+
+ return ( ( ( void * ) res ) + acpi_resource_len ( res ) );
+}
+
/**
* An ACPI description header
*
@@ -220,9 +355,12 @@ struct acpi_model {
#define PROVIDE_ACPI_INLINE( _subsys, _api_func ) \
PROVIDE_SINGLE_API_INLINE ( ACPI_PREFIX_ ## _subsys, _api_func )
+extern userptr_t acpi_find_via_rsdt ( uint32_t signature, unsigned int index );
+
/* Include all architecture-independent ACPI API headers */
#include <ipxe/null_acpi.h>
#include <ipxe/efi/efi_acpi.h>
+#include <ipxe/linux/linux_acpi.h>
/* Include all architecture-dependent ACPI API headers */
#include <bits/acpi.h>
@@ -234,13 +372,21 @@ struct acpi_model {
*/
userptr_t acpi_find_rsdt ( void );
+/**
+ * Locate ACPI table
+ *
+ * @v signature Requested table signature
+ * @v index Requested index of table with this signature
+ * @ret table Table, or UNULL if not found
+ */
+userptr_t acpi_find ( uint32_t signature, unsigned int index );
+
extern struct acpi_descriptor *
acpi_describe ( struct interface *interface );
#define acpi_describe_TYPE( object_type ) \
typeof ( struct acpi_descriptor * ( object_type ) )
extern void acpi_fix_checksum ( struct acpi_header *acpi );
-extern userptr_t acpi_find ( uint32_t signature, unsigned int index );
extern int acpi_sx ( uint32_t signature );
extern void acpi_add ( struct acpi_descriptor *desc );
extern void acpi_del ( struct acpi_descriptor *desc );
diff --git a/src/include/ipxe/aoe.h b/src/include/ipxe/aoe.h
index a51044d15..14d11c5cb 100644
--- a/src/include/ipxe/aoe.h
+++ b/src/include/ipxe/aoe.h
@@ -15,6 +15,8 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <ipxe/retry.h>
#include <ipxe/ata.h>
#include <ipxe/acpi.h>
+#include <ipxe/netdevice.h>
+#include <ipxe/interface.h>
/** An AoE config command */
struct aoecfg {
@@ -109,6 +111,35 @@ struct aoehdr {
/** Maximum number of sectors per packet */
#define AOE_MAX_COUNT 2
+/** An AoE device */
+struct aoe_device {
+ /** Reference counter */
+ struct refcnt refcnt;
+
+ /** Network device */
+ struct net_device *netdev;
+ /** ATA command issuing interface */
+ struct interface ata;
+
+ /** Major number */
+ uint16_t major;
+ /** Minor number */
+ uint8_t minor;
+ /** Target MAC address */
+ uint8_t target[MAX_LL_ADDR_LEN];
+
+ /** Saved timeout value */
+ unsigned long timeout;
+
+ /** Configuration command interface */
+ struct interface config;
+ /** Device is configued */
+ int configured;
+
+ /** ACPI descriptor */
+ struct acpi_descriptor desc;
+};
+
/** AoE boot firmware table signature */
#define ABFT_SIG ACPI_SIGNATURE ( 'a', 'B', 'F', 'T' )
diff --git a/src/include/ipxe/asn1.h b/src/include/ipxe/asn1.h
index efc66631d..fdf06f109 100644
--- a/src/include/ipxe/asn1.h
+++ b/src/include/ipxe/asn1.h
@@ -11,6 +11,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <stddef.h>
#include <stdint.h>
+#include <stdarg.h>
#include <assert.h>
#include <time.h>
#include <ipxe/tables.h>
@@ -75,6 +76,9 @@ struct asn1_builder_header {
/** ASN.1 enumeration */
#define ASN1_ENUMERATED 0x0a
+/** ASN.1 UTF-8 string */
+#define ASN1_UTF8_STRING 0x0c
+
/** ASN.1 UTC time */
#define ASN1_UTC_TIME 0x17
@@ -96,6 +100,10 @@ struct asn1_builder_header {
/** ASN.1 "any tag" magic value */
#define ASN1_ANY -1U
+/** Construct a short ASN.1 value */
+#define ASN1_SHORT( tag, ... ) \
+ (tag), VA_ARG_COUNT ( __VA_ARGS__ ), __VA_ARGS__
+
/** Initial OID byte */
#define ASN1_OID_INITIAL( first, second ) ( ( (first) * 40 ) + (second) )
@@ -288,10 +296,10 @@ struct asn1_builder_header {
ASN1_OID_INITIAL ( 2, 5 ), ASN1_OID_SINGLE ( 29 ), \
ASN1_OID_SINGLE ( 17 )
-/** Define an ASN.1 cursor containing an OID */
-#define ASN1_OID_CURSOR( oid_value ) { \
- .data = oid_value, \
- .len = sizeof ( oid_value ), \
+/** Define an ASN.1 cursor for a static value */
+#define ASN1_CURSOR( value ) { \
+ .data = value, \
+ .len = sizeof ( value ), \
}
/** An ASN.1 OID-identified algorithm */
@@ -313,22 +321,27 @@ struct asn1_algorithm {
#define __asn1_algorithm __table_entry ( ASN1_ALGORITHMS, 01 )
/* ASN.1 OID-identified algorithms */
-extern struct asn1_algorithm rsa_encryption_algorithm;
-extern struct asn1_algorithm md5_with_rsa_encryption_algorithm;
-extern struct asn1_algorithm sha1_with_rsa_encryption_algorithm;
-extern struct asn1_algorithm sha256_with_rsa_encryption_algorithm;
-extern struct asn1_algorithm sha384_with_rsa_encryption_algorithm;
-extern struct asn1_algorithm sha512_with_rsa_encryption_algorithm;
-extern struct asn1_algorithm sha224_with_rsa_encryption_algorithm;
-extern struct asn1_algorithm oid_md4_algorithm;
-extern struct asn1_algorithm oid_md5_algorithm;
-extern struct asn1_algorithm oid_sha1_algorithm;
-extern struct asn1_algorithm oid_sha256_algorithm;
-extern struct asn1_algorithm oid_sha384_algorithm;
-extern struct asn1_algorithm oid_sha512_algorithm;
-extern struct asn1_algorithm oid_sha224_algorithm;
-extern struct asn1_algorithm oid_sha512_224_algorithm;
-extern struct asn1_algorithm oid_sha512_256_algorithm;
+extern struct asn1_algorithm rsa_encryption_algorithm __asn1_algorithm;
+extern struct asn1_algorithm md5_with_rsa_encryption_algorithm __asn1_algorithm;
+extern struct asn1_algorithm
+sha1_with_rsa_encryption_algorithm __asn1_algorithm;
+extern struct asn1_algorithm
+sha256_with_rsa_encryption_algorithm __asn1_algorithm;
+extern struct asn1_algorithm
+sha384_with_rsa_encryption_algorithm __asn1_algorithm;
+extern struct asn1_algorithm
+sha512_with_rsa_encryption_algorithm __asn1_algorithm;
+extern struct asn1_algorithm
+sha224_with_rsa_encryption_algorithm __asn1_algorithm;
+extern struct asn1_algorithm oid_md4_algorithm __asn1_algorithm;
+extern struct asn1_algorithm oid_md5_algorithm __asn1_algorithm;
+extern struct asn1_algorithm oid_sha1_algorithm __asn1_algorithm;
+extern struct asn1_algorithm oid_sha256_algorithm __asn1_algorithm;
+extern struct asn1_algorithm oid_sha384_algorithm __asn1_algorithm;
+extern struct asn1_algorithm oid_sha512_algorithm __asn1_algorithm;
+extern struct asn1_algorithm oid_sha224_algorithm __asn1_algorithm;
+extern struct asn1_algorithm oid_sha512_224_algorithm __asn1_algorithm;
+extern struct asn1_algorithm oid_sha512_256_algorithm __asn1_algorithm;
/** An ASN.1 bit string */
struct asn1_bit_string {
diff --git a/src/include/ipxe/cachedhcp.h b/src/include/ipxe/cachedhcp.h
new file mode 100644
index 000000000..7765c6455
--- /dev/null
+++ b/src/include/ipxe/cachedhcp.h
@@ -0,0 +1,17 @@
+#ifndef _IPXE_CACHEDHCP_H
+#define _IPXE_CACHEDHCP_H
+
+/** @file
+ *
+ * Cached DHCP packet
+ *
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+#include <stddef.h>
+#include <ipxe/uaccess.h>
+
+extern int cachedhcp_record ( userptr_t data, size_t max_len );
+
+#endif /* _IPXE_CACHEDHCP_H */
diff --git a/src/include/ipxe/certstore.h b/src/include/ipxe/certstore.h
index e4c789cfd..ce96666cf 100644
--- a/src/include/ipxe/certstore.h
+++ b/src/include/ipxe/certstore.h
@@ -11,11 +11,12 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <ipxe/asn1.h>
#include <ipxe/x509.h>
+#include <ipxe/privkey.h>
extern struct x509_chain certstore;
extern struct x509_certificate * certstore_find ( struct asn1_cursor *raw );
-extern struct x509_certificate * certstore_find_key ( struct asn1_cursor *key );
+extern struct x509_certificate * certstore_find_key ( struct private_key *key );
extern void certstore_add ( struct x509_certificate *cert );
extern void certstore_del ( struct x509_certificate *cert );
diff --git a/src/include/ipxe/dma.h b/src/include/ipxe/dma.h
new file mode 100644
index 000000000..385e4baf7
--- /dev/null
+++ b/src/include/ipxe/dma.h
@@ -0,0 +1,480 @@
+#ifndef _IPXE_DMA_H
+#define _IPXE_DMA_H
+
+/** @file
+ *
+ * DMA mappings
+ *
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+#include <stdint.h>
+#include <ipxe/api.h>
+#include <ipxe/io.h>
+#include <ipxe/malloc.h>
+#include <ipxe/umalloc.h>
+#include <config/ioapi.h>
+
+#ifdef DMAAPI_OP
+#define DMAAPI_PREFIX_op
+#else
+#define DMAAPI_PREFIX_op __op_
+#endif
+
+#ifdef DMAAPI_FLAT
+#define DMAAPI_PREFIX_flat
+#else
+#define DMAAPI_PREFIX_flat __flat_
+#endif
+
+/** A DMA mapping */
+struct dma_mapping {
+ /** Address offset
+ *
+ * This is the value that must be added to a physical address
+ * within the mapping in order to produce the corresponding
+ * device-side DMA address.
+ */
+ physaddr_t offset;
+ /** DMA device (if unmapping is required) */
+ struct dma_device *dma;
+ /** Platform mapping token */
+ void *token;
+};
+
+/** A DMA-capable device */
+struct dma_device {
+ /** DMA operations */
+ struct dma_operations *op;
+ /** Addressable space mask */
+ physaddr_t mask;
+ /** Total number of mappings (for debugging) */
+ unsigned int mapped;
+ /** Total number of allocations (for debugging) */
+ unsigned int allocated;
+};
+
+/** DMA operations */
+struct dma_operations {
+ /**
+ * Map buffer for DMA
+ *
+ * @v dma DMA device
+ * @v map DMA mapping to fill in
+ * @v addr Buffer address
+ * @v len Length of buffer
+ * @v flags Mapping flags
+ * @ret rc Return status code
+ */
+ int ( * map ) ( struct dma_device *dma, struct dma_mapping *map,
+ physaddr_t addr, size_t len, int flags );
+ /**
+ * Unmap buffer
+ *
+ * @v dma DMA device
+ * @v map DMA mapping
+ */
+ void ( * unmap ) ( struct dma_device *dma, struct dma_mapping *map );
+ /**
+ * Allocate and map DMA-coherent buffer
+ *
+ * @v dma DMA device
+ * @v map DMA mapping to fill in
+ * @v len Length of buffer
+ * @v align Physical alignment
+ * @ret addr Buffer address, or NULL on error
+ */
+ void * ( * alloc ) ( struct dma_device *dma, struct dma_mapping *map,
+ size_t len, size_t align );
+ /**
+ * Unmap and free DMA-coherent buffer
+ *
+ * @v dma DMA device
+ * @v map DMA mapping
+ * @v addr Buffer address
+ * @v len Length of buffer
+ */
+ void ( * free ) ( struct dma_device *dma, struct dma_mapping *map,
+ void *addr, size_t len );
+ /**
+ * Allocate and map DMA-coherent buffer from external (user) memory
+ *
+ * @v dma DMA device
+ * @v map DMA mapping to fill in
+ * @v len Length of buffer
+ * @v align Physical alignment
+ * @ret addr Buffer address, or NULL on error
+ */
+ userptr_t ( * umalloc ) ( struct dma_device *dma,
+ struct dma_mapping *map,
+ size_t len, size_t align );
+ /**
+ * Unmap and free DMA-coherent buffer from external (user) memory
+ *
+ * @v dma DMA device
+ * @v map DMA mapping
+ * @v addr Buffer address
+ * @v len Length of buffer
+ */
+ void ( * ufree ) ( struct dma_device *dma, struct dma_mapping *map,
+ userptr_t addr, size_t len );
+ /**
+ * Set addressable space mask
+ *
+ * @v dma DMA device
+ * @v mask Addressable space mask
+ */
+ void ( * set_mask ) ( struct dma_device *dma, physaddr_t mask );
+};
+
+/** Device will read data from host memory */
+#define DMA_TX 0x01
+
+/** Device will write data to host memory */
+#define DMA_RX 0x02
+
+/** Device will both read data from and write data to host memory */
+#define DMA_BI ( DMA_TX | DMA_RX )
+
+/**
+ * Calculate static inline DMA I/O API function name
+ *
+ * @v _prefix Subsystem prefix
+ * @v _api_func API function
+ * @ret _subsys_func Subsystem API function
+ */
+#define DMAAPI_INLINE( _subsys, _api_func ) \
+ SINGLE_API_INLINE ( DMAAPI_PREFIX_ ## _subsys, _api_func )
+
+/**
+ * Provide a DMA I/O API implementation
+ *
+ * @v _prefix Subsystem prefix
+ * @v _api_func API function
+ * @v _func Implementing function
+ */
+#define PROVIDE_DMAAPI( _subsys, _api_func, _func ) \
+ PROVIDE_SINGLE_API ( DMAAPI_PREFIX_ ## _subsys, _api_func, _func )
+
+/**
+ * Provide a static inline DMA I/O API implementation
+ *
+ * @v _prefix Subsystem prefix
+ * @v _api_func API function
+ */
+#define PROVIDE_DMAAPI_INLINE( _subsys, _api_func ) \
+ PROVIDE_SINGLE_API_INLINE ( DMAAPI_PREFIX_ ## _subsys, _api_func )
+
+/**
+ * Map buffer for DMA
+ *
+ * @v dma DMA device
+ * @v map DMA mapping to fill in
+ * @v addr Buffer address
+ * @v len Length of buffer
+ * @v flags Mapping flags
+ * @ret rc Return status code
+ */
+static inline __always_inline int
+DMAAPI_INLINE ( flat, dma_map ) ( struct dma_device *dma,
+ struct dma_mapping *map,
+ physaddr_t addr __unused,
+ size_t len __unused, int flags __unused ) {
+
+ /* Increment mapping count (for debugging) */
+ if ( DBG_LOG ) {
+ map->dma = dma;
+ dma->mapped++;
+ }
+
+ return 0;
+}
+
+/**
+ * Unmap buffer
+ *
+ * @v map DMA mapping
+ */
+static inline __always_inline void
+DMAAPI_INLINE ( flat, dma_unmap ) ( struct dma_mapping *map ) {
+
+ /* Decrement mapping count (for debugging) */
+ if ( DBG_LOG ) {
+ assert ( map->dma != NULL );
+ map->dma->mapped--;
+ map->dma = NULL;
+ }
+}
+
+/**
+ * Allocate and map DMA-coherent buffer
+ *
+ * @v dma DMA device
+ * @v map DMA mapping to fill in
+ * @v len Length of buffer
+ * @v align Physical alignment
+ * @ret addr Buffer address, or NULL on error
+ */
+static inline __always_inline void *
+DMAAPI_INLINE ( flat, dma_alloc ) ( struct dma_device *dma,
+ struct dma_mapping *map,
+ size_t len, size_t align ) {
+ void *addr;
+
+ /* Allocate buffer */
+ addr = malloc_phys ( len, align );
+
+ /* Increment mapping count (for debugging) */
+ if ( DBG_LOG && addr ) {
+ map->dma = dma;
+ dma->mapped++;
+ }
+
+ return addr;
+}
+
+/**
+ * Unmap and free DMA-coherent buffer
+ *
+ * @v map DMA mapping
+ * @v addr Buffer address
+ * @v len Length of buffer
+ */
+static inline __always_inline void
+DMAAPI_INLINE ( flat, dma_free ) ( struct dma_mapping *map,
+ void *addr, size_t len ) {
+
+ /* Free buffer */
+ free_phys ( addr, len );
+
+ /* Decrement mapping count (for debugging) */
+ if ( DBG_LOG ) {
+ assert ( map->dma != NULL );
+ map->dma->mapped--;
+ map->dma = NULL;
+ }
+}
+
+/**
+ * Allocate and map DMA-coherent buffer from external (user) memory
+ *
+ * @v dma DMA device
+ * @v map DMA mapping to fill in
+ * @v len Length of buffer
+ * @v align Physical alignment
+ * @ret addr Buffer address, or NULL on error
+ */
+static inline __always_inline userptr_t
+DMAAPI_INLINE ( flat, dma_umalloc ) ( struct dma_device *dma,
+ struct dma_mapping *map,
+ size_t len, size_t align __unused ) {
+ userptr_t addr;
+
+ /* Allocate buffer */
+ addr = umalloc ( len );
+
+ /* Increment mapping count (for debugging) */
+ if ( DBG_LOG && addr ) {
+ map->dma = dma;
+ dma->mapped++;
+ }
+
+ return addr;
+}
+
+/**
+ * Unmap and free DMA-coherent buffer from external (user) memory
+ *
+ * @v map DMA mapping
+ * @v addr Buffer address
+ * @v len Length of buffer
+ */
+static inline __always_inline void
+DMAAPI_INLINE ( flat, dma_ufree ) ( struct dma_mapping *map,
+ userptr_t addr, size_t len __unused ) {
+
+ /* Free buffer */
+ ufree ( addr );
+
+ /* Decrement mapping count (for debugging) */
+ if ( DBG_LOG ) {
+ assert ( map->dma != NULL );
+ map->dma->mapped--;
+ map->dma = NULL;
+ }
+}
+
+/**
+ * Set addressable space mask
+ *
+ * @v dma DMA device
+ * @v mask Addressable space mask
+ */
+static inline __always_inline void
+DMAAPI_INLINE ( flat, dma_set_mask ) ( struct dma_device *dma __unused,
+ physaddr_t mask __unused ) {
+
+ /* Nothing to do */
+}
+
+/**
+ * Get DMA address from physical address
+ *
+ * @v map DMA mapping
+ * @v addr Physical address within the mapped region
+ * @ret addr Device-side DMA address
+ */
+static inline __always_inline physaddr_t
+DMAAPI_INLINE ( flat, dma_phys ) ( struct dma_mapping *map __unused,
+ physaddr_t addr ) {
+
+ /* Use physical address as device address */
+ return addr;
+}
+
+/**
+ * Get DMA address from physical address
+ *
+ * @v map DMA mapping
+ * @v addr Physical address within the mapped region
+ * @ret addr Device-side DMA address
+ */
+static inline __always_inline physaddr_t
+DMAAPI_INLINE ( op, dma_phys ) ( struct dma_mapping *map, physaddr_t addr ) {
+
+ /* Adjust physical address using mapping offset */
+ return ( addr + map->offset );
+}
+
+/**
+ * Map buffer for DMA
+ *
+ * @v dma DMA device
+ * @v map DMA mapping to fill in
+ * @v addr Buffer address
+ * @v len Length of buffer
+ * @v flags Mapping flags
+ * @ret rc Return status code
+ */
+int dma_map ( struct dma_device *dma, struct dma_mapping *map,
+ physaddr_t addr, size_t len, int flags );
+
+/**
+ * Unmap buffer
+ *
+ * @v map DMA mapping
+ */
+void dma_unmap ( struct dma_mapping *map );
+
+/**
+ * Allocate and map DMA-coherent buffer
+ *
+ * @v dma DMA device
+ * @v map DMA mapping to fill in
+ * @v len Length of buffer
+ * @v align Physical alignment
+ * @ret addr Buffer address, or NULL on error
+ */
+void * dma_alloc ( struct dma_device *dma, struct dma_mapping *map,
+ size_t len, size_t align );
+
+/**
+ * Unmap and free DMA-coherent buffer
+ *
+ * @v map DMA mapping
+ * @v addr Buffer address
+ * @v len Length of buffer
+ */
+void dma_free ( struct dma_mapping *map, void *addr, size_t len );
+
+/**
+ * Allocate and map DMA-coherent buffer from external (user) memory
+ *
+ * @v dma DMA device
+ * @v map DMA mapping to fill in
+ * @v len Length of buffer
+ * @v align Physical alignment
+ * @ret addr Buffer address, or NULL on error
+ */
+userptr_t dma_umalloc ( struct dma_device *dma, struct dma_mapping *map,
+ size_t len, size_t align );
+
+/**
+ * Unmap and free DMA-coherent buffer from external (user) memory
+ *
+ * @v map DMA mapping
+ * @v addr Buffer address
+ * @v len Length of buffer
+ */
+void dma_ufree ( struct dma_mapping *map, userptr_t addr, size_t len );
+
+/**
+ * Set addressable space mask
+ *
+ * @v dma DMA device
+ * @v mask Addressable space mask
+ */
+void dma_set_mask ( struct dma_device *dma, physaddr_t mask );
+
+/**
+ * Get DMA address from physical address
+ *
+ * @v map DMA mapping
+ * @v addr Physical address within the mapped region
+ * @ret addr Device-side DMA address
+ */
+physaddr_t dma_phys ( struct dma_mapping *map, physaddr_t addr );
+
+/**
+ * Get DMA address from virtual address
+ *
+ * @v map DMA mapping
+ * @v addr Virtual address within the mapped region
+ * @ret addr Device-side DMA address
+ */
+static inline __always_inline physaddr_t dma ( struct dma_mapping *map,
+ void *addr ) {
+
+ /* Get DMA address from corresponding physical address */
+ return dma_phys ( map, virt_to_phys ( addr ) );
+}
+
+/**
+ * Check if DMA unmapping is required
+ *
+ * @v map DMA mapping
+ * @v unmap Unmapping is required
+ */
+static inline __always_inline int dma_mapped ( struct dma_mapping *map ) {
+
+ /* Unmapping is required if a DMA device was recorded */
+ return ( map->dma != NULL );
+}
+
+/**
+ * Initialise DMA device
+ *
+ * @v dma DMA device
+ * @v op DMA operations
+ */
+static inline __always_inline void dma_init ( struct dma_device *dma,
+ struct dma_operations *op ) {
+
+ /* Set operations table */
+ dma->op = op;
+}
+
+/**
+ * Set 64-bit addressable space mask
+ *
+ * @v dma DMA device
+ */
+static inline __always_inline void
+dma_set_mask_64bit ( struct dma_device *dma ) {
+
+ /* Set mask to maximum physical address */
+ dma_set_mask ( dma, ~( ( physaddr_t ) 0 ) );
+}
+
+#endif /* _IPXE_DMA_H */
diff --git a/src/include/ipxe/eap.h b/src/include/ipxe/eap.h
new file mode 100644
index 000000000..6fe70189b
--- /dev/null
+++ b/src/include/ipxe/eap.h
@@ -0,0 +1,69 @@
+#ifndef _IPXE_EAP_H
+#define _IPXE_EAP_H
+
+/** @file
+ *
+ * Extensible Authentication Protocol
+ *
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+#include <stdint.h>
+#include <ipxe/netdevice.h>
+#include <ipxe/timer.h>
+
+/** EAP header */
+struct eap_header {
+ /** Code */
+ uint8_t code;
+ /** Identifier */
+ uint8_t id;
+ /** Length */
+ uint16_t len;
+} __attribute__ (( packed ));
+
+/** EAP request */
+#define EAP_CODE_REQUEST 1
+
+/** EAP request */
+struct eap_request {
+ /** Header */
+ struct eap_header hdr;
+ /** Type */
+ uint8_t type;
+} __attribute__ (( packed ));
+
+/** EAP identity */
+#define EAP_TYPE_IDENTITY 1
+
+/** EAP success */
+#define EAP_CODE_SUCCESS 3
+
+/** EAP failure */
+#define EAP_CODE_FAILURE 4
+
+/** EAP packet */
+union eap_packet {
+ /** Header */
+ struct eap_header hdr;
+ /** Request */
+ struct eap_request req;
+};
+
+/** Link block timeout
+ *
+ * We mark the link as blocked upon receiving a Request-Identity, on
+ * the basis that this most likely indicates that the switch will not
+ * yet be forwarding packets.
+ *
+ * There is no way to tell how frequently the Request-Identity packet
+ * will be retransmitted by the switch. The default value for Cisco
+ * switches seems to be 30 seconds, so treat the link as blocked for
+ * 45 seconds.
+ */
+#define EAP_BLOCK_TIMEOUT ( 45 * TICKS_PER_SEC )
+
+extern int eap_rx ( struct net_device *netdev, const void *data, size_t len );
+
+#endif /* _IPXE_EAP_H */
diff --git a/src/include/ipxe/eapol.h b/src/include/ipxe/eapol.h
index 5ca9c2815..952d6c752 100644
--- a/src/include/ipxe/eapol.h
+++ b/src/include/ipxe/eapol.h
@@ -1,114 +1,61 @@
-/*
- * Copyright (c) 2009 Joshua Oreman <oremanj@rwcr.net>.
- *
- * 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.
- */
-
#ifndef _IPXE_EAPOL_H
#define _IPXE_EAPOL_H
/** @file
*
- * Definitions for EAPOL (Extensible Authentication Protocol over
- * LANs) frames. Definitions for the packets usually encapsulated in
- * them are elsewhere.
- */
-
-#include <ipxe/tables.h>
-#include <stdint.h>
-
-FILE_LICENCE ( GPL2_OR_LATER );
-
-
-/**
- * @defgroup eapol_type EAPOL archetype identifiers
- * @{
- */
-#define EAPOL_TYPE_EAP 0 /**< EAP authentication handshake packet */
-#define EAPOL_TYPE_START 1 /**< Request by Peer to begin (no data) */
-#define EAPOL_TYPE_LOGOFF 2 /**< Request by Peer to terminate (no data) */
-#define EAPOL_TYPE_KEY 3 /**< EAPOL-Key packet */
-/** @} */
-
-/** Expected EAPOL version field value
- *
- * Version 2 is often seen and has no format differences from version 1;
- * however, many older APs will completely drop version-2 packets, so
- * we advertise ourselves as version 1.
- */
-#define EAPOL_THIS_VERSION 1
-
-/** Length of an EAPOL frame header */
-#define EAPOL_HDR_LEN 4
-
-/** An EAPOL frame
+ * Extensible Authentication Protocol over LAN (EAPoL)
*
- * This may encapsulate an eap_pkt, an eapol_key_pkt, or a Start or
- * Logoff request with no data attached. It is transmitted directly in
- * an Ethernet frame, with no IP packet header.
*/
-struct eapol_frame
-{
- /** EAPOL version identifier, always 1 */
- u8 version;
- /** EAPOL archetype identifier indicating format of payload */
- u8 type;
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
- /** Length of payload, in network byte order */
- u16 length;
+#include <stdint.h>
+#include <ipxe/netdevice.h>
+#include <ipxe/tables.h>
- /** Payload, if @a type is EAP or EAPOL-Key */
- u8 data[0];
+/** EAPoL header */
+struct eapol_header {
+ /** Version */
+ uint8_t version;
+ /** Type */
+ uint8_t type;
+ /** Payload length */
+ uint16_t len;
} __attribute__ (( packed ));
+/** 802.1X-2001 */
+#define EAPOL_VERSION_2001 1
-/** An EAPOL frame type handler
- *
- * Normally there will be at most two of these, one for EAP and one
- * for EAPOL-Key frames. The EAPOL interface code handles Start and
- * Logoff directly.
- */
-struct eapol_handler
-{
- /** EAPOL archetype identifier for payload this handler will handle */
- u8 type;
+/** EAPoL-encapsulated EAP packets */
+#define EAPOL_TYPE_EAP 0
- /** Receive EAPOL-encapsulated packet of specified type
- *
- * @v iob I/O buffer containing packet payload
- * @v netdev Network device from which packet was received
- * @V ll_dest Destination link-layer address
- * @v ll_source Source link-layer address
- * @ret rc Return status code
+/** EAPoL key */
+#define EAPOL_TYPE_KEY 5
+
+/** An EAPoL handler */
+struct eapol_handler {
+ /** Type */
+ uint8_t type;
+ /**
+ * Process received packet
*
- * The I/O buffer will have the EAPOL header pulled off it, so
- * @c iob->data points to the first byte of the payload.
+ * @v iobuf I/O buffer
+ * @v netdev Network device
+ * @v ll_source Link-layer source address
+ * @ret rc Return status code
*
- * This function takes ownership of the I/O buffer passed to it.
+ * This method takes ownership of the I/O buffer.
*/
- int ( * rx ) ( struct io_buffer *iob, struct net_device *netdev,
- const void *ll_dest, const void *ll_source );
+ int ( * rx ) ( struct io_buffer *iobuf, struct net_device *netdev,
+ const void *ll_source );
};
-#define EAPOL_HANDLERS __table ( struct eapol_handler, "eapol_handlers" )
-#define __eapol_handler __table_entry ( EAPOL_HANDLERS, 01 )
+/** EAPoL handler table */
+#define EAPOL_HANDLERS __table ( struct eapol_handler, "eapol_handlers" )
+/** Declare an EAPoL handler */
+#define __eapol_handler __table_entry ( EAPOL_HANDLERS, 01 )
extern struct net_protocol eapol_protocol __net_protocol;
-
#endif /* _IPXE_EAPOL_H */
diff --git a/src/include/ipxe/efi/efi.h b/src/include/ipxe/efi/efi.h
index b8777ef47..a83fa0f27 100644
--- a/src/include/ipxe/efi/efi.h
+++ b/src/include/ipxe/efi/efi.h
@@ -29,11 +29,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
/* EFI headers redefine ARRAY_SIZE */
#undef ARRAY_SIZE
-/* EFI headers expect ICC to define __GNUC__ */
-#if defined ( __ICC ) && ! defined ( __GNUC__ )
-#define __GNUC__ 1
-#endif
-
/* EFI headers think your compiler uses the MS ABI by default on X64 */
#if __x86_64__
#define EFIAPI __attribute__((ms_abi))
@@ -68,6 +63,14 @@ typedef struct {} *EFI_HANDLE;
#include <ipxe/version.h>
#include <ipxe/profile.h>
+/** An EFI saved task priority level */
+struct efi_saved_tpl {
+ /** Current external TPL */
+ EFI_TPL current;
+ /** Previous external TPL */
+ EFI_TPL previous;
+};
+
/** An EFI protocol used by iPXE */
struct efi_protocol {
/** GUID */
@@ -220,9 +223,11 @@ 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 EFI_TPL efi_external_tpl;
extern int efi_shutdown_in_progress;
-extern const __attribute__ (( pure )) char * efi_guid_ntoa ( EFI_GUID *guid );
+extern const __attribute__ (( pure )) char *
+efi_guid_ntoa ( CONST EFI_GUID *guid );
extern const __attribute__ (( pure )) char *
efi_locate_search_type_name ( EFI_LOCATE_SEARCH_TYPE search_type );
extern const __attribute__ (( pure )) char *
@@ -232,9 +237,19 @@ efi_devpath_text ( EFI_DEVICE_PATH_PROTOCOL *path );
extern const __attribute__ (( pure )) char *
efi_handle_name ( EFI_HANDLE handle );
+extern void dbg_efi_opener ( EFI_HANDLE handle, EFI_GUID *protocol,
+ EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *opener );
extern void dbg_efi_openers ( EFI_HANDLE handle, EFI_GUID *protocol );
extern void dbg_efi_protocols ( EFI_HANDLE handle );
+#define DBG_EFI_OPENER_IF( level, handle, protocol, \
+ opener ) do { \
+ if ( DBG_ ## level ) { \
+ dbg_efi_opener ( handle, protocol, \
+ opener ); \
+ } \
+ } while ( 0 )
+
#define DBG_EFI_OPENERS_IF( level, handle, protocol ) do { \
if ( DBG_ ## level ) { \
dbg_efi_openers ( handle, protocol ); \
@@ -247,6 +262,12 @@ extern void dbg_efi_protocols ( EFI_HANDLE handle );
} \
} while ( 0 )
+#define DBGC_EFI_OPENER_IF( level, id, ... ) do { \
+ DBG_AC_IF ( level, id ); \
+ DBG_EFI_OPENER_IF ( level, __VA_ARGS__ ); \
+ DBG_DC_IF ( level ); \
+ } while ( 0 )
+
#define DBGC_EFI_OPENERS_IF( level, id, ... ) do { \
DBG_AC_IF ( level, id ); \
DBG_EFI_OPENERS_IF ( level, __VA_ARGS__ ); \
@@ -259,21 +280,34 @@ extern void dbg_efi_protocols ( EFI_HANDLE handle );
DBG_DC_IF ( level ); \
} while ( 0 )
+#define DBGC_EFI_OPENER( ... ) \
+ DBGC_EFI_OPENER_IF ( LOG, ##__VA_ARGS__ )
#define DBGC_EFI_OPENERS( ... ) \
DBGC_EFI_OPENERS_IF ( LOG, ##__VA_ARGS__ )
#define DBGC_EFI_PROTOCOLS( ... ) \
DBGC_EFI_PROTOCOLS_IF ( LOG, ##__VA_ARGS__ )
+#define DBGC2_EFI_OPENER( ... ) \
+ DBGC_EFI_OPENER_IF ( EXTRA, ##__VA_ARGS__ )
#define DBGC2_EFI_OPENERS( ... ) \
DBGC_EFI_OPENERS_IF ( EXTRA, ##__VA_ARGS__ )
#define DBGC2_EFI_PROTOCOLS( ... ) \
DBGC_EFI_PROTOCOLS_IF ( EXTRA, ##__VA_ARGS__ )
+#define DBGCP_EFI_OPENER( ... ) \
+ DBGC_EFI_OPENER_IF ( PROFILE, ##__VA_ARGS__ )
#define DBGCP_EFI_OPENERS( ... ) \
DBGC_EFI_OPENERS_IF ( PROFILE, ##__VA_ARGS__ )
#define DBGCP_EFI_PROTOCOLS( ... ) \
DBGC_EFI_PROTOCOLS_IF ( PROFILE, ##__VA_ARGS__ )
+/* Allow for EFI-only interface operations */
+#ifdef PLATFORM_efi
+#define EFI_INTF_OP INTF_OP
+#else
+#define EFI_INTF_OP UNUSED_INTF_OP
+#endif
+
extern unsigned long __stack_chk_guard;
extern unsigned long efi_stack_cookie ( EFI_HANDLE handle );
extern void __stack_chk_fail ( void );
@@ -306,5 +340,7 @@ efi_init_stack_guard ( EFI_HANDLE handle ) {
extern EFI_STATUS efi_init ( EFI_HANDLE image_handle,
EFI_SYSTEM_TABLE *systab );
+extern void efi_raise_tpl ( struct efi_saved_tpl *tpl );
+extern void efi_restore_tpl ( struct efi_saved_tpl *tpl );
#endif /* _IPXE_EFI_H */
diff --git a/src/include/ipxe/efi/efi_acpi.h b/src/include/ipxe/efi/efi_acpi.h
index 01456f137..a698863a6 100644
--- a/src/include/ipxe/efi/efi_acpi.h
+++ b/src/include/ipxe/efi/efi_acpi.h
@@ -15,4 +15,17 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#define ACPI_PREFIX_efi __efi_
#endif
+/**
+ * Locate ACPI table
+ *
+ * @v signature Requested table signature
+ * @v index Requested index of table with this signature
+ * @ret table Table, or UNULL if not found
+ */
+static inline __attribute__ (( always_inline )) userptr_t
+ACPI_INLINE ( efi, acpi_find ) ( uint32_t signature, unsigned int index ) {
+
+ return acpi_find_via_rsdt ( signature, index );
+}
+
#endif /* _IPXE_EFI_ACPI_H */
diff --git a/src/include/ipxe/efi/efi_autoboot.h b/src/include/ipxe/efi/efi_autoboot.h
index 1d5ddc8c3..706885e28 100644
--- a/src/include/ipxe/efi/efi_autoboot.h
+++ b/src/include/ipxe/efi/efi_autoboot.h
@@ -9,6 +9,8 @@
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
-extern void efi_set_autoboot ( void );
+#include <ipxe/efi/efi.h>
+
+extern int efi_set_autoboot_ll_addr ( EFI_HANDLE device );
#endif /* _IPXE_EFI_AUTOBOOT_H */
diff --git a/src/include/ipxe/efi/efi_autoexec.h b/src/include/ipxe/efi/efi_autoexec.h
new file mode 100644
index 000000000..1f93b41cd
--- /dev/null
+++ b/src/include/ipxe/efi/efi_autoexec.h
@@ -0,0 +1,16 @@
+#ifndef _IPXE_EFI_AUTOEXEC_H
+#define _IPXE_EFI_AUTOEXEC_H
+
+/** @file
+ *
+ * EFI autoexec script
+ *
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+#include <ipxe/efi/efi.h>
+
+extern int efi_autoexec_load ( EFI_HANDLE device );
+
+#endif /* _IPXE_EFI_AUTOEXEC_H */
diff --git a/src/include/ipxe/efi/efi_blacklist.h b/src/include/ipxe/efi/efi_blacklist.h
deleted file mode 100644
index c5a5a61dc..000000000
--- a/src/include/ipxe/efi/efi_blacklist.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#ifndef _IPXE_EFI_BLACKLIST_H
-#define _IPXE_EFI_BLACKLIST_H
-
-/** @file
- *
- * EFI driver blacklist
- */
-
-FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
-
-extern void efi_unload_blacklist ( void );
-
-#endif /* _IPXE_EFI_BLACKLIST_H */
diff --git a/src/include/ipxe/efi/efi_cachedhcp.h b/src/include/ipxe/efi/efi_cachedhcp.h
new file mode 100644
index 000000000..cd60d4095
--- /dev/null
+++ b/src/include/ipxe/efi/efi_cachedhcp.h
@@ -0,0 +1,16 @@
+#ifndef _IPXE_EFI_CACHEDHCP_H
+#define _IPXE_EFI_CACHEDHCP_H
+
+/** @file
+ *
+ * EFI cached DHCP packet
+ *
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+#include <ipxe/efi/efi.h>
+
+extern int efi_cachedhcp_record ( EFI_HANDLE device );
+
+#endif /* _IPXE_EFI_CACHEDHCP_H */
diff --git a/src/include/ipxe/efi/efi_null.h b/src/include/ipxe/efi/efi_null.h
new file mode 100644
index 000000000..297457081
--- /dev/null
+++ b/src/include/ipxe/efi/efi_null.h
@@ -0,0 +1,33 @@
+#ifndef _IPXE_EFI_NULL_H
+#define _IPXE_EFI_NULL_H
+
+/** @file
+ *
+ * EFI null interfaces
+ *
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+#include <ipxe/efi/efi.h>
+#include <ipxe/efi/Protocol/AppleNetBoot.h>
+#include <ipxe/efi/Protocol/BlockIo.h>
+#include <ipxe/efi/Protocol/ComponentName2.h>
+#include <ipxe/efi/Protocol/HiiConfigAccess.h>
+#include <ipxe/efi/Protocol/LoadFile.h>
+#include <ipxe/efi/Protocol/NetworkInterfaceIdentifier.h>
+#include <ipxe/efi/Protocol/PxeBaseCode.h>
+#include <ipxe/efi/Protocol/SimpleNetwork.h>
+#include <ipxe/efi/Protocol/UsbIo.h>
+
+extern void efi_nullify_snp ( EFI_SIMPLE_NETWORK_PROTOCOL *snp );
+extern void efi_nullify_nii ( EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL *nii );
+extern void efi_nullify_name2 ( EFI_COMPONENT_NAME2_PROTOCOL *name2 );
+extern void efi_nullify_load_file ( EFI_LOAD_FILE_PROTOCOL *load_file );
+extern void efi_nullify_hii ( EFI_HII_CONFIG_ACCESS_PROTOCOL *hii );
+extern void efi_nullify_block ( EFI_BLOCK_IO_PROTOCOL *block );
+extern void efi_nullify_pxe ( EFI_PXE_BASE_CODE_PROTOCOL *pxe );
+extern void efi_nullify_apple ( EFI_APPLE_NET_BOOT_PROTOCOL *apple );
+extern void efi_nullify_usbio ( EFI_USB_IO_PROTOCOL *usbio );
+
+#endif /* _IPXE_EFI_NULL_H */
diff --git a/src/include/ipxe/efi/efi_path.h b/src/include/ipxe/efi/efi_path.h
new file mode 100644
index 000000000..76ded728c
--- /dev/null
+++ b/src/include/ipxe/efi/efi_path.h
@@ -0,0 +1,43 @@
+#ifndef _IPXE_EFI_PATH_H
+#define _IPXE_EFI_PATH_H
+
+/** @file
+ *
+ * EFI device paths
+ *
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+#include <ipxe/interface.h>
+#include <ipxe/efi/efi.h>
+#include <ipxe/efi/Protocol/DevicePath.h>
+
+struct net_device;
+struct uri;
+struct iscsi_session;
+struct aoe_device;
+struct fcp_description;
+struct ib_srp_device;
+struct usb_function;
+
+extern EFI_DEVICE_PATH_PROTOCOL *
+efi_path_end ( EFI_DEVICE_PATH_PROTOCOL *path );
+extern size_t efi_path_len ( EFI_DEVICE_PATH_PROTOCOL *path );
+extern EFI_DEVICE_PATH_PROTOCOL * efi_paths ( EFI_DEVICE_PATH_PROTOCOL *first,
+ ... );
+extern EFI_DEVICE_PATH_PROTOCOL * efi_netdev_path ( struct net_device *netdev );
+extern EFI_DEVICE_PATH_PROTOCOL * efi_uri_path ( struct uri *uri );
+extern EFI_DEVICE_PATH_PROTOCOL *
+efi_iscsi_path ( struct iscsi_session *iscsi );
+extern EFI_DEVICE_PATH_PROTOCOL * efi_aoe_path ( struct aoe_device *aoedev );
+extern EFI_DEVICE_PATH_PROTOCOL * efi_fcp_path ( struct fcp_description *desc );
+extern EFI_DEVICE_PATH_PROTOCOL *
+efi_ib_srp_path ( struct ib_srp_device *ib_srp );
+extern EFI_DEVICE_PATH_PROTOCOL * efi_usb_path ( struct usb_function *func );
+
+extern EFI_DEVICE_PATH_PROTOCOL * efi_describe ( struct interface *interface );
+#define efi_describe_TYPE( object_type ) \
+ typeof ( EFI_DEVICE_PATH_PROTOCOL * ( object_type ) )
+
+#endif /* _IPXE_EFI_PATH_H */
diff --git a/src/include/ipxe/efi/efi_pci.h b/src/include/ipxe/efi/efi_pci.h
index 6dd945f05..2ea1a8f0e 100644
--- a/src/include/ipxe/efi/efi_pci.h
+++ b/src/include/ipxe/efi/efi_pci.h
@@ -17,9 +17,17 @@ static inline EFIAPI uint64_t LShiftU64 ( UINT64 value, UINTN shift ) {
return ( value << shift );
}
+/** An EFI PCI device */
+struct efi_pci_device {
+ /** PCI device */
+ struct pci_device pci;
+ /** PCI I/O protocol */
+ EFI_PCI_IO_PROTOCOL *io;
+};
+
extern int efipci_open ( EFI_HANDLE device, UINT32 attributes,
- struct pci_device *pci );
+ struct efi_pci_device *efipci );
extern void efipci_close ( EFI_HANDLE device );
-extern int efipci_info ( EFI_HANDLE device, struct pci_device *pci );
+extern int efipci_info ( EFI_HANDLE device, struct efi_pci_device *efipci );
#endif /* _IPXE_EFI_PCI_H */
diff --git a/src/include/ipxe/efi/efi_snp.h b/src/include/ipxe/efi/efi_snp.h
index 9076f1d56..c278b1d4c 100644
--- a/src/include/ipxe/efi/efi_snp.h
+++ b/src/include/ipxe/efi/efi_snp.h
@@ -76,7 +76,7 @@ struct efi_snp_device {
};
extern int efi_snp_hii_install ( struct efi_snp_device *snpdev );
-extern void efi_snp_hii_uninstall ( struct efi_snp_device *snpdev );
+extern int 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 );
diff --git a/src/include/ipxe/efi/efi_usb.h b/src/include/ipxe/efi/efi_usb.h
index 05b4fad00..06baff529 100644
--- a/src/include/ipxe/efi/efi_usb.h
+++ b/src/include/ipxe/efi/efi_usb.h
@@ -17,14 +17,14 @@
struct efi_usb_device {
/** Name */
const char *name;
- /** The underlying USB device */
- struct usb_device *usb;
- /** The underlying EFI device */
- struct efi_device *efidev;
+ /** The underlying USB function */
+ struct usb_function *func;
/** Configuration descriptor */
struct usb_configuration_descriptor *config;
/** Supported languages */
- struct usb_descriptor_header *languages;
+ uint16_t *lang;
+ /** Length of supported languages */
+ size_t lang_len;
/** List of interfaces */
struct list_head interfaces;
};
diff --git a/src/include/ipxe/efi/efi_utils.h b/src/include/ipxe/efi/efi_utils.h
index 67acba17e..270d38dc8 100644
--- a/src/include/ipxe/efi/efi_utils.h
+++ b/src/include/ipxe/efi/efi_utils.h
@@ -9,13 +9,9 @@
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <ipxe/efi/efi.h>
-#include <ipxe/efi/Protocol/DevicePath.h>
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/src/include/ipxe/efi/efi_veto.h b/src/include/ipxe/efi/efi_veto.h
new file mode 100644
index 000000000..c9ecbb05c
--- /dev/null
+++ b/src/include/ipxe/efi/efi_veto.h
@@ -0,0 +1,13 @@
+#ifndef _IPXE_EFI_VETO_H
+#define _IPXE_EFI_VETO_H
+
+/** @file
+ *
+ * EFI driver vetoes
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+extern void efi_veto ( void );
+
+#endif /* _IPXE_EFI_VETO_H */
diff --git a/src/include/ipxe/efi/efi_wrap.h b/src/include/ipxe/efi/efi_wrap.h
index d8ed1a5cc..6c7ccf2e4 100644
--- a/src/include/ipxe/efi/efi_wrap.h
+++ b/src/include/ipxe/efi/efi_wrap.h
@@ -10,6 +10,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <ipxe/efi/efi.h>
+extern EFI_SYSTEM_TABLE * efi_wrap_systab ( void );
extern void efi_wrap ( EFI_HANDLE handle );
#endif /* _IPXE_EFI_WRAP_H */
diff --git a/src/include/ipxe/errfile.h b/src/include/ipxe/errfile.h
index 242f91f82..e3bf9f565 100644
--- a/src/include/ipxe/errfile.h
+++ b/src/include/ipxe/errfile.h
@@ -75,6 +75,8 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#define ERRFILE_sanboot ( ERRFILE_CORE | 0x00230000 )
#define ERRFILE_dummy_sanboot ( ERRFILE_CORE | 0x00240000 )
#define ERRFILE_fdt ( ERRFILE_CORE | 0x00250000 )
+#define ERRFILE_dma ( ERRFILE_CORE | 0x00260000 )
+#define ERRFILE_cachedhcp ( ERRFILE_CORE | 0x00270000 )
#define ERRFILE_eisa ( ERRFILE_DRIVER | 0x00000000 )
#define ERRFILE_isa ( ERRFILE_DRIVER | 0x00010000 )
@@ -208,6 +210,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#define ERRFILE_intelxl ( ERRFILE_DRIVER | 0x00cb0000 )
#define ERRFILE_pcimsix ( ERRFILE_DRIVER | 0x00cc0000 )
#define ERRFILE_intelxlvf ( ERRFILE_DRIVER | 0x00cd0000 )
+#define ERRFILE_usbblk ( ERRFILE_DRIVER | 0x00ce0000 )
+#define ERRFILE_iphone ( ERRFILE_DRIVER | 0x00cf0000 )
+#define ERRFILE_slirp ( ERRFILE_DRIVER | 0x00d00000 )
#define ERRFILE_aoe ( ERRFILE_NET | 0x00000000 )
#define ERRFILE_arp ( ERRFILE_NET | 0x00010000 )
@@ -284,6 +289,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#define ERRFILE_xsigo ( ERRFILE_NET | 0x00480000 )
#define ERRFILE_ntp ( ERRFILE_NET | 0x00490000 )
#define ERRFILE_httpntlm ( ERRFILE_NET | 0x004a0000 )
+#define ERRFILE_eap ( ERRFILE_NET | 0x004b0000 )
#define ERRFILE_image ( ERRFILE_IMAGE | 0x00000000 )
#define ERRFILE_elf ( ERRFILE_IMAGE | 0x00010000 )
@@ -378,7 +384,12 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#define ERRFILE_cert_cmd ( ERRFILE_OTHER | 0x004f0000 )
#define ERRFILE_acpi_settings ( ERRFILE_OTHER | 0x00500000 )
#define ERRFILE_ntlm ( ERRFILE_OTHER | 0x00510000 )
-#define ERRFILE_efi_blacklist ( ERRFILE_OTHER | 0x00520000 )
+#define ERRFILE_efi_veto ( ERRFILE_OTHER | 0x00520000 )
+#define ERRFILE_efi_autoboot ( ERRFILE_OTHER | 0x00530000 )
+#define ERRFILE_efi_autoexec ( ERRFILE_OTHER | 0x00540000 )
+#define ERRFILE_efi_cachedhcp ( ERRFILE_OTHER | 0x00550000 )
+#define ERRFILE_linux_sysfs ( ERRFILE_OTHER | 0x00560000 )
+#define ERRFILE_linux_acpi ( ERRFILE_OTHER | 0x00570000 )
/** @} */
diff --git a/src/include/ipxe/fcp.h b/src/include/ipxe/fcp.h
index 853ca13f6..d86afab42 100644
--- a/src/include/ipxe/fcp.h
+++ b/src/include/ipxe/fcp.h
@@ -163,4 +163,12 @@ struct fcp_prli_service_parameters {
/** Enhanced discovery supported */
#define FCP_PRLI_ENH_DISC 0x0800
+/** An FCP device description */
+struct fcp_description {
+ /** Fibre Channel WWN */
+ struct fc_name wwn;
+ /** SCSI LUN */
+ struct scsi_lun lun;
+};
+
#endif /* _IPXE_FCP_H */
diff --git a/src/include/ipxe/http.h b/src/include/ipxe/http.h
index 0893c9537..5a9baddcb 100644
--- a/src/include/ipxe/http.h
+++ b/src/include/ipxe/http.h
@@ -21,6 +21,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <ipxe/ntlm.h>
struct http_transaction;
+struct http_connection;
/******************************************************************************
*
@@ -43,13 +44,10 @@ struct http_scheme {
unsigned int port;
/** Transport-layer filter (if any)
*
- * @v xfer Data transfer interface
- * @v name Host name
- * @v next Next interface
+ * @v conn HTTP connection
* @ret rc Return status code
*/
- int ( * filter ) ( struct interface *xfer, const char *name,
- struct interface **next );
+ int ( * filter ) ( struct http_connection *conn );
};
/** HTTP scheme table */
diff --git a/src/include/ipxe/ib_srp.h b/src/include/ipxe/ib_srp.h
index ad407b0cf..4b6df8d3b 100644
--- a/src/include/ipxe/ib_srp.h
+++ b/src/include/ipxe/ib_srp.h
@@ -10,6 +10,8 @@
FILE_LICENCE ( BSD2 );
#include <stdint.h>
+#include <ipxe/acpi.h>
+#include <ipxe/interface.h>
#include <ipxe/infiniband.h>
#include <ipxe/srp.h>
@@ -55,4 +57,37 @@ struct sbft_ib_subtable {
uint8_t reserved[6];
} __attribute__ (( packed ));
+/**
+ * An Infiniband SRP sBFT created by iPXE
+ */
+struct ipxe_ib_sbft {
+ /** The table header */
+ struct sbft_table table;
+ /** The SCSI subtable */
+ struct sbft_scsi_subtable scsi;
+ /** The SRP subtable */
+ struct sbft_srp_subtable srp;
+ /** The Infiniband subtable */
+ struct sbft_ib_subtable ib;
+};
+
+/** An Infiniband SRP device */
+struct ib_srp_device {
+ /** Reference count */
+ struct refcnt refcnt;
+
+ /** SRP transport interface */
+ struct interface srp;
+ /** CMRC interface */
+ struct interface cmrc;
+
+ /** Infiniband device */
+ struct ib_device *ibdev;
+
+ /** ACPI descriptor */
+ struct acpi_descriptor desc;
+ /** Boot firmware table parameters */
+ struct ipxe_ib_sbft sbft;
+};
+
#endif /* _IPXE_IB_SRP_H */
diff --git a/src/include/ipxe/image.h b/src/include/ipxe/image.h
index 2e7eb4cee..4fd270081 100644
--- a/src/include/ipxe/image.h
+++ b/src/include/ipxe/image.h
@@ -175,6 +175,7 @@ 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 image_set_data ( struct image *image, userptr_t data, size_t len );
extern int register_image ( struct image *image );
extern void unregister_image ( struct image *image );
struct image * find_image ( const char *name );
@@ -183,6 +184,8 @@ extern int image_replace ( struct image *replacement );
extern int image_select ( struct image *image );
extern struct image * image_find_selected ( void );
extern int image_set_trust ( int require_trusted, int permanent );
+extern struct image * image_memory ( const char *name, userptr_t data,
+ size_t len );
extern int image_pixbuf ( struct image *image, struct pixel_buffer **pixbuf );
extern int image_asn1 ( struct image *image, size_t offset,
struct asn1_cursor **cursor );
diff --git a/src/include/ipxe/infiniband.h b/src/include/ipxe/infiniband.h
index 6f4951f17..379bc109e 100644
--- a/src/include/ipxe/infiniband.h
+++ b/src/include/ipxe/infiniband.h
@@ -416,6 +416,8 @@ struct ib_device {
struct ib_device_operations *op;
/** Port number */
unsigned int port;
+ /** Total ports on device */
+ unsigned int ports;
/** Port open request counter */
unsigned int open_count;
@@ -538,7 +540,6 @@ extern int ib_mcast_attach ( struct ib_device *ibdev, struct ib_queue_pair *qp,
union ib_gid *gid );
extern void ib_mcast_detach ( struct ib_device *ibdev,
struct ib_queue_pair *qp, union ib_gid *gid );
-extern int ib_count_ports ( struct ib_device *ibdev );
extern int ib_set_port_info ( struct ib_device *ibdev, union ib_mad *mad );
extern int ib_set_pkey_table ( struct ib_device *ibdev, union ib_mad *mad );
extern struct ib_device * alloc_ibdev ( size_t priv_size );
diff --git a/src/include/ipxe/interface.h b/src/include/ipxe/interface.h
index b65002c80..19f58a4b4 100644
--- a/src/include/ipxe/interface.h
+++ b/src/include/ipxe/interface.h
@@ -36,6 +36,21 @@ struct interface_operation {
? op_func : op_func ), \
}
+/**
+ * Define an unused object interface operation
+ *
+ * @v op_type Operation type
+ * @v object_type Implementing method's expected object type
+ * @v op_func Implementing method
+ * @ret op Object interface operation
+ */
+#define UNUSED_INTF_OP( op_type, object_type, op_func ) { \
+ .type = NULL, \
+ .func = ( ( ( ( typeof ( op_func ) * ) NULL ) == \
+ ( ( op_type ## _TYPE ( object_type ) * ) NULL ) ) \
+ ? NULL : NULL ), \
+ }
+
/** An object interface descriptor */
struct interface_descriptor {
/** Offset of interface within containing object */
@@ -154,6 +169,8 @@ extern void intfs_shutdown ( int rc, ... ) __attribute__ (( sentinel ));
extern void intf_restart ( struct interface *intf, int rc );
extern void intfs_vrestart ( va_list intfs, int rc );
extern void intfs_restart ( int rc, ... ) __attribute__ (( sentinel ));
+extern void intf_insert ( struct interface *intf, struct interface *upper,
+ struct interface *lower );
extern void intf_poke ( struct interface *intf,
void ( type ) ( struct interface *intf ) );
diff --git a/src/include/ipxe/iobuf.h b/src/include/ipxe/iobuf.h
index b40ade350..3e079c064 100644
--- a/src/include/ipxe/iobuf.h
+++ b/src/include/ipxe/iobuf.h
@@ -12,6 +12,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <stdint.h>
#include <assert.h>
#include <ipxe/list.h>
+#include <ipxe/dma.h>
/**
* Minimum I/O buffer length
@@ -38,6 +39,9 @@ struct io_buffer {
*/
struct list_head list;
+ /** DMA mapping */
+ struct dma_mapping map;
+
/** Start of the buffer */
void *head;
/** Start of data */
@@ -210,10 +214,75 @@ static inline void iob_populate ( struct io_buffer *iobuf,
(iobuf) = NULL; \
__iobuf; } )
+/**
+ * Map I/O buffer for DMA
+ *
+ * @v iobuf I/O buffer
+ * @v dma DMA device
+ * @v len Length to map
+ * @v flags Mapping flags
+ * @ret rc Return status code
+ */
+static inline __always_inline int iob_map ( struct io_buffer *iobuf,
+ struct dma_device *dma,
+ size_t len, int flags ) {
+ return dma_map ( dma, &iobuf->map, virt_to_phys ( iobuf->data ),
+ len, flags );
+}
+
+/**
+ * Map I/O buffer for transmit DMA
+ *
+ * @v iobuf I/O buffer
+ * @v dma DMA device
+ * @ret rc Return status code
+ */
+static inline __always_inline int iob_map_tx ( struct io_buffer *iobuf,
+ struct dma_device *dma ) {
+ return iob_map ( iobuf, dma, iob_len ( iobuf ), DMA_TX );
+}
+
+/**
+ * Map empty I/O buffer for receive DMA
+ *
+ * @v iobuf I/O buffer
+ * @v dma DMA device
+ * @ret rc Return status code
+ */
+static inline __always_inline int iob_map_rx ( struct io_buffer *iobuf,
+ struct dma_device *dma ) {
+ assert ( iob_len ( iobuf ) == 0 );
+ return iob_map ( iobuf, dma, iob_tailroom ( iobuf ), DMA_RX );
+}
+
+/**
+ * Get I/O buffer DMA address
+ *
+ * @v iobuf I/O buffer
+ * @ret addr DMA address
+ */
+static inline __always_inline physaddr_t iob_dma ( struct io_buffer *iobuf ) {
+ return dma ( &iobuf->map, iobuf->data );
+}
+
+/**
+ * Unmap I/O buffer for DMA
+ *
+ * @v iobuf I/O buffer
+ * @v dma DMA device
+ * @ret rc Return status code
+ */
+static inline __always_inline void iob_unmap ( struct io_buffer *iobuf ) {
+ dma_unmap ( &iobuf->map );
+}
+
extern struct io_buffer * __malloc alloc_iob_raw ( size_t len, size_t align,
size_t offset );
extern struct io_buffer * __malloc alloc_iob ( size_t len );
extern void free_iob ( struct io_buffer *iobuf );
+extern struct io_buffer * __malloc alloc_rx_iob ( size_t len,
+ struct dma_device *dma );
+extern void free_rx_iob ( struct io_buffer *iobuf );
extern void iob_pad ( struct io_buffer *iobuf, size_t min_len );
extern int iob_ensure_headroom ( struct io_buffer *iobuf, size_t len );
extern struct io_buffer * iob_concatenate ( struct list_head *list );
diff --git a/src/include/ipxe/linux/linux_acpi.h b/src/include/ipxe/linux/linux_acpi.h
new file mode 100644
index 000000000..a2c33ce2c
--- /dev/null
+++ b/src/include/ipxe/linux/linux_acpi.h
@@ -0,0 +1,18 @@
+#ifndef _IPXE_LINUX_ACPI_H
+#define _IPXE_LINUX_ACPI_H
+
+/** @file
+ *
+ * iPXE ACPI API for Linux
+ *
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+#ifdef ACPI_LINUX
+#define ACPI_PREFIX_linux
+#else
+#define ACPI_PREFIX_linux __linux_
+#endif
+
+#endif /* _IPXE_LINUX_ACPI_H */
diff --git a/src/include/ipxe/linux/linux_pci.h b/src/include/ipxe/linux/linux_pci.h
index 22ae7f1bc..de42f766b 100644
--- a/src/include/ipxe/linux/linux_pci.h
+++ b/src/include/ipxe/linux/linux_pci.h
@@ -23,6 +23,17 @@ extern int linux_pci_write ( struct pci_device *pci, unsigned long where,
unsigned long value, size_t len );
/**
+ * Determine number of PCI buses within system
+ *
+ * @ret num_bus Number of buses
+ */
+static inline __always_inline int
+PCIAPI_INLINE ( linux, pci_num_bus ) ( void ) {
+ /* Assume all buses may exist */
+ return 0x100;
+}
+
+/**
* Read byte from PCI configuration space
*
* @v pci PCI device
@@ -127,4 +138,17 @@ PCIAPI_INLINE ( linux, pci_write_config_dword ) ( struct pci_device *pci,
return linux_pci_write ( pci, where, value, sizeof ( value ) );
}
+/**
+ * Map PCI bus address as an I/O address
+ *
+ * @v bus_addr PCI bus address
+ * @v len Length of region
+ * @ret io_addr I/O address, or NULL on error
+ */
+static inline __always_inline void *
+PCIAPI_INLINE ( linux, pci_ioremap ) ( struct pci_device *pci __unused,
+ unsigned long bus_addr, size_t len ) {
+ return ioremap ( bus_addr, len );
+}
+
#endif /* _IPXE_LINUX_PCI_H */
diff --git a/src/include/ipxe/linux_api.h b/src/include/ipxe/linux_api.h
new file mode 100644
index 000000000..5b0b242d1
--- /dev/null
+++ b/src/include/ipxe/linux_api.h
@@ -0,0 +1,106 @@
+#ifndef _IPXE_LINUX_API_H
+#define _IPXE_LINUX_API_H
+
+/*
+ * Copyright (C) 2010 Piotr Jaroszyński <p.jaroszynski@gmail.com>.
+ * Copyright (C) 2021 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 St, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/** @file
+ *
+ * Linux host API
+ *
+ * This file is included from both the iPXE build environment and the
+ * host build environment.
+ *
+ */
+
+#if __STDC_HOSTED__
+#define __asmcall
+#define FILE_LICENCE(x)
+#endif
+
+FILE_LICENCE ( GPL2_OR_LATER );
+
+#include <stdint.h>
+
+#if ! __STDC_HOSTED__
+#define __KERNEL_STRICT_NAMES
+#include <linux/time.h>
+#include <linux/mman.h>
+#include <linux/fcntl.h>
+#include <linux/ioctl.h>
+#include <linux/poll.h>
+#include <linux/fs.h>
+#define MAP_FAILED ( ( void * ) -1 )
+#endif
+
+struct sockaddr;
+struct slirp_config;
+struct slirp_callbacks;
+struct Slirp;
+
+extern int linux_errno;
+extern int linux_argc;
+extern char **linux_argv;
+
+extern int __asmcall linux_open ( const char *pathname, int flags, ... );
+extern int __asmcall linux_close ( int fd );
+extern off_t __asmcall linux_lseek ( int fd, off_t offset, int whence );
+extern ssize_t __asmcall linux_read ( int fd, void *buf, size_t count );
+extern ssize_t __asmcall linux_write ( int fd, const void *buf, size_t count );
+extern int __asmcall linux_fcntl ( int fd, int cmd, ... );
+extern int __asmcall linux_ioctl ( int fd, unsigned long request, ... );
+extern int __asmcall linux_fstat_size ( int fd, size_t *size );
+extern int __asmcall linux_poll ( struct pollfd *fds, unsigned int nfds,
+ int timeout );
+extern int __asmcall linux_nanosleep ( const struct timespec *req,
+ struct timespec *rem );
+extern int __asmcall linux_usleep ( unsigned int usec );
+extern int __asmcall linux_gettimeofday ( struct timeval *tv,
+ struct timezone *tz );
+extern void * __asmcall linux_mmap ( void *addr, size_t length, int prot,
+ int flags, int fd, off_t offset );
+extern void * __asmcall linux_mremap ( void *old_address, size_t old_size,
+ size_t new_size, int flags, ... );
+extern int __asmcall linux_munmap ( void *addr, size_t length );
+extern int __asmcall linux_socket ( int domain, int type, int protocol );
+extern int __asmcall linux_bind ( int sockfd, const struct sockaddr *addr,
+ size_t addrlen );
+extern ssize_t __asmcall linux_sendto ( int sockfd, const void *buf,
+ size_t len, int flags,
+ const struct sockaddr *dest_addr,
+ size_t addrlen );
+extern const char * __asmcall linux_strerror ( int linux_errno );
+extern struct Slirp * __asmcall
+linux_slirp_new ( const struct slirp_config *config,
+ const struct slirp_callbacks *callbacks, void *opaque );
+extern void __asmcall linux_slirp_cleanup ( struct Slirp *slirp );
+extern void __asmcall linux_slirp_input ( struct Slirp *slirp,
+ const uint8_t *pkt, int pkt_len );
+extern void __asmcall
+linux_slirp_pollfds_fill ( struct Slirp *slirp, uint32_t *timeout,
+ int ( __asmcall * add_poll ) ( int fd, int events,
+ void *opaque ),
+ void *opaque );
+extern void __asmcall
+linux_slirp_pollfds_poll ( struct Slirp *slirp, int select_error,
+ int ( __asmcall * get_revents ) ( int idx,
+ void *opaque ),
+ void *opaque );
+
+#endif /* _IPXE_LINUX_API_H */
diff --git a/src/include/ipxe/linux_sysfs.h b/src/include/ipxe/linux_sysfs.h
new file mode 100644
index 000000000..d97b649c0
--- /dev/null
+++ b/src/include/ipxe/linux_sysfs.h
@@ -0,0 +1,16 @@
+#ifndef _IPXE_LINUX_SYSFS_H
+#define _IPXE_LINUX_SYSFS_H
+
+/** @file
+ *
+ * Linux sysfs files
+ *
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER );
+
+#include <ipxe/uaccess.h>
+
+extern int linux_sysfs_read ( const char *filename, userptr_t *data );
+
+#endif /* _IPXE_LINUX_SYSFS_H */
diff --git a/src/include/ipxe/malloc.h b/src/include/ipxe/malloc.h
index 1878978fd..180ca001d 100644
--- a/src/include/ipxe/malloc.h
+++ b/src/include/ipxe/malloc.h
@@ -14,7 +14,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/*
* Prototypes for the standard functions (malloc() et al) are in
* stdlib.h. Include <ipxe/malloc.h> only if you need the
- * non-standard functions, such as malloc_dma().
+ * non-standard functions, such as malloc_phys().
*
*/
#include <stdlib.h>
@@ -32,20 +32,18 @@ extern void mpopulate ( void *start, size_t len );
extern void mdumpfree ( void );
/**
- * Allocate memory for DMA
+ * Allocate memory with specified physical alignment and offset
*
* @v size Requested size
* @v align Physical alignment
* @v offset Offset from physical alignment
* @ret ptr Memory, or NULL
*
- * Allocates physically-aligned memory for DMA.
- *
* @c align must be a power of two. @c size may not be zero.
*/
-static inline void * __malloc malloc_dma_offset ( size_t size,
- size_t phys_align,
- size_t offset ) {
+static inline void * __malloc malloc_phys_offset ( size_t size,
+ size_t phys_align,
+ size_t offset ) {
void * ptr = alloc_memblock ( size, phys_align, offset );
if ( ptr && size )
VALGRIND_MALLOCLIKE_BLOCK ( ptr, size, 0, 0 );
@@ -53,32 +51,30 @@ static inline void * __malloc malloc_dma_offset ( size_t size,
}
/**
- * Allocate memory for DMA
+ * Allocate memory with specified physical alignment
*
* @v size Requested size
* @v align Physical alignment
* @ret ptr Memory, or NULL
*
- * Allocates physically-aligned memory for DMA.
- *
* @c align must be a power of two. @c size may not be zero.
*/
-static inline void * __malloc malloc_dma ( size_t size, size_t phys_align ) {
- return malloc_dma_offset ( size, phys_align, 0 );
+static inline void * __malloc malloc_phys ( size_t size, size_t phys_align ) {
+ return malloc_phys_offset ( size, phys_align, 0 );
}
/**
- * Free memory allocated with malloc_dma()
+ * Free memory allocated with malloc_phys()
*
- * @v ptr Memory allocated by malloc_dma(), or NULL
- * @v size Size of memory, as passed to malloc_dma()
+ * @v ptr Memory allocated by malloc_phys(), or NULL
+ * @v size Size of memory, as passed to malloc_phys()
*
- * Memory allocated with malloc_dma() can only be freed with
- * free_dma(); it cannot be freed with the standard free().
+ * Memory allocated with malloc_phys() can only be freed with
+ * free_phys(); it cannot be freed with the standard free().
*
* If @c ptr is NULL, no action is taken.
*/
-static inline void free_dma ( void *ptr, size_t size ) {
+static inline void free_phys ( void *ptr, size_t size ) {
VALGRIND_FREELIKE_BLOCK ( ptr, 0 );
free_memblock ( ptr, size );
}
diff --git a/src/include/ipxe/netdevice.h b/src/include/ipxe/netdevice.h
index d498ab697..b9c651c71 100644
--- a/src/include/ipxe/netdevice.h
+++ b/src/include/ipxe/netdevice.h
@@ -246,6 +246,10 @@ struct net_device_operations {
*
* This method is guaranteed to be called only when the device
* is open.
+ *
+ * If the network device has an associated DMA device, then
+ * the I/O buffer will be automatically mapped for transmit
+ * DMA.
*/
int ( * transmit ) ( struct net_device *netdev,
struct io_buffer *iobuf );
@@ -358,6 +362,8 @@ struct net_device {
char name[NETDEV_NAME_LEN];
/** Underlying hardware device */
struct device *dev;
+ /** DMA device */
+ struct dma_device *dma;
/** Network device operations */
struct net_device_operations *op;
diff --git a/src/include/ipxe/null_acpi.h b/src/include/ipxe/null_acpi.h
index 1e469e33d..cedb02839 100644
--- a/src/include/ipxe/null_acpi.h
+++ b/src/include/ipxe/null_acpi.h
@@ -15,8 +15,10 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#define ACPI_PREFIX_null __null_
#endif
-static inline __always_inline userptr_t
-ACPI_INLINE ( null, acpi_find_rsdt ) ( void ) {
+static inline __attribute__ (( always_inline )) userptr_t
+ACPI_INLINE ( null, acpi_find ) ( uint32_t signature __unused,
+ unsigned int index __unused ) {
+
return UNULL;
}
diff --git a/src/include/ipxe/pci.h b/src/include/ipxe/pci.h
index 272c4c06f..6632c574d 100644
--- a/src/include/ipxe/pci.h
+++ b/src/include/ipxe/pci.h
@@ -12,6 +12,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <stdint.h>
#include <ipxe/device.h>
#include <ipxe/tables.h>
+#include <ipxe/dma.h>
#include <ipxe/pci_io.h>
/** PCI vendor ID */
@@ -187,6 +188,8 @@ struct pci_class_id {
struct pci_device {
/** Generic device */
struct device dev;
+ /** DMA device */
+ struct dma_device dma;
/** Memory base
*
* This is the physical address of the first valid memory BAR.
diff --git a/src/include/ipxe/pci_io.h b/src/include/ipxe/pci_io.h
index 10e69763e..2dcdd9b28 100644
--- a/src/include/ipxe/pci_io.h
+++ b/src/include/ipxe/pci_io.h
@@ -11,6 +11,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <stdint.h>
#include <ipxe/api.h>
+#include <ipxe/iomap.h>
#include <config/ioapi.h>
/**
@@ -122,4 +123,14 @@ int pci_write_config_word ( struct pci_device *pci, unsigned int where,
int pci_write_config_dword ( struct pci_device *pci, unsigned int where,
uint32_t value );
+/**
+ * Map PCI bus address as an I/O address
+ *
+ * @v bus_addr PCI bus address
+ * @v len Length of region
+ * @ret io_addr I/O address, or NULL on error
+ */
+void * pci_ioremap ( struct pci_device *pci, unsigned long bus_addr,
+ size_t len );
+
#endif /* _IPXE_PCI_IO_H */
diff --git a/src/include/ipxe/privkey.h b/src/include/ipxe/privkey.h
index 81108b6bf..a65cf6106 100644
--- a/src/include/ipxe/privkey.h
+++ b/src/include/ipxe/privkey.h
@@ -10,7 +10,60 @@
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <ipxe/asn1.h>
+#include <ipxe/refcnt.h>
-extern struct asn1_cursor private_key;
+/** A private key */
+struct private_key {
+ /** Reference counter */
+ struct refcnt refcnt;
+ /** ASN.1 object builder */
+ struct asn1_builder builder;
+};
+
+/**
+ * Get reference to private key
+ *
+ * @v key Private key
+ * @ret key Private key
+ */
+static inline __attribute__ (( always_inline )) struct private_key *
+privkey_get ( struct private_key *key ) {
+ ref_get ( &key->refcnt );
+ return key;
+}
+
+/**
+ * Drop reference to private key
+ *
+ * @v key Private key
+ */
+static inline __attribute__ (( always_inline )) void
+privkey_put ( struct private_key *key ) {
+ ref_put ( &key->refcnt );
+}
+
+/**
+ * Get private key ASN.1 cursor
+ *
+ * @v key Private key
+ * @ret cursor ASN.1 cursor
+ */
+static inline __attribute__ (( always_inline )) struct asn1_cursor *
+privkey_cursor ( struct private_key *key ) {
+ return asn1_built ( &key->builder );
+}
+
+extern void privkey_free ( struct refcnt *refcnt );
+
+/**
+ * Initialise empty private key
+ *
+ */
+static inline __attribute__ (( always_inline )) void
+privkey_init ( struct private_key *key ) {
+ ref_init ( &key->refcnt, privkey_free );
+}
+
+extern struct private_key private_key;
#endif /* _IPXE_PRIVKEY_H */
diff --git a/src/include/ipxe/slirp.h b/src/include/ipxe/slirp.h
new file mode 100644
index 000000000..4fb13b934
--- /dev/null
+++ b/src/include/ipxe/slirp.h
@@ -0,0 +1,155 @@
+#ifndef _IPXE_SLIRP_H
+#define _IPXE_SLIRP_H
+
+/** @file
+ *
+ * Linux Slirp network driver
+ *
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER );
+
+#include <stdint.h>
+#include <stdbool.h>
+
+/** Ready to be read */
+#define SLIRP_EVENT_IN 0x01
+
+/** Ready to be written */
+#define SLIRP_EVENT_OUT 0x02
+
+/** Exceptional condition */
+#define SLIRP_EVENT_PRI 0x04
+
+/** Error condition */
+#define SLIRP_EVENT_ERR 0x08
+
+/** Hang up */
+#define SLIRP_EVENT_HUP 0x10
+
+/** Slirp device configuration */
+struct slirp_config {
+ /** Configuration version */
+ uint32_t version;
+ /** Restrict to host loopback connections only */
+ int restricted;
+ /** IPv4 is enabled */
+ bool in_enabled;
+ /** IPv4 network */
+ struct in_addr vnetwork;
+ /** IPv4 netmask */
+ struct in_addr vnetmask;
+ /** IPv4 host server address */
+ struct in_addr vhost;
+ /** IPv6 is enabled */
+ bool in6_enabled;
+ /** IPv6 prefix */
+ struct in6_addr vprefix_addr6;
+ /** IPv6 prefix length */
+ uint8_t vprefix_len;
+ /** IPv6 host server address */
+ struct in6_addr vhost6;
+ /** Client hostname */
+ const char *vhostname;
+ /** TFTP server name */
+ const char *tftp_server_name;
+ /** TFTP path prefix */
+ const char *tftp_path;
+ /** Boot filename */
+ const char *bootfile;
+ /** DHCPv4 start address */
+ struct in_addr vdhcp_start;
+ /** DNS IPv4 address */
+ struct in_addr vnameserver;
+ /** DNS IPv6 address */
+ struct in_addr vnameserver6;
+ /** DNS search list */
+ const char **vdnssearch;
+ /** Domain name */
+ const char *vdomainname;
+ /** Interface MTU */
+ size_t if_mtu;
+ /** Interface MRU */
+ size_t if_mru;
+ /** Disable host loopback connections */
+ bool disable_host_loopback;
+ /** Enable emulation (apparently unsafe) */
+ bool enable_emu;
+};
+
+/** Slirp device callbacks */
+struct slirp_callbacks {
+ /**
+ * Send packet
+ *
+ * @v buf Data buffer
+ * @v len Length of data
+ * @v device Device opaque pointer
+ * @ret len Consumed length (or negative on error)
+ */
+ ssize_t ( __asmcall * send_packet ) ( const void *buf, size_t len,
+ void *device );
+ /**
+ * Print an error message
+ *
+ * @v msg Error message
+ * @v device Device opaque pointer
+ */
+ void ( __asmcall * guest_error ) ( const char *msg, void *device );
+ /**
+ * Get virtual clock
+ *
+ * @v device Device opaque pointer
+ * @ret clock_ns Clock time in nanoseconds
+ */
+ int64_t ( __asmcall * clock_get_ns ) ( void *device );
+ /**
+ * Create a new timer
+ *
+ * @v callback Timer callback
+ * @v opaque Timer opaque pointer
+ * @v device Device opaque pointer
+ * @ret timer Timer
+ */
+ void * ( __asmcall * timer_new ) ( void ( __asmcall * callback )
+ ( void *opaque ),
+ void *opaque, void *device );
+ /**
+ * Delete a timer
+ *
+ * @v timer Timer
+ * @v device Device opaque pointer
+ */
+ void ( __asmcall * timer_free ) ( void *timer, void *device );
+ /**
+ * Set timer expiry time
+ *
+ * @v timer Timer
+ * @v expire Expiry time
+ * @v device Device opaque pointer
+ */
+ void ( __asmcall * timer_mod ) ( void *timer, int64_t expire,
+ void *device );
+ /**
+ * Register file descriptor for polling
+ *
+ * @v fd File descriptor
+ * @v device Device opaque pointer
+ */
+ void ( __asmcall * register_poll_fd ) ( int fd, void *device );
+ /**
+ * Unregister file descriptor
+ *
+ * @v fd File descriptor
+ * @v device Device opaque pointer
+ */
+ void ( __asmcall * unregister_poll_fd ) ( int fd, void *device );
+ /**
+ * Notify that new events are ready
+ *
+ * @v device Device opaque pointer
+ */
+ void ( __asmcall * notify ) ( void *device );
+};
+
+#endif /* _IPXE_SLIRP_H */
diff --git a/src/include/ipxe/smbios.h b/src/include/ipxe/smbios.h
index c1d8fea3e..42278fb24 100644
--- a/src/include/ipxe/smbios.h
+++ b/src/include/ipxe/smbios.h
@@ -31,15 +31,20 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/* Include all architecture-dependent SMBIOS API headers */
#include <bits/smbios.h>
-/** Signature for SMBIOS entry point */
+/** Signature for 32-bit SMBIOS entry point */
#define SMBIOS_SIGNATURE \
( ( '_' << 0 ) + ( 'S' << 8 ) + ( 'M' << 16 ) + ( '_' << 24 ) )
+/** Signature for 64-bit SMBIOS entry point */
+#define SMBIOS3_SIGNATURE \
+ ( ( '_' << 0 ) + ( 'S' << 8 ) + ( 'M' << 16 ) + ( '3' << 24 ) )
+
/**
- * SMBIOS entry point
+ * SMBIOS 32-bit entry point
*
- * This is the single table which describes the list of SMBIOS
- * structures. It is located by scanning through the BIOS segment.
+ * This is the 32-bit version of the table which describes the list of
+ * SMBIOS structures. It may be located by scanning through the BIOS
+ * segment or via an EFI configuration table.
*/
struct smbios_entry {
/** Signature
@@ -75,6 +80,41 @@ struct smbios_entry {
uint8_t bcd_revision;
} __attribute__ (( packed ));
+/**
+ * SMBIOS 64-bit entry point
+ *
+ * This is the 64-bit version of the table which describes the list of
+ * SMBIOS structures. It may be located by scanning through the BIOS
+ * segment or via an EFI configuration table.
+ */
+struct smbios3_entry {
+ /** Signature
+ *
+ * Must be equal to SMBIOS3_SIGNATURE
+ */
+ uint32_t signature;
+ /** Signature extra byte */
+ uint8_t extra;
+ /** Checksum */
+ uint8_t checksum;
+ /** Length */
+ uint8_t len;
+ /** Major version */
+ uint8_t major;
+ /** Minor version */
+ uint8_t minor;
+ /** Documentation revision */
+ uint8_t docrev;
+ /** Entry point revision */
+ uint8_t revision;
+ /** Reserved */
+ uint8_t reserved;
+ /** Structure table length */
+ uint32_t smbios_len;
+ /** Structure table address */
+ uint64_t smbios_address;
+} __attribute__ (( packed ));
+
/** An SMBIOS structure header */
struct smbios_header {
/** Type */
@@ -155,6 +195,9 @@ struct smbios_enclosure_information {
/** SMBIOS OEM strings structure type */
#define SMBIOS_TYPE_OEM_STRINGS 11
+/** SMBIOS end of table type */
+#define SMBIOS_TYPE_END 127
+
/**
* SMBIOS entry point descriptor
*
@@ -192,5 +235,6 @@ extern int read_smbios_string ( struct smbios_structure *structure,
unsigned int index,
void *data, size_t len );
extern int smbios_version ( void );
+extern void smbios_clear ( void );
#endif /* _IPXE_SMBIOS_H */
diff --git a/src/include/ipxe/tables.h b/src/include/ipxe/tables.h
index 60f8efdea..28a87da96 100644
--- a/src/include/ipxe/tables.h
+++ b/src/include/ipxe/tables.h
@@ -444,75 +444,4 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
pointer >= table_start ( table ) ; \
pointer-- )
-/******************************************************************************
- *
- * Intel's C compiler chokes on several of the constructs used in this
- * file. The workarounds are ugly, so we use them only for an icc
- * build.
- *
- */
-#define ICC_ALIGN_HACK_FACTOR 128
-#ifdef __ICC
-
-/*
- * icc miscompiles zero-length arrays by inserting padding to a length
- * of two array elements. We therefore have to generate the
- * __table_entries() symbols by hand in asm.
- *
- */
-#undef __table_entries
-#define __table_entries( table, idx ) ( { \
- extern __table_type ( table ) \
- __table_temp_sym ( idx, __LINE__ ) [] \
- __table_entry ( table, idx ) \
- asm ( __table_entries_sym ( table, idx ) ); \
- __asm__ ( ".ifndef %c0\n\t" \
- ".section " __table_section ( table, idx ) "\n\t" \
- ".align %c1\n\t" \
- "\n%c0:\n\t" \
- ".previous\n\t" \
- ".endif\n\t" \
- : : "i" ( __table_temp_sym ( idx, __LINE__ ) ), \
- "i" ( __table_alignment ( table ) ) ); \
- __table_temp_sym ( idx, __LINE__ ); } )
-#define __table_entries_sym( table, idx ) \
- "__tbl_" __table_name ( table ) "_" #idx
-#define __table_temp_sym( a, b ) \
- ___table_temp_sym( __table_, a, _, b )
-#define ___table_temp_sym( a, b, c, d ) a ## b ## c ## d
-
-/*
- * icc ignores __attribute__ (( aligned (x) )) when it is used to
- * decrease the compiler's default choice of alignment (which may be
- * higher than the alignment actually required by the structure). We
- * work around this by forcing the alignment to a large multiple of
- * the required value (so that we are never attempting to decrease the
- * default alignment) and then postprocessing the object file to
- * reduce the alignment back down to the "real" value.
- *
- */
-#undef __table_alignment
-#define __table_alignment( table ) \
- ( ICC_ALIGN_HACK_FACTOR * __alignof__ ( __table_type ( table ) ) )
-
-/*
- * Because of the alignment hack, we must ensure that the compiler
- * never tries to place multiple objects within the same section,
- * otherwise the assembler will insert padding to the (incorrect)
- * alignment boundary. Do this by appending the line number to table
- * section names.
- *
- * Note that we don't need to worry about padding between array
- * elements, since the alignment is declared on the variable (i.e. the
- * whole array) rather than on the type (i.e. on all individual array
- * elements).
- */
-#undef __table_section
-#define __table_section( table, idx ) \
- ".tbl." __table_name ( table ) "." __table_str ( idx ) \
- "." __table_xstr ( __LINE__ )
-#define __table_xstr( x ) __table_str ( x )
-
-#endif /* __ICC */
-
#endif /* _IPXE_TABLES_H */
diff --git a/src/include/ipxe/tls.h b/src/include/ipxe/tls.h
index febbdc589..8b03579cc 100644
--- a/src/include/ipxe/tls.h
+++ b/src/include/ipxe/tls.h
@@ -18,6 +18,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <ipxe/sha1.h>
#include <ipxe/sha256.h>
#include <ipxe/x509.h>
+#include <ipxe/privkey.h>
#include <ipxe/pending.h>
#include <ipxe/iobuf.h>
#include <ipxe/tables.h>
@@ -255,6 +256,11 @@ struct tls_session {
/** Server name */
const char *name;
+ /** Root of trust */
+ struct x509_root *root;
+ /** Private key */
+ struct private_key *key;
+
/** Session ID */
uint8_t id[32];
/** Length of session ID */
@@ -319,13 +325,17 @@ struct tls_connection {
struct digest_algorithm *handshake_digest;
/** Digest algorithm context used for handshake verification */
uint8_t *handshake_ctx;
- /** Client certificate (if used) */
- struct x509_certificate *cert;
+ /** Private key */
+ struct private_key *key;
+ /** Client certificate chain (if used) */
+ struct x509_chain *certs;
/** Secure renegotiation flag */
int secure_renegotiation;
/** Verification data */
struct tls_verify_data verify;
+ /** Root of trust */
+ struct x509_root *root;
/** Server certificate chain */
struct x509_chain *chain;
/** Certificate validator */
@@ -379,6 +389,6 @@ struct tls_connection {
#define TLS_RX_ALIGN 16
extern int add_tls ( struct interface *xfer, const char *name,
- struct interface **next );
+ struct x509_root *root, struct private_key *key );
#endif /* _IPXE_TLS_H */
diff --git a/src/include/ipxe/usb.h b/src/include/ipxe/usb.h
index 68289d26d..911247ede 100644
--- a/src/include/ipxe/usb.h
+++ b/src/include/ipxe/usb.h
@@ -580,6 +580,7 @@ usb_endpoint_described ( struct usb_endpoint *ep,
struct usb_interface_descriptor *interface,
unsigned int type, unsigned int index );
extern int usb_endpoint_open ( struct usb_endpoint *ep );
+extern int usb_endpoint_clear_halt ( struct usb_endpoint *ep );
extern void usb_endpoint_close ( struct usb_endpoint *ep );
extern int usb_message ( struct usb_endpoint *ep, unsigned int request,
unsigned int value, unsigned int index,
@@ -620,6 +621,7 @@ usb_recycle ( struct usb_endpoint *ep, struct io_buffer *iobuf ) {
}
extern int usb_prefill ( struct usb_endpoint *ep );
+extern int usb_refill_limit ( struct usb_endpoint *ep, unsigned int max );
extern int usb_refill ( struct usb_endpoint *ep );
extern void usb_flush ( struct usb_endpoint *ep );
@@ -1237,6 +1239,23 @@ usb_set_interface ( struct usb_device *usb, unsigned int interface,
NULL, 0 );
}
+/**
+ * Get USB depth
+ *
+ * @v usb USB device
+ * @ret depth Hub depth
+ */
+static inline unsigned int usb_depth ( struct usb_device *usb ) {
+ struct usb_device *parent;
+ unsigned int depth;
+
+ /* Navigate up to root hub, constructing depth as we go */
+ for ( depth = 0 ; ( parent = usb->port->hub->usb ) ; usb = parent )
+ depth++;
+
+ return depth;
+}
+
extern struct list_head usb_buses;
extern struct usb_interface_descriptor *
@@ -1272,7 +1291,6 @@ extern struct usb_bus * find_usb_bus_by_location ( unsigned int bus_type,
extern int usb_alloc_address ( struct usb_bus *bus );
extern void usb_free_address ( struct usb_bus *bus, unsigned int address );
extern unsigned int usb_route_string ( struct usb_device *usb );
-extern unsigned int usb_depth ( struct usb_device *usb );
extern struct usb_port * usb_root_hub_port ( struct usb_device *usb );
extern struct usb_port * usb_transaction_translator ( struct usb_device *usb );
@@ -1396,6 +1414,9 @@ struct usb_driver {
/** Declare a USB driver */
#define __usb_driver __table_entry ( USB_DRIVERS, 01 )
+/** Declare a USB fallback driver */
+#define __usb_fallback_driver __table_entry ( USB_DRIVERS, 02 )
+
/** USB driver scores */
enum usb_driver_score {
/** Fallback driver (has no effect on overall score) */
diff --git a/src/include/ipxe/validator.h b/src/include/ipxe/validator.h
index 0aee56eb0..367e4045d 100644
--- a/src/include/ipxe/validator.h
+++ b/src/include/ipxe/validator.h
@@ -12,6 +12,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <ipxe/interface.h>
#include <ipxe/x509.h>
-extern int create_validator ( struct interface *job, struct x509_chain *chain );
+extern int create_validator ( struct interface *job, struct x509_chain *chain,
+ struct x509_root *root );
#endif /* _IPXE_VALIDATOR_H */
diff --git a/src/include/ipxe/x509.h b/src/include/ipxe/x509.h
index 78eeafbfb..c703c8f10 100644
--- a/src/include/ipxe/x509.h
+++ b/src/include/ipxe/x509.h
@@ -191,6 +191,8 @@ struct x509_certificate {
/** Flags */
unsigned int flags;
+ /** Root against which certificate has been validated (if any) */
+ struct x509_root *root;
/** Maximum number of subsequent certificates in chain */
unsigned int path_remaining;
@@ -218,12 +220,10 @@ struct x509_certificate {
/** X.509 certificate flags */
enum x509_flags {
- /** Certificate has been validated */
- X509_FL_VALIDATED = 0x0001,
/** Certificate was added at build time */
- X509_FL_PERMANENT = 0x0002,
+ X509_FL_PERMANENT = 0x0001,
/** Certificate was added explicitly at run time */
- X509_FL_EXPLICIT = 0x0004,
+ X509_FL_EXPLICIT = 0x0002,
};
/**
@@ -340,8 +340,10 @@ struct x509_access_method {
const struct asn1_cursor *raw );
};
-/** An X.509 root certificate store */
+/** An X.509 root certificate list */
struct x509_root {
+ /** Reference count */
+ struct refcnt refcnt;
/** Fingerprint digest algorithm */
struct digest_algorithm *digest;
/** Number of certificates */
@@ -350,11 +352,35 @@ struct x509_root {
const void *fingerprints;
};
+/**
+ * Get reference to X.509 root certificate list
+ *
+ * @v root X.509 root certificate list
+ * @ret root X.509 root certificate list
+ */
+static inline __attribute__ (( always_inline )) struct x509_root *
+x509_root_get ( struct x509_root *root ) {
+ ref_get ( &root->refcnt );
+ return root;
+}
+
+/**
+ * Drop reference to X.509 root certificate list
+ *
+ * @v root X.509 root certificate list
+ */
+static inline __attribute__ (( always_inline )) void
+x509_root_put ( struct x509_root *root ) {
+ ref_put ( &root->refcnt );
+}
+
extern const char * x509_name ( struct x509_certificate *cert );
extern int x509_parse ( struct x509_certificate *cert,
const struct asn1_cursor *raw );
extern int x509_certificate ( const void *data, size_t len,
struct x509_certificate **cert );
+extern int x509_is_valid ( struct x509_certificate *cert,
+ struct x509_root *root );
extern int x509_validate ( struct x509_certificate *cert,
struct x509_certificate *issuer,
time_t time, struct x509_root *root );
@@ -384,21 +410,13 @@ extern int x509_check_root ( struct x509_certificate *cert,
extern int x509_check_time ( struct x509_certificate *cert, time_t time );
/**
- * Check if X.509 certificate is valid
- *
- * @v cert X.509 certificate
- */
-static inline int x509_is_valid ( struct x509_certificate *cert ) {
- return ( cert->flags & X509_FL_VALIDATED );
-}
-
-/**
* Invalidate X.509 certificate
*
* @v cert X.509 certificate
*/
static inline void x509_invalidate ( struct x509_certificate *cert ) {
- cert->flags &= ~X509_FL_VALIDATED;
+ x509_root_put ( cert->root );
+ cert->root = NULL;
cert->path_remaining = 0;
}
diff --git a/src/include/linux_api.h b/src/include/linux_api.h
deleted file mode 100644
index fe9fa910f..000000000
--- a/src/include/linux_api.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Copyright (C) 2010 Piotr Jaroszyński <p.jaroszynski@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 St, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#ifndef _LINUX_API_H
-#define _LINUX_API_H
-
-/** * @file
- *
- * Linux API prototypes.
- * Most of the functions map directly to linux syscalls and are the equivalent
- * of POSIX functions with the linux_ prefix removed.
- */
-
-FILE_LICENCE(GPL2_OR_LATER);
-
-#include <bits/linux_api.h>
-#include <bits/linux_api_platform.h>
-
-#include <stdint.h>
-
-#define __KERNEL_STRICT_NAMES
-#include <linux/types.h>
-#include <linux/posix_types.h>
-typedef __kernel_pid_t pid_t;
-typedef __kernel_suseconds_t suseconds_t;
-typedef __kernel_loff_t loff_t;
-#include <linux/time.h>
-#include <linux/mman.h>
-#include <linux/fcntl.h>
-#include <linux/ioctl.h>
-#include <linux/poll.h>
-typedef unsigned long nfds_t;
-typedef uint32_t useconds_t;
-typedef uint32_t socklen_t;
-struct sockaddr;
-#define MAP_FAILED ( ( void * ) -1 )
-#define SEEK_SET 0
-
-extern long linux_syscall ( int number, ... );
-
-extern int linux_open ( const char *pathname, int flags );
-extern int linux_close ( int fd );
-extern off_t linux_lseek ( int fd, off_t offset, int whence );
-extern __kernel_ssize_t linux_read ( int fd, void *buf, __kernel_size_t count );
-extern __kernel_ssize_t linux_write ( int fd, const void *buf,
- __kernel_size_t count );
-extern int linux_fcntl ( int fd, int cmd, ... );
-extern int linux_ioctl ( int fd, int request, ... );
-extern int linux_poll ( struct pollfd *fds, nfds_t nfds, int timeout );
-extern int linux_nanosleep ( const struct timespec *req, struct timespec *rem );
-extern int linux_usleep ( useconds_t usec );
-extern int linux_gettimeofday ( struct timeval *tv, struct timezone *tz );
-extern void * linux_mmap ( void *addr, __kernel_size_t length, int prot,
- int flags, int fd, off_t offset );
-extern void * linux_mremap ( void *old_address, __kernel_size_t old_size,
- __kernel_size_t new_size, int flags );
-extern int linux_munmap ( void *addr, __kernel_size_t length );
-extern int linux_socket ( int domain, int type_, int protocol );
-extern int linux_bind ( int fd, const struct sockaddr *addr,
- socklen_t addrlen );
-extern ssize_t linux_sendto ( int fd, const void *buf, size_t len, int flags,
- const struct sockaddr *daddr, socklen_t addrlen );
-
-extern const char * linux_strerror ( int errnum );
-
-#endif /* _LINUX_API_H */
diff --git a/src/include/usr/ifmgmt.h b/src/include/usr/ifmgmt.h
index 52f88f957..8d8a6bb56 100644
--- a/src/include/usr/ifmgmt.h
+++ b/src/include/usr/ifmgmt.h
@@ -18,6 +18,7 @@ extern int ifconf ( struct net_device *netdev,
unsigned long timeout );
extern void ifclose ( struct net_device *netdev );
extern void ifstat ( struct net_device *netdev );
-extern int iflinkwait ( struct net_device *netdev, unsigned long timeout );
+extern int iflinkwait ( struct net_device *netdev, unsigned long timeout,
+ int verbose );
#endif /* _USR_IFMGMT_H */
diff --git a/src/include/usr/imgmgmt.h b/src/include/usr/imgmgmt.h
index 806df0bfb..14fb7cbc6 100644
--- a/src/include/usr/imgmgmt.h
+++ b/src/include/usr/imgmgmt.h
@@ -18,5 +18,6 @@ extern int imgdownload_string ( const char *uri_string, unsigned long timeout,
extern int imgacquire ( const char *name, unsigned long timeout,
struct image **image );
extern void imgstat ( struct image *image );
+extern int imgmem ( const char *name, userptr_t data, size_t len );
#endif /* _USR_IMGMGMT_H */
diff --git a/src/interface/efi/efi_acpi.c b/src/interface/efi/efi_acpi.c
index a347eaf3a..07a225632 100644
--- a/src/interface/efi/efi_acpi.c
+++ b/src/interface/efi/efi_acpi.c
@@ -54,3 +54,4 @@ static userptr_t efi_find_rsdt ( void ) {
}
PROVIDE_ACPI ( efi, acpi_find_rsdt, efi_find_rsdt );
+PROVIDE_ACPI_INLINE ( efi, acpi_find );
diff --git a/src/interface/efi/efi_autoboot.c b/src/interface/efi/efi_autoboot.c
index a9e807e23..08d67f761 100644
--- a/src/interface/efi/efi_autoboot.c
+++ b/src/interface/efi/efi_autoboot.c
@@ -23,6 +23,8 @@
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+#include <string.h>
+#include <errno.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/efi_autoboot.h>
#include <ipxe/efi/Protocol/SimpleNetwork.h>
@@ -37,8 +39,10 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/**
* Identify autoboot device
*
+ * @v device Device handle
+ * @ret rc Return status code
*/
-void efi_set_autoboot ( void ) {
+int efi_set_autoboot_ll_addr ( EFI_HANDLE device ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
union {
EFI_SIMPLE_NETWORK_PROTOCOL *snp;
@@ -46,26 +50,30 @@ void efi_set_autoboot ( void ) {
} snp;
EFI_SIMPLE_NETWORK_MODE *mode;
EFI_STATUS efirc;
+ int rc;
/* Look for an SNP instance on the image's device handle */
- if ( ( efirc = bs->OpenProtocol ( efi_loaded_image->DeviceHandle,
+ if ( ( efirc = bs->OpenProtocol ( device,
&efi_simple_network_protocol_guid,
&snp.interface, efi_image_handle,
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){
- DBGC ( efi_loaded_image, "EFI found no autoboot device\n" );
- return;
+ rc = -EEFI ( efirc );
+ DBGC ( device, "EFI %s has no SNP instance: %s\n",
+ efi_handle_name ( device ), strerror ( rc ) );
+ return rc;
}
/* Record autoboot device */
mode = snp.snp->Mode;
set_autoboot_ll_addr ( &mode->CurrentAddress, mode->HwAddressSize );
- DBGC ( efi_loaded_image, "EFI found autoboot link-layer address:\n" );
- DBGC_HDA ( efi_loaded_image, 0, &mode->CurrentAddress,
- mode->HwAddressSize );
+ DBGC ( device, "EFI %s found autoboot link-layer address:\n",
+ efi_handle_name ( device ) );
+ DBGC_HDA ( device, 0, &mode->CurrentAddress, mode->HwAddressSize );
/* Close protocol */
- bs->CloseProtocol ( efi_loaded_image->DeviceHandle,
- &efi_simple_network_protocol_guid,
+ bs->CloseProtocol ( device, &efi_simple_network_protocol_guid,
efi_image_handle, NULL );
+
+ return 0;
}
diff --git a/src/interface/efi/efi_autoexec.c b/src/interface/efi/efi_autoexec.c
new file mode 100644
index 000000000..88eb379bb
--- /dev/null
+++ b/src/interface/efi/efi_autoexec.c
@@ -0,0 +1,206 @@
+/*
+ * Copyright (C) 2021 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 <errno.h>
+#include <ipxe/image.h>
+#include <ipxe/init.h>
+#include <ipxe/efi/efi.h>
+#include <ipxe/efi/efi_autoexec.h>
+#include <ipxe/efi/Protocol/SimpleFileSystem.h>
+#include <ipxe/efi/Guid/FileInfo.h>
+
+/** @file
+ *
+ * EFI autoexec script
+ *
+ */
+
+/** Autoexec script filename */
+#define AUTOEXEC_FILENAME L"autoexec.ipxe"
+
+/** Autoexec script image name */
+#define AUTOEXEC_NAME "autoexec.ipxe"
+
+/** Autoexec script (if any) */
+static void *efi_autoexec;
+
+/** Autoexec script length */
+static size_t efi_autoexec_len;
+
+/**
+ * Load autoexec script
+ *
+ * @v device Device handle
+ * @ret rc Return status code
+ */
+int efi_autoexec_load ( EFI_HANDLE device ) {
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+ static wchar_t name[] = AUTOEXEC_FILENAME;
+ union {
+ void *interface;
+ EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *fs;
+ } u;
+ struct {
+ EFI_FILE_INFO info;
+ CHAR16 name[ sizeof ( name ) / sizeof ( name[0] ) ];
+ } info;
+ EFI_FILE_PROTOCOL *root;
+ EFI_FILE_PROTOCOL *file;
+ UINTN size;
+ VOID *data;
+ EFI_STATUS efirc;
+ int rc;
+
+ /* Sanity check */
+ assert ( efi_autoexec == NULL );
+ assert ( efi_autoexec_len == 0 );
+
+ /* Open simple 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 ( device, "EFI %s has no filesystem instance: %s\n",
+ 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 ( device, "EFI %s could not open volume: %s\n",
+ efi_handle_name ( device ), strerror ( rc ) );
+ goto err_volume;
+ }
+
+ /* Open autoexec script */
+ if ( ( efirc = root->Open ( root, &file, name,
+ EFI_FILE_MODE_READ, 0 ) ) != 0 ) {
+ rc = -EEFI ( efirc );
+ DBGC ( device, "EFI %s has no %ls: %s\n",
+ efi_handle_name ( device ), name, strerror ( rc ) );
+ goto err_open;
+ }
+
+ /* Get file information */
+ size = sizeof ( info );
+ if ( ( efirc = file->GetInfo ( file, &efi_file_info_id, &size,
+ &info ) ) != 0 ) {
+ rc = -EEFI ( efirc );
+ DBGC ( device, "EFI %s could not get %ls info: %s\n",
+ efi_handle_name ( device ), name, strerror ( rc ) );
+ goto err_getinfo;
+ }
+ size = info.info.FileSize;
+
+ /* Ignore zero-length files */
+ if ( ! size ) {
+ rc = -EINVAL;
+ DBGC ( device, "EFI %s has zero-length %ls\n",
+ efi_handle_name ( device ), name );
+ goto err_empty;
+ }
+
+ /* Allocate temporary copy */
+ if ( ( efirc = bs->AllocatePool ( EfiBootServicesData, size,
+ &data ) ) != 0 ) {
+ rc = -EEFI ( efirc );
+ DBGC ( device, "EFI %s could not allocate %ls: %s\n",
+ efi_handle_name ( device ), name, strerror ( rc ) );
+ goto err_alloc;
+ }
+
+ /* Read file */
+ if ( ( efirc = file->Read ( file, &size, data ) ) != 0 ) {
+ rc = -EEFI ( efirc );
+ DBGC ( device, "EFI %s could not read %ls: %s\n",
+ efi_handle_name ( device ), name, strerror ( rc ) );
+ goto err_read;
+ }
+
+ /* Record autoexec script */
+ efi_autoexec = data;
+ efi_autoexec_len = size;
+ data = NULL;
+ DBGC ( device, "EFI %s found %ls\n",
+ efi_handle_name ( device ), name );
+
+ /* Success */
+ rc = 0;
+
+ err_read:
+ if ( data )
+ bs->FreePool ( data );
+ err_alloc:
+ err_empty:
+ err_getinfo:
+ file->Close ( file );
+ err_open:
+ root->Close ( root );
+ err_volume:
+ bs->CloseProtocol ( device, &efi_simple_file_system_protocol_guid,
+ efi_image_handle, device );
+ err_filesystem:
+ return rc;
+}
+
+/**
+ * Register autoexec script
+ *
+ */
+static void efi_autoexec_startup ( void ) {
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+ EFI_HANDLE device = efi_loaded_image->DeviceHandle;
+ const char *name = AUTOEXEC_NAME;
+ struct image *image;
+
+ /* Do nothing if we have no autoexec script */
+ if ( ! efi_autoexec )
+ return;
+
+ /* Create autoexec image */
+ image = image_memory ( name, virt_to_user ( efi_autoexec ),
+ efi_autoexec_len );
+ if ( ! image ) {
+ DBGC ( device, "EFI %s could not create %s\n",
+ efi_handle_name ( device ), name );
+ return;
+ }
+ DBGC ( device, "EFI %s registered %s\n",
+ efi_handle_name ( device ), name );
+
+ /* Free temporary copy */
+ bs->FreePool ( efi_autoexec );
+ efi_autoexec = NULL;
+}
+
+/** Autoexec script startup function */
+struct startup_fn efi_autoexec_startup_fn __startup_fn ( STARTUP_NORMAL ) = {
+ .name = "efi_autoexec",
+ .startup = efi_autoexec_startup,
+};
diff --git a/src/interface/efi/efi_blacklist.c b/src/interface/efi/efi_blacklist.c
deleted file mode 100644
index 292b28e8c..000000000
--- a/src/interface/efi/efi_blacklist.c
+++ /dev/null
@@ -1,237 +0,0 @@
-/*
- * Copyright (C) 2019 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.
- */
-
-FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
-
-#include <stddef.h>
-#include <string.h>
-#include <errno.h>
-#include <ipxe/settings.h>
-#include <ipxe/efi/efi.h>
-#include <ipxe/efi/Protocol/DriverBinding.h>
-#include <ipxe/efi/Protocol/LoadedImage.h>
-#include <ipxe/efi/Protocol/ComponentName.h>
-#include <ipxe/efi/efi_blacklist.h>
-
-/** @file
- *
- * EFI driver blacklist
- *
- */
-
-/** A blacklisted driver */
-struct efi_blacklist {
- /** Name */
- const char *name;
- /**
- * Check if driver is blacklisted
- *
- * @v binding Driver binding protocol
- * @v loaded Loaded image protocol
- * @v wtf Component name protocol, if present
- * @ret blacklisted Driver is the blacklisted driver
- */
- int ( * blacklist ) ( EFI_DRIVER_BINDING_PROTOCOL *binding,
- EFI_LOADED_IMAGE_PROTOCOL *loaded,
- EFI_COMPONENT_NAME_PROTOCOL *wtf );
-};
-
-/**
- * Blacklist Dell Ip4ConfigDxe driver
- *
- * @v binding Driver binding protocol
- * @v loaded Loaded image protocol
- * @v wtf Component name protocol, if present
- * @ret blacklisted Driver is the blacklisted driver
- */
-static int
-efi_blacklist_dell_ip4config ( EFI_DRIVER_BINDING_PROTOCOL *binding __unused,
- EFI_LOADED_IMAGE_PROTOCOL *loaded __unused,
- EFI_COMPONENT_NAME_PROTOCOL *wtf ) {
- static const CHAR16 ip4cfg[] = L"IP4 CONFIG Network Service Driver";
- static const char dell[] = "Dell Inc.";
- char manufacturer[ sizeof ( dell ) ];
- CHAR16 *name;
-
- /* Check driver name */
- if ( ! wtf )
- return 0;
- if ( wtf->GetDriverName ( wtf, "eng", &name ) != 0 )
- return 0;
- if ( memcmp ( name, ip4cfg, sizeof ( ip4cfg ) ) != 0 )
- return 0;
-
- /* Check manufacturer */
- fetch_string_setting ( NULL, &manufacturer_setting, manufacturer,
- sizeof ( manufacturer ) );
- if ( strcmp ( manufacturer, dell ) != 0 )
- return 0;
-
- return 1;
-}
-
-/** Blacklisted drivers */
-static struct efi_blacklist efi_blacklists[] = {
- {
- .name = "Dell Ip4Config",
- .blacklist = efi_blacklist_dell_ip4config,
- },
-};
-
-/**
- * Find driver blacklisting, if any
- *
- * @v driver Driver binding handle
- * @ret blacklist Driver blacklisting, or NULL
- * @ret rc Return status code
- */
-static int efi_blacklist ( EFI_HANDLE driver,
- struct efi_blacklist **blacklist ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
- union {
- EFI_DRIVER_BINDING_PROTOCOL *binding;
- void *interface;
- } binding;
- union {
- EFI_LOADED_IMAGE_PROTOCOL *loaded;
- void *interface;
- } loaded;
- union {
- EFI_COMPONENT_NAME_PROTOCOL *wtf;
- void *interface;
- } wtf;
- unsigned int i;
- EFI_HANDLE image;
- EFI_STATUS efirc;
- int rc;
-
- DBGC2 ( &efi_blacklists, "EFIBL checking %s\n",
- efi_handle_name ( driver ) );
-
- /* Mark as not blacklisted */
- *blacklist = NULL;
-
- /* Open driver binding protocol */
- if ( ( efirc = bs->OpenProtocol (
- driver, &efi_driver_binding_protocol_guid,
- &binding.interface, efi_image_handle, driver,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
- rc = -EEFI ( efirc );
- DBGC ( driver, "EFIBL %s could not open driver binding "
- "protocol: %s\n", efi_handle_name ( driver ),
- strerror ( rc ) );
- goto err_binding;
- }
- image = binding.binding->ImageHandle;
-
- /* Open loaded image protocol */
- if ( ( efirc = bs->OpenProtocol (
- image, &efi_loaded_image_protocol_guid,
- &loaded.interface, efi_image_handle, image,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
- rc = -EEFI ( efirc );
- DBGC ( driver, "EFIBL %s could not open",
- efi_handle_name ( driver ) );
- DBGC ( driver, " %s loaded image protocol: %s\n",
- efi_handle_name ( image ), strerror ( rc ) );
- goto err_loaded;
- }
-
- /* Open component name protocol, if present*/
- if ( ( efirc = bs->OpenProtocol (
- driver, &efi_component_name_protocol_guid,
- &wtf.interface, efi_image_handle, driver,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
- /* Ignore failure; is not required to be present */
- wtf.interface = NULL;
- }
-
- /* Check blacklistings */
- for ( i = 0 ; i < ( sizeof ( efi_blacklists ) /
- sizeof ( efi_blacklists[0] ) ) ; i++ ) {
- if ( efi_blacklists[i].blacklist ( binding.binding,
- loaded.loaded, wtf.wtf ) ) {
- *blacklist = &efi_blacklists[i];
- break;
- }
- }
-
- /* Success */
- rc = 0;
-
- /* Close protocols */
- if ( wtf.wtf ) {
- bs->CloseProtocol ( driver, &efi_component_name_protocol_guid,
- efi_image_handle, driver );
- }
- bs->CloseProtocol ( image, &efi_loaded_image_protocol_guid,
- efi_image_handle, image );
- err_loaded:
- bs->CloseProtocol ( driver, &efi_driver_binding_protocol_guid,
- efi_image_handle, driver );
- err_binding:
- return rc;
-}
-
-/**
- * Unload any blacklisted drivers
- *
- */
-void efi_unload_blacklist ( void ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
- struct efi_blacklist *blacklist;
- EFI_HANDLE *drivers;
- EFI_HANDLE driver;
- UINTN num_drivers;
- unsigned int i;
- EFI_STATUS efirc;
- int rc;
-
- /* Locate all driver binding protocol handles */
- if ( ( efirc = bs->LocateHandleBuffer (
- ByProtocol, &efi_driver_binding_protocol_guid,
- NULL, &num_drivers, &drivers ) ) != 0 ) {
- rc = -EEFI ( efirc );
- DBGC ( &efi_blacklists, "EFIBL could not list all drivers: "
- "%s\n", strerror ( rc ) );
- return;
- }
-
- /* Unload any blacklisted drivers */
- for ( i = 0 ; i < num_drivers ; i++ ) {
- driver = drivers[i];
- if ( ( rc = efi_blacklist ( driver, &blacklist ) ) != 0 ) {
- DBGC ( driver, "EFIBL could not determine "
- "blacklisting for %s: %s\n",
- efi_handle_name ( driver ), strerror ( rc ) );
- continue;
- }
- if ( ! blacklist )
- continue;
- DBGC ( driver, "EFIBL unloading %s (%s)\n",
- efi_handle_name ( driver ), blacklist->name );
- if ( ( efirc = bs->UnloadImage ( driver ) ) != 0 ) {
- DBGC ( driver, "EFIBL could not unload %s: %s\n",
- efi_handle_name ( driver ), strerror ( rc ) );
- }
- }
-
- /* Free handle list */
- bs->FreePool ( drivers );
-}
diff --git a/src/interface/efi/efi_block.c b/src/interface/efi/efi_block.c
index 64d1e1980..74cf7c0c0 100644
--- a/src/interface/efi/efi_block.c
+++ b/src/interface/efi/efi_block.c
@@ -54,7 +54,8 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <ipxe/efi/efi_driver.h>
#include <ipxe/efi/efi_strings.h>
#include <ipxe/efi/efi_snp.h>
-#include <ipxe/efi/efi_utils.h>
+#include <ipxe/efi/efi_path.h>
+#include <ipxe/efi/efi_null.h>
#include <ipxe/efi/efi_block.h>
/** ACPI table protocol protocol */
@@ -64,23 +65,6 @@ EFI_REQUEST_PROTOCOL ( EFI_ACPI_TABLE_PROTOCOL, &acpi );
/** Boot filename */
static wchar_t efi_block_boot_filename[] = EFI_REMOVABLE_MEDIA_FILE_NAME;
-/** iPXE EFI block device vendor device path GUID */
-#define IPXE_BLOCK_DEVICE_PATH_GUID \
- { 0x8998b594, 0xf531, 0x4e87, \
- { 0x8b, 0xdf, 0x8f, 0x88, 0x54, 0x3e, 0x99, 0xd4 } }
-
-/** iPXE EFI block device vendor device path GUID */
-static EFI_GUID ipxe_block_device_path_guid
- = IPXE_BLOCK_DEVICE_PATH_GUID;
-
-/** An iPXE EFI block device vendor device path */
-struct efi_block_vendor_path {
- /** Generic vendor device path */
- VENDOR_DEVICE_PATH vendor;
- /** Block device URI */
- CHAR16 uri[0];
-} __attribute__ (( packed ));
-
/** EFI SAN device private data */
struct efi_block_data {
/** SAN device */
@@ -237,7 +221,7 @@ static void efi_block_connect ( struct san_device *sandev ) {
/* Try to connect all possible drivers to this block device */
if ( ( efirc = bs->ConnectController ( block->handle, NULL,
- NULL, 1 ) ) != 0 ) {
+ NULL, TRUE ) ) != 0 ) {
rc = -EEFI ( efirc );
DBGC ( sandev, "EFIBLK %#02x could not connect drivers: %s\n",
sandev->drive, strerror ( rc ) );
@@ -259,16 +243,9 @@ static void efi_block_connect ( struct san_device *sandev ) {
static int efi_block_hook ( unsigned int drive, struct uri **uris,
unsigned int count, unsigned int flags ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
- EFI_DEVICE_PATH_PROTOCOL *end;
- struct efi_block_vendor_path *vendor;
- struct efi_snp_device *snpdev;
struct san_device *sandev;
struct efi_block_data *block;
- size_t prefix_len;
- size_t uri_len;
- size_t vendor_len;
- size_t len;
- char *uri_buf;
+ int leak = 0;
EFI_STATUS efirc;
int rc;
@@ -279,24 +256,8 @@ static int efi_block_hook ( unsigned int drive, struct uri **uris,
goto err_no_uris;
}
- /* Find an appropriate parent device handle */
- snpdev = last_opened_snpdev();
- if ( ! snpdev ) {
- DBG ( "EFIBLK could not identify SNP device\n" );
- rc = -ENODEV;
- goto err_no_snpdev;
- }
-
- /* Calculate length of private data */
- prefix_len = efi_devpath_len ( snpdev->path );
- uri_len = format_uri ( uris[0], NULL, 0 );
- vendor_len = ( sizeof ( *vendor ) +
- ( ( uri_len + 1 /* NUL */ ) * sizeof ( wchar_t ) ) );
- len = ( sizeof ( *block ) + uri_len + 1 /* NUL */ + prefix_len +
- vendor_len + sizeof ( *end ) );
-
/* Allocate and initialise structure */
- sandev = alloc_sandev ( uris, count, len );
+ sandev = alloc_sandev ( uris, count, sizeof ( *block ) );
if ( ! sandev ) {
rc = -ENOMEM;
goto err_alloc;
@@ -311,26 +272,6 @@ static int efi_block_hook ( unsigned int drive, struct uri **uris,
block->block_io.ReadBlocks = efi_block_io_read;
block->block_io.WriteBlocks = efi_block_io_write;
block->block_io.FlushBlocks = efi_block_io_flush;
- uri_buf = ( ( ( void * ) block ) + sizeof ( *block ) );
- block->path = ( ( ( void * ) uri_buf ) + uri_len + 1 /* NUL */ );
-
- /* Construct device path */
- memcpy ( block->path, snpdev->path, prefix_len );
- vendor = ( ( ( void * ) block->path ) + prefix_len );
- vendor->vendor.Header.Type = HARDWARE_DEVICE_PATH;
- vendor->vendor.Header.SubType = HW_VENDOR_DP;
- vendor->vendor.Header.Length[0] = ( vendor_len & 0xff );
- vendor->vendor.Header.Length[1] = ( vendor_len >> 8 );
- memcpy ( &vendor->vendor.Guid, &ipxe_block_device_path_guid,
- sizeof ( vendor->vendor.Guid ) );
- format_uri ( uris[0], uri_buf, ( uri_len + 1 /* NUL */ ) );
- efi_snprintf ( vendor->uri, ( uri_len + 1 /* NUL */ ), "%s", uri_buf );
- end = ( ( ( void * ) vendor ) + vendor_len );
- end->Type = END_DEVICE_PATH_TYPE;
- end->SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE;
- end->Length[0] = sizeof ( *end );
- DBGC ( sandev, "EFIBLK %#02x has device path %s\n",
- drive, efi_devpath_text ( block->path ) );
/* Register SAN device */
if ( ( rc = register_sandev ( sandev, drive, flags ) ) != 0 ) {
@@ -345,6 +286,22 @@ static int efi_block_hook ( unsigned int drive, struct uri **uris,
block->media.LastBlock =
( ( sandev->capacity.blocks >> sandev->blksize_shift ) - 1 );
+ /* Construct device path */
+ if ( ! sandev->active ) {
+ rc = -ENODEV;
+ DBGC ( sandev, "EFIBLK %#02x not active after registration\n",
+ drive );
+ goto err_active;
+ }
+ block->path = efi_describe ( &sandev->active->block );
+ if ( ! block->path ) {
+ rc = -ENODEV;
+ DBGC ( sandev, "EFIBLK %#02x has no device path\n", drive );
+ goto err_describe;
+ }
+ DBGC ( sandev, "EFIBLK %#02x has device path %s\n",
+ drive, efi_devpath_text ( block->path ) );
+
/* Install protocols */
if ( ( efirc = bs->InstallMultipleProtocolInterfaces (
&block->handle,
@@ -362,17 +319,33 @@ static int efi_block_hook ( unsigned int drive, struct uri **uris,
return drive;
- bs->UninstallMultipleProtocolInterfaces (
+ if ( ( efirc = bs->UninstallMultipleProtocolInterfaces (
block->handle,
&efi_block_io_protocol_guid, &block->block_io,
- &efi_device_path_protocol_guid, block->path, NULL );
+ &efi_device_path_protocol_guid, block->path,
+ NULL ) ) != 0 ) {
+ DBGC ( sandev, "EFIBLK %#02x could not uninstall protocols: "
+ "%s\n", sandev->drive, strerror ( -EEFI ( efirc ) ) );
+ leak = 1;
+ }
+ efi_nullify_block ( &block->block_io );
err_install:
+ if ( ! leak ) {
+ free ( block->path );
+ block->path = NULL;
+ }
+ err_describe:
+ err_active:
unregister_sandev ( sandev );
err_register:
- sandev_put ( sandev );
+ if ( ! leak )
+ sandev_put ( sandev );
err_alloc:
- err_no_snpdev:
err_no_uris:
+ if ( leak ) {
+ DBGC ( sandev, "EFIBLK %#02x nullified and leaked\n",
+ sandev->drive );
+ }
return rc;
}
@@ -385,6 +358,8 @@ static void efi_block_unhook ( unsigned int drive ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
struct san_device *sandev;
struct efi_block_data *block;
+ int leak = efi_shutdown_in_progress;
+ EFI_STATUS efirc;
/* Find SAN device */
sandev = sandev_find ( drive );
@@ -395,16 +370,36 @@ static void efi_block_unhook ( unsigned int drive ) {
block = sandev->priv;
/* Uninstall protocols */
- bs->UninstallMultipleProtocolInterfaces (
+ if ( ( ! efi_shutdown_in_progress ) &&
+ ( ( efirc = bs->UninstallMultipleProtocolInterfaces (
block->handle,
&efi_block_io_protocol_guid, &block->block_io,
- &efi_device_path_protocol_guid, block->path, NULL );
+ &efi_device_path_protocol_guid, block->path,
+ NULL ) ) != 0 ) ) {
+ DBGC ( sandev, "EFIBLK %#02x could not uninstall protocols: "
+ "%s\n", sandev->drive, strerror ( -EEFI ( efirc ) ) );
+ leak = 1;
+ }
+ efi_nullify_block ( &block->block_io );
+
+ /* Free device path */
+ if ( ! leak ) {
+ free ( block->path );
+ block->path = NULL;
+ }
/* Unregister SAN device */
unregister_sandev ( sandev );
/* Drop reference to drive */
- sandev_put ( sandev );
+ if ( ! leak )
+ sandev_put ( sandev );
+
+ /* Report leakage, if applicable */
+ if ( leak && ( ! efi_shutdown_in_progress ) ) {
+ DBGC ( sandev, "EFIBLK %#02x nullified and leaked\n",
+ sandev->drive );
+ }
}
/** An installed ACPI table */
@@ -450,17 +445,17 @@ static int efi_block_install ( struct acpi_header *hdr ) {
rc = -EEFI ( efirc );
DBGC ( acpi, "EFIBLK could not install %s: %s\n",
acpi_name ( hdr->signature ), strerror ( rc ) );
- DBGC_HDA ( acpi, 0, hdr, len );
+ DBGC2_HDA ( acpi, 0, hdr, len );
goto err_install;
}
/* Add to list of installed tables */
list_add_tail ( &installed->list, &efi_acpi_tables );
- DBGC ( acpi, "EFIBLK installed %s as ACPI table %#lx:\n",
+ DBGC ( acpi, "EFIBLK installed %s as ACPI table %#lx\n",
acpi_name ( hdr->signature ),
( ( unsigned long ) installed->key ) );
- DBGC_HDA ( acpi, 0, hdr, len );
+ DBGC2_HDA ( acpi, 0, hdr, len );
return 0;
list_del ( &installed->list );
@@ -551,7 +546,7 @@ static int efi_block_boot_image ( struct san_device *sandev, EFI_HANDLE handle,
}
/* Check if this device is a child of our block device */
- prefix_len = efi_devpath_len ( block->path );
+ prefix_len = efi_path_len ( block->path );
if ( memcmp ( path.path, block->path, prefix_len ) != 0 ) {
/* Not a child device */
rc = -ENOTTY;
@@ -561,7 +556,7 @@ static int efi_block_boot_image ( struct san_device *sandev, EFI_HANDLE handle,
sandev->drive, efi_devpath_text ( path.path ) );
/* Construct device path for boot image */
- end = efi_devpath_end ( path.path );
+ end = efi_path_end ( path.path );
prefix_len = ( ( ( void * ) end ) - ( ( void * ) path.path ) );
filepath_len = ( SIZE_OF_FILEPATH_DEVICE_PATH +
( filename ?
diff --git a/src/interface/efi/efi_bofm.c b/src/interface/efi/efi_bofm.c
index 00f6a1d5c..15f3837cc 100644
--- a/src/interface/efi/efi_bofm.c
+++ b/src/interface/efi/efi_bofm.c
@@ -164,7 +164,7 @@ static EFI_GUID bofm2_protocol_guid =
*/
static int efi_bofm_supported ( EFI_HANDLE device ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
- struct pci_device pci;
+ struct efi_pci_device efipci;
union {
IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL *bofm1;
void *interface;
@@ -173,11 +173,11 @@ static int efi_bofm_supported ( EFI_HANDLE device ) {
int rc;
/* Get PCI device information */
- if ( ( rc = efipci_info ( device, &pci ) ) != 0 )
+ if ( ( rc = efipci_info ( device, &efipci ) ) != 0 )
return rc;
/* Look for a BOFM driver */
- if ( ( rc = bofm_find_driver ( &pci ) ) != 0 ) {
+ if ( ( rc = bofm_find_driver ( &efipci.pci ) ) != 0 ) {
DBGCP ( device, "EFIBOFM %s has no driver\n",
efi_handle_name ( device ) );
return rc;
@@ -204,7 +204,7 @@ static int efi_bofm_supported ( EFI_HANDLE device ) {
}
DBGC ( device, "EFIBOFM %s has driver \"%s\"\n",
- efi_handle_name ( device ), pci.id->name );
+ efi_handle_name ( device ), efipci.pci.id->name );
return 0;
}
@@ -225,7 +225,7 @@ static int efi_bofm_start ( struct efi_device *efidev ) {
IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL2 *bofm2;
void *interface;
} bofm2;
- struct pci_device pci;
+ struct efi_pci_device efipci;
IBM_BOFM_TABLE *bofmtab;
IBM_BOFM_TABLE *bofmtab2;
int bofmrc;
@@ -234,7 +234,7 @@ static int efi_bofm_start ( struct efi_device *efidev ) {
/* Open PCI device, if possible */
if ( ( rc = efipci_open ( device, EFI_OPEN_PROTOCOL_GET_PROTOCOL,
- &pci ) ) != 0 )
+ &efipci ) ) != 0 )
goto err_open;
/* Locate BOFM protocol */
@@ -274,7 +274,8 @@ static int efi_bofm_start ( struct efi_device *efidev ) {
efi_handle_name ( device ) );
DBGC2_HD ( device, bofmtab2, bofmtab2->Parameters.Length );
}
- bofmrc = bofm ( virt_to_user ( bofmtab2 ? bofmtab2 : bofmtab ), &pci );
+ bofmrc = bofm ( virt_to_user ( bofmtab2 ? bofmtab2 : bofmtab ),
+ &efipci.pci );
DBGC ( device, "EFIBOFM %s status %08x\n",
efi_handle_name ( device ), bofmrc );
DBGC2 ( device, "EFIBOFM %s version 1 after processing:\n",
diff --git a/src/interface/efi/efi_cachedhcp.c b/src/interface/efi/efi_cachedhcp.c
new file mode 100644
index 000000000..14b531d09
--- /dev/null
+++ b/src/interface/efi/efi_cachedhcp.c
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2021 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 <errno.h>
+#include <ipxe/cachedhcp.h>
+#include <ipxe/efi/efi.h>
+#include <ipxe/efi/efi_cachedhcp.h>
+#include <ipxe/efi/Protocol/PxeBaseCode.h>
+
+/** @file
+ *
+ * EFI cached DHCP packet
+ *
+ */
+
+/**
+ * Record cached DHCP packet
+ *
+ * @v device Device handle
+ * @ret rc Return status code
+ */
+int efi_cachedhcp_record ( EFI_HANDLE device ) {
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+ union {
+ EFI_PXE_BASE_CODE_PROTOCOL *pxe;
+ void *interface;
+ } pxe;
+ EFI_PXE_BASE_CODE_MODE *mode;
+ EFI_STATUS efirc;
+ int rc;
+
+ /* Look for a PXE base code instance on the image's device handle */
+ if ( ( efirc = bs->OpenProtocol ( device,
+ &efi_pxe_base_code_protocol_guid,
+ &pxe.interface, efi_image_handle,
+ NULL,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){
+ rc = -EEFI ( efirc );
+ DBGC ( device, "EFI %s has no PXE base code instance: %s\n",
+ efi_handle_name ( device ), strerror ( rc ) );
+ goto err_open;
+ }
+
+ /* Do not attempt to cache IPv6 packets */
+ mode = pxe.pxe->Mode;
+ if ( mode->UsingIpv6 ) {
+ rc = -ENOTSUP;
+ DBGC ( device, "EFI %s has IPv6 PXE base code\n",
+ efi_handle_name ( device ) );
+ goto err_ipv6;
+ }
+
+ /* Record DHCPACK, if present */
+ if ( mode->DhcpAckReceived &&
+ ( ( rc = cachedhcp_record ( virt_to_user ( &mode->DhcpAck ),
+ sizeof ( mode->DhcpAck ) ) ) != 0 ) ) {
+ DBGC ( device, "EFI %s could not record DHCPACK: %s\n",
+ efi_handle_name ( device ), strerror ( rc ) );
+ goto err_record;
+ }
+
+ /* Success */
+ rc = 0;
+
+ err_record:
+ err_ipv6:
+ bs->CloseProtocol ( device, &efi_pxe_base_code_protocol_guid,
+ efi_image_handle, NULL );
+ err_open:
+ return rc;
+}
diff --git a/src/interface/efi/efi_console.c b/src/interface/efi/efi_console.c
index 047baed47..98ebbf3ac 100644
--- a/src/interface/efi/efi_console.c
+++ b/src/interface/efi/efi_console.c
@@ -54,6 +54,8 @@ FILE_LICENCE ( GPL2_OR_LATER );
#define ATTR_DEFAULT ATTR_FCOL_WHITE
+#define CTRL_MASK 0x1f
+
/* Set default console usage if applicable */
#if ! ( defined ( CONSOLE_EFI ) && CONSOLE_EXPLICIT ( CONSOLE_EFI ) )
#undef CONSOLE_EFI
@@ -67,6 +69,9 @@ static unsigned int efi_attr = ATTR_DEFAULT;
static EFI_CONSOLE_CONTROL_PROTOCOL *conctrl;
EFI_REQUEST_PROTOCOL ( EFI_CONSOLE_CONTROL_PROTOCOL, &conctrl );
+/** Extended simple text input protocol, if present */
+static EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *efi_conin_ex;
+
/**
* Handle ANSI CUP (cursor position)
*
@@ -278,8 +283,9 @@ static const char * scancode_to_ansi_seq ( unsigned int scancode ) {
*/
static int efi_getchar ( void ) {
EFI_SIMPLE_TEXT_INPUT_PROTOCOL *conin = efi_systab->ConIn;
+ EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *conin_ex = efi_conin_ex;
const char *ansi_seq;
- EFI_INPUT_KEY key;
+ EFI_KEY_DATA key;
EFI_STATUS efirc;
int rc;
@@ -288,20 +294,42 @@ static int efi_getchar ( void ) {
return *(ansi_input++);
/* Read key from real EFI console */
- if ( ( efirc = conin->ReadKeyStroke ( conin, &key ) ) != 0 ) {
- rc = -EEFI ( efirc );
- DBG ( "EFI could not read keystroke: %s\n", strerror ( rc ) );
- return 0;
+ memset ( &key, 0, sizeof ( key ) );
+ if ( conin_ex ) {
+ if ( ( efirc = conin_ex->ReadKeyStrokeEx ( conin_ex,
+ &key ) ) != 0 ) {
+ rc = -EEFI ( efirc );
+ DBG ( "EFI could not read extended keystroke: %s\n",
+ strerror ( rc ) );
+ return 0;
+ }
+ } else {
+ if ( ( efirc = conin->ReadKeyStroke ( conin,
+ &key.Key ) ) != 0 ) {
+ rc = -EEFI ( efirc );
+ DBG ( "EFI could not read keystroke: %s\n",
+ strerror ( rc ) );
+ return 0;
+ }
+ }
+ DBG2 ( "EFI read key stroke shift %08x toggle %02x unicode %04x "
+ "scancode %04x\n", key.KeyState.KeyShiftState,
+ key.KeyState.KeyToggleState, key.Key.UnicodeChar,
+ key.Key.ScanCode );
+
+ /* Translate Ctrl-<key> */
+ if ( ( key.KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID ) &&
+ ( key.KeyState.KeyShiftState & ( EFI_LEFT_CONTROL_PRESSED |
+ EFI_RIGHT_CONTROL_PRESSED ) ) ) {
+ key.Key.UnicodeChar &= CTRL_MASK;
}
- DBG2 ( "EFI read key stroke with unicode %04x scancode %04x\n",
- key.UnicodeChar, key.ScanCode );
/* If key has a Unicode representation, return it */
- if ( key.UnicodeChar )
- return key.UnicodeChar;
+ if ( key.Key.UnicodeChar )
+ return key.Key.UnicodeChar;
/* Otherwise, check for a special key that we know about */
- if ( ( ansi_seq = scancode_to_ansi_seq ( key.ScanCode ) ) ) {
+ if ( ( ansi_seq = scancode_to_ansi_seq ( key.Key.ScanCode ) ) ) {
/* Start of escape sequence: return ESC (0x1b) */
ansi_input = ansi_seq;
return 0x1b;
@@ -319,6 +347,8 @@ static int efi_getchar ( void ) {
static int efi_iskey ( void ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
EFI_SIMPLE_TEXT_INPUT_PROTOCOL *conin = efi_systab->ConIn;
+ EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *conin_ex = efi_conin_ex;
+ EFI_EVENT *event;
EFI_STATUS efirc;
/* If we are mid-sequence, we are always ready */
@@ -326,7 +356,8 @@ static int efi_iskey ( void ) {
return 1;
/* Check to see if the WaitForKey event has fired */
- if ( ( efirc = bs->CheckEvent ( conin->WaitForKey ) ) == 0 )
+ event = ( conin_ex ? conin_ex->WaitForKeyEx : conin->WaitForKey );
+ if ( ( efirc = bs->CheckEvent ( event ) ) == 0 )
return 1;
return 0;
@@ -345,7 +376,14 @@ struct console_driver efi_console __console_driver = {
*
*/
static void efi_console_init ( void ) {
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
EFI_CONSOLE_CONTROL_SCREEN_MODE mode;
+ union {
+ void *interface;
+ EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *wtf;
+ } u;
+ EFI_STATUS efirc;
+ int rc;
/* On some older EFI 1.10 implementations, we must use the
* (now obsolete) EFI_CONSOLE_CONTROL_PROTOCOL to switch the
@@ -358,6 +396,23 @@ static void efi_console_init ( void ) {
EfiConsoleControlScreenText );
}
}
+
+ /* Attempt to open the Simple Text Input Ex protocol on the
+ * console input handle. This is provably unsafe, but is
+ * apparently the expected behaviour for all UEFI
+ * applications. Don't ask.
+ */
+ if ( ( efirc = bs->OpenProtocol ( efi_systab->ConsoleInHandle,
+ &efi_simple_text_input_ex_protocol_guid,
+ &u.interface, efi_image_handle,
+ efi_systab->ConsoleInHandle,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) == 0 ) {
+ efi_conin_ex = u.wtf;
+ DBG ( "EFI using SimpleTextInputEx\n" );
+ } else {
+ rc = -EEFI ( efirc );
+ DBG ( "EFI has no SimpleTextInputEx: %s\n", strerror ( rc ) );
+ }
}
/**
diff --git a/src/interface/efi/efi_debug.c b/src/interface/efi/efi_debug.c
index de9b1af55..967bb6182 100644
--- a/src/interface/efi/efi_debug.c
+++ b/src/interface/efi/efi_debug.c
@@ -37,7 +37,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <ipxe/base16.h>
#include <ipxe/vsprintf.h>
#include <ipxe/efi/efi.h>
-#include <ipxe/efi/efi_utils.h>
+#include <ipxe/efi/efi_path.h>
#include <ipxe/efi/Protocol/ComponentName.h>
#include <ipxe/efi/Protocol/ComponentName2.h>
#include <ipxe/efi/Protocol/DevicePathToText.h>
@@ -189,7 +189,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 __attribute__ (( pure )) char * efi_guid_ntoa ( CONST EFI_GUID *guid ) {
union {
union uuid uuid;
EFI_GUID guid;
@@ -263,6 +263,28 @@ efi_open_attributes_name ( unsigned int attributes ) {
}
/**
+ * Print opened protocol information
+ *
+ * @v handle EFI handle
+ * @V protocol Protocol GUID
+ * @v opener Opened protocol information
+ */
+void dbg_efi_opener ( EFI_HANDLE handle, EFI_GUID *protocol,
+ EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *opener ) {
+
+ printf ( "HANDLE %s %s opened %dx (%s)", efi_handle_name ( handle ),
+ efi_guid_ntoa ( protocol ), opener->OpenCount,
+ efi_open_attributes_name ( opener->Attributes ) );
+ printf ( " by %s", efi_handle_name ( opener->AgentHandle ) );
+ if ( opener->ControllerHandle == handle ) {
+ printf ( "\n" );
+ } else {
+ printf ( " for %s\n",
+ efi_handle_name ( opener->ControllerHandle ) );
+ }
+}
+
+/**
* Print list of openers of a given protocol on a given handle
*
* @v handle EFI handle
@@ -271,7 +293,6 @@ efi_open_attributes_name ( unsigned int attributes ) {
void dbg_efi_openers ( EFI_HANDLE handle, EFI_GUID *protocol ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *openers;
- EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *opener;
UINTN count;
unsigned int i;
EFI_STATUS efirc;
@@ -296,20 +317,8 @@ void dbg_efi_openers ( EFI_HANDLE handle, EFI_GUID *protocol ) {
}
/* Dump list of openers */
- for ( i = 0 ; i < count ; i++ ) {
- opener = &openers[i];
- printf ( "HANDLE %s %s opened %dx (%s)",
- efi_handle_name ( handle ),
- efi_guid_ntoa ( protocol ), opener->OpenCount,
- efi_open_attributes_name ( opener->Attributes ) );
- printf ( " by %s", efi_handle_name ( opener->AgentHandle ) );
- if ( opener->ControllerHandle == handle ) {
- printf ( "\n" );
- } else {
- printf ( " for %s\n",
- efi_handle_name ( opener->ControllerHandle ) );
- }
- }
+ for ( i = 0 ; i < count ; i++ )
+ dbg_efi_opener ( handle, protocol, &openers[i] );
/* Free list */
bs->FreePool ( openers );
@@ -365,7 +374,7 @@ void dbg_efi_protocols ( EFI_HANDLE handle ) {
const __attribute__ (( pure )) char *
efi_devpath_text ( EFI_DEVICE_PATH_PROTOCOL *path ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
- static char text[256];
+ static char text[512];
size_t len;
CHAR16 *wtext;
@@ -378,7 +387,7 @@ 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 );
+ len = efi_path_len ( path );
base16_encode ( path, len, text, sizeof ( text ) );
return text;
}
diff --git a/src/interface/efi/efi_driver.c b/src/interface/efi/efi_driver.c
index 760ee41a8..8e537d535 100644
--- a/src/interface/efi/efi_driver.c
+++ b/src/interface/efi/efi_driver.c
@@ -30,7 +30,7 @@ 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_path.h>
#include <ipxe/efi/efi_driver.h>
/** @file
@@ -156,13 +156,13 @@ efi_driver_start ( EFI_DRIVER_BINDING_PROTOCOL *driver __unused,
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
struct efi_driver *efidrv;
struct efi_device *efidev;
+ struct efi_saved_tpl tpl;
union {
EFI_DEVICE_PATH_PROTOCOL *path;
void *interface;
} path;
EFI_DEVICE_PATH_PROTOCOL *path_end;
size_t path_len;
- EFI_TPL saved_tpl;
EFI_STATUS efirc;
int rc;
@@ -181,7 +181,7 @@ efi_driver_start ( EFI_DRIVER_BINDING_PROTOCOL *driver __unused,
}
/* Raise TPL */
- saved_tpl = bs->RaiseTPL ( TPL_CALLBACK );
+ efi_raise_tpl ( &tpl );
/* Do nothing if we are currently disconnecting drivers */
if ( efi_driver_disconnecting ) {
@@ -202,7 +202,7 @@ efi_driver_start ( EFI_DRIVER_BINDING_PROTOCOL *driver __unused,
efi_handle_name ( device ), strerror ( rc ) );
goto err_open_path;
}
- path_len = ( efi_devpath_len ( path.path ) + sizeof ( *path_end ) );
+ path_len = ( efi_path_len ( path.path ) + sizeof ( *path_end ) );
/* Allocate and initialise structure */
efidev = zalloc ( sizeof ( *efidev ) + path_len );
@@ -236,7 +236,7 @@ efi_driver_start ( EFI_DRIVER_BINDING_PROTOCOL *driver __unused,
DBGC ( device, "EFIDRV %s using driver \"%s\"\n",
efi_handle_name ( device ),
efidev->driver->name );
- bs->RestoreTPL ( saved_tpl );
+ efi_restore_tpl ( &tpl );
return 0;
}
DBGC ( device, "EFIDRV %s could not start driver \"%s\": %s\n",
@@ -254,7 +254,7 @@ efi_driver_start ( EFI_DRIVER_BINDING_PROTOCOL *driver __unused,
}
err_open_path:
err_disconnecting:
- bs->RestoreTPL ( saved_tpl );
+ efi_restore_tpl ( &tpl );
err_already_started:
return efirc;
}
@@ -273,10 +273,9 @@ static EFI_STATUS EFIAPI
efi_driver_stop ( EFI_DRIVER_BINDING_PROTOCOL *driver __unused,
EFI_HANDLE device, UINTN num_children,
EFI_HANDLE *children ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
struct efi_driver *efidrv;
struct efi_device *efidev;
- EFI_TPL saved_tpl;
+ struct efi_saved_tpl tpl;
UINTN i;
DBGC ( device, "EFIDRV %s DRIVER_STOP", efi_handle_name ( device ) );
@@ -295,7 +294,7 @@ efi_driver_stop ( EFI_DRIVER_BINDING_PROTOCOL *driver __unused,
}
/* Raise TPL */
- saved_tpl = bs->RaiseTPL ( TPL_CALLBACK );
+ efi_raise_tpl ( &tpl );
/* Stop this device */
efidrv = efidev->driver;
@@ -304,7 +303,7 @@ efi_driver_stop ( EFI_DRIVER_BINDING_PROTOCOL *driver __unused,
list_del ( &efidev->dev.siblings );
free ( efidev );
- bs->RestoreTPL ( saved_tpl );
+ efi_restore_tpl ( &tpl );
return 0;
}
@@ -470,7 +469,7 @@ static int efi_driver_connect ( EFI_HANDLE device ) {
DBGC ( device, "EFIDRV %s connecting new drivers\n",
efi_handle_name ( device ) );
if ( ( efirc = bs->ConnectController ( device, drivers, NULL,
- FALSE ) ) != 0 ) {
+ TRUE ) ) != 0 ) {
rc = -EEFI_CONNECT ( efirc );
DBGC ( device, "EFIDRV %s could not connect new drivers: "
"%s\n", efi_handle_name ( device ), strerror ( rc ) );
@@ -520,7 +519,7 @@ static int efi_driver_reconnect ( EFI_HANDLE device ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
/* Reconnect any available driver */
- bs->ConnectController ( device, NULL, NULL, FALSE );
+ bs->ConnectController ( device, NULL, NULL, TRUE );
return 0;
}
diff --git a/src/interface/efi/efi_entropy.c b/src/interface/efi/efi_entropy.c
index f6e82e2c0..b7cb6a40c 100644
--- a/src/interface/efi/efi_entropy.c
+++ b/src/interface/efi/efi_entropy.c
@@ -84,8 +84,8 @@ static int efi_entropy_enable ( void ) {
DBGC ( &tick, "ENTROPY %s RNG protocol\n",
( efirng ? "has" : "has no" ) );
- /* Drop to TPL_APPLICATION to allow timer tick event to take place */
- bs->RestoreTPL ( TPL_APPLICATION );
+ /* Drop to external TPL to allow timer tick event to take place */
+ bs->RestoreTPL ( efi_external_tpl );
/* Create timer tick event */
if ( ( efirc = bs->CreateEvent ( EVT_TIMER, TPL_NOTIFY, NULL, NULL,
diff --git a/src/interface/efi/efi_init.c b/src/interface/efi/efi_init.c
index 70212b184..b7cac16e5 100644
--- a/src/interface/efi/efi_init.c
+++ b/src/interface/efi/efi_init.c
@@ -26,7 +26,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <ipxe/rotate.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/efi_driver.h>
-#include <ipxe/efi/efi_utils.h>
+#include <ipxe/efi/efi_path.h>
#include <ipxe/efi/Protocol/LoadedImage.h>
/** Image handle passed to entry point */
@@ -47,6 +47,9 @@ EFI_DEVICE_PATH_PROTOCOL *efi_loaded_image_path;
*/
EFI_SYSTEM_TABLE * _C2 ( PLATFORM, _systab );
+/** External task priority level */
+EFI_TPL efi_external_tpl = TPL_APPLICATION;
+
/** EFI shutdown is in progress */
int efi_shutdown_in_progress;
@@ -252,7 +255,7 @@ EFI_STATUS efi_init ( EFI_HANDLE image_handle,
* path, since the device handle itself may become invalidated
* when we load our own drivers.
*/
- device_path_len = ( efi_devpath_len ( device_path ) +
+ device_path_len = ( efi_path_len ( device_path ) +
sizeof ( EFI_DEVICE_PATH_PROTOCOL ) );
if ( ( efirc = bs->AllocatePool ( EfiBootServicesData, device_path_len,
&device_path_copy ) ) != 0 ) {
@@ -361,3 +364,34 @@ __attribute__ (( noreturn )) void __stack_chk_fail ( void ) {
while ( 1 ) {}
}
+
+/**
+ * Raise task priority level to TPL_CALLBACK
+ *
+ * @v tpl Saved TPL
+ */
+void efi_raise_tpl ( struct efi_saved_tpl *tpl ) {
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+
+ /* Record current external TPL */
+ tpl->previous = efi_external_tpl;
+
+ /* Raise TPL and record previous TPL as new external TPL */
+ tpl->current = bs->RaiseTPL ( TPL_CALLBACK );
+ efi_external_tpl = tpl->current;
+}
+
+/**
+ * Restore task priority level
+ *
+ * @v tpl Saved TPL
+ */
+void efi_restore_tpl ( struct efi_saved_tpl *tpl ) {
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+
+ /* Restore external TPL */
+ efi_external_tpl = tpl->previous;
+
+ /* Restore TPL */
+ bs->RestoreTPL ( tpl->current );
+}
diff --git a/src/interface/efi/efi_local.c b/src/interface/efi/efi_local.c
index 79ea822f3..4ebca5726 100644
--- a/src/interface/efi/efi_local.c
+++ b/src/interface/efi/efi_local.c
@@ -37,7 +37,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <ipxe/process.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/efi_strings.h>
-#include <ipxe/efi/efi_utils.h>
+#include <ipxe/efi/efi_path.h>
#include <ipxe/efi/Protocol/SimpleFileSystem.h>
#include <ipxe/efi/Guid/FileInfo.h>
#include <ipxe/efi/Guid/FileSystemInfo.h>
@@ -425,7 +425,7 @@ static int efi_local_open_resolved ( struct efi_local *local,
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 );
+ size_t fp_len = ( fp ? efi_path_len ( &fp->Header ) : 0 );
char base[ fp_len / 2 /* Cannot exceed this length */ ];
size_t remaining = sizeof ( base );
size_t len;
@@ -548,8 +548,8 @@ static int efi_local_open ( struct interface *xfer, struct uri *uri ) {
}
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 );
+ process_init_stopped ( &local->process, &efi_local_process_desc,
+ &local->refcnt );
/* Open specified volume */
if ( ( rc = efi_local_open_volume ( local, volume ) ) != 0 )
@@ -563,6 +563,9 @@ static int efi_local_open ( struct interface *xfer, struct uri *uri ) {
if ( ( rc = efi_local_len ( local ) ) != 0 )
goto err_len;
+ /* Start download process */
+ process_add ( &local->process );
+
/* Attach to parent interface, mortalise self, and return */
intf_plug_plug ( &local->xfer, xfer );
ref_put ( &local->refcnt );
diff --git a/src/interface/efi/efi_null.c b/src/interface/efi/efi_null.c
new file mode 100644
index 000000000..29ca5b9b6
--- /dev/null
+++ b/src/interface/efi/efi_null.c
@@ -0,0 +1,672 @@
+/*
+ * Copyright (C) 2020 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 <ipxe/efi/efi.h>
+#include <ipxe/efi/efi_null.h>
+
+/** @file
+ *
+ * EFI null interfaces
+ *
+ */
+
+/******************************************************************************
+ *
+ * Simple Network Protocol
+ *
+ ******************************************************************************
+ */
+
+static EFI_STATUS EFIAPI
+efi_null_snp_start ( EFI_SIMPLE_NETWORK_PROTOCOL *snp __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_snp_stop ( EFI_SIMPLE_NETWORK_PROTOCOL *snp __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_snp_initialize ( EFI_SIMPLE_NETWORK_PROTOCOL *snp __unused,
+ UINTN extra_rx_bufsize __unused,
+ UINTN extra_tx_bufsize __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_snp_reset ( EFI_SIMPLE_NETWORK_PROTOCOL *snp __unused,
+ BOOLEAN ext_verify __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_snp_shutdown ( EFI_SIMPLE_NETWORK_PROTOCOL *snp __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_snp_receive_filters ( EFI_SIMPLE_NETWORK_PROTOCOL *snp __unused,
+ UINT32 enable __unused,
+ UINT32 disable __unused,
+ BOOLEAN mcast_reset __unused,
+ UINTN mcast_count __unused,
+ EFI_MAC_ADDRESS *mcast __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_snp_station_address ( EFI_SIMPLE_NETWORK_PROTOCOL *snp __unused,
+ BOOLEAN reset __unused,
+ EFI_MAC_ADDRESS *new __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_snp_statistics ( EFI_SIMPLE_NETWORK_PROTOCOL *snp __unused,
+ BOOLEAN reset __unused, UINTN *stats_len __unused,
+ EFI_NETWORK_STATISTICS *stats __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_snp_mcast_ip_to_mac ( EFI_SIMPLE_NETWORK_PROTOCOL *snp __unused,
+ BOOLEAN ipv6 __unused,
+ EFI_IP_ADDRESS *ip __unused,
+ EFI_MAC_ADDRESS *mac __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_snp_nvdata ( EFI_SIMPLE_NETWORK_PROTOCOL *snp __unused,
+ BOOLEAN read __unused, UINTN offset __unused,
+ UINTN len __unused, VOID *data __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_snp_get_status ( EFI_SIMPLE_NETWORK_PROTOCOL *snp __unused,
+ UINT32 *interrupts __unused, VOID **txbuf __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_snp_transmit ( EFI_SIMPLE_NETWORK_PROTOCOL *snp __unused,
+ UINTN ll_header_len __unused, UINTN len __unused,
+ VOID *data __unused, EFI_MAC_ADDRESS *ll_src __unused,
+ EFI_MAC_ADDRESS *ll_dest __unused,
+ UINT16 *net_proto __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_snp_receive ( EFI_SIMPLE_NETWORK_PROTOCOL *snp __unused,
+ UINTN *ll_header_len __unused, UINTN *len __unused,
+ VOID *data __unused, EFI_MAC_ADDRESS *ll_src __unused,
+ EFI_MAC_ADDRESS *ll_dest __unused,
+ UINT16 *net_proto __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_SIMPLE_NETWORK_PROTOCOL efi_null_snp = {
+ .Revision = EFI_SIMPLE_NETWORK_PROTOCOL_REVISION,
+ .Start = efi_null_snp_start,
+ .Stop = efi_null_snp_stop,
+ .Initialize = efi_null_snp_initialize,
+ .Reset = efi_null_snp_reset,
+ .Shutdown = efi_null_snp_shutdown,
+ .ReceiveFilters = efi_null_snp_receive_filters,
+ .StationAddress = efi_null_snp_station_address,
+ .Statistics = efi_null_snp_statistics,
+ .MCastIpToMac = efi_null_snp_mcast_ip_to_mac,
+ .NvData = efi_null_snp_nvdata,
+ .GetStatus = efi_null_snp_get_status,
+ .Transmit = efi_null_snp_transmit,
+ .Receive = efi_null_snp_receive,
+};
+
+/**
+ * Nullify SNP interface
+ *
+ * @v snp SNP interface
+ */
+void efi_nullify_snp ( EFI_SIMPLE_NETWORK_PROTOCOL *snp ) {
+
+ memcpy ( snp, &efi_null_snp,
+ offsetof ( typeof ( *snp ), WaitForPacket ) );
+ snp->Mode->State = EfiSimpleNetworkStopped;
+}
+
+/******************************************************************************
+ *
+ * Network Interface Identification protocol
+ *
+ ******************************************************************************
+ */
+
+static EFIAPI VOID efi_null_undi_issue ( UINT64 cdb_phys ) {
+ PXE_CDB *cdb = ( ( void * ) ( intptr_t ) cdb_phys );
+
+ cdb->StatCode = PXE_STATCODE_UNSUPPORTED;
+ cdb->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;
+}
+
+static PXE_SW_UNDI efi_null_undi __attribute__ (( aligned ( 16 ) )) = {
+ .Signature = PXE_ROMID_SIGNATURE,
+ .Len = sizeof ( efi_null_undi ),
+ .Rev = PXE_ROMID_REV,
+ .MajorVer = PXE_ROMID_MAJORVER,
+ .MinorVer = PXE_ROMID_MINORVER,
+ .Implementation = PXE_ROMID_IMP_SW_VIRT_ADDR,
+};
+
+/**
+ * Nullify NII interface
+ *
+ * @v nii NII interface
+ */
+void efi_nullify_nii ( EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL *nii ) {
+ efi_null_undi.EntryPoint = ( ( intptr_t ) efi_null_undi_issue );
+ nii->Id = ( ( intptr_t ) &efi_null_undi );
+}
+
+/******************************************************************************
+ *
+ * Component name protocol
+ *
+ ******************************************************************************
+ */
+
+static EFI_STATUS EFIAPI
+efi_null_get_driver_name ( EFI_COMPONENT_NAME2_PROTOCOL *name2 __unused,
+ CHAR8 *language __unused,
+ CHAR16 **driver_name __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_get_controller_name ( EFI_COMPONENT_NAME2_PROTOCOL *name2 __unused,
+ EFI_HANDLE device __unused,
+ EFI_HANDLE child __unused,
+ CHAR8 *language __unused,
+ CHAR16 **controller_name __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_COMPONENT_NAME2_PROTOCOL efi_null_name2 = {
+ .GetDriverName = efi_null_get_driver_name,
+ .GetControllerName = efi_null_get_controller_name,
+ .SupportedLanguages = "",
+};
+
+/**
+ * Nullify Component Name Protocol interface
+ *
+ * @v name2 Component name protocol
+ */
+void efi_nullify_name2 ( EFI_COMPONENT_NAME2_PROTOCOL *name2 ) {
+
+ memcpy ( name2, &efi_null_name2, sizeof ( *name2 ) );
+}
+
+/******************************************************************************
+ *
+ * Load file protocol
+ *
+ ******************************************************************************
+ */
+
+static EFI_STATUS EFIAPI
+efi_null_load_file ( EFI_LOAD_FILE_PROTOCOL *load_file __unused,
+ EFI_DEVICE_PATH_PROTOCOL *path __unused,
+ BOOLEAN booting __unused, UINTN *len __unused,
+ VOID *data __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+/**
+ * Nullify Load File Protocol interface
+ *
+ * @v load_file Load file protocol
+ */
+void efi_nullify_load_file ( EFI_LOAD_FILE_PROTOCOL *load_file ) {
+ load_file->LoadFile = efi_null_load_file;
+}
+
+/******************************************************************************
+ *
+ * HII configuration access protocol
+ *
+ ******************************************************************************
+ */
+
+static EFI_STATUS EFIAPI
+efi_null_hii_extract ( const EFI_HII_CONFIG_ACCESS_PROTOCOL *hii __unused,
+ EFI_STRING request __unused,
+ EFI_STRING *progress __unused,
+ EFI_STRING *results __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_hii_route ( const EFI_HII_CONFIG_ACCESS_PROTOCOL *hii __unused,
+ EFI_STRING config __unused,
+ EFI_STRING *progress __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_hii_callback ( const EFI_HII_CONFIG_ACCESS_PROTOCOL *hii __unused,
+ EFI_BROWSER_ACTION action __unused,
+ EFI_QUESTION_ID question_id __unused,
+ UINT8 type __unused, EFI_IFR_TYPE_VALUE *value __unused,
+ EFI_BROWSER_ACTION_REQUEST *action_request __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_HII_CONFIG_ACCESS_PROTOCOL efi_null_hii = {
+ .ExtractConfig = efi_null_hii_extract,
+ .RouteConfig = efi_null_hii_route,
+ .Callback = efi_null_hii_callback,
+};
+
+/**
+ * Nullify HII configuration access protocol
+ *
+ * @v hii HII configuration access protocol
+ */
+void efi_nullify_hii ( EFI_HII_CONFIG_ACCESS_PROTOCOL *hii ) {
+
+ memcpy ( hii, &efi_null_hii, sizeof ( *hii ) );
+}
+
+/******************************************************************************
+ *
+ * Block I/O protocol
+ *
+ ******************************************************************************
+ */
+
+static EFI_STATUS EFIAPI
+efi_null_block_reset ( EFI_BLOCK_IO_PROTOCOL *block __unused,
+ BOOLEAN verify __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_block_read ( EFI_BLOCK_IO_PROTOCOL *block __unused,
+ UINT32 media __unused, EFI_LBA lba __unused,
+ UINTN len __unused, VOID *data __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_block_write ( EFI_BLOCK_IO_PROTOCOL *block __unused,
+ UINT32 media __unused, EFI_LBA lba __unused,
+ UINTN len __unused, VOID *data __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_block_flush ( EFI_BLOCK_IO_PROTOCOL *block __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_BLOCK_IO_MEDIA efi_null_block_media;
+
+static EFI_BLOCK_IO_PROTOCOL efi_null_block = {
+ .Revision = EFI_BLOCK_IO_INTERFACE_REVISION,
+ .Media = &efi_null_block_media,
+ .Reset = efi_null_block_reset,
+ .ReadBlocks = efi_null_block_read,
+ .WriteBlocks = efi_null_block_write,
+ .FlushBlocks = efi_null_block_flush,
+};
+
+/**
+ * Nullify block I/O protocol
+ *
+ * @v block Block I/O protocol
+ */
+void efi_nullify_block ( EFI_BLOCK_IO_PROTOCOL *block ) {
+
+ memcpy ( block, &efi_null_block, sizeof ( *block ) );
+}
+
+/******************************************************************************
+ *
+ * PXE base code protocol
+ *
+ ******************************************************************************
+ */
+
+static EFI_STATUS EFIAPI
+efi_null_pxe_start ( EFI_PXE_BASE_CODE_PROTOCOL *pxe __unused,
+ BOOLEAN use_ipv6 __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_pxe_stop ( EFI_PXE_BASE_CODE_PROTOCOL *pxe __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_pxe_dhcp ( EFI_PXE_BASE_CODE_PROTOCOL *pxe __unused,
+ BOOLEAN sort __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_pxe_discover ( EFI_PXE_BASE_CODE_PROTOCOL *pxe __unused,
+ UINT16 type __unused, UINT16 *layer __unused,
+ BOOLEAN bis __unused,
+ EFI_PXE_BASE_CODE_DISCOVER_INFO *info __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_pxe_mtftp ( EFI_PXE_BASE_CODE_PROTOCOL *pxe __unused,
+ EFI_PXE_BASE_CODE_TFTP_OPCODE opcode __unused,
+ VOID *data __unused, BOOLEAN overwrite __unused,
+ UINT64 *len __unused, UINTN *blksize __unused,
+ EFI_IP_ADDRESS *ip __unused, UINT8 *filename __unused,
+ EFI_PXE_BASE_CODE_MTFTP_INFO *info __unused,
+ BOOLEAN callback __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_pxe_udp_write ( EFI_PXE_BASE_CODE_PROTOCOL *pxe __unused,
+ UINT16 flags __unused,
+ EFI_IP_ADDRESS *dest_ip __unused,
+ EFI_PXE_BASE_CODE_UDP_PORT *dest_port __unused,
+ EFI_IP_ADDRESS *gateway __unused,
+ EFI_IP_ADDRESS *src_ip __unused,
+ EFI_PXE_BASE_CODE_UDP_PORT *src_port __unused,
+ UINTN *hdr_len __unused, VOID *hdr __unused,
+ UINTN *len __unused, VOID *data __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_pxe_udp_read ( EFI_PXE_BASE_CODE_PROTOCOL *pxe __unused,
+ UINT16 flags __unused,
+ EFI_IP_ADDRESS *dest_ip __unused,
+ EFI_PXE_BASE_CODE_UDP_PORT *dest_port __unused,
+ EFI_IP_ADDRESS *src_ip __unused,
+ EFI_PXE_BASE_CODE_UDP_PORT *src_port __unused,
+ UINTN *hdr_len __unused, VOID *hdr __unused,
+ UINTN *len __unused, VOID *data __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_pxe_set_ip_filter ( EFI_PXE_BASE_CODE_PROTOCOL *pxe __unused,
+ EFI_PXE_BASE_CODE_IP_FILTER *filter __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_pxe_arp ( EFI_PXE_BASE_CODE_PROTOCOL *pxe __unused,
+ EFI_IP_ADDRESS *ip __unused,
+ EFI_MAC_ADDRESS *mac __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_pxe_set_parameters ( EFI_PXE_BASE_CODE_PROTOCOL *pxe __unused,
+ BOOLEAN *autoarp __unused,
+ BOOLEAN *sendguid __unused, UINT8 *ttl __unused,
+ UINT8 *tos __unused,
+ BOOLEAN *callback __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_pxe_set_station_ip ( EFI_PXE_BASE_CODE_PROTOCOL *pxe __unused,
+ EFI_IP_ADDRESS *ip __unused,
+ EFI_IP_ADDRESS *netmask __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_pxe_set_packets ( EFI_PXE_BASE_CODE_PROTOCOL *pxe __unused,
+ BOOLEAN *dhcpdisc_ok __unused,
+ BOOLEAN *dhcpack_ok __unused,
+ BOOLEAN *proxyoffer_ok __unused,
+ BOOLEAN *pxebsdisc_ok __unused,
+ BOOLEAN *pxebsack_ok __unused,
+ BOOLEAN *pxebsbis_ok __unused,
+ EFI_PXE_BASE_CODE_PACKET *dhcpdisc __unused,
+ EFI_PXE_BASE_CODE_PACKET *dhcpack __unused,
+ EFI_PXE_BASE_CODE_PACKET *proxyoffer __unused,
+ EFI_PXE_BASE_CODE_PACKET *pxebsdisc __unused,
+ EFI_PXE_BASE_CODE_PACKET *pxebsack __unused,
+ EFI_PXE_BASE_CODE_PACKET *pxebsbis __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_PXE_BASE_CODE_PROTOCOL efi_null_pxe = {
+ .Revision = EFI_PXE_BASE_CODE_PROTOCOL_REVISION,
+ .Start = efi_null_pxe_start,
+ .Stop = efi_null_pxe_stop,
+ .Dhcp = efi_null_pxe_dhcp,
+ .Discover = efi_null_pxe_discover,
+ .Mtftp = efi_null_pxe_mtftp,
+ .UdpWrite = efi_null_pxe_udp_write,
+ .UdpRead = efi_null_pxe_udp_read,
+ .SetIpFilter = efi_null_pxe_set_ip_filter,
+ .Arp = efi_null_pxe_arp,
+ .SetParameters = efi_null_pxe_set_parameters,
+ .SetStationIp = efi_null_pxe_set_station_ip,
+ .SetPackets = efi_null_pxe_set_packets,
+};
+
+/**
+ * Nullify PXE base code protocol
+ *
+ * @v pxe PXE base code protocol
+ */
+void efi_nullify_pxe ( EFI_PXE_BASE_CODE_PROTOCOL *pxe ) {
+
+ memcpy ( pxe, &efi_null_pxe, offsetof ( typeof ( *pxe ), Mode ) );
+ pxe->Mode->Started = FALSE;
+}
+
+/******************************************************************************
+ *
+ * Apple Net Boot protocol
+ *
+ ******************************************************************************
+ */
+
+static EFI_STATUS EFIAPI
+efi_null_apple_dhcp ( EFI_APPLE_NET_BOOT_PROTOCOL *apple __unused,
+ UINTN *len __unused, VOID *data __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_apple_bsdp ( EFI_APPLE_NET_BOOT_PROTOCOL *apple __unused,
+ UINTN *len __unused, VOID *data __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_APPLE_NET_BOOT_PROTOCOL efi_null_apple = {
+ .GetDhcpResponse = efi_null_apple_dhcp,
+ .GetBsdpResponse = efi_null_apple_bsdp,
+};
+
+/**
+ * Nullify Apple Net Boot protocol
+ *
+ * @v apple Apple Net Boot protocol
+ */
+void efi_nullify_apple ( EFI_APPLE_NET_BOOT_PROTOCOL *apple ) {
+
+ memcpy ( apple, &efi_null_apple, sizeof ( *apple ) );
+}
+
+/******************************************************************************
+ *
+ * USB I/O Protocol
+ *
+ ******************************************************************************
+ */
+
+static EFI_STATUS EFIAPI
+efi_null_usb_control_transfer ( EFI_USB_IO_PROTOCOL *usbio __unused,
+ EFI_USB_DEVICE_REQUEST *packet __unused,
+ EFI_USB_DATA_DIRECTION direction __unused,
+ UINT32 timeout __unused, VOID *data __unused,
+ UINTN len __unused, UINT32 *status __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_usb_bulk_transfer ( EFI_USB_IO_PROTOCOL *usbio __unused,
+ UINT8 endpoint __unused, VOID *data __unused,
+ UINTN *len __unused, UINTN timeout __unused,
+ UINT32 *status __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_usb_sync_interrupt_transfer ( EFI_USB_IO_PROTOCOL *usbio __unused,
+ UINT8 endpoint __unused,
+ VOID *data __unused,
+ UINTN *len __unused,
+ UINTN timeout __unused,
+ UINT32 *status __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_usb_async_interrupt_transfer ( EFI_USB_IO_PROTOCOL *usbio __unused,
+ UINT8 endpoint __unused,
+ BOOLEAN start __unused,
+ UINTN interval __unused,
+ UINTN len __unused,
+ EFI_ASYNC_USB_TRANSFER_CALLBACK
+ callback __unused,
+ VOID *context __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_usb_isochronous_transfer ( EFI_USB_IO_PROTOCOL *usbio __unused,
+ UINT8 endpoint __unused,
+ VOID *data __unused, UINTN len __unused,
+ UINT32 *status __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_usb_async_isochronous_transfer ( EFI_USB_IO_PROTOCOL *usbio __unused,
+ UINT8 endpoint __unused,
+ VOID *data __unused,
+ UINTN len __unused,
+ EFI_ASYNC_USB_TRANSFER_CALLBACK
+ callback __unused,
+ VOID *context __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_usb_get_device_descriptor ( EFI_USB_IO_PROTOCOL *usbio __unused,
+ EFI_USB_DEVICE_DESCRIPTOR
+ *efidesc __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_usb_get_config_descriptor ( EFI_USB_IO_PROTOCOL *usbio __unused,
+ EFI_USB_CONFIG_DESCRIPTOR
+ *efidesc __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_usb_get_interface_descriptor ( EFI_USB_IO_PROTOCOL *usbio __unused,
+ EFI_USB_INTERFACE_DESCRIPTOR
+ *efidesc __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_usb_get_endpoint_descriptor ( EFI_USB_IO_PROTOCOL *usbio __unused,
+ UINT8 index __unused,
+ EFI_USB_ENDPOINT_DESCRIPTOR
+ *efidesc __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_usb_get_string_descriptor ( EFI_USB_IO_PROTOCOL *usbio __unused,
+ UINT16 language __unused,
+ UINT8 index __unused,
+ CHAR16 **string __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_usb_get_supported_languages ( EFI_USB_IO_PROTOCOL *usbio __unused,
+ UINT16 **languages __unused,
+ UINT16 *len __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_STATUS EFIAPI
+efi_null_usb_port_reset ( EFI_USB_IO_PROTOCOL *usbio __unused ) {
+ return EFI_UNSUPPORTED;
+}
+
+static EFI_USB_IO_PROTOCOL efi_null_usbio = {
+ .UsbControlTransfer = efi_null_usb_control_transfer,
+ .UsbBulkTransfer = efi_null_usb_bulk_transfer,
+ .UsbAsyncInterruptTransfer = efi_null_usb_async_interrupt_transfer,
+ .UsbSyncInterruptTransfer = efi_null_usb_sync_interrupt_transfer,
+ .UsbIsochronousTransfer = efi_null_usb_isochronous_transfer,
+ .UsbAsyncIsochronousTransfer = efi_null_usb_async_isochronous_transfer,
+ .UsbGetDeviceDescriptor = efi_null_usb_get_device_descriptor,
+ .UsbGetConfigDescriptor = efi_null_usb_get_config_descriptor,
+ .UsbGetInterfaceDescriptor = efi_null_usb_get_interface_descriptor,
+ .UsbGetEndpointDescriptor = efi_null_usb_get_endpoint_descriptor,
+ .UsbGetStringDescriptor = efi_null_usb_get_string_descriptor,
+ .UsbGetSupportedLanguages = efi_null_usb_get_supported_languages,
+ .UsbPortReset = efi_null_usb_port_reset,
+};
+
+/**
+ * Nullify USB I/O protocol
+ *
+ * @v usbio USB I/O protocol
+ */
+void efi_nullify_usbio ( EFI_USB_IO_PROTOCOL *usbio ) {
+
+ memcpy ( usbio, &efi_null_usbio, sizeof ( *usbio ) );
+}
diff --git a/src/interface/efi/efi_path.c b/src/interface/efi/efi_path.c
new file mode 100644
index 000000000..bae0ac4b5
--- /dev/null
+++ b/src/interface/efi/efi_path.c
@@ -0,0 +1,506 @@
+/*
+ * Copyright (C) 2020 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.
+ */
+
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <byteswap.h>
+#include <ipxe/netdevice.h>
+#include <ipxe/vlan.h>
+#include <ipxe/tcpip.h>
+#include <ipxe/uri.h>
+#include <ipxe/iscsi.h>
+#include <ipxe/aoe.h>
+#include <ipxe/fcp.h>
+#include <ipxe/ib_srp.h>
+#include <ipxe/usb.h>
+#include <ipxe/efi/efi.h>
+#include <ipxe/efi/efi_driver.h>
+#include <ipxe/efi/efi_path.h>
+
+/** @file
+ *
+ * EFI device paths
+ *
+ */
+
+/**
+ * Find end of device path
+ *
+ * @v path Path to device
+ * @ret path_end End of device path
+ */
+EFI_DEVICE_PATH_PROTOCOL * efi_path_end ( EFI_DEVICE_PATH_PROTOCOL *path ) {
+
+ while ( path->Type != END_DEVICE_PATH_TYPE ) {
+ path = ( ( ( void * ) path ) +
+ /* There's this amazing new-fangled thing known as
+ * a UINT16, but who wants to use one of those? */
+ ( ( path->Length[1] << 8 ) | path->Length[0] ) );
+ }
+
+ return path;
+}
+
+/**
+ * Find length of device path (excluding terminator)
+ *
+ * @v path Path to device
+ * @ret path_len Length of device path
+ */
+size_t efi_path_len ( EFI_DEVICE_PATH_PROTOCOL *path ) {
+ EFI_DEVICE_PATH_PROTOCOL *end = efi_path_end ( path );
+
+ return ( ( ( void * ) end ) - ( ( void * ) path ) );
+}
+
+/**
+ * Concatenate EFI device paths
+ *
+ * @v ... List of device paths (NULL terminated)
+ * @ret path Concatenated device path, or NULL on error
+ *
+ * The caller is responsible for eventually calling free() on the
+ * allocated device path.
+ */
+EFI_DEVICE_PATH_PROTOCOL * efi_paths ( EFI_DEVICE_PATH_PROTOCOL *first, ... ) {
+ EFI_DEVICE_PATH_PROTOCOL *path;
+ EFI_DEVICE_PATH_PROTOCOL *src;
+ EFI_DEVICE_PATH_PROTOCOL *dst;
+ EFI_DEVICE_PATH_PROTOCOL *end;
+ va_list args;
+ size_t len;
+
+ /* Calculate device path length */
+ va_start ( args, first );
+ len = 0;
+ src = first;
+ while ( src ) {
+ len += efi_path_len ( src );
+ src = va_arg ( args, EFI_DEVICE_PATH_PROTOCOL * );
+ }
+ va_end ( args );
+
+ /* Allocate device path */
+ path = zalloc ( len + sizeof ( *end ) );
+ if ( ! path )
+ return NULL;
+
+ /* Populate device path */
+ va_start ( args, first );
+ dst = path;
+ src = first;
+ while ( src ) {
+ len = efi_path_len ( src );
+ memcpy ( dst, src, len );
+ dst = ( ( ( void * ) dst ) + len );
+ src = va_arg ( args, EFI_DEVICE_PATH_PROTOCOL * );
+ }
+ va_end ( args );
+ end = dst;
+ end->Type = END_DEVICE_PATH_TYPE;
+ end->SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE;
+ end->Length[0] = sizeof ( *end );
+
+ return path;
+}
+
+/**
+ * Construct EFI device path for network device
+ *
+ * @v netdev Network device
+ * @ret path EFI device path, or NULL on error
+ *
+ * The caller is responsible for eventually calling free() on the
+ * allocated device path.
+ */
+EFI_DEVICE_PATH_PROTOCOL * efi_netdev_path ( struct net_device *netdev ) {
+ struct efi_device *efidev;
+ EFI_DEVICE_PATH_PROTOCOL *path;
+ MAC_ADDR_DEVICE_PATH *macpath;
+ VLAN_DEVICE_PATH *vlanpath;
+ EFI_DEVICE_PATH_PROTOCOL *end;
+ unsigned int tag;
+ size_t prefix_len;
+ size_t len;
+
+ /* Find parent EFI device */
+ efidev = efidev_parent ( netdev->dev );
+ if ( ! efidev )
+ return NULL;
+
+ /* Calculate device path length */
+ prefix_len = efi_path_len ( efidev->path );
+ len = ( prefix_len + sizeof ( *macpath ) + sizeof ( *vlanpath ) +
+ sizeof ( *end ) );
+
+ /* Allocate device path */
+ path = zalloc ( len );
+ if ( ! path )
+ return NULL;
+
+ /* Construct device path */
+ memcpy ( path, efidev->path, prefix_len );
+ macpath = ( ( ( void * ) path ) + prefix_len );
+ macpath->Header.Type = MESSAGING_DEVICE_PATH;
+ macpath->Header.SubType = MSG_MAC_ADDR_DP;
+ macpath->Header.Length[0] = sizeof ( *macpath );
+ assert ( netdev->ll_protocol->ll_addr_len <
+ sizeof ( macpath->MacAddress ) );
+ memcpy ( &macpath->MacAddress, netdev->ll_addr,
+ netdev->ll_protocol->ll_addr_len );
+ macpath->IfType = ntohs ( netdev->ll_protocol->ll_proto );
+ if ( ( tag = vlan_tag ( netdev ) ) ) {
+ vlanpath = ( ( ( void * ) macpath ) + sizeof ( *macpath ) );
+ vlanpath->Header.Type = MESSAGING_DEVICE_PATH;
+ vlanpath->Header.SubType = MSG_VLAN_DP;
+ vlanpath->Header.Length[0] = sizeof ( *vlanpath );
+ vlanpath->VlanId = tag;
+ end = ( ( ( void * ) vlanpath ) + sizeof ( *vlanpath ) );
+ } else {
+ end = ( ( ( void * ) macpath ) + sizeof ( *macpath ) );
+ }
+ end->Type = END_DEVICE_PATH_TYPE;
+ end->SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE;
+ end->Length[0] = sizeof ( *end );
+
+ return path;
+}
+
+/**
+ * Construct EFI device path for URI
+ *
+ * @v uri URI
+ * @ret path EFI device path, or NULL on error
+ *
+ * The caller is responsible for eventually calling free() on the
+ * allocated device path.
+ */
+EFI_DEVICE_PATH_PROTOCOL * efi_uri_path ( struct uri *uri ) {
+ EFI_DEVICE_PATH_PROTOCOL *path;
+ EFI_DEVICE_PATH_PROTOCOL *end;
+ URI_DEVICE_PATH *uripath;
+ size_t uri_len;
+ size_t uripath_len;
+ size_t len;
+
+ /* Calculate device path length */
+ uri_len = ( format_uri ( uri, NULL, 0 ) + 1 /* NUL */ );
+ uripath_len = ( sizeof ( *uripath ) + uri_len );
+ len = ( uripath_len + sizeof ( *end ) );
+
+ /* Allocate device path */
+ path = zalloc ( len );
+ if ( ! path )
+ return NULL;
+
+ /* Construct device path */
+ uripath = ( ( void * ) path );
+ uripath->Header.Type = MESSAGING_DEVICE_PATH;
+ uripath->Header.SubType = MSG_URI_DP;
+ uripath->Header.Length[0] = ( uripath_len & 0xff );
+ uripath->Header.Length[1] = ( uripath_len >> 8 );
+ format_uri ( uri, uripath->Uri, uri_len );
+ end = ( ( ( void * ) path ) + uripath_len );
+ end->Type = END_DEVICE_PATH_TYPE;
+ end->SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE;
+ end->Length[0] = sizeof ( *end );
+
+ return path;
+}
+
+/**
+ * Construct EFI device path for iSCSI device
+ *
+ * @v iscsi iSCSI session
+ * @ret path EFI device path, or NULL on error
+ */
+EFI_DEVICE_PATH_PROTOCOL * efi_iscsi_path ( struct iscsi_session *iscsi ) {
+ struct sockaddr_tcpip *st_target;
+ struct net_device *netdev;
+ EFI_DEVICE_PATH_PROTOCOL *netpath;
+ EFI_DEVICE_PATH_PROTOCOL *path;
+ EFI_DEVICE_PATH_PROTOCOL *end;
+ ISCSI_DEVICE_PATH *iscsipath;
+ char *name;
+ size_t prefix_len;
+ size_t name_len;
+ size_t iscsi_len;
+ size_t len;
+
+ /* Get network device associated with target address */
+ st_target = ( ( struct sockaddr_tcpip * ) &iscsi->target_sockaddr );
+ netdev = tcpip_netdev ( st_target );
+ if ( ! netdev )
+ goto err_netdev;
+
+ /* Get network device path */
+ netpath = efi_netdev_path ( netdev );
+ if ( ! netpath )
+ goto err_netpath;
+
+ /* Calculate device path length */
+ prefix_len = efi_path_len ( netpath );
+ name_len = ( strlen ( iscsi->target_iqn ) + 1 /* NUL */ );
+ iscsi_len = ( sizeof ( *iscsipath ) + name_len );
+ len = ( prefix_len + iscsi_len + sizeof ( *end ) );
+
+ /* Allocate device path */
+ path = zalloc ( len );
+ if ( ! path )
+ goto err_alloc;
+
+ /* Construct device path */
+ memcpy ( path, netpath, prefix_len );
+ iscsipath = ( ( ( void * ) path ) + prefix_len );
+ iscsipath->Header.Type = MESSAGING_DEVICE_PATH;
+ iscsipath->Header.SubType = MSG_ISCSI_DP;
+ iscsipath->Header.Length[0] = iscsi_len;
+ iscsipath->LoginOption = ISCSI_LOGIN_OPTION_AUTHMETHOD_NON;
+ memcpy ( &iscsipath->Lun, &iscsi->lun, sizeof ( iscsipath->Lun ) );
+ name = ( ( ( void * ) iscsipath ) + sizeof ( *iscsipath ) );
+ memcpy ( name, iscsi->target_iqn, name_len );
+ end = ( ( ( void * ) name ) + name_len );
+ end->Type = END_DEVICE_PATH_TYPE;
+ end->SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE;
+ end->Length[0] = sizeof ( *end );
+
+ /* Free temporary paths */
+ free ( netpath );
+
+ return path;
+
+ err_alloc:
+ free ( netpath );
+ err_netpath:
+ err_netdev:
+ return NULL;
+}
+
+/**
+ * Construct EFI device path for AoE device
+ *
+ * @v aoedev AoE device
+ * @ret path EFI device path, or NULL on error
+ */
+EFI_DEVICE_PATH_PROTOCOL * efi_aoe_path ( struct aoe_device *aoedev ) {
+ struct {
+ SATA_DEVICE_PATH sata;
+ EFI_DEVICE_PATH_PROTOCOL end;
+ } satapath;
+ EFI_DEVICE_PATH_PROTOCOL *netpath;
+ EFI_DEVICE_PATH_PROTOCOL *path;
+
+ /* Get network device path */
+ netpath = efi_netdev_path ( aoedev->netdev );
+ if ( ! netpath )
+ goto err_netdev;
+
+ /* Construct SATA path */
+ memset ( &satapath, 0, sizeof ( satapath ) );
+ satapath.sata.Header.Type = MESSAGING_DEVICE_PATH;
+ satapath.sata.Header.SubType = MSG_SATA_DP;
+ satapath.sata.Header.Length[0] = sizeof ( satapath.sata );
+ satapath.sata.HBAPortNumber = aoedev->major;
+ satapath.sata.PortMultiplierPortNumber = aoedev->minor;
+ satapath.end.Type = END_DEVICE_PATH_TYPE;
+ satapath.end.SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE;
+ satapath.end.Length[0] = sizeof ( satapath.end );
+
+ /* Construct overall device path */
+ path = efi_paths ( netpath, &satapath, NULL );
+ if ( ! path )
+ goto err_paths;
+
+ /* Free temporary paths */
+ free ( netpath );
+
+ return path;
+
+ err_paths:
+ free ( netpath );
+ err_netdev:
+ return NULL;
+}
+
+/**
+ * Construct EFI device path for Fibre Channel device
+ *
+ * @v desc FCP device description
+ * @ret path EFI device path, or NULL on error
+ */
+EFI_DEVICE_PATH_PROTOCOL * efi_fcp_path ( struct fcp_description *desc ) {
+ struct {
+ FIBRECHANNELEX_DEVICE_PATH fc;
+ EFI_DEVICE_PATH_PROTOCOL end;
+ } __attribute__ (( packed )) *path;
+
+ /* Allocate device path */
+ path = zalloc ( sizeof ( *path ) );
+ if ( ! path )
+ return NULL;
+
+ /* Construct device path */
+ path->fc.Header.Type = MESSAGING_DEVICE_PATH;
+ path->fc.Header.SubType = MSG_FIBRECHANNELEX_DP;
+ path->fc.Header.Length[0] = sizeof ( path->fc );
+ memcpy ( path->fc.WWN, &desc->wwn, sizeof ( path->fc.WWN ) );
+ memcpy ( path->fc.Lun, &desc->lun, sizeof ( path->fc.Lun ) );
+ path->end.Type = END_DEVICE_PATH_TYPE;
+ path->end.SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE;
+ path->end.Length[0] = sizeof ( path->end );
+
+ return &path->fc.Header;
+}
+
+/**
+ * Construct EFI device path for Infiniband SRP device
+ *
+ * @v ib_srp Infiniband SRP device
+ * @ret path EFI device path, or NULL on error
+ */
+EFI_DEVICE_PATH_PROTOCOL * efi_ib_srp_path ( struct ib_srp_device *ib_srp ) {
+ const struct ipxe_ib_sbft *sbft = &ib_srp->sbft;
+ union ib_srp_target_port_id *id =
+ container_of ( &sbft->srp.target, union ib_srp_target_port_id,
+ srp );
+ struct efi_device *efidev;
+ EFI_DEVICE_PATH_PROTOCOL *path;
+ INFINIBAND_DEVICE_PATH *ibpath;
+ EFI_DEVICE_PATH_PROTOCOL *end;
+ size_t prefix_len;
+ size_t len;
+
+ /* Find parent EFI device */
+ efidev = efidev_parent ( ib_srp->ibdev->dev );
+ if ( ! efidev )
+ return NULL;
+
+ /* Calculate device path length */
+ prefix_len = efi_path_len ( efidev->path );
+ len = ( prefix_len + sizeof ( *ibpath ) + sizeof ( *end ) );
+
+ /* Allocate device path */
+ path = zalloc ( len );
+ if ( ! path )
+ return NULL;
+
+ /* Construct device path */
+ memcpy ( path, efidev->path, prefix_len );
+ ibpath = ( ( ( void * ) path ) + prefix_len );
+ ibpath->Header.Type = MESSAGING_DEVICE_PATH;
+ ibpath->Header.SubType = MSG_INFINIBAND_DP;
+ ibpath->Header.Length[0] = sizeof ( *ibpath );
+ ibpath->ResourceFlags = INFINIBAND_RESOURCE_FLAG_STORAGE_PROTOCOL;
+ memcpy ( ibpath->PortGid, &sbft->ib.dgid, sizeof ( ibpath->PortGid ) );
+ memcpy ( &ibpath->ServiceId, &sbft->ib.service_id,
+ sizeof ( ibpath->ServiceId ) );
+ memcpy ( &ibpath->TargetPortId, &id->ib.ioc_guid,
+ sizeof ( ibpath->TargetPortId ) );
+ memcpy ( &ibpath->DeviceId, &id->ib.id_ext,
+ sizeof ( ibpath->DeviceId ) );
+ end = ( ( ( void * ) ibpath ) + sizeof ( *ibpath ) );
+ end->Type = END_DEVICE_PATH_TYPE;
+ end->SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE;
+ end->Length[0] = sizeof ( *end );
+
+ return path;
+}
+
+/**
+ * Construct EFI device path for USB function
+ *
+ * @v func USB function
+ * @ret path EFI device path, or NULL on error
+ *
+ * The caller is responsible for eventually calling free() on the
+ * allocated device path.
+ */
+EFI_DEVICE_PATH_PROTOCOL * efi_usb_path ( struct usb_function *func ) {
+ struct usb_device *usb = func->usb;
+ struct efi_device *efidev;
+ EFI_DEVICE_PATH_PROTOCOL *path;
+ EFI_DEVICE_PATH_PROTOCOL *end;
+ USB_DEVICE_PATH *usbpath;
+ unsigned int count;
+ size_t prefix_len;
+ size_t len;
+
+ /* Sanity check */
+ assert ( func->desc.count >= 1 );
+
+ /* Find parent EFI device */
+ efidev = efidev_parent ( &func->dev );
+ if ( ! efidev )
+ return NULL;
+
+ /* Calculate device path length */
+ count = ( usb_depth ( usb ) + 1 );
+ prefix_len = efi_path_len ( efidev->path );
+ len = ( prefix_len + ( count * sizeof ( *usbpath ) ) +
+ sizeof ( *end ) );
+
+ /* Allocate device path */
+ path = zalloc ( len );
+ if ( ! path )
+ return NULL;
+
+ /* Construct device path */
+ memcpy ( path, efidev->path, prefix_len );
+ end = ( ( ( void * ) path ) + len - sizeof ( *end ) );
+ end->Type = END_DEVICE_PATH_TYPE;
+ end->SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE;
+ end->Length[0] = sizeof ( *end );
+ usbpath = ( ( ( void * ) end ) - sizeof ( *usbpath ) );
+ usbpath->InterfaceNumber = func->interface[0];
+ for ( ; 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 - 1 );
+ }
+
+ return path;
+}
+
+/**
+ * Describe object as an EFI device path
+ *
+ * @v intf Interface
+ * @ret path EFI device path, or NULL
+ *
+ * The caller is responsible for eventually calling free() on the
+ * allocated device path.
+ */
+EFI_DEVICE_PATH_PROTOCOL * efi_describe ( struct interface *intf ) {
+ struct interface *dest;
+ efi_describe_TYPE ( void * ) *op =
+ intf_get_dest_op ( intf, efi_describe, &dest );
+ void *object = intf_object ( dest );
+ EFI_DEVICE_PATH_PROTOCOL *path;
+
+ if ( op ) {
+ path = op ( object );
+ } else {
+ path = NULL;
+ }
+
+ intf_put ( dest );
+ return path;
+}
diff --git a/src/interface/efi/efi_pci.c b/src/interface/efi/efi_pci.c
index c1f451c99..4adee0fd8 100644
--- a/src/interface/efi/efi_pci.c
+++ b/src/interface/efi/efi_pci.c
@@ -26,6 +26,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <stdlib.h>
#include <errno.h>
#include <ipxe/pci.h>
+#include <ipxe/acpi.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/efi_pci.h>
#include <ipxe/efi/efi_driver.h>
@@ -62,15 +63,79 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
*/
/**
- * Locate EFI PCI root bridge I/O protocol
+ * Check for a matching PCI root bridge I/O protocol
+ *
+ * @v pci PCI device
+ * @v handle EFI PCI root bridge handle
+ * @v root EFI PCI root bridge I/O protocol
+ * @ret rc Return status code
+ */
+static int efipci_root_match ( struct pci_device *pci, EFI_HANDLE handle,
+ EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *root ) {
+ union {
+ union acpi_resource *res;
+ void *raw;
+ } u;
+ unsigned int segment = PCI_SEG ( pci->busdevfn );
+ unsigned int bus = PCI_BUS ( pci->busdevfn );
+ unsigned int start;
+ unsigned int end;
+ unsigned int tag;
+ EFI_STATUS efirc;
+ int rc;
+
+ /* Check segment number */
+ if ( root->SegmentNumber != segment )
+ return -ENOENT;
+
+ /* Get ACPI resource descriptors */
+ if ( ( efirc = root->Configuration ( root, &u.raw ) ) != 0 ) {
+ rc = -EEFI ( efirc );
+ DBGC ( pci, "EFIPCI " PCI_FMT " cannot get configuration for "
+ "%s: %s\n", PCI_ARGS ( pci ),
+ efi_handle_name ( handle ), strerror ( rc ) );
+ return rc;
+ }
+
+ /* Assume success if no bus number range descriptors are found */
+ rc = 0;
+
+ /* Parse resource descriptors */
+ for ( ; ( ( tag = acpi_resource_tag ( u.res ) ) != ACPI_END_RESOURCE ) ;
+ u.res = acpi_resource_next ( u.res ) ) {
+
+ /* Ignore anything other than a bus number range descriptor */
+ if ( tag != ACPI_QWORD_ADDRESS_SPACE_RESOURCE )
+ continue;
+ if ( u.res->qword.type != ACPI_ADDRESS_TYPE_BUS )
+ continue;
+
+ /* Check for a matching bus number */
+ start = le64_to_cpu ( u.res->qword.min );
+ end = ( start + le64_to_cpu ( u.res->qword.len ) );
+ if ( ( bus >= start ) && ( bus < end ) )
+ return 0;
+
+ /* We have seen at least one non-matching range
+ * descriptor, so assume failure unless we find a
+ * subsequent match.
+ */
+ rc = -ENOENT;
+ }
+
+ return rc;
+}
+
+/**
+ * Open 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 ) {
+static int efipci_root_open ( 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;
@@ -105,7 +170,7 @@ static int efipci_root ( struct pci_device *pci, EFI_HANDLE *handle,
strerror ( rc ) );
continue;
}
- if ( u.root->SegmentNumber == PCI_SEG ( pci->busdevfn ) ) {
+ if ( efipci_root_match ( pci, *handle, u.root ) == 0 ) {
*root = u.root;
bs->FreePool ( handles );
return 0;
@@ -124,6 +189,19 @@ static int efipci_root ( struct pci_device *pci, EFI_HANDLE *handle,
}
/**
+ * Close EFI PCI root bridge I/O protocol
+ *
+ * @v handle EFI PCI root bridge handle
+ */
+static void efipci_root_close ( EFI_HANDLE handle ) {
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+
+ /* Close protocol */
+ bs->CloseProtocol ( handle, &efi_pci_root_bridge_io_protocol_guid,
+ efi_image_handle, handle );
+}
+
+/**
* Calculate EFI PCI configuration space address
*
* @v pci PCI device
@@ -149,14 +227,13 @@ static unsigned long efipci_address ( struct pci_device *pci,
*/
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 )
+ /* Open root bridge */
+ if ( ( rc = efipci_root_open ( pci, &handle, &root ) ) != 0 )
goto err_root;
/* Read from configuration space */
@@ -171,8 +248,7 @@ int efipci_read ( struct pci_device *pci, unsigned long location,
}
err_read:
- bs->CloseProtocol ( handle, &efi_pci_root_bridge_io_protocol_guid,
- efi_image_handle, handle );
+ efipci_root_close ( handle );
err_root:
return rc;
}
@@ -187,14 +263,13 @@ int efipci_read ( struct pci_device *pci, unsigned long location,
*/
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 )
+ /* Open root bridge */
+ if ( ( rc = efipci_root_open ( pci, &handle, &root ) ) != 0 )
goto err_root;
/* Read from configuration space */
@@ -209,12 +284,81 @@ int efipci_write ( struct pci_device *pci, unsigned long location,
}
err_write:
- bs->CloseProtocol ( handle, &efi_pci_root_bridge_io_protocol_guid,
- efi_image_handle, handle );
+ efipci_root_close ( handle );
err_root:
return rc;
}
+/**
+ * Map PCI bus address as an I/O address
+ *
+ * @v bus_addr PCI bus address
+ * @v len Length of region
+ * @ret io_addr I/O address, or NULL on error
+ */
+void * efipci_ioremap ( struct pci_device *pci, unsigned long bus_addr,
+ size_t len ) {
+ union {
+ union acpi_resource *res;
+ void *raw;
+ } u;
+ EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *root;
+ EFI_HANDLE handle;
+ unsigned int tag;
+ uint64_t offset;
+ uint64_t start;
+ uint64_t end;
+ EFI_STATUS efirc;
+ int rc;
+
+ /* Open root bridge */
+ if ( ( rc = efipci_root_open ( pci, &handle, &root ) ) != 0 )
+ goto err_root;
+
+ /* Get ACPI resource descriptors */
+ if ( ( efirc = root->Configuration ( root, &u.raw ) ) != 0 ) {
+ rc = -EEFI ( efirc );
+ DBGC ( pci, "EFIPCI " PCI_FMT " cannot get configuration: "
+ "%s\n", PCI_ARGS ( pci ), strerror ( rc ) );
+ goto err_config;
+ }
+
+ /* Parse resource descriptors */
+ for ( ; ( ( tag = acpi_resource_tag ( u.res ) ) != ACPI_END_RESOURCE ) ;
+ u.res = acpi_resource_next ( u.res ) ) {
+
+ /* Ignore anything other than a memory range descriptor */
+ if ( tag != ACPI_QWORD_ADDRESS_SPACE_RESOURCE )
+ continue;
+ if ( u.res->qword.type != ACPI_ADDRESS_TYPE_MEM )
+ continue;
+
+ /* Ignore descriptors that do not cover this memory range */
+ offset = le64_to_cpu ( u.res->qword.offset );
+ start = ( offset + le64_to_cpu ( u.res->qword.min ) );
+ end = ( start + le64_to_cpu ( u.res->qword.len ) );
+ if ( ( bus_addr < start ) || ( ( bus_addr + len ) > end ) )
+ continue;
+
+ /* Use this address space descriptor */
+ DBGC2 ( pci, "EFIPCI " PCI_FMT " %08lx+%zx -> ",
+ PCI_ARGS ( pci ), bus_addr, len );
+ bus_addr -= offset;
+ DBGC2 ( pci, "%08lx\n", bus_addr );
+ break;
+ }
+ if ( tag == ACPI_END_RESOURCE ) {
+ DBGC ( pci, "EFIPCI " PCI_FMT " %08lx+%zx is not within "
+ "root bridge address space\n",
+ PCI_ARGS ( pci ), bus_addr, len );
+ }
+
+ err_config:
+ efipci_root_close ( handle );
+ err_root:
+ return ioremap ( bus_addr, len );
+}
+
PROVIDE_PCIAPI_INLINE ( efi, pci_num_bus );
PROVIDE_PCIAPI_INLINE ( efi, pci_read_config_byte );
PROVIDE_PCIAPI_INLINE ( efi, pci_read_config_word );
@@ -222,6 +366,282 @@ PROVIDE_PCIAPI_INLINE ( efi, pci_read_config_dword );
PROVIDE_PCIAPI_INLINE ( efi, pci_write_config_byte );
PROVIDE_PCIAPI_INLINE ( efi, pci_write_config_word );
PROVIDE_PCIAPI_INLINE ( efi, pci_write_config_dword );
+PROVIDE_PCIAPI ( efi, pci_ioremap, efipci_ioremap );
+
+/******************************************************************************
+ *
+ * EFI PCI DMA mappings
+ *
+ ******************************************************************************
+ */
+
+/**
+ * Map buffer for DMA
+ *
+ * @v dma DMA device
+ * @v map DMA mapping to fill in
+ * @v addr Buffer address
+ * @v len Length of buffer
+ * @v flags Mapping flags
+ * @ret rc Return status code
+ */
+static int efipci_dma_map ( struct dma_device *dma, struct dma_mapping *map,
+ physaddr_t addr, size_t len, int flags ) {
+ struct efi_pci_device *efipci =
+ container_of ( dma, struct efi_pci_device, pci.dma );
+ struct pci_device *pci = &efipci->pci;
+ EFI_PCI_IO_PROTOCOL *pci_io = efipci->io;
+ EFI_PCI_IO_PROTOCOL_OPERATION op;
+ EFI_PHYSICAL_ADDRESS bus;
+ UINTN count;
+ VOID *mapping;
+ EFI_STATUS efirc;
+ int rc;
+
+ /* Sanity check */
+ assert ( map->dma == NULL );
+ assert ( map->offset == 0 );
+ assert ( map->token == NULL );
+
+ /* Determine operation */
+ switch ( flags ) {
+ case DMA_TX:
+ op = EfiPciIoOperationBusMasterRead;
+ break;
+ case DMA_RX:
+ op = EfiPciIoOperationBusMasterWrite;
+ break;
+ default:
+ op = EfiPciIoOperationBusMasterCommonBuffer;
+ break;
+ }
+
+ /* Map buffer (if non-zero length) */
+ count = len;
+ if ( len ) {
+ if ( ( efirc = pci_io->Map ( pci_io, op, phys_to_virt ( addr ),
+ &count, &bus, &mapping ) ) != 0 ) {
+ rc = -EEFI ( efirc );
+ DBGC ( pci, "EFIPCI " PCI_FMT " cannot map %08lx+%zx: "
+ "%s\n", PCI_ARGS ( pci ), addr, len,
+ strerror ( rc ) );
+ goto err_map;
+ }
+ } else {
+ bus = addr;
+ mapping = NULL;
+ }
+
+ /* Check that full length was mapped. The UEFI specification
+ * allows for multiple mappings to be required, but even the
+ * EDK2 PCI device drivers will fail if a platform ever
+ * requires this.
+ */
+ if ( count != len ) {
+ DBGC ( pci, "EFIPCI " PCI_FMT " attempted split mapping for "
+ "%08lx+%zx\n", PCI_ARGS ( pci ), addr, len );
+ rc = -ENOTSUP;
+ goto err_len;
+ }
+
+ /* Populate mapping */
+ map->dma = dma;
+ map->offset = ( bus - addr );
+ map->token = mapping;
+
+ /* Increment mapping count (for debugging) */
+ if ( DBG_LOG )
+ dma->mapped++;
+
+ return 0;
+
+ err_len:
+ pci_io->Unmap ( pci_io, mapping );
+ err_map:
+ return rc;
+}
+
+/**
+ * Unmap buffer
+ *
+ * @v dma DMA device
+ * @v map DMA mapping
+ */
+static void efipci_dma_unmap ( struct dma_device *dma,
+ struct dma_mapping *map ) {
+ struct efi_pci_device *efipci =
+ container_of ( dma, struct efi_pci_device, pci.dma );
+ EFI_PCI_IO_PROTOCOL *pci_io = efipci->io;
+
+ /* Unmap buffer (if non-zero length) */
+ if ( map->token )
+ pci_io->Unmap ( pci_io, map->token );
+
+ /* Clear mapping */
+ map->dma = NULL;
+ map->offset = 0;
+ map->token = NULL;
+
+ /* Decrement mapping count (for debugging) */
+ if ( DBG_LOG )
+ dma->mapped--;
+}
+
+/**
+ * Allocate and map DMA-coherent buffer
+ *
+ * @v dma DMA device
+ * @v map DMA mapping to fill in
+ * @v len Length of buffer
+ * @v align Physical alignment
+ * @ret addr Buffer address, or NULL on error
+ */
+static void * efipci_dma_alloc ( struct dma_device *dma,
+ struct dma_mapping *map,
+ size_t len, size_t align __unused ) {
+ struct efi_pci_device *efipci =
+ container_of ( dma, struct efi_pci_device, pci.dma );
+ struct pci_device *pci = &efipci->pci;
+ EFI_PCI_IO_PROTOCOL *pci_io = efipci->io;
+ unsigned int pages;
+ VOID *addr;
+ EFI_STATUS efirc;
+ int rc;
+
+ /* Calculate number of pages */
+ pages = ( ( len + EFI_PAGE_SIZE - 1 ) / EFI_PAGE_SIZE );
+
+ /* Allocate (page-aligned) buffer */
+ if ( ( efirc = pci_io->AllocateBuffer ( pci_io, AllocateAnyPages,
+ EfiBootServicesData, pages,
+ &addr, 0 ) ) != 0 ) {
+ rc = -EEFI ( efirc );
+ DBGC ( pci, "EFIPCI " PCI_FMT " could not allocate %zd bytes: "
+ "%s\n", PCI_ARGS ( pci ), len, strerror ( rc ) );
+ goto err_alloc;
+ }
+
+ /* Map buffer */
+ if ( ( rc = efipci_dma_map ( dma, map, virt_to_phys ( addr ),
+ len, DMA_BI ) ) != 0 )
+ goto err_map;
+
+ /* Increment allocation count (for debugging) */
+ if ( DBG_LOG )
+ dma->allocated++;
+
+ return addr;
+
+ efipci_dma_unmap ( dma, map );
+ err_map:
+ pci_io->FreeBuffer ( pci_io, pages, addr );
+ err_alloc:
+ return NULL;
+}
+
+/**
+ * Unmap and free DMA-coherent buffer
+ *
+ * @v dma DMA device
+ * @v map DMA mapping
+ * @v addr Buffer address
+ * @v len Length of buffer
+ */
+static void efipci_dma_free ( struct dma_device *dma, struct dma_mapping *map,
+ void *addr, size_t len ) {
+ struct efi_pci_device *efipci =
+ container_of ( dma, struct efi_pci_device, pci.dma );
+ EFI_PCI_IO_PROTOCOL *pci_io = efipci->io;
+ unsigned int pages;
+
+ /* Calculate number of pages */
+ pages = ( ( len + EFI_PAGE_SIZE - 1 ) / EFI_PAGE_SIZE );
+
+ /* Unmap buffer */
+ efipci_dma_unmap ( dma, map );
+
+ /* Free buffer */
+ pci_io->FreeBuffer ( pci_io, pages, addr );
+
+ /* Decrement allocation count (for debugging) */
+ if ( DBG_LOG )
+ dma->allocated--;
+}
+
+/**
+ * Allocate and map DMA-coherent buffer from external (user) memory
+ *
+ * @v dma DMA device
+ * @v map DMA mapping to fill in
+ * @v len Length of buffer
+ * @v align Physical alignment
+ * @ret addr Buffer address, or NULL on error
+ */
+static userptr_t efipci_dma_umalloc ( struct dma_device *dma,
+ struct dma_mapping *map,
+ size_t len, size_t align ) {
+ void *addr;
+
+ addr = efipci_dma_alloc ( dma, map, len, align );
+ return virt_to_user ( addr );
+}
+
+/**
+ * Unmap and free DMA-coherent buffer from external (user) memory
+ *
+ * @v dma DMA device
+ * @v map DMA mapping
+ * @v addr Buffer address
+ * @v len Length of buffer
+ */
+static void efipci_dma_ufree ( struct dma_device *dma, struct dma_mapping *map,
+ userptr_t addr, size_t len ) {
+
+ efipci_dma_free ( dma, map, user_to_virt ( addr, 0 ), len );
+}
+
+/**
+ * Set addressable space mask
+ *
+ * @v dma DMA device
+ * @v mask Addressable space mask
+ */
+static void efipci_dma_set_mask ( struct dma_device *dma, physaddr_t mask ) {
+ struct efi_pci_device *efipci =
+ container_of ( dma, struct efi_pci_device, pci.dma );
+ struct pci_device *pci = &efipci->pci;
+ EFI_PCI_IO_PROTOCOL *pci_io = efipci->io;
+ EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION op;
+ UINT64 attrs;
+ int is64;
+ EFI_STATUS efirc;
+ int rc;
+
+ /* Set dual address cycle attribute for 64-bit capable devices */
+ is64 = ( ( ( ( uint64_t ) mask ) + 1 ) == 0 );
+ op = ( is64 ? EfiPciIoAttributeOperationEnable :
+ EfiPciIoAttributeOperationDisable );
+ attrs = EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE;
+ if ( ( efirc = pci_io->Attributes ( pci_io, op, attrs, NULL ) ) != 0 ) {
+ rc = -EEFI ( efirc );
+ DBGC ( pci, "EFIPCI " PCI_FMT " could not %sable DAC: %s\n",
+ PCI_ARGS ( pci ), ( is64 ? "en" : "dis" ),
+ strerror ( rc ) );
+ /* Ignore failure: errors will manifest in mapping attempts */
+ return;
+ }
+}
+
+/** EFI PCI DMA operations */
+static struct dma_operations efipci_dma_operations = {
+ .map = efipci_dma_map,
+ .unmap = efipci_dma_unmap,
+ .alloc = efipci_dma_alloc,
+ .free = efipci_dma_free,
+ .umalloc = efipci_dma_umalloc,
+ .ufree = efipci_dma_ufree,
+ .set_mask = efipci_dma_set_mask,
+};
/******************************************************************************
*
@@ -235,11 +655,11 @@ PROVIDE_PCIAPI_INLINE ( efi, pci_write_config_dword );
*
* @v device EFI device handle
* @v attributes Protocol opening attributes
- * @v pci PCI device to fill in
+ * @v efipci EFI PCI device to fill in
* @ret rc Return status code
*/
int efipci_open ( EFI_HANDLE device, UINT32 attributes,
- struct pci_device *pci ) {
+ struct efi_pci_device *efipci ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
union {
EFI_PCI_IO_PROTOCOL *pci_io;
@@ -259,6 +679,7 @@ int efipci_open ( EFI_HANDLE device, UINT32 attributes,
efi_handle_name ( device ), strerror ( rc ) );
goto err_open_protocol;
}
+ efipci->io = pci_io.pci_io;
/* Get PCI bus:dev.fn address */
if ( ( efirc = pci_io.pci_io->GetLocation ( pci_io.pci_io, &pci_segment,
@@ -270,9 +691,10 @@ int efipci_open ( EFI_HANDLE device, UINT32 attributes,
goto err_get_location;
}
busdevfn = PCI_BUSDEVFN ( pci_segment, pci_bus, pci_dev, pci_fn );
- pci_init ( pci, busdevfn );
+ pci_init ( &efipci->pci, busdevfn );
+ dma_init ( &efipci->pci.dma, &efipci_dma_operations );
DBGCP ( device, "EFIPCI " PCI_FMT " is %s\n",
- PCI_ARGS ( pci ), efi_handle_name ( device ) );
+ PCI_ARGS ( &efipci->pci ), efi_handle_name ( device ) );
/* Try to enable I/O cycles, memory cycles, and bus mastering.
* Some platforms will 'helpfully' report errors if these bits
@@ -291,10 +713,10 @@ int efipci_open ( EFI_HANDLE device, UINT32 attributes,
EFI_PCI_IO_ATTRIBUTE_BUS_MASTER, NULL );
/* Populate PCI device */
- if ( ( rc = pci_read_config ( pci ) ) != 0 ) {
+ if ( ( rc = pci_read_config ( &efipci->pci ) ) != 0 ) {
DBGC ( device, "EFIPCI " PCI_FMT " cannot read PCI "
"configuration: %s\n",
- PCI_ARGS ( pci ), strerror ( rc ) );
+ PCI_ARGS ( &efipci->pci ), strerror ( rc ) );
goto err_pci_read_config;
}
@@ -324,15 +746,15 @@ void efipci_close ( EFI_HANDLE device ) {
* Get EFI PCI device information
*
* @v device EFI device handle
- * @v pci PCI device to fill in
+ * @v efipci EFI PCI device to fill in
* @ret rc Return status code
*/
-int efipci_info ( EFI_HANDLE device, struct pci_device *pci ) {
+int efipci_info ( EFI_HANDLE device, struct efi_pci_device *efipci ) {
int rc;
/* Open PCI device, if possible */
if ( ( rc = efipci_open ( device, EFI_OPEN_PROTOCOL_GET_PROTOCOL,
- pci ) ) != 0 )
+ efipci ) ) != 0 )
return rc;
/* Close PCI device */
@@ -355,23 +777,24 @@ int efipci_info ( EFI_HANDLE device, struct pci_device *pci ) {
* @ret rc Return status code
*/
static int efipci_supported ( EFI_HANDLE device ) {
- struct pci_device pci;
+ struct efi_pci_device efipci;
int rc;
/* Get PCI device information */
- if ( ( rc = efipci_info ( device, &pci ) ) != 0 )
+ if ( ( rc = efipci_info ( device, &efipci ) ) != 0 )
return rc;
/* Look for a driver */
- if ( ( rc = pci_find_driver ( &pci ) ) != 0 ) {
+ if ( ( rc = pci_find_driver ( &efipci.pci ) ) != 0 ) {
DBGC ( device, "EFIPCI " PCI_FMT " (%04x:%04x class %06x) "
- "has no driver\n", PCI_ARGS ( &pci ), pci.vendor,
- pci.device, pci.class );
+ "has no driver\n", PCI_ARGS ( &efipci.pci ),
+ efipci.pci.vendor, efipci.pci.device,
+ efipci.pci.class );
return rc;
}
DBGC ( device, "EFIPCI " PCI_FMT " (%04x:%04x class %06x) has driver "
- "\"%s\"\n", PCI_ARGS ( &pci ), pci.vendor, pci.device,
- pci.class, pci.id->name );
+ "\"%s\"\n", PCI_ARGS ( &efipci.pci ), efipci.pci.vendor,
+ efipci.pci.device, efipci.pci.class, efipci.pci.id->name );
return 0;
}
@@ -384,12 +807,12 @@ static int efipci_supported ( EFI_HANDLE device ) {
*/
static int efipci_start ( struct efi_device *efidev ) {
EFI_HANDLE device = efidev->device;
- struct pci_device *pci;
+ struct efi_pci_device *efipci;
int rc;
/* Allocate PCI device */
- pci = zalloc ( sizeof ( *pci ) );
- if ( ! pci ) {
+ efipci = zalloc ( sizeof ( *efipci ) );
+ if ( ! efipci ) {
rc = -ENOMEM;
goto err_alloc;
}
@@ -397,7 +820,7 @@ static int efipci_start ( struct efi_device *efidev ) {
/* Open PCI device */
if ( ( rc = efipci_open ( device, ( EFI_OPEN_PROTOCOL_BY_DRIVER |
EFI_OPEN_PROTOCOL_EXCLUSIVE ),
- pci ) ) != 0 ) {
+ efipci ) ) != 0 ) {
DBGC ( device, "EFIPCI %s could not open PCI device: %s\n",
efi_handle_name ( device ), strerror ( rc ) );
DBGC_EFI_OPENERS ( device, device, &efi_pci_io_protocol_guid );
@@ -405,36 +828,36 @@ static int efipci_start ( struct efi_device *efidev ) {
}
/* Find driver */
- if ( ( rc = pci_find_driver ( pci ) ) != 0 ) {
+ if ( ( rc = pci_find_driver ( &efipci->pci ) ) != 0 ) {
DBGC ( device, "EFIPCI " PCI_FMT " has no driver\n",
- PCI_ARGS ( pci ) );
+ PCI_ARGS ( &efipci->pci ) );
goto err_find_driver;
}
/* Mark PCI device as a child of the EFI device */
- pci->dev.parent = &efidev->dev;
- list_add ( &pci->dev.siblings, &efidev->dev.children );
+ efipci->pci.dev.parent = &efidev->dev;
+ list_add ( &efipci->pci.dev.siblings, &efidev->dev.children );
/* Probe driver */
- if ( ( rc = pci_probe ( pci ) ) != 0 ) {
+ if ( ( rc = pci_probe ( &efipci->pci ) ) != 0 ) {
DBGC ( device, "EFIPCI " PCI_FMT " could not probe driver "
- "\"%s\": %s\n", PCI_ARGS ( pci ), pci->id->name,
- strerror ( rc ) );
+ "\"%s\": %s\n", PCI_ARGS ( &efipci->pci ),
+ efipci->pci.id->name, strerror ( rc ) );
goto err_probe;
}
DBGC ( device, "EFIPCI " PCI_FMT " using driver \"%s\"\n",
- PCI_ARGS ( pci ), pci->id->name );
+ PCI_ARGS ( &efipci->pci ), efipci->pci.id->name );
- efidev_set_drvdata ( efidev, pci );
+ efidev_set_drvdata ( efidev, efipci );
return 0;
- pci_remove ( pci );
+ pci_remove ( &efipci->pci );
err_probe:
- list_del ( &pci->dev.siblings );
+ list_del ( &efipci->pci.dev.siblings );
err_find_driver:
efipci_close ( device );
err_open:
- free ( pci );
+ free ( efipci );
err_alloc:
return rc;
}
@@ -445,13 +868,15 @@ static int efipci_start ( struct efi_device *efidev ) {
* @v efidev EFI device
*/
static void efipci_stop ( struct efi_device *efidev ) {
- struct pci_device *pci = efidev_get_drvdata ( efidev );
+ struct efi_pci_device *efipci = efidev_get_drvdata ( efidev );
EFI_HANDLE device = efidev->device;
- pci_remove ( pci );
- list_del ( &pci->dev.siblings );
+ pci_remove ( &efipci->pci );
+ list_del ( &efipci->pci.dev.siblings );
+ assert ( efipci->pci.dma.mapped == 0 );
+ assert ( efipci->pci.dma.allocated == 0 );
efipci_close ( device );
- free ( pci );
+ free ( efipci );
}
/** EFI PCI driver */
diff --git a/src/interface/efi/efi_pxe.c b/src/interface/efi/efi_pxe.c
index a1f81df59..15224a5e4 100644
--- a/src/interface/efi/efi_pxe.c
+++ b/src/interface/efi/efi_pxe.c
@@ -41,6 +41,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <ipxe/efi/efi.h>
#include <ipxe/efi/efi_snp.h>
#include <ipxe/efi/efi_pxe.h>
+#include <ipxe/efi/efi_null.h>
#include <ipxe/efi/Protocol/PxeBaseCode.h>
#include <ipxe/efi/Protocol/AppleNetBoot.h>
#include <usr/ifmgmt.h>
@@ -755,7 +756,8 @@ static EFI_STATUS EFIAPI efi_pxe_start ( EFI_PXE_BASE_CODE_PROTOCOL *base,
sa_family_t family = ( use_ipv6 ? AF_INET6 : AF_INET );
int rc;
- DBGC ( pxe, "PXE %s START %s\n", pxe->name, ( ipv6 ? "IPv6" : "IPv4" ));
+ DBGC ( pxe, "PXE %s START %s\n",
+ pxe->name, ( use_ipv6 ? "IPv6" : "IPv4" ) );
/* Initialise mode structure */
memset ( mode, 0, sizeof ( *mode ) );
@@ -1591,6 +1593,7 @@ int efi_pxe_install ( EFI_HANDLE handle, struct net_device *netdev ) {
struct efi_pxe *pxe;
struct in_addr ip;
BOOLEAN use_ipv6;
+ int leak = 0;
EFI_STATUS efirc;
int rc;
@@ -1643,14 +1646,23 @@ int efi_pxe_install ( EFI_HANDLE handle, struct net_device *netdev ) {
pxe->name, efi_handle_name ( handle ) );
return 0;
- bs->UninstallMultipleProtocolInterfaces (
+ if ( ( efirc = bs->UninstallMultipleProtocolInterfaces (
handle,
&efi_pxe_base_code_protocol_guid, &pxe->base,
&efi_apple_net_boot_protocol_guid, &pxe->apple,
- NULL );
+ NULL ) ) != 0 ) {
+ DBGC ( pxe, "PXE %s could not uninstall: %s\n",
+ pxe->name, strerror ( -EEFI ( efirc ) ) );
+ leak = 1;
+ }
+ efi_nullify_pxe ( &pxe->base );
+ efi_nullify_apple ( &pxe->apple );
err_install_protocol:
- ref_put ( &pxe->refcnt );
+ if ( ! leak )
+ ref_put ( &pxe->refcnt );
err_alloc:
+ if ( leak )
+ DBGC ( pxe, "PXE %s nullified and leaked\n", pxe->name );
return rc;
}
@@ -1662,6 +1674,8 @@ int efi_pxe_install ( EFI_HANDLE handle, struct net_device *netdev ) {
void efi_pxe_uninstall ( EFI_HANDLE handle ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
struct efi_pxe *pxe;
+ int leak = efi_shutdown_in_progress;
+ EFI_STATUS efirc;
/* Locate PXE base code */
pxe = efi_pxe_find ( handle );
@@ -1675,13 +1689,25 @@ void efi_pxe_uninstall ( EFI_HANDLE handle ) {
efi_pxe_stop ( &pxe->base );
/* Uninstall PXE base code protocol */
- bs->UninstallMultipleProtocolInterfaces (
+ if ( ( ! efi_shutdown_in_progress ) &&
+ ( ( efirc = bs->UninstallMultipleProtocolInterfaces (
handle,
&efi_pxe_base_code_protocol_guid, &pxe->base,
&efi_apple_net_boot_protocol_guid, &pxe->apple,
- NULL );
+ NULL ) ) != 0 ) ) {
+ DBGC ( pxe, "PXE %s could not uninstall: %s\n",
+ pxe->name, strerror ( -EEFI ( efirc ) ) );
+ leak = 1;
+ }
+ efi_nullify_pxe ( &pxe->base );
+ efi_nullify_apple ( &pxe->apple );
/* Remove from list and drop list's reference */
list_del ( &pxe->list );
- ref_put ( &pxe->refcnt );
+ if ( ! leak )
+ ref_put ( &pxe->refcnt );
+
+ /* Report leakage, if applicable */
+ if ( leak && ( ! efi_shutdown_in_progress ) )
+ DBGC ( pxe, "PXE %s nullified and leaked\n", pxe->name );
}
diff --git a/src/interface/efi/efi_smbios.c b/src/interface/efi/efi_smbios.c
index 304f95a56..d7877b0aa 100644
--- a/src/interface/efi/efi_smbios.c
+++ b/src/interface/efi/efi_smbios.c
@@ -34,6 +34,10 @@ FILE_LICENCE ( GPL2_OR_LATER );
static struct smbios_entry *smbios_entry;
EFI_USE_TABLE ( SMBIOS_TABLE, &smbios_entry, 0 );
+/** SMBIOS configuration table */
+static struct smbios3_entry *smbios3_entry;
+EFI_USE_TABLE ( SMBIOS3_TABLE, &smbios3_entry, 0 );
+
/**
* Find SMBIOS
*
@@ -42,26 +46,34 @@ EFI_USE_TABLE ( SMBIOS_TABLE, &smbios_entry, 0 );
*/
static int efi_find_smbios ( struct smbios *smbios ) {
- if ( ! smbios_entry ) {
- DBG ( "No SMBIOS table provided\n" );
- return -ENODEV;
+ /* Use 64-bit table if present */
+ if ( smbios3_entry && ( smbios3_entry->signature == SMBIOS3_SIGNATURE ) ) {
+ smbios->address = phys_to_user ( smbios3_entry->smbios_address );
+ smbios->len = smbios3_entry->smbios_len;
+ smbios->count = 0;
+ smbios->version =
+ SMBIOS_VERSION ( smbios3_entry->major, smbios3_entry->minor );
+ DBG ( "Found 64-bit SMBIOS v%d.%d entry point at %p (%lx+%zx)\n",
+ smbios3_entry->major, smbios3_entry->minor, smbios3_entry,
+ user_to_phys ( smbios->address, 0 ), smbios->len );
+ return 0;
}
- if ( smbios_entry->signature != SMBIOS_SIGNATURE ) {
- DBG ( "Invalid SMBIOS signature\n" );
- return -ENODEV;
+ /* Otherwise, use 32-bit table if present */
+ if ( smbios_entry && ( smbios_entry->signature == SMBIOS_SIGNATURE ) ) {
+ smbios->address = phys_to_user ( smbios_entry->smbios_address );
+ smbios->len = smbios_entry->smbios_len;
+ smbios->count = smbios_entry->smbios_count;
+ smbios->version =
+ SMBIOS_VERSION ( smbios_entry->major, smbios_entry->minor );
+ DBG ( "Found 32-bit SMBIOS v%d.%d entry point at %p (%lx+%zx)\n",
+ smbios_entry->major, smbios_entry->minor, smbios_entry,
+ user_to_phys ( smbios->address, 0 ), smbios->len );
+ return 0;
}
- smbios->address = phys_to_user ( smbios_entry->smbios_address );
- smbios->len = smbios_entry->smbios_len;
- smbios->count = smbios_entry->smbios_count;
- smbios->version =
- SMBIOS_VERSION ( smbios_entry->major, smbios_entry->minor );
- DBG ( "Found SMBIOS v%d.%d entry point at %p (%x+%zx)\n",
- smbios_entry->major, smbios_entry->minor, smbios_entry,
- smbios_entry->smbios_address, smbios->len );
-
- return 0;
+ DBG ( "No SMBIOS table provided\n" );
+ return -ENODEV;
}
PROVIDE_SMBIOS ( efi, find_smbios, efi_find_smbios );
diff --git a/src/interface/efi/efi_snp.c b/src/interface/efi/efi_snp.c
index d648700f6..6649eb1b0 100644
--- a/src/interface/efi/efi_snp.c
+++ b/src/interface/efi/efi_snp.c
@@ -33,8 +33,10 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <ipxe/efi/efi.h>
#include <ipxe/efi/efi_driver.h>
#include <ipxe/efi/efi_strings.h>
+#include <ipxe/efi/efi_path.h>
#include <ipxe/efi/efi_utils.h>
#include <ipxe/efi/efi_watchdog.h>
+#include <ipxe/efi/efi_null.h>
#include <ipxe/efi/efi_snp.h>
#include <usr/autoboot.h>
#include <config/general.h>
@@ -46,7 +48,7 @@ static LIST_HEAD ( efi_snp_devices );
static int efi_snp_claimed;
/** TPL prior to network devices being claimed */
-static EFI_TPL efi_snp_old_tpl;
+static struct efi_saved_tpl efi_snp_saved_tpl;
/* Downgrade user experience if configured to do so
*
@@ -190,9 +192,11 @@ efi_snp_start ( EFI_SIMPLE_NETWORK_PROTOCOL *snp ) {
DBGC ( snpdev, "SNPDEV %p START\n", snpdev );
- /* Fail if net device is currently claimed for use by iPXE */
- if ( efi_snp_claimed )
- return EFI_NOT_READY;
+ /* Allow start even if net device is currently claimed by iPXE */
+ if ( efi_snp_claimed ) {
+ DBGC ( snpdev, "SNPDEV %p allowing start while claimed\n",
+ snpdev );
+ }
snpdev->started = 1;
efi_snp_set_state ( snpdev );
@@ -233,24 +237,29 @@ efi_snp_stop ( EFI_SIMPLE_NETWORK_PROTOCOL *snp ) {
static EFI_STATUS EFIAPI
efi_snp_initialize ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
UINTN extra_rx_bufsize, UINTN extra_tx_bufsize ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
struct efi_snp_device *snpdev =
container_of ( snp, struct efi_snp_device, snp );
- EFI_TPL saved_tpl;
+ struct efi_saved_tpl tpl;
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 ) );
- /* Fail if net device is currently claimed for use by iPXE */
+ /* Do nothing if net device is currently claimed for use by
+ * iPXE. Do not return an error, because this will cause
+ * MnpDxe et al to fail to install the relevant child handles
+ * and to leave behind a partially initialised device handle
+ * that can cause a later system crash.
+ */
if ( efi_snp_claimed ) {
- rc = -EAGAIN;
- goto err_claimed;
+ DBGC ( snpdev, "SNPDEV %p ignoring initialization while "
+ "claimed\n", snpdev );
+ return 0;
}
/* Raise TPL */
- saved_tpl = bs->RaiseTPL ( TPL_CALLBACK );
+ efi_raise_tpl ( &tpl );
/* Open network device */
if ( ( rc = netdev_open ( snpdev->netdev ) ) != 0 ) {
@@ -261,8 +270,7 @@ efi_snp_initialize ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
efi_snp_set_state ( snpdev );
err_open:
- bs->RestoreTPL ( saved_tpl );
- err_claimed:
+ efi_restore_tpl ( &tpl );
return EFIRC ( rc );
}
@@ -275,10 +283,9 @@ efi_snp_initialize ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
*/
static EFI_STATUS EFIAPI
efi_snp_reset ( EFI_SIMPLE_NETWORK_PROTOCOL *snp, BOOLEAN ext_verify ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
struct efi_snp_device *snpdev =
container_of ( snp, struct efi_snp_device, snp );
- EFI_TPL saved_tpl;
+ struct efi_saved_tpl tpl;
int rc;
DBGC ( snpdev, "SNPDEV %p RESET (%s extended verification)\n",
@@ -291,7 +298,7 @@ efi_snp_reset ( EFI_SIMPLE_NETWORK_PROTOCOL *snp, BOOLEAN ext_verify ) {
}
/* Raise TPL */
- saved_tpl = bs->RaiseTPL ( TPL_CALLBACK );
+ efi_raise_tpl ( &tpl );
/* Close network device */
netdev_close ( snpdev->netdev );
@@ -307,7 +314,7 @@ efi_snp_reset ( EFI_SIMPLE_NETWORK_PROTOCOL *snp, BOOLEAN ext_verify ) {
efi_snp_set_state ( snpdev );
err_open:
- bs->RestoreTPL ( saved_tpl );
+ efi_restore_tpl ( &tpl );
err_claimed:
return EFIRC ( rc );
}
@@ -320,10 +327,9 @@ efi_snp_reset ( EFI_SIMPLE_NETWORK_PROTOCOL *snp, BOOLEAN ext_verify ) {
*/
static EFI_STATUS EFIAPI
efi_snp_shutdown ( EFI_SIMPLE_NETWORK_PROTOCOL *snp ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
struct efi_snp_device *snpdev =
container_of ( snp, struct efi_snp_device, snp );
- EFI_TPL saved_tpl;
+ struct efi_saved_tpl tpl;
DBGC ( snpdev, "SNPDEV %p SHUTDOWN\n", snpdev );
@@ -332,7 +338,7 @@ efi_snp_shutdown ( EFI_SIMPLE_NETWORK_PROTOCOL *snp ) {
return EFI_NOT_READY;
/* Raise TPL */
- saved_tpl = bs->RaiseTPL ( TPL_CALLBACK );
+ efi_raise_tpl ( &tpl );
/* Close network device */
netdev_close ( snpdev->netdev );
@@ -340,7 +346,7 @@ efi_snp_shutdown ( EFI_SIMPLE_NETWORK_PROTOCOL *snp ) {
efi_snp_flush ( snpdev );
/* Restore TPL */
- bs->RestoreTPL ( saved_tpl );
+ efi_restore_tpl ( &tpl );
return 0;
}
@@ -544,10 +550,9 @@ efi_snp_nvdata ( EFI_SIMPLE_NETWORK_PROTOCOL *snp, BOOLEAN read,
static EFI_STATUS EFIAPI
efi_snp_get_status ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
UINT32 *interrupts, VOID **txbuf ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
struct efi_snp_device *snpdev =
container_of ( snp, struct efi_snp_device, snp );
- EFI_TPL saved_tpl;
+ struct efi_saved_tpl tpl;
DBGC2 ( snpdev, "SNPDEV %p GET_STATUS", snpdev );
@@ -558,7 +563,7 @@ efi_snp_get_status ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
}
/* Raise TPL */
- saved_tpl = bs->RaiseTPL ( TPL_CALLBACK );
+ efi_raise_tpl ( &tpl );
/* Poll the network device */
efi_snp_poll ( snpdev );
@@ -583,7 +588,7 @@ efi_snp_get_status ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
}
/* Restore TPL */
- bs->RestoreTPL ( saved_tpl );
+ efi_restore_tpl ( &tpl );
DBGC2 ( snpdev, "\n" );
return 0;
@@ -606,14 +611,13 @@ efi_snp_transmit ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
UINTN ll_header_len, UINTN len, VOID *data,
EFI_MAC_ADDRESS *ll_src, EFI_MAC_ADDRESS *ll_dest,
UINT16 *net_proto ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
struct efi_snp_device *snpdev =
container_of ( snp, struct efi_snp_device, snp );
struct ll_protocol *ll_protocol = snpdev->netdev->ll_protocol;
+ struct efi_saved_tpl tpl;
struct io_buffer *iobuf;
size_t payload_len;
unsigned int tx_fill;
- EFI_TPL saved_tpl;
int rc;
DBGC2 ( snpdev, "SNPDEV %p TRANSMIT %p+%lx", snpdev, data,
@@ -640,7 +644,7 @@ efi_snp_transmit ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
}
/* Raise TPL */
- saved_tpl = bs->RaiseTPL ( TPL_CALLBACK );
+ efi_raise_tpl ( &tpl );
/* Sanity checks */
if ( ll_header_len ) {
@@ -725,7 +729,7 @@ efi_snp_transmit ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
snpdev->interrupts |= EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT;
/* Restore TPL */
- bs->RestoreTPL ( saved_tpl );
+ efi_restore_tpl ( &tpl );
return 0;
@@ -735,7 +739,7 @@ efi_snp_transmit ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
free_iob ( iobuf );
err_alloc_iob:
err_sanity:
- bs->RestoreTPL ( saved_tpl );
+ efi_restore_tpl ( &tpl );
err_claimed:
return EFIRC ( rc );
}
@@ -757,17 +761,16 @@ efi_snp_receive ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
UINTN *ll_header_len, UINTN *len, VOID *data,
EFI_MAC_ADDRESS *ll_src, EFI_MAC_ADDRESS *ll_dest,
UINT16 *net_proto ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
struct efi_snp_device *snpdev =
container_of ( snp, struct efi_snp_device, snp );
struct ll_protocol *ll_protocol = snpdev->netdev->ll_protocol;
+ struct efi_saved_tpl tpl;
struct io_buffer *iobuf;
const void *iob_ll_dest;
const void *iob_ll_src;
uint16_t iob_net_proto;
unsigned int iob_flags;
size_t copy_len;
- EFI_TPL saved_tpl;
int rc;
DBGC2 ( snpdev, "SNPDEV %p RECEIVE %p(+%lx)", snpdev, data,
@@ -780,7 +783,7 @@ efi_snp_receive ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
}
/* Raise TPL */
- saved_tpl = bs->RaiseTPL ( TPL_CALLBACK );
+ efi_raise_tpl ( &tpl );
/* Poll the network device */
efi_snp_poll ( snpdev );
@@ -829,7 +832,7 @@ efi_snp_receive ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
out_bad_ll_header:
free_iob ( iobuf );
out_no_packet:
- bs->RestoreTPL ( saved_tpl );
+ efi_restore_tpl ( &tpl );
err_claimed:
return EFIRC ( rc );
}
@@ -842,9 +845,8 @@ efi_snp_receive ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
*/
static VOID EFIAPI efi_snp_wait_for_packet ( EFI_EVENT event __unused,
VOID *context ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
struct efi_snp_device *snpdev = context;
- EFI_TPL saved_tpl;
+ struct efi_saved_tpl tpl;
DBGCP ( snpdev, "SNPDEV %p WAIT_FOR_PACKET\n", snpdev );
@@ -857,13 +859,13 @@ static VOID EFIAPI efi_snp_wait_for_packet ( EFI_EVENT event __unused,
return;
/* Raise TPL */
- saved_tpl = bs->RaiseTPL ( TPL_CALLBACK );
+ efi_raise_tpl ( &tpl );
/* Poll the network device */
efi_snp_poll ( snpdev );
/* Restore TPL */
- bs->RestoreTPL ( saved_tpl );
+ efi_restore_tpl ( &tpl );
}
/** SNP interface */
@@ -1623,13 +1625,9 @@ 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;
- 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;
+ int leak = 0;
EFI_STATUS efirc;
int rc;
@@ -1713,41 +1711,13 @@ static int efi_snp_probe ( struct net_device *netdev ) {
sizeof ( snpdev->name[0] ) ),
"%s", netdev->name );
- /* Allocate the new device path */
- path_prefix_len = efi_devpath_len ( efidev->path );
- snpdev->path = zalloc ( path_prefix_len + sizeof ( *macpath ) +
- sizeof ( *vlanpath ) + sizeof ( *path_end ) );
+ /* Construct device path */
+ snpdev->path = efi_netdev_path ( netdev );
if ( ! snpdev->path ) {
rc = -ENOMEM;
- goto err_alloc_device_path;
+ goto err_path;
}
- /* Populate the device path */
- memcpy ( snpdev->path, efidev->path, path_prefix_len );
- macpath = ( ( ( void * ) snpdev->path ) + path_prefix_len );
- 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 );
- 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;
- path_end->Length[0] = sizeof ( *path_end );
-
/* Install the SNP */
if ( ( efirc = bs->InstallMultipleProtocolInterfaces (
&snpdev->handle,
@@ -1826,7 +1796,7 @@ static int efi_snp_probe ( struct net_device *netdev ) {
list_del ( &snpdev->list );
if ( snpdev->package_list )
- efi_snp_hii_uninstall ( snpdev );
+ leak |= efi_snp_hii_uninstall ( snpdev );
efi_child_del ( efidev->device, snpdev->handle );
err_efi_child_add:
bs->CloseProtocol ( snpdev->handle, &efi_nii31_protocol_guid,
@@ -1835,7 +1805,7 @@ static int efi_snp_probe ( struct net_device *netdev ) {
bs->CloseProtocol ( snpdev->handle, &efi_nii_protocol_guid,
efi_image_handle, snpdev->handle );
err_open_nii:
- bs->UninstallMultipleProtocolInterfaces (
+ if ( ( efirc = bs->UninstallMultipleProtocolInterfaces (
snpdev->handle,
&efi_simple_network_protocol_guid, &snpdev->snp,
&efi_device_path_protocol_guid, snpdev->path,
@@ -1843,17 +1813,30 @@ static int efi_snp_probe ( struct net_device *netdev ) {
&efi_nii31_protocol_guid, &snpdev->nii,
&efi_component_name2_protocol_guid, &snpdev->name2,
&efi_load_file_protocol_guid, &snpdev->load_file,
- NULL );
+ NULL ) ) != 0 ) {
+ DBGC ( snpdev, "SNPDEV %p could not uninstall: %s\n",
+ snpdev, strerror ( -EEFI ( efirc ) ) );
+ leak = 1;
+ }
+ efi_nullify_snp ( &snpdev->snp );
+ efi_nullify_nii ( &snpdev->nii );
+ efi_nullify_name2 ( &snpdev->name2 );
+ efi_nullify_load_file ( &snpdev->load_file );
err_install_protocol_interface:
- free ( snpdev->path );
- err_alloc_device_path:
+ if ( ! leak )
+ free ( snpdev->path );
+ err_path:
bs->CloseEvent ( snpdev->snp.WaitForPacket );
err_create_event:
err_ll_addr_len:
- netdev_put ( netdev );
- free ( snpdev );
+ if ( ! leak ) {
+ netdev_put ( netdev );
+ free ( snpdev );
+ }
err_alloc_snp:
err_no_efidev:
+ if ( leak )
+ DBGC ( snpdev, "SNPDEV %p nullified and leaked\n", snpdev );
return rc;
}
@@ -1890,6 +1873,8 @@ static void efi_snp_notify ( struct net_device *netdev ) {
static void efi_snp_remove ( struct net_device *netdev ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
struct efi_snp_device *snpdev;
+ int leak = efi_shutdown_in_progress;
+ EFI_STATUS efirc;
/* Locate SNP device */
snpdev = efi_snp_demux ( netdev );
@@ -1901,13 +1886,14 @@ 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 );
+ leak |= 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 );
- bs->UninstallMultipleProtocolInterfaces (
+ if ( ( ! efi_shutdown_in_progress ) &&
+ ( ( efirc = bs->UninstallMultipleProtocolInterfaces (
snpdev->handle,
&efi_simple_network_protocol_guid, &snpdev->snp,
&efi_device_path_protocol_guid, snpdev->path,
@@ -1915,11 +1901,26 @@ static void efi_snp_remove ( struct net_device *netdev ) {
&efi_nii31_protocol_guid, &snpdev->nii,
&efi_component_name2_protocol_guid, &snpdev->name2,
&efi_load_file_protocol_guid, &snpdev->load_file,
- NULL );
- free ( snpdev->path );
+ NULL ) ) != 0 ) ) {
+ DBGC ( snpdev, "SNPDEV %p could not uninstall: %s\n",
+ snpdev, strerror ( -EEFI ( efirc ) ) );
+ leak = 1;
+ }
+ efi_nullify_snp ( &snpdev->snp );
+ efi_nullify_nii ( &snpdev->nii );
+ efi_nullify_name2 ( &snpdev->name2 );
+ efi_nullify_load_file ( &snpdev->load_file );
+ if ( ! leak )
+ free ( snpdev->path );
bs->CloseEvent ( snpdev->snp.WaitForPacket );
- netdev_put ( snpdev->netdev );
- free ( snpdev );
+ if ( ! leak ) {
+ netdev_put ( snpdev->netdev );
+ free ( snpdev );
+ }
+
+ /* Report leakage, if applicable */
+ if ( leak && ( ! efi_shutdown_in_progress ) )
+ DBGC ( snpdev, "SNPDEV %p nullified and leaked\n", snpdev );
}
/** SNP driver */
@@ -1967,12 +1968,11 @@ struct efi_snp_device * last_opened_snpdev ( void ) {
* @v delta Claim count change
*/
void efi_snp_add_claim ( int delta ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
struct efi_snp_device *snpdev;
/* Raise TPL if we are about to claim devices */
if ( ! efi_snp_claimed )
- efi_snp_old_tpl = bs->RaiseTPL ( TPL_CALLBACK );
+ efi_raise_tpl ( &efi_snp_saved_tpl );
/* Claim SNP devices */
efi_snp_claimed += delta;
@@ -1984,5 +1984,5 @@ void efi_snp_add_claim ( int delta ) {
/* Restore TPL if we have released devices */
if ( ! efi_snp_claimed )
- bs->RestoreTPL ( efi_snp_old_tpl );
+ efi_restore_tpl ( &efi_snp_saved_tpl );
}
diff --git a/src/interface/efi/efi_snp_hii.c b/src/interface/efi/efi_snp_hii.c
index 1e681a429..5d5f80cd7 100644
--- a/src/interface/efi/efi_snp_hii.c
+++ b/src/interface/efi/efi_snp_hii.c
@@ -63,7 +63,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <ipxe/efi/efi_hii.h>
#include <ipxe/efi/efi_snp.h>
#include <ipxe/efi/efi_strings.h>
+#include <ipxe/efi/efi_path.h>
#include <ipxe/efi/efi_utils.h>
+#include <ipxe/efi/efi_null.h>
#include <config/branding.h>
/** EFI platform setup formset GUID */
@@ -658,7 +660,8 @@ int efi_snp_hii_install ( struct efi_snp_device *snpdev ) {
VENDOR_DEVICE_PATH *vendor_path;
EFI_DEVICE_PATH_PROTOCOL *path_end;
size_t path_prefix_len;
- int efirc;
+ int leak = 0;
+ EFI_STATUS efirc;
int rc;
/* Do nothing if HII database protocol is not supported */
@@ -680,7 +683,7 @@ int efi_snp_hii_install ( struct efi_snp_device *snpdev ) {
}
/* Allocate the new device path */
- path_prefix_len = efi_devpath_len ( snpdev->path );
+ path_prefix_len = efi_path_len ( snpdev->path );
snpdev->hii_child_path = zalloc ( path_prefix_len +
sizeof ( *vendor_path ) +
sizeof ( *path_end ) );
@@ -750,23 +753,37 @@ int efi_snp_hii_install ( struct efi_snp_device *snpdev ) {
efi_child_del ( snpdev->handle, snpdev->hii_child_handle );
err_efi_child_add:
- bs->UninstallMultipleProtocolInterfaces (
+ if ( ( efirc = bs->UninstallMultipleProtocolInterfaces (
snpdev->hii_child_handle,
&efi_hii_config_access_protocol_guid, &snpdev->hii,
- NULL );
+ NULL ) ) != 0 ) {
+ DBGC ( snpdev, "SNPDEV %p could not uninstall HII protocol: "
+ "%s\n", snpdev, strerror ( -EEFI ( efirc ) ) );
+ leak = 1;
+ }
+ efi_nullify_hii ( &snpdev->hii );
err_install_protocol:
- efihii->RemovePackageList ( efihii, snpdev->hii_handle );
+ if ( ! leak )
+ efihii->RemovePackageList ( efihii, snpdev->hii_handle );
err_new_package_list:
- bs->UninstallMultipleProtocolInterfaces (
+ if ( ( efirc = bs->UninstallMultipleProtocolInterfaces (
snpdev->hii_child_handle,
&efi_device_path_protocol_guid, snpdev->hii_child_path,
- NULL );
+ NULL ) ) != 0 ) {
+ DBGC ( snpdev, "SNPDEV %p could not uninstall HII path: %s\n",
+ snpdev, strerror ( -EEFI ( efirc ) ) );
+ leak = 1;
+ }
err_hii_child_handle:
- free ( snpdev->hii_child_path );
- snpdev->hii_child_path = NULL;
+ if ( ! leak ) {
+ free ( snpdev->hii_child_path );
+ snpdev->hii_child_path = NULL;
+ }
err_alloc_child_path:
- free ( snpdev->package_list );
- snpdev->package_list = NULL;
+ if ( ! leak ) {
+ free ( snpdev->package_list );
+ snpdev->package_list = NULL;
+ }
err_build_package_list:
err_no_hii:
return rc;
@@ -776,27 +793,49 @@ int efi_snp_hii_install ( struct efi_snp_device *snpdev ) {
* Uninstall HII protocol and package for SNP device
*
* @v snpdev SNP device
+ * @ret leak Uninstallation failed: leak memory
*/
-void efi_snp_hii_uninstall ( struct efi_snp_device *snpdev ) {
+int efi_snp_hii_uninstall ( struct efi_snp_device *snpdev ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+ int leak = efi_shutdown_in_progress;
+ EFI_STATUS efirc;
/* Do nothing if HII database protocol is not supported */
if ( ! efihii )
- return;
+ return 0;
/* Uninstall protocols and remove package list */
efi_child_del ( snpdev->handle, snpdev->hii_child_handle );
- bs->UninstallMultipleProtocolInterfaces (
+ if ( ( ! efi_shutdown_in_progress ) &&
+ ( ( efirc = bs->UninstallMultipleProtocolInterfaces (
snpdev->hii_child_handle,
&efi_hii_config_access_protocol_guid, &snpdev->hii,
- NULL );
- efihii->RemovePackageList ( efihii, snpdev->hii_handle );
- bs->UninstallMultipleProtocolInterfaces (
+ NULL ) ) != 0 ) ) {
+ DBGC ( snpdev, "SNPDEV %p could not uninstall HII protocol: "
+ "%s\n", snpdev, strerror ( -EEFI ( efirc ) ) );
+ leak = 1;
+ }
+ efi_nullify_hii ( &snpdev->hii );
+ if ( ! leak )
+ efihii->RemovePackageList ( efihii, snpdev->hii_handle );
+ if ( ( ! efi_shutdown_in_progress ) &&
+ ( ( efirc = bs->UninstallMultipleProtocolInterfaces (
snpdev->hii_child_handle,
&efi_device_path_protocol_guid, snpdev->hii_child_path,
- NULL );
- free ( snpdev->hii_child_path );
- snpdev->hii_child_path = NULL;
- free ( snpdev->package_list );
- snpdev->package_list = NULL;
+ NULL ) ) != 0 ) ) {
+ DBGC ( snpdev, "SNPDEV %p could not uninstall HII path: %s\n",
+ snpdev, strerror ( -EEFI ( efirc ) ) );
+ leak = 1;
+ }
+ if ( ! leak ) {
+ free ( snpdev->hii_child_path );
+ snpdev->hii_child_path = NULL;
+ free ( snpdev->package_list );
+ snpdev->package_list = NULL;
+ }
+
+ /* Report leakage, if applicable */
+ if ( leak && ( ! efi_shutdown_in_progress ) )
+ DBGC ( snpdev, "SNPDEV %p HII nullified and leaked\n", snpdev );
+ return leak;
}
diff --git a/src/interface/efi/efi_timer.c b/src/interface/efi/efi_timer.c
index 8f40cb81a..405cd3454 100644
--- a/src/interface/efi/efi_timer.c
+++ b/src/interface/efi/efi_timer.c
@@ -97,8 +97,17 @@ static unsigned long efi_currticks ( void ) {
* 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 run at TPL_CALLBACK
- * almost all of the time, dropping to TPL_APPLICATION to
- * allow timer ticks to occur.
+ * almost all of the time, dropping to a lower TPL to allow
+ * timer ticks to occur.
+ *
+ * We record the external TPL at the point of entry into iPXE,
+ * and drop back only as far as this external TPL. This
+ * avoids the unexpected behaviour that may arise from having
+ * iPXE temporarily drop to TPL_APPLICATION in the middle of
+ * an entry point invoked at TPL_CALLBACK. The side effect is
+ * that iPXE's view of the system time is effectively frozen
+ * for the duration of any call made in to iPXE at
+ * TPL_CALLBACK or higher.
*
*
* For added excitement, UEFI provides no clean way for device
@@ -127,7 +136,7 @@ static unsigned long efi_currticks ( void ) {
if ( efi_shutdown_in_progress ) {
efi_jiffies++;
} else {
- bs->RestoreTPL ( TPL_APPLICATION );
+ bs->RestoreTPL ( efi_external_tpl );
bs->RaiseTPL ( TPL_CALLBACK );
}
diff --git a/src/interface/efi/efi_usb.c b/src/interface/efi/efi_usb.c
index 6f49b369e..28dfc8680 100644
--- a/src/interface/efi/efi_usb.c
+++ b/src/interface/efi/efi_usb.c
@@ -30,8 +30,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <errno.h>
#include <assert.h>
#include <ipxe/efi/efi.h>
-#include <ipxe/efi/efi_utils.h>
+#include <ipxe/efi/efi_path.h>
#include <ipxe/efi/efi_driver.h>
+#include <ipxe/efi/efi_null.h>
#include <ipxe/efi/efi_usb.h>
#include <ipxe/usb.h>
@@ -73,13 +74,14 @@ static const char * efi_usb_direction_name ( EFI_USB_DATA_DIRECTION direction ){
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;
+ struct usb_function *func = usbep->usbintf->usbdev->func;
/* Poll bus */
- usb_poll ( bus );
+ usb_poll ( func->usb->port->hub->bus );
/* Refill endpoint */
- usb_refill ( &usbep->ep );
+ if ( usbep->ep.open )
+ usb_refill ( &usbep->ep );
}
/**
@@ -118,6 +120,21 @@ static int efi_usb_mtu ( struct efi_usb_interface *usbintf,
}
/**
+ * Check if endpoint is open
+ *
+ * @v usbintf EFI USB interface
+ * @v endpoint Endpoint address
+ * @ret is_open Endpoint is open
+ */
+static int efi_usb_is_open ( struct efi_usb_interface *usbintf,
+ unsigned int endpoint ) {
+ unsigned int index = USB_ENDPOINT_IDX ( endpoint );
+ struct efi_usb_endpoint *usbep = usbintf->endpoint[index];
+
+ return ( usbep && usbep->ep.open );
+}
+
+/**
* Open endpoint
*
* @v usbintf EFI USB interface
@@ -139,6 +156,22 @@ static int efi_usb_open ( struct efi_usb_interface *usbintf,
EFI_STATUS efirc;
int rc;
+ /* Allocate structure, if needed. Once allocated, we leave
+ * the endpoint structure in place until the device is
+ * removed, to work around external UEFI code that closes the
+ * endpoint at illegal times.
+ */
+ usbep = usbintf->endpoint[index];
+ if ( ! usbep ) {
+ usbep = zalloc ( sizeof ( *usbep ) );
+ if ( ! usbep ) {
+ rc = -ENOMEM;
+ goto err_alloc;
+ }
+ usbep->usbintf = usbintf;
+ usbintf->endpoint[index] = usbep;
+ }
+
/* Get endpoint MTU */
mtu = efi_usb_mtu ( usbintf, endpoint );
if ( mtu < 0 ) {
@@ -147,13 +180,7 @@ static int efi_usb_open ( struct efi_usb_interface *usbintf,
}
/* 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_init ( &usbep->ep, usbdev->func->usb, driver );
usb_endpoint_describe ( &usbep->ep, endpoint, attributes, mtu, 0,
( interval << 3 /* microframes */ ) );
@@ -164,9 +191,6 @@ static int efi_usb_open ( struct efi_usb_interface *usbintf,
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 ) );
@@ -185,12 +209,10 @@ static int efi_usb_open ( struct efi_usb_interface *usbintf,
bs->CloseEvent ( usbep->event );
err_event:
- usbintf->endpoint[index] = usbep;
usb_endpoint_close ( &usbep->ep );
err_open:
- free ( usbep );
- err_alloc:
err_mtu:
+ err_alloc:
return rc;
}
@@ -216,12 +238,6 @@ static void efi_usb_close ( struct efi_usb_endpoint *usbep ) {
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;
}
/**
@@ -236,12 +252,32 @@ static void efi_usb_close_all ( struct efi_usb_interface *usbintf ) {
for ( i = 0 ; i < ( sizeof ( usbintf->endpoint ) /
sizeof ( usbintf->endpoint[0] ) ) ; i++ ) {
usbep = usbintf->endpoint[i];
- if ( usbep )
+ if ( usbep && usbep->ep.open )
efi_usb_close ( usbep );
}
}
/**
+ * Free all endpoints
+ *
+ * @v usbintf EFI USB interface
+ */
+static void efi_usb_free_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 ) {
+ assert ( ! usbep->ep.open );
+ free ( usbep );
+ usbintf->endpoint[i] = NULL;
+ }
+ }
+}
+
+/**
* Complete synchronous transfer
*
* @v ep USB endpoint
@@ -286,7 +322,7 @@ static int efi_usb_sync_transfer ( struct efi_usb_interface *usbintf,
int rc;
/* Open endpoint, if applicable */
- if ( ( ! usbintf->endpoint[index] ) &&
+ if ( ( ! efi_usb_is_open ( usbintf, endpoint ) ) &&
( ( rc = efi_usb_open ( usbintf, endpoint, attributes, 0,
&efi_usb_sync_driver ) ) != 0 ) ) {
goto err_open;
@@ -319,7 +355,7 @@ static int efi_usb_sync_transfer ( struct efi_usb_interface *usbintf,
for ( i = 0 ; ( ( timeout == 0 ) || ( i < timeout ) ) ; i++ ) {
/* Poll bus */
- usb_poll ( usbdev->usb->port->hub->bus );
+ usb_poll ( usbdev->func->usb->port->hub->bus );
/* Check for completion */
if ( usbep->rc != -EINPROGRESS ) {
@@ -377,15 +413,21 @@ static void efi_usb_async_complete ( struct usb_endpoint *ep,
goto drop;
/* Construct status */
- status = ( ( rc == 0 ) ? 0 : EFI_USB_ERR_STALL );
+ status = ( ( rc == 0 ) ? 0 : EFI_USB_ERR_SYSTEM );
- /* Report completion */
- usbep->callback ( iobuf->data, iob_len ( iobuf ), usbep->context,
- status );
+ /* Report completion, if applicable */
+ if ( usbep->callback ) {
+ usbep->callback ( iobuf->data, iob_len ( iobuf ),
+ usbep->context, status );
+ }
drop:
- /* Recycle I/O buffer */
- usb_recycle ( &usbep->ep, iobuf );
+ /* Recycle or free I/O buffer */
+ if ( usbep->ep.open ) {
+ usb_recycle ( &usbep->ep, iobuf );
+ } else {
+ free_iob ( iobuf );
+ }
}
/** Asynchronous endpoint operations */
@@ -416,6 +458,10 @@ static int efi_usb_async_start ( struct efi_usb_interface *usbintf,
EFI_STATUS efirc;
int rc;
+ /* Close endpoint, if applicable */
+ if ( efi_usb_is_open ( usbintf, endpoint ) )
+ efi_usb_close ( usbintf->endpoint[index] );
+
/* Open endpoint */
if ( ( rc = efi_usb_open ( usbintf, endpoint,
USB_ENDPOINT_ATTR_INTERRUPT, interval,
@@ -451,6 +497,8 @@ static int efi_usb_async_start ( struct efi_usb_interface *usbintf,
bs->SetTimer ( usbep->event, TimerCancel, 0 );
err_timer:
err_prefill:
+ usbep->callback = NULL;
+ usbep->context = NULL;
efi_usb_close ( usbep );
err_open:
return rc;
@@ -469,15 +517,16 @@ static void efi_usb_async_stop ( struct efi_usb_interface *usbintf,
unsigned int index = USB_ENDPOINT_IDX ( endpoint );
/* Do nothing if endpoint is already closed */
- usbep = usbintf->endpoint[index];
- if ( ! usbep )
+ if ( ! efi_usb_is_open ( usbintf, endpoint ) )
return;
+ usbep = usbintf->endpoint[index];
/* Stop timer */
bs->SetTimer ( usbep->event, TimerCancel, 0 );
- /* Close endpoint */
- efi_usb_close ( usbep );
+ /* Clear callback parameters */
+ usbep->callback = NULL;
+ usbep->context = NULL;
}
/******************************************************************************
@@ -505,7 +554,6 @@ efi_usb_control_transfer ( EFI_USB_IO_PROTOCOL *usbio,
EFI_USB_DATA_DIRECTION direction,
UINT32 timeout, VOID *data, UINTN len,
UINT32 *status ) {
- 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;
@@ -513,7 +561,7 @@ efi_usb_control_transfer ( EFI_USB_IO_PROTOCOL *usbio,
USB_REQUEST_TYPE ( packet->Request ) );
unsigned int value = le16_to_cpu ( packet->Value );
unsigned int index = le16_to_cpu ( packet->Index );
- EFI_TPL saved_tpl;
+ struct efi_saved_tpl tpl;
int rc;
DBGC2 ( usbdev, "USBDEV %s control %04x:%04x:%04x:%04x %s %dms "
@@ -523,7 +571,7 @@ efi_usb_control_transfer ( EFI_USB_IO_PROTOCOL *usbio,
( ( size_t ) len ) );
/* Raise TPL */
- saved_tpl = bs->RaiseTPL ( TPL_CALLBACK );
+ efi_raise_tpl ( &tpl );
/* Clear status */
*status = 0;
@@ -548,14 +596,13 @@ efi_usb_control_transfer ( EFI_USB_IO_PROTOCOL *usbio,
efi_usb_close_all ( usbintf );
/* Issue control transfer */
- if ( ( rc = usb_control ( usbdev->usb, request, value, index,
+ if ( ( rc = usb_control ( usbdev->func->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;
+ *status = EFI_USB_ERR_SYSTEM;
goto err_control;
}
@@ -568,7 +615,7 @@ efi_usb_control_transfer ( EFI_USB_IO_PROTOCOL *usbio,
err_control:
err_change_config:
- bs->RestoreTPL ( saved_tpl );
+ efi_restore_tpl ( &tpl );
return EFIRC ( rc );
}
@@ -586,12 +633,11 @@ efi_usb_control_transfer ( EFI_USB_IO_PROTOCOL *usbio,
static EFI_STATUS EFIAPI
efi_usb_bulk_transfer ( EFI_USB_IO_PROTOCOL *usbio, UINT8 endpoint, VOID *data,
UINTN *len, UINTN timeout, UINT32 *status ) {
- 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;
size_t actual = *len;
- EFI_TPL saved_tpl;
+ struct efi_saved_tpl tpl;
int rc;
DBGC2 ( usbdev, "USBDEV %s bulk %s %p+%zx %dms\n", usbintf->name,
@@ -599,7 +645,7 @@ efi_usb_bulk_transfer ( EFI_USB_IO_PROTOCOL *usbio, UINT8 endpoint, VOID *data,
( ( size_t ) *len ), ( ( unsigned int ) timeout ) );
/* Raise TPL */
- saved_tpl = bs->RaiseTPL ( TPL_CALLBACK );
+ efi_raise_tpl ( &tpl );
/* Clear status */
*status = 0;
@@ -614,7 +660,7 @@ efi_usb_bulk_transfer ( EFI_USB_IO_PROTOCOL *usbio, UINT8 endpoint, VOID *data,
}
err_transfer:
- bs->RestoreTPL ( saved_tpl );
+ efi_restore_tpl ( &tpl );
return EFIRC ( rc );
}
@@ -633,12 +679,11 @@ static EFI_STATUS EFIAPI
efi_usb_sync_interrupt_transfer ( EFI_USB_IO_PROTOCOL *usbio, UINT8 endpoint,
VOID *data, UINTN *len, UINTN timeout,
UINT32 *status ) {
- 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;
size_t actual = *len;
- EFI_TPL saved_tpl;
+ struct efi_saved_tpl tpl;
int rc;
DBGC2 ( usbdev, "USBDEV %s sync intr %s %p+%zx %dms\n", usbintf->name,
@@ -646,7 +691,7 @@ efi_usb_sync_interrupt_transfer ( EFI_USB_IO_PROTOCOL *usbio, UINT8 endpoint,
( ( size_t ) *len ), ( ( unsigned int ) timeout ) );
/* Raise TPL */
- saved_tpl = bs->RaiseTPL ( TPL_CALLBACK );
+ efi_raise_tpl ( &tpl );
/* Clear status */
*status = 0;
@@ -661,7 +706,7 @@ efi_usb_sync_interrupt_transfer ( EFI_USB_IO_PROTOCOL *usbio, UINT8 endpoint,
}
err_transfer:
- bs->RestoreTPL ( saved_tpl );
+ efi_restore_tpl ( &tpl );
return EFIRC ( rc );
}
@@ -682,11 +727,10 @@ 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 ) {
- 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;
- EFI_TPL saved_tpl;
+ struct efi_saved_tpl tpl;
int rc;
DBGC2 ( usbdev, "USBDEV %s async intr %s len %#zx int %d %p/%p\n",
@@ -696,7 +740,7 @@ efi_usb_async_interrupt_transfer ( EFI_USB_IO_PROTOCOL *usbio, UINT8 endpoint,
callback, context );
/* Raise TPL */
- saved_tpl = bs->RaiseTPL ( TPL_CALLBACK );
+ efi_raise_tpl ( &tpl );
/* Start/stop transfer as applicable */
if ( start ) {
@@ -718,7 +762,7 @@ efi_usb_async_interrupt_transfer ( EFI_USB_IO_PROTOCOL *usbio, UINT8 endpoint,
}
err_start:
- bs->RestoreTPL ( saved_tpl );
+ efi_restore_tpl ( &tpl );
return EFIRC ( rc );
}
@@ -796,7 +840,7 @@ efi_usb_get_device_descriptor ( EFI_USB_IO_PROTOCOL *usbio,
DBGC2 ( usbdev, "USBDEV %s get device descriptor\n", usbintf->name );
/* Copy cached device descriptor */
- memcpy ( efidesc, &usbdev->usb->device, sizeof ( *efidesc ) );
+ memcpy ( efidesc, &usbdev->func->usb->device, sizeof ( *efidesc ) );
return 0;
}
@@ -914,9 +958,9 @@ efi_usb_get_string_descriptor ( EFI_USB_IO_PROTOCOL *usbio, UINT16 language,
container_of ( usbio, struct efi_usb_interface, usbio );
struct efi_usb_device *usbdev = usbintf->usbdev;
struct usb_descriptor_header header;
+ struct efi_saved_tpl tpl;
VOID *buffer;
size_t len;
- EFI_TPL saved_tpl;
EFI_STATUS efirc;
int rc;
@@ -924,11 +968,12 @@ efi_usb_get_string_descriptor ( EFI_USB_IO_PROTOCOL *usbio, UINT16 language,
usbintf->name, language, index );
/* Raise TPL */
- saved_tpl = bs->RaiseTPL ( TPL_CALLBACK );
+ efi_raise_tpl ( &tpl );
/* Read descriptor header */
- if ( ( rc = usb_get_descriptor ( usbdev->usb, 0, USB_STRING_DESCRIPTOR,
- index, language, &header,
+ if ( ( rc = usb_get_descriptor ( usbdev->func->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,
@@ -936,6 +981,12 @@ efi_usb_get_string_descriptor ( EFI_USB_IO_PROTOCOL *usbio, UINT16 language,
goto err_get_header;
}
len = header.len;
+ if ( len < sizeof ( header ) ) {
+ DBGC ( usbdev, "USBDEV %s underlength string %d:%d\n",
+ usbintf->name, language, index );
+ rc = -EINVAL;
+ goto err_len;
+ }
/* Allocate buffer */
if ( ( efirc = bs->AllocatePool ( EfiBootServicesData, len,
@@ -945,9 +996,9 @@ efi_usb_get_string_descriptor ( EFI_USB_IO_PROTOCOL *usbio, UINT16 language,
}
/* Read whole descriptor */
- if ( ( rc = usb_get_descriptor ( usbdev->usb, 0, USB_STRING_DESCRIPTOR,
- index, language, buffer,
- len ) ) != 0 ) {
+ if ( ( rc = usb_get_descriptor ( usbdev->func->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 ) );
@@ -960,7 +1011,7 @@ efi_usb_get_string_descriptor ( EFI_USB_IO_PROTOCOL *usbio, UINT16 language,
memset ( ( buffer + len - sizeof ( header ) ), 0, sizeof ( **string ) );
/* Restore TPL */
- bs->RestoreTPL ( saved_tpl );
+ efi_restore_tpl ( &tpl );
/* Return allocated string */
*string = buffer;
@@ -969,8 +1020,9 @@ efi_usb_get_string_descriptor ( EFI_USB_IO_PROTOCOL *usbio, UINT16 language,
err_get_descriptor:
bs->FreePool ( buffer );
err_alloc:
+ err_len:
err_get_header:
- bs->RestoreTPL ( saved_tpl );
+ efi_restore_tpl ( &tpl );
return EFIRC ( rc );
}
@@ -992,9 +1044,8 @@ efi_usb_get_supported_languages ( EFI_USB_IO_PROTOCOL *usbio,
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;
+ *languages = usbdev->lang;
+ *len = usbdev->lang_len;
return 0;
}
@@ -1056,25 +1107,14 @@ static EFI_USB_IO_PROTOCOL efi_usb_io_protocol = {
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 usb_function *func = usbdev->func;
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;
+ int leak = 0;
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 );
+ usbintf = zalloc ( sizeof ( *usbintf ) );
if ( ! usbintf ) {
rc = -ENOMEM;
goto err_alloc;
@@ -1085,22 +1125,12 @@ static int efi_usb_install ( struct efi_usb_device *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 - 1 );
+ usbintf->path = efi_usb_path ( func );
+ if ( ! usbintf->path ) {
+ rc = -ENODEV;
+ goto err_path;
}
/* Add to list of interfaces */
@@ -1122,16 +1152,30 @@ static int efi_usb_install ( struct efi_usb_device *usbdev,
usbintf->name, efi_handle_name ( usbintf->handle ) );
return 0;
- efi_usb_close_all ( usbintf );
- bs->UninstallMultipleProtocolInterfaces (
+ if ( ( efirc = bs->UninstallMultipleProtocolInterfaces (
usbintf->handle,
&efi_usb_io_protocol_guid, &usbintf->usbio,
&efi_device_path_protocol_guid, usbintf->path,
- NULL );
+ NULL ) ) != 0 ) {
+ DBGC ( usbdev, "USBDEV %s could not uninstall: %s\n",
+ usbintf->name, strerror ( -EEFI ( efirc ) ) );
+ leak = 1;
+ }
+ efi_nullify_usbio ( &usbintf->usbio );
err_install_protocol:
+ efi_usb_close_all ( usbintf );
+ efi_usb_free_all ( usbintf );
list_del ( &usbintf->list );
- free ( usbintf );
+ if ( ! leak )
+ free ( usbintf->path );
+ err_path:
+ if ( ! leak )
+ free ( usbintf );
err_alloc:
+ if ( leak ) {
+ DBGC ( usbdev, "USBDEV %s nullified and leaked\n",
+ usbintf->name );
+ }
return rc;
}
@@ -1142,22 +1186,53 @@ static int efi_usb_install ( struct efi_usb_device *usbdev,
*/
static void efi_usb_uninstall ( struct efi_usb_interface *usbintf ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+ struct efi_usb_device *usbdev = usbintf->usbdev;
+ int leak = efi_shutdown_in_progress;
+ EFI_STATUS efirc;
- /* Close all endpoints */
- efi_usb_close_all ( usbintf );
+ DBGC ( usbdev, "USBDEV %s uninstalling %s\n",
+ usbintf->name, efi_handle_name ( usbintf->handle ) );
+
+ /* Disconnect controllers. This should not be necessary, but
+ * seems to be required on some platforms to avoid failures
+ * when uninstalling protocols.
+ */
+ if ( ! efi_shutdown_in_progress )
+ bs->DisconnectController ( usbintf->handle, NULL, NULL );
/* Uninstall protocols */
- bs->UninstallMultipleProtocolInterfaces (
+ if ( ( ! efi_shutdown_in_progress ) &&
+ ( ( efirc = bs->UninstallMultipleProtocolInterfaces (
usbintf->handle,
&efi_usb_io_protocol_guid, &usbintf->usbio,
&efi_device_path_protocol_guid, usbintf->path,
- NULL );
+ NULL ) ) != 0 ) ) {
+ DBGC ( usbdev, "USBDEV %s could not uninstall: %s\n",
+ usbintf->name, strerror ( -EEFI ( efirc ) ) );
+ leak = 1;
+ }
+ efi_nullify_usbio ( &usbintf->usbio );
+
+ /* Close and free all endpoints */
+ efi_usb_close_all ( usbintf );
+ efi_usb_free_all ( usbintf );
/* Remove from list of interfaces */
list_del ( &usbintf->list );
+ /* Free device path */
+ if ( ! leak )
+ free ( usbintf->path );
+
/* Free interface */
- free ( usbintf );
+ if ( ! leak )
+ free ( usbintf );
+
+ /* Report leakage, if applicable */
+ if ( leak && ( ! efi_shutdown_in_progress ) ) {
+ DBGC ( usbdev, "USBDEV %s nullified and leaked\n",
+ usbintf->name );
+ }
}
/**
@@ -1189,19 +1264,13 @@ static int efi_usb_probe ( struct usb_function *func,
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;
+ struct usb_descriptor_header *lang;
size_t config_len;
+ size_t lang_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 );
@@ -1211,27 +1280,30 @@ static int efi_usb_probe ( struct usb_function *func,
/* Assume no strings are present */
header.len = 0;
}
+ lang_len = ( ( header.len >= sizeof ( header ) ) ?
+ ( header.len - sizeof ( header ) ) : 0 );
/* Allocate and initialise structure */
- usbdev = zalloc ( sizeof ( *usbdev ) + config_len + header.len );
+ usbdev = zalloc ( sizeof ( *usbdev ) + config_len +
+ sizeof ( *lang ) + lang_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->func = func;
usbdev->config = ( ( ( void * ) usbdev ) + sizeof ( *usbdev ) );
memcpy ( usbdev->config, config, config_len );
- usbdev->languages = ( ( ( void * ) usbdev->config ) + config_len );
+ lang = ( ( ( void * ) usbdev->config ) + config_len );
+ usbdev->lang = ( ( ( void * ) lang ) + sizeof ( *lang ) );
+ usbdev->lang_len = lang_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 ) {
+ /* Get supported languages descriptor, if applicable */
+ if ( lang_len &&
+ ( ( rc = usb_get_descriptor ( usb, 0, USB_STRING_DESCRIPTOR,
+ 0, 0, lang, header.len ) ) != 0 ) ) {
DBGC ( usbdev, "USBDEV %s could not get supported languages: "
"%s\n", usbdev->name, strerror ( rc ) );
goto err_get_languages;
@@ -1256,7 +1328,6 @@ static int efi_usb_probe ( struct usb_function *func,
err_get_languages:
free ( usbdev );
err_alloc:
- err_no_efidev:
return rc;
}
@@ -1286,7 +1357,7 @@ static struct usb_device_id efi_usb_ids[] = {
};
/** USB I/O protocol driver */
-struct usb_driver usbio_driver __usb_driver = {
+struct usb_driver usbio_driver __usb_fallback_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 ),
diff --git a/src/interface/efi/efi_utils.c b/src/interface/efi/efi_utils.c
index 4dc75414c..8e660e9d7 100644
--- a/src/interface/efi/efi_utils.c
+++ b/src/interface/efi/efi_utils.c
@@ -33,36 +33,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
*/
/**
- * Find end of device path
- *
- * @v path Path to device
- * @ret path_end End of device path
- */
-EFI_DEVICE_PATH_PROTOCOL * efi_devpath_end ( EFI_DEVICE_PATH_PROTOCOL *path ) {
-
- while ( path->Type != END_DEVICE_PATH_TYPE ) {
- path = ( ( ( void * ) path ) +
- /* There's this amazing new-fangled thing known as
- * a UINT16, but who wants to use one of those? */
- ( ( path->Length[1] << 8 ) | path->Length[0] ) );
- }
-
- return 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
@@ -175,7 +145,7 @@ void efi_child_del ( EFI_HANDLE parent, EFI_HANDLE child ) {
static int efi_pci_info ( EFI_HANDLE device, const char *prefix,
struct device *dev ) {
EFI_HANDLE pci_device;
- struct pci_device pci;
+ struct efi_pci_device efipci;
int rc;
/* Find parent PCI device */
@@ -187,16 +157,16 @@ static int efi_pci_info ( EFI_HANDLE device, const char *prefix,
}
/* Get PCI device information */
- if ( ( rc = efipci_info ( pci_device, &pci ) ) != 0 ) {
+ if ( ( rc = efipci_info ( pci_device, &efipci ) ) != 0 ) {
DBGC ( device, "EFIDEV %s could not get PCI information: %s\n",
efi_handle_name ( device ), strerror ( rc ) );
return rc;
}
/* Populate device information */
- memcpy ( &dev->desc, &pci.dev.desc, sizeof ( dev->desc ) );
+ memcpy ( &dev->desc, &efipci.pci.dev.desc, sizeof ( dev->desc ) );
snprintf ( dev->name, sizeof ( dev->name ), "%s-%s",
- prefix, pci.dev.name );
+ prefix, efipci.pci.dev.name );
return 0;
}
diff --git a/src/interface/efi/efi_veto.c b/src/interface/efi/efi_veto.c
new file mode 100644
index 000000000..6ff7898e9
--- /dev/null
+++ b/src/interface/efi/efi_veto.c
@@ -0,0 +1,609 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <ipxe/settings.h>
+#include <ipxe/pci.h>
+#include <ipxe/efi/efi.h>
+#include <ipxe/efi/Protocol/DriverBinding.h>
+#include <ipxe/efi/Protocol/LoadedImage.h>
+#include <ipxe/efi/Protocol/ComponentName.h>
+#include <ipxe/efi/efi_veto.h>
+
+/** @file
+ *
+ * EFI driver vetoes
+ *
+ */
+
+/** A driver veto */
+struct efi_veto {
+ /** Veto name (for debugging) */
+ const char *name;
+ /**
+ * Check if driver is vetoed
+ *
+ * @v binding Driver binding protocol
+ * @v loaded Loaded image protocol
+ * @v wtf Component name protocol, if present
+ * @v manufacturer Manufacturer name, if present
+ * @v name Driver name (in "eng" language), if present
+ * @ret vetoed Driver is to be vetoed
+ */
+ int ( * veto ) ( EFI_DRIVER_BINDING_PROTOCOL *binding,
+ EFI_LOADED_IMAGE_PROTOCOL *loaded,
+ EFI_COMPONENT_NAME_PROTOCOL *wtf,
+ const char *manufacturer, const CHAR16 *name );
+};
+
+/**
+ * Unload an EFI driver
+ *
+ * @v driver Driver binding handle
+ * @ret rc Return status code
+ */
+static int efi_veto_unload ( EFI_HANDLE driver ) {
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+ EFI_STATUS efirc;
+ int rc;
+
+ /* Unload the driver */
+ if ( ( efirc = bs->UnloadImage ( driver ) ) != 0 ) {
+ rc = -EEFI ( efirc );
+ DBGC ( driver, "EFIVETO %s could not unload: %s\n",
+ efi_handle_name ( driver ), strerror ( rc ) );
+ return rc;
+ }
+
+ return 0;
+}
+
+/**
+ * Disconnect an EFI driver from all handles
+ *
+ * @v driver Driver binding handle
+ * @ret rc Return status code
+ */
+static int efi_veto_disconnect ( EFI_HANDLE driver ) {
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+ EFI_HANDLE *handles;
+ EFI_HANDLE handle;
+ UINTN count;
+ unsigned int i;
+ EFI_STATUS efirc;
+ int rc;
+
+ /* Enumerate all handles */
+ if ( ( efirc = bs->LocateHandleBuffer ( AllHandles, NULL, NULL,
+ &count, &handles ) ) != 0 ) {
+ rc = -EEFI ( efirc );
+ DBGC ( driver, "EFIVETO %s could not enumerate handles: %s\n",
+ efi_handle_name ( driver ), strerror ( rc ) );
+ goto err_list;
+ }
+
+ /* Disconnect driver from all handles, in reverse order */
+ for ( i = 0 ; i < count ; i++ ) {
+ handle = handles[ count - i - 1 ];
+ efirc = bs->DisconnectController ( handle, driver, NULL );
+ if ( ( efirc != 0 ) && ( efirc != EFI_NOT_FOUND ) ) {
+ rc = -EEFI ( efirc );
+ DBGC ( driver, "EFIVETO %s could not disconnect",
+ efi_handle_name ( driver ) );
+ DBGC ( driver, " %s: %s\n",
+ efi_handle_name ( handle ), strerror ( rc ) );
+ goto err_disconnect;
+ }
+ }
+
+ /* Success */
+ rc = 0;
+ DBGC2 ( driver, "EFIVETO %s disconnected all handles\n",
+ efi_handle_name ( driver ) );
+
+ err_disconnect:
+ bs->FreePool ( handles );
+ err_list:
+ return rc;
+}
+
+/**
+ * Uninstall an EFI driver binding protocol
+ *
+ * @v driver Driver binding handle
+ * @ret rc Return status code
+ */
+static int efi_veto_uninstall ( EFI_HANDLE driver ) {
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+ union {
+ EFI_DRIVER_BINDING_PROTOCOL *binding;
+ void *interface;
+ } binding;
+ EFI_STATUS efirc;
+ int rc;
+
+ /* Open driver binding protocol */
+ if ( ( efirc = bs->OpenProtocol (
+ driver, &efi_driver_binding_protocol_guid,
+ &binding.interface, efi_image_handle, driver,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
+ rc = -EEFI ( efirc );
+ DBGC ( driver, "EFIVETO %s could not open driver binding "
+ "protocol: %s\n", efi_handle_name ( driver ),
+ strerror ( rc ) );
+ return rc;
+ }
+
+ /* Close driver binding protocol */
+ bs->CloseProtocol ( driver, &efi_driver_binding_protocol_guid,
+ efi_image_handle, driver );
+
+ /* Uninstall driver binding protocol */
+ if ( ( efirc = bs->UninstallMultipleProtocolInterfaces (
+ driver, &efi_driver_binding_protocol_guid,
+ binding.binding, NULL ) ) != 0 ) {
+ rc = -EEFI ( efirc );
+ DBGC ( driver, "EFIVETO %s could not uninstall driver "
+ "binding protocol: %s\n",
+ efi_handle_name ( driver ), strerror ( rc ) );
+ return rc;
+ }
+
+ DBGC2 ( driver, "EFIVETO %s uninstalled driver binding protocol\n",
+ efi_handle_name ( driver ) );
+ return 0;
+}
+
+/**
+ * Close protocol on handle potentially opened by an EFI driver
+ *
+ * @v driver Driver binding handle
+ * @v handle Potentially opened handle
+ * @v protocol Opened protocol
+ * @ret rc Return status code
+ */
+static int efi_veto_close_protocol ( EFI_HANDLE driver, EFI_HANDLE handle,
+ EFI_GUID *protocol ) {
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+ EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *openers;
+ EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *opener;
+ EFI_HANDLE controller;
+ UINTN count;
+ unsigned int i;
+ EFI_STATUS efirc;
+ int rc;
+
+ /* Retrieve list of openers */
+ if ( ( efirc = bs->OpenProtocolInformation ( handle, protocol, &openers,
+ &count ) ) != 0 ) {
+ rc = -EEFI ( efirc );
+ DBGC ( driver, "EFIVETO %s could not retrieve openers",
+ efi_handle_name ( driver ) );
+ DBGC ( driver, " of %s %s: %s", efi_handle_name ( handle ),
+ efi_guid_ntoa ( protocol ), strerror ( rc ) );
+ goto err_list;
+ }
+
+ /* Close anything opened by this driver */
+ for ( i = 0 ; i < count ; i++ ) {
+ opener = &openers[i];
+ if ( opener->AgentHandle != driver )
+ continue;
+ controller = opener->ControllerHandle;
+ DBGC_EFI_OPENER ( driver, handle, protocol, opener );
+ if ( ( efirc = bs->CloseProtocol ( handle, protocol, driver,
+ controller ) ) != 0 ) {
+ rc = -EEFI ( efirc );
+ DBGC ( driver, "EFIVETO %s could not close stray open",
+ efi_handle_name ( driver ) );
+ DBGC ( driver, " of %s: %s\n",
+ efi_handle_name ( handle ), strerror ( rc ) );
+ goto err_close;
+ }
+ }
+
+ /* Success */
+ rc = 0;
+
+ err_close:
+ bs->FreePool ( openers );
+ err_list:
+ return rc;
+}
+
+/**
+ * Close handle potentially opened by an EFI driver
+ *
+ * @v driver Driver binding handle
+ * @v handle Potentially opened handle
+ * @ret rc Return status code
+ */
+static int efi_veto_close_handle ( EFI_HANDLE driver, EFI_HANDLE handle ) {
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+ EFI_GUID **protocols;
+ UINTN count;
+ unsigned int i;
+ EFI_STATUS efirc;
+ int rc;
+
+ /* Retrieve list of protocols */
+ if ( ( efirc = bs->ProtocolsPerHandle ( handle, &protocols,
+ &count ) ) != 0 ) {
+ rc = -EEFI ( efirc );
+ DBGC ( driver, "EFIVETO %s could not retrieve protocols",
+ efi_handle_name ( driver ) );
+ DBGC ( driver, " for %s: %s\n",
+ efi_handle_name ( handle ), strerror ( rc ) );
+ goto err_list;
+ }
+
+ /* Close each protocol */
+ for ( i = 0 ; i < count ; i++ ) {
+ if ( ( rc = efi_veto_close_protocol ( driver, handle,
+ protocols[i] ) ) != 0 )
+ goto err_close;
+ }
+
+ /* Success */
+ rc = 0;
+
+ err_close:
+ bs->FreePool ( protocols );
+ err_list:
+ return rc;
+}
+
+/**
+ * Close all remaining handles opened by an EFI driver
+ *
+ * @v driver Driver binding handle
+ * @ret rc Return status code
+ */
+static int efi_veto_close ( EFI_HANDLE driver ) {
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+ EFI_HANDLE *handles;
+ UINTN count;
+ unsigned int i;
+ EFI_STATUS efirc;
+ int rc;
+
+ /* Enumerate all handles */
+ if ( ( efirc = bs->LocateHandleBuffer ( AllHandles, NULL, NULL,
+ &count, &handles ) ) != 0 ) {
+ rc = -EEFI ( efirc );
+ DBGC ( driver, "EFIVETO %s could not enumerate handles: %s\n",
+ efi_handle_name ( driver ), strerror ( rc ) );
+ goto err_list;
+ }
+
+ /* Close each handle */
+ for ( i = 0 ; i < count ; i++ ) {
+ if ( ( rc = efi_veto_close_handle ( driver,
+ handles[i] ) ) != 0 )
+ goto err_close;
+ }
+
+ /* Success */
+ rc = 0;
+ DBGC2 ( driver, "EFIVETO %s closed all remaining handles\n",
+ efi_handle_name ( driver ) );
+
+ err_close:
+ bs->FreePool ( handles );
+ err_list:
+ return rc;
+}
+
+/**
+ * Terminate an EFI driver with extreme prejudice
+ *
+ * @v driver Driver binding handle
+ * @ret rc Return status code
+ */
+static int efi_veto_destroy ( EFI_HANDLE driver ) {
+ int rc;
+
+ /* Disconnect driver from all handles */
+ if ( ( rc = efi_veto_disconnect ( driver ) ) != 0 )
+ return rc;
+
+ /* Uninstall driver binding protocol */
+ if ( ( rc = efi_veto_uninstall ( driver ) ) != 0 )
+ return rc;
+
+ /* Close any remaining opened handles */
+ if ( ( rc = efi_veto_close ( driver ) ) != 0 )
+ return rc;
+
+ DBGC ( driver, "EFIVETO %s forcibly removed\n",
+ efi_handle_name ( driver ) );
+ return 0;
+}
+
+/**
+ * Veto an EFI driver
+ *
+ * @v driver Driver binding handle
+ * @ret rc Return status code
+ */
+static int efi_veto_driver ( EFI_HANDLE driver ) {
+ int rc;
+
+ /* Try gracefully unloading the driver */
+ if ( ( rc = efi_veto_unload ( driver ) ) == 0 )
+ return 0;
+
+ /* If that fails, use a hammer */
+ if ( ( rc = efi_veto_destroy ( driver ) ) == 0 )
+ return 0;
+
+ return rc;
+}
+
+/**
+ * Veto Dell Ip4ConfigDxe driver
+ *
+ * @v binding Driver binding protocol
+ * @v loaded Loaded image protocol
+ * @v wtf Component name protocol, if present
+ * @v manufacturer Manufacturer name, if present
+ * @v name Driver name, if present
+ * @ret vetoed Driver is to be vetoed
+ */
+static int
+efi_veto_dell_ip4config ( EFI_DRIVER_BINDING_PROTOCOL *binding __unused,
+ EFI_LOADED_IMAGE_PROTOCOL *loaded __unused,
+ EFI_COMPONENT_NAME_PROTOCOL *wtf __unused,
+ const char *manufacturer, const CHAR16 *name ) {
+ static const CHAR16 ip4cfg[] = L"IP4 CONFIG Network Service Driver";
+ static const char *dell = "Dell Inc.";
+
+ /* Check manufacturer and driver name */
+ if ( ! manufacturer )
+ return 0;
+ if ( ! name )
+ return 0;
+ if ( strcmp ( manufacturer, dell ) != 0 )
+ return 0;
+ if ( memcmp ( name, ip4cfg, sizeof ( ip4cfg ) ) != 0 )
+ return 0;
+
+ return 1;
+}
+
+/**
+ * Veto HP XhciDxe driver
+ *
+ * @v binding Driver binding protocol
+ * @v loaded Loaded image protocol
+ * @v wtf Component name protocol, if present
+ * @v manufacturer Manufacturer name, if present
+ * @v name Driver name, if present
+ * @ret vetoed Driver is to be vetoed
+ */
+static int
+efi_veto_hp_xhci ( EFI_DRIVER_BINDING_PROTOCOL *binding __unused,
+ EFI_LOADED_IMAGE_PROTOCOL *loaded __unused,
+ EFI_COMPONENT_NAME_PROTOCOL *wtf __unused,
+ const char *manufacturer, const CHAR16 *name ) {
+ static const CHAR16 xhci[] = L"Usb Xhci Driver";
+ static const char *hp = "HP";
+ struct pci_driver *driver;
+
+ /* Check manufacturer and driver name */
+ if ( ! manufacturer )
+ return 0;
+ if ( ! name )
+ return 0;
+ if ( strcmp ( manufacturer, hp ) != 0 )
+ return 0;
+ if ( memcmp ( name, xhci, sizeof ( xhci ) ) != 0 )
+ return 0;
+
+ /* Veto driver only if we have our own xHCI driver */
+ for_each_table_entry ( driver, PCI_DRIVERS ) {
+ if ( driver->class.class ==
+ PCI_CLASS ( PCI_CLASS_SERIAL, PCI_CLASS_SERIAL_USB,
+ PCI_CLASS_SERIAL_USB_XHCI ) ) {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+/** Driver vetoes */
+static struct efi_veto efi_vetoes[] = {
+ {
+ .name = "Dell Ip4Config",
+ .veto = efi_veto_dell_ip4config,
+ },
+ {
+ .name = "HP Xhci",
+ .veto = efi_veto_hp_xhci,
+ },
+};
+
+/**
+ * Find driver veto, if any
+ *
+ * @v driver Driver binding handle
+ * @v manufacturer Manufacturer name, if present
+ * @ret veto Driver veto, or NULL
+ * @ret rc Return status code
+ */
+static int efi_veto_find ( EFI_HANDLE driver, const char *manufacturer,
+ struct efi_veto **veto ) {
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+ union {
+ EFI_DRIVER_BINDING_PROTOCOL *binding;
+ void *interface;
+ } binding;
+ union {
+ EFI_LOADED_IMAGE_PROTOCOL *loaded;
+ void *interface;
+ } loaded;
+ union {
+ EFI_COMPONENT_NAME_PROTOCOL *wtf;
+ void *interface;
+ } wtf;
+ CHAR16 *name;
+ unsigned int i;
+ EFI_HANDLE image;
+ EFI_STATUS efirc;
+ int rc;
+
+ DBGC2 ( &efi_vetoes, "EFIVETO checking %s\n",
+ efi_handle_name ( driver ) );
+
+ /* Mark as not vetoed */
+ *veto = NULL;
+
+ /* Open driver binding protocol */
+ if ( ( efirc = bs->OpenProtocol (
+ driver, &efi_driver_binding_protocol_guid,
+ &binding.interface, efi_image_handle, driver,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
+ rc = -EEFI ( efirc );
+ DBGC ( driver, "EFIVETO %s could not open driver binding "
+ "protocol: %s\n", efi_handle_name ( driver ),
+ strerror ( rc ) );
+ goto err_binding;
+ }
+ image = binding.binding->ImageHandle;
+
+ /* Open loaded image protocol */
+ if ( ( efirc = bs->OpenProtocol (
+ image, &efi_loaded_image_protocol_guid,
+ &loaded.interface, efi_image_handle, image,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
+ rc = -EEFI ( efirc );
+ DBGC ( driver, "EFIVETO %s could not open",
+ efi_handle_name ( driver ) );
+ DBGC ( driver, " %s loaded image protocol: %s\n",
+ efi_handle_name ( image ), strerror ( rc ) );
+ goto err_loaded;
+ }
+
+ /* Open component name protocol, if present*/
+ if ( ( efirc = bs->OpenProtocol (
+ driver, &efi_component_name_protocol_guid,
+ &wtf.interface, efi_image_handle, driver,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
+ /* Ignore failure; is not required to be present */
+ wtf.interface = NULL;
+ }
+
+ /* Get driver name, if available */
+ if ( wtf.wtf &&
+ ( ( efirc = wtf.wtf->GetDriverName ( wtf.wtf, "eng",
+ &name ) == 0 ) ) ) {
+ /* Driver has a name */
+ } else {
+ /* Ignore failure; name is not required to be present */
+ name = NULL;
+ }
+
+ /* Check vetoes */
+ for ( i = 0 ; i < ( sizeof ( efi_vetoes ) /
+ sizeof ( efi_vetoes[0] ) ) ; i++ ) {
+ if ( efi_vetoes[i].veto ( binding.binding, loaded.loaded,
+ wtf.wtf, manufacturer, name ) ) {
+ *veto = &efi_vetoes[i];
+ break;
+ }
+ }
+
+ /* Success */
+ rc = 0;
+
+ /* Close protocols */
+ if ( wtf.wtf ) {
+ bs->CloseProtocol ( driver, &efi_component_name_protocol_guid,
+ efi_image_handle, driver );
+ }
+ bs->CloseProtocol ( image, &efi_loaded_image_protocol_guid,
+ efi_image_handle, image );
+ err_loaded:
+ bs->CloseProtocol ( driver, &efi_driver_binding_protocol_guid,
+ efi_image_handle, driver );
+ err_binding:
+ return rc;
+}
+
+/**
+ * Remove any vetoed drivers
+ *
+ */
+void efi_veto ( void ) {
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+ struct efi_veto *veto;
+ EFI_HANDLE *drivers;
+ EFI_HANDLE driver;
+ UINTN num_drivers;
+ unsigned int i;
+ char *manufacturer;
+ EFI_STATUS efirc;
+ int rc;
+
+ /* Locate all driver binding protocol handles */
+ if ( ( efirc = bs->LocateHandleBuffer (
+ ByProtocol, &efi_driver_binding_protocol_guid,
+ NULL, &num_drivers, &drivers ) ) != 0 ) {
+ rc = -EEFI ( efirc );
+ DBGC ( &efi_vetoes, "EFIVETO could not list all drivers: "
+ "%s\n", strerror ( rc ) );
+ return;
+ }
+
+ /* Get manufacturer name */
+ fetch_string_setting_copy ( NULL, &manufacturer_setting,
+ &manufacturer );
+
+ /* Unload any vetoed drivers */
+ for ( i = 0 ; i < num_drivers ; i++ ) {
+ driver = drivers[i];
+ if ( ( rc = efi_veto_find ( driver, manufacturer,
+ &veto ) ) != 0 ) {
+ DBGC ( driver, "EFIVETO %s could not determine "
+ "vetoing: %s\n",
+ efi_handle_name ( driver ), strerror ( rc ) );
+ continue;
+ }
+ if ( ! veto )
+ continue;
+ DBGC ( driver, "EFIVETO %s is vetoed (%s)\n",
+ efi_handle_name ( driver ), veto->name );
+ if ( ( rc = efi_veto_driver ( driver ) ) != 0 ) {
+ DBGC ( driver, "EFIVETO %s could not veto: %s\n",
+ efi_handle_name ( driver ), strerror ( rc ) );
+ }
+ }
+
+ /* Free manufacturer name */
+ free ( manufacturer );
+
+ /* Free handle list */
+ bs->FreePool ( drivers );
+}
diff --git a/src/interface/efi/efi_wrap.c b/src/interface/efi/efi_wrap.c
index c0c40eec6..5c02a7ee1 100644
--- a/src/interface/efi/efi_wrap.c
+++ b/src/interface/efi/efi_wrap.c
@@ -37,14 +37,8 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <ipxe/efi/Protocol/LoadedImage.h>
#include <ipxe/efi/efi_wrap.h>
-/** EFI system table wrapper */
-static EFI_SYSTEM_TABLE efi_systab_wrapper;
-
-/** EFI boot services table wrapper */
-static EFI_BOOT_SERVICES efi_bs_wrapper;
-
/** Colour for debug messages */
-#define colour &efi_systab_wrapper
+#define colour &efi_systab
/**
* Convert EFI status code to text
@@ -112,6 +106,358 @@ static const char * efi_boolean ( BOOLEAN boolean ) {
}
/**
+ * Convert EFI TPL to text
+ *
+ * @v tpl Task priority level
+ * @ret text Task priority level as text
+ */
+static const char * efi_tpl ( EFI_TPL tpl ) {
+ static char buf[ 19 /* "0xXXXXXXXXXXXXXXXX" + NUL */ ];
+
+ switch ( tpl ) {
+ case TPL_APPLICATION: return "Application";
+ case TPL_CALLBACK: return "Callback";
+ case TPL_NOTIFY: return "Notify";
+ case TPL_HIGH_LEVEL: return "HighLevel";
+ default:
+ snprintf ( buf, sizeof ( buf ), "%#lx",
+ ( unsigned long ) tpl );
+ return buf;
+ }
+}
+
+/**
+ * Convert EFI allocation type to text
+ *
+ * @v type Allocation type
+ * @ret text Allocation type as text
+ */
+static const char * efi_allocate_type ( EFI_ALLOCATE_TYPE type ) {
+ static char buf[ 11 /* "0xXXXXXXXX" + NUL */ ];
+
+ switch ( type ) {
+ case AllocateAnyPages: return "AnyPages";
+ case AllocateMaxAddress: return "MaxAddress";
+ case AllocateAddress: return "Address";
+ default:
+ snprintf ( buf, sizeof ( buf ), "%#x", type );
+ return buf;
+ }
+}
+
+/**
+ * Convert EFI memory type to text
+ *
+ * @v type Memory type
+ * @ret text Memory type as text
+ */
+static const char * efi_memory_type ( EFI_MEMORY_TYPE type ) {
+ static char buf[ 11 /* "0xXXXXXXXX" + NUL */ ];
+
+ switch ( type ) {
+ case EfiReservedMemoryType: return "Reserved";
+ case EfiLoaderCode: return "LoaderCode";
+ case EfiLoaderData: return "LoaderData";
+ case EfiBootServicesCode: return "BootCode";
+ case EfiBootServicesData: return "BootData";
+ case EfiRuntimeServicesCode: return "RuntimeCode";
+ case EfiRuntimeServicesData: return "RuntimeData";
+ case EfiConventionalMemory: return "Conventional";
+ case EfiUnusableMemory: return "Unusable";
+ case EfiACPIReclaimMemory: return "ACPIReclaim";
+ case EfiACPIMemoryNVS: return "ACPINVS";
+ case EfiMemoryMappedIO: return "MMIO";
+ case EfiMemoryMappedIOPortSpace:return "PIO";
+ case EfiPalCode: return "PalCode";
+ case EfiPersistentMemory: return "Persistent";
+ default:
+ snprintf ( buf, sizeof ( buf ), "%#x", type );
+ return buf;
+ }
+}
+
+/**
+ * Convert EFI timer delay type to text
+ *
+ * @v type Timer delay type
+ * @ret text Timer delay type as text
+ */
+static const char * efi_timer_delay ( EFI_TIMER_DELAY type ) {
+ static char buf[ 11 /* "0xXXXXXXXX" + NUL */ ];
+
+ switch ( type ) {
+ case TimerCancel: return "Cancel";
+ case TimerPeriodic: return "Periodic";
+ case TimerRelative: return "Relative";
+ default:
+ snprintf ( buf, sizeof ( buf ), "%#x", type );
+ return buf;
+ }
+}
+
+/**
+ * Wrap RaiseTPL()
+ *
+ */
+static EFI_TPL EFIAPI
+efi_raise_tpl_wrapper ( EFI_TPL new_tpl ) {
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+ void *retaddr = __builtin_return_address ( 0 );
+ EFI_TPL old_tpl;
+
+ DBGCP ( colour, "RaiseTPL ( %s ) ", efi_tpl ( new_tpl ) );
+ old_tpl = bs->RaiseTPL ( new_tpl );
+ DBGCP ( colour, "= %s -> %p\n", efi_tpl ( old_tpl ), retaddr );
+ return old_tpl;
+}
+
+/**
+ * Wrap RestoreTPL()
+ *
+ */
+static VOID EFIAPI
+efi_restore_tpl_wrapper ( EFI_TPL old_tpl ) {
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+ void *retaddr = __builtin_return_address ( 0 );
+
+ DBGCP ( colour, "RestoreTPL ( %s ) ", efi_tpl ( old_tpl ) );
+ bs->RestoreTPL ( old_tpl );
+ DBGCP ( colour, "-> %p\n", retaddr );
+}
+
+/**
+ * Wrap AllocatePages()
+ *
+ */
+static EFI_STATUS EFIAPI
+efi_allocate_pages_wrapper ( EFI_ALLOCATE_TYPE type,
+ EFI_MEMORY_TYPE memory_type, UINTN pages,
+ EFI_PHYSICAL_ADDRESS *memory ) {
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+ void *retaddr = __builtin_return_address ( 0 );
+ EFI_STATUS efirc;
+
+ DBGC2 ( colour, "AllocatePages ( %s, %s, %#llx, %#llx ) ",
+ efi_allocate_type ( type ), efi_memory_type ( memory_type ),
+ ( ( unsigned long long ) pages ),
+ ( ( unsigned long long ) *memory ) );
+ efirc = bs->AllocatePages ( type, memory_type, pages, memory );
+ DBGC2 ( colour, "= %s ( %#llx ) -> %p\n", efi_status ( efirc ),
+ ( ( unsigned long long ) *memory ), retaddr );
+ return efirc;
+}
+
+/**
+ * Wrap FreePages()
+ *
+ */
+static EFI_STATUS EFIAPI
+efi_free_pages_wrapper ( EFI_PHYSICAL_ADDRESS memory, UINTN pages ) {
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+ void *retaddr = __builtin_return_address ( 0 );
+ EFI_STATUS efirc;
+
+ DBGC2 ( colour, "FreePages ( %#llx, %#llx ) ",
+ ( ( unsigned long long ) memory ),
+ ( ( unsigned long long ) pages ) );
+ efirc = bs->FreePages ( memory, pages );
+ DBGC2 ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr );
+ return efirc;
+}
+
+/**
+ * Wrap GetMemoryMap()
+ *
+ */
+static EFI_STATUS EFIAPI
+efi_get_memory_map_wrapper ( UINTN *memory_map_size,
+ EFI_MEMORY_DESCRIPTOR *memory_map, UINTN *map_key,
+ UINTN *descriptor_size,
+ UINT32 *descriptor_version ) {
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+ void *retaddr = __builtin_return_address ( 0 );
+ EFI_MEMORY_DESCRIPTOR *desc;
+ size_t remaining;
+ EFI_STATUS efirc;
+
+ DBGC ( colour, "GetMemoryMap ( %#llx, %p ) ",
+ ( ( unsigned long long ) *memory_map_size ), memory_map );
+ efirc = bs->GetMemoryMap ( memory_map_size, memory_map, map_key,
+ descriptor_size, descriptor_version );
+ DBGC ( colour, "= %s ( %#llx, %#llx, %#llx, v%d",
+ efi_status ( efirc ),
+ ( ( unsigned long long ) *memory_map_size ),
+ ( ( unsigned long long ) *map_key ),
+ ( ( unsigned long long ) *descriptor_size ),
+ *descriptor_version );
+ if ( DBG_EXTRA && ( efirc == 0 ) ) {
+ DBGC2 ( colour, ",\n" );
+ for ( desc = memory_map, remaining = *memory_map_size ;
+ remaining >= *descriptor_size ;
+ desc = ( ( ( void * ) desc ) + *descriptor_size ),
+ remaining -= *descriptor_size ) {
+ DBGC2 ( colour, "%#016llx+%#08llx %#016llx "
+ "%s\n", desc->PhysicalStart,
+ ( desc->NumberOfPages * EFI_PAGE_SIZE ),
+ desc->Attribute,
+ efi_memory_type ( desc->Type ) );
+ }
+ } else {
+ DBGC ( colour, " " );
+ }
+ DBGC ( colour, ") -> %p\n", retaddr );
+ return efirc;
+}
+
+/**
+ * Wrap AllocatePool()
+ *
+ */
+static EFI_STATUS EFIAPI
+efi_allocate_pool_wrapper ( EFI_MEMORY_TYPE pool_type, UINTN size,
+ VOID **buffer ) {
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+ void *retaddr = __builtin_return_address ( 0 );
+ EFI_STATUS efirc;
+
+ DBGC2 ( colour, "AllocatePool ( %s, %#llx ) ",
+ efi_memory_type ( pool_type ),
+ ( ( unsigned long long ) size ) );
+ efirc = bs->AllocatePool ( pool_type, size, buffer );
+ DBGC2 ( colour, "= %s ( %p ) -> %p\n",
+ efi_status ( efirc ), *buffer, retaddr );
+ return efirc;
+}
+
+/**
+ * Wrap FreePool()
+ *
+ */
+static EFI_STATUS EFIAPI
+efi_free_pool_wrapper ( VOID *buffer ) {
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+ void *retaddr = __builtin_return_address ( 0 );
+ EFI_STATUS efirc;
+
+ DBGC2 ( colour, "FreePool ( %p ) ", buffer );
+ efirc = bs->FreePool ( buffer );
+ DBGC2 ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr );
+ return efirc;
+}
+
+/**
+ * Wrap CreateEvent()
+ *
+ */
+static EFI_STATUS EFIAPI
+efi_create_event_wrapper ( UINT32 type, EFI_TPL notify_tpl,
+ EFI_EVENT_NOTIFY notify_function,
+ VOID *notify_context, EFI_EVENT *event ) {
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+ void *retaddr = __builtin_return_address ( 0 );
+ EFI_STATUS efirc;
+
+ DBGC ( colour, "CreateEvent ( %#x, %s, %p, %p ) ",
+ type, efi_tpl ( notify_tpl ), notify_function, notify_context );
+ efirc = bs->CreateEvent ( type, notify_tpl, notify_function,
+ notify_context, event );
+ DBGC ( colour, "= %s ( %p ) -> %p\n",
+ efi_status ( efirc ), *event, retaddr );
+ return efirc;
+}
+
+/**
+ * Wrap SetTimer()
+ *
+ */
+static EFI_STATUS EFIAPI
+efi_set_timer_wrapper ( EFI_EVENT event, EFI_TIMER_DELAY type,
+ UINT64 trigger_time ) {
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+ void *retaddr = __builtin_return_address ( 0 );
+ EFI_STATUS efirc;
+
+ DBGC ( colour, "SetTimer ( %p, %s, %ld.%07ld00s ) ",
+ event, efi_timer_delay ( type ),
+ ( ( unsigned long ) ( trigger_time / 10000000 ) ),
+ ( ( unsigned long ) ( trigger_time % 10000000 ) ) );
+ efirc = bs->SetTimer ( event, type, trigger_time );
+ DBGC ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr );
+ return efirc;
+}
+
+/**
+ * Wrap WaitForEvent()
+ *
+ */
+static EFI_STATUS EFIAPI
+efi_wait_for_event_wrapper ( UINTN number_of_events, EFI_EVENT *event,
+ UINTN *index ) {
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+ void *retaddr = __builtin_return_address ( 0 );
+ unsigned int i;
+ EFI_STATUS efirc;
+
+ DBGC ( colour, "WaitForEvent (" );
+ for ( i = 0 ; i < number_of_events ; i++ )
+ DBGC ( colour, " %p", event[i] );
+ DBGC ( colour, " ) " );
+ efirc = bs->WaitForEvent ( number_of_events, event, index );
+ DBGC ( colour, "= %s", efi_status ( efirc ) );
+ if ( efirc == 0 )
+ DBGC ( colour, " ( %p )", event[*index] );
+ DBGC ( colour, " -> %p\n", retaddr );
+ return efirc;
+}
+
+/**
+ * Wrap SignalEvent()
+ *
+ */
+static EFI_STATUS EFIAPI
+efi_signal_event_wrapper ( EFI_EVENT event ) {
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+ void *retaddr = __builtin_return_address ( 0 );
+ EFI_STATUS efirc;
+
+ DBGC2 ( colour, "SignalEvent ( %p ) ", event );
+ efirc = bs->SignalEvent ( event );
+ DBGC2 ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr );
+ return efirc;
+}
+
+/**
+ * Wrap CloseEvent()
+ *
+ */
+static EFI_STATUS EFIAPI
+efi_close_event_wrapper ( EFI_EVENT event ) {
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+ void *retaddr = __builtin_return_address ( 0 );
+ EFI_STATUS efirc;
+
+ DBGC ( colour, "CloseEvent ( %p ) ", event );
+ efirc = bs->SignalEvent ( event );
+ DBGC ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr );
+ return efirc;
+}
+/**
+ * Wrap CheckEvent()
+ *
+ */
+static EFI_STATUS EFIAPI
+efi_check_event_wrapper ( EFI_EVENT event ) {
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+ void *retaddr = __builtin_return_address ( 0 );
+ EFI_STATUS efirc;
+
+ DBGCP ( colour, "CheckEvent ( %p ) ", event );
+ efirc = bs->SignalEvent ( event );
+ DBGCP ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr );
+ return efirc;
+}
+
+/**
* Wrap InstallProtocolInterface()
*
*/
@@ -195,6 +541,25 @@ efi_handle_protocol_wrapper ( EFI_HANDLE handle, EFI_GUID *protocol,
}
/**
+ * Wrap RegisterProtocolNotify()
+ *
+ */
+static EFI_STATUS EFIAPI
+efi_register_protocol_notify_wrapper ( EFI_GUID *protocol, EFI_EVENT event,
+ VOID **registration ) {
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+ void *retaddr = __builtin_return_address ( 0 );
+ EFI_STATUS efirc;
+
+ DBGC ( colour, "RegisterProtocolNotify ( %s, %p ) ",
+ efi_guid_ntoa ( protocol ), event );
+ efirc = bs->RegisterProtocolNotify ( protocol, event, registration );
+ DBGC ( colour, "= %s ( %p ) -> %p\n",
+ efi_status ( efirc ), *registration, retaddr );
+ return efirc;
+}
+
+/**
* Wrap LocateHandle()
*
*/
@@ -249,6 +614,23 @@ efi_locate_device_path_wrapper ( EFI_GUID *protocol,
}
/**
+ * Wrap InstallConfigurationTable()
+ *
+ */
+static EFI_STATUS EFIAPI
+efi_install_configuration_table_wrapper ( EFI_GUID *guid, VOID *table ) {
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+ void *retaddr = __builtin_return_address ( 0 );
+ EFI_STATUS efirc;
+
+ DBGC ( colour, "InstallConfigurationTable ( %s, %p ) ",
+ efi_guid_ntoa ( guid ), table );
+ efirc = bs->InstallConfigurationTable ( guid, table );
+ DBGC ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr );
+ return efirc;
+}
+
+/**
* Wrap LoadImage()
*
*/
@@ -362,6 +744,61 @@ efi_exit_boot_services_wrapper ( EFI_HANDLE image_handle, UINTN map_key ) {
}
/**
+ * Wrap GetNextMonotonicCount()
+ *
+ */
+static EFI_STATUS EFIAPI
+efi_get_next_monotonic_count_wrapper ( UINT64 *count ) {
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+ void *retaddr = __builtin_return_address ( 0 );
+ EFI_STATUS efirc;
+
+ DBGCP ( colour, "GetNextMonotonicCount() " );
+ efirc = bs->GetNextMonotonicCount ( count );
+ DBGCP ( colour, "= %s ( %#llx ) -> %p\n",
+ efi_status ( efirc ), *count, retaddr );
+ return efirc;
+}
+
+/**
+ * Wrap Stall()
+ *
+ */
+static EFI_STATUS EFIAPI
+efi_stall_wrapper ( UINTN microseconds ) {
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+ void *retaddr = __builtin_return_address ( 0 );
+ EFI_STATUS efirc;
+
+ DBGC2 ( colour, "Stall ( %ld.%06lds ) ",
+ ( ( unsigned long ) ( microseconds / 1000000 ) ),
+ ( ( unsigned long ) ( microseconds % 1000000 ) ) );
+ efirc = bs->Stall ( microseconds );
+ DBGC2 ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr );
+ return efirc;
+}
+
+/**
+ * Wrap SetWatchdogTimer()
+ *
+ */
+static EFI_STATUS EFIAPI
+efi_set_watchdog_timer_wrapper ( UINTN timeout, UINT64 watchdog_code,
+ UINTN data_size, CHAR16 *watchdog_data ) {
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+ void *retaddr = __builtin_return_address ( 0 );
+ EFI_STATUS efirc;
+
+ DBGC ( colour, "SetWatchdogTimer ( %lds, %#llx, %#llx, %p ) ",
+ ( ( unsigned long ) timeout ), watchdog_code,
+ ( ( unsigned long long ) data_size ), watchdog_data );
+ efirc = bs->SetWatchdogTimer ( timeout, watchdog_code, data_size,
+ watchdog_data );
+ DBGC ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr );
+ return efirc;
+}
+
+/**
* Wrap ConnectController()
*
*/
@@ -463,6 +900,29 @@ efi_close_protocol_wrapper ( EFI_HANDLE handle, EFI_GUID *protocol,
}
/**
+ * Wrap OpenProtocolInformation()
+ *
+ */
+static EFI_STATUS EFIAPI
+efi_open_protocol_information_wrapper ( EFI_HANDLE handle, EFI_GUID *protocol,
+ EFI_OPEN_PROTOCOL_INFORMATION_ENTRY
+ **entry_buffer,
+ UINTN *entry_count ) {
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+ void *retaddr = __builtin_return_address ( 0 );
+ EFI_STATUS efirc;
+
+ DBGC ( colour, "OpenProtocolInformation ( %s, %s ) ",
+ efi_handle_name ( handle ), efi_guid_ntoa ( protocol ) );
+ efirc = bs->OpenProtocolInformation ( handle, protocol, entry_buffer,
+ entry_count );
+ DBGC ( colour, "= %s ( %p, %#llx ) -> %p\n",
+ efi_status ( efirc ), *entry_buffer,
+ ( ( unsigned long long ) *entry_count ), retaddr );
+ return efirc;
+}
+
+/**
* Wrap ProtocolsPerHandle()
*
*/
@@ -542,29 +1002,157 @@ efi_locate_protocol_wrapper ( EFI_GUID *protocol, VOID *registration,
return efirc;
}
+/** Maximum number of interfaces for wrapped ...MultipleProtocolInterfaces() */
+#define MAX_WRAP_MULTI 20
+
/**
- * Wrap the calls made by a loaded image
+ * Wrap InstallMultipleProtocolInterfaces()
*
- * @v handle Image handle
*/
- void efi_wrap ( EFI_HANDLE handle ) {
+static EFI_STATUS EFIAPI
+efi_install_multiple_protocol_interfaces_wrapper ( EFI_HANDLE *handle, ... ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
- union {
- EFI_LOADED_IMAGE_PROTOCOL *image;
- void *intf;
- } loaded;
+ void *retaddr = __builtin_return_address ( 0 );
+ EFI_GUID *protocol[ MAX_WRAP_MULTI + 1 ];
+ VOID *interface[MAX_WRAP_MULTI];
+ VA_LIST ap;
+ unsigned int i;
EFI_STATUS efirc;
- int rc;
- /* Do nothing unless debugging is enabled */
- if ( ! DBG_LOG )
- return;
+ DBGC ( colour, "InstallMultipleProtocolInterfaces ( %s",
+ efi_handle_name ( *handle ) );
+ memset ( protocol, 0, sizeof ( protocol ) );
+ memset ( interface, 0, sizeof ( interface ) );
+ VA_START ( ap, handle );
+ for ( i = 0 ; ( protocol[i] = VA_ARG ( ap, EFI_GUID * ) ) ; i++ ) {
+ if ( i == MAX_WRAP_MULTI ) {
+ VA_END ( ap );
+ efirc = EFI_OUT_OF_RESOURCES;
+ DBGC ( colour, "<FATAL: too many arguments> ) = %s "
+ "-> %p\n", efi_status ( efirc ), retaddr );
+ return efirc;
+ }
+ interface[i] = VA_ARG ( ap, VOID * );
+ DBGC ( colour, ", %s, %p",
+ efi_guid_ntoa ( protocol[i] ), interface[i] );
+ }
+ VA_END ( ap );
+ DBGC ( colour, " ) " );
+ efirc = bs->InstallMultipleProtocolInterfaces ( handle,
+ protocol[0], interface[0], protocol[1], interface[1],
+ protocol[2], interface[2], protocol[3], interface[3],
+ protocol[4], interface[4], protocol[5], interface[5],
+ protocol[6], interface[6], protocol[7], interface[7],
+ protocol[8], interface[8], protocol[9], interface[9],
+ protocol[10], interface[10], protocol[11], interface[11],
+ protocol[12], interface[12], protocol[13], interface[13],
+ protocol[14], interface[14], protocol[15], interface[15],
+ protocol[16], interface[16], protocol[17], interface[17],
+ protocol[18], interface[18], protocol[19], interface[19],
+ NULL );
+ DBGC ( colour, "= %s ( %s ) -> %p\n",
+ efi_status ( efirc ), efi_handle_name ( *handle ), retaddr );
+ return efirc;
+}
- /* Populate table wrappers */
- memcpy ( &efi_systab_wrapper, efi_systab,
- sizeof ( efi_systab_wrapper ) );
+/**
+ * Wrap UninstallMultipleProtocolInterfaces()
+ *
+ */
+static EFI_STATUS EFIAPI
+efi_uninstall_multiple_protocol_interfaces_wrapper ( EFI_HANDLE handle, ... ) {
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+ void *retaddr = __builtin_return_address ( 0 );
+ EFI_GUID *protocol[ MAX_WRAP_MULTI + 1 ];
+ VOID *interface[MAX_WRAP_MULTI];
+ VA_LIST ap;
+ unsigned int i;
+ EFI_STATUS efirc;
+
+ DBGC ( colour, "UninstallMultipleProtocolInterfaces ( %s",
+ efi_handle_name ( handle ) );
+ memset ( protocol, 0, sizeof ( protocol ) );
+ memset ( interface, 0, sizeof ( interface ) );
+ VA_START ( ap, handle );
+ for ( i = 0 ; ( protocol[i] = VA_ARG ( ap, EFI_GUID * ) ) ; i++ ) {
+ if ( i == MAX_WRAP_MULTI ) {
+ VA_END ( ap );
+ efirc = EFI_OUT_OF_RESOURCES;
+ DBGC ( colour, "<FATAL: too many arguments> ) = %s "
+ "-> %p\n", efi_status ( efirc ), retaddr );
+ return efirc;
+ }
+ interface[i] = VA_ARG ( ap, VOID * );
+ DBGC ( colour, ", %s, %p",
+ efi_guid_ntoa ( protocol[i] ), interface[i] );
+ }
+ VA_END ( ap );
+ DBGC ( colour, " ) " );
+ efirc = bs->UninstallMultipleProtocolInterfaces ( handle,
+ protocol[0], interface[0], protocol[1], interface[1],
+ protocol[2], interface[2], protocol[3], interface[3],
+ protocol[4], interface[4], protocol[5], interface[5],
+ protocol[6], interface[6], protocol[7], interface[7],
+ protocol[8], interface[8], protocol[9], interface[9],
+ protocol[10], interface[10], protocol[11], interface[11],
+ protocol[12], interface[12], protocol[13], interface[13],
+ protocol[14], interface[14], protocol[15], interface[15],
+ protocol[16], interface[16], protocol[17], interface[17],
+ protocol[18], interface[18], protocol[19], interface[19],
+ NULL );
+ DBGC ( colour, "= %s -> %p\n",
+ efi_status ( efirc ), retaddr );
+ return efirc;
+}
+
+/**
+ * Wrap CreateEventEx()
+ *
+ */
+static EFI_STATUS EFIAPI
+efi_create_event_ex_wrapper ( UINT32 type, EFI_TPL notify_tpl,
+ EFI_EVENT_NOTIFY notify_function,
+ CONST VOID *notify_context,
+ CONST EFI_GUID *event_group, EFI_EVENT *event ) {
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+ void *retaddr = __builtin_return_address ( 0 );
+ EFI_STATUS efirc;
+
+ DBGC ( colour, "CreateEventEx ( %#x, %s, %p, %p, %s ) ",
+ type, efi_tpl ( notify_tpl ), notify_function, notify_context,
+ efi_guid_ntoa ( event_group ) );
+ efirc = bs->CreateEventEx ( type, notify_tpl, notify_function,
+ notify_context, event_group, event );
+ DBGC ( colour, "= %s ( %p ) -> %p\n",
+ efi_status ( efirc ), *event, retaddr );
+ return efirc;
+}
+
+/**
+ * Build table wrappers
+ *
+ * @ret systab Wrapped system table
+ */
+EFI_SYSTEM_TABLE * efi_wrap_systab ( void ) {
+ static EFI_SYSTEM_TABLE efi_systab_wrapper;
+ static EFI_BOOT_SERVICES efi_bs_wrapper;
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+
+ /* Build boot services table wrapper */
memcpy ( &efi_bs_wrapper, bs, sizeof ( efi_bs_wrapper ) );
- efi_systab_wrapper.BootServices = &efi_bs_wrapper;
+ efi_bs_wrapper.RaiseTPL = efi_raise_tpl_wrapper;
+ efi_bs_wrapper.RestoreTPL = efi_restore_tpl_wrapper;
+ efi_bs_wrapper.AllocatePages = efi_allocate_pages_wrapper;
+ efi_bs_wrapper.FreePages = efi_free_pages_wrapper;
+ efi_bs_wrapper.GetMemoryMap = efi_get_memory_map_wrapper;
+ efi_bs_wrapper.AllocatePool = efi_allocate_pool_wrapper;
+ efi_bs_wrapper.FreePool = efi_free_pool_wrapper;
+ efi_bs_wrapper.CreateEvent = efi_create_event_wrapper;
+ efi_bs_wrapper.SetTimer = efi_set_timer_wrapper;
+ efi_bs_wrapper.WaitForEvent = efi_wait_for_event_wrapper;
+ efi_bs_wrapper.SignalEvent = efi_signal_event_wrapper;
+ efi_bs_wrapper.CloseEvent = efi_close_event_wrapper;
+ efi_bs_wrapper.CheckEvent = efi_check_event_wrapper;
efi_bs_wrapper.InstallProtocolInterface
= efi_install_protocol_interface_wrapper;
efi_bs_wrapper.ReinstallProtocolInterface
@@ -572,24 +1160,65 @@ efi_locate_protocol_wrapper ( EFI_GUID *protocol, VOID *registration,
efi_bs_wrapper.UninstallProtocolInterface
= efi_uninstall_protocol_interface_wrapper;
efi_bs_wrapper.HandleProtocol = efi_handle_protocol_wrapper;
+ efi_bs_wrapper.RegisterProtocolNotify
+ = efi_register_protocol_notify_wrapper;
efi_bs_wrapper.LocateHandle = efi_locate_handle_wrapper;
efi_bs_wrapper.LocateDevicePath = efi_locate_device_path_wrapper;
+ efi_bs_wrapper.InstallConfigurationTable
+ = efi_install_configuration_table_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.GetNextMonotonicCount
+ = efi_get_next_monotonic_count_wrapper;
+ efi_bs_wrapper.Stall = efi_stall_wrapper;
+ efi_bs_wrapper.SetWatchdogTimer = efi_set_watchdog_timer_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.OpenProtocolInformation
+ = efi_open_protocol_information_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;
+ efi_bs_wrapper.InstallMultipleProtocolInterfaces
+ = efi_install_multiple_protocol_interfaces_wrapper;
+ efi_bs_wrapper.UninstallMultipleProtocolInterfaces
+ = efi_uninstall_multiple_protocol_interfaces_wrapper;
+ efi_bs_wrapper.CreateEventEx = efi_create_event_ex_wrapper;
+
+ /* Build system table wrapper */
+ memcpy ( &efi_systab_wrapper, efi_systab,
+ sizeof ( efi_systab_wrapper ) );
+ efi_systab_wrapper.BootServices = &efi_bs_wrapper;
+
+ return &efi_systab_wrapper;
+}
+
+/**
+ * Wrap the calls made by a loaded image
+ *
+ * @v handle Image handle
+ */
+void efi_wrap ( EFI_HANDLE handle ) {
+ EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+ union {
+ EFI_LOADED_IMAGE_PROTOCOL *image;
+ void *intf;
+ } loaded;
+ EFI_STATUS efirc;
+ int rc;
+
+ /* Do nothing unless debugging is enabled */
+ if ( ! DBG_LOG )
+ return;
/* Open loaded image protocol */
if ( ( efirc = bs->OpenProtocol ( handle,
@@ -603,7 +1232,7 @@ efi_locate_protocol_wrapper ( EFI_GUID *protocol, VOID *registration,
}
/* Provide system table wrapper to image */
- loaded.image->SystemTable = &efi_systab_wrapper;
+ loaded.image->SystemTable = efi_wrap_systab();
DBGC ( colour, "WRAP %s at base %p has protocols:\n",
efi_handle_name ( handle ), loaded.image->ImageBase );
DBGC_EFI_PROTOCOLS ( colour, handle );
diff --git a/src/interface/efi/efidrvprefix.c b/src/interface/efi/efidrvprefix.c
index ac7d94374..9ca54ff4f 100644
--- a/src/interface/efi/efidrvprefix.c
+++ b/src/interface/efi/efidrvprefix.c
@@ -34,8 +34,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
*/
EFI_STATUS EFIAPI _efidrv_start ( EFI_HANDLE image_handle,
EFI_SYSTEM_TABLE *systab ) {
- EFI_BOOT_SERVICES *bs;
- EFI_TPL saved_tpl;
+ static struct efi_saved_tpl tpl; /* avoid triggering stack protector */
EFI_STATUS efirc;
/* Initialise stack cookie */
@@ -46,15 +45,14 @@ EFI_STATUS EFIAPI _efidrv_start ( EFI_HANDLE image_handle,
return efirc;
/* Raise TPL */
- bs = efi_systab->BootServices;
- saved_tpl = bs->RaiseTPL ( TPL_CALLBACK );
+ efi_raise_tpl ( &tpl );
/* Initialise iPXE environment */
initialise();
startup();
/* Restore TPL */
- bs->RestoreTPL ( saved_tpl );
+ efi_restore_tpl ( &tpl );
return 0;
}
diff --git a/src/interface/efi/efiprefix.c b/src/interface/efi/efiprefix.c
index 2c5a5b31d..126c813d7 100644
--- a/src/interface/efi/efiprefix.c
+++ b/src/interface/efi/efiprefix.c
@@ -22,12 +22,15 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <stdlib.h>
#include <errno.h>
#include <ipxe/device.h>
+#include <ipxe/init.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/efi_driver.h>
#include <ipxe/efi/efi_snp.h>
#include <ipxe/efi/efi_autoboot.h>
+#include <ipxe/efi/efi_autoexec.h>
+#include <ipxe/efi/efi_cachedhcp.h>
#include <ipxe/efi/efi_watchdog.h>
-#include <ipxe/efi/efi_blacklist.h>
+#include <ipxe/efi/efi_veto.h>
/**
* EFI entry point
@@ -48,9 +51,6 @@ EFI_STATUS EFIAPI _efi_start ( EFI_HANDLE image_handle,
if ( ( efirc = efi_init ( image_handle, systab ) ) != 0 )
goto err_init;
- /* Record autoboot device (if any) */
- efi_set_autoboot();
-
/* Claim SNP devices for use by iPXE */
efi_snp_claim();
@@ -73,14 +73,36 @@ EFI_STATUS EFIAPI _efi_start ( EFI_HANDLE image_handle,
}
/**
+ * Initialise EFI application
+ *
+ */
+static void efi_init_application ( void ) {
+ EFI_HANDLE device = efi_loaded_image->DeviceHandle;
+
+ /* Identify autoboot device, if any */
+ efi_set_autoboot_ll_addr ( device );
+
+ /* Store cached DHCP packet, if any */
+ efi_cachedhcp_record ( device );
+
+ /* Load autoexec script, if any */
+ efi_autoexec_load ( device );
+}
+
+/** EFI application initialisation function */
+struct init_fn efi_init_application_fn __init_fn ( INIT_NORMAL ) = {
+ .initialise = efi_init_application,
+};
+
+/**
* Probe EFI root bus
*
* @v rootdev EFI root device
*/
static int efi_probe ( struct root_device *rootdev __unused ) {
- /* Unloaded any blacklisted drivers */
- efi_unload_blacklist();
+ /* Remove any vetoed drivers */
+ efi_veto();
/* Connect our drivers */
return efi_driver_connect_all();
diff --git a/src/interface/hyperv/vmbus.c b/src/interface/hyperv/vmbus.c
index e50fe9951..86d2a08d7 100644
--- a/src/interface/hyperv/vmbus.c
+++ b/src/interface/hyperv/vmbus.c
@@ -434,7 +434,7 @@ int vmbus_open ( struct vmbus_device *vmdev,
len = ( sizeof ( *vmdev->out ) + out_len +
sizeof ( *vmdev->in ) + in_len );
assert ( ( len % PAGE_SIZE ) == 0 );
- ring = malloc_dma ( len, PAGE_SIZE );
+ ring = malloc_phys ( len, PAGE_SIZE );
if ( ! ring ) {
rc = -ENOMEM;
goto err_alloc_ring;
@@ -509,7 +509,7 @@ int vmbus_open ( struct vmbus_device *vmdev,
err_post_message:
vmbus_gpadl_teardown ( vmdev, vmdev->gpadl );
err_establish:
- free_dma ( ring, len );
+ free_phys ( ring, len );
err_alloc_ring:
free ( packet );
err_alloc_packet:
@@ -555,7 +555,7 @@ void vmbus_close ( struct vmbus_device *vmdev ) {
/* Free ring buffer */
len = ( sizeof ( *vmdev->out ) + vmdev->out_len +
sizeof ( *vmdev->in ) + vmdev->in_len );
- free_dma ( vmdev->out, len );
+ free_phys ( vmdev->out, len );
vmdev->out = NULL;
vmdev->in = NULL;
diff --git a/src/interface/linux/linux_acpi.c b/src/interface/linux/linux_acpi.c
new file mode 100644
index 000000000..e658936f2
--- /dev/null
+++ b/src/interface/linux/linux_acpi.c
@@ -0,0 +1,148 @@
+/*
+ * Copyright (C) 2021 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.
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER );
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <ipxe/linux_api.h>
+#include <ipxe/linux_sysfs.h>
+#include <ipxe/linux.h>
+#include <ipxe/list.h>
+#include <ipxe/init.h>
+#include <ipxe/umalloc.h>
+#include <ipxe/acpi.h>
+
+/** ACPI sysfs directory */
+#define ACPI_SYSFS_PREFIX "/sys/firmware/acpi/tables/"
+
+/** A cached ACPI table */
+struct linux_acpi_table {
+ /** List of cached tables */
+ struct list_head list;
+ /** Signature */
+ uint32_t signature;
+ /** Index */
+ unsigned int index;
+ /** Cached data */
+ userptr_t data;
+};
+
+/** List of cached ACPI tables */
+static LIST_HEAD ( linux_acpi_tables );
+
+/**
+ * Locate ACPI table
+ *
+ * @v signature Requested table signature
+ * @v index Requested index of table with this signature
+ * @ret table Table, or UNULL if not found
+ */
+static userptr_t linux_acpi_find ( uint32_t signature, unsigned int index ) {
+ struct linux_acpi_table *table;
+ struct acpi_header *header;
+ union {
+ uint32_t signature;
+ char filename[5];
+ } u;
+ static const char prefix[] = ACPI_SYSFS_PREFIX;
+ char filename[ sizeof ( prefix ) - 1 /* NUL */ + 4 /* signature */
+ + 3 /* "999" */ + 1 /* NUL */ ];
+ int len;
+ int rc;
+
+ /* Check for existing table */
+ list_for_each_entry ( table, &linux_acpi_tables, list ) {
+ if ( ( table->signature == signature ) &&
+ ( table->index == index ) )
+ return table->data;
+ }
+
+ /* Allocate a new table */
+ table = malloc ( sizeof ( *table ) );
+ if ( ! table )
+ goto err_alloc;
+ table->signature = signature;
+ table->index = index;
+
+ /* Construct filename (including numeric suffix) */
+ memset ( &u, 0, sizeof ( u ) );
+ u.signature = le32_to_cpu ( signature );
+ snprintf ( filename, sizeof ( filename ), "%s%s%d", prefix,
+ u.filename, ( index + 1 ) );
+
+ /* Read file (with or without numeric suffix for index 0) */
+ len = linux_sysfs_read ( filename, &table->data );
+ if ( ( len < 0 ) && ( index == 0 ) ) {
+ filename[ sizeof ( prefix ) - 1 /* NUL */ +
+ 4 /* signature */ ] = '\0';
+ len = linux_sysfs_read ( filename, &table->data );
+ }
+ if ( len < 0 ) {
+ rc = len;
+ DBGC ( &linux_acpi_tables, "ACPI could not read %s: %s\n",
+ filename, strerror ( rc ) );
+ goto err_read;
+ }
+ header = user_to_virt ( table->data, 0 );
+ if ( ( ( ( size_t ) len ) < sizeof ( *header ) ) ||
+ ( ( ( size_t ) len ) < le32_to_cpu ( header->length ) ) ) {
+ rc = -ENOENT;
+ DBGC ( &linux_acpi_tables, "ACPI underlength %s (%d bytes)\n",
+ filename, len );
+ goto err_len;
+ }
+
+ /* Add to list of tables */
+ list_add ( &table->list, &linux_acpi_tables );
+ DBGC ( &linux_acpi_tables, "ACPI cached %s\n", filename );
+
+ return table->data;
+
+ err_len:
+ ufree ( table->data );
+ err_read:
+ free ( table );
+ err_alloc:
+ return UNULL;
+}
+
+/**
+ * Free cached ACPI data
+ *
+ */
+static void linux_acpi_shutdown ( int booting __unused ) {
+ struct linux_acpi_table *table;
+ struct linux_acpi_table *tmp;
+
+ list_for_each_entry_safe ( table, tmp, &linux_acpi_tables, list ) {
+ list_del ( &table->list );
+ ufree ( table->data );
+ free ( table );
+ }
+}
+
+/** ACPI shutdown function */
+struct startup_fn linux_acpi_startup_fn __startup_fn ( STARTUP_NORMAL ) = {
+ .name = "linux_acpi",
+ .shutdown = linux_acpi_shutdown,
+};
+
+PROVIDE_ACPI ( linux, acpi_find, linux_acpi_find );
diff --git a/src/interface/linux/linux_api.c b/src/interface/linux/linux_api.c
new file mode 100644
index 000000000..d1f969aa7
--- /dev/null
+++ b/src/interface/linux/linux_api.c
@@ -0,0 +1,551 @@
+/*
+ * Copyright (C) 2010 Piotr Jaroszyński <p.jaroszynski@gmail.com>.
+ * Copyright (C) 2021 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.
+ */
+
+#define _GNU_SOURCE
+#include <stdint.h>
+#include <stdarg.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <assert.h>
+#include <fcntl.h>
+#include <time.h>
+#include <poll.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <sys/stat.h>
+#include <netinet/in.h>
+#include <ipxe/linux_api.h>
+#include <ipxe/slirp.h>
+
+#ifdef HAVE_LIBSLIRP
+#include <slirp/libslirp.h>
+#endif
+
+#undef static_assert
+#define static_assert(x) _Static_assert(x, #x)
+
+/** @file
+ *
+ * Linux host API
+ *
+ */
+
+/** Construct prefixed symbol name */
+#define _C1( x, y ) x ## y
+#define _C2( x, y ) _C1 ( x, y )
+
+/** Construct prefixed symbol name for iPXE symbols */
+#define IPXE_SYM( symbol ) _C2 ( SYMBOL_PREFIX, symbol )
+
+/** Provide a prefixed symbol alias visible to iPXE code */
+#define PROVIDE_IPXE_SYM( symbol ) \
+ extern typeof ( symbol ) IPXE_SYM ( symbol ) \
+ __attribute__ (( alias ( #symbol) ))
+
+/** Most recent system call error */
+int linux_errno __attribute__ (( nocommon ));
+
+/******************************************************************************
+ *
+ * Host entry point
+ *
+ ******************************************************************************
+ */
+
+extern int IPXE_SYM ( _linux_start ) ( int argc, char **argv );
+
+/**
+ * Main entry point
+ *
+ * @v argc Argument count
+ * @v argv Argument list
+ * @ret rc Exit status
+ */
+int main ( int argc, char **argv ) {
+
+ return IPXE_SYM ( _linux_start ) ( argc, argv );
+}
+
+/******************************************************************************
+ *
+ * System call wrappers
+ *
+ ******************************************************************************
+ */
+
+/**
+ * Wrap open()
+ *
+ */
+int __asmcall linux_open ( const char *pathname, int flags, ... ) {
+ va_list args;
+ mode_t mode;
+ int ret;
+
+ va_start ( args, flags );
+ mode = va_arg ( args, mode_t );
+ va_end ( args );
+ ret = open ( pathname, flags, mode );
+ if ( ret == -1 )
+ linux_errno = errno;
+ return ret;
+}
+
+/**
+ * Wrap close()
+ *
+ */
+int __asmcall linux_close ( int fd ) {
+ int ret;
+
+ ret = close ( fd );
+ if ( ret == -1 )
+ linux_errno = errno;
+ return ret;
+}
+
+/**
+ * Wrap lseek()
+ *
+ */
+off_t __asmcall linux_lseek ( int fd, off_t offset, int whence ) {
+ off_t ret;
+
+ ret = lseek ( fd, offset, whence );
+ if ( ret == -1 )
+ linux_errno = errno;
+ return ret;
+}
+
+/**
+ * Wrap read()
+ *
+ */
+ssize_t __asmcall linux_read ( int fd, void *buf, size_t count ) {
+ ssize_t ret;
+
+ ret = read ( fd, buf, count );
+ if ( ret == -1 )
+ linux_errno = errno;
+ return ret;
+}
+
+/**
+ * Wrap write()
+ *
+ */
+ssize_t __asmcall linux_write ( int fd, const void *buf, size_t count ) {
+ ssize_t ret;
+
+ ret = write ( fd, buf, count );
+ if ( ret == -1 )
+ linux_errno = errno;
+ return ret;
+}
+
+/**
+ * Wrap fcntl()
+ *
+ */
+int __asmcall linux_fcntl ( int fd, int cmd, ... ) {
+ va_list args;
+ long arg;
+ int ret;
+
+ va_start ( args, cmd );
+ arg = va_arg ( args, long );
+ va_end ( args );
+ ret = fcntl ( fd, cmd, arg );
+ if ( ret == -1 )
+ linux_errno = errno;
+ return ret;
+}
+
+/**
+ * Wrap ioctl()
+ *
+ */
+int __asmcall linux_ioctl ( int fd, unsigned long request, ... ) {
+ va_list args;
+ void *arg;
+ int ret;
+
+ va_start ( args, request );
+ arg = va_arg ( args, void * );
+ va_end ( args );
+ ret = ioctl ( fd, request, arg );
+ if ( ret == -1 )
+ linux_errno = errno;
+ return ret;
+}
+
+/**
+ * Wrap part of fstat()
+ *
+ */
+int __asmcall linux_fstat_size ( int fd, size_t *size ) {
+ struct stat stat;
+ int ret;
+
+ ret = fstat ( fd, &stat );
+ *size = stat.st_size;
+ if ( ret == -1 )
+ linux_errno = errno;
+ return ret;
+}
+
+/**
+ * Wrap poll()
+ *
+ */
+int __asmcall linux_poll ( struct pollfd *fds, unsigned int nfds,
+ int timeout ) {
+ int ret;
+
+ ret = poll ( fds, nfds, timeout );
+ if ( ret == -1 )
+ linux_errno = errno;
+}
+
+/**
+ * Wrap nanosleep()
+ *
+ */
+int __asmcall linux_nanosleep ( const struct timespec *req,
+ struct timespec *rem ) {
+ int ret;
+
+ ret = nanosleep ( req, rem );
+ if ( ret == -1 )
+ linux_errno = errno;
+ return ret;
+}
+
+/**
+ * Wrap usleep()
+ *
+ */
+int __asmcall linux_usleep ( unsigned int usec ) {
+ int ret;
+
+ ret = usleep ( usec );
+ if ( ret == -1 )
+ linux_errno = errno;
+ return ret;
+}
+
+/**
+ * Wrap gettimeofday()
+ *
+ */
+int __asmcall linux_gettimeofday ( struct timeval *tv, struct timezone *tz ) {
+ int ret;
+
+ ret = gettimeofday ( tv, tz );
+ if ( ret == -1 )
+ linux_errno = errno;
+ return ret;
+}
+
+/**
+ * Wrap mmap()
+ *
+*/
+void * __asmcall linux_mmap ( void *addr, size_t length, int prot, int flags,
+ int fd, off_t offset ) {
+ void *ret;
+
+ ret = mmap ( addr, length, prot, flags, fd, offset );
+ if ( ret == MAP_FAILED )
+ linux_errno = errno;
+ return ret;
+}
+
+/**
+ * Wrap mremap()
+ *
+ */
+void * __asmcall linux_mremap ( void *old_address, size_t old_size,
+ size_t new_size, int flags, ... ) {
+ va_list args;
+ void *new_address;
+ void *ret;
+
+ va_start ( args, flags );
+ new_address = va_arg ( args, void * );
+ va_end ( args );
+ ret = mremap ( old_address, old_size, new_size, flags, new_address );
+ if ( ret == MAP_FAILED )
+ linux_errno = errno;
+ return ret;
+}
+
+/**
+ * Wrap munmap()
+ *
+ */
+int __asmcall linux_munmap ( void *addr, size_t length ) {
+ int ret;
+
+ ret = munmap ( addr, length );
+ if ( ret == -1 )
+ linux_errno = errno;
+ return ret;
+}
+
+/**
+ * Wrap socket()
+ *
+ */
+int __asmcall linux_socket ( int domain, int type, int protocol ) {
+ int ret;
+
+ ret = socket ( domain, type, protocol );
+ if ( ret == -1 )
+ linux_errno = errno;
+ return ret;
+}
+
+/**
+ * Wrap bind()
+ *
+ */
+int __asmcall linux_bind ( int sockfd, const struct sockaddr *addr,
+ size_t addrlen ) {
+ int ret;
+
+ ret = bind ( sockfd, addr, addrlen );
+ if ( ret == -1 )
+ linux_errno = errno;
+ return ret;
+}
+
+/**
+ * Wrap sendto()
+ *
+ */
+ssize_t __asmcall linux_sendto ( int sockfd, const void *buf, size_t len,
+ int flags, const struct sockaddr *dest_addr,
+ size_t addrlen ) {
+ ssize_t ret;
+
+ ret = sendto ( sockfd, buf, len, flags, dest_addr, addrlen );
+ if ( ret == -1 )
+ linux_errno = errno;
+ return ret;
+}
+
+/******************************************************************************
+ *
+ * C library wrappers
+ *
+ ******************************************************************************
+ */
+
+/**
+ * Wrap strerror()
+ *
+ */
+const char * __asmcall linux_strerror ( int linux_errno ) {
+
+ return strerror ( linux_errno );
+}
+
+/******************************************************************************
+ *
+ * libslirp wrappers
+ *
+ ******************************************************************************
+ */
+
+#ifdef HAVE_LIBSLIRP
+
+/**
+ * Wrap slirp_new()
+ *
+ */
+struct Slirp * __asmcall
+linux_slirp_new ( const struct slirp_config *config,
+ const struct slirp_callbacks *callbacks, void *opaque ) {
+ const union {
+ struct slirp_callbacks callbacks;
+ SlirpCb cb;
+ } *u = ( ( typeof ( u ) ) callbacks );
+ SlirpConfig cfg;
+ Slirp *slirp;
+
+ /* Translate configuration */
+ memset ( &cfg, 0, sizeof ( cfg ) );
+ cfg.version = config->version;
+ cfg.restricted = config->restricted;
+ cfg.in_enabled = config->in_enabled;
+ cfg.vnetwork = config->vnetwork;
+ cfg.vnetmask = config->vnetmask;
+ cfg.vhost = config->vhost;
+ cfg.in6_enabled = config->in6_enabled;
+ memcpy ( &cfg.vprefix_addr6, &config->vprefix_addr6,
+ sizeof ( cfg.vprefix_addr6 ) );
+ cfg.vprefix_len = config->vprefix_len;
+ memcpy ( &cfg.vhost6, &config->vhost6, sizeof ( cfg.vhost6 ) );
+ cfg.vhostname = config->vhostname;
+ cfg.tftp_server_name = config->tftp_server_name;
+ cfg.tftp_path = config->tftp_path;
+ cfg.bootfile = config->bootfile;
+ cfg.vdhcp_start = config->vdhcp_start;
+ cfg.vnameserver = config->vnameserver;
+ memcpy ( &cfg.vnameserver6, &config->vnameserver6,
+ sizeof ( cfg.vnameserver6 ) );
+ cfg.vdnssearch = config->vdnssearch;
+ cfg.vdomainname = config->vdomainname;
+ cfg.if_mtu = config->if_mtu;
+ cfg.if_mru = config->if_mru;
+ cfg.disable_host_loopback = config->disable_host_loopback;
+ cfg.enable_emu = config->enable_emu;
+
+ /* Validate callback structure */
+ static_assert ( &u->cb.send_packet == &u->callbacks.send_packet );
+ static_assert ( &u->cb.guest_error == &u->callbacks.guest_error );
+ static_assert ( &u->cb.clock_get_ns == &u->callbacks.clock_get_ns );
+ static_assert ( &u->cb.timer_new == &u->callbacks.timer_new );
+ static_assert ( &u->cb.timer_free == &u->callbacks.timer_free );
+ static_assert ( &u->cb.timer_mod == &u->callbacks.timer_mod );
+ static_assert ( &u->cb.register_poll_fd ==
+ &u->callbacks.register_poll_fd );
+ static_assert ( &u->cb.unregister_poll_fd ==
+ &u->callbacks.unregister_poll_fd );
+ static_assert ( &u->cb.notify == &u->callbacks.notify );
+
+ /* Create device */
+ slirp = slirp_new ( &cfg, &u->cb, opaque );
+
+ return slirp;
+}
+
+/**
+ * Wrap slirp_cleanup()
+ *
+ */
+void __asmcall linux_slirp_cleanup ( struct Slirp *slirp ) {
+
+ slirp_cleanup ( slirp );
+}
+
+/**
+ * Wrap slirp_input()
+ *
+ */
+void __asmcall linux_slirp_input ( struct Slirp *slirp, const uint8_t *pkt,
+ int pkt_len ) {
+
+ slirp_input ( slirp, pkt, pkt_len );
+}
+
+/**
+ * Wrap slirp_pollfds_fill()
+ *
+ */
+void __asmcall
+linux_slirp_pollfds_fill ( struct Slirp *slirp, uint32_t *timeout,
+ int ( __asmcall * add_poll ) ( int fd, int events,
+ void *opaque ),
+ void *opaque ) {
+
+ slirp_pollfds_fill ( slirp, timeout, add_poll, opaque );
+}
+
+/**
+ * Wrap slirp_pollfds_poll()
+ *
+ */
+void __asmcall
+linux_slirp_pollfds_poll ( struct Slirp *slirp, int select_error,
+ int ( __asmcall * get_revents ) ( int idx,
+ void *opaque ),
+ void *opaque ) {
+
+ slirp_pollfds_poll ( slirp, select_error, get_revents, opaque );
+}
+
+#else /* HAVE_LIBSLIRP */
+
+struct Slirp * __asmcall
+linux_slirp_new ( const struct slirp_config *config,
+ const struct slirp_callbacks *callbacks, void *opaque ) {
+ return NULL;
+}
+
+void __asmcall linux_slirp_cleanup ( struct Slirp *slirp ) {
+}
+
+void __asmcall linux_slirp_input ( struct Slirp *slirp, const uint8_t *pkt,
+ int pkt_len ) {
+}
+
+void __asmcall
+linux_slirp_pollfds_fill ( struct Slirp *slirp, uint32_t *timeout,
+ int ( __asmcall * add_poll ) ( int fd, int events,
+ void *opaque ),
+ void *opaque ) {
+}
+
+void __asmcall
+linux_slirp_pollfds_poll ( struct Slirp *slirp, int select_error,
+ int ( __asmcall * get_revents ) ( int idx,
+ void *opaque ),
+ void *opaque ) {
+}
+
+#endif /* HAVE_LIBSLIRP */
+
+/******************************************************************************
+ *
+ * Symbol aliases
+ *
+ ******************************************************************************
+ */
+
+PROVIDE_IPXE_SYM ( linux_errno );
+PROVIDE_IPXE_SYM ( linux_open );
+PROVIDE_IPXE_SYM ( linux_close );
+PROVIDE_IPXE_SYM ( linux_lseek );
+PROVIDE_IPXE_SYM ( linux_read );
+PROVIDE_IPXE_SYM ( linux_write );
+PROVIDE_IPXE_SYM ( linux_fcntl );
+PROVIDE_IPXE_SYM ( linux_ioctl );
+PROVIDE_IPXE_SYM ( linux_fstat_size );
+PROVIDE_IPXE_SYM ( linux_poll );
+PROVIDE_IPXE_SYM ( linux_nanosleep );
+PROVIDE_IPXE_SYM ( linux_usleep );
+PROVIDE_IPXE_SYM ( linux_gettimeofday );
+PROVIDE_IPXE_SYM ( linux_mmap );
+PROVIDE_IPXE_SYM ( linux_mremap );
+PROVIDE_IPXE_SYM ( linux_munmap );
+PROVIDE_IPXE_SYM ( linux_socket );
+PROVIDE_IPXE_SYM ( linux_bind );
+PROVIDE_IPXE_SYM ( linux_sendto );
+PROVIDE_IPXE_SYM ( linux_strerror );
+PROVIDE_IPXE_SYM ( linux_slirp_new );
+PROVIDE_IPXE_SYM ( linux_slirp_cleanup );
+PROVIDE_IPXE_SYM ( linux_slirp_input );
+PROVIDE_IPXE_SYM ( linux_slirp_pollfds_fill );
+PROVIDE_IPXE_SYM ( linux_slirp_pollfds_poll );
diff --git a/src/interface/linux/linux_console.c b/src/interface/linux/linux_console.c
index 5294fca79..d5415b61c 100644
--- a/src/interface/linux/linux_console.c
+++ b/src/interface/linux/linux_console.c
@@ -28,7 +28,7 @@ FILE_LICENCE(GPL2_OR_LATER);
#include <ipxe/init.h>
#include <ipxe/keys.h>
-#include <linux_api.h>
+#include <ipxe/linux_api.h>
#include <linux/termios.h>
#include <asm/errno.h>
diff --git a/src/interface/linux/linux_entropy.c b/src/interface/linux/linux_entropy.c
index 0f8e45d36..257e993a0 100644
--- a/src/interface/linux/linux_entropy.c
+++ b/src/interface/linux/linux_entropy.c
@@ -31,7 +31,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <stdint.h>
#include <errno.h>
-#include <linux_api.h>
+#include <ipxe/linux_api.h>
#include <ipxe/entropy.h>
/** Entropy source filename */
diff --git a/src/interface/linux/linux_nap.c b/src/interface/linux/linux_nap.c
index f1d3cd962..3e77bc7f1 100644
--- a/src/interface/linux/linux_nap.c
+++ b/src/interface/linux/linux_nap.c
@@ -21,7 +21,7 @@ FILE_LICENCE(GPL2_OR_LATER);
#include <ipxe/nap.h>
-#include <linux_api.h>
+#include <ipxe/linux_api.h>
/** @file
*
diff --git a/src/interface/linux/linux_pci.c b/src/interface/linux/linux_pci.c
index 0c140cb89..99c629c19 100644
--- a/src/interface/linux/linux_pci.c
+++ b/src/interface/linux/linux_pci.c
@@ -26,7 +26,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <stdio.h>
#include <errno.h>
#include <byteswap.h>
-#include <linux_api.h>
+#include <ipxe/linux_api.h>
#include <ipxe/linux.h>
#include <ipxe/pci.h>
diff --git a/src/interface/linux/linux_smbios.c b/src/interface/linux/linux_smbios.c
index 6e5174d23..981873943 100644
--- a/src/interface/linux/linux_smbios.c
+++ b/src/interface/linux/linux_smbios.c
@@ -20,21 +20,22 @@
FILE_LICENCE ( GPL2_OR_LATER );
#include <errno.h>
-#include <linux_api.h>
+#include <ipxe/linux_api.h>
+#include <ipxe/linux_sysfs.h>
#include <ipxe/linux.h>
+#include <ipxe/umalloc.h>
+#include <ipxe/init.h>
#include <ipxe/smbios.h>
-/** SMBIOS filename */
-static const char smbios_filename[] = "/dev/mem";
-
-/** SMBIOS entry point scan region start address */
-#define SMBIOS_ENTRY_START 0xf0000
+/** SMBIOS entry point filename */
+static const char smbios_entry_filename[] =
+ "/sys/firmware/dmi/tables/smbios_entry_point";
-/** SMBIOS entry point scan region length */
-#define SMBIOS_ENTRY_LEN 0x10000
+/** SMBIOS filename */
+static const char smbios_filename[] = "/sys/firmware/dmi/tables/DMI";
-/** SMBIOS mapping alignment */
-#define SMBIOS_ALIGN 0x1000
+/** Cache SMBIOS data */
+static userptr_t smbios_data;
/**
* Find SMBIOS
@@ -43,73 +44,84 @@ static const char smbios_filename[] = "/dev/mem";
* @ret rc Return status code
*/
static int linux_find_smbios ( struct smbios *smbios ) {
- struct smbios_entry entry;
- void *entry_mem;
- void *smbios_mem;
- size_t smbios_offset;
- size_t smbios_indent;
- size_t smbios_len;
- int fd;
+ struct smbios3_entry *smbios3_entry;
+ struct smbios_entry *smbios_entry;
+ userptr_t entry;
+ void *data;
+ int len;
int rc;
- /* Open SMBIOS file */
- fd = linux_open ( smbios_filename, O_RDONLY );
- if ( fd < 0 ) {
- rc = -ELINUX ( linux_errno );
- DBGC ( smbios, "SMBIOS could not open %s: %s\n",
- smbios_filename, linux_strerror ( linux_errno ) );
- goto err_open;
+ /* Read entry point file */
+ len = linux_sysfs_read ( smbios_entry_filename, &entry );
+ if ( len < 0 ) {
+ rc = len;
+ DBGC ( smbios, "SMBIOS could not read %s: %s\n",
+ smbios_entry_filename, strerror ( rc ) );
+ goto err_entry;
}
-
- /* Map the region potentially containing the SMBIOS entry point */
- entry_mem = linux_mmap ( NULL, SMBIOS_ENTRY_LEN, PROT_READ, MAP_SHARED,
- fd, SMBIOS_ENTRY_START );
- if ( entry_mem == MAP_FAILED ) {
- rc = -ELINUX ( linux_errno );
- DBGC ( smbios, "SMBIOS could not mmap %s (%#x+%#x): %s\n",
- smbios_filename, SMBIOS_ENTRY_START, SMBIOS_ENTRY_LEN,
- linux_strerror ( linux_errno ) );
- goto err_mmap_entry;
+ data = user_to_virt ( entry, 0 );
+ smbios3_entry = data;
+ smbios_entry = data;
+ if ( ( len >= ( ( int ) sizeof ( *smbios3_entry ) ) ) &&
+ ( smbios3_entry->signature == SMBIOS3_SIGNATURE ) ) {
+ smbios->version = SMBIOS_VERSION ( smbios3_entry->major,
+ smbios3_entry->minor );
+ } else if ( ( len >= ( ( int ) sizeof ( *smbios_entry ) ) ) &&
+ ( smbios_entry->signature == SMBIOS_SIGNATURE ) ) {
+ smbios->version = SMBIOS_VERSION ( smbios_entry->major,
+ smbios_entry->minor );
+ } else {
+ DBGC ( smbios, "SMBIOS invalid entry point %s:\n",
+ smbios_entry_filename );
+ DBGC_HDA ( smbios, 0, data, len );
+ rc = -EINVAL;
+ goto err_version;
}
- /* Scan for the SMBIOS entry point */
- if ( ( rc = find_smbios_entry ( virt_to_user ( entry_mem ),
- SMBIOS_ENTRY_LEN, &entry ) ) != 0 )
- goto err_find_entry;
-
- /* Map the region containing the SMBIOS structures */
- smbios_indent = ( entry.smbios_address & ( SMBIOS_ALIGN - 1 ) );
- smbios_offset = ( entry.smbios_address - smbios_indent );
- smbios_len = ( entry.smbios_len + smbios_indent );
- smbios_mem = linux_mmap ( NULL, smbios_len, PROT_READ, MAP_SHARED,
- fd, smbios_offset );
- if ( smbios_mem == MAP_FAILED ) {
- rc = -ELINUX ( linux_errno );
- DBGC ( smbios, "SMBIOS could not mmap %s (%#zx+%#zx): %s\n",
- smbios_filename, smbios_offset, smbios_len,
- linux_strerror ( linux_errno ) );
- goto err_mmap_smbios;
+ /* Read SMBIOS file */
+ len = linux_sysfs_read ( smbios_filename, &smbios_data );
+ if ( len < 0 ) {
+ rc = len;
+ DBGC ( smbios, "SMBIOS could not read %s: %s\n",
+ smbios_filename, strerror ( rc ) );
+ goto err_read;
}
- /* Fill in entry point descriptor structure */
- smbios->address = virt_to_user ( smbios_mem + smbios_indent );
- smbios->len = entry.smbios_len;
- smbios->count = entry.smbios_count;
- smbios->version = SMBIOS_VERSION ( entry.major, entry.minor );
+ /* Populate SMBIOS descriptor */
+ smbios->address = smbios_data;
+ smbios->len = len;
+ smbios->count = 0;
- /* Unmap the entry point region (no longer required) */
- linux_munmap ( entry_mem, SMBIOS_ENTRY_LEN );
+ /* Free entry point */
+ ufree ( entry );
return 0;
- linux_munmap ( smbios_mem, smbios_len );
- err_mmap_smbios:
- err_find_entry:
- linux_munmap ( entry_mem, SMBIOS_ENTRY_LEN );
- err_mmap_entry:
- linux_close ( fd );
- err_open:
+ ufree ( smbios_data );
+ err_read:
+ err_version:
+ ufree ( entry );
+ err_entry:
return rc;
}
+/**
+ * Free cached SMBIOS data
+ *
+ */
+static void linux_smbios_shutdown ( int booting __unused ) {
+
+ /* Clear SMBIOS data pointer */
+ smbios_clear();
+
+ /* Free SMBIOS data */
+ ufree ( smbios_data );
+}
+
+/** SMBIOS shutdown function */
+struct startup_fn linux_smbios_startup_fn __startup_fn ( STARTUP_NORMAL ) = {
+ .name = "linux_smbios",
+ .shutdown = linux_smbios_shutdown,
+};
+
PROVIDE_SMBIOS ( linux, find_smbios, linux_find_smbios );
diff --git a/src/interface/linux/linux_sysfs.c b/src/interface/linux/linux_sysfs.c
new file mode 100644
index 000000000..4f0027cd4
--- /dev/null
+++ b/src/interface/linux/linux_sysfs.c
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2021 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.
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER );
+
+#include <string.h>
+#include <errno.h>
+#include <ipxe/umalloc.h>
+#include <ipxe/linux_api.h>
+#include <ipxe/linux.h>
+#include <ipxe/linux_sysfs.h>
+
+/** @file
+ *
+ * Linux sysfs files
+ *
+ */
+
+/** Read blocksize */
+#define LINUX_SYSFS_BLKSIZE 4096
+
+/**
+ * Read file from sysfs
+ *
+ * @v filename Filename
+ * @v data Data to fill in
+ * @ret len Length read, or negative error
+ */
+int linux_sysfs_read ( const char *filename, userptr_t *data ) {
+ userptr_t tmp;
+ ssize_t read;
+ size_t len;
+ int fd;
+ int rc;
+
+ /* Open file */
+ fd = linux_open ( filename, O_RDONLY );
+ if ( fd < 0 ) {
+ rc = -ELINUX ( linux_errno );
+ DBGC ( filename, "LINUX could not open %s: %s\n",
+ filename, linux_strerror ( linux_errno ) );
+ goto err_open;
+ }
+
+ /* Read file */
+ for ( *data = UNULL, len = 0 ; ; len += read ) {
+
+ /* (Re)allocate space */
+ tmp = urealloc ( *data, ( len + LINUX_SYSFS_BLKSIZE ) );
+ if ( ! tmp ) {
+ rc = -ENOMEM;
+ goto err_alloc;
+ }
+ *data = tmp;
+
+ /* Read from file */
+ read = linux_read ( fd, user_to_virt ( *data, len ),
+ LINUX_SYSFS_BLKSIZE );
+ if ( read == 0 )
+ break;
+ if ( read < 0 ) {
+ DBGC ( filename, "LINUX could not read %s: %s\n",
+ filename, linux_strerror ( linux_errno ) );
+ goto err_read;
+ }
+ }
+
+ /* Close file */
+ linux_close ( fd );
+
+ DBGC ( filename, "LINUX read %s\n", filename );
+ return len;
+
+ err_read:
+ err_alloc:
+ ufree ( *data );
+ linux_close ( fd );
+ err_open:
+ return rc;
+}
diff --git a/src/interface/linux/linux_time.c b/src/interface/linux/linux_time.c
index 9e99fe9cd..9d410f8e0 100644
--- a/src/interface/linux/linux_time.c
+++ b/src/interface/linux/linux_time.c
@@ -32,7 +32,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <stdint.h>
#include <stddef.h>
#include <errno.h>
-#include <linux_api.h>
+#include <ipxe/linux_api.h>
#include <ipxe/time.h>
/**
diff --git a/src/interface/linux/linux_timer.c b/src/interface/linux/linux_timer.c
index 9c5e96f2b..418fd046a 100644
--- a/src/interface/linux/linux_timer.c
+++ b/src/interface/linux/linux_timer.c
@@ -21,7 +21,7 @@ FILE_LICENCE(GPL2_OR_LATER);
#include <stddef.h>
#include <ipxe/timer.h>
-#include <linux_api.h>
+#include <ipxe/linux_api.h>
/** @file
*
diff --git a/src/interface/linux/linux_umalloc.c b/src/interface/linux/linux_umalloc.c
index aa0052c53..a7250fa5b 100644
--- a/src/interface/linux/linux_umalloc.c
+++ b/src/interface/linux/linux_umalloc.c
@@ -29,7 +29,7 @@ FILE_LICENCE(GPL2_OR_LATER);
#include <assert.h>
#include <ipxe/umalloc.h>
-#include <linux_api.h>
+#include <ipxe/linux_api.h>
/** Special address returned for empty allocations */
#define NOWHERE ((void *)-1)
diff --git a/src/include/hci/linux_args.h b/src/interface/linux/linuxprefix.c
index ae1ed0526..f38236202 100644
--- a/src/include/hci/linux_args.h
+++ b/src/interface/linux/linuxprefix.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010 Piotr Jaroszyński <p.jaroszynski@gmail.com>
+ * Copyright (C) 2021 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
@@ -13,19 +13,26 @@
*
* 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 St, Fifth Floor, Boston, MA 02110-1301 USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
*/
-#ifndef _HCI_LINUX_ARGS_H
-#define _HCI_LINUX_ARGS_H
-
-FILE_LICENCE(GPL2_OR_LATER);
+#include <stdlib.h>
+#include <ipxe/linux_api.h>
/**
- * Save argc and argv for later access.
+ * Linux entry point
*
- * To be called by linuxprefix
+ * @v argc Argument count
+ * @v argv Argument list
+ * @ret rc Return status code
*/
-extern __asmcall void save_args(int argc, char **argv);
+int __asmcall _linux_start ( int argc, char **argv ) {
+
+ /* Store command-line arguments */
+ linux_argc = argc;
+ linux_argv = argv;
-#endif /* _HCI_LINUX_ARGS_H */
+ /* Run iPXE */
+ return main();
+}
diff --git a/src/interface/smbios/smbios.c b/src/interface/smbios/smbios.c
index 1dcf819c2..12a080da2 100644
--- a/src/interface/smbios/smbios.c
+++ b/src/interface/smbios/smbios.c
@@ -130,8 +130,8 @@ int find_smbios_structure ( unsigned int type, unsigned int instance,
assert ( smbios.address != UNULL );
/* Scan through list of structures */
- while ( ( ( offset + sizeof ( structure->header ) ) < smbios.len )
- && ( count < smbios.count ) ) {
+ while ( ( ( offset + sizeof ( structure->header ) ) < smbios.len ) &&
+ ( ( smbios.count == 0 ) || ( count < smbios.count ) ) ) {
/* Read next SMBIOS structure header */
copy_from_user ( &structure->header, smbios.address, offset,
@@ -157,6 +157,11 @@ int find_smbios_structure ( unsigned int type, unsigned int instance,
"strings length %zx\n", offset, structure->header.type,
structure->header.len, structure->strings_len );
+ /* Stop if we have reached an end-of-table marker */
+ if ( ( smbios.count == 0 ) &&
+ ( structure->header.type == SMBIOS_TYPE_END ) )
+ break;
+
/* If this is the structure we want, return */
if ( ( structure->header.type == type ) &&
( instance-- == 0 ) ) {
@@ -250,3 +255,13 @@ int smbios_version ( void ) {
return smbios.version;
}
+
+/**
+ * Clear SMBIOS entry point descriptor
+ *
+ */
+void smbios_clear ( void ) {
+
+ /* Clear address */
+ smbios.address = UNULL;
+}
diff --git a/src/net/80211/wpa.c b/src/net/80211/wpa.c
index 5ec5005bf..1484d0e80 100644
--- a/src/net/80211/wpa.c
+++ b/src/net/80211/wpa.c
@@ -414,12 +414,13 @@ static int wpa_maybe_install_gtk ( struct wpa_common_ctx *ctx,
static struct io_buffer * wpa_alloc_frame ( int kdlen )
{
struct io_buffer *ret = alloc_iob ( sizeof ( struct eapol_key_pkt ) +
- kdlen + EAPOL_HDR_LEN +
+ kdlen +
+ sizeof ( struct eapol_header ) +
MAX_LL_HEADER_LEN );
if ( ! ret )
return NULL;
- iob_reserve ( ret, MAX_LL_HEADER_LEN + EAPOL_HDR_LEN );
+ iob_reserve ( ret, MAX_LL_HEADER_LEN + sizeof ( struct eapol_header ) );
memset ( iob_put ( ret, sizeof ( struct eapol_key_pkt ) ), 0,
sizeof ( struct eapol_key_pkt ) );
@@ -442,19 +443,19 @@ static int wpa_send_eapol ( struct io_buffer *iob, struct wpa_common_ctx *ctx,
struct wpa_kie *kie )
{
struct eapol_key_pkt *pkt = iob->data;
- struct eapol_frame *eapol = iob_push ( iob, EAPOL_HDR_LEN );
+ struct eapol_header *eapol = iob_push ( iob, sizeof ( *eapol ) );
pkt->info = htons ( pkt->info );
pkt->keysize = htons ( pkt->keysize );
pkt->datalen = htons ( pkt->datalen );
pkt->replay = cpu_to_be64 ( pkt->replay );
- eapol->version = EAPOL_THIS_VERSION;
+ eapol->version = EAPOL_VERSION_2001;
eapol->type = EAPOL_TYPE_KEY;
- eapol->length = htons ( iob->tail - iob->data - sizeof ( *eapol ) );
+ eapol->len = htons ( iob->tail - iob->data - sizeof ( *eapol ) );
memset ( pkt->mic, 0, sizeof ( pkt->mic ) );
if ( kie )
- kie->mic ( &ctx->ptk.kck, eapol, EAPOL_HDR_LEN +
+ kie->mic ( &ctx->ptk.kck, eapol, sizeof ( *eapol ) +
sizeof ( *pkt ) + ntohs ( pkt->datalen ),
pkt->mic );
@@ -762,21 +763,23 @@ static int wpa_handle_1_of_2 ( struct wpa_common_ctx *ctx,
*
* @v iob I/O buffer
* @v netdev Network device
- * @v ll_dest Link-layer destination address
* @v ll_source Source link-layer address
*/
static int eapol_key_rx ( struct io_buffer *iob, struct net_device *netdev,
- const void *ll_dest __unused,
const void *ll_source )
{
struct net80211_device *dev = net80211_get ( netdev );
- struct eapol_key_pkt *pkt = iob->data;
+ struct eapol_header *eapol;
+ struct eapol_key_pkt *pkt;
int is_rsn, found_ctx;
struct wpa_common_ctx *ctx;
int rc = 0;
struct wpa_kie *kie;
u8 their_mic[16], our_mic[16];
+ eapol = iob->data;
+ pkt = ( ( ( void * ) eapol ) + sizeof ( *eapol ) );
+
if ( pkt->type != EAPOL_KEY_TYPE_WPA &&
pkt->type != EAPOL_KEY_TYPE_RSN ) {
DBG ( "EAPOL-Key: packet not of 802.11 type\n" );
@@ -840,8 +843,8 @@ static int eapol_key_rx ( struct io_buffer *iob, struct net_device *netdev,
if ( ntohs ( pkt->info ) & EAPOL_KEY_INFO_KEY_MIC ) {
memcpy ( their_mic, pkt->mic, sizeof ( pkt->mic ) );
memset ( pkt->mic, 0, sizeof ( pkt->mic ) );
- kie->mic ( &ctx->ptk.kck, ( void * ) pkt - EAPOL_HDR_LEN,
- EAPOL_HDR_LEN + sizeof ( *pkt ) +
+ kie->mic ( &ctx->ptk.kck, eapol,
+ sizeof ( *eapol ) + sizeof ( *pkt ) +
ntohs ( pkt->datalen ), our_mic );
DBGC2 ( ctx, "WPA %p MIC comparison (theirs, ours):\n", ctx );
DBGC2_HD ( ctx, their_mic, 16 );
diff --git a/src/net/aoe.c b/src/net/aoe.c
index 3a6611d04..e785e8979 100644
--- a/src/net/aoe.c
+++ b/src/net/aoe.c
@@ -42,6 +42,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <ipxe/open.h>
#include <ipxe/ata.h>
#include <ipxe/device.h>
+#include <ipxe/efi/efi_path.h>
#include <ipxe/aoe.h>
/** @file
@@ -68,35 +69,6 @@ static LIST_HEAD ( aoe_devices );
/** List of active AoE commands */
static LIST_HEAD ( aoe_commands );
-/** An AoE device */
-struct aoe_device {
- /** Reference counter */
- struct refcnt refcnt;
-
- /** Network device */
- struct net_device *netdev;
- /** ATA command issuing interface */
- struct interface ata;
-
- /** Major number */
- uint16_t major;
- /** Minor number */
- uint8_t minor;
- /** Target MAC address */
- uint8_t target[MAX_LL_ADDR_LEN];
-
- /** Saved timeout value */
- unsigned long timeout;
-
- /** Configuration command interface */
- struct interface config;
- /** Device is configued */
- int configured;
-
- /** ACPI descriptor */
- struct acpi_descriptor desc;
-};
-
/** An AoE command */
struct aoe_command {
/** Reference count */
@@ -811,6 +783,7 @@ static struct interface_operation aoedev_ata_op[] = {
INTF_OP ( acpi_describe, struct aoe_device *, aoedev_describe ),
INTF_OP ( identify_device, struct aoe_device *,
aoedev_identify_device ),
+ EFI_INTF_OP ( efi_describe, struct aoe_device *, efi_aoe_path ),
};
/** AoE device ATA interface descriptor */
diff --git a/src/net/eap.c b/src/net/eap.c
new file mode 100644
index 000000000..8d1d540fb
--- /dev/null
+++ b/src/net/eap.c
@@ -0,0 +1,142 @@
+/*
+ * Copyright (C) 2021 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 <errno.h>
+#include <ipxe/netdevice.h>
+#include <ipxe/eap.h>
+
+/** @file
+ *
+ * Extensible Authentication Protocol
+ *
+ */
+
+/**
+ * Handle EAP Request-Identity
+ *
+ * @v netdev Network device
+ * @ret rc Return status code
+ */
+static int eap_rx_request_identity ( struct net_device *netdev ) {
+
+ /* Treat Request-Identity as blocking the link */
+ DBGC ( netdev, "EAP %s Request-Identity blocking link\n",
+ netdev->name );
+ netdev_link_block ( netdev, EAP_BLOCK_TIMEOUT );
+
+ return 0;
+}
+
+/**
+ * Handle EAP Request
+ *
+ * @v netdev Network device
+ * @v req EAP request
+ * @v len Length of EAP request
+ * @ret rc Return status code
+ */
+static int eap_rx_request ( struct net_device *netdev,
+ const struct eap_request *req, size_t len ) {
+
+ /* Sanity check */
+ if ( len < sizeof ( *req ) ) {
+ DBGC ( netdev, "EAP %s underlength request:\n", netdev->name );
+ DBGC_HDA ( netdev, 0, req, len );
+ return -EINVAL;
+ }
+
+ /* Handle according to type */
+ switch ( req->type ) {
+ case EAP_TYPE_IDENTITY:
+ return eap_rx_request_identity ( netdev );
+ default:
+ DBGC ( netdev, "EAP %s requested type %d unknown:\n",
+ netdev->name, req->type );
+ DBGC_HDA ( netdev, 0, req, len );
+ return -ENOTSUP;
+ }
+}
+
+/**
+ * Handle EAP Success
+ *
+ * @v netdev Network device
+ * @ret rc Return status code
+ */
+static int eap_rx_success ( struct net_device *netdev ) {
+
+ /* Mark link as unblocked */
+ DBGC ( netdev, "EAP %s Success\n", netdev->name );
+ netdev_link_unblock ( netdev );
+
+ return 0;
+}
+
+/**
+ * Handle EAP Failure
+ *
+ * @v netdev Network device
+ * @ret rc Return status code
+ */
+static int eap_rx_failure ( struct net_device *netdev ) {
+
+ /* Record error */
+ DBGC ( netdev, "EAP %s Failure\n", netdev->name );
+ return -EPERM;
+}
+
+/**
+ * Handle EAP packet
+ *
+ * @v netdev Network device
+ * @v data EAP packet
+ * @v len Length of EAP packet
+ * @ret rc Return status code
+ */
+int eap_rx ( struct net_device *netdev, const void *data, size_t len ) {
+ const union eap_packet *eap = data;
+
+ /* Sanity check */
+ if ( len < sizeof ( eap->hdr ) ) {
+ DBGC ( netdev, "EAP %s underlength header:\n", netdev->name );
+ DBGC_HDA ( netdev, 0, eap, len );
+ return -EINVAL;
+ }
+
+ /* Handle according to code */
+ switch ( eap->hdr.code ) {
+ case EAP_CODE_REQUEST:
+ return eap_rx_request ( netdev, &eap->req, len );
+ case EAP_CODE_SUCCESS:
+ return eap_rx_success ( netdev );
+ case EAP_CODE_FAILURE:
+ return eap_rx_failure ( netdev );
+ default:
+ DBGC ( netdev, "EAP %s unsupported code %d\n",
+ netdev->name, eap->hdr.code );
+ DBGC_HDA ( netdev, 0, eap, len );
+ return -ENOTSUP;
+ }
+}
diff --git a/src/net/eapol.c b/src/net/eapol.c
index eb0362994..3578f0e37 100644
--- a/src/net/eapol.c
+++ b/src/net/eapol.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009 Joshua Oreman <oremanj@rwcr.net>.
+ * Copyright (C) 2021 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
@@ -15,74 +15,127 @@
* 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 );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+#include <assert.h>
+#include <errno.h>
+#include <byteswap.h>
+#include <ipxe/iobuf.h>
+#include <ipxe/if_ether.h>
+#include <ipxe/netdevice.h>
+#include <ipxe/eap.h>
+#include <ipxe/eapol.h>
/** @file
*
- * 802.1X Extensible Authentication Protocol over LANs demultiplexer
+ * Extensible Authentication Protocol over LAN (EAPoL)
*
*/
-#include <ipxe/netdevice.h>
-#include <ipxe/iobuf.h>
-#include <ipxe/if_ether.h>
-#include <ipxe/eapol.h>
-#include <errno.h>
-#include <byteswap.h>
-
/**
- * Receive EAPOL network-layer packet
+ * Process EAPoL packet
*
- * @v iob I/O buffer
- * @v netdev Network device
- * @v ll_dest Link-layer destination address
- * @v ll_source Link-layer source address
- * @v flags Packet flags
- *
- * This function takes ownership of the I/O buffer passed to it.
+ * @v iobuf I/O buffer
+ * @v netdev Network device
+ * @v ll_dest Link-layer destination address
+ * @v ll_source Link-layer source address
+ * @v flags Packet flags
+ * @ret rc Return status code
*/
-static int eapol_rx ( struct io_buffer *iob, struct net_device *netdev,
- const void *ll_dest, const void *ll_source,
+static int eapol_rx ( struct io_buffer *iobuf, struct net_device *netdev,
+ const void *ll_dest __unused, const void *ll_source,
unsigned int flags __unused ) {
- struct eapol_frame *eapol = iob->data;
+ struct eapol_header *eapol;
struct eapol_handler *handler;
+ size_t remaining;
+ size_t len;
+ int rc;
- if ( iob_len ( iob ) < EAPOL_HDR_LEN ) {
- free_iob ( iob );
- return -EINVAL;
+ /* Sanity checks */
+ if ( iob_len ( iobuf ) < sizeof ( *eapol ) ) {
+ DBGC ( netdev, "EAPOL %s underlength header:\n",
+ netdev->name );
+ DBGC_HDA ( netdev, 0, iobuf->data, iob_len ( iobuf ) );
+ rc = -EINVAL;
+ goto drop;
+ }
+ eapol = iobuf->data;
+ remaining = ( iob_len ( iobuf ) - sizeof ( *eapol ) );
+ len = ntohs ( eapol->len );
+ if ( len > remaining ) {
+ DBGC ( netdev, "EAPOL %s v%d type %d len %zd underlength "
+ "payload:\n", netdev->name, eapol->version,
+ eapol->type, len );
+ DBGC_HDA ( netdev, 0, iobuf->data, iob_len ( iobuf ) );
+ rc = -EINVAL;
+ goto drop;
}
+ /* Strip any trailing padding */
+ iob_unput ( iobuf, ( len - remaining ) );
+
+ /* Handle according to type */
for_each_table_entry ( handler, EAPOL_HANDLERS ) {
if ( handler->type == eapol->type ) {
- iob_pull ( iob, EAPOL_HDR_LEN );
- return handler->rx ( iob, netdev, ll_dest, ll_source );
+ return handler->rx ( iob_disown ( iobuf ) , netdev,
+ ll_source );
}
}
+ rc = -ENOTSUP;
+ DBGC ( netdev, "EAPOL %s v%d type %d unsupported\n",
+ netdev->name, eapol->version, eapol->type );
+ DBGC_HDA ( netdev, 0, iobuf->data, iob_len ( iobuf ) );
- free_iob ( iob );
- return -( ENOTSUP | ( ( eapol->type & 0x1f ) << 8 ) );
+ drop:
+ free_iob ( iobuf );
+ return rc;
}
+/** EAPoL protocol */
+struct net_protocol eapol_protocol __net_protocol = {
+ .name = "EAPOL",
+ .net_proto = htons ( ETH_P_EAPOL ),
+ .rx = eapol_rx,
+};
+
/**
- * Transcribe EAPOL network-layer address
+ * Process EAPoL-encapsulated EAP packet
*
- * @v net_addr Network-layer address
- * @ret str String representation of network-layer address
- *
- * EAPOL doesn't have network-layer addresses, so we just return the
- * string @c "<EAPOL>".
+ * @v netdev Network device
+ * @v ll_source Link-layer source address
+ * @ret rc Return status code
*/
-static const char * eapol_ntoa ( const void *net_addr __unused )
-{
- return "<EAPOL>";
+static int eapol_eap_rx ( struct io_buffer *iobuf, struct net_device *netdev,
+ const void *ll_source __unused ) {
+ struct eapol_header *eapol;
+ int rc;
+
+ /* Sanity check */
+ assert ( iob_len ( iobuf ) >= sizeof ( *eapol ) );
+
+ /* Strip EAPoL header */
+ eapol = iob_pull ( iobuf, sizeof ( *eapol ) );
+
+ /* Process EAP packet */
+ if ( ( rc = eap_rx ( netdev, iobuf->data, iob_len ( iobuf ) ) ) != 0 ) {
+ DBGC ( netdev, "EAPOL %s v%d EAP failed: %s\n",
+ netdev->name, eapol->version, strerror ( rc ) );
+ goto drop;
+ }
+
+ drop:
+ free_iob ( iobuf );
+ return rc;
}
-/** EAPOL network protocol */
-struct net_protocol eapol_protocol __net_protocol = {
- .name = "EAPOL",
- .rx = eapol_rx,
- .ntoa = eapol_ntoa,
- .net_proto = htons ( ETH_P_EAPOL ),
+/** EAPoL handler for EAP packets */
+struct eapol_handler eapol_eap __eapol_handler = {
+ .type = EAPOL_TYPE_EAP,
+ .rx = eapol_eap_rx,
};
diff --git a/src/net/eth_slow.c b/src/net/eth_slow.c
index baa51dbc1..1103a49f3 100644
--- a/src/net/eth_slow.c
+++ b/src/net/eth_slow.c
@@ -153,6 +153,14 @@ static int eth_slow_lacp_rx ( struct io_buffer *iobuf,
eth_slow_lacp_dump ( iobuf, netdev, "RX" );
+ /* Check for looped-back packets */
+ if ( memcmp ( lacp->actor.system, netdev->ll_addr,
+ sizeof ( lacp->actor.system ) ) == 0 ) {
+ DBGC ( netdev, "SLOW %s RX loopback detected\n",
+ netdev->name );
+ return -ELOOP;
+ }
+
/* If partner is not in sync, collecting, and distributing,
* then block the link until after the next expected LACP
* packet.
@@ -278,6 +286,9 @@ static int eth_slow_rx ( struct io_buffer *iobuf,
return -EINVAL;
}
+ /* Strip any trailing padding */
+ iob_unput ( iobuf, ( sizeof ( *eth_slow ) - iob_len ( iobuf ) ) );
+
/* Handle according to subtype */
switch ( eth_slow->header.subtype ) {
case ETH_SLOW_SUBTYPE_LACP:
diff --git a/src/net/fcp.c b/src/net/fcp.c
index d92cfdcf3..f78f7bd9b 100644
--- a/src/net/fcp.c
+++ b/src/net/fcp.c
@@ -43,6 +43,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <ipxe/scsi.h>
#include <ipxe/device.h>
#include <ipxe/edd.h>
+#include <ipxe/efi/efi_path.h>
#include <ipxe/fc.h>
#include <ipxe/fcels.h>
#include <ipxe/fcp.h>
@@ -158,10 +159,8 @@ struct fcp_device {
/** List of active commands */
struct list_head fcpcmds;
- /** Fibre Channel WWN (for boot firmware table) */
- struct fc_name wwn;
- /** SCSI LUN (for boot firmware table) */
- struct scsi_lun lun;
+ /** Device description (for boot firmware table) */
+ struct fcp_description desc;
};
/** An FCP command */
@@ -864,9 +863,9 @@ static int fcpdev_edd_describe ( struct fcp_device *fcpdev,
} lun;
type->type = cpu_to_le64 ( EDD_INTF_TYPE_FIBRE );
- memcpy ( &wwn.fc, &fcpdev->wwn, sizeof ( wwn.fc ) );
+ memcpy ( &wwn.fc, &fcpdev->desc.wwn, sizeof ( wwn.fc ) );
path->fibre.wwn = be64_to_cpu ( wwn.u64 );
- memcpy ( &lun.scsi, &fcpdev->lun, sizeof ( lun.scsi ) );
+ memcpy ( &lun.scsi, &fcpdev->desc.lun, sizeof ( lun.scsi ) );
path->fibre.lun = be64_to_cpu ( lun.u64 );
return 0;
}
@@ -893,6 +892,18 @@ static struct device * fcpdev_identify_device ( struct fcp_device *fcpdev ) {
return identify_device ( &fcpdev->user.ulp->peer->port->transport );
}
+/**
+ * Describe as an EFI device path
+ *
+ * @v fcp FCP device
+ * @ret path EFI device path, or NULL on error
+ */
+static EFI_DEVICE_PATH_PROTOCOL *
+fcpdev_efi_describe ( struct fcp_device *fcpdev ) {
+
+ return efi_fcp_path ( &fcpdev->desc );
+}
+
/** FCP device SCSI interface operations */
static struct interface_operation fcpdev_scsi_op[] = {
INTF_OP ( scsi_command, struct fcp_device *, fcpdev_scsi_command ),
@@ -901,6 +912,7 @@ static struct interface_operation fcpdev_scsi_op[] = {
INTF_OP ( edd_describe, struct fcp_device *, fcpdev_edd_describe ),
INTF_OP ( identify_device, struct fcp_device *,
fcpdev_identify_device ),
+ EFI_INTF_OP ( efi_describe, struct fcp_device *, fcpdev_efi_describe ),
};
/** FCP device SCSI interface descriptor */
@@ -965,8 +977,8 @@ static int fcpdev_open ( struct interface *parent, struct fc_name *wwn,
fc_ulp_attach ( ulp, &fcpdev->user );
/* Preserve parameters required for boot firmware table */
- memcpy ( &fcpdev->wwn, wwn, sizeof ( fcpdev->wwn ) );
- memcpy ( &fcpdev->lun, lun, sizeof ( fcpdev->lun ) );
+ memcpy ( &fcpdev->desc.wwn, wwn, sizeof ( fcpdev->desc.wwn ) );
+ memcpy ( &fcpdev->desc.lun, lun, sizeof ( fcpdev->desc.lun ) );
/* Attach SCSI device to parent interface */
if ( ( rc = scsi_open ( parent, &fcpdev->scsi, lun ) ) != 0 ) {
diff --git a/src/net/infiniband.c b/src/net/infiniband.c
index 3b79a660c..e19e121c1 100644
--- a/src/net/infiniband.c
+++ b/src/net/infiniband.c
@@ -814,26 +814,6 @@ void ib_mcast_detach ( struct ib_device *ibdev, struct ib_queue_pair *qp,
*/
/**
- * Count Infiniband HCA ports
- *
- * @v ibdev Infiniband device
- * @ret num_ports Number of ports
- */
-int ib_count_ports ( struct ib_device *ibdev ) {
- struct ib_device *tmp;
- int num_ports = 0;
-
- /* Search for IB devices with the same physical device to
- * identify port count.
- */
- for_each_ibdev ( tmp ) {
- if ( tmp->dev == ibdev->dev )
- num_ports++;
- }
- return num_ports;
-}
-
-/**
* Set port information
*
* @v ibdev Infiniband device
diff --git a/src/net/infiniband/ib_sma.c b/src/net/infiniband/ib_sma.c
index 24ec9f4e0..b553e66b1 100644
--- a/src/net/infiniband/ib_sma.c
+++ b/src/net/infiniband/ib_sma.c
@@ -63,7 +63,7 @@ static void ib_sma_node_info ( struct ib_device *ibdev,
node_info->base_version = IB_MGMT_BASE_VERSION;
node_info->class_version = IB_SMP_CLASS_VERSION;
node_info->node_type = IB_NODE_TYPE_HCA;
- node_info->num_ports = ib_count_ports ( ibdev );
+ node_info->num_ports = ibdev->ports;
memcpy ( &node_info->sys_guid, &ibdev->node_guid,
sizeof ( node_info->sys_guid ) );
memcpy ( &node_info->node_guid, &ibdev->node_guid,
diff --git a/src/net/infiniband/ib_srp.c b/src/net/infiniband/ib_srp.c
index 4913f449c..e6b43291f 100644
--- a/src/net/infiniband/ib_srp.c
+++ b/src/net/infiniband/ib_srp.c
@@ -37,6 +37,7 @@ FILE_LICENCE ( BSD2 );
#include <ipxe/open.h>
#include <ipxe/base16.h>
#include <ipxe/acpi.h>
+#include <ipxe/efi/efi_path.h>
#include <ipxe/srp.h>
#include <ipxe/infiniband.h>
#include <ipxe/ib_cmrc.h>
@@ -70,39 +71,6 @@ struct acpi_model ib_sbft_model __acpi_model;
*/
/**
- * An IB SRP sBFT created by iPXE
- */
-struct ipxe_ib_sbft {
- /** The table header */
- struct sbft_table table;
- /** The SCSI subtable */
- struct sbft_scsi_subtable scsi;
- /** The SRP subtable */
- struct sbft_srp_subtable srp;
- /** The Infiniband subtable */
- struct sbft_ib_subtable ib;
-};
-
-/** An Infiniband SRP device */
-struct ib_srp_device {
- /** Reference count */
- struct refcnt refcnt;
-
- /** SRP transport interface */
- struct interface srp;
- /** CMRC interface */
- struct interface cmrc;
-
- /** Infiniband device */
- struct ib_device *ibdev;
-
- /** ACPI descriptor */
- struct acpi_descriptor desc;
- /** Boot firmware table parameters */
- struct ipxe_ib_sbft sbft;
-};
-
-/**
* Free IB SRP device
*
* @v refcnt Reference count
@@ -153,6 +121,7 @@ static struct interface_descriptor ib_srp_cmrc_desc =
static struct interface_operation ib_srp_srp_op[] = {
INTF_OP ( acpi_describe, struct ib_srp_device *, ib_srp_describe ),
INTF_OP ( intf_close, struct ib_srp_device *, ib_srp_close ),
+ EFI_INTF_OP ( efi_describe, struct ib_srp_device *, efi_ib_srp_path ),
};
/** IB SRP SRP interface descriptor */
diff --git a/src/net/ndp.c b/src/net/ndp.c
index f28e71cbd..75e531648 100644
--- a/src/net/ndp.c
+++ b/src/net/ndp.c
@@ -31,6 +31,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <ipxe/icmpv6.h>
#include <ipxe/neighbour.h>
#include <ipxe/dhcpv6.h>
+#include <ipxe/timer.h>
#include <ipxe/ndp.h>
/** @file
@@ -39,6 +40,18 @@ FILE_LICENCE ( GPL2_OR_LATER );
*
*/
+/** Router discovery minimum timeout */
+#define IPV6CONF_MIN_TIMEOUT ( TICKS_PER_SEC / 8 )
+
+/** Router discovery maximum timeout */
+#define IPV6CONF_MAX_TIMEOUT ( TICKS_PER_SEC * 3 )
+
+/** Router discovery blocked link retry timeout */
+#define IPV6CONF_BLOCK_TIMEOUT ( TICKS_PER_SEC )
+
+/** Router discovery maximum number of deferrals */
+#define IPV6CONF_MAX_DEFERRALS 180
+
static struct ipv6conf * ipv6conf_demux ( struct net_device *netdev );
static int
ipv6conf_rx_router_advertisement ( struct net_device *netdev,
@@ -1061,6 +1074,9 @@ struct ipv6conf {
/** Retransmission timer */
struct retry_timer timer;
+
+ /** Deferred discovery counter */
+ unsigned int deferred;
};
/** List of IPv6 configurators */
@@ -1124,6 +1140,7 @@ static void ipv6conf_done ( struct ipv6conf *ipv6conf, int rc ) {
static void ipv6conf_expired ( struct retry_timer *timer, int fail ) {
struct ipv6conf *ipv6conf =
container_of ( timer, struct ipv6conf, timer );
+ struct net_device *netdev = ipv6conf->netdev;
/* If we have failed, terminate autoconfiguration */
if ( fail ) {
@@ -1133,7 +1150,15 @@ static void ipv6conf_expired ( struct retry_timer *timer, int fail ) {
/* Otherwise, transmit router solicitation and restart timer */
start_timer ( &ipv6conf->timer );
- ndp_tx_router_solicitation ( ipv6conf->netdev );
+ ndp_tx_router_solicitation ( netdev );
+
+ /* If link is blocked, defer router discovery timeout */
+ if ( netdev_link_blocked ( netdev ) &&
+ ( ipv6conf->deferred++ <= IPV6CONF_MAX_DEFERRALS ) ) {
+ DBGC ( netdev, "NDP %s deferring discovery timeout\n",
+ netdev->name );
+ start_timer_fixed ( &ipv6conf->timer, IPV6CONF_BLOCK_TIMEOUT );
+ }
}
/**
@@ -1235,6 +1260,8 @@ int start_ipv6conf ( struct interface *job, struct net_device *netdev ) {
intf_init ( &ipv6conf->job, &ipv6conf_job_desc, &ipv6conf->refcnt );
intf_init ( &ipv6conf->dhcp, &ipv6conf_dhcp_desc, &ipv6conf->refcnt );
timer_init ( &ipv6conf->timer, ipv6conf_expired, &ipv6conf->refcnt );
+ set_timer_limits ( &ipv6conf->timer, IPV6CONF_MIN_TIMEOUT,
+ IPV6CONF_MAX_TIMEOUT );
ipv6conf->netdev = netdev_get ( netdev );
/* Start timer to initiate router solicitation */
diff --git a/src/net/netdevice.c b/src/net/netdevice.c
index 3b02e64bd..6e685630c 100644
--- a/src/net/netdevice.c
+++ b/src/net/netdevice.c
@@ -307,6 +307,12 @@ int netdev_tx ( struct net_device *netdev, struct io_buffer *iobuf ) {
if ( ( rc = inject_fault ( NETDEV_DISCARD_RATE ) ) != 0 )
goto err;
+ /* Map for DMA, if required */
+ if ( netdev->dma && ( ! dma_mapped ( &iobuf->map ) ) ) {
+ if ( ( rc = iob_map_tx ( iobuf, netdev->dma ) ) != 0 )
+ goto err;
+ }
+
/* Transmit packet */
if ( ( rc = netdev->op->transmit ( netdev, iobuf ) ) != 0 )
goto err;
@@ -340,6 +346,9 @@ int netdev_tx ( struct net_device *netdev, struct io_buffer *iobuf ) {
* Failure to do this will cause the retransmitted packet to be
* immediately redeferred (which will result in out-of-order
* transmissions and other nastiness).
+ *
+ * I/O buffers that have been mapped for DMA will remain mapped while
+ * present in the deferred transmit queue.
*/
void netdev_tx_defer ( struct net_device *netdev, struct io_buffer *iobuf ) {
@@ -365,6 +374,9 @@ void netdev_tx_defer ( struct net_device *netdev, struct io_buffer *iobuf ) {
*
* The packet is discarded and a TX error is recorded. This function
* takes ownership of the I/O buffer.
+ *
+ * The I/O buffer will be automatically unmapped for DMA, if
+ * applicable.
*/
void netdev_tx_err ( struct net_device *netdev,
struct io_buffer *iobuf, int rc ) {
@@ -379,6 +391,10 @@ void netdev_tx_err ( struct net_device *netdev,
netdev->name, iobuf, strerror ( rc ) );
}
+ /* Unmap I/O buffer, if required */
+ if ( iobuf && dma_mapped ( &iobuf->map ) )
+ iob_unmap ( iobuf );
+
/* Discard packet */
free_iob ( iobuf );
}
@@ -462,10 +478,13 @@ static void netdev_tx_flush ( struct net_device *netdev ) {
* Add packet to receive queue
*
* @v netdev Network device
- * @v iobuf I/O buffer, or NULL
+ * @v iobuf I/O buffer
*
* The packet is added to the network device's RX queue. This
* function takes ownership of the I/O buffer.
+ *
+ * The I/O buffer will be automatically unmapped for DMA, if
+ * applicable.
*/
void netdev_rx ( struct net_device *netdev, struct io_buffer *iobuf ) {
int rc;
@@ -479,6 +498,10 @@ void netdev_rx ( struct net_device *netdev, struct io_buffer *iobuf ) {
return;
}
+ /* Unmap I/O buffer, if required */
+ if ( dma_mapped ( &iobuf->map ) )
+ iob_unmap ( iobuf );
+
/* Enqueue packet */
list_add_tail ( &iobuf->list, &netdev->rx_queue );
@@ -497,6 +520,9 @@ void netdev_rx ( struct net_device *netdev, struct io_buffer *iobuf ) {
* takes ownership of the I/O buffer. @c iobuf may be NULL if, for
* example, the net device wishes to report an error due to being
* unable to allocate an I/O buffer.
+ *
+ * The I/O buffer will be automatically unmapped for DMA, if
+ * applicable.
*/
void netdev_rx_err ( struct net_device *netdev,
struct io_buffer *iobuf, int rc ) {
@@ -504,6 +530,10 @@ void netdev_rx_err ( struct net_device *netdev,
DBGC ( netdev, "NETDEV %s failed to receive %p: %s\n",
netdev->name, iobuf, strerror ( rc ) );
+ /* Unmap I/O buffer, if required */
+ if ( iobuf && dma_mapped ( &iobuf->map ) )
+ iob_unmap ( iobuf );
+
/* Discard packet */
free_iob ( iobuf );
@@ -1178,6 +1208,8 @@ static unsigned int net_discard ( void ) {
/* Discard first deferred packet */
list_del ( &iobuf->list );
+ if ( dma_mapped ( &iobuf->map ) )
+ iob_unmap ( iobuf );
free_iob ( iobuf );
/* Report discard */
diff --git a/src/net/tcp/httpconn.c b/src/net/tcp/httpconn.c
index 5121ff6c2..f9221b27e 100644
--- a/src/net/tcp/httpconn.c
+++ b/src/net/tcp/httpconn.c
@@ -236,7 +236,6 @@ int http_connect ( struct interface *xfer, struct uri *uri ) {
struct http_connection *conn;
struct http_scheme *scheme;
struct sockaddr_tcpip server;
- struct interface *socket;
unsigned int port;
int rc;
@@ -296,15 +295,15 @@ int http_connect ( struct interface *xfer, struct uri *uri ) {
/* Open socket */
memset ( &server, 0, sizeof ( server ) );
server.st_port = htons ( port );
- socket = &conn->socket;
- if ( scheme->filter &&
- ( ( rc = scheme->filter ( socket, uri->host, &socket ) ) != 0 ) )
- goto err_filter;
- if ( ( rc = xfer_open_named_socket ( socket, SOCK_STREAM,
+ if ( ( rc = xfer_open_named_socket ( &conn->socket, SOCK_STREAM,
( struct sockaddr * ) &server,
uri->host, NULL ) ) != 0 )
goto err_open;
+ /* Add filter, if any */
+ if ( scheme->filter && ( ( rc = scheme->filter ( conn ) ) != 0 ) )
+ goto err_filter;
+
/* Attach to parent interface, mortalise self, and return */
intf_plug_plug ( &conn->xfer, xfer );
ref_put ( &conn->refcnt );
@@ -313,8 +312,8 @@ int http_connect ( struct interface *xfer, struct uri *uri ) {
conn->scheme->name, conn->uri->host, port );
return 0;
- err_open:
err_filter:
+ err_open:
DBGC2 ( conn, "HTTPCONN %p could not create %s://%s:%d: %s\n", conn,
conn->scheme->name, conn->uri->host, port, strerror ( rc ) );
http_conn_close ( conn, rc );
diff --git a/src/net/tcp/httpcore.c b/src/net/tcp/httpcore.c
index f755fb72d..01bb496b2 100644
--- a/src/net/tcp/httpcore.c
+++ b/src/net/tcp/httpcore.c
@@ -56,6 +56,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <ipxe/profile.h>
#include <ipxe/vsprintf.h>
#include <ipxe/errortab.h>
+#include <ipxe/efi/efi_path.h>
#include <ipxe/http.h>
/* Disambiguate the various error causes */
@@ -519,6 +520,18 @@ __weak int http_block_read_capacity ( struct http_transaction *http __unused,
return -ENOTSUP;
}
+/**
+ * Describe as an EFI device path
+ *
+ * @v http HTTP transaction
+ * @ret path EFI device path, or NULL on error
+ */
+static EFI_DEVICE_PATH_PROTOCOL *
+http_efi_describe ( struct http_transaction *http ) {
+
+ return efi_uri_path ( http->uri );
+}
+
/** HTTP data transfer interface operations */
static struct interface_operation http_xfer_operations[] = {
INTF_OP ( block_read, struct http_transaction *, http_block_read ),
@@ -526,6 +539,8 @@ static struct interface_operation http_xfer_operations[] = {
http_block_read_capacity ),
INTF_OP ( xfer_window_changed, struct http_transaction *, http_step ),
INTF_OP ( intf_close, struct http_transaction *, http_close ),
+ EFI_INTF_OP ( efi_describe, struct http_transaction *,
+ http_efi_describe ),
};
/** HTTP data transfer interface descriptor */
diff --git a/src/net/tcp/https.c b/src/net/tcp/https.c
index e91000322..85f1f124f 100644
--- a/src/net/tcp/https.c
+++ b/src/net/tcp/https.c
@@ -31,12 +31,24 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
*/
#include <ipxe/open.h>
+#include <ipxe/uri.h>
#include <ipxe/tls.h>
#include <ipxe/http.h>
#include <ipxe/features.h>
FEATURE ( FEATURE_PROTOCOL, "HTTPS", DHCP_EB_FEATURE_HTTPS, 1 );
+/**
+ * Add HTTPS filter
+ *
+ * @v conn HTTP connection
+ * @ret rc Return status code
+ */
+static int https_filter ( struct http_connection *conn ) {
+
+ return add_tls ( &conn->socket, conn->uri->host, NULL, NULL );
+}
+
/** HTTPS URI opener */
struct uri_opener https_uri_opener __uri_opener = {
.scheme = "https",
@@ -47,5 +59,5 @@ struct uri_opener https_uri_opener __uri_opener = {
struct http_scheme https_scheme __http_scheme = {
.name = "https",
.port = HTTPS_PORT,
- .filter = add_tls,
+ .filter = https_filter,
};
diff --git a/src/net/tcp/iscsi.c b/src/net/tcp/iscsi.c
index 3a44b90f0..e36d5619d 100644
--- a/src/net/tcp/iscsi.c
+++ b/src/net/tcp/iscsi.c
@@ -46,6 +46,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <ipxe/base16.h>
#include <ipxe/base64.h>
#include <ipxe/ibft.h>
+#include <ipxe/efi/efi_path.h>
#include <ipxe/iscsi.h>
/** @file
@@ -1863,6 +1864,7 @@ static struct interface_operation iscsi_control_op[] = {
INTF_OP ( xfer_window, struct iscsi_session *, iscsi_scsi_window ),
INTF_OP ( intf_close, struct iscsi_session *, iscsi_close ),
INTF_OP ( acpi_describe, struct iscsi_session *, iscsi_describe ),
+ EFI_INTF_OP ( efi_describe, struct iscsi_session *, efi_iscsi_path ),
};
/** iSCSI SCSI command-issuing interface descriptor */
diff --git a/src/net/tcp/syslogs.c b/src/net/tcp/syslogs.c
index 0c07f86d5..f1f70d59e 100644
--- a/src/net/tcp/syslogs.c
+++ b/src/net/tcp/syslogs.c
@@ -62,9 +62,10 @@ static struct sockaddr_tcpip logserver = {
* @v intf Interface
* @v rc Reason for close
*/
-static void syslogs_close ( struct interface *intf __unused, int rc ) {
+static void syslogs_close ( struct interface *intf, int rc ) {
DBG ( "SYSLOGS console disconnected: %s\n", strerror ( rc ) );
+ intf_restart ( intf, rc );
}
/**
@@ -208,7 +209,6 @@ const struct setting syslogs_setting __setting ( SETTING_MISC, syslogs ) = {
static int apply_syslogs_settings ( void ) {
static char *old_server;
char *server;
- struct interface *socket;
int rc;
/* Fetch log server */
@@ -234,33 +234,32 @@ static int apply_syslogs_settings ( void ) {
rc = 0;
goto out_no_server;
}
-
- /* Add TLS filter */
- if ( ( rc = add_tls ( &syslogs, server, &socket ) ) != 0 ) {
- DBG ( "SYSLOGS cannot create TLS filter: %s\n",
- strerror ( rc ) );
- goto err_add_tls;
- }
+ DBG ( "SYSLOGS using log server %s\n", server );
/* Connect to log server */
- if ( ( rc = xfer_open_named_socket ( socket, SOCK_STREAM,
+ if ( ( rc = xfer_open_named_socket ( &syslogs, SOCK_STREAM,
(( struct sockaddr *) &logserver ),
server, NULL ) ) != 0 ) {
DBG ( "SYSLOGS cannot connect to log server: %s\n",
strerror ( rc ) );
goto err_open_named_socket;
}
- DBG ( "SYSLOGS using log server %s\n", server );
+
+ /* Add TLS filter */
+ if ( ( rc = add_tls ( &syslogs, server, NULL, NULL ) ) != 0 ) {
+ DBG ( "SYSLOGS cannot create TLS filter: %s\n",
+ strerror ( rc ) );
+ goto err_add_tls;
+ }
/* Record log server */
old_server = server;
- server = NULL;
- /* Success */
- rc = 0;
+ return 0;
- err_open_named_socket:
err_add_tls:
+ err_open_named_socket:
+ syslogs_close ( &syslogs, rc );
out_no_server:
out_no_change:
free ( server );
diff --git a/src/net/tls.c b/src/net/tls.c
index ea827600f..3c4144450 100644
--- a/src/net/tls.c
+++ b/src/net/tls.c
@@ -45,6 +45,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <ipxe/x509.h>
#include <ipxe/privkey.h>
#include <ipxe/certstore.h>
+#include <ipxe/rootcert.h>
#include <ipxe/rbg.h>
#include <ipxe/validator.h>
#include <ipxe/job.h>
@@ -349,7 +350,9 @@ static void free_tls_session ( struct refcnt *refcnt ) {
/* Remove from list of sessions */
list_del ( &session->list );
- /* Free session ticket */
+ /* Free dynamically-allocated resources */
+ x509_root_put ( session->root );
+ privkey_put ( session->key );
free ( session->ticket );
/* Free session */
@@ -378,8 +381,10 @@ static void free_tls ( struct refcnt *refcnt ) {
list_del ( &iobuf->list );
free_iob ( iobuf );
}
- x509_put ( tls->cert );
+ x509_chain_put ( tls->certs );
x509_chain_put ( tls->chain );
+ x509_root_put ( tls->root );
+ privkey_put ( tls->key );
/* Drop reference to session */
assert ( list_empty ( &tls->list ) );
@@ -1148,40 +1153,56 @@ static int tls_send_client_hello ( struct tls_connection *tls ) {
*/
static int tls_send_certificate ( struct tls_connection *tls ) {
struct {
- uint32_t type_length;
tls24_t length;
- struct {
- tls24_t length;
- uint8_t data[ tls->cert->raw.len ];
- } __attribute__ (( packed )) certificates[1];
+ uint8_t data[0];
} __attribute__ (( packed )) *certificate;
+ struct {
+ uint32_t type_length;
+ tls24_t length;
+ typeof ( *certificate ) certificates[0];
+ } __attribute__ (( packed )) *certificates;
+ struct x509_link *link;
+ struct x509_certificate *cert;
+ size_t len;
int rc;
+ /* Calculate length of client certificates */
+ len = 0;
+ list_for_each_entry ( link, &tls->certs->links, list ) {
+ cert = link->cert;
+ len += ( sizeof ( *certificate ) + cert->raw.len );
+ DBGC ( tls, "TLS %p sending client certificate %s\n",
+ tls, x509_name ( cert ) );
+ }
+
/* Allocate storage for Certificate record (which may be too
* large for the stack).
*/
- certificate = zalloc ( sizeof ( *certificate ) );
- if ( ! certificate )
+ certificates = zalloc ( sizeof ( *certificates ) + len );
+ if ( ! certificates )
return -ENOMEM_CERTIFICATE;
/* Populate record */
- certificate->type_length =
+ certificates->type_length =
( cpu_to_le32 ( TLS_CERTIFICATE ) |
- htonl ( sizeof ( *certificate ) -
- sizeof ( certificate->type_length ) ) );
- tls_set_uint24 ( &certificate->length,
- sizeof ( certificate->certificates ) );
- tls_set_uint24 ( &certificate->certificates[0].length,
- sizeof ( certificate->certificates[0].data ) );
- memcpy ( certificate->certificates[0].data,
- tls->cert->raw.data,
- sizeof ( certificate->certificates[0].data ) );
+ htonl ( sizeof ( *certificates ) + len -
+ sizeof ( certificates->type_length ) ) );
+ tls_set_uint24 ( &certificates->length, len );
+ certificate = &certificates->certificates[0];
+ list_for_each_entry ( link, &tls->certs->links, list ) {
+ cert = link->cert;
+ tls_set_uint24 ( &certificate->length, cert->raw.len );
+ memcpy ( certificate->data, cert->raw.data, cert->raw.len );
+ certificate = ( ( ( void * ) certificate->data ) +
+ cert->raw.len );
+ }
/* Transmit record */
- rc = tls_send_handshake ( tls, certificate, sizeof ( *certificate ) );
+ rc = tls_send_handshake ( tls, certificates,
+ ( sizeof ( *certificates ) + len ) );
/* Free record */
- free ( certificate );
+ free ( certificates );
return rc;
}
@@ -1238,8 +1259,9 @@ static int tls_send_client_key_exchange ( struct tls_connection *tls ) {
*/
static int tls_send_certificate_verify ( struct tls_connection *tls ) {
struct digest_algorithm *digest = tls->handshake_digest;
- struct x509_certificate *cert = tls->cert;
+ struct x509_certificate *cert = x509_first ( tls->certs );
struct pubkey_algorithm *pubkey = cert->signature_algorithm->pubkey;
+ struct asn1_cursor *key = privkey_cursor ( tls->key );
uint8_t digest_out[ digest->digestsize ];
uint8_t ctx[ pubkey->ctxsize ];
struct tls_signature_hash_algorithm *sig_hash = NULL;
@@ -1249,8 +1271,7 @@ static int tls_send_certificate_verify ( struct tls_connection *tls ) {
tls_verify_handshake ( tls, digest_out );
/* Initialise public-key algorithm */
- if ( ( rc = pubkey_init ( pubkey, ctx, private_key.data,
- private_key.len ) ) != 0 ) {
+ if ( ( rc = pubkey_init ( pubkey, ctx, key->data, key->len ) ) != 0 ) {
DBGC ( tls, "TLS %p could not initialise %s client private "
"key: %s\n", tls, pubkey->name, strerror ( rc ) );
goto err_pubkey_init;
@@ -1845,26 +1866,57 @@ static int tls_new_certificate ( struct tls_connection *tls,
static int tls_new_certificate_request ( struct tls_connection *tls,
const void *data __unused,
size_t len __unused ) {
+ struct x509_certificate *cert;
+ int rc;
/* We can only send a single certificate, so there is no point
* in parsing the Certificate Request.
*/
- /* Free any existing client certificate */
- x509_put ( tls->cert );
+ /* Free any existing client certificate chain */
+ x509_chain_put ( tls->certs );
+ tls->certs = NULL;
/* Determine client certificate to be sent */
- tls->cert = certstore_find_key ( &private_key );
- if ( ! tls->cert ) {
+ cert = certstore_find_key ( tls->key );
+ if ( ! cert ) {
DBGC ( tls, "TLS %p could not find certificate corresponding "
"to private key\n", tls );
- return -EPERM_CLIENT_CERT;
+ rc = -EPERM_CLIENT_CERT;
+ goto err_find;
+ }
+ x509_get ( cert );
+ DBGC ( tls, "TLS %p selected client certificate %s\n",
+ tls, x509_name ( cert ) );
+
+ /* Create client certificate chain */
+ tls->certs = x509_alloc_chain();
+ if ( ! tls->certs ) {
+ rc = -ENOMEM;
+ goto err_alloc;
}
- x509_get ( tls->cert );
- DBGC ( tls, "TLS %p sending client certificate %s\n",
- tls, x509_name ( tls->cert ) );
+
+ /* Append client certificate to chain */
+ if ( ( rc = x509_append ( tls->certs, cert ) ) != 0 )
+ goto err_append;
+
+ /* Append any relevant issuer certificates */
+ if ( ( rc = x509_auto_append ( tls->certs, &certstore ) ) != 0 )
+ goto err_auto_append;
+
+ /* Drop local reference to client certificate */
+ x509_put ( cert );
return 0;
+
+ err_auto_append:
+ err_append:
+ x509_chain_put ( tls->certs );
+ tls->certs = NULL;
+ err_alloc:
+ x509_put ( cert );
+ err_find:
+ return rc;
}
/**
@@ -1891,7 +1943,8 @@ static int tls_new_server_hello_done ( struct tls_connection *tls,
}
/* Begin certificate validation */
- if ( ( rc = create_validator ( &tls->validator, tls->chain ) ) != 0 ) {
+ if ( ( rc = create_validator ( &tls->validator, tls->chain,
+ tls->root ) ) != 0 ) {
DBGC ( tls, "TLS %p could not start certificate validation: "
"%s\n", tls, strerror ( rc ) );
return rc;
@@ -2880,7 +2933,7 @@ static void tls_validator_done ( struct tls_connection *tls, int rc ) {
tls->tx_pending |= ( TLS_TX_CLIENT_KEY_EXCHANGE |
TLS_TX_CHANGE_CIPHER |
TLS_TX_FINISHED );
- if ( tls->cert ) {
+ if ( tls->certs ) {
tls->tx_pending |= ( TLS_TX_CERTIFICATE |
TLS_TX_CERTIFICATE_VERIFY );
}
@@ -3048,7 +3101,9 @@ static int tls_session ( struct tls_connection *tls, const char *name ) {
/* Find existing matching session, if any */
list_for_each_entry ( session, &tls_sessions, list ) {
- if ( strcmp ( name, session->name ) == 0 ) {
+ if ( ( strcmp ( name, session->name ) == 0 ) &&
+ ( tls->root == session->root ) &&
+ ( tls->key == session->key ) ) {
ref_get ( &session->refcnt );
tls->session = session;
DBGC ( tls, "TLS %p joining session %s\n", tls, name );
@@ -3067,6 +3122,8 @@ static int tls_session ( struct tls_connection *tls, const char *name ) {
name_copy = ( ( ( void * ) session ) + sizeof ( *session ) );
strcpy ( name_copy, name );
session->name = name_copy;
+ session->root = x509_root_get ( tls->root );
+ session->key = privkey_get ( tls->key );
INIT_LIST_HEAD ( &session->conn );
list_add ( &session->list, &tls_sessions );
@@ -3088,8 +3145,17 @@ static int tls_session ( struct tls_connection *tls, const char *name ) {
******************************************************************************
*/
+/**
+ * Add TLS on an interface
+ *
+ * @v xfer Data transfer interface
+ * @v name Host name
+ * @v root Root of trust (or NULL to use default)
+ * @v key Private key (or NULL to use default)
+ * @ret rc Return status code
+ */
int add_tls ( struct interface *xfer, const char *name,
- struct interface **next ) {
+ struct x509_root *root, struct private_key *key ) {
struct tls_connection *tls;
int rc;
@@ -3107,6 +3173,8 @@ int add_tls ( struct interface *xfer, const char *name,
intf_init ( &tls->validator, &tls_validator_desc, &tls->refcnt );
process_init_stopped ( &tls->process, &tls_process_desc,
&tls->refcnt );
+ tls->key = privkey_get ( key ? key : &private_key );
+ tls->root = x509_root_get ( root ? root : &root_certificates );
tls->version = TLS_VERSION_TLS_1_2;
tls_clear_cipher ( tls, &tls->tx_cipherspec );
tls_clear_cipher ( tls, &tls->tx_cipherspec_pending );
@@ -3133,8 +3201,7 @@ int add_tls ( struct interface *xfer, const char *name,
tls_restart ( tls );
/* Attach to parent interface, mortalise self, and return */
- intf_plug_plug ( &tls->plainstream, xfer );
- *next = &tls->cipherstream;
+ intf_insert ( xfer, &tls->plainstream, &tls->cipherstream );
ref_put ( &tls->refcnt );
return 0;
diff --git a/src/net/udp/dhcp.c b/src/net/udp/dhcp.c
index 3a3666c9a..4ebd38bbb 100644
--- a/src/net/udp/dhcp.c
+++ b/src/net/udp/dhcp.c
@@ -451,17 +451,6 @@ static void dhcp_discovery_rx ( struct dhcp_session *dhcp,
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 ) ) {
- DBGC ( dhcp, "DHCP %p deferring discovery\n", dhcp );
- dhcp->start = currticks();
- start_timer_fixed ( &dhcp->timer,
- ( DHCP_DISC_START_TIMEOUT_SEC *
- TICKS_PER_SEC ) );
- return;
- }
-
/* Give up waiting for ProxyDHCP before we reach the failure point */
if ( dhcp->offer.s_addr &&
( elapsed > DHCP_DISC_PROXY_TIMEOUT_SEC * TICKS_PER_SEC ) ) {
@@ -469,8 +458,18 @@ static void dhcp_discovery_expired ( struct dhcp_session *dhcp ) {
return;
}
- /* Otherwise, retransmit current packet */
+ /* Retransmit current packet */
dhcp_tx ( dhcp );
+
+ /* If link is blocked, defer DHCP discovery timeout */
+ if ( netdev_link_blocked ( dhcp->netdev ) &&
+ ( dhcp->count <= DHCP_DISC_MAX_DEFERRALS ) ) {
+ DBGC ( dhcp, "DHCP %p deferring discovery timeout\n", dhcp );
+ dhcp->start = currticks();
+ start_timer_fixed ( &dhcp->timer,
+ ( DHCP_DISC_START_TIMEOUT_SEC *
+ TICKS_PER_SEC ) );
+ }
}
/** DHCP discovery state operations */
diff --git a/src/net/udp/dns.c b/src/net/udp/dns.c
index f23e10dcc..e5579174e 100644
--- a/src/net/udp/dns.c
+++ b/src/net/udp/dns.c
@@ -1211,7 +1211,7 @@ static int apply_dns_settings ( void ) {
/* Fetch DNS server address */
apply_dns_servers();
- if ( DBG_LOG && ( dns_count != 0 ) ) {
+ if ( DBG_EXTRA && ( dns_count != 0 ) ) {
union {
struct sockaddr sa;
struct sockaddr_in sin;
@@ -1219,37 +1219,37 @@ static int apply_dns_settings ( void ) {
} u;
unsigned int i;
- DBGC ( dbgcol, "DNS servers:" );
+ DBGC2 ( dbgcol, "DNS servers:" );
for ( i = 0 ; i < dns6.count ; i++ ) {
u.sin6.sin6_family = AF_INET6;
memcpy ( &u.sin6.sin6_addr, &dns6.in6[i],
sizeof ( u.sin6.sin6_addr ) );
- DBGC ( dbgcol, " %s", sock_ntoa ( &u.sa ) );
+ DBGC2 ( dbgcol, " %s", sock_ntoa ( &u.sa ) );
}
for ( i = 0 ; i < dns4.count ; i++ ) {
u.sin.sin_family = AF_INET;
u.sin.sin_addr = dns4.in[i];
- DBGC ( dbgcol, " %s", sock_ntoa ( &u.sa ) );
+ DBGC2 ( dbgcol, " %s", sock_ntoa ( &u.sa ) );
}
- DBGC ( dbgcol, "\n" );
+ DBGC2 ( dbgcol, "\n" );
}
/* Fetch DNS search list */
apply_dns_search();
- if ( DBG_LOG && ( dns_search.len != 0 ) ) {
+ if ( DBG_EXTRA && ( dns_search.len != 0 ) ) {
struct dns_name name;
int offset;
- DBGC ( dbgcol, "DNS search list:" );
+ DBGC2 ( dbgcol, "DNS search list:" );
memcpy ( &name, &dns_search, sizeof ( name ) );
while ( name.offset != name.len ) {
- DBGC ( dbgcol, " %s", dns_name ( &name ) );
+ DBGC2 ( dbgcol, " %s", dns_name ( &name ) );
offset = dns_skip_search ( &name );
if ( offset < 0 )
break;
name.offset = offset;
}
- DBGC ( dbgcol, "\n" );
+ DBGC2 ( dbgcol, "\n" );
}
return 0;
diff --git a/src/net/udp/tftp.c b/src/net/udp/tftp.c
index a0dac1ec5..3073e682f 100644
--- a/src/net/udp/tftp.c
+++ b/src/net/udp/tftp.c
@@ -43,6 +43,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <ipxe/settings.h>
#include <ipxe/dhcp.h>
#include <ipxe/uri.h>
+#include <ipxe/profile.h>
#include <ipxe/tftp.h>
/** @file
@@ -158,6 +159,14 @@ enum {
/** Maximum number of MTFTP open requests before falling back to TFTP */
#define MTFTP_MAX_TIMEOUTS 3
+/** Client profiler */
+static struct profiler tftp_client_profiler __profiler =
+ { .name = "tftp.client" };
+
+/** Server profiler */
+static struct profiler tftp_server_profiler __profiler =
+ { .name = "tftp.server" };
+
/**
* Free TFTP request
*
@@ -802,6 +811,10 @@ static int tftp_rx_data ( struct tftp_request *tftp,
}
block += ( ntohs ( data->block ) - 1 );
+ /* Stop profiling server turnaround if applicable */
+ if ( block )
+ profile_stop ( &tftp_server_profiler );
+
/* Extract data */
offset = ( block * tftp->blksize );
iob_pull ( iobuf, sizeof ( *data ) );
@@ -834,6 +847,12 @@ static int tftp_rx_data ( struct tftp_request *tftp,
/* Acknowledge block */
tftp_send_packet ( tftp );
+ /* Stop profiling client turnaround */
+ profile_stop ( &tftp_client_profiler );
+
+ /* Start profiling server turnaround */
+ profile_start ( &tftp_server_profiler );
+
/* If all blocks have been received, finish. */
if ( bitmap_full ( &tftp->bitmap ) )
tftp_done ( tftp, 0 );
@@ -906,7 +925,10 @@ static int tftp_rx ( struct tftp_request *tftp,
struct tftp_common *common = iobuf->data;
size_t len = iob_len ( iobuf );
int rc = -EINVAL;
-
+
+ /* Start profiling client turnaround */
+ profile_start ( &tftp_client_profiler );
+
/* Sanity checks */
if ( len < sizeof ( *common ) ) {
DBGC ( tftp, "TFTP %p received underlength packet length "
diff --git a/src/net/validator.c b/src/net/validator.c
index f6b03ff41..693d4464b 100644
--- a/src/net/validator.c
+++ b/src/net/validator.c
@@ -73,6 +73,8 @@ struct validator {
/** Process */
struct process process;
+ /** Root of trust (or NULL to use default) */
+ struct x509_root *root;
/** X.509 certificate chain */
struct x509_chain *chain;
/** OCSP check */
@@ -114,6 +116,7 @@ static void validator_free ( struct refcnt *refcnt ) {
DBGC2 ( validator, "VALIDATOR %p \"%s\" freed\n",
validator, validator_name ( validator ) );
+ x509_root_put ( validator->root );
x509_chain_put ( validator->chain );
ocsp_put ( validator->ocsp );
xferbuf_free ( &validator->buffer );
@@ -554,7 +557,7 @@ static void validator_step ( struct validator *validator ) {
*/
now = time ( NULL );
if ( ( rc = x509_validate_chain ( validator->chain, now, NULL,
- NULL ) ) == 0 ) {
+ validator->root ) ) == 0 ) {
DBGC ( validator, "VALIDATOR %p \"%s\" validated\n",
validator, validator_name ( validator ) );
validator_finished ( validator, 0 );
@@ -569,7 +572,7 @@ static void validator_step ( struct validator *validator ) {
issuer = link->cert;
if ( ! cert )
continue;
- if ( ! x509_is_valid ( issuer ) )
+ if ( ! x509_is_valid ( issuer, validator->root ) )
continue;
/* The issuer is valid, but this certificate is not
* yet valid. If OCSP is applicable, start it.
@@ -621,9 +624,11 @@ static struct process_descriptor validator_process_desc =
*
* @v job Job control interface
* @v chain X.509 certificate chain
+ * @v root Root of trust, or NULL to use default
* @ret rc Return status code
*/
-int create_validator ( struct interface *job, struct x509_chain *chain ) {
+int create_validator ( struct interface *job, struct x509_chain *chain,
+ struct x509_root *root ) {
struct validator *validator;
int rc;
@@ -646,6 +651,7 @@ int create_validator ( struct interface *job, struct x509_chain *chain ) {
&validator->refcnt );
process_init ( &validator->process, &validator_process_desc,
&validator->refcnt );
+ validator->root = x509_root_get ( root );
validator->chain = x509_chain_get ( chain );
xferbuf_malloc_init ( &validator->buffer );
diff --git a/src/tests/cms_test.c b/src/tests/cms_test.c
index b805a9974..f35fa206d 100644
--- a/src/tests/cms_test.c
+++ b/src/tests/cms_test.c
@@ -1317,6 +1317,7 @@ static struct x509_chain empty_store = {
/** Root certificate list containing the iPXE self-test root CA */
static struct x509_root test_root = {
+ .refcnt = REF_INIT ( ref_no_free ),
.digest = &cms_test_algorithm,
.count = 1,
.fingerprints = root_crt_fingerprint,
@@ -1331,6 +1332,7 @@ static uint8_t dummy_fingerprint[] =
/** Certificate store containing a dummy fingerprint */
static struct x509_root dummy_root = {
+ .refcnt = REF_INIT ( ref_no_free ),
.digest = &cms_test_algorithm,
.count = 1,
.fingerprints = dummy_fingerprint,
diff --git a/src/tests/ocsp_test.c b/src/tests/ocsp_test.c
index a3349346a..3d2f556ed 100644
--- a/src/tests/ocsp_test.c
+++ b/src/tests/ocsp_test.c
@@ -42,6 +42,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <stdlib.h>
#include <string.h>
#include <ipxe/x509.h>
+#include <ipxe/rootcert.h>
#include <ipxe/ocsp.h>
#include <ipxe/test.h>
@@ -110,7 +111,7 @@ static void ocsp_prepare_test ( struct ocsp_test *test ) {
x509_invalidate ( cert );
/* Force-validate issuer certificate */
- issuer->flags |= X509_FL_VALIDATED;
+ issuer->root = &root_certificates;
issuer->path_remaining = ( issuer->extensions.basic.path_len + 1 );
}
diff --git a/src/tests/x509_test.c b/src/tests/x509_test.c
index 658d5247c..256c3e85e 100644
--- a/src/tests/x509_test.c
+++ b/src/tests/x509_test.c
@@ -674,6 +674,7 @@ static struct x509_chain empty_store = {
/** Root certificate list containing the iPXE self-test root CA */
static struct x509_root test_root = {
+ .refcnt = REF_INIT ( ref_no_free ),
.digest = &x509_test_algorithm,
.count = 1,
.fingerprints = root_crt_fingerprint,
@@ -681,6 +682,7 @@ static struct x509_root test_root = {
/** Root certificate list containing the iPXE self-test intermediate CA */
static struct x509_root intermediate_root = {
+ .refcnt = REF_INIT ( ref_no_free ),
.digest = &x509_test_algorithm,
.count = 1,
.fingerprints = intermediate_crt_fingerprint,
@@ -695,6 +697,7 @@ static uint8_t dummy_fingerprint[] =
/** Certificate store containing a dummy fingerprint */
static struct x509_root dummy_root = {
+ .refcnt = REF_INIT ( ref_no_free ),
.digest = &x509_test_algorithm,
.count = 1,
.fingerprints = dummy_fingerprint,
@@ -943,6 +946,10 @@ static void x509_validate_chain_okx ( struct x509_test_chain *chn, time_t time,
x509_invalidate_chain ( chn->chain );
okx ( x509_validate_chain ( chn->chain, time, store, root ) == 0,
file, line );
+ okx ( x509_is_valid ( chn->certs[0]->cert, root ),
+ file, line );
+ okx ( ! x509_is_valid ( chn->certs[0]->cert, &dummy_root ),
+ file, line );
}
#define x509_validate_chain_ok( chn, time, store, root ) \
x509_validate_chain_okx ( chn, time, store, root, __FILE__, __LINE__ )
diff --git a/src/usr/autoboot.c b/src/usr/autoboot.c
index 51b07e125..62e90ecd0 100644
--- a/src/usr/autoboot.c
+++ b/src/usr/autoboot.c
@@ -210,18 +210,19 @@ int uriboot ( struct uri *filename, struct uri **root_paths,
}
/**
- * Close all open net devices
+ * Close all but one network device
*
* Called before a fresh boot attempt in order to free up memory. We
* don't just close the device immediately after the boot fails,
* because there may still be TCP connections in the process of
* closing.
*/
-static void close_all_netdevs ( void ) {
- struct net_device *netdev;
+static void close_other_netdevs ( struct net_device *netdev ) {
+ struct net_device *other;
- for_each_netdev ( netdev ) {
- ifclose ( netdev );
+ for_each_netdev ( other ) {
+ if ( other != netdev )
+ ifclose ( other );
}
}
@@ -388,7 +389,7 @@ int netboot ( struct net_device *netdev ) {
int rc;
/* Close all other network devices */
- close_all_netdevs();
+ close_other_netdevs ( netdev );
/* Open device and display device status */
if ( ( rc = ifopen ( netdev ) ) != 0 )
diff --git a/src/usr/certmgmt.c b/src/usr/certmgmt.c
index 2f233fe4f..e6bf51fd8 100644
--- a/src/usr/certmgmt.c
+++ b/src/usr/certmgmt.c
@@ -57,7 +57,7 @@ void certstat ( struct x509_certificate *cert ) {
printf ( " [PERMANENT]" );
if ( cert->flags & X509_FL_EXPLICIT )
printf ( " [EXPLICIT]" );
- if ( x509_is_valid ( cert ) )
+ if ( x509_is_valid ( cert, NULL ) )
printf ( " [VALIDATED]" );
printf ( "\n" );
}
diff --git a/src/usr/ifmgmt.c b/src/usr/ifmgmt.c
index f1172bafb..d87ffff27 100644
--- a/src/usr/ifmgmt.c
+++ b/src/usr/ifmgmt.c
@@ -108,10 +108,11 @@ static void ifstat_errors ( struct net_device_stats *stats,
* @v netdev Network device
*/
void ifstat ( struct net_device *netdev ) {
- printf ( "%s: %s using %s on %s (%s)\n"
+ printf ( "%s: %s using %s on %s (%s) [%s]\n"
" [Link:%s%s, TX:%d TXE:%d RX:%d RXE:%d]\n",
netdev->name, netdev_addr ( netdev ),
netdev->dev->driver_name, netdev->dev->name,
+ netdev->ll_protocol->name,
( netdev_is_open ( netdev ) ? "open" : "closed" ),
( netdev_link_ok ( netdev ) ? "up" : "down" ),
( netdev_link_blocked ( netdev ) ? " (blocked)" : "" ),
@@ -212,17 +213,20 @@ static int iflinkwait_progress ( struct ifpoller *ifpoller ) {
*
* @v netdev Network device
* @v timeout Timeout period, in ticks
+ * @v verbose Always display progress message
+ * @ret rc Return status code
*/
-int iflinkwait ( struct net_device *netdev, unsigned long timeout ) {
+int iflinkwait ( struct net_device *netdev, unsigned long timeout,
+ int verbose ) {
int rc;
/* Ensure device is open */
if ( ( rc = ifopen ( netdev ) ) != 0 )
return rc;
- /* Return immediately if link is already up */
+ /* Return immediately if link is already up, unless being verbose */
netdev_poll ( netdev );
- if ( netdev_link_ok ( netdev ) )
+ if ( netdev_link_ok ( netdev ) && ( ! verbose ) )
return 0;
/* Wait for link-up */
@@ -273,7 +277,7 @@ int ifconf ( struct net_device *netdev,
int rc;
/* Ensure device is open and link is up */
- if ( ( rc = iflinkwait ( netdev, LINK_WAIT_TIMEOUT ) ) != 0 )
+ if ( ( rc = iflinkwait ( netdev, LINK_WAIT_TIMEOUT, 0 ) ) != 0 )
return rc;
/* Start configuration */
diff --git a/src/usr/imgmgmt.c b/src/usr/imgmgmt.c
index a01d6e291..f8d149153 100644
--- a/src/usr/imgmgmt.c
+++ b/src/usr/imgmgmt.c
@@ -169,3 +169,24 @@ void imgstat ( struct image *image ) {
printf ( " \"%s\"", image->cmdline );
printf ( "\n" );
}
+
+/**
+ * Create image from block of memory
+ *
+ * @v name Name
+ * @v data Image data
+ * @v len Length
+ * @ret rc Return status code
+ */
+int imgmem ( const char *name, userptr_t data, size_t len ) {
+ struct image *image;
+
+ /* Create image */
+ image = image_memory ( name, data, len );
+ if ( ! image ) {
+ printf ( "Could not create image\n" );
+ return -ENOMEM;
+ }
+
+ return 0;
+}
diff --git a/src/usr/imgtrust.c b/src/usr/imgtrust.c
index 595ea6b25..e7c2067a0 100644
--- a/src/usr/imgtrust.c
+++ b/src/usr/imgtrust.c
@@ -77,7 +77,8 @@ int imgverify ( struct image *image, struct image *signature,
/* Complete all certificate chains */
list_for_each_entry ( info, &sig->info, list ) {
- if ( ( rc = create_validator ( &monojob, info->chain ) ) != 0 )
+ if ( ( rc = create_validator ( &monojob, info->chain,
+ NULL ) ) != 0 )
goto err_create_validator;
if ( ( rc = monojob_wait ( NULL, 0 ) ) != 0 )
goto err_validator_wait;
diff --git a/src/usr/lotest.c b/src/usr/lotest.c
index 6b75b5048..5b88ef27e 100644
--- a/src/usr/lotest.c
+++ b/src/usr/lotest.c
@@ -208,9 +208,9 @@ int loopback_test ( struct net_device *sender, struct net_device *receiver,
return rc;
/* Wait for link-up */
- if ( ( rc = iflinkwait ( sender, 0 ) ) != 0 )
+ if ( ( rc = iflinkwait ( sender, 0, 0 ) ) != 0 )
return rc;
- if ( ( rc = iflinkwait ( receiver, 0 ) ) != 0 )
+ if ( ( rc = iflinkwait ( receiver, 0, 0 ) ) != 0 )
return rc;
/* Allocate data buffer */
diff --git a/src/util/.gitignore b/src/util/.gitignore
index 33bedefd0..b4cb13601 100644
--- a/src/util/.gitignore
+++ b/src/util/.gitignore
@@ -6,5 +6,4 @@ elf2efi32
elf2efi64
efirom
efifatbin
-iccfix
einfo
diff --git a/src/util/eficompress.c b/src/util/eficompress.c
new file mode 100644
index 000000000..4fd74ccee
--- /dev/null
+++ b/src/util/eficompress.c
@@ -0,0 +1,1588 @@
+/** @file
+Compression routine. The compression algorithm is a mixture of LZ77 and Huffman
+coding. LZ77 transforms the source data into a sequence of Original Characters
+and Pointers to repeated strings. This sequence is further divided into Blocks
+and Huffman codings are applied to each Block.
+
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+//
+// Macro Definitions
+//
+
+#undef UINT8_MAX
+typedef INT16 NODE;
+#define UINT8_MAX 0xff
+#define UINT8_BIT 8
+#define THRESHOLD 3
+#define INIT_CRC 0
+#define WNDBIT 13
+#define WNDSIZ (1 << WNDBIT)
+#define MAXMATCH 256
+#define PERC_FLAG 0x8000U
+#define CODE_BIT 16
+#define NIL 0
+#define MAX_HASH_VAL (3 * WNDSIZ + (WNDSIZ / 512 + 1) * UINT8_MAX)
+#define HASH(p, c) ((p) + ((c) << (WNDBIT - 9)) + WNDSIZ * 2)
+#define CRCPOLY 0xA001
+#define UPDATE_CRC(c) mCrc = mCrcTable[(mCrc ^ (c)) & 0xFF] ^ (mCrc >> UINT8_BIT)
+
+//
+// C: the Char&Len Set; P: the Position Set; T: the exTra Set
+//
+
+#define NC (UINT8_MAX + MAXMATCH + 2 - THRESHOLD)
+#define CBIT 9
+#define NP (WNDBIT + 1)
+#define PBIT 4
+#define NT (CODE_BIT + 3)
+#define TBIT 5
+#if NT > NP
+ #define NPT NT
+#else
+ #define NPT NP
+#endif
+
+//
+// Function Prototypes
+//
+
+STATIC
+VOID
+PutDword(
+ IN UINT32 Data
+ );
+
+STATIC
+EFI_STATUS
+AllocateMemory (
+ );
+
+STATIC
+VOID
+FreeMemory (
+ );
+
+STATIC
+VOID
+InitSlide (
+ );
+
+STATIC
+NODE
+Child (
+ IN NODE q,
+ IN UINT8 c
+ );
+
+STATIC
+VOID
+MakeChild (
+ IN NODE q,
+ IN UINT8 c,
+ IN NODE r
+ );
+
+STATIC
+VOID
+Split (
+ IN NODE Old
+ );
+
+STATIC
+VOID
+InsertNode (
+ );
+
+STATIC
+VOID
+DeleteNode (
+ );
+
+STATIC
+VOID
+GetNextMatch (
+ );
+
+STATIC
+EFI_STATUS
+Encode (
+ );
+
+STATIC
+VOID
+CountTFreq (
+ );
+
+STATIC
+VOID
+WritePTLen (
+ IN INT32 n,
+ IN INT32 nbit,
+ IN INT32 Special
+ );
+
+STATIC
+VOID
+WriteCLen (
+ );
+
+STATIC
+VOID
+EncodeC (
+ IN INT32 c
+ );
+
+STATIC
+VOID
+EncodeP (
+ IN UINT32 p
+ );
+
+STATIC
+VOID
+SendBlock (
+ );
+
+STATIC
+VOID
+Output (
+ IN UINT32 c,
+ IN UINT32 p
+ );
+
+STATIC
+VOID
+HufEncodeStart (
+ );
+
+STATIC
+VOID
+HufEncodeEnd (
+ );
+
+STATIC
+VOID
+MakeCrcTable (
+ );
+
+STATIC
+VOID
+PutBits (
+ IN INT32 n,
+ IN UINT32 x
+ );
+
+STATIC
+INT32
+FreadCrc (
+ OUT UINT8 *p,
+ IN INT32 n
+ );
+
+STATIC
+VOID
+InitPutBits (
+ );
+
+STATIC
+VOID
+CountLen (
+ IN INT32 i
+ );
+
+STATIC
+VOID
+MakeLen (
+ IN INT32 Root
+ );
+
+STATIC
+VOID
+DownHeap (
+ IN INT32 i
+ );
+
+STATIC
+VOID
+MakeCode (
+ IN INT32 n,
+ IN UINT8 Len[],
+ OUT UINT16 Code[]
+ );
+
+STATIC
+INT32
+MakeTree (
+ IN INT32 NParm,
+ IN UINT16 FreqParm[],
+ OUT UINT8 LenParm[],
+ OUT UINT16 CodeParm[]
+ );
+
+
+//
+// Global Variables
+//
+
+STATIC UINT8 *mSrc, *mDst, *mSrcUpperLimit, *mDstUpperLimit;
+
+STATIC UINT8 *mLevel, *mText, *mChildCount, *mBuf, mCLen[NC], mPTLen[NPT], *mLen;
+STATIC INT16 mHeap[NC + 1];
+STATIC INT32 mRemainder, mMatchLen, mBitCount, mHeapSize, mN;
+STATIC UINT32 mBufSiz = 0, mOutputPos, mOutputMask, mSubBitBuf, mCrc;
+STATIC UINT32 mCompSize, mOrigSize;
+
+STATIC UINT16 *mFreq, *mSortPtr, mLenCnt[17], mLeft[2 * NC - 1], mRight[2 * NC - 1],
+ mCrcTable[UINT8_MAX + 1], mCFreq[2 * NC - 1],mCCode[NC],
+ mPFreq[2 * NP - 1], mPTCode[NPT], mTFreq[2 * NT - 1];
+
+STATIC NODE mPos, mMatchPos, mAvail, *mPosition, *mParent, *mPrev, *mNext = NULL;
+
+
+//
+// functions
+//
+
+EFI_STATUS
+EfiCompress (
+ IN UINT8 *SrcBuffer,
+ IN UINT32 SrcSize,
+ IN UINT8 *DstBuffer,
+ IN OUT UINT32 *DstSize
+ )
+/*++
+
+Routine Description:
+
+ The main compression routine.
+
+Arguments:
+
+ SrcBuffer - The buffer storing the source data
+ SrcSize - The size of source data
+ DstBuffer - The buffer to store the compressed data
+ DstSize - On input, the size of DstBuffer; On output,
+ the size of the actual compressed data.
+
+Returns:
+
+ EFI_BUFFER_TOO_SMALL - The DstBuffer is too small. In this case,
+ DstSize contains the size needed.
+ EFI_SUCCESS - Compression is successful.
+
+--*/
+{
+ EFI_STATUS Status = EFI_SUCCESS;
+
+ //
+ // Initializations
+ //
+ mBufSiz = 0;
+ mBuf = NULL;
+ mText = NULL;
+ mLevel = NULL;
+ mChildCount = NULL;
+ mPosition = NULL;
+ mParent = NULL;
+ mPrev = NULL;
+ mNext = NULL;
+
+
+ mSrc = SrcBuffer;
+ mSrcUpperLimit = mSrc + SrcSize;
+ mDst = DstBuffer;
+ mDstUpperLimit = mDst + *DstSize;
+
+ PutDword(0L);
+ PutDword(0L);
+
+ MakeCrcTable ();
+
+ mOrigSize = mCompSize = 0;
+ mCrc = INIT_CRC;
+
+ //
+ // Compress it
+ //
+
+ Status = Encode();
+ if (EFI_ERROR (Status)) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ //
+ // Null terminate the compressed data
+ //
+ if (mDst < mDstUpperLimit) {
+ *mDst++ = 0;
+ }
+
+ //
+ // Fill in compressed size and original size
+ //
+ mDst = DstBuffer;
+ PutDword(mCompSize+1);
+ PutDword(mOrigSize);
+
+ //
+ // Return
+ //
+
+ if (mCompSize + 1 + 8 > *DstSize) {
+ *DstSize = mCompSize + 1 + 8;
+ return EFI_BUFFER_TOO_SMALL;
+ } else {
+ *DstSize = mCompSize + 1 + 8;
+ return EFI_SUCCESS;
+ }
+
+}
+
+STATIC
+VOID
+PutDword(
+ IN UINT32 Data
+ )
+/*++
+
+Routine Description:
+
+ Put a dword to output stream
+
+Arguments:
+
+ Data - the dword to put
+
+Returns: (VOID)
+
+--*/
+{
+ if (mDst < mDstUpperLimit) {
+ *mDst++ = (UINT8)(((UINT8)(Data )) & 0xff);
+ }
+
+ if (mDst < mDstUpperLimit) {
+ *mDst++ = (UINT8)(((UINT8)(Data >> 0x08)) & 0xff);
+ }
+
+ if (mDst < mDstUpperLimit) {
+ *mDst++ = (UINT8)(((UINT8)(Data >> 0x10)) & 0xff);
+ }
+
+ if (mDst < mDstUpperLimit) {
+ *mDst++ = (UINT8)(((UINT8)(Data >> 0x18)) & 0xff);
+ }
+}
+
+STATIC
+EFI_STATUS
+AllocateMemory ()
+/*++
+
+Routine Description:
+
+ Allocate memory spaces for data structures used in compression process
+
+Arguments: (VOID)
+
+Returns:
+
+ EFI_SUCCESS - Memory is allocated successfully
+ EFI_OUT_OF_RESOURCES - Allocation fails
+
+--*/
+{
+ UINT32 i;
+
+ mText = malloc (WNDSIZ * 2 + MAXMATCH);
+ if (mText == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+ for (i = 0 ; i < WNDSIZ * 2 + MAXMATCH; i ++) {
+ mText[i] = 0;
+ }
+
+ mLevel = malloc ((WNDSIZ + UINT8_MAX + 1) * sizeof(*mLevel));
+ mChildCount = malloc ((WNDSIZ + UINT8_MAX + 1) * sizeof(*mChildCount));
+ mPosition = malloc ((WNDSIZ + UINT8_MAX + 1) * sizeof(*mPosition));
+ mParent = malloc (WNDSIZ * 2 * sizeof(*mParent));
+ mPrev = malloc (WNDSIZ * 2 * sizeof(*mPrev));
+ mNext = malloc ((MAX_HASH_VAL + 1) * sizeof(*mNext));
+ if (mLevel == NULL || mChildCount == NULL || mPosition == NULL ||
+ mParent == NULL || mPrev == NULL || mNext == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ mBufSiz = 16 * 1024U;
+ while ((mBuf = malloc(mBufSiz)) == NULL) {
+ mBufSiz = (mBufSiz / 10U) * 9U;
+ if (mBufSiz < 4 * 1024U) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+ }
+ mBuf[0] = 0;
+
+ return EFI_SUCCESS;
+}
+
+VOID
+FreeMemory ()
+/*++
+
+Routine Description:
+
+ Called when compression is completed to free memory previously allocated.
+
+Arguments: (VOID)
+
+Returns: (VOID)
+
+--*/
+{
+ if (mText) {
+ free (mText);
+ }
+
+ if (mLevel) {
+ free (mLevel);
+ }
+
+ if (mChildCount) {
+ free (mChildCount);
+ }
+
+ if (mPosition) {
+ free (mPosition);
+ }
+
+ if (mParent) {
+ free (mParent);
+ }
+
+ if (mPrev) {
+ free (mPrev);
+ }
+
+ if (mNext) {
+ free (mNext);
+ }
+
+ if (mBuf) {
+ free (mBuf);
+ }
+
+ return;
+}
+
+
+STATIC
+VOID
+InitSlide ()
+/*++
+
+Routine Description:
+
+ Initialize String Info Log data structures
+
+Arguments: (VOID)
+
+Returns: (VOID)
+
+--*/
+{
+ NODE i;
+
+ for (i = WNDSIZ; i <= WNDSIZ + UINT8_MAX; i++) {
+ mLevel[i] = 1;
+ mPosition[i] = NIL; /* sentinel */
+ }
+ for (i = WNDSIZ; i < WNDSIZ * 2; i++) {
+ mParent[i] = NIL;
+ }
+ mAvail = 1;
+ for (i = 1; i < WNDSIZ - 1; i++) {
+ mNext[i] = (NODE)(i + 1);
+ }
+
+ mNext[WNDSIZ - 1] = NIL;
+ for (i = WNDSIZ * 2; i <= MAX_HASH_VAL; i++) {
+ mNext[i] = NIL;
+ }
+}
+
+
+STATIC
+NODE
+Child (
+ IN NODE q,
+ IN UINT8 c
+ )
+/*++
+
+Routine Description:
+
+ Find child node given the parent node and the edge character
+
+Arguments:
+
+ q - the parent node
+ c - the edge character
+
+Returns:
+
+ The child node (NIL if not found)
+
+--*/
+{
+ NODE r;
+
+ r = mNext[HASH(q, c)];
+ mParent[NIL] = q; /* sentinel */
+ while (mParent[r] != q) {
+ r = mNext[r];
+ }
+
+ return r;
+}
+
+STATIC
+VOID
+MakeChild (
+ IN NODE q,
+ IN UINT8 c,
+ IN NODE r
+ )
+/*++
+
+Routine Description:
+
+ Create a new child for a given parent node.
+
+Arguments:
+
+ q - the parent node
+ c - the edge character
+ r - the child node
+
+Returns: (VOID)
+
+--*/
+{
+ NODE h, t;
+
+ h = (NODE)HASH(q, c);
+ t = mNext[h];
+ mNext[h] = r;
+ mNext[r] = t;
+ mPrev[t] = r;
+ mPrev[r] = h;
+ mParent[r] = q;
+ mChildCount[q]++;
+}
+
+STATIC
+VOID
+Split (
+ NODE Old
+ )
+/*++
+
+Routine Description:
+
+ Split a node.
+
+Arguments:
+
+ Old - the node to split
+
+Returns: (VOID)
+
+--*/
+{
+ NODE New, t;
+
+ New = mAvail;
+ mAvail = mNext[New];
+ mChildCount[New] = 0;
+ t = mPrev[Old];
+ mPrev[New] = t;
+ mNext[t] = New;
+ t = mNext[Old];
+ mNext[New] = t;
+ mPrev[t] = New;
+ mParent[New] = mParent[Old];
+ mLevel[New] = (UINT8)mMatchLen;
+ mPosition[New] = mPos;
+ MakeChild(New, mText[mMatchPos + mMatchLen], Old);
+ MakeChild(New, mText[mPos + mMatchLen], mPos);
+}
+
+STATIC
+VOID
+InsertNode ()
+/*++
+
+Routine Description:
+
+ Insert string info for current position into the String Info Log
+
+Arguments: (VOID)
+
+Returns: (VOID)
+
+--*/
+{
+ NODE q, r, j, t;
+ UINT8 c, *t1, *t2;
+
+ if (mMatchLen >= 4) {
+
+ //
+ // We have just got a long match, the target tree
+ // can be located by MatchPos + 1. Traverse the tree
+ // from bottom up to get to a proper starting point.
+ // The usage of PERC_FLAG ensures proper node deletion
+ // in DeleteNode() later.
+ //
+
+ mMatchLen--;
+ r = (INT16)((mMatchPos + 1) | WNDSIZ);
+ while ((q = mParent[r]) == NIL) {
+ r = mNext[r];
+ }
+ while (mLevel[q] >= mMatchLen) {
+ r = q; q = mParent[q];
+ }
+ t = q;
+ while (mPosition[t] < 0) {
+ mPosition[t] = mPos;
+ t = mParent[t];
+ }
+ if (t < WNDSIZ) {
+ mPosition[t] = (NODE)(mPos | PERC_FLAG);
+ }
+ } else {
+
+ //
+ // Locate the target tree
+ //
+
+ q = (INT16)(mText[mPos] + WNDSIZ);
+ c = mText[mPos + 1];
+ if ((r = Child(q, c)) == NIL) {
+ MakeChild(q, c, mPos);
+ mMatchLen = 1;
+ return;
+ }
+ mMatchLen = 2;
+ }
+
+ //
+ // Traverse down the tree to find a match.
+ // Update Position value along the route.
+ // Node split or creation is involved.
+ //
+
+ for ( ; ; ) {
+ if (r >= WNDSIZ) {
+ j = MAXMATCH;
+ mMatchPos = r;
+ } else {
+ j = mLevel[r];
+ mMatchPos = (NODE)(mPosition[r] & ~PERC_FLAG);
+ }
+ if (mMatchPos >= mPos) {
+ mMatchPos -= WNDSIZ;
+ }
+ t1 = &mText[mPos + mMatchLen];
+ t2 = &mText[mMatchPos + mMatchLen];
+ while (mMatchLen < j) {
+ if (*t1 != *t2) {
+ Split(r);
+ return;
+ }
+ mMatchLen++;
+ t1++;
+ t2++;
+ }
+ if (mMatchLen >= MAXMATCH) {
+ break;
+ }
+ mPosition[r] = mPos;
+ q = r;
+ if ((r = Child(q, *t1)) == NIL) {
+ MakeChild(q, *t1, mPos);
+ return;
+ }
+ mMatchLen++;
+ }
+ t = mPrev[r];
+ mPrev[mPos] = t;
+ mNext[t] = mPos;
+ t = mNext[r];
+ mNext[mPos] = t;
+ mPrev[t] = mPos;
+ mParent[mPos] = q;
+ mParent[r] = NIL;
+
+ //
+ // Special usage of 'next'
+ //
+ mNext[r] = mPos;
+
+}
+
+STATIC
+VOID
+DeleteNode ()
+/*++
+
+Routine Description:
+
+ Delete outdated string info. (The Usage of PERC_FLAG
+ ensures a clean deletion)
+
+Arguments: (VOID)
+
+Returns: (VOID)
+
+--*/
+{
+ NODE q, r, s, t, u;
+
+ if (mParent[mPos] == NIL) {
+ return;
+ }
+
+ r = mPrev[mPos];
+ s = mNext[mPos];
+ mNext[r] = s;
+ mPrev[s] = r;
+ r = mParent[mPos];
+ mParent[mPos] = NIL;
+ if (r >= WNDSIZ || --mChildCount[r] > 1) {
+ return;
+ }
+ t = (NODE)(mPosition[r] & ~PERC_FLAG);
+ if (t >= mPos) {
+ t -= WNDSIZ;
+ }
+ s = t;
+ q = mParent[r];
+ while ((u = mPosition[q]) & PERC_FLAG) {
+ u &= ~PERC_FLAG;
+ if (u >= mPos) {
+ u -= WNDSIZ;
+ }
+ if (u > s) {
+ s = u;
+ }
+ mPosition[q] = (INT16)(s | WNDSIZ);
+ q = mParent[q];
+ }
+ if (q < WNDSIZ) {
+ if (u >= mPos) {
+ u -= WNDSIZ;
+ }
+ if (u > s) {
+ s = u;
+ }
+ mPosition[q] = (INT16)(s | WNDSIZ | PERC_FLAG);
+ }
+ s = Child(r, mText[t + mLevel[r]]);
+ t = mPrev[s];
+ u = mNext[s];
+ mNext[t] = u;
+ mPrev[u] = t;
+ t = mPrev[r];
+ mNext[t] = s;
+ mPrev[s] = t;
+ t = mNext[r];
+ mPrev[t] = s;
+ mNext[s] = t;
+ mParent[s] = mParent[r];
+ mParent[r] = NIL;
+ mNext[r] = mAvail;
+ mAvail = r;
+}
+
+STATIC
+VOID
+GetNextMatch ()
+/*++
+
+Routine Description:
+
+ Advance the current position (read in new data if needed).
+ Delete outdated string info. Find a match string for current position.
+
+Arguments: (VOID)
+
+Returns: (VOID)
+
+--*/
+{
+ INT32 n;
+
+ mRemainder--;
+ if (++mPos == WNDSIZ * 2) {
+ memmove(&mText[0], &mText[WNDSIZ], WNDSIZ + MAXMATCH);
+ n = FreadCrc(&mText[WNDSIZ + MAXMATCH], WNDSIZ);
+ mRemainder += n;
+ mPos = WNDSIZ;
+ }
+ DeleteNode();
+ InsertNode();
+}
+
+STATIC
+EFI_STATUS
+Encode ()
+/*++
+
+Routine Description:
+
+ The main controlling routine for compression process.
+
+Arguments: (VOID)
+
+Returns:
+
+ EFI_SUCCESS - The compression is successful
+ EFI_OUT_0F_RESOURCES - Not enough memory for compression process
+
+--*/
+{
+ EFI_STATUS Status;
+ INT32 LastMatchLen;
+ NODE LastMatchPos;
+
+ Status = AllocateMemory();
+ if (EFI_ERROR(Status)) {
+ FreeMemory();
+ return Status;
+ }
+
+ InitSlide();
+
+ HufEncodeStart();
+
+ mRemainder = FreadCrc(&mText[WNDSIZ], WNDSIZ + MAXMATCH);
+
+ mMatchLen = 0;
+ mPos = WNDSIZ;
+ InsertNode();
+ if (mMatchLen > mRemainder) {
+ mMatchLen = mRemainder;
+ }
+ while (mRemainder > 0) {
+ LastMatchLen = mMatchLen;
+ LastMatchPos = mMatchPos;
+ GetNextMatch();
+ if (mMatchLen > mRemainder) {
+ mMatchLen = mRemainder;
+ }
+
+ if (mMatchLen > LastMatchLen || LastMatchLen < THRESHOLD) {
+
+ //
+ // Not enough benefits are gained by outputting a pointer,
+ // so just output the original character
+ //
+
+ Output(mText[mPos - 1], 0);
+ } else {
+
+ //
+ // Outputting a pointer is beneficial enough, do it.
+ //
+
+ Output(LastMatchLen + (UINT8_MAX + 1 - THRESHOLD),
+ (mPos - LastMatchPos - 2) & (WNDSIZ - 1));
+ while (--LastMatchLen > 0) {
+ GetNextMatch();
+ }
+ if (mMatchLen > mRemainder) {
+ mMatchLen = mRemainder;
+ }
+ }
+ }
+
+ HufEncodeEnd();
+ FreeMemory();
+ return EFI_SUCCESS;
+}
+
+STATIC
+VOID
+CountTFreq ()
+/*++
+
+Routine Description:
+
+ Count the frequencies for the Extra Set
+
+Arguments: (VOID)
+
+Returns: (VOID)
+
+--*/
+{
+ INT32 i, k, n, Count;
+
+ for (i = 0; i < NT; i++) {
+ mTFreq[i] = 0;
+ }
+ n = NC;
+ while (n > 0 && mCLen[n - 1] == 0) {
+ n--;
+ }
+ i = 0;
+ while (i < n) {
+ k = mCLen[i++];
+ if (k == 0) {
+ Count = 1;
+ while (i < n && mCLen[i] == 0) {
+ i++;
+ Count++;
+ }
+ if (Count <= 2) {
+ mTFreq[0] = (UINT16)(mTFreq[0] + Count);
+ } else if (Count <= 18) {
+ mTFreq[1]++;
+ } else if (Count == 19) {
+ mTFreq[0]++;
+ mTFreq[1]++;
+ } else {
+ mTFreq[2]++;
+ }
+ } else {
+ mTFreq[k + 2]++;
+ }
+ }
+}
+
+STATIC
+VOID
+WritePTLen (
+ IN INT32 n,
+ IN INT32 nbit,
+ IN INT32 Special
+ )
+/*++
+
+Routine Description:
+
+ Outputs the code length array for the Extra Set or the Position Set.
+
+Arguments:
+
+ n - the number of symbols
+ nbit - the number of bits needed to represent 'n'
+ Special - the special symbol that needs to be take care of
+
+Returns: (VOID)
+
+--*/
+{
+ INT32 i, k;
+
+ while (n > 0 && mPTLen[n - 1] == 0) {
+ n--;
+ }
+ PutBits(nbit, n);
+ i = 0;
+ while (i < n) {
+ k = mPTLen[i++];
+ if (k <= 6) {
+ PutBits(3, k);
+ } else {
+ PutBits(k - 3, (1U << (k - 3)) - 2);
+ }
+ if (i == Special) {
+ while (i < 6 && mPTLen[i] == 0) {
+ i++;
+ }
+ PutBits(2, (i - 3) & 3);
+ }
+ }
+}
+
+STATIC
+VOID
+WriteCLen ()
+/*++
+
+Routine Description:
+
+ Outputs the code length array for Char&Length Set
+
+Arguments: (VOID)
+
+Returns: (VOID)
+
+--*/
+{
+ INT32 i, k, n, Count;
+
+ n = NC;
+ while (n > 0 && mCLen[n - 1] == 0) {
+ n--;
+ }
+ PutBits(CBIT, n);
+ i = 0;
+ while (i < n) {
+ k = mCLen[i++];
+ if (k == 0) {
+ Count = 1;
+ while (i < n && mCLen[i] == 0) {
+ i++;
+ Count++;
+ }
+ if (Count <= 2) {
+ for (k = 0; k < Count; k++) {
+ PutBits(mPTLen[0], mPTCode[0]);
+ }
+ } else if (Count <= 18) {
+ PutBits(mPTLen[1], mPTCode[1]);
+ PutBits(4, Count - 3);
+ } else if (Count == 19) {
+ PutBits(mPTLen[0], mPTCode[0]);
+ PutBits(mPTLen[1], mPTCode[1]);
+ PutBits(4, 15);
+ } else {
+ PutBits(mPTLen[2], mPTCode[2]);
+ PutBits(CBIT, Count - 20);
+ }
+ } else {
+ PutBits(mPTLen[k + 2], mPTCode[k + 2]);
+ }
+ }
+}
+
+STATIC
+VOID
+EncodeC (
+ IN INT32 c
+ )
+{
+ PutBits(mCLen[c], mCCode[c]);
+}
+
+STATIC
+VOID
+EncodeP (
+ IN UINT32 p
+ )
+{
+ UINT32 c, q;
+
+ c = 0;
+ q = p;
+ while (q) {
+ q >>= 1;
+ c++;
+ }
+ PutBits(mPTLen[c], mPTCode[c]);
+ if (c > 1) {
+ PutBits(c - 1, p & (0xFFFFU >> (17 - c)));
+ }
+}
+
+STATIC
+VOID
+SendBlock ()
+/*++
+
+Routine Description:
+
+ Huffman code the block and output it.
+
+Argument: (VOID)
+
+Returns: (VOID)
+
+--*/
+{
+ UINT32 i, k, Flags, Root, Pos, Size;
+ Flags = 0;
+
+ Root = MakeTree(NC, mCFreq, mCLen, mCCode);
+ Size = mCFreq[Root];
+ PutBits(16, Size);
+ if (Root >= NC) {
+ CountTFreq();
+ Root = MakeTree(NT, mTFreq, mPTLen, mPTCode);
+ if (Root >= NT) {
+ WritePTLen(NT, TBIT, 3);
+ } else {
+ PutBits(TBIT, 0);
+ PutBits(TBIT, Root);
+ }
+ WriteCLen();
+ } else {
+ PutBits(TBIT, 0);
+ PutBits(TBIT, 0);
+ PutBits(CBIT, 0);
+ PutBits(CBIT, Root);
+ }
+ Root = MakeTree(NP, mPFreq, mPTLen, mPTCode);
+ if (Root >= NP) {
+ WritePTLen(NP, PBIT, -1);
+ } else {
+ PutBits(PBIT, 0);
+ PutBits(PBIT, Root);
+ }
+ Pos = 0;
+ for (i = 0; i < Size; i++) {
+ if (i % UINT8_BIT == 0) {
+ Flags = mBuf[Pos++];
+ } else {
+ Flags <<= 1;
+ }
+ if (Flags & (1U << (UINT8_BIT - 1))) {
+ EncodeC(mBuf[Pos++] + (1U << UINT8_BIT));
+ k = mBuf[Pos++] << UINT8_BIT;
+ k += mBuf[Pos++];
+ EncodeP(k);
+ } else {
+ EncodeC(mBuf[Pos++]);
+ }
+ }
+ for (i = 0; i < NC; i++) {
+ mCFreq[i] = 0;
+ }
+ for (i = 0; i < NP; i++) {
+ mPFreq[i] = 0;
+ }
+}
+
+
+STATIC
+VOID
+Output (
+ IN UINT32 c,
+ IN UINT32 p
+ )
+/*++
+
+Routine Description:
+
+ Outputs an Original Character or a Pointer
+
+Arguments:
+
+ c - The original character or the 'String Length' element of a Pointer
+ p - The 'Position' field of a Pointer
+
+Returns: (VOID)
+
+--*/
+{
+ STATIC UINT32 CPos;
+
+ if ((mOutputMask >>= 1) == 0) {
+ mOutputMask = 1U << (UINT8_BIT - 1);
+ if (mOutputPos >= mBufSiz - 3 * UINT8_BIT) {
+ SendBlock();
+ mOutputPos = 0;
+ }
+ CPos = mOutputPos++;
+ mBuf[CPos] = 0;
+ }
+ mBuf[mOutputPos++] = (UINT8) c;
+ mCFreq[c]++;
+ if (c >= (1U << UINT8_BIT)) {
+ mBuf[CPos] |= mOutputMask;
+ mBuf[mOutputPos++] = (UINT8)(p >> UINT8_BIT);
+ mBuf[mOutputPos++] = (UINT8) p;
+ c = 0;
+ while (p) {
+ p >>= 1;
+ c++;
+ }
+ mPFreq[c]++;
+ }
+}
+
+STATIC
+VOID
+HufEncodeStart ()
+{
+ INT32 i;
+
+ for (i = 0; i < NC; i++) {
+ mCFreq[i] = 0;
+ }
+ for (i = 0; i < NP; i++) {
+ mPFreq[i] = 0;
+ }
+ mOutputPos = mOutputMask = 0;
+ InitPutBits();
+ return;
+}
+
+STATIC
+VOID
+HufEncodeEnd ()
+{
+ SendBlock();
+
+ //
+ // Flush remaining bits
+ //
+ PutBits(UINT8_BIT - 1, 0);
+
+ return;
+}
+
+
+STATIC
+VOID
+MakeCrcTable ()
+{
+ UINT32 i, j, r;
+
+ for (i = 0; i <= UINT8_MAX; i++) {
+ r = i;
+ for (j = 0; j < UINT8_BIT; j++) {
+ if (r & 1) {
+ r = (r >> 1) ^ CRCPOLY;
+ } else {
+ r >>= 1;
+ }
+ }
+ mCrcTable[i] = (UINT16)r;
+ }
+}
+
+STATIC
+VOID
+PutBits (
+ IN INT32 n,
+ IN UINT32 x
+ )
+/*++
+
+Routine Description:
+
+ Outputs rightmost n bits of x
+
+Arguments:
+
+ n - the rightmost n bits of the data is used
+ x - the data
+
+Returns: (VOID)
+
+--*/
+{
+ UINT8 Temp;
+
+ if (n < mBitCount) {
+ mSubBitBuf |= x << (mBitCount -= n);
+ } else {
+
+ Temp = (UINT8)(mSubBitBuf | (x >> (n -= mBitCount)));
+ if (mDst < mDstUpperLimit) {
+ *mDst++ = Temp;
+ }
+ mCompSize++;
+
+ if (n < UINT8_BIT) {
+ mSubBitBuf = x << (mBitCount = UINT8_BIT - n);
+ } else {
+
+ Temp = (UINT8)(x >> (n - UINT8_BIT));
+ if (mDst < mDstUpperLimit) {
+ *mDst++ = Temp;
+ }
+ mCompSize++;
+
+ mSubBitBuf = x << (mBitCount = 2 * UINT8_BIT - n);
+ }
+ }
+}
+
+STATIC
+INT32
+FreadCrc (
+ OUT UINT8 *p,
+ IN INT32 n
+ )
+/*++
+
+Routine Description:
+
+ Read in source data
+
+Arguments:
+
+ p - the buffer to hold the data
+ n - number of bytes to read
+
+Returns:
+
+ number of bytes actually read
+
+--*/
+{
+ INT32 i;
+
+ for (i = 0; mSrc < mSrcUpperLimit && i < n; i++) {
+ *p++ = *mSrc++;
+ }
+ n = i;
+
+ p -= n;
+ mOrigSize += n;
+ while (--i >= 0) {
+ UPDATE_CRC(*p++);
+ }
+ return n;
+}
+
+
+STATIC
+VOID
+InitPutBits ()
+{
+ mBitCount = UINT8_BIT;
+ mSubBitBuf = 0;
+}
+
+STATIC
+VOID
+CountLen (
+ IN INT32 i
+ )
+/*++
+
+Routine Description:
+
+ Count the number of each code length for a Huffman tree.
+
+Arguments:
+
+ i - the top node
+
+Returns: (VOID)
+
+--*/
+{
+ STATIC INT32 Depth = 0;
+
+ if (i < mN) {
+ mLenCnt[(Depth < 16) ? Depth : 16]++;
+ } else {
+ Depth++;
+ CountLen(mLeft [i]);
+ CountLen(mRight[i]);
+ Depth--;
+ }
+}
+
+STATIC
+VOID
+MakeLen (
+ IN INT32 Root
+ )
+/*++
+
+Routine Description:
+
+ Create code length array for a Huffman tree
+
+Arguments:
+
+ Root - the root of the tree
+
+--*/
+{
+ INT32 i, k;
+ UINT32 Cum;
+
+ for (i = 0; i <= 16; i++) {
+ mLenCnt[i] = 0;
+ }
+ CountLen(Root);
+
+ //
+ // Adjust the length count array so that
+ // no code will be generated longer than its designated length
+ //
+
+ Cum = 0;
+ for (i = 16; i > 0; i--) {
+ Cum += mLenCnt[i] << (16 - i);
+ }
+ while (Cum != (1U << 16)) {
+ mLenCnt[16]--;
+ for (i = 15; i > 0; i--) {
+ if (mLenCnt[i] != 0) {
+ mLenCnt[i]--;
+ mLenCnt[i+1] += 2;
+ break;
+ }
+ }
+ Cum--;
+ }
+ for (i = 16; i > 0; i--) {
+ k = mLenCnt[i];
+ while (--k >= 0) {
+ mLen[*mSortPtr++] = (UINT8)i;
+ }
+ }
+}
+
+STATIC
+VOID
+DownHeap (
+ IN INT32 i
+ )
+{
+ INT32 j, k;
+
+ //
+ // priority queue: send i-th entry down heap
+ //
+
+ k = mHeap[i];
+ while ((j = 2 * i) <= mHeapSize) {
+ if (j < mHeapSize && mFreq[mHeap[j]] > mFreq[mHeap[j + 1]]) {
+ j++;
+ }
+ if (mFreq[k] <= mFreq[mHeap[j]]) {
+ break;
+ }
+ mHeap[i] = mHeap[j];
+ i = j;
+ }
+ mHeap[i] = (INT16)k;
+}
+
+STATIC
+VOID
+MakeCode (
+ IN INT32 n,
+ IN UINT8 Len[],
+ OUT UINT16 Code[]
+ )
+/*++
+
+Routine Description:
+
+ Assign code to each symbol based on the code length array
+
+Arguments:
+
+ n - number of symbols
+ Len - the code length array
+ Code - stores codes for each symbol
+
+Returns: (VOID)
+
+--*/
+{
+ INT32 i;
+ UINT16 Start[18];
+
+ Start[1] = 0;
+ for (i = 1; i <= 16; i++) {
+ Start[i + 1] = (UINT16)((Start[i] + mLenCnt[i]) << 1);
+ }
+ for (i = 0; i < n; i++) {
+ Code[i] = Start[Len[i]]++;
+ }
+}
+
+STATIC
+INT32
+MakeTree (
+ IN INT32 NParm,
+ IN UINT16 FreqParm[],
+ OUT UINT8 LenParm[],
+ OUT UINT16 CodeParm[]
+ )
+/*++
+
+Routine Description:
+
+ Generates Huffman codes given a frequency distribution of symbols
+
+Arguments:
+
+ NParm - number of symbols
+ FreqParm - frequency of each symbol
+ LenParm - code length for each symbol
+ CodeParm - code for each symbol
+
+Returns:
+
+ Root of the Huffman tree.
+
+--*/
+{
+ INT32 i, j, k, Avail;
+
+ //
+ // make tree, calculate len[], return root
+ //
+
+ mN = NParm;
+ mFreq = FreqParm;
+ mLen = LenParm;
+ Avail = mN;
+ mHeapSize = 0;
+ mHeap[1] = 0;
+ for (i = 0; i < mN; i++) {
+ mLen[i] = 0;
+ if (mFreq[i]) {
+ mHeap[++mHeapSize] = (INT16)i;
+ }
+ }
+ if (mHeapSize < 2) {
+ CodeParm[mHeap[1]] = 0;
+ return mHeap[1];
+ }
+ for (i = mHeapSize / 2; i >= 1; i--) {
+
+ //
+ // make priority queue
+ //
+ DownHeap(i);
+ }
+ mSortPtr = CodeParm;
+ do {
+ i = mHeap[1];
+ if (i < mN) {
+ *mSortPtr++ = (UINT16)i;
+ }
+ mHeap[1] = mHeap[mHeapSize--];
+ DownHeap(1);
+ j = mHeap[1];
+ if (j < mN) {
+ *mSortPtr++ = (UINT16)j;
+ }
+ k = Avail++;
+ mFreq[k] = (UINT16)(mFreq[i] + mFreq[j]);
+ mHeap[1] = (INT16)k;
+ DownHeap(1);
+ mLeft[k] = (UINT16)i;
+ mRight[k] = (UINT16)j;
+ } while (mHeapSize > 1);
+
+ mSortPtr = CodeParm;
+ MakeLen(k);
+ MakeCode(NParm, LenParm, CodeParm);
+
+ //
+ // return root
+ //
+ return k;
+}
+
diff --git a/src/util/efirom.c b/src/util/efirom.c
index 8fa15ca90..95feaf239 100644
--- a/src/util/efirom.c
+++ b/src/util/efirom.c
@@ -34,10 +34,17 @@
#define eprintf(...) fprintf ( stderr, __VA_ARGS__ )
+/* Round up ROM size */
+#define ROM_SIZE( len ) ( ( (len) + 511 ) & ~511 )
+
+/* Include the EDK2 compression code */
+#include "eficompress.c"
+
/** Command-line options */
struct options {
uint16_t vendor;
uint16_t device;
+ int compress;
};
/**
@@ -95,6 +102,35 @@ static void read_pe_info ( void *pe, uint16_t *machine,
}
/**
+ * Attempt to compress EFI data in-place
+ *
+ * @v data Data to be compressed
+ * @v max_len Length of data
+ * @ret len Length after attempted compression
+ */
+static size_t efi_compress ( void *data, size_t max_len ) {
+ void *tmp;
+ UINT32 len;
+
+ /* Allocate temporary buffer for compressed data */
+ tmp = xmalloc ( max_len );
+
+ /* Attempt compression */
+ len = max_len;
+ if ( ( EfiCompress ( data, max_len, tmp, &len ) == 0 ) &&
+ ( len < max_len ) ) {
+ memcpy ( data, tmp, len );
+ } else {
+ len = max_len;
+ }
+
+ /* Free temporary buffer */
+ free ( tmp );
+
+ return len;
+}
+
+/**
* Convert EFI image to ROM image
*
* @v pe EFI file
@@ -109,10 +145,14 @@ static void make_efi_rom ( FILE *pe, FILE *rom, struct options *opts ) {
struct stat pe_stat;
size_t pe_size;
size_t rom_size;
+ size_t compressed_size;
void *buf;
void *payload;
unsigned int i;
+ uint16_t machine;
+ uint16_t subsystem;
uint8_t checksum;
+ int compressed;
/* Determine PE file size */
if ( fstat ( fileno ( pe ), &pe_stat ) != 0 ) {
@@ -123,7 +163,7 @@ static void make_efi_rom ( FILE *pe, FILE *rom, struct options *opts ) {
pe_size = pe_stat.st_size;
/* Determine ROM file size */
- rom_size = ( ( pe_size + sizeof ( *headers ) + 511 ) & ~511 );
+ rom_size = ROM_SIZE ( sizeof ( *headers ) + pe_size );
/* Allocate ROM buffer and read in PE file */
buf = xmalloc ( rom_size );
@@ -136,12 +176,26 @@ static void make_efi_rom ( FILE *pe, FILE *rom, struct options *opts ) {
exit ( 1 );
}
+ /* Parse PE headers */
+ read_pe_info ( payload, &machine, &subsystem );
+
+ /* Compress the image, if requested */
+ if ( opts->compress ) {
+ compressed_size = efi_compress ( payload, pe_size );
+ rom_size = ROM_SIZE ( sizeof ( *headers ) + compressed_size );
+ compressed = ( compressed_size < pe_size );
+ } else {
+ compressed = 0;
+ }
+
/* Construct ROM header */
headers->rom.Signature = PCI_EXPANSION_ROM_HEADER_SIGNATURE;
headers->rom.InitializationSize = ( rom_size / 512 );
headers->rom.EfiSignature = EFI_PCI_EXPANSION_ROM_HEADER_EFISIGNATURE;
- read_pe_info ( payload, &headers->rom.EfiMachineType,
- &headers->rom.EfiSubsystem );
+ headers->rom.EfiSubsystem = subsystem;
+ headers->rom.EfiMachineType = machine;
+ headers->rom.CompressionType =
+ ( compressed ? EFI_PCI_EXPANSION_ROM_HEADER_COMPRESSED : 0 );
headers->rom.EfiImageHeaderOffset = sizeof ( *headers );
headers->rom.PcirOffset =
offsetof ( typeof ( *headers ), pci );
@@ -194,11 +248,12 @@ static int parse_options ( const int argc, char **argv,
static struct option long_options[] = {
{ "vendor", required_argument, NULL, 'v' },
{ "device", required_argument, NULL, 'd' },
+ { "compress", 0, NULL, 'c' },
{ "help", 0, NULL, 'h' },
{ 0, 0, 0, 0 }
};
- if ( ( c = getopt_long ( argc, argv, "v:d:h",
+ if ( ( c = getopt_long ( argc, argv, "v:d:ch",
long_options,
&option_index ) ) == -1 ) {
break;
@@ -219,6 +274,9 @@ static int parse_options ( const int argc, char **argv,
exit ( 2 );
}
break;
+ case 'c':
+ opts->compress = 1;
+ break;
case 'h':
print_help ( argv[0] );
exit ( 0 );
diff --git a/src/util/elf2efi.c b/src/util/elf2efi.c
index 4f517d7d2..38eb29964 100644
--- a/src/util/elf2efi.c
+++ b/src/util/elf2efi.c
@@ -38,6 +38,9 @@
#define eprintf(...) fprintf ( stderr, __VA_ARGS__ )
+#undef ELF_R_TYPE
+#undef ELF_R_SYM
+
#ifdef EFI_TARGET32
#define EFI_IMAGE_NT_HEADERS EFI_IMAGE_NT_HEADERS32
@@ -72,21 +75,46 @@
#define ELF_MREL( mach, type ) ( (mach) | ( (type) << 16 ) )
-/* Allow for building with older versions of elf.h */
+/* Provide constants missing on some platforms */
#ifndef EM_AARCH64
#define EM_AARCH64 183
+#endif
+#ifndef R_AARCH64_NONE
#define R_AARCH64_NONE 0
+#endif
+#ifndef R_AARCH64_NULL
+#define R_AARCH64_NULL 256
+#endif
+#ifndef R_AARCH64_ABS64
#define R_AARCH64_ABS64 257
+#endif
+#ifndef R_AARCH64_CALL26
#define R_AARCH64_CALL26 283
+#endif
+#ifndef R_AARCH64_JUMP26
#define R_AARCH64_JUMP26 282
+#endif
+#ifndef R_AARCH64_ADR_PREL_LO21
#define R_AARCH64_ADR_PREL_LO21 274
+#endif
+#ifndef R_AARCH64_ADR_PREL_PG_HI21
#define R_AARCH64_ADR_PREL_PG_HI21 275
+#endif
+#ifndef R_AARCH64_ADD_ABS_LO12_NC
#define R_AARCH64_ADD_ABS_LO12_NC 277
+#endif
+#ifndef R_AARCH64_LDST8_ABS_LO12_NC
#define R_AARCH64_LDST8_ABS_LO12_NC 278
+#endif
+#ifndef R_AARCH64_LDST16_ABS_LO12_NC
#define R_AARCH64_LDST16_ABS_LO12_NC 284
+#endif
+#ifndef R_AARCH64_LDST32_ABS_LO12_NC
#define R_AARCH64_LDST32_ABS_LO12_NC 285
+#endif
+#ifndef R_AARCH64_LDST64_ABS_LO12_NC
#define R_AARCH64_LDST64_ABS_LO12_NC 286
-#endif /* EM_AARCH64 */
+#endif
#ifndef R_ARM_CALL
#define R_ARM_CALL 28
#endif
@@ -97,11 +125,6 @@
#define R_ARM_V4BX 40
#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 {
diff --git a/src/util/genefidsk b/src/util/genefidsk
deleted file mode 100755
index 7064f99b6..000000000
--- a/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/src/util/genfsimg b/src/util/genfsimg
new file mode 100755
index 000000000..c3123f3ed
--- /dev/null
+++ b/src/util/genfsimg
@@ -0,0 +1,306 @@
+#!/bin/sh
+#
+# Generate a filesystem-based image
+
+set -e
+set -u
+
+# Print usage message
+#
+help() {
+ echo "usage: ${0} [OPTIONS] foo.lkrn|foo.efi [bar.lkrn|bar.efi,...]"
+ echo
+ echo "where OPTIONS are:"
+ echo " -h show this help"
+ echo " -o FILE save image to file"
+ echo " -p PAD pad filesystem (in kB)"
+ echo " -s SCRIPT use executable script"
+}
+
+# Get hex byte from binary file
+#
+get_byte() {
+ local FILENAME
+ local OFFSET
+
+ FILENAME="${1}"
+ OFFSET="${2}"
+
+ od -j "${OFFSET}" -N 1 -A n -t x1 -- "${FILENAME}" | tr -d " "
+}
+
+# Get hex word from binary file
+#
+get_word() {
+ local FILENAME
+ local OFFSET
+
+ FILENAME="${1}"
+ OFFSET="${2}"
+
+ od -j "${OFFSET}" -N 2 -A n -t x1 -- "${FILENAME}" | tr -d " "
+}
+
+# Get appropriate EFI boot filename for CPU architecture
+#
+efi_boot_name() {
+ local FILENAME
+ local PESIG
+ local ARCH
+
+ FILENAME="${1}"
+
+ MZSIG=$(get_word "${FILENAME}" 0)
+ if [ "${MZSIG}" != "4d5a" ] ; then
+ echo "${FILENAME}: invalid MZ header" >&2
+ exit 1
+ fi
+ PEOFF=$(get_byte "${FILENAME}" 0x3c)
+ PESIG=$(get_word "${FILENAME}" 0x${PEOFF})
+ if [ "${PESIG}" != "5045" ] ; then
+ echo "${FILENAME}: invalid PE header" >&2
+ exit 1
+ fi
+ ARCH=$(get_word "${FILENAME}" $(( 0x${PEOFF} + 4 )) )
+ case "${ARCH}" in
+ "4c01" )
+ echo "BOOTIA32.EFI"
+ ;;
+ "6486" )
+ echo "BOOTX64.EFI"
+ ;;
+ "c201" )
+ echo "BOOTARM.EFI"
+ ;;
+ "64aa" )
+ echo "BOOTAA64.EFI"
+ ;;
+ * )
+ echo "${FILENAME}: unrecognised EFI architecture ${ARCH}" >&2
+ exit 1
+ esac
+}
+
+# Copy syslinux file
+#
+copy_syslinux_file() {
+ local FILENAME
+ local DESTDIR
+ local SRCDIR
+
+ FILENAME="${1}"
+ DESTDIR="${2}"
+
+ for SRCDIR in \
+ /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/bios/core \
+ /usr/local/share/syslinux/bios/com32/elflink/ldlinux \
+ /usr/local/share/syslinux/modules/bios \
+ /usr/lib/ISOLINUX \
+ ; do
+ if [ -e "${SRCDIR}/${FILENAME}" ] ; then
+ install -m 644 "${SRCDIR}/${FILENAME}" "${DESTDIR}/"
+ return 0
+ fi
+ done
+ echo "${0}: could not find ${FILENAME}" >&2
+ return 1
+}
+
+# Parse command-line options
+#
+OUTFILE=
+PAD=0
+SCRIPT=
+while getopts "hlo:p:s:" OPTION ; do
+ case "${OPTION}" in
+ h)
+ help
+ exit 0
+ ;;
+ o)
+ OUTFILE="${OPTARG}"
+ ;;
+ p)
+ PAD="${OPTARG}"
+ ;;
+ s)
+ SCRIPT="${OPTARG}"
+ ;;
+ *)
+ help
+ exit 1
+ ;;
+ esac
+done
+if [ -z "${OUTFILE}" ]; then
+ echo "${0}: no output file given" >&2
+ help
+ exit 1
+fi
+shift $(( OPTIND - 1 ))
+if [ $# -eq 0 ] ; then
+ echo "${0}: no input files given" >&2
+ help
+ exit 1
+fi
+
+# Create temporary working directory
+#
+WORKDIR=$(mktemp -d "${OUTFILE}.XXXXXX")
+ISODIR="${WORKDIR}/iso"
+FATDIR="${WORKDIR}/fat"
+mkdir -p "${ISODIR}" "${FATDIR}"
+
+# Configure output
+#
+case "${OUTFILE}" in
+ *.iso)
+ ISOIMG="${OUTFILE}"
+ FATIMG="${ISODIR}/esp.img"
+ BIOSDIR="${ISODIR}"
+ SYSLINUXCFG="${ISODIR}/isolinux.cfg"
+ ;;
+ *)
+ ISOIMG=
+ FATIMG="${OUTFILE}"
+ BIOSDIR="${FATDIR}"
+ SYSLINUXCFG="${FATDIR}/syslinux.cfg"
+ ;;
+esac
+
+# Copy files to temporary working directory
+#
+LKRN=
+EFI=
+for FILENAME ; do
+ case "${FILENAME}" in
+ *.lkrn)
+ DESTDIR="${BIOSDIR}"
+ DESTFILE=$(basename "${FILENAME}")
+ if [ -z "${LKRN}" ] ; then
+ echo "SAY iPXE boot image" > "${SYSLINUXCFG}"
+ echo "TIMEOUT 30" >> "${SYSLINUXCFG}"
+ echo "DEFAULT ${DESTFILE}" >> "${SYSLINUXCFG}"
+ if [ -n "${SCRIPT}" ] ; then
+ cp "${SCRIPT}" "${BIOSDIR}/autoexec.ipxe"
+ fi
+ fi
+ echo "LABEL ${DESTFILE}" >> "${SYSLINUXCFG}"
+ echo " KERNEL ${DESTFILE}" >> "${SYSLINUXCFG}"
+ if [ -n "${SCRIPT}" ] ; then
+ echo " APPEND initrd=autoexec.ipxe" >> "${SYSLINUXCFG}"
+ fi
+ LKRN=1
+ ;;
+ *.efi)
+ DESTDIR="${FATDIR}/EFI/BOOT"
+ DESTFILE=$(efi_boot_name "${FILENAME}")
+ if [ -z "${EFI}" ] ; then
+ mkdir -p "${DESTDIR}"
+ if [ -n "${SCRIPT}" ] ; then
+ cp "${SCRIPT}" "${FATDIR}/autoexec.ipxe"
+ fi
+ fi
+ EFI=1
+ ;;
+ *)
+ echo "${0}: unrecognised input filename ${FILENAME}" >&2
+ help
+ exit 1
+ ;;
+ esac
+ if [ -e "${DESTDIR}/${DESTFILE}" ] ; then
+ echo "${0}: duplicate ${DESTFILE} from ${FILENAME}" >&2
+ exit 1
+ fi
+ cp "${FILENAME}" "${DESTDIR}/${DESTFILE}"
+done
+
+# Configure ISO image, if applicable
+#
+# Note that the BIOS boot files are required even for an EFI-only ISO,
+# since isohybrid will refuse to work without them.
+#
+if [ -n "${ISOIMG}" ] ; then
+ ISOARGS="-J -R"
+ copy_syslinux_file "isolinux.bin" "${ISODIR}"
+ copy_syslinux_file "ldlinux.c32" "${ISODIR}" 2>/dev/null || true
+ ISOARGS="${ISOARGS} -no-emul-boot -eltorito-boot isolinux.bin"
+ ISOARGS="${ISOARGS} -boot-load-size 4 -boot-info-table"
+ if [ -n "${EFI}" ] ; then
+ ISOARGS="${ISOARGS} -eltorito-alt-boot -no-emul-boot -e esp.img"
+ else
+ FATIMG=
+ fi
+fi
+
+# Create FAT filesystem image, if applicable
+#
+if [ -n "${FATIMG}" ] ; then
+ FATSIZE=$(du -s -k ${FATDIR} | cut -f1)
+ FATSIZE=$(( FATSIZE + PAD + 256 ))
+ touch "${FATIMG}"
+ if [ "${FATSIZE}" -le "1440" ] ; then
+ FATSIZE=1440
+ FATARGS="-f 1440"
+ else
+ FATCYLS=$(( ( FATSIZE + 503 ) / 504 ))
+ FATSIZE=$(( FATCYLS * 504 ))
+ FATARGS="-s 63 -h 16 -t ${FATCYLS}"
+ fi
+ truncate -s "${FATSIZE}K" "${FATIMG}"
+ mformat -v iPXE -i "${FATIMG}" ${FATARGS} ::
+ mcopy -i "${FATIMG}" -s "${FATDIR}"/* ::
+ if [ "${BIOSDIR}" = "${FATDIR}" ] ; then
+ syslinux "${FATIMG}"
+ fi
+fi
+
+# Create ISO filesystem image, if applicable
+#
+if [ -n "${ISOIMG}" ] ; then
+ MKISOFS=
+ MKISOFS_MISSING=
+ MKISOFS_NOTSUP=
+ for CMD in genisoimage mkisofs xorrisofs ; do
+ if ! "${CMD}" --version >/dev/null 2>&1 ; then
+ MKISOFS_MISSING="${MKISOFS_MISSING} ${CMD}"
+ continue
+ fi
+ if ! "${CMD}" ${ISOARGS} --version "${ISODIR}" >/dev/null 2>&1 ; then
+ MKISOFS_NOTSUP="${MKISOFS_NOTSUP} ${CMD}"
+ continue
+ fi
+ MKISOFS="${CMD}"
+ break
+ done
+ if [ -z "${MKISOFS}" ] ; then
+ if [ -n "${MKISOFS_MISSING}" ] ; then
+ echo "${0}:${MKISOFS_MISSING}: not installed" >&2
+ fi
+ if [ -n "${MKISOFS_NOTSUP}" ] ; then
+ echo "${0}:${MKISOFS_NOTSUP}: cannot handle ${ISOARGS}" >&2
+ fi
+ echo "${0}: cannot find a suitable mkisofs or equivalent" >&2
+ exit 1
+ fi
+ "${MKISOFS}" -quiet -volid "iPXE" -preparer "iPXE build system" \
+ -appid "iPXE - Open Source Network Boot Firmware" \
+ -publisher "ipxe.org" -sysid "iPXE" -o "${ISOIMG}" \
+ ${ISOARGS} "${ISODIR}"
+ if isohybrid --version >/dev/null 2>&1 ; then
+ isohybrid "${ISOIMG}"
+ fi
+fi
+
+# Clean up temporary working directory
+#
+rm -rf "${WORKDIR}"
diff --git a/src/util/geniso b/src/util/geniso
deleted file mode 100755
index ff090d4a0..000000000
--- a/src/util/geniso
+++ /dev/null
@@ -1,141 +0,0 @@
-#!/bin/bash
-#
-# Generate a isolinux ISO boot image
-
-function help() {
- echo "usage: ${0} [OPTIONS] foo.lkrn [bar.lkrn,...]"
- echo
- echo "where OPTIONS are:"
- echo " -h show this help"
- echo " -l build legacy image with floppy emulation"
- echo " -o FILE save iso image to file"
-}
-
-LEGACY=0
-FIRST=""
-
-while getopts "hlo:" opt; do
- case ${opt} in
- h)
- help
- exit 0
- ;;
- l)
- LEGACY=1
- ;;
- o)
- OUT="${OPTARG}"
- ;;
- esac
-done
-
-shift $((OPTIND - 1))
-
-if [ -z "${OUT}" ]; then
- echo "${0}: no output file given" >&2
- help
- exit 1
-fi
-
-# There should either be mkisofs or the compatible genisoimage program
-for command in genisoimage mkisofs; do
- if ${command} --version >/dev/null 2>/dev/null; then
- mkisofs=(${command})
- break
- fi
-done
-
-if [ -z "${mkisofs}" ]; then
- echo "${0}: mkisofs or genisoimage not found, please install or set PATH" >&2
- exit 1
-fi
-
-dir=$(mktemp -d bin/iso.dir.XXXXXX)
-cfg=${dir}/isolinux.cfg
-
-mkisofs+=(-quiet -l -volid "iPXE" -preparer "iPXE build system"
- -appid "iPXE ${VERSION} - Open Source Network Boot Firmware"
- -publisher "http://ipxe.org/" -c boot.cat)
-
-# generate the config
-cat > ${cfg} <<EOF
-# These default options can be changed in the geniso script
-SAY iPXE ISO boot image
-TIMEOUT 30
-EOF
-for f; do
- if [ ! -r ${f} ]; then
- echo "${f} does not exist, skipping" >&2
- continue
- fi
- b=$(basename ${f})
- g=${b%.lkrn}
- g=${g//[^a-z0-9]}
- g=${g:0:8}.krn
- case "${FIRST}" in
- "")
- echo "DEFAULT ${b}"
- FIRST=${g}
- ;;
- esac
- echo "LABEL ${b}"
- echo " KERNEL ${g}"
- cp ${f} ${dir}/${g}
-done >> ${cfg}
-
-case "${LEGACY}" in
- 1)
- # check for mtools
- case "$(mtools -V)" in
- Mtools\ version\ 3.9.9*|Mtools\ version\ 3.9.1[0-9]*|[mM]tools\ *\ [4-9].*)
- ;;
- *)
- echo "Mtools version 3.9.9 or later is required" >&2
- exit 1
- ;;
- esac
-
- # generate floppy image
- img=${dir}/boot.img
- mformat -f 1440 -C -i ${img} ::
-
- # copy lkrn file to floppy image
- for f in ${dir}/*.krn; do
- mcopy -m -i ${img} ${f} ::$(basename ${g})
- rm -f ${f}
- done
-
- # copy config file to floppy image
- mcopy -i ${img} ${cfg} ::syslinux.cfg
- rm -f ${cfg}
-
- # write syslinux bootloader to floppy image
- if ! syslinux ${img}; then
- echo "${0}: failed writing syslinux to floppy image ${img}" >&2
- exit 1
- fi
-
- # generate the iso image
- "${mkisofs[@]}" -b boot.img -output ${OUT} ${dir}
- ;;
- 0)
- # copy isolinux bootloader
- cp ${ISOLINUX_BIN} ${dir}
-
- # syslinux 6.x needs a file called ldlinux.c32
- if [ -n "${LDLINUX_C32}" -a -s "${LDLINUX_C32}" ]; then
- cp ${LDLINUX_C32} ${dir}
- fi
-
- # generate the iso image
- "${mkisofs[@]}" -b isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table -output ${OUT} ${dir}
-
- # isohybrid will be used if available
- if isohybrid --version >/dev/null 2>/dev/null; then
- isohybrid ${OUT} >/dev/null
- fi
- ;;
-esac
-
-# clean up temporary dir
-rm -fr ${dir}
diff --git a/src/util/gensdsk b/src/util/gensdsk
deleted file mode 100755
index fe302d587..000000000
--- a/src/util/gensdsk
+++ /dev/null
@@ -1,65 +0,0 @@
-#!/bin/bash
-#
-# Generate a syslinux floppy that loads a iPXE image
-#
-# gensdsk foo.sdsk foo.lkrn
-#
-# the floppy image is the first argument
-# followed by list of .lkrn images
-#
-
-case $# in
-0|1)
- echo Usage: $0 foo.sdsk foo.lkrn ...
- exit 1
- ;;
-esac
-case "`mtools -V`" in
-Mtools\ version\ 3.9.9*|Mtools\ version\ 3.9.1[0-9]*|[mM]tools\ *\ [4-9].*)
- ;;
-*)
- echo Mtools version 3.9.9 or later is required
- exit 1
- ;;
-esac
-img=$1
-shift
-dir=`mktemp -d bin/sdsk.dir.XXXXXX`
-
-mformat -f 1440 -C -i $img ::
-cfg=$dir/syslinux.cfg
-cat > $cfg <<EOF
-
-# These default options can be changed in the gensdsk script
-TIMEOUT 30
-EOF
-first=
-for f
-do
- if [ ! -r $f ]
- then
- echo $f does not exist, skipping 1>&2
- continue
- fi
- # shorten name for 8.3 filesystem
- b=$(basename $f)
- g=${b%.lkrn}
- g=${g//[^a-z0-9]}
- g=${g:0:8}.krn
- case "$first" in
- "")
- echo DEFAULT $b
- ;;
- esac
- first=$g
- echo LABEL $b
- echo "" KERNEL $g
- mcopy -m -i $img $f ::$g
-done >> $cfg
-mcopy -i $img $cfg ::syslinux.cfg
-if ! syslinux $img
-then
- exit 1
-fi
-
-rm -fr $dir
diff --git a/src/util/iccfix.c b/src/util/iccfix.c
deleted file mode 100644
index 528bf4b26..000000000
--- a/src/util/iccfix.c
+++ /dev/null
@@ -1,157 +0,0 @@
-#include <stdint.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/mman.h>
-#include <elf.h>
-#include <ipxe/tables.h>
-
-#define DEBUG 0
-
-#define eprintf(...) fprintf ( stderr, __VA_ARGS__ )
-
-#define dprintf(...) do { \
- if ( DEBUG ) \
- fprintf ( stderr, __VA_ARGS__ ); \
- } while ( 0 )
-
-#ifdef SELF_INCLUDED
-
-/**
- * Fix up ICC alignments
- *
- * @v elf ELF header
- * @ret rc Return status code
- *
- * See comments in tables.h for an explanation of why this monstrosity
- * is necessary.
- */
-static int ICCFIX ( void *elf ) {
- ELF_EHDR *ehdr = elf;
- ELF_SHDR *shdr = ( elf + ehdr->e_shoff );
- size_t shentsize = ehdr->e_shentsize;
- unsigned int shnum = ehdr->e_shnum;
- ELF_SHDR *strtab = ( ( ( void * ) shdr ) +
- ( ehdr->e_shstrndx * shentsize ) );
- char *strings = ( elf + strtab->sh_offset );
-
- for ( ; shnum-- ; shdr = ( ( ( void * ) shdr ) + shentsize ) ) {
- char *name = ( strings + shdr->sh_name );
- unsigned long align = shdr->sh_addralign;
- unsigned long new_align;
-
- if ( ( strncmp ( name, ".tbl.", 5 ) == 0 ) &&
- ( align >= ICC_ALIGN_HACK_FACTOR ) ) {
- new_align = ( align / ICC_ALIGN_HACK_FACTOR );
- shdr->sh_addralign = new_align;
- dprintf ( "Section \"%s\": alignment %ld->%ld\n",
- name, align, new_align );
- }
- }
- return 0;
-}
-
-#else /* SELF_INCLUDED */
-
-#define SELF_INCLUDED
-
-/* Include iccfix32() function */
-#define ELF_EHDR Elf32_Ehdr
-#define ELF_SHDR Elf32_Shdr
-#define ICCFIX iccfix32
-#include "iccfix.c"
-#undef ELF_EHDR
-#undef ELF_SHDR
-#undef ICCFIX
-
-/* Include iccfix64() function */
-#define ELF_EHDR Elf64_Ehdr
-#define ELF_SHDR Elf64_Shdr
-#define ICCFIX iccfix64
-#include "iccfix.c"
-#undef ELF_EHDR
-#undef ELF_SHDR
-#undef ICCFIX
-
-static int iccfix ( const char *filename ) {
- int fd;
- struct stat stat;
- void *elf;
- unsigned char *eident;
- int rc;
-
- /* Open and mmap file */
- fd = open ( filename, O_RDWR );
- if ( fd < 0 ) {
- eprintf ( "Could not open %s: %s\n",
- filename, strerror ( errno ) );
- rc = -1;
- goto err_open;
- }
- if ( fstat ( fd, &stat ) < 0 ) {
- eprintf ( "Could not determine size of %s: %s\n",
- filename, strerror ( errno ) );
- rc = -1;
- goto err_fstat;
- }
- elf = mmap ( NULL, stat.st_size, ( PROT_READ | PROT_WRITE ),
- MAP_SHARED, fd, 0 );
- if ( elf == MAP_FAILED ) {
- eprintf ( "Could not map %s: %s\n",
- filename, strerror ( errno ) );
- rc = -1;
- goto err_mmap;
- }
-
- /* Perform fixups */
- eident = elf;
- switch ( eident[EI_CLASS] ) {
- case ELFCLASS32:
- rc = iccfix32 ( elf );
- break;
- case ELFCLASS64:
- rc = iccfix64 ( elf );
- break;
- default:
- eprintf ( "Unknown ELF class %d in %s\n",
- eident[EI_CLASS], filename );
- rc = -1;
- break;
- }
-
- munmap ( elf, stat.st_size );
- err_mmap:
- err_fstat:
- close ( fd );
- err_open:
- return rc;
-}
-
-int main ( int argc, char **argv ) {
- int i;
- int rc;
-
- /* Parse command line */
- if ( argc < 2 ) {
- eprintf ( "Syntax: %s <object_file>...\n", argv[0] );
- exit ( 1 );
- }
-
- /* Process each object in turn */
- for ( i = 1 ; i < argc ; i++ ) {
- if ( ( rc = iccfix ( argv[i] ) ) != 0 ) {
- eprintf ( "Could not fix up %s\n", argv[i] );
- exit ( 1 );
- }
- }
-
- return 0;
-}
-
-#endif /* SELF_INCLUDED */