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