2019-05-29 21:18:01 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2005-09-07 05:17:14 +07:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*
|
2019-10-13 00:11:10 +07:00
|
|
|
* See Documentation/admin-guide/dell_rbu.rst for more info.
|
2005-09-07 05:17:14 +07:00
|
|
|
*/
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/module.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2005-09-07 05:17:14 +07:00
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/blkdev.h>
|
2005-10-30 01:07:23 +07:00
|
|
|
#include <linux/platform_device.h>
|
2005-09-07 05:17:14 +07:00
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/firmware.h>
|
|
|
|
#include <linux/dma-mapping.h>
|
2018-09-27 04:50:17 +07:00
|
|
|
#include <asm/set_memory.h>
|
2005-09-07 05:17:14 +07:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Abhay Salunke <abhay_salunke@dell.com>");
|
|
|
|
MODULE_DESCRIPTION("Driver for updating BIOS image on DELL systems");
|
|
|
|
MODULE_LICENSE("GPL");
|
2006-01-15 04:21:14 +07:00
|
|
|
MODULE_VERSION("3.2");
|
2005-09-07 05:17:14 +07:00
|
|
|
|
|
|
|
#define BIOS_SCAN_LIMIT 0xffffffff
|
|
|
|
#define MAX_IMAGE_LENGTH 16
|
|
|
|
static struct _rbu_data {
|
|
|
|
void *image_update_buffer;
|
|
|
|
unsigned long image_update_buffer_size;
|
|
|
|
unsigned long bios_image_size;
|
|
|
|
int image_update_ordernum;
|
|
|
|
spinlock_t lock;
|
|
|
|
unsigned long packet_read_count;
|
|
|
|
unsigned long num_packets;
|
|
|
|
unsigned long packetsize;
|
2005-10-11 22:29:02 +07:00
|
|
|
unsigned long imagesize;
|
2005-09-17 09:28:04 +07:00
|
|
|
int entry_created;
|
2005-09-07 05:17:14 +07:00
|
|
|
} rbu_data;
|
|
|
|
|
2005-09-17 09:28:04 +07:00
|
|
|
static char image_type[MAX_IMAGE_LENGTH + 1] = "mono";
|
|
|
|
module_param_string(image_type, image_type, sizeof (image_type), 0);
|
2005-10-11 22:29:02 +07:00
|
|
|
MODULE_PARM_DESC(image_type,
|
|
|
|
"BIOS image type. choose- mono or packet or init");
|
2005-09-07 05:17:14 +07:00
|
|
|
|
2005-11-07 15:59:26 +07:00
|
|
|
static unsigned long allocation_floor = 0x100000;
|
|
|
|
module_param(allocation_floor, ulong, 0644);
|
|
|
|
MODULE_PARM_DESC(allocation_floor,
|
|
|
|
"Minimum address for allocations when using Packet mode");
|
|
|
|
|
2005-09-07 05:17:14 +07:00
|
|
|
struct packet_data {
|
|
|
|
struct list_head list;
|
|
|
|
size_t length;
|
|
|
|
void *data;
|
|
|
|
int ordernum;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct packet_data packet_data_head;
|
|
|
|
|
|
|
|
static struct platform_device *rbu_device;
|
|
|
|
static int context;
|
|
|
|
|
2005-09-17 09:28:05 +07:00
|
|
|
static void init_packet_head(void)
|
2005-09-07 05:17:14 +07:00
|
|
|
{
|
|
|
|
INIT_LIST_HEAD(&packet_data_head.list);
|
|
|
|
rbu_data.packet_read_count = 0;
|
|
|
|
rbu_data.num_packets = 0;
|
|
|
|
rbu_data.packetsize = 0;
|
2005-10-11 22:29:02 +07:00
|
|
|
rbu_data.imagesize = 0;
|
2005-09-07 05:17:14 +07:00
|
|
|
}
|
|
|
|
|
2005-10-11 22:29:02 +07:00
|
|
|
static int create_packet(void *data, size_t length)
|
2005-09-07 05:17:14 +07:00
|
|
|
{
|
|
|
|
struct packet_data *newpacket;
|
|
|
|
int ordernum = 0;
|
2005-11-07 15:59:26 +07:00
|
|
|
int retval = 0;
|
|
|
|
unsigned int packet_array_size = 0;
|
2005-12-15 16:18:00 +07:00
|
|
|
void **invalid_addr_packet_array = NULL;
|
|
|
|
void *packet_data_temp_buf = NULL;
|
2005-11-07 15:59:26 +07:00
|
|
|
unsigned int idx = 0;
|
2005-09-07 05:17:14 +07:00
|
|
|
|
|
|
|
pr_debug("create_packet: entry \n");
|
|
|
|
|
|
|
|
if (!rbu_data.packetsize) {
|
|
|
|
pr_debug("create_packet: packetsize not specified\n");
|
2005-11-07 15:59:26 +07:00
|
|
|
retval = -EINVAL;
|
|
|
|
goto out_noalloc;
|
2005-09-07 05:17:14 +07:00
|
|
|
}
|
2005-11-07 15:59:26 +07:00
|
|
|
|
2005-09-17 09:28:04 +07:00
|
|
|
spin_unlock(&rbu_data.lock);
|
2005-11-07 15:59:26 +07:00
|
|
|
|
|
|
|
newpacket = kzalloc(sizeof (struct packet_data), GFP_KERNEL);
|
2005-09-07 05:17:14 +07:00
|
|
|
|
|
|
|
if (!newpacket) {
|
|
|
|
printk(KERN_WARNING
|
2005-09-17 09:28:04 +07:00
|
|
|
"dell_rbu:%s: failed to allocate new "
|
2008-04-29 14:59:19 +07:00
|
|
|
"packet\n", __func__);
|
2005-11-07 15:59:26 +07:00
|
|
|
retval = -ENOMEM;
|
|
|
|
spin_lock(&rbu_data.lock);
|
|
|
|
goto out_noalloc;
|
2005-09-07 05:17:14 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
ordernum = get_order(length);
|
2005-11-07 15:59:26 +07:00
|
|
|
|
2005-09-07 05:17:14 +07:00
|
|
|
/*
|
2005-11-07 15:59:26 +07:00
|
|
|
* 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.
|
2005-09-07 05:17:14 +07:00
|
|
|
*/
|
2005-11-07 15:59:26 +07:00
|
|
|
packet_array_size = max(
|
|
|
|
(unsigned int)(allocation_floor / rbu_data.packetsize),
|
|
|
|
(unsigned int)1);
|
treewide: kzalloc() -> kcalloc()
The kzalloc() function has a 2-factor argument form, kcalloc(). This
patch replaces cases of:
kzalloc(a * b, gfp)
with:
kcalloc(a * b, gfp)
as well as handling cases of:
kzalloc(a * b * c, gfp)
with:
kzalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kzalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kzalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kzalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kzalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kzalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kzalloc
+ kcalloc
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kzalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kzalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kzalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kzalloc(sizeof(THING) * C2, ...)
|
kzalloc(sizeof(TYPE) * C2, ...)
|
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(C1 * C2, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * E2
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-13 04:03:40 +07:00
|
|
|
invalid_addr_packet_array = kcalloc(packet_array_size, sizeof(void *),
|
2005-11-07 15:59:26 +07:00
|
|
|
GFP_KERNEL);
|
2005-09-07 05:17:14 +07:00
|
|
|
|
2005-11-07 15:59:26 +07:00
|
|
|
if (!invalid_addr_packet_array) {
|
2005-09-07 05:17:14 +07:00
|
|
|
printk(KERN_WARNING
|
2005-11-07 15:59:26 +07:00
|
|
|
"dell_rbu:%s: failed to allocate "
|
|
|
|
"invalid_addr_packet_array \n",
|
2008-04-29 14:59:19 +07:00
|
|
|
__func__);
|
2005-11-07 15:59:26 +07:00
|
|
|
retval = -ENOMEM;
|
|
|
|
spin_lock(&rbu_data.lock);
|
|
|
|
goto out_alloc_packet;
|
2005-09-07 05:17:14 +07:00
|
|
|
}
|
|
|
|
|
2005-11-07 15:59:26 +07:00
|
|
|
while (!packet_data_temp_buf) {
|
|
|
|
packet_data_temp_buf = (unsigned char *)
|
|
|
|
__get_free_pages(GFP_KERNEL, ordernum);
|
|
|
|
if (!packet_data_temp_buf) {
|
|
|
|
printk(KERN_WARNING
|
|
|
|
"dell_rbu:%s: failed to allocate new "
|
2008-04-29 14:59:19 +07:00
|
|
|
"packet\n", __func__);
|
2005-11-07 15:59:26 +07:00
|
|
|
retval = -ENOMEM;
|
|
|
|
spin_lock(&rbu_data.lock);
|
|
|
|
goto out_alloc_packet_array;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((unsigned long)virt_to_phys(packet_data_temp_buf)
|
|
|
|
< allocation_floor) {
|
|
|
|
pr_debug("packet 0x%lx below floor at 0x%lx.\n",
|
|
|
|
(unsigned long)virt_to_phys(
|
|
|
|
packet_data_temp_buf),
|
|
|
|
allocation_floor);
|
|
|
|
invalid_addr_packet_array[idx++] = packet_data_temp_buf;
|
2005-12-15 16:18:00 +07:00
|
|
|
packet_data_temp_buf = NULL;
|
2005-11-07 15:59:26 +07:00
|
|
|
}
|
|
|
|
}
|
2018-09-27 04:50:17 +07:00
|
|
|
/*
|
|
|
|
* set to uncachable or it may never get written back before reboot
|
|
|
|
*/
|
|
|
|
set_memory_uc((unsigned long)packet_data_temp_buf, 1 << ordernum);
|
|
|
|
|
2005-11-07 15:59:26 +07:00
|
|
|
spin_lock(&rbu_data.lock);
|
|
|
|
|
|
|
|
newpacket->data = packet_data_temp_buf;
|
|
|
|
|
|
|
|
pr_debug("create_packet: newpacket at physical addr %lx\n",
|
|
|
|
(unsigned long)virt_to_phys(newpacket->data));
|
|
|
|
|
|
|
|
/* packets may not have fixed size */
|
|
|
|
newpacket->length = length;
|
2005-09-07 05:17:14 +07:00
|
|
|
newpacket->ordernum = ordernum;
|
|
|
|
++rbu_data.num_packets;
|
2005-11-07 15:59:26 +07:00
|
|
|
|
|
|
|
/* initialize the newly created packet headers */
|
2005-09-07 05:17:14 +07:00
|
|
|
INIT_LIST_HEAD(&newpacket->list);
|
|
|
|
list_add_tail(&newpacket->list, &packet_data_head.list);
|
2005-10-11 22:29:02 +07:00
|
|
|
|
|
|
|
memcpy(newpacket->data, data, length);
|
2005-09-07 05:17:14 +07:00
|
|
|
|
|
|
|
pr_debug("create_packet: exit \n");
|
|
|
|
|
2005-11-07 15:59:26 +07:00
|
|
|
out_alloc_packet_array:
|
|
|
|
/* always free packet array */
|
|
|
|
for (;idx>0;idx--) {
|
|
|
|
pr_debug("freeing unused packet below floor 0x%lx.\n",
|
|
|
|
(unsigned long)virt_to_phys(
|
|
|
|
invalid_addr_packet_array[idx-1]));
|
|
|
|
free_pages((unsigned long)invalid_addr_packet_array[idx-1],
|
|
|
|
ordernum);
|
|
|
|
}
|
|
|
|
kfree(invalid_addr_packet_array);
|
|
|
|
|
|
|
|
out_alloc_packet:
|
|
|
|
/* if error, free data */
|
|
|
|
if (retval)
|
|
|
|
kfree(newpacket);
|
|
|
|
|
|
|
|
out_noalloc:
|
|
|
|
return retval;
|
2005-09-07 05:17:14 +07:00
|
|
|
}
|
|
|
|
|
2008-05-30 00:05:08 +07:00
|
|
|
static int packetize_data(const u8 *data, size_t length)
|
2005-09-07 05:17:14 +07:00
|
|
|
{
|
|
|
|
int rc = 0;
|
2005-10-11 22:29:02 +07:00
|
|
|
int done = 0;
|
|
|
|
int packet_length;
|
|
|
|
u8 *temp;
|
|
|
|
u8 *end = (u8 *) data + length;
|
2006-10-03 15:16:09 +07:00
|
|
|
pr_debug("packetize_data: data length %zd\n", length);
|
2005-10-11 22:29:02 +07:00
|
|
|
if (!rbu_data.packetsize) {
|
|
|
|
printk(KERN_WARNING
|
|
|
|
"dell_rbu: packetsize not specified\n");
|
|
|
|
return -EIO;
|
|
|
|
}
|
2005-09-07 05:17:14 +07:00
|
|
|
|
2005-10-11 22:29:02 +07:00
|
|
|
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)))
|
2005-09-07 05:17:14 +07:00
|
|
|
return rc;
|
2005-10-11 22:29:02 +07:00
|
|
|
|
2006-10-11 15:22:13 +07:00
|
|
|
pr_debug("%p:%td\n", temp, (end - temp));
|
2005-10-11 22:29:02 +07:00
|
|
|
temp += packet_length;
|
2005-09-07 05:17:14 +07:00
|
|
|
}
|
2005-10-11 22:29:02 +07:00
|
|
|
|
|
|
|
rbu_data.imagesize = length;
|
2005-09-07 05:17:14 +07:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2005-09-17 09:28:05 +07:00
|
|
|
static int do_packet_read(char *data, struct list_head *ptemp_list,
|
2005-09-17 09:28:04 +07:00
|
|
|
int length, int bytes_read, int *list_read_count)
|
2005-09-07 05:17:14 +07:00
|
|
|
{
|
|
|
|
void *ptemp_buf;
|
|
|
|
struct packet_data *newpacket = NULL;
|
|
|
|
int bytes_copied = 0;
|
|
|
|
int j = 0;
|
|
|
|
|
|
|
|
newpacket = list_entry(ptemp_list, struct packet_data, list);
|
|
|
|
*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;
|
|
|
|
}
|
|
|
|
|
2005-10-11 22:29:02 +07:00
|
|
|
static int packet_read_list(char *data, size_t * pread_length)
|
2005-09-07 05:17:14 +07:00
|
|
|
{
|
|
|
|
struct list_head *ptemp_list;
|
|
|
|
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;
|
|
|
|
|
|
|
|
remaining_bytes = *pread_length;
|
|
|
|
bytes_read = rbu_data.packet_read_count;
|
|
|
|
|
|
|
|
ptemp_list = (&packet_data_head.list)->next;
|
|
|
|
while (!list_empty(ptemp_list)) {
|
|
|
|
bytes_copied = do_packet_read(pdest, ptemp_list,
|
2005-09-17 09:28:04 +07:00
|
|
|
remaining_bytes, bytes_read, &temp_count);
|
2005-09-07 05:17:14 +07:00
|
|
|
remaining_bytes -= bytes_copied;
|
|
|
|
bytes_read += bytes_copied;
|
|
|
|
pdest += bytes_copied;
|
|
|
|
/*
|
|
|
|
* check if we reached end of buffer before reaching the
|
|
|
|
* last packet
|
|
|
|
*/
|
|
|
|
if (remaining_bytes == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
ptemp_list = ptemp_list->next;
|
|
|
|
}
|
|
|
|
/*finally set the bytes read */
|
|
|
|
*pread_length = bytes_read - rbu_data.packet_read_count;
|
|
|
|
rbu_data.packet_read_count = bytes_read;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-09-17 09:28:05 +07:00
|
|
|
static void packet_empty_list(void)
|
2005-09-07 05:17:14 +07:00
|
|
|
{
|
|
|
|
struct list_head *ptemp_list;
|
|
|
|
struct list_head *pnext_list;
|
|
|
|
struct packet_data *newpacket;
|
|
|
|
|
|
|
|
ptemp_list = (&packet_data_head.list)->next;
|
|
|
|
while (!list_empty(ptemp_list)) {
|
|
|
|
newpacket =
|
2005-09-17 09:28:04 +07:00
|
|
|
list_entry(ptemp_list, struct packet_data, list);
|
2005-09-07 05:17:14 +07:00
|
|
|
pnext_list = ptemp_list->next;
|
|
|
|
list_del(ptemp_list);
|
|
|
|
ptemp_list = pnext_list;
|
|
|
|
/*
|
|
|
|
* zero out the RBU packet memory before freeing
|
|
|
|
* to make sure there are no stale RBU packets left in memory
|
|
|
|
*/
|
|
|
|
memset(newpacket->data, 0, rbu_data.packetsize);
|
2018-09-27 04:50:17 +07:00
|
|
|
set_memory_wb((unsigned long)newpacket->data,
|
|
|
|
1 << newpacket->ordernum);
|
2005-09-17 09:28:04 +07:00
|
|
|
free_pages((unsigned long) newpacket->data,
|
|
|
|
newpacket->ordernum);
|
2005-09-07 05:17:14 +07:00
|
|
|
kfree(newpacket);
|
|
|
|
}
|
|
|
|
rbu_data.packet_read_count = 0;
|
|
|
|
rbu_data.num_packets = 0;
|
2005-10-11 22:29:02 +07:00
|
|
|
rbu_data.imagesize = 0;
|
2005-09-07 05:17:14 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* img_update_free: Frees the buffer allocated for storing BIOS image
|
|
|
|
* Always called with lock held and returned with lock held
|
|
|
|
*/
|
2005-09-17 09:28:05 +07:00
|
|
|
static void img_update_free(void)
|
2005-09-07 05:17:14 +07:00
|
|
|
{
|
|
|
|
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,
|
2005-09-17 09:28:04 +07:00
|
|
|
rbu_data.image_update_buffer_size);
|
2019-01-29 14:34:09 +07:00
|
|
|
free_pages((unsigned long) rbu_data.image_update_buffer,
|
|
|
|
rbu_data.image_update_ordernum);
|
2005-09-07 05:17:14 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2005-09-17 09:28:05 +07:00
|
|
|
static int img_update_realloc(unsigned long size)
|
2005-09-07 05:17:14 +07:00
|
|
|
{
|
|
|
|
unsigned char *image_update_buffer = NULL;
|
|
|
|
unsigned long 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)) {
|
|
|
|
printk(KERN_ERR "dell_rbu:%s: corruption "
|
2008-04-29 14:59:19 +07:00
|
|
|
"check failed\n", __func__);
|
2005-09-07 05:17:14 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* we have a valid pre-allocated buffer with
|
|
|
|
* sufficient size
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* free any previously allocated buffer
|
|
|
|
*/
|
|
|
|
img_update_free();
|
|
|
|
|
|
|
|
spin_unlock(&rbu_data.lock);
|
|
|
|
|
|
|
|
ordernum = get_order(size);
|
|
|
|
image_update_buffer =
|
2019-01-29 14:34:09 +07:00
|
|
|
(unsigned char *)__get_free_pages(GFP_DMA32, ordernum);
|
2019-02-11 20:09:40 +07:00
|
|
|
spin_lock(&rbu_data.lock);
|
2019-01-29 14:34:09 +07:00
|
|
|
if (!image_update_buffer) {
|
2005-09-07 05:17:14 +07:00
|
|
|
pr_debug("Not enough memory for image update:"
|
2005-09-17 09:28:04 +07:00
|
|
|
"size = %ld\n", size);
|
2019-01-29 14:34:09 +07:00
|
|
|
return -ENOMEM;
|
2005-09-07 05:17:14 +07:00
|
|
|
}
|
|
|
|
|
2019-01-29 14:34:09 +07:00
|
|
|
img_buf_phys_addr = (unsigned long)virt_to_phys(image_update_buffer);
|
|
|
|
if (WARN_ON_ONCE(img_buf_phys_addr > BIOS_SCAN_LIMIT))
|
|
|
|
return -EINVAL; /* can't happen per definition */
|
|
|
|
|
|
|
|
rbu_data.image_update_buffer = image_update_buffer;
|
|
|
|
rbu_data.image_update_buffer_size = size;
|
|
|
|
rbu_data.bios_image_size = rbu_data.image_update_buffer_size;
|
|
|
|
rbu_data.image_update_ordernum = ordernum;
|
|
|
|
return 0;
|
2005-09-07 05:17:14 +07:00
|
|
|
}
|
|
|
|
|
2005-09-17 09:28:05 +07:00
|
|
|
static ssize_t read_packet_data(char *buffer, loff_t pos, size_t count)
|
2005-09-07 05:17:14 +07:00
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
size_t bytes_left;
|
|
|
|
size_t data_length;
|
|
|
|
char *ptempBuf = buffer;
|
|
|
|
|
|
|
|
/* check to see if we have something to return */
|
|
|
|
if (rbu_data.num_packets == 0) {
|
|
|
|
pr_debug("read_packet_data: no packets written\n");
|
|
|
|
retval = -ENOMEM;
|
|
|
|
goto read_rbu_data_exit;
|
|
|
|
}
|
|
|
|
|
2005-10-11 22:29:02 +07:00
|
|
|
if (pos > rbu_data.imagesize) {
|
2005-09-07 05:17:14 +07:00
|
|
|
retval = 0;
|
|
|
|
printk(KERN_WARNING "dell_rbu:read_packet_data: "
|
2005-09-17 09:28:04 +07:00
|
|
|
"data underrun\n");
|
2005-09-07 05:17:14 +07:00
|
|
|
goto read_rbu_data_exit;
|
|
|
|
}
|
|
|
|
|
2005-10-11 22:29:02 +07:00
|
|
|
bytes_left = rbu_data.imagesize - pos;
|
2005-09-07 05:17:14 +07:00
|
|
|
data_length = min(bytes_left, count);
|
|
|
|
|
|
|
|
if ((retval = packet_read_list(ptempBuf, &data_length)) < 0)
|
|
|
|
goto read_rbu_data_exit;
|
|
|
|
|
2005-10-11 22:29:02 +07:00
|
|
|
if ((pos + count) > rbu_data.imagesize) {
|
2005-09-07 05:17:14 +07:00
|
|
|
rbu_data.packet_read_count = 0;
|
|
|
|
/* this was the last copy */
|
|
|
|
retval = bytes_left;
|
|
|
|
} else
|
|
|
|
retval = count;
|
|
|
|
|
|
|
|
read_rbu_data_exit:
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2005-09-17 09:28:05 +07:00
|
|
|
static ssize_t read_rbu_mono_data(char *buffer, loff_t pos, size_t count)
|
2005-09-07 05:17:14 +07:00
|
|
|
{
|
|
|
|
/* check to see if we have something to return */
|
|
|
|
if ((rbu_data.image_update_buffer == NULL) ||
|
2005-09-17 09:28:04 +07:00
|
|
|
(rbu_data.bios_image_size == 0)) {
|
2005-09-07 05:17:14 +07:00
|
|
|
pr_debug("read_rbu_data_mono: image_update_buffer %p ,"
|
2005-09-17 09:28:04 +07:00
|
|
|
"bios_image_size %lu\n",
|
|
|
|
rbu_data.image_update_buffer,
|
|
|
|
rbu_data.bios_image_size);
|
2008-07-25 15:48:27 +07:00
|
|
|
return -ENOMEM;
|
2005-09-07 05:17:14 +07:00
|
|
|
}
|
|
|
|
|
2008-07-25 15:48:27 +07:00
|
|
|
return memory_read_from_buffer(buffer, count, &pos,
|
|
|
|
rbu_data.image_update_buffer, rbu_data.bios_image_size);
|
2005-09-07 05:17:14 +07:00
|
|
|
}
|
|
|
|
|
2010-05-13 08:28:57 +07:00
|
|
|
static ssize_t read_rbu_data(struct file *filp, struct kobject *kobj,
|
2007-06-09 12:57:22 +07:00
|
|
|
struct bin_attribute *bin_attr,
|
|
|
|
char *buffer, loff_t pos, size_t count)
|
2005-09-07 05:17:14 +07:00
|
|
|
{
|
|
|
|
ssize_t ret_count = 0;
|
|
|
|
|
|
|
|
spin_lock(&rbu_data.lock);
|
|
|
|
|
|
|
|
if (!strcmp(image_type, "mono"))
|
|
|
|
ret_count = read_rbu_mono_data(buffer, pos, count);
|
|
|
|
else if (!strcmp(image_type, "packet"))
|
|
|
|
ret_count = read_packet_data(buffer, pos, count);
|
|
|
|
else
|
|
|
|
pr_debug("read_rbu_data: invalid image type specified\n");
|
|
|
|
|
|
|
|
spin_unlock(&rbu_data.lock);
|
|
|
|
return ret_count;
|
|
|
|
}
|
|
|
|
|
2005-09-17 09:28:05 +07:00
|
|
|
static void callbackfn_rbu(const struct firmware *fw, void *context)
|
2005-09-17 09:28:04 +07:00
|
|
|
{
|
2006-01-15 04:21:14 +07:00
|
|
|
rbu_data.entry_created = 0;
|
2005-09-17 09:28:04 +07:00
|
|
|
|
2009-10-29 18:36:02 +07:00
|
|
|
if (!fw)
|
2005-09-17 09:28:04 +07:00
|
|
|
return;
|
|
|
|
|
2009-10-29 18:36:02 +07:00
|
|
|
if (!fw->size)
|
|
|
|
goto out;
|
|
|
|
|
2005-09-17 09:28:04 +07:00
|
|
|
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);
|
|
|
|
} else if (!strcmp(image_type, "packet")) {
|
2005-10-11 22:29:02 +07:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2005-09-17 09:28:04 +07:00
|
|
|
packet_empty_list();
|
|
|
|
} else
|
|
|
|
pr_debug("invalid image type specified.\n");
|
|
|
|
spin_unlock(&rbu_data.lock);
|
2009-10-29 18:36:02 +07:00
|
|
|
out:
|
|
|
|
release_firmware(fw);
|
2005-09-17 09:28:04 +07:00
|
|
|
}
|
|
|
|
|
2010-05-13 08:28:57 +07:00
|
|
|
static ssize_t read_rbu_image_type(struct file *filp, struct kobject *kobj,
|
2007-06-09 12:57:22 +07:00
|
|
|
struct bin_attribute *bin_attr,
|
|
|
|
char *buffer, loff_t pos, size_t count)
|
2005-09-07 05:17:14 +07:00
|
|
|
{
|
|
|
|
int size = 0;
|
|
|
|
if (!pos)
|
2009-01-18 01:33:03 +07:00
|
|
|
size = scnprintf(buffer, count, "%s\n", image_type);
|
2005-09-07 05:17:14 +07:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2010-05-13 08:28:57 +07:00
|
|
|
static ssize_t write_rbu_image_type(struct file *filp, struct kobject *kobj,
|
2007-06-09 12:57:22 +07:00
|
|
|
struct bin_attribute *bin_attr,
|
|
|
|
char *buffer, loff_t pos, size_t count)
|
2005-09-07 05:17:14 +07:00
|
|
|
{
|
|
|
|
int rc = count;
|
2005-09-17 09:28:04 +07:00
|
|
|
int req_firm_rc = 0;
|
|
|
|
int i;
|
2005-09-07 05:17:14 +07:00
|
|
|
spin_lock(&rbu_data.lock);
|
2005-09-17 09:28:04 +07:00
|
|
|
/*
|
|
|
|
* 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");
|
|
|
|
else if (strstr(buffer, "packet"))
|
|
|
|
strcpy(image_type, "packet");
|
|
|
|
else if (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_NOHOTPLUG, "dell_rbu",
|
2009-10-29 18:36:02 +07:00
|
|
|
&rbu_device->dev, GFP_KERNEL, &context,
|
2005-09-17 09:28:04 +07:00
|
|
|
callbackfn_rbu);
|
|
|
|
if (req_firm_rc) {
|
|
|
|
printk(KERN_ERR
|
|
|
|
"dell_rbu:%s request_firmware_nowait"
|
2008-04-29 14:59:19 +07:00
|
|
|
" failed %d\n", __func__, rc);
|
2005-09-17 09:28:04 +07:00
|
|
|
rc = -EIO;
|
|
|
|
} else
|
|
|
|
rbu_data.entry_created = 1;
|
|
|
|
|
|
|
|
spin_lock(&rbu_data.lock);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
printk(KERN_WARNING "dell_rbu: image_type is invalid\n");
|
|
|
|
spin_unlock(&rbu_data.lock);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2005-09-07 05:17:14 +07:00
|
|
|
|
|
|
|
/* we must free all previous allocations */
|
|
|
|
packet_empty_list();
|
|
|
|
img_update_free();
|
|
|
|
spin_unlock(&rbu_data.lock);
|
|
|
|
|
2005-09-17 09:28:04 +07:00
|
|
|
return rc;
|
2005-09-07 05:17:14 +07:00
|
|
|
}
|
|
|
|
|
2010-05-13 08:28:57 +07:00
|
|
|
static ssize_t read_rbu_packet_size(struct file *filp, struct kobject *kobj,
|
2007-06-09 12:57:22 +07:00
|
|
|
struct bin_attribute *bin_attr,
|
|
|
|
char *buffer, loff_t pos, size_t count)
|
2005-10-11 22:29:02 +07:00
|
|
|
{
|
|
|
|
int size = 0;
|
|
|
|
if (!pos) {
|
|
|
|
spin_lock(&rbu_data.lock);
|
2009-01-18 01:33:03 +07:00
|
|
|
size = scnprintf(buffer, count, "%lu\n", rbu_data.packetsize);
|
2005-10-11 22:29:02 +07:00
|
|
|
spin_unlock(&rbu_data.lock);
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2010-05-13 08:28:57 +07:00
|
|
|
static ssize_t write_rbu_packet_size(struct file *filp, struct kobject *kobj,
|
2007-06-09 12:57:22 +07:00
|
|
|
struct bin_attribute *bin_attr,
|
|
|
|
char *buffer, loff_t pos, size_t count)
|
2005-10-11 22:29:02 +07:00
|
|
|
{
|
|
|
|
unsigned long temp;
|
|
|
|
spin_lock(&rbu_data.lock);
|
|
|
|
packet_empty_list();
|
|
|
|
sscanf(buffer, "%lu", &temp);
|
|
|
|
if (temp < 0xffffffff)
|
|
|
|
rbu_data.packetsize = temp;
|
|
|
|
|
|
|
|
spin_unlock(&rbu_data.lock);
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2005-09-07 05:17:14 +07:00
|
|
|
static struct bin_attribute rbu_data_attr = {
|
2007-06-14 01:45:17 +07:00
|
|
|
.attr = {.name = "data", .mode = 0444},
|
2005-09-07 05:17:14 +07:00
|
|
|
.read = read_rbu_data,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct bin_attribute rbu_image_type_attr = {
|
2007-06-14 01:45:17 +07:00
|
|
|
.attr = {.name = "image_type", .mode = 0644},
|
2005-09-07 05:17:14 +07:00
|
|
|
.read = read_rbu_image_type,
|
|
|
|
.write = write_rbu_image_type,
|
|
|
|
};
|
|
|
|
|
2005-10-11 22:29:02 +07:00
|
|
|
static struct bin_attribute rbu_packet_size_attr = {
|
2007-06-14 01:45:17 +07:00
|
|
|
.attr = {.name = "packet_size", .mode = 0644},
|
2005-10-11 22:29:02 +07:00
|
|
|
.read = read_rbu_packet_size,
|
|
|
|
.write = write_rbu_packet_size,
|
|
|
|
};
|
|
|
|
|
2005-09-17 09:28:05 +07:00
|
|
|
static int __init dcdrbu_init(void)
|
2005-09-07 05:17:14 +07:00
|
|
|
{
|
2006-11-16 16:19:25 +07:00
|
|
|
int rc;
|
2005-09-07 05:17:14 +07:00
|
|
|
spin_lock_init(&rbu_data.lock);
|
|
|
|
|
|
|
|
init_packet_head();
|
2006-11-16 16:19:25 +07:00
|
|
|
rbu_device = platform_device_register_simple("dell_rbu", -1, NULL, 0);
|
|
|
|
if (IS_ERR(rbu_device)) {
|
2005-09-07 05:17:14 +07:00
|
|
|
printk(KERN_ERR
|
2005-09-17 09:28:04 +07:00
|
|
|
"dell_rbu:%s:platform_device_register_simple "
|
2008-04-29 14:59:19 +07:00
|
|
|
"failed\n", __func__);
|
2006-11-16 16:19:25 +07:00
|
|
|
return PTR_ERR(rbu_device);
|
2005-09-07 05:17:14 +07:00
|
|
|
}
|
|
|
|
|
2006-10-11 15:22:20 +07:00
|
|
|
rc = sysfs_create_bin_file(&rbu_device->dev.kobj, &rbu_data_attr);
|
|
|
|
if (rc)
|
|
|
|
goto out_devreg;
|
|
|
|
rc = sysfs_create_bin_file(&rbu_device->dev.kobj, &rbu_image_type_attr);
|
|
|
|
if (rc)
|
|
|
|
goto out_data;
|
|
|
|
rc = sysfs_create_bin_file(&rbu_device->dev.kobj,
|
2005-10-11 22:29:02 +07:00
|
|
|
&rbu_packet_size_attr);
|
2006-10-11 15:22:20 +07:00
|
|
|
if (rc)
|
|
|
|
goto out_imtype;
|
2005-09-07 05:17:14 +07:00
|
|
|
|
2006-01-15 04:21:14 +07:00
|
|
|
rbu_data.entry_created = 0;
|
2006-10-11 15:22:20 +07:00
|
|
|
return 0;
|
2005-09-07 05:17:14 +07:00
|
|
|
|
2006-10-11 15:22:20 +07:00
|
|
|
out_imtype:
|
|
|
|
sysfs_remove_bin_file(&rbu_device->dev.kobj, &rbu_image_type_attr);
|
|
|
|
out_data:
|
|
|
|
sysfs_remove_bin_file(&rbu_device->dev.kobj, &rbu_data_attr);
|
|
|
|
out_devreg:
|
|
|
|
platform_device_unregister(rbu_device);
|
|
|
|
return rc;
|
2005-09-07 05:17:14 +07:00
|
|
|
}
|
|
|
|
|
2005-09-17 09:28:05 +07:00
|
|
|
static __exit void dcdrbu_exit(void)
|
2005-09-07 05:17:14 +07:00
|
|
|
{
|
|
|
|
spin_lock(&rbu_data.lock);
|
|
|
|
packet_empty_list();
|
|
|
|
img_update_free();
|
|
|
|
spin_unlock(&rbu_data.lock);
|
|
|
|
platform_device_unregister(rbu_device);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_exit(dcdrbu_exit);
|
|
|
|
module_init(dcdrbu_init);
|
2005-11-07 15:59:26 +07:00
|
|
|
|
|
|
|
/* vim:noet:ts=8:sw=8
|
|
|
|
*/
|