// SPDX-License-Identifier: GPL-2.0-only /* * dell_rbu.c * Bios Update driver for Dell systems * Author: Dell Inc * Abhay Salunke <abhay_salunke@dell.com> * * Copyright (C) 2005 Dell Inc. * * Remote BIOS Update (rbu) driver is used for updating DELL BIOS by * creating entries in the /sys file systems on Linux 2.6 and higher * kernels. The driver supports two mechanism to update the BIOS namely * contiguous and packetized. Both these methods still require having some * application to set the CMOS bit indicating the BIOS to update itself * after a reboot. * * Contiguous method: * This driver writes the incoming data in a monolithic image by allocating * contiguous physical pages large enough to accommodate the incoming BIOS * image size. * * Packetized method: * The driver writes the incoming packet image by allocating a new packet * on every time the packet data is written. This driver requires an * application to break the BIOS image in to fixed sized packet chunks. * * See Documentation/admin-guide/dell_rbu.rst for more info.
*/
if (!newpacket) {
pr_warn("failed to allocate new packet\n");
retval = -ENOMEM;
spin_lock(&rbu_data.lock); goto out_noalloc;
}
ordernum = get_order(length);
/* * BIOS errata mean we cannot allocate packets below 1MB or they will * be overwritten by BIOS. * * array to temporarily hold packets * that are below the allocation floor * * NOTE: very simplistic because we only need the floor to be at 1MB * due to BIOS errata. This shouldn't be used for higher floors * or you will run out of mem trying to allocate the array.
*/
packet_array_size = max_t(unsignedint, allocation_floor / rbu_data.packetsize, 1);
invalid_addr_packet_array = kcalloc(packet_array_size, sizeof(void *),
GFP_KERNEL);
if (!invalid_addr_packet_array) {
pr_warn("failed to allocate invalid_addr_packet_array\n");
retval = -ENOMEM;
spin_lock(&rbu_data.lock); goto out_alloc_packet;
}
while (!packet_data_temp_buf) {
packet_data_temp_buf = (unsignedchar *)
__get_free_pages(GFP_KERNEL, ordernum); if (!packet_data_temp_buf) {
pr_warn("failed to allocate new packet\n");
retval = -ENOMEM;
spin_lock(&rbu_data.lock); goto out_alloc_packet_array;
}
if ((unsignedlong)virt_to_phys(packet_data_temp_buf)
< allocation_floor) {
pr_debug("packet 0x%lx below floor at 0x%lx\n",
(unsignedlong)virt_to_phys(
packet_data_temp_buf),
allocation_floor);
invalid_addr_packet_array[idx++] = packet_data_temp_buf;
packet_data_temp_buf = NULL;
}
} /* * set to uncachable or it may never get written back before reboot
*/
set_memory_uc((unsignedlong)packet_data_temp_buf, 1 << ordernum);
spin_lock(&rbu_data.lock);
newpacket->data = packet_data_temp_buf;
pr_debug("newpacket at physical addr %lx\n",
(unsignedlong)virt_to_phys(newpacket->data));
/* packets may not have fixed size */
newpacket->length = length;
newpacket->ordernum = ordernum;
++rbu_data.num_packets;
/* initialize the newly created packet headers */
INIT_LIST_HEAD(&newpacket->list);
list_add_tail(&newpacket->list, &packet_data_list);
out_alloc_packet: /* if error, free data */ if (retval)
kfree(newpacket);
out_noalloc: return retval;
}
staticint packetize_data(const u8 *data, size_t length)
{ int rc = 0; int done = 0; int packet_length;
u8 *temp;
u8 *end = (u8 *) data + length;
pr_debug("data length %zd\n", length); if (!rbu_data.packetsize) {
pr_warn("packetsize not specified\n"); return -EIO;
}
temp = (u8 *) data;
/* packetize the hunk */ while (!done) { if ((temp + rbu_data.packetsize) < end)
packet_length = rbu_data.packetsize; else { /* this is the last packet */
packet_length = end - temp;
done = 1;
}
if ((rc = create_packet(temp, packet_length))) return rc;
staticint do_packet_read(char *data, struct packet_data *newpacket, int length, int bytes_read, int *list_read_count)
{ void *ptemp_buf; int bytes_copied = 0; int j = 0;
*list_read_count += newpacket->length;
if (*list_read_count > bytes_read) { /* point to the start of unread data */
j = newpacket->length - (*list_read_count - bytes_read); /* point to the offset in the packet buffer */
ptemp_buf = (u8 *) newpacket->data + j; /* * check if there is enough room in * * the incoming buffer
*/ if (length > (*list_read_count - bytes_read)) /* * copy what ever is there in this * packet and move on
*/
bytes_copied = (*list_read_count - bytes_read); else /* copy the remaining */
bytes_copied = length;
memcpy(data, ptemp_buf, bytes_copied);
} return bytes_copied;
}
staticint packet_read_list(char *data, size_t * pread_length)
{ struct packet_data *newpacket; int temp_count = 0; int bytes_copied = 0; int bytes_read = 0; int remaining_bytes = 0; char *pdest = data;
/* check if we have any packets */ if (0 == rbu_data.num_packets) return -ENOMEM;
/* * zero out the RBU packet memory before freeing * to make sure there are no stale RBU packets left in memory
*/
memset(newpacket->data, 0, newpacket->length);
set_memory_wb((unsignedlong)newpacket->data,
1 << newpacket->ordernum);
free_pages((unsignedlong) newpacket->data,
newpacket->ordernum);
kfree(newpacket);
}
rbu_data.packet_read_count = 0;
rbu_data.num_packets = 0;
rbu_data.imagesize = 0;
}
/* * img_update_free: Frees the buffer allocated for storing BIOS image * Always called with lock held and returned with lock held
*/ staticvoid img_update_free(void)
{ if (!rbu_data.image_update_buffer) return; /* * zero out this buffer before freeing it to get rid of any stale * BIOS image copied in memory.
*/
memset(rbu_data.image_update_buffer, 0,
rbu_data.image_update_buffer_size);
free_pages((unsignedlong) rbu_data.image_update_buffer,
rbu_data.image_update_ordernum);
/* * Re-initialize the rbu_data variables after a free
*/
rbu_data.image_update_ordernum = -1;
rbu_data.image_update_buffer = NULL;
rbu_data.image_update_buffer_size = 0;
rbu_data.bios_image_size = 0;
}
/* * img_update_realloc: This function allocates the contiguous pages to * accommodate the requested size of data. The memory address and size * values are stored globally and on every call to this function the new * size is checked to see if more data is required than the existing size. * If true the previous memory is freed and new allocation is done to * accommodate the new size. If the incoming size is less then than the * already allocated size, then that memory is reused. This function is * called with lock held and returns with lock held.
*/ staticint img_update_realloc(unsignedlong size)
{ unsignedchar *image_update_buffer = NULL; unsignedlong img_buf_phys_addr; int ordernum;
/* * check if the buffer of sufficient size has been * already allocated
*/ if (rbu_data.image_update_buffer_size >= size) { /* * check for corruption
*/ if ((size != 0) && (rbu_data.image_update_buffer == NULL)) {
pr_err("corruption check failed\n"); return -EINVAL;
} /* * we have a valid pre-allocated buffer with * sufficient size
*/ return 0;
}
/* * free any previously allocated buffer
*/
img_update_free();
/* check to see if we have something to return */ if (rbu_data.num_packets == 0) {
pr_debug("no packets written\n");
retval = -ENOMEM; goto read_rbu_data_exit;
}
spin_lock(&rbu_data.lock); if (!strcmp(image_type, "mono")) { if (!img_update_realloc(fw->size))
memcpy(rbu_data.image_update_buffer,
fw->data, fw->size);
} elseif (!strcmp(image_type, "packet")) { /* * we need to free previous packets if a * new hunk of packets needs to be downloaded
*/
packet_empty_list(); if (packetize_data(fw->data, fw->size)) /* Incase something goes wrong when we are * in middle of packetizing the data, we * need to free up whatever packets might * have been created before we quit.
*/
packet_empty_list();
} else
pr_debug("invalid image type specified\n");
spin_unlock(&rbu_data.lock);
out:
release_firmware(fw);
}
static ssize_t image_type_write(struct file *filp, struct kobject *kobj, conststruct bin_attribute *bin_attr, char *buffer, loff_t pos, size_t count)
{ int rc = count; int req_firm_rc = 0; int i;
spin_lock(&rbu_data.lock); /* * Find the first newline or space
*/ for (i = 0; i < count; ++i) if (buffer[i] == '\n' || buffer[i] == ' ') {
buffer[i] = '\0'; break;
} if (i == count)
buffer[count] = '\0';
if (strstr(buffer, "mono"))
strcpy(image_type, "mono"); elseif (strstr(buffer, "packet"))
strcpy(image_type, "packet"); elseif (strstr(buffer, "init")) { /* * If due to the user error the driver gets in a bad * state where even though it is loaded , the * /sys/class/firmware/dell_rbu entries are missing. * to cover this situation the user can recreate entries * by writing init to image_type.
*/ if (!rbu_data.entry_created) {
spin_unlock(&rbu_data.lock);
req_firm_rc = request_firmware_nowait(THIS_MODULE,
FW_ACTION_NOUEVENT, "dell_rbu",
&rbu_device->dev, GFP_KERNEL, &context,
callbackfn_rbu); if (req_firm_rc) {
pr_err("request_firmware_nowait failed %d\n", rc);
rc = -EIO;
} else
rbu_data.entry_created = 1;
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.