DDI_UFM(9E) | Driver Entry Points | DDI_UFM(9E) |
ddi_ufm
, ddi_ufm_op_nimages
,
ddi_ufm_op_fill_image
,
ddi_ufm_op_fill_slot
,
ddi_ufm_op_getcaps
—
#include
<sys/ddi_ufm.h>
int
ddi_ufm_op_getcaps
(ddi_ufm_handle_t
*uhp, void *drv_arg,
ddi_ufm_cap_t *caps);
int
ddi_ufm_op_nimages
(ddi_ufm_handle_t
*uhp, void *drv_arg, uint_t
*nimgp);
int
ddi_ufm_op_fill_image
(ddi_ufm_handle_t
*uhp, void *drv_arg, uint_t
imgid, ddi_ufm_image_t *uip);
int
ddi_ufm_op_fill_slot
(ddi_ufm_handle_t
*uhp, void *drv_arg, uint_t
imgid, uint_t slotid,
ddi_ufm_slot_t *usp);
The motherboard often has a UFM in the form of the BIOS or UEFI. The Lights out management controller on a system has a UFM, which is usually the entire system image. CPUs also have a UFM in the form of microcode.
An important property of a UFM is that it is a property of the device itself. For example, many WiFi device drivers are required to send a binary blob of firmware to the device after every reset. Because these images are not properties of the device and must be upgraded by either changing the device driver or related system files, we do not consider these UFMs.
There are also devices that have firmware which is a property of the device, but may not be upgradable from the running OS. This may be because the vendor doesn't have tooling to upgrade the image or because the firmware image itself cannot be upgraded in the field at all. For example, a YubiKey has a firmware image that's burned into it in the factory, but there is no way to change the firmware on it short of replacing the device in its entirety. However, because these images are a permanent part of the device, we also consider them a UFM.
A given image may have a number of slots. A slot represents a particular version of the image. Only one slot can be active at a given time. Devices support slots such that a firmware image can be downloaded to the device without impacting the current device if it fails half-way through. The slot that's currently in use is referred to as the active slot.
The various entry points are designed such that all a driver has to do is provide information about the image and its slots to the kernel, it does not have to wrangle with how that is marshalled to users and the appearance of those structures.
Once the driver has finished initializing, it must call ddi_ufm_update(9F) to indicate that the driver is in a state where it's ready to receive calls to the entry points.
The various UFM entry points may be called from an arbitrary kernel context. However, they will only ever be called from a single thread at a given time.
typedef struct ddi_ufm_ops { int (*ddi_ufm_op_nimages)(ddi_ufm_handle_t *uhp, void *arg, uint_t *nimgp); int (*ddi_ufm_op_fill_image)(ddi_ufm_handle_t *uhp, void *arg, uint_t imgid, ddi_ufm_image_t *img); int (*ddi_ufm_op_fill_slot)(ddi_ufm_handle_t *uhp, void *arg, int imgid, ddi_ufm_image_t *img, uint_t slotid, ddi_ufm_slot_t *slotp); int (*ddi_ufm_op_getcaps)(ddi_ufm_handle_t *uhp, void *arg, ddi_ufm_cap_t *caps); } ddi_ufm_ops_t;
The ddi_ufm_op_nimages
() entry point is
optional. If a device only has a single image, then there is no reason to
implement the
ddi_ufm_op_nimages
(entry,
point.) The system will assume that there is only a
single image.
Slots and images are numbered starting at zero. If a driver indicates support for multiple images or slots then the images or slots will be numbered sequentially going from 0 to the number of images or slots minus one. These values will be passed to the various entry points to indicate which image and slot the system is interested in. It is up to the driver to maintain a consistent view of the images and slots for a given UFM.
The members of this structure should be filled in the following ways:
ddi_ufm_op_nimages
()ddi_ufm_op_nimages
() entry point is an
optional entry point that answers the question of how many different,
distinct firmware images are present on the device. Once the driver
determines how many are present, it should set the value in
nimgp to the determined value.
It is legal for a device to pass in zero for this value, which indicates that there are none present.
Upon successful completion, the driver should return 0. Otherwise, the driver should return the appropriate error number. For a full list of error numbers, see Intro(2). Common values are:
EIO
ddi_ufm_op_fill_image
()ddi_ufm_op_fill_image
() entry point is used to
fill in information about a given image. The value in
imgid is used to indicate which image the system is
asking to fill information about. If the driver does not recognize the
image ID in imgid then it should return an error.
The ddi_ufm_image_t structure passed in uip is opaque. To fill in information about the image, the driver should call the functions described in ddi_ufm_image(9F).
The driver should call the ddi_ufm_image_set_desc(9F) function to set a description of the image which indicates its purpose. This should be a human-readable string. The driver may also set any ancillary data that it deems may be useful with the ddi_ufm_image_set_misc(9F) function. This function takes an nvlist, allowing the driver to set arbitrary keys and values.
Once the driver has finished setting all of the information about the image then the driver should return 0. Otherwise, the driver should return the appropriate error number. For a full list of error numbers, see Intro(2). Common values are:
EINVAL
EIO
ENOMEM
ddi_ufm_op_fill_slot
()ddi_ufm_op_fill_slot
() function is used to
fill in information about a specific slot for a specific image. The value
in imgid indicates the image the system wants slot
information for and the value in slotid indicates
which slot of that image the system is interested in. If the device driver
does not recognize the value in either or imgid or
slotid, then it should return an error.
The ddi_ufm_slot_t structure passed in usp is opaque. To fill in information about the image the driver should call the functions described in ddi_ufm_slot(9F).
The driver should call the ddi_ufm_slot_set_version(9F) function to indicate the version of the UFM. The version is a device-specific character string. It should contain the current version of the UFM as a human can understand it and it should try to match the format used by device vendor.
The ddi_ufm_slot_set_attrs(9F) function should be used to set the attributes of the UFM slot. These attributes include the following enumeration values:
DDI_UFM_ATTR_READABLE
DDI_UFM_ATTR_WRITEABLE
DDI_UFM_ATTR_ACTIVE
DDI_UFM_ATTR_EMPTY
Finally, if there are any device-specific key-value pairs that form useful, ancillary data, then the driver should assemble an nvlist and pass it to the ddi_ufm_set_misc(9F) function.
Once the driver has finished setting all of the information about the slot then the driver should return 0. Otherwise, the driver should return the appropriate error number. For a full list of error numbers, see Intro(2). Common values are:
EINVAL
EIO
ENOMEM
ddi_ufm_op_getcaps
()ddi_ufm_op_getcaps
() function is used to
indicate which DDI UFM capabilities are supported by this driver instance.
Currently there is only a single capability (DDI_UFM_CAP_REPORT) which
indicates that the driver is capable of reporting UFM information for this
instance. Future UFM versions may add additional capabilities such as the
ability to obtain a raw dump of the firmware image or to upgrade the
firmware.
The driver should indicate the supported capabilities by setting the value in the caps parameter. Once the driver has populated caps with an appropriate value, then the driver should return 0. Otherwise, the driver should return the appropriate error number. For a full list of error numbers, see Intro(2). Common values are:
EIO
ENOMEM
February 15, 2020 | illumos |