Commit Graph

38 Commits (32a9408217810498deeeae3d2564ab15468c9c39)

Author SHA1 Message Date
Michael Brown 32a9408217 [efi] Allow use of typed pointers for efi_open() et al
Provide wrapper macros to allow efi_open() and related functions to
accept a pointer to any pointer type as the "interface" argument, in
order to allow a substantial amount of type adjustment boilerplate to
be removed.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-03-24 15:43:56 +00:00
Michael Brown bac3187439 [efi] Use efi_open() for all ephemeral protocol opens
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-03-24 13:19:26 +00:00
Michael Brown b52b4a46d9 [efi] Allow for allocating EFI devices from arbitrary handles
Split out the code that allocates our internal struct efi_device
representations, to allow for the creation of temporary MNP devices in
order to download the autoexec.ipxe script.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2024-03-29 14:46:13 +00:00
Michael Brown da5188f3ea [efi] Allow for drivers to be located via child handles
When using a service binding protocol, CreateChild() will create a new
protocol instance (and optionally a new handle).  The caller will then
typically open this new protocol instance with BY_DRIVER attributes,
since the service binding mechanism has no equivalent of the driver
binding protocol's Stop() method, and there is therefore no other way
for the caller to be informed if the protocol instance is about to
become invalid (e.g. because the service driver wants to remove the
child).

The caller cannot ask CreateChild() to install the new protocol
instance on the original handle (i.e. the service binding handle),
since the whole point of the service binding protocol is to allow for
the existence of multiple children, and UEFI does not permit multiple
instances of the same protocol to be installed on a handle.

Our current drivers all open the original handle (as passed to our
driver binding's Start() method) with BY_DRIVER attributes, and so the
same handle will be passed to our Stop() method.  This changes when
our driver must use a separate handle, as described above.

Add an optional "child handle" field to struct efi_device (on the
assumption that we will not have any drivers that need to create
multiple children), and generalise efidev_find() to match on either
the original handle or the child handle.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2024-03-25 17:58:33 +00:00
Michael Brown e10a40d41f [efi] Avoid dropping below TPL as at entry to iPXE
iPXE will currently drop to TPL_APPLICATION whenever the current
system time is obtained via currticks(), since the system time
mechanism relies on a timer that can fire only when the TPL is below
TPL_CALLBACK.

This can cause unexpected behaviour if the system time is obtained in
the middle of an API call into iPXE by external code.  For example,
MnpDxe sets up a 10ms periodic timer running at TPL_CALLBACK to poll
the underling EFI_SIMPLE_NETWORK_PROTOCOL device for received packets.
If the resulting poll within iPXE happens to hit a code path that
requires obtaining the current system time (e.g. due to reception of
an STP packet, which affects iPXE's blocked link timer), then iPXE
will end up temporarily dropping to TPL_APPLICATION.  This can
potentially result in retriggering the MnpDxe periodic timer, causing
code to be unexpectedly re-entered.

Fix by recording the external TPL at any entry point into iPXE and
dropping only as far as this external TPL, rather than dropping
unconditionally to TPL_APPLICATION.

The side effect of this change is that iPXE's view of the current
system time will be frozen for the duration of any API calls made into
iPXE by external code at TPL_CALLBACK or above.  Since any such
external code is already responsible for allowing execution at
TPL_APPLICATION to occur, then this should not cause a problem in
practice.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2020-11-20 16:57:50 +00:00
Michael Brown 2bf0fd39ca [efi] Split device path functions out to efi_path.c
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2020-10-16 15:36:37 +01:00
Michael Brown c70b3e04e8 [efi] Always enable recursion when calling ConnectController()
There appears to be no reason for avoiding recursion when calling
ConnectController(), and recursion provides the least surprising
behaviour.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2020-10-02 00:36:33 +01:00
Michael Brown 9ee70fb95b [efi] Attempt to connect our driver directly if ConnectController fails
Some platforms (observed with an AMI BIOS on an Apollo Lake system)
will spuriously fail the call to ConnectController() when the UEFI
network stack is disabled.  This appears to be a BIOS bug that also
affects attempts to connect any non-iPXE driver to the NIC controller
handle via the UEFI shell "connect" utility.

Work around this BIOS bug by falling back to calling our
efi_driver_start() directly if the call to ConnectController() fails.
This bypasses any BIOS policy in terms of deciding which driver to
connect but still cooperates with the UEFI driver model in terms of
handle ownership, since the use of EFI_OPEN_PROTOCOL_BY_DRIVER ensures
that the BIOS is aware of our ownership claim.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2020-06-10 23:01:23 +01:00
Michael Brown bdf0e029ae [efi] Disambiguate errors returned by ConnectController
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2020-03-14 09:49:49 +00:00
Michael Brown a385e23768 [efi] Return only registered EFI devices from efidev_parent()
efidev_parent() currently assumes that any device with BUS_TYPE_EFI is
part of a struct efi_device.  This assumption is not valid, since the
code in efi_device_info() may also create a device with BUS_TYPE_EFI.

Fix by searching through the list of registered EFI devices when
looking for a match, instead of relying on the bus type value.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2019-07-15 12:49:47 +01:00
Michael Brown 4f362a032b [efi] Do not raise TPL within EFI_DRIVER_BINDING_PROTOCOL.Supported()
When booting some versions of the UEFI shell, our driver binding
protocol's Supported() entry point is called at TPL_NOTIFY for no
discernible reason.  Attempting to raise to TPL_CALLBACK triggers an
immediate assertion failure in the firmware.

Since our Supported() method can run at any TPL, fix by simply not
attempting to raise the TPL within this method.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2018-03-26 12:10:09 +01:00
Michael Brown 10d083ffa9 [efi] Raise TPL within EFI_DRIVER_BINDING_PROTOCOL entry points
Debugged-by: Rob Taglang <rob@privatemachines.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2018-03-14 23:55:28 +00:00
Michael Brown 74d90b33f8 [efi] Inhibit our driver Start() method during disconnection attempts
Some HP BIOSes (observed with a Z840) seem to attempt to connect our
drivers in the middle of our call to DisconnectController().  The
precise chain of events is unclear, but the symptom is that we see
several calls to our Supported() and Start() methods, followed by a
system lock-up.

Work around this dubious BIOS behaviour by explicitly failing calls to
our Start() method while we are in the middle of attempting to
disconnect drivers.

Reported-by: Jordan Wright <jordan.m.wright@disney.com>
Debugged-by: Adrian Lucrèce Céleste <adrianlucrececeleste@airmail.cc>
Debugged-by: Christian Nilsson <nikize@gmail.com>
Tested-by: Jordan Wright <jordan.m.wright@disney.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-09-22 18:39:04 +01:00
Michael Brown d46c53cfc6 [efi] Continue to connect remaining handles after connection errors
Some UEFI BIOSes will deliberately break the implementation of
ConnectController() to return errors for devices that have been
"disabled" via the BIOS setup screen.  (As an added bonus, such BIOSes
may return garbage EFI_STATUS values such as 0xff.)

Work around these broken UEFI BIOSes by ignoring failures and
continuing to attempt to connect any remaining handles.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-09-13 10:07:55 +03:00
Michael Brown 9ff6d08bf5 [efi] Avoid infinite loops when asked to stop non-existent devices
Calling EDK2's OpenProtocol() with attributes BY_DRIVER|EXCLUSIVE will
call DisconnectController() in a loop to attempt to dislodge any
existing openers with attributes BY_DRIVER.  The loop will continue
indefinitely until either no such openers remain, or until
DisconnectController() returns an error.

If our driver binding protocol's Stop() method is ever called to
disconnect a device that we are not in fact driving, then return
EFI_DEVICE_ERROR rather than EFI_SUCCESS, in order to break this
potentially infinite loop.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2015-09-28 03:20:59 +01:00
Michael Brown e727f576c2 [efi] Include a copy of the device path within struct efi_device
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2015-09-13 13:08:08 +01:00
Michael Brown 5cea7bdb2a [efi] Allow efidev_parent() to traverse multiple device generations
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2015-09-07 01:26:29 +01:00
Michael Brown 9501eaf68d [efi] Remove raw EFI_HANDLE values from debug messages
The raw EFI_HANDLE value is almost never useful to know, and simply
adds noise to the already verbose debug messages.  Improve the
legibility of debug messages by using only the name generated by
efi_handle_name().

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2015-08-27 15:40:44 +01:00
Michael Brown 2bf428c2a9 [efi] Move abstract device path and handle functions to efi_utils.c
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2014-08-06 14:27:45 +01:00
Michael Brown 7b3cc18462 [efi] Open device path protocol only at point of use
Some EFI 1.10 systems (observed on an Apple iMac) do not allow us to
open the device path protocol with an attribute of
EFI_OPEN_PROTOCOL_BY_DRIVER and so we cannot maintain a safe,
long-lived pointer to the device path.  Work around this by instead
opening the device path protocol with an attribute of
EFI_OPEN_PROTOCOL_GET_PROTOCOL whenever we need to use it.

Debugged-by: Curtis Larsen <larsen@dixie.edu>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2014-08-05 23:10:33 +01:00
Michael Brown 3b42ed477f [efi] Provide centralised definitions of commonly-used GUIDs
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2014-08-05 23:08:32 +01:00
Curtis Larsen 27e9ee147a [efi] Report errors from attempting to disconnect existing drivers
Modified-by: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2014-08-05 16:45:51 +01:00
Michael Brown 7023923db2 [efi] Dump handle information around connect/disconnect attempts
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2014-07-31 12:50:14 +01:00
Michael Brown 16d99cc8ef [efi] Dump existing openers when we are unable to open a protocol
Dump the existing openers of a protocol whenever we are unable to open
a protocol using attributes of BY_DEVICE, EXCLUSIVE, or
BY_CHILD_CONTROLLER.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2014-07-31 12:50:14 +01:00
Michael Brown 2e0821b9ed [efi] Use efi_handle_name() instead of efi_handle_devpath_text()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2014-07-31 11:56:44 +01:00
Michael Brown 057eb9e496 [efi] Report exact failure when unable to open the device path
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2014-07-30 17:53:51 +01:00
Michael Brown 608fb792eb [efi] Fix incorrect debug message level when device has no device path
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2014-07-30 17:15:39 +01:00
Michael Brown 56b2f66dd2 [efi] Attempt to start only drivers claiming support for a device
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2014-07-08 14:01:50 +01:00
Michael Brown c7051d826b [efi] Allow network devices to be created on top of arbitrary SNP devices
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2014-07-03 15:28:17 +01:00
Michael Brown 0e3ab6064e [efi] Restructure EFI driver model
Provide a single instance of EFI_DRIVER_BINDING_PROTOCOL (attached to
our image handle); this matches the expectations scattered throughout
the EFI specification.

Open the underlying hardware device using EFI_OPEN_PROTOCOL_BY_DRIVER
and EFI_OPEN_PROTOCOL_EXCLUSIVE, to prevent other drivers from
attaching to the same device.

Do not automatically connect to devices when being loaded as a driver;
leave this task to the platform firmware (or to the user, if loading
directly from the EFI shell).

When running as an application, forcibly disconnect any existing
drivers from devices that we want to control, and reconnect them on
exit.

Provide a meaningful driver version number (based on the build
timestamp), to allow platform firmware to automatically load newer
versions of iPXE drivers if multiple drivers are present.

Include device paths within debug messages where possible, to aid in
debugging.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2014-06-25 14:47:35 +01:00
Michael Brown 8290a95513 [build] Expose build timestamp, build name, and product names
Expose the build timestamp (measured in seconds since the Epoch) and
the build name (e.g. "rtl8139.rom" or "ipxe.efi"), and provide the
product name and product short name in a single centralised location.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2014-06-24 15:32:35 +01:00
Michael Brown 2602965806 [efi] Connect driver to devices as part of installation
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2014-03-12 15:34:44 +00:00
Michael Brown 8de6b973c4 [efi] Allow driver to be unloaded
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2014-03-10 16:39:46 +00:00
Michael Brown 54409583e2 [efi] Perform meaningful error code conversions
Exploit the redefinition of iPXE error codes to include a "platform
error code" to allow for meaningful conversion of EFI_STATUS values to
iPXE errors and vice versa.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2013-04-19 13:34:19 +01:00
Michael Brown 1a79f6f37a [efi] Delegate to child device's EFI_COMPONENT_NAME2_PROTOCOL, if present
EFI's device naming model requires drivers to provide names for child
devices.  Allow the driver's GetControllerName() method to delegate to
an instance of EFI_COMPONENT_NAME2_PROTOCOL installed on the child
device itself (if present); this allows the SNP device to expose its
own device name via the PCI driver's GetControllerName() method.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-11-21 03:26:45 +00:00
Michael Brown c3b4860ce3 [legal] Update FSF mailing address in GPL licence texts
Suggested-by: Daniel P. Berrange <berrange@redhat.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-07-20 19:55:45 +01:00
Michael Brown 870524a3b2 [efi] Add EFI string formatting functions
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-04-07 23:15:06 +01:00
Michael Brown d7736fbb7b [efi] Allow EFI to control PCI bus enumeration
EFI performs its own PCI bus enumeration.  Respect this, and start
controlling devices only when instructed to do so by EFI.

As a side benefit, we should now correctly create multiple SNP
instances for multi-port devices.

This should also fix the problem of failing to enumerate devices
because the PCI bridges have not yet been enabled at the time the iPXE
driver is loaded.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-02-17 02:56:55 +00:00