/** * efi_free_all_buff_pages - free all previous allocated buffer pages * @cap_info: pointer to current instance of capsule_info structure * * In addition to freeing buffer pages, it flags NO_FURTHER_WRITE_ACTION * to cease processing data in subsequent write(2) calls until close(2) * is called.
**/ staticvoid efi_free_all_buff_pages(struct capsule_info *cap_info)
{ while (cap_info->index > 0)
__free_page(cap_info->pages[--cap_info->index]);
cap_info->index = NO_FURTHER_WRITE_ACTION;
}
int __efi_capsule_setup_info(struct capsule_info *cap_info)
{
size_t pages_needed; int ret; void *temp_page;
/* Check if the capsule binary supported */
ret = efi_capsule_supported(cap_info->header.guid,
cap_info->header.flags,
cap_info->header.imagesize,
&cap_info->reset_type); if (ret) {
pr_err("capsule not supported\n"); return ret;
}
/** * efi_capsule_setup_info - obtain the efi capsule header in the binary and * setup capsule_info structure * @cap_info: pointer to current instance of capsule_info structure * @kbuff: a mapped first page buffer pointer * @hdr_bytes: the total received number of bytes for efi header * * Platforms with non-standard capsule update mechanisms can override * this __weak function so they can perform any required capsule * image munging. See quark_quirk_function() for an example.
**/ int __weak efi_capsule_setup_info(struct capsule_info *cap_info, void *kbuff,
size_t hdr_bytes)
{ /* Only process data block that is larger than efi header size */ if (hdr_bytes < sizeof(efi_capsule_header_t)) return 0;
/** * efi_capsule_submit_update - invoke the efi_capsule_update API once binary * upload done * @cap_info: pointer to current instance of capsule_info structure
**/ static ssize_t efi_capsule_submit_update(struct capsule_info *cap_info)
{ bool do_vunmap = false; int ret;
/* * cap_info->capsule may have been assigned already by a quirk * handler, so only overwrite it if it is NULL
*/ if (!cap_info->capsule) {
cap_info->capsule = vmap(cap_info->pages, cap_info->index,
VM_MAP, PAGE_KERNEL); if (!cap_info->capsule) return -ENOMEM;
do_vunmap = true;
}
ret = efi_capsule_update(cap_info->capsule, cap_info->phys); if (do_vunmap)
vunmap(cap_info->capsule); if (ret) {
pr_err("capsule update failed\n"); return ret;
}
/** * efi_capsule_write - store the capsule binary and pass it to * efi_capsule_update() API * @file: file pointer * @buff: buffer pointer * @count: number of bytes in @buff * @offp: not used * * Expectation: * - A user space tool should start at the beginning of capsule binary and * pass data in sequentially. * - Users should close and re-open this file note in order to upload more * capsules. * - After an error returned, user should close the file and restart the * operation for the next try otherwise -EIO will be returned until the * file is closed. * - An EFI capsule header must be located at the beginning of capsule * binary file and passed in as first block data of write operation.
**/ static ssize_t efi_capsule_write(struct file *file, constchar __user *buff,
size_t count, loff_t *offp)
{ int ret; struct capsule_info *cap_info = file->private_data; struct page *page; void *kbuff = NULL;
size_t write_byte;
if (count == 0) return 0;
/* Return error while NO_FURTHER_WRITE_ACTION is flagged */ if (cap_info->index < 0) return -EIO;
/* Only alloc a new page when previous page is full */ if (!cap_info->page_bytes_remain) {
page = alloc_page(GFP_KERNEL); if (!page) {
ret = -ENOMEM; goto failed;
}
/* Copy capsule binary data from user space to kernel space buffer */
write_byte = min_t(size_t, count, cap_info->page_bytes_remain); if (copy_from_user(kbuff, buff, write_byte)) {
ret = -EFAULT; goto fail_unmap;
}
cap_info->page_bytes_remain -= write_byte;
/* Setup capsule binary info structure */ if (cap_info->header.headersize == 0) {
ret = efi_capsule_setup_info(cap_info, kbuff - cap_info->count,
cap_info->count + write_byte); if (ret) goto fail_unmap;
}
cap_info->count += write_byte;
kunmap(page);
/* Submit the full binary to efi_capsule_update() API */ if (cap_info->header.headersize > 0 &&
cap_info->count >= cap_info->total_size) { if (cap_info->count > cap_info->total_size) {
pr_err("capsule upload size exceeded header defined size\n");
ret = -EINVAL; goto failed;
}
ret = efi_capsule_submit_update(cap_info); if (ret) goto failed;
}
/** * efi_capsule_release - called by file close * @inode: not used * @file: file pointer * * We will not free successfully submitted pages since efi update * requires data to be maintained across system reboot.
**/ staticint efi_capsule_release(struct inode *inode, struct file *file)
{ struct capsule_info *cap_info = file->private_data;
if (cap_info->index > 0 &&
(cap_info->header.headersize == 0 ||
cap_info->count < cap_info->total_size)) {
pr_err("capsule upload not complete\n");
efi_free_all_buff_pages(cap_info);
}
/** * efi_capsule_open - called by file open * @inode: not used * @file: file pointer * * Will allocate each capsule_info memory for each file open call. * This provided the capability to support multiple file open feature * where user is not needed to wait for others to finish in order to * upload their capsule binary.
**/ staticint efi_capsule_open(struct inode *inode, struct file *file)
{ struct capsule_info *cap_info;
cap_info = kzalloc(sizeof(*cap_info), GFP_KERNEL); if (!cap_info) return -ENOMEM;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.