Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 1 | /* |
| 2 | * dell_rbu.c |
| 3 | * Bios Update driver for Dell systems |
| 4 | * Author: Dell Inc |
| 5 | * Abhay Salunke <abhay_salunke@dell.com> |
| 6 | * |
| 7 | * Copyright (C) 2005 Dell Inc. |
| 8 | * |
| 9 | * Remote BIOS Update (rbu) driver is used for updating DELL BIOS by |
| 10 | * creating entries in the /sys file systems on Linux 2.6 and higher |
| 11 | * kernels. The driver supports two mechanism to update the BIOS namely |
| 12 | * contiguous and packetized. Both these methods still require having some |
| 13 | * application to set the CMOS bit indicating the BIOS to update itself |
| 14 | * after a reboot. |
| 15 | * |
| 16 | * Contiguous method: |
| 17 | * This driver writes the incoming data in a monolithic image by allocating |
| 18 | * contiguous physical pages large enough to accommodate the incoming BIOS |
| 19 | * image size. |
| 20 | * |
| 21 | * Packetized method: |
| 22 | * The driver writes the incoming packet image by allocating a new packet |
| 23 | * on every time the packet data is written. This driver requires an |
| 24 | * application to break the BIOS image in to fixed sized packet chunks. |
| 25 | * |
| 26 | * See Documentation/dell_rbu.txt for more info. |
| 27 | * |
| 28 | * This program is free software; you can redistribute it and/or modify |
| 29 | * it under the terms of the GNU General Public License v2.0 as published by |
| 30 | * the Free Software Foundation |
| 31 | * |
| 32 | * This program is distributed in the hope that it will be useful, |
| 33 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 34 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 35 | * GNU General Public License for more details. |
| 36 | */ |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 37 | #include <linux/init.h> |
| 38 | #include <linux/module.h> |
| 39 | #include <linux/string.h> |
| 40 | #include <linux/errno.h> |
| 41 | #include <linux/blkdev.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 42 | #include <linux/platform_device.h> |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 43 | #include <linux/spinlock.h> |
| 44 | #include <linux/moduleparam.h> |
| 45 | #include <linux/firmware.h> |
| 46 | #include <linux/dma-mapping.h> |
| 47 | |
| 48 | MODULE_AUTHOR("Abhay Salunke <abhay_salunke@dell.com>"); |
| 49 | MODULE_DESCRIPTION("Driver for updating BIOS image on DELL systems"); |
| 50 | MODULE_LICENSE("GPL"); |
Abhay Salunke | 2c56084 | 2006-01-14 13:21:14 -0800 | [diff] [blame] | 51 | MODULE_VERSION("3.2"); |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 52 | |
| 53 | #define BIOS_SCAN_LIMIT 0xffffffff |
| 54 | #define MAX_IMAGE_LENGTH 16 |
| 55 | static struct _rbu_data { |
| 56 | void *image_update_buffer; |
| 57 | unsigned long image_update_buffer_size; |
| 58 | unsigned long bios_image_size; |
| 59 | int image_update_ordernum; |
| 60 | int dma_alloc; |
| 61 | spinlock_t lock; |
| 62 | unsigned long packet_read_count; |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 63 | unsigned long num_packets; |
| 64 | unsigned long packetsize; |
Abhay Salunke | ad6ce87 | 2005-10-11 08:29:02 -0700 | [diff] [blame] | 65 | unsigned long imagesize; |
Abhay Salunke | e61c0e3 | 2005-09-16 19:28:04 -0700 | [diff] [blame] | 66 | int entry_created; |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 67 | } rbu_data; |
| 68 | |
Abhay Salunke | e61c0e3 | 2005-09-16 19:28:04 -0700 | [diff] [blame] | 69 | static char image_type[MAX_IMAGE_LENGTH + 1] = "mono"; |
| 70 | module_param_string(image_type, image_type, sizeof (image_type), 0); |
Abhay Salunke | ad6ce87 | 2005-10-11 08:29:02 -0700 | [diff] [blame] | 71 | MODULE_PARM_DESC(image_type, |
| 72 | "BIOS image type. choose- mono or packet or init"); |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 73 | |
Abhay Salunke | 274b693 | 2005-11-07 00:59:26 -0800 | [diff] [blame] | 74 | static unsigned long allocation_floor = 0x100000; |
| 75 | module_param(allocation_floor, ulong, 0644); |
| 76 | MODULE_PARM_DESC(allocation_floor, |
| 77 | "Minimum address for allocations when using Packet mode"); |
| 78 | |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 79 | struct packet_data { |
| 80 | struct list_head list; |
| 81 | size_t length; |
| 82 | void *data; |
| 83 | int ordernum; |
| 84 | }; |
| 85 | |
| 86 | static struct packet_data packet_data_head; |
| 87 | |
| 88 | static struct platform_device *rbu_device; |
| 89 | static int context; |
| 90 | static dma_addr_t dell_rbu_dmaaddr; |
| 91 | |
Andrew Morton | dda8577 | 2005-09-16 19:28:05 -0700 | [diff] [blame] | 92 | static void init_packet_head(void) |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 93 | { |
| 94 | INIT_LIST_HEAD(&packet_data_head.list); |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 95 | rbu_data.packet_read_count = 0; |
| 96 | rbu_data.num_packets = 0; |
| 97 | rbu_data.packetsize = 0; |
Abhay Salunke | ad6ce87 | 2005-10-11 08:29:02 -0700 | [diff] [blame] | 98 | rbu_data.imagesize = 0; |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Abhay Salunke | ad6ce87 | 2005-10-11 08:29:02 -0700 | [diff] [blame] | 101 | static int create_packet(void *data, size_t length) |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 102 | { |
| 103 | struct packet_data *newpacket; |
| 104 | int ordernum = 0; |
Abhay Salunke | 274b693 | 2005-11-07 00:59:26 -0800 | [diff] [blame] | 105 | int retval = 0; |
| 106 | unsigned int packet_array_size = 0; |
Al Viro | 5ad9201 | 2005-12-15 09:18:00 +0000 | [diff] [blame] | 107 | void **invalid_addr_packet_array = NULL; |
| 108 | void *packet_data_temp_buf = NULL; |
Abhay Salunke | 274b693 | 2005-11-07 00:59:26 -0800 | [diff] [blame] | 109 | unsigned int idx = 0; |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 110 | |
| 111 | pr_debug("create_packet: entry \n"); |
| 112 | |
| 113 | if (!rbu_data.packetsize) { |
| 114 | pr_debug("create_packet: packetsize not specified\n"); |
Abhay Salunke | 274b693 | 2005-11-07 00:59:26 -0800 | [diff] [blame] | 115 | retval = -EINVAL; |
| 116 | goto out_noalloc; |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 117 | } |
Abhay Salunke | 274b693 | 2005-11-07 00:59:26 -0800 | [diff] [blame] | 118 | |
Abhay Salunke | e61c0e3 | 2005-09-16 19:28:04 -0700 | [diff] [blame] | 119 | spin_unlock(&rbu_data.lock); |
Abhay Salunke | 274b693 | 2005-11-07 00:59:26 -0800 | [diff] [blame] | 120 | |
| 121 | newpacket = kzalloc(sizeof (struct packet_data), GFP_KERNEL); |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 122 | |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 123 | if (!newpacket) { |
| 124 | printk(KERN_WARNING |
Abhay Salunke | e61c0e3 | 2005-09-16 19:28:04 -0700 | [diff] [blame] | 125 | "dell_rbu:%s: failed to allocate new " |
Harvey Harrison | eecd585 | 2008-04-29 00:59:19 -0700 | [diff] [blame] | 126 | "packet\n", __func__); |
Abhay Salunke | 274b693 | 2005-11-07 00:59:26 -0800 | [diff] [blame] | 127 | retval = -ENOMEM; |
| 128 | spin_lock(&rbu_data.lock); |
| 129 | goto out_noalloc; |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | ordernum = get_order(length); |
Abhay Salunke | 274b693 | 2005-11-07 00:59:26 -0800 | [diff] [blame] | 133 | |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 134 | /* |
Abhay Salunke | 274b693 | 2005-11-07 00:59:26 -0800 | [diff] [blame] | 135 | * BIOS errata mean we cannot allocate packets below 1MB or they will |
| 136 | * be overwritten by BIOS. |
| 137 | * |
| 138 | * array to temporarily hold packets |
| 139 | * that are below the allocation floor |
| 140 | * |
| 141 | * NOTE: very simplistic because we only need the floor to be at 1MB |
| 142 | * due to BIOS errata. This shouldn't be used for higher floors |
| 143 | * or you will run out of mem trying to allocate the array. |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 144 | */ |
Abhay Salunke | 274b693 | 2005-11-07 00:59:26 -0800 | [diff] [blame] | 145 | packet_array_size = max( |
| 146 | (unsigned int)(allocation_floor / rbu_data.packetsize), |
| 147 | (unsigned int)1); |
| 148 | invalid_addr_packet_array = kzalloc(packet_array_size * sizeof(void*), |
| 149 | GFP_KERNEL); |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 150 | |
Abhay Salunke | 274b693 | 2005-11-07 00:59:26 -0800 | [diff] [blame] | 151 | if (!invalid_addr_packet_array) { |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 152 | printk(KERN_WARNING |
Abhay Salunke | 274b693 | 2005-11-07 00:59:26 -0800 | [diff] [blame] | 153 | "dell_rbu:%s: failed to allocate " |
| 154 | "invalid_addr_packet_array \n", |
Harvey Harrison | eecd585 | 2008-04-29 00:59:19 -0700 | [diff] [blame] | 155 | __func__); |
Abhay Salunke | 274b693 | 2005-11-07 00:59:26 -0800 | [diff] [blame] | 156 | retval = -ENOMEM; |
| 157 | spin_lock(&rbu_data.lock); |
| 158 | goto out_alloc_packet; |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Abhay Salunke | 274b693 | 2005-11-07 00:59:26 -0800 | [diff] [blame] | 161 | while (!packet_data_temp_buf) { |
| 162 | packet_data_temp_buf = (unsigned char *) |
| 163 | __get_free_pages(GFP_KERNEL, ordernum); |
| 164 | if (!packet_data_temp_buf) { |
| 165 | printk(KERN_WARNING |
| 166 | "dell_rbu:%s: failed to allocate new " |
Harvey Harrison | eecd585 | 2008-04-29 00:59:19 -0700 | [diff] [blame] | 167 | "packet\n", __func__); |
Abhay Salunke | 274b693 | 2005-11-07 00:59:26 -0800 | [diff] [blame] | 168 | retval = -ENOMEM; |
| 169 | spin_lock(&rbu_data.lock); |
| 170 | goto out_alloc_packet_array; |
| 171 | } |
| 172 | |
| 173 | if ((unsigned long)virt_to_phys(packet_data_temp_buf) |
| 174 | < allocation_floor) { |
| 175 | pr_debug("packet 0x%lx below floor at 0x%lx.\n", |
| 176 | (unsigned long)virt_to_phys( |
| 177 | packet_data_temp_buf), |
| 178 | allocation_floor); |
| 179 | invalid_addr_packet_array[idx++] = packet_data_temp_buf; |
Al Viro | 5ad9201 | 2005-12-15 09:18:00 +0000 | [diff] [blame] | 180 | packet_data_temp_buf = NULL; |
Abhay Salunke | 274b693 | 2005-11-07 00:59:26 -0800 | [diff] [blame] | 181 | } |
| 182 | } |
| 183 | spin_lock(&rbu_data.lock); |
| 184 | |
| 185 | newpacket->data = packet_data_temp_buf; |
| 186 | |
| 187 | pr_debug("create_packet: newpacket at physical addr %lx\n", |
| 188 | (unsigned long)virt_to_phys(newpacket->data)); |
| 189 | |
| 190 | /* packets may not have fixed size */ |
| 191 | newpacket->length = length; |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 192 | newpacket->ordernum = ordernum; |
| 193 | ++rbu_data.num_packets; |
Abhay Salunke | 274b693 | 2005-11-07 00:59:26 -0800 | [diff] [blame] | 194 | |
| 195 | /* initialize the newly created packet headers */ |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 196 | INIT_LIST_HEAD(&newpacket->list); |
| 197 | list_add_tail(&newpacket->list, &packet_data_head.list); |
Abhay Salunke | ad6ce87 | 2005-10-11 08:29:02 -0700 | [diff] [blame] | 198 | |
| 199 | memcpy(newpacket->data, data, length); |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 200 | |
| 201 | pr_debug("create_packet: exit \n"); |
| 202 | |
Abhay Salunke | 274b693 | 2005-11-07 00:59:26 -0800 | [diff] [blame] | 203 | out_alloc_packet_array: |
| 204 | /* always free packet array */ |
| 205 | for (;idx>0;idx--) { |
| 206 | pr_debug("freeing unused packet below floor 0x%lx.\n", |
| 207 | (unsigned long)virt_to_phys( |
| 208 | invalid_addr_packet_array[idx-1])); |
| 209 | free_pages((unsigned long)invalid_addr_packet_array[idx-1], |
| 210 | ordernum); |
| 211 | } |
| 212 | kfree(invalid_addr_packet_array); |
| 213 | |
| 214 | out_alloc_packet: |
| 215 | /* if error, free data */ |
| 216 | if (retval) |
| 217 | kfree(newpacket); |
| 218 | |
| 219 | out_noalloc: |
| 220 | return retval; |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Greg Kroah-Hartman | c6c1c94 | 2008-05-29 10:05:08 -0700 | [diff] [blame] | 223 | static int packetize_data(const u8 *data, size_t length) |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 224 | { |
| 225 | int rc = 0; |
Abhay Salunke | ad6ce87 | 2005-10-11 08:29:02 -0700 | [diff] [blame] | 226 | int done = 0; |
| 227 | int packet_length; |
| 228 | u8 *temp; |
| 229 | u8 *end = (u8 *) data + length; |
Zach Brown | cb7cf57 | 2006-10-03 01:16:09 -0700 | [diff] [blame] | 230 | pr_debug("packetize_data: data length %zd\n", length); |
Abhay Salunke | ad6ce87 | 2005-10-11 08:29:02 -0700 | [diff] [blame] | 231 | if (!rbu_data.packetsize) { |
| 232 | printk(KERN_WARNING |
| 233 | "dell_rbu: packetsize not specified\n"); |
| 234 | return -EIO; |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 235 | } |
Abhay Salunke | ad6ce87 | 2005-10-11 08:29:02 -0700 | [diff] [blame] | 236 | |
| 237 | temp = (u8 *) data; |
| 238 | |
| 239 | /* packetize the hunk */ |
| 240 | while (!done) { |
| 241 | if ((temp + rbu_data.packetsize) < end) |
| 242 | packet_length = rbu_data.packetsize; |
| 243 | else { |
| 244 | /* this is the last packet */ |
| 245 | packet_length = end - temp; |
| 246 | done = 1; |
| 247 | } |
| 248 | |
| 249 | if ((rc = create_packet(temp, packet_length))) |
| 250 | return rc; |
| 251 | |
Andrew Morton | 9e42ef7 | 2006-10-11 01:22:13 -0700 | [diff] [blame] | 252 | pr_debug("%p:%td\n", temp, (end - temp)); |
Abhay Salunke | ad6ce87 | 2005-10-11 08:29:02 -0700 | [diff] [blame] | 253 | temp += packet_length; |
| 254 | } |
| 255 | |
| 256 | rbu_data.imagesize = length; |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 257 | |
| 258 | return rc; |
| 259 | } |
| 260 | |
Andrew Morton | dda8577 | 2005-09-16 19:28:05 -0700 | [diff] [blame] | 261 | static int do_packet_read(char *data, struct list_head *ptemp_list, |
Abhay Salunke | e61c0e3 | 2005-09-16 19:28:04 -0700 | [diff] [blame] | 262 | int length, int bytes_read, int *list_read_count) |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 263 | { |
| 264 | void *ptemp_buf; |
| 265 | struct packet_data *newpacket = NULL; |
| 266 | int bytes_copied = 0; |
| 267 | int j = 0; |
| 268 | |
| 269 | newpacket = list_entry(ptemp_list, struct packet_data, list); |
| 270 | *list_read_count += newpacket->length; |
| 271 | |
| 272 | if (*list_read_count > bytes_read) { |
| 273 | /* point to the start of unread data */ |
| 274 | j = newpacket->length - (*list_read_count - bytes_read); |
| 275 | /* point to the offset in the packet buffer */ |
| 276 | ptemp_buf = (u8 *) newpacket->data + j; |
| 277 | /* |
| 278 | * check if there is enough room in |
| 279 | * * the incoming buffer |
| 280 | */ |
| 281 | if (length > (*list_read_count - bytes_read)) |
| 282 | /* |
| 283 | * copy what ever is there in this |
| 284 | * packet and move on |
| 285 | */ |
| 286 | bytes_copied = (*list_read_count - bytes_read); |
| 287 | else |
| 288 | /* copy the remaining */ |
| 289 | bytes_copied = length; |
| 290 | memcpy(data, ptemp_buf, bytes_copied); |
| 291 | } |
| 292 | return bytes_copied; |
| 293 | } |
| 294 | |
Abhay Salunke | ad6ce87 | 2005-10-11 08:29:02 -0700 | [diff] [blame] | 295 | static int packet_read_list(char *data, size_t * pread_length) |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 296 | { |
| 297 | struct list_head *ptemp_list; |
| 298 | int temp_count = 0; |
| 299 | int bytes_copied = 0; |
| 300 | int bytes_read = 0; |
| 301 | int remaining_bytes = 0; |
| 302 | char *pdest = data; |
| 303 | |
| 304 | /* check if we have any packets */ |
| 305 | if (0 == rbu_data.num_packets) |
| 306 | return -ENOMEM; |
| 307 | |
| 308 | remaining_bytes = *pread_length; |
| 309 | bytes_read = rbu_data.packet_read_count; |
| 310 | |
| 311 | ptemp_list = (&packet_data_head.list)->next; |
| 312 | while (!list_empty(ptemp_list)) { |
| 313 | bytes_copied = do_packet_read(pdest, ptemp_list, |
Abhay Salunke | e61c0e3 | 2005-09-16 19:28:04 -0700 | [diff] [blame] | 314 | remaining_bytes, bytes_read, &temp_count); |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 315 | remaining_bytes -= bytes_copied; |
| 316 | bytes_read += bytes_copied; |
| 317 | pdest += bytes_copied; |
| 318 | /* |
| 319 | * check if we reached end of buffer before reaching the |
| 320 | * last packet |
| 321 | */ |
| 322 | if (remaining_bytes == 0) |
| 323 | break; |
| 324 | |
| 325 | ptemp_list = ptemp_list->next; |
| 326 | } |
| 327 | /*finally set the bytes read */ |
| 328 | *pread_length = bytes_read - rbu_data.packet_read_count; |
| 329 | rbu_data.packet_read_count = bytes_read; |
| 330 | return 0; |
| 331 | } |
| 332 | |
Andrew Morton | dda8577 | 2005-09-16 19:28:05 -0700 | [diff] [blame] | 333 | static void packet_empty_list(void) |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 334 | { |
| 335 | struct list_head *ptemp_list; |
| 336 | struct list_head *pnext_list; |
| 337 | struct packet_data *newpacket; |
| 338 | |
| 339 | ptemp_list = (&packet_data_head.list)->next; |
| 340 | while (!list_empty(ptemp_list)) { |
| 341 | newpacket = |
Abhay Salunke | e61c0e3 | 2005-09-16 19:28:04 -0700 | [diff] [blame] | 342 | list_entry(ptemp_list, struct packet_data, list); |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 343 | pnext_list = ptemp_list->next; |
| 344 | list_del(ptemp_list); |
| 345 | ptemp_list = pnext_list; |
| 346 | /* |
| 347 | * zero out the RBU packet memory before freeing |
| 348 | * to make sure there are no stale RBU packets left in memory |
| 349 | */ |
| 350 | memset(newpacket->data, 0, rbu_data.packetsize); |
Abhay Salunke | e61c0e3 | 2005-09-16 19:28:04 -0700 | [diff] [blame] | 351 | free_pages((unsigned long) newpacket->data, |
| 352 | newpacket->ordernum); |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 353 | kfree(newpacket); |
| 354 | } |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 355 | rbu_data.packet_read_count = 0; |
| 356 | rbu_data.num_packets = 0; |
Abhay Salunke | ad6ce87 | 2005-10-11 08:29:02 -0700 | [diff] [blame] | 357 | rbu_data.imagesize = 0; |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | /* |
| 361 | * img_update_free: Frees the buffer allocated for storing BIOS image |
| 362 | * Always called with lock held and returned with lock held |
| 363 | */ |
Andrew Morton | dda8577 | 2005-09-16 19:28:05 -0700 | [diff] [blame] | 364 | static void img_update_free(void) |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 365 | { |
| 366 | if (!rbu_data.image_update_buffer) |
| 367 | return; |
| 368 | /* |
| 369 | * zero out this buffer before freeing it to get rid of any stale |
| 370 | * BIOS image copied in memory. |
| 371 | */ |
| 372 | memset(rbu_data.image_update_buffer, 0, |
Abhay Salunke | e61c0e3 | 2005-09-16 19:28:04 -0700 | [diff] [blame] | 373 | rbu_data.image_update_buffer_size); |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 374 | if (rbu_data.dma_alloc == 1) |
| 375 | dma_free_coherent(NULL, rbu_data.bios_image_size, |
Abhay Salunke | e61c0e3 | 2005-09-16 19:28:04 -0700 | [diff] [blame] | 376 | rbu_data.image_update_buffer, dell_rbu_dmaaddr); |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 377 | else |
Abhay Salunke | e61c0e3 | 2005-09-16 19:28:04 -0700 | [diff] [blame] | 378 | free_pages((unsigned long) rbu_data.image_update_buffer, |
| 379 | rbu_data.image_update_ordernum); |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 380 | |
| 381 | /* |
| 382 | * Re-initialize the rbu_data variables after a free |
| 383 | */ |
| 384 | rbu_data.image_update_ordernum = -1; |
| 385 | rbu_data.image_update_buffer = NULL; |
| 386 | rbu_data.image_update_buffer_size = 0; |
| 387 | rbu_data.bios_image_size = 0; |
| 388 | rbu_data.dma_alloc = 0; |
| 389 | } |
| 390 | |
| 391 | /* |
| 392 | * img_update_realloc: This function allocates the contiguous pages to |
| 393 | * accommodate the requested size of data. The memory address and size |
| 394 | * values are stored globally and on every call to this function the new |
| 395 | * size is checked to see if more data is required than the existing size. |
| 396 | * If true the previous memory is freed and new allocation is done to |
| 397 | * accommodate the new size. If the incoming size is less then than the |
| 398 | * already allocated size, then that memory is reused. This function is |
| 399 | * called with lock held and returns with lock held. |
| 400 | */ |
Andrew Morton | dda8577 | 2005-09-16 19:28:05 -0700 | [diff] [blame] | 401 | static int img_update_realloc(unsigned long size) |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 402 | { |
| 403 | unsigned char *image_update_buffer = NULL; |
| 404 | unsigned long rc; |
| 405 | unsigned long img_buf_phys_addr; |
| 406 | int ordernum; |
| 407 | int dma_alloc = 0; |
| 408 | |
| 409 | /* |
| 410 | * check if the buffer of sufficient size has been |
| 411 | * already allocated |
| 412 | */ |
| 413 | if (rbu_data.image_update_buffer_size >= size) { |
| 414 | /* |
| 415 | * check for corruption |
| 416 | */ |
| 417 | if ((size != 0) && (rbu_data.image_update_buffer == NULL)) { |
| 418 | printk(KERN_ERR "dell_rbu:%s: corruption " |
Harvey Harrison | eecd585 | 2008-04-29 00:59:19 -0700 | [diff] [blame] | 419 | "check failed\n", __func__); |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 420 | return -EINVAL; |
| 421 | } |
| 422 | /* |
| 423 | * we have a valid pre-allocated buffer with |
| 424 | * sufficient size |
| 425 | */ |
| 426 | return 0; |
| 427 | } |
| 428 | |
| 429 | /* |
| 430 | * free any previously allocated buffer |
| 431 | */ |
| 432 | img_update_free(); |
| 433 | |
| 434 | spin_unlock(&rbu_data.lock); |
| 435 | |
| 436 | ordernum = get_order(size); |
| 437 | image_update_buffer = |
Abhay Salunke | e61c0e3 | 2005-09-16 19:28:04 -0700 | [diff] [blame] | 438 | (unsigned char *) __get_free_pages(GFP_KERNEL, ordernum); |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 439 | |
| 440 | img_buf_phys_addr = |
Abhay Salunke | e61c0e3 | 2005-09-16 19:28:04 -0700 | [diff] [blame] | 441 | (unsigned long) virt_to_phys(image_update_buffer); |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 442 | |
| 443 | if (img_buf_phys_addr > BIOS_SCAN_LIMIT) { |
Abhay Salunke | e61c0e3 | 2005-09-16 19:28:04 -0700 | [diff] [blame] | 444 | free_pages((unsigned long) image_update_buffer, ordernum); |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 445 | ordernum = -1; |
| 446 | image_update_buffer = dma_alloc_coherent(NULL, size, |
Abhay Salunke | e61c0e3 | 2005-09-16 19:28:04 -0700 | [diff] [blame] | 447 | &dell_rbu_dmaaddr, GFP_KERNEL); |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 448 | dma_alloc = 1; |
| 449 | } |
| 450 | |
| 451 | spin_lock(&rbu_data.lock); |
| 452 | |
| 453 | if (image_update_buffer != NULL) { |
| 454 | rbu_data.image_update_buffer = image_update_buffer; |
| 455 | rbu_data.image_update_buffer_size = size; |
| 456 | rbu_data.bios_image_size = |
Abhay Salunke | e61c0e3 | 2005-09-16 19:28:04 -0700 | [diff] [blame] | 457 | rbu_data.image_update_buffer_size; |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 458 | rbu_data.image_update_ordernum = ordernum; |
| 459 | rbu_data.dma_alloc = dma_alloc; |
| 460 | rc = 0; |
| 461 | } else { |
| 462 | pr_debug("Not enough memory for image update:" |
Abhay Salunke | e61c0e3 | 2005-09-16 19:28:04 -0700 | [diff] [blame] | 463 | "size = %ld\n", size); |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 464 | rc = -ENOMEM; |
| 465 | } |
| 466 | |
| 467 | return rc; |
| 468 | } |
| 469 | |
Andrew Morton | dda8577 | 2005-09-16 19:28:05 -0700 | [diff] [blame] | 470 | static ssize_t read_packet_data(char *buffer, loff_t pos, size_t count) |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 471 | { |
| 472 | int retval; |
| 473 | size_t bytes_left; |
| 474 | size_t data_length; |
| 475 | char *ptempBuf = buffer; |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 476 | |
| 477 | /* check to see if we have something to return */ |
| 478 | if (rbu_data.num_packets == 0) { |
| 479 | pr_debug("read_packet_data: no packets written\n"); |
| 480 | retval = -ENOMEM; |
| 481 | goto read_rbu_data_exit; |
| 482 | } |
| 483 | |
Abhay Salunke | ad6ce87 | 2005-10-11 08:29:02 -0700 | [diff] [blame] | 484 | if (pos > rbu_data.imagesize) { |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 485 | retval = 0; |
| 486 | printk(KERN_WARNING "dell_rbu:read_packet_data: " |
Abhay Salunke | e61c0e3 | 2005-09-16 19:28:04 -0700 | [diff] [blame] | 487 | "data underrun\n"); |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 488 | goto read_rbu_data_exit; |
| 489 | } |
| 490 | |
Abhay Salunke | ad6ce87 | 2005-10-11 08:29:02 -0700 | [diff] [blame] | 491 | bytes_left = rbu_data.imagesize - pos; |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 492 | data_length = min(bytes_left, count); |
| 493 | |
| 494 | if ((retval = packet_read_list(ptempBuf, &data_length)) < 0) |
| 495 | goto read_rbu_data_exit; |
| 496 | |
Abhay Salunke | ad6ce87 | 2005-10-11 08:29:02 -0700 | [diff] [blame] | 497 | if ((pos + count) > rbu_data.imagesize) { |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 498 | rbu_data.packet_read_count = 0; |
| 499 | /* this was the last copy */ |
| 500 | retval = bytes_left; |
| 501 | } else |
| 502 | retval = count; |
| 503 | |
| 504 | read_rbu_data_exit: |
| 505 | return retval; |
| 506 | } |
| 507 | |
Andrew Morton | dda8577 | 2005-09-16 19:28:05 -0700 | [diff] [blame] | 508 | static ssize_t read_rbu_mono_data(char *buffer, loff_t pos, size_t count) |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 509 | { |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 510 | /* check to see if we have something to return */ |
| 511 | if ((rbu_data.image_update_buffer == NULL) || |
Abhay Salunke | e61c0e3 | 2005-09-16 19:28:04 -0700 | [diff] [blame] | 512 | (rbu_data.bios_image_size == 0)) { |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 513 | pr_debug("read_rbu_data_mono: image_update_buffer %p ," |
Abhay Salunke | e61c0e3 | 2005-09-16 19:28:04 -0700 | [diff] [blame] | 514 | "bios_image_size %lu\n", |
| 515 | rbu_data.image_update_buffer, |
| 516 | rbu_data.bios_image_size); |
Akinobu Mita | 2537747 | 2008-07-25 01:48:27 -0700 | [diff] [blame] | 517 | return -ENOMEM; |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 518 | } |
| 519 | |
Akinobu Mita | 2537747 | 2008-07-25 01:48:27 -0700 | [diff] [blame] | 520 | return memory_read_from_buffer(buffer, count, &pos, |
| 521 | rbu_data.image_update_buffer, rbu_data.bios_image_size); |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 522 | } |
| 523 | |
Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 524 | static ssize_t read_rbu_data(struct kobject *kobj, |
| 525 | struct bin_attribute *bin_attr, |
| 526 | char *buffer, loff_t pos, size_t count) |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 527 | { |
| 528 | ssize_t ret_count = 0; |
| 529 | |
| 530 | spin_lock(&rbu_data.lock); |
| 531 | |
| 532 | if (!strcmp(image_type, "mono")) |
| 533 | ret_count = read_rbu_mono_data(buffer, pos, count); |
| 534 | else if (!strcmp(image_type, "packet")) |
| 535 | ret_count = read_packet_data(buffer, pos, count); |
| 536 | else |
| 537 | pr_debug("read_rbu_data: invalid image type specified\n"); |
| 538 | |
| 539 | spin_unlock(&rbu_data.lock); |
| 540 | return ret_count; |
| 541 | } |
| 542 | |
Andrew Morton | dda8577 | 2005-09-16 19:28:05 -0700 | [diff] [blame] | 543 | static void callbackfn_rbu(const struct firmware *fw, void *context) |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 544 | { |
Abhay Salunke | 2c56084 | 2006-01-14 13:21:14 -0800 | [diff] [blame] | 545 | rbu_data.entry_created = 0; |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 546 | |
Abhay Salunke | 2c56084 | 2006-01-14 13:21:14 -0800 | [diff] [blame] | 547 | if (!fw || !fw->size) |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 548 | return; |
| 549 | |
| 550 | spin_lock(&rbu_data.lock); |
| 551 | if (!strcmp(image_type, "mono")) { |
| 552 | if (!img_update_realloc(fw->size)) |
| 553 | memcpy(rbu_data.image_update_buffer, |
Abhay Salunke | e61c0e3 | 2005-09-16 19:28:04 -0700 | [diff] [blame] | 554 | fw->data, fw->size); |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 555 | } else if (!strcmp(image_type, "packet")) { |
Abhay Salunke | ad6ce87 | 2005-10-11 08:29:02 -0700 | [diff] [blame] | 556 | /* |
| 557 | * we need to free previous packets if a |
| 558 | * new hunk of packets needs to be downloaded |
| 559 | */ |
| 560 | packet_empty_list(); |
| 561 | if (packetize_data(fw->data, fw->size)) |
| 562 | /* Incase something goes wrong when we are |
| 563 | * in middle of packetizing the data, we |
| 564 | * need to free up whatever packets might |
| 565 | * have been created before we quit. |
| 566 | */ |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 567 | packet_empty_list(); |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 568 | } else |
| 569 | pr_debug("invalid image type specified.\n"); |
| 570 | spin_unlock(&rbu_data.lock); |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 571 | } |
| 572 | |
Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 573 | static ssize_t read_rbu_image_type(struct kobject *kobj, |
| 574 | struct bin_attribute *bin_attr, |
| 575 | char *buffer, loff_t pos, size_t count) |
Abhay Salunke | e61c0e3 | 2005-09-16 19:28:04 -0700 | [diff] [blame] | 576 | { |
| 577 | int size = 0; |
| 578 | if (!pos) |
| 579 | size = sprintf(buffer, "%s\n", image_type); |
| 580 | return size; |
| 581 | } |
| 582 | |
Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 583 | static ssize_t write_rbu_image_type(struct kobject *kobj, |
| 584 | struct bin_attribute *bin_attr, |
| 585 | char *buffer, loff_t pos, size_t count) |
Abhay Salunke | e61c0e3 | 2005-09-16 19:28:04 -0700 | [diff] [blame] | 586 | { |
| 587 | int rc = count; |
| 588 | int req_firm_rc = 0; |
| 589 | int i; |
| 590 | spin_lock(&rbu_data.lock); |
| 591 | /* |
| 592 | * Find the first newline or space |
| 593 | */ |
| 594 | for (i = 0; i < count; ++i) |
| 595 | if (buffer[i] == '\n' || buffer[i] == ' ') { |
| 596 | buffer[i] = '\0'; |
| 597 | break; |
| 598 | } |
| 599 | if (i == count) |
| 600 | buffer[count] = '\0'; |
| 601 | |
| 602 | if (strstr(buffer, "mono")) |
| 603 | strcpy(image_type, "mono"); |
| 604 | else if (strstr(buffer, "packet")) |
| 605 | strcpy(image_type, "packet"); |
| 606 | else if (strstr(buffer, "init")) { |
| 607 | /* |
| 608 | * If due to the user error the driver gets in a bad |
| 609 | * state where even though it is loaded , the |
| 610 | * /sys/class/firmware/dell_rbu entries are missing. |
| 611 | * to cover this situation the user can recreate entries |
| 612 | * by writing init to image_type. |
| 613 | */ |
| 614 | if (!rbu_data.entry_created) { |
| 615 | spin_unlock(&rbu_data.lock); |
| 616 | req_firm_rc = request_firmware_nowait(THIS_MODULE, |
| 617 | FW_ACTION_NOHOTPLUG, "dell_rbu", |
| 618 | &rbu_device->dev, &context, |
| 619 | callbackfn_rbu); |
| 620 | if (req_firm_rc) { |
| 621 | printk(KERN_ERR |
| 622 | "dell_rbu:%s request_firmware_nowait" |
Harvey Harrison | eecd585 | 2008-04-29 00:59:19 -0700 | [diff] [blame] | 623 | " failed %d\n", __func__, rc); |
Abhay Salunke | e61c0e3 | 2005-09-16 19:28:04 -0700 | [diff] [blame] | 624 | rc = -EIO; |
| 625 | } else |
| 626 | rbu_data.entry_created = 1; |
| 627 | |
| 628 | spin_lock(&rbu_data.lock); |
| 629 | } |
| 630 | } else { |
| 631 | printk(KERN_WARNING "dell_rbu: image_type is invalid\n"); |
| 632 | spin_unlock(&rbu_data.lock); |
| 633 | return -EINVAL; |
| 634 | } |
| 635 | |
| 636 | /* we must free all previous allocations */ |
| 637 | packet_empty_list(); |
| 638 | img_update_free(); |
| 639 | spin_unlock(&rbu_data.lock); |
| 640 | |
| 641 | return rc; |
| 642 | } |
| 643 | |
Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 644 | static ssize_t read_rbu_packet_size(struct kobject *kobj, |
| 645 | struct bin_attribute *bin_attr, |
| 646 | char *buffer, loff_t pos, size_t count) |
Abhay Salunke | ad6ce87 | 2005-10-11 08:29:02 -0700 | [diff] [blame] | 647 | { |
| 648 | int size = 0; |
| 649 | if (!pos) { |
| 650 | spin_lock(&rbu_data.lock); |
| 651 | size = sprintf(buffer, "%lu\n", rbu_data.packetsize); |
| 652 | spin_unlock(&rbu_data.lock); |
| 653 | } |
| 654 | return size; |
| 655 | } |
| 656 | |
Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 657 | static ssize_t write_rbu_packet_size(struct kobject *kobj, |
| 658 | struct bin_attribute *bin_attr, |
| 659 | char *buffer, loff_t pos, size_t count) |
Abhay Salunke | ad6ce87 | 2005-10-11 08:29:02 -0700 | [diff] [blame] | 660 | { |
| 661 | unsigned long temp; |
| 662 | spin_lock(&rbu_data.lock); |
| 663 | packet_empty_list(); |
| 664 | sscanf(buffer, "%lu", &temp); |
| 665 | if (temp < 0xffffffff) |
| 666 | rbu_data.packetsize = temp; |
| 667 | |
| 668 | spin_unlock(&rbu_data.lock); |
| 669 | return count; |
| 670 | } |
| 671 | |
Abhay Salunke | e61c0e3 | 2005-09-16 19:28:04 -0700 | [diff] [blame] | 672 | static struct bin_attribute rbu_data_attr = { |
Tejun Heo | 7b59575 | 2007-06-14 03:45:17 +0900 | [diff] [blame] | 673 | .attr = {.name = "data", .mode = 0444}, |
Abhay Salunke | e61c0e3 | 2005-09-16 19:28:04 -0700 | [diff] [blame] | 674 | .read = read_rbu_data, |
| 675 | }; |
| 676 | |
| 677 | static struct bin_attribute rbu_image_type_attr = { |
Tejun Heo | 7b59575 | 2007-06-14 03:45:17 +0900 | [diff] [blame] | 678 | .attr = {.name = "image_type", .mode = 0644}, |
Abhay Salunke | e61c0e3 | 2005-09-16 19:28:04 -0700 | [diff] [blame] | 679 | .read = read_rbu_image_type, |
| 680 | .write = write_rbu_image_type, |
| 681 | }; |
| 682 | |
Abhay Salunke | ad6ce87 | 2005-10-11 08:29:02 -0700 | [diff] [blame] | 683 | static struct bin_attribute rbu_packet_size_attr = { |
Tejun Heo | 7b59575 | 2007-06-14 03:45:17 +0900 | [diff] [blame] | 684 | .attr = {.name = "packet_size", .mode = 0644}, |
Abhay Salunke | ad6ce87 | 2005-10-11 08:29:02 -0700 | [diff] [blame] | 685 | .read = read_rbu_packet_size, |
| 686 | .write = write_rbu_packet_size, |
| 687 | }; |
| 688 | |
Andrew Morton | dda8577 | 2005-09-16 19:28:05 -0700 | [diff] [blame] | 689 | static int __init dcdrbu_init(void) |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 690 | { |
Akinobu Mita | 6897083 | 2006-11-16 01:19:25 -0800 | [diff] [blame] | 691 | int rc; |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 692 | spin_lock_init(&rbu_data.lock); |
| 693 | |
| 694 | init_packet_head(); |
Akinobu Mita | 6897083 | 2006-11-16 01:19:25 -0800 | [diff] [blame] | 695 | rbu_device = platform_device_register_simple("dell_rbu", -1, NULL, 0); |
| 696 | if (IS_ERR(rbu_device)) { |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 697 | printk(KERN_ERR |
Abhay Salunke | e61c0e3 | 2005-09-16 19:28:04 -0700 | [diff] [blame] | 698 | "dell_rbu:%s:platform_device_register_simple " |
Harvey Harrison | eecd585 | 2008-04-29 00:59:19 -0700 | [diff] [blame] | 699 | "failed\n", __func__); |
Akinobu Mita | 6897083 | 2006-11-16 01:19:25 -0800 | [diff] [blame] | 700 | return PTR_ERR(rbu_device); |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 701 | } |
| 702 | |
Jeff Garzik | 41bfcfd | 2006-10-11 01:22:20 -0700 | [diff] [blame] | 703 | rc = sysfs_create_bin_file(&rbu_device->dev.kobj, &rbu_data_attr); |
| 704 | if (rc) |
| 705 | goto out_devreg; |
| 706 | rc = sysfs_create_bin_file(&rbu_device->dev.kobj, &rbu_image_type_attr); |
| 707 | if (rc) |
| 708 | goto out_data; |
| 709 | rc = sysfs_create_bin_file(&rbu_device->dev.kobj, |
Abhay Salunke | ad6ce87 | 2005-10-11 08:29:02 -0700 | [diff] [blame] | 710 | &rbu_packet_size_attr); |
Jeff Garzik | 41bfcfd | 2006-10-11 01:22:20 -0700 | [diff] [blame] | 711 | if (rc) |
| 712 | goto out_imtype; |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 713 | |
Abhay Salunke | 2c56084 | 2006-01-14 13:21:14 -0800 | [diff] [blame] | 714 | rbu_data.entry_created = 0; |
Jeff Garzik | 41bfcfd | 2006-10-11 01:22:20 -0700 | [diff] [blame] | 715 | return 0; |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 716 | |
Jeff Garzik | 41bfcfd | 2006-10-11 01:22:20 -0700 | [diff] [blame] | 717 | out_imtype: |
| 718 | sysfs_remove_bin_file(&rbu_device->dev.kobj, &rbu_image_type_attr); |
| 719 | out_data: |
| 720 | sysfs_remove_bin_file(&rbu_device->dev.kobj, &rbu_data_attr); |
| 721 | out_devreg: |
| 722 | platform_device_unregister(rbu_device); |
| 723 | return rc; |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 724 | } |
| 725 | |
Andrew Morton | dda8577 | 2005-09-16 19:28:05 -0700 | [diff] [blame] | 726 | static __exit void dcdrbu_exit(void) |
Abhay Salunke | 6c54c28 | 2005-09-06 15:17:14 -0700 | [diff] [blame] | 727 | { |
| 728 | spin_lock(&rbu_data.lock); |
| 729 | packet_empty_list(); |
| 730 | img_update_free(); |
| 731 | spin_unlock(&rbu_data.lock); |
| 732 | platform_device_unregister(rbu_device); |
| 733 | } |
| 734 | |
| 735 | module_exit(dcdrbu_exit); |
| 736 | module_init(dcdrbu_init); |
Abhay Salunke | 274b693 | 2005-11-07 00:59:26 -0800 | [diff] [blame] | 737 | |
| 738 | /* vim:noet:ts=8:sw=8 |
| 739 | */ |