Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * c 2001 PPC 64 Team, IBM Corp |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; either version |
| 7 | * 2 of the License, or (at your option) any later version. |
| 8 | * |
Benjamin Herrenschmidt | 188917e | 2009-09-24 19:29:13 +0000 | [diff] [blame] | 9 | * /proc/powerpc/rtas/firmware_flash interface |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * |
| 11 | * This file implements a firmware_flash interface to pump a firmware |
| 12 | * image into the kernel. At reboot time rtas_restart() will see the |
| 13 | * firmware image and flash it as it reboots (see rtas.c). |
| 14 | */ |
| 15 | |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/init.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 18 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/proc_fs.h> |
Amerigo Wang | c5f4175 | 2011-07-25 17:13:10 -0700 | [diff] [blame] | 20 | #include <linux/reboot.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <asm/delay.h> |
| 22 | #include <asm/uaccess.h> |
| 23 | #include <asm/rtas.h> |
| 24 | |
| 25 | #define MODULE_VERS "1.0" |
| 26 | #define MODULE_NAME "rtas_flash" |
| 27 | |
| 28 | #define FIRMWARE_FLASH_NAME "firmware_flash" |
| 29 | #define FIRMWARE_UPDATE_NAME "firmware_update" |
| 30 | #define MANAGE_FLASH_NAME "manage_flash" |
| 31 | #define VALIDATE_FLASH_NAME "validate_flash" |
| 32 | |
| 33 | /* General RTAS Status Codes */ |
| 34 | #define RTAS_RC_SUCCESS 0 |
| 35 | #define RTAS_RC_HW_ERR -1 |
| 36 | #define RTAS_RC_BUSY -2 |
| 37 | |
| 38 | /* Flash image status values */ |
| 39 | #define FLASH_AUTH -9002 /* RTAS Not Service Authority Partition */ |
| 40 | #define FLASH_NO_OP -1099 /* No operation initiated by user */ |
| 41 | #define FLASH_IMG_SHORT -1005 /* Flash image shorter than expected */ |
| 42 | #define FLASH_IMG_BAD_LEN -1004 /* Bad length value in flash list block */ |
| 43 | #define FLASH_IMG_NULL_DATA -1003 /* Bad data value in flash list block */ |
| 44 | #define FLASH_IMG_READY 0 /* Firmware img ready for flash on reboot */ |
| 45 | |
| 46 | /* Manage image status values */ |
| 47 | #define MANAGE_AUTH -9002 /* RTAS Not Service Authority Partition */ |
| 48 | #define MANAGE_ACTIVE_ERR -9001 /* RTAS Cannot Overwrite Active Img */ |
| 49 | #define MANAGE_NO_OP -1099 /* No operation initiated by user */ |
| 50 | #define MANAGE_PARAM_ERR -3 /* RTAS Parameter Error */ |
| 51 | #define MANAGE_HW_ERR -1 /* RTAS Hardware Error */ |
| 52 | |
| 53 | /* Validate image status values */ |
| 54 | #define VALIDATE_AUTH -9002 /* RTAS Not Service Authority Partition */ |
| 55 | #define VALIDATE_NO_OP -1099 /* No operation initiated by the user */ |
| 56 | #define VALIDATE_INCOMPLETE -1002 /* User copied < VALIDATE_BUF_SIZE */ |
| 57 | #define VALIDATE_READY -1001 /* Firmware image ready for validation */ |
| 58 | #define VALIDATE_PARAM_ERR -3 /* RTAS Parameter Error */ |
| 59 | #define VALIDATE_HW_ERR -1 /* RTAS Hardware Error */ |
Vasant Hegde | f51005d | 2013-04-23 04:20:48 +0000 | [diff] [blame^] | 60 | |
| 61 | /* ibm,validate-flash-image update result tokens */ |
| 62 | #define VALIDATE_TMP_UPDATE 0 /* T side will be updated */ |
| 63 | #define VALIDATE_FLASH_AUTH 1 /* Partition does not have authority */ |
| 64 | #define VALIDATE_INVALID_IMG 2 /* Candidate image is not valid */ |
| 65 | #define VALIDATE_CUR_UNKNOWN 3 /* Current fixpack level is unknown */ |
| 66 | /* |
| 67 | * Current T side will be committed to P side before being replace with new |
| 68 | * image, and the new image is downlevel from current image |
| 69 | */ |
| 70 | #define VALIDATE_TMP_COMMIT_DL 4 |
| 71 | /* |
| 72 | * Current T side will be committed to P side before being replaced with new |
| 73 | * image |
| 74 | */ |
| 75 | #define VALIDATE_TMP_COMMIT 5 |
| 76 | /* |
| 77 | * T side will be updated with a downlevel image |
| 78 | */ |
| 79 | #define VALIDATE_TMP_UPDATE_DL 6 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
| 81 | /* ibm,manage-flash-image operation tokens */ |
| 82 | #define RTAS_REJECT_TMP_IMG 0 |
| 83 | #define RTAS_COMMIT_TMP_IMG 1 |
| 84 | |
| 85 | /* Array sizes */ |
| 86 | #define VALIDATE_BUF_SIZE 4096 |
| 87 | #define RTAS_MSG_MAXLEN 64 |
| 88 | |
John Rose | ae883ca | 2006-11-08 10:07:30 -0600 | [diff] [blame] | 89 | /* Quirk - RTAS requires 4k list length and block size */ |
| 90 | #define RTAS_BLKLIST_LENGTH 4096 |
| 91 | #define RTAS_BLK_SIZE 4096 |
| 92 | |
Paul Mackerras | f4fcbbe | 2005-11-03 14:41:19 +1100 | [diff] [blame] | 93 | struct flash_block { |
| 94 | char *data; |
| 95 | unsigned long length; |
| 96 | }; |
| 97 | |
| 98 | /* This struct is very similar but not identical to |
| 99 | * that needed by the rtas flash update. |
| 100 | * All we need to do for rtas is rewrite num_blocks |
| 101 | * into a version/length and translate the pointers |
| 102 | * to absolute. |
| 103 | */ |
John Rose | ae883ca | 2006-11-08 10:07:30 -0600 | [diff] [blame] | 104 | #define FLASH_BLOCKS_PER_NODE ((RTAS_BLKLIST_LENGTH - 16) / sizeof(struct flash_block)) |
Paul Mackerras | f4fcbbe | 2005-11-03 14:41:19 +1100 | [diff] [blame] | 105 | struct flash_block_list { |
| 106 | unsigned long num_blocks; |
| 107 | struct flash_block_list *next; |
| 108 | struct flash_block blocks[FLASH_BLOCKS_PER_NODE]; |
| 109 | }; |
Paul Mackerras | f4fcbbe | 2005-11-03 14:41:19 +1100 | [diff] [blame] | 110 | |
Milton Miller | bd2b64a | 2010-06-12 03:48:47 +0000 | [diff] [blame] | 111 | static struct flash_block_list *rtas_firmware_flash_list; |
Paul Mackerras | f4fcbbe | 2005-11-03 14:41:19 +1100 | [diff] [blame] | 112 | |
John Rose | ae883ca | 2006-11-08 10:07:30 -0600 | [diff] [blame] | 113 | /* Use slab cache to guarantee 4k alignment */ |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 114 | static struct kmem_cache *flash_block_cache = NULL; |
John Rose | ae883ca | 2006-11-08 10:07:30 -0600 | [diff] [blame] | 115 | |
Paul Mackerras | f4fcbbe | 2005-11-03 14:41:19 +1100 | [diff] [blame] | 116 | #define FLASH_BLOCK_LIST_VERSION (1UL) |
| 117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | /* Local copy of the flash block list. |
| 119 | * We only allow one open of the flash proc file and create this |
Milton Miller | bd2b64a | 2010-06-12 03:48:47 +0000 | [diff] [blame] | 120 | * list as we go. The rtas_firmware_flash_list varable will be |
| 121 | * set once the data is fully read. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | * |
| 123 | * For convenience as we build the list we use virtual addrs, |
| 124 | * we do not fill in the version number, and the length field |
| 125 | * is treated as the number of entries currently in the block |
Milton Miller | bd2b64a | 2010-06-12 03:48:47 +0000 | [diff] [blame] | 126 | * (i.e. not a byte count). This is all fixed when calling |
| 127 | * the flash routine. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | */ |
| 129 | |
| 130 | /* Status int must be first member of struct */ |
| 131 | struct rtas_update_flash_t |
| 132 | { |
| 133 | int status; /* Flash update status */ |
| 134 | struct flash_block_list *flist; /* Local copy of flash block list */ |
| 135 | }; |
| 136 | |
| 137 | /* Status int must be first member of struct */ |
| 138 | struct rtas_manage_flash_t |
| 139 | { |
| 140 | int status; /* Returned status */ |
| 141 | unsigned int op; /* Reject or commit image */ |
| 142 | }; |
| 143 | |
| 144 | /* Status int must be first member of struct */ |
| 145 | struct rtas_validate_flash_t |
| 146 | { |
| 147 | int status; /* Returned status */ |
| 148 | char buf[VALIDATE_BUF_SIZE]; /* Candidate image buffer */ |
| 149 | unsigned int buf_size; /* Size of image buf */ |
| 150 | unsigned int update_results; /* Update results token */ |
| 151 | }; |
| 152 | |
| 153 | static DEFINE_SPINLOCK(flash_file_open_lock); |
| 154 | static struct proc_dir_entry *firmware_flash_pde; |
| 155 | static struct proc_dir_entry *firmware_update_pde; |
| 156 | static struct proc_dir_entry *validate_pde; |
| 157 | static struct proc_dir_entry *manage_pde; |
| 158 | |
| 159 | /* Do simple sanity checks on the flash image. */ |
| 160 | static int flash_list_valid(struct flash_block_list *flist) |
| 161 | { |
| 162 | struct flash_block_list *f; |
| 163 | int i; |
| 164 | unsigned long block_size, image_size; |
| 165 | |
| 166 | /* Paranoid self test here. We also collect the image size. */ |
| 167 | image_size = 0; |
| 168 | for (f = flist; f; f = f->next) { |
| 169 | for (i = 0; i < f->num_blocks; i++) { |
| 170 | if (f->blocks[i].data == NULL) { |
| 171 | return FLASH_IMG_NULL_DATA; |
| 172 | } |
| 173 | block_size = f->blocks[i].length; |
John Rose | ae883ca | 2006-11-08 10:07:30 -0600 | [diff] [blame] | 174 | if (block_size <= 0 || block_size > RTAS_BLK_SIZE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | return FLASH_IMG_BAD_LEN; |
| 176 | } |
| 177 | image_size += block_size; |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | if (image_size < (256 << 10)) { |
| 182 | if (image_size < 2) |
| 183 | return FLASH_NO_OP; |
| 184 | } |
| 185 | |
| 186 | printk(KERN_INFO "FLASH: flash image with %ld bytes stored for hardware flash on reboot\n", image_size); |
| 187 | |
| 188 | return FLASH_IMG_READY; |
| 189 | } |
| 190 | |
| 191 | static void free_flash_list(struct flash_block_list *f) |
| 192 | { |
| 193 | struct flash_block_list *next; |
| 194 | int i; |
| 195 | |
| 196 | while (f) { |
| 197 | for (i = 0; i < f->num_blocks; i++) |
John Rose | ae883ca | 2006-11-08 10:07:30 -0600 | [diff] [blame] | 198 | kmem_cache_free(flash_block_cache, f->blocks[i].data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | next = f->next; |
John Rose | ae883ca | 2006-11-08 10:07:30 -0600 | [diff] [blame] | 200 | kmem_cache_free(flash_block_cache, f); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | f = next; |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | static int rtas_flash_release(struct inode *inode, struct file *file) |
| 206 | { |
Al Viro | 496ad9a | 2013-01-23 17:07:38 -0500 | [diff] [blame] | 207 | struct proc_dir_entry *dp = PDE(file_inode(file)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | struct rtas_update_flash_t *uf; |
| 209 | |
| 210 | uf = (struct rtas_update_flash_t *) dp->data; |
| 211 | if (uf->flist) { |
| 212 | /* File was opened in write mode for a new flash attempt */ |
| 213 | /* Clear saved list */ |
Milton Miller | bd2b64a | 2010-06-12 03:48:47 +0000 | [diff] [blame] | 214 | if (rtas_firmware_flash_list) { |
| 215 | free_flash_list(rtas_firmware_flash_list); |
| 216 | rtas_firmware_flash_list = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | if (uf->status != FLASH_AUTH) |
| 220 | uf->status = flash_list_valid(uf->flist); |
| 221 | |
| 222 | if (uf->status == FLASH_IMG_READY) |
Milton Miller | bd2b64a | 2010-06-12 03:48:47 +0000 | [diff] [blame] | 223 | rtas_firmware_flash_list = uf->flist; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | else |
| 225 | free_flash_list(uf->flist); |
| 226 | |
| 227 | uf->flist = NULL; |
| 228 | } |
| 229 | |
| 230 | atomic_dec(&dp->count); |
| 231 | return 0; |
| 232 | } |
| 233 | |
| 234 | static void get_flash_status_msg(int status, char *buf) |
| 235 | { |
| 236 | char *msg; |
| 237 | |
| 238 | switch (status) { |
| 239 | case FLASH_AUTH: |
| 240 | msg = "error: this partition does not have service authority\n"; |
| 241 | break; |
| 242 | case FLASH_NO_OP: |
| 243 | msg = "info: no firmware image for flash\n"; |
| 244 | break; |
| 245 | case FLASH_IMG_SHORT: |
| 246 | msg = "error: flash image short\n"; |
| 247 | break; |
| 248 | case FLASH_IMG_BAD_LEN: |
| 249 | msg = "error: internal error bad length\n"; |
| 250 | break; |
| 251 | case FLASH_IMG_NULL_DATA: |
| 252 | msg = "error: internal error null data\n"; |
| 253 | break; |
| 254 | case FLASH_IMG_READY: |
| 255 | msg = "ready: firmware image ready for flash on reboot\n"; |
| 256 | break; |
| 257 | default: |
| 258 | sprintf(buf, "error: unexpected status value %d\n", status); |
| 259 | return; |
| 260 | } |
| 261 | |
| 262 | strcpy(buf, msg); |
| 263 | } |
| 264 | |
| 265 | /* Reading the proc file will show status (not the firmware contents) */ |
Al Viro | efa5457 | 2005-04-26 11:26:53 -0700 | [diff] [blame] | 266 | static ssize_t rtas_flash_read(struct file *file, char __user *buf, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | size_t count, loff_t *ppos) |
| 268 | { |
Al Viro | 496ad9a | 2013-01-23 17:07:38 -0500 | [diff] [blame] | 269 | struct proc_dir_entry *dp = PDE(file_inode(file)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | struct rtas_update_flash_t *uf; |
| 271 | char msg[RTAS_MSG_MAXLEN]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | |
Akinobu Mita | 4c4a5cf | 2010-12-24 20:03:59 +0000 | [diff] [blame] | 273 | uf = dp->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | |
| 275 | if (!strcmp(dp->name, FIRMWARE_FLASH_NAME)) { |
| 276 | get_flash_status_msg(uf->status, msg); |
| 277 | } else { /* FIRMWARE_UPDATE_NAME */ |
| 278 | sprintf(msg, "%d\n", uf->status); |
| 279 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | |
Akinobu Mita | 4c4a5cf | 2010-12-24 20:03:59 +0000 | [diff] [blame] | 281 | return simple_read_from_buffer(buf, count, ppos, msg, strlen(msg)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | } |
| 283 | |
John Rose | ae883ca | 2006-11-08 10:07:30 -0600 | [diff] [blame] | 284 | /* constructor for flash_block_cache */ |
Alexey Dobriyan | 51cc506 | 2008-07-25 19:45:34 -0700 | [diff] [blame] | 285 | void rtas_block_ctor(void *ptr) |
John Rose | ae883ca | 2006-11-08 10:07:30 -0600 | [diff] [blame] | 286 | { |
| 287 | memset(ptr, 0, RTAS_BLK_SIZE); |
| 288 | } |
| 289 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | /* We could be much more efficient here. But to keep this function |
| 291 | * simple we allocate a page to the block list no matter how small the |
| 292 | * count is. If the system is low on memory it will be just as well |
| 293 | * that we fail.... |
| 294 | */ |
Al Viro | efa5457 | 2005-04-26 11:26:53 -0700 | [diff] [blame] | 295 | static ssize_t rtas_flash_write(struct file *file, const char __user *buffer, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | size_t count, loff_t *off) |
| 297 | { |
Al Viro | 496ad9a | 2013-01-23 17:07:38 -0500 | [diff] [blame] | 298 | struct proc_dir_entry *dp = PDE(file_inode(file)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | struct rtas_update_flash_t *uf; |
| 300 | char *p; |
| 301 | int next_free; |
| 302 | struct flash_block_list *fl; |
| 303 | |
| 304 | uf = (struct rtas_update_flash_t *) dp->data; |
| 305 | |
| 306 | if (uf->status == FLASH_AUTH || count == 0) |
| 307 | return count; /* discard data */ |
| 308 | |
| 309 | /* In the case that the image is not ready for flashing, the memory |
| 310 | * allocated for the block list will be freed upon the release of the |
| 311 | * proc file |
| 312 | */ |
| 313 | if (uf->flist == NULL) { |
John Rose | ae883ca | 2006-11-08 10:07:30 -0600 | [diff] [blame] | 314 | uf->flist = kmem_cache_alloc(flash_block_cache, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | if (!uf->flist) |
| 316 | return -ENOMEM; |
| 317 | } |
| 318 | |
| 319 | fl = uf->flist; |
| 320 | while (fl->next) |
| 321 | fl = fl->next; /* seek to last block_list for append */ |
| 322 | next_free = fl->num_blocks; |
| 323 | if (next_free == FLASH_BLOCKS_PER_NODE) { |
| 324 | /* Need to allocate another block_list */ |
John Rose | ae883ca | 2006-11-08 10:07:30 -0600 | [diff] [blame] | 325 | fl->next = kmem_cache_alloc(flash_block_cache, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | if (!fl->next) |
| 327 | return -ENOMEM; |
| 328 | fl = fl->next; |
| 329 | next_free = 0; |
| 330 | } |
| 331 | |
John Rose | ae883ca | 2006-11-08 10:07:30 -0600 | [diff] [blame] | 332 | if (count > RTAS_BLK_SIZE) |
| 333 | count = RTAS_BLK_SIZE; |
| 334 | p = kmem_cache_alloc(flash_block_cache, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | if (!p) |
| 336 | return -ENOMEM; |
| 337 | |
| 338 | if(copy_from_user(p, buffer, count)) { |
John Rose | ae883ca | 2006-11-08 10:07:30 -0600 | [diff] [blame] | 339 | kmem_cache_free(flash_block_cache, p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | return -EFAULT; |
| 341 | } |
| 342 | fl->blocks[next_free].data = p; |
| 343 | fl->blocks[next_free].length = count; |
| 344 | fl->num_blocks++; |
| 345 | |
| 346 | return count; |
| 347 | } |
| 348 | |
| 349 | static int rtas_excl_open(struct inode *inode, struct file *file) |
| 350 | { |
| 351 | struct proc_dir_entry *dp = PDE(inode); |
| 352 | |
| 353 | /* Enforce exclusive open with use count of PDE */ |
| 354 | spin_lock(&flash_file_open_lock); |
Maxim Shchetynin | 7484839 | 2008-04-02 00:12:20 +1100 | [diff] [blame] | 355 | if (atomic_read(&dp->count) > 2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | spin_unlock(&flash_file_open_lock); |
| 357 | return -EBUSY; |
| 358 | } |
| 359 | |
| 360 | atomic_inc(&dp->count); |
| 361 | spin_unlock(&flash_file_open_lock); |
| 362 | |
| 363 | return 0; |
| 364 | } |
| 365 | |
| 366 | static int rtas_excl_release(struct inode *inode, struct file *file) |
| 367 | { |
| 368 | struct proc_dir_entry *dp = PDE(inode); |
| 369 | |
| 370 | atomic_dec(&dp->count); |
| 371 | |
| 372 | return 0; |
| 373 | } |
| 374 | |
| 375 | static void manage_flash(struct rtas_manage_flash_t *args_buf) |
| 376 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | s32 rc; |
| 378 | |
John Rose | 507279d | 2006-06-05 16:31:48 -0500 | [diff] [blame] | 379 | do { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | rc = rtas_call(rtas_token("ibm,manage-flash-image"), 1, |
| 381 | 1, NULL, args_buf->op); |
John Rose | 507279d | 2006-06-05 16:31:48 -0500 | [diff] [blame] | 382 | } while (rtas_busy_delay(rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | |
| 384 | args_buf->status = rc; |
| 385 | } |
| 386 | |
Al Viro | efa5457 | 2005-04-26 11:26:53 -0700 | [diff] [blame] | 387 | static ssize_t manage_flash_read(struct file *file, char __user *buf, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | size_t count, loff_t *ppos) |
| 389 | { |
Al Viro | 496ad9a | 2013-01-23 17:07:38 -0500 | [diff] [blame] | 390 | struct proc_dir_entry *dp = PDE(file_inode(file)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | struct rtas_manage_flash_t *args_buf; |
| 392 | char msg[RTAS_MSG_MAXLEN]; |
| 393 | int msglen; |
| 394 | |
Akinobu Mita | 4c4a5cf | 2010-12-24 20:03:59 +0000 | [diff] [blame] | 395 | args_buf = dp->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | if (args_buf == NULL) |
| 397 | return 0; |
| 398 | |
| 399 | msglen = sprintf(msg, "%d\n", args_buf->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
Akinobu Mita | 4c4a5cf | 2010-12-24 20:03:59 +0000 | [diff] [blame] | 401 | return simple_read_from_buffer(buf, count, ppos, msg, msglen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Al Viro | efa5457 | 2005-04-26 11:26:53 -0700 | [diff] [blame] | 404 | static ssize_t manage_flash_write(struct file *file, const char __user *buf, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | size_t count, loff_t *off) |
| 406 | { |
Al Viro | 496ad9a | 2013-01-23 17:07:38 -0500 | [diff] [blame] | 407 | struct proc_dir_entry *dp = PDE(file_inode(file)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | struct rtas_manage_flash_t *args_buf; |
| 409 | const char reject_str[] = "0"; |
| 410 | const char commit_str[] = "1"; |
| 411 | char stkbuf[10]; |
| 412 | int op; |
| 413 | |
| 414 | args_buf = (struct rtas_manage_flash_t *) dp->data; |
| 415 | if ((args_buf->status == MANAGE_AUTH) || (count == 0)) |
| 416 | return count; |
| 417 | |
| 418 | op = -1; |
| 419 | if (buf) { |
| 420 | if (count > 9) count = 9; |
| 421 | if (copy_from_user (stkbuf, buf, count)) { |
| 422 | return -EFAULT; |
| 423 | } |
| 424 | if (strncmp(stkbuf, reject_str, strlen(reject_str)) == 0) |
| 425 | op = RTAS_REJECT_TMP_IMG; |
| 426 | else if (strncmp(stkbuf, commit_str, strlen(commit_str)) == 0) |
| 427 | op = RTAS_COMMIT_TMP_IMG; |
| 428 | } |
| 429 | |
| 430 | if (op == -1) /* buf is empty, or contains invalid string */ |
| 431 | return -EINVAL; |
| 432 | |
| 433 | args_buf->op = op; |
| 434 | manage_flash(args_buf); |
| 435 | |
| 436 | return count; |
| 437 | } |
| 438 | |
| 439 | static void validate_flash(struct rtas_validate_flash_t *args_buf) |
| 440 | { |
| 441 | int token = rtas_token("ibm,validate-flash-image"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | int update_results; |
| 443 | s32 rc; |
| 444 | |
| 445 | rc = 0; |
John Rose | 507279d | 2006-06-05 16:31:48 -0500 | [diff] [blame] | 446 | do { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | spin_lock(&rtas_data_buf_lock); |
| 448 | memcpy(rtas_data_buf, args_buf->buf, VALIDATE_BUF_SIZE); |
| 449 | rc = rtas_call(token, 2, 2, &update_results, |
| 450 | (u32) __pa(rtas_data_buf), args_buf->buf_size); |
| 451 | memcpy(args_buf->buf, rtas_data_buf, VALIDATE_BUF_SIZE); |
| 452 | spin_unlock(&rtas_data_buf_lock); |
John Rose | 507279d | 2006-06-05 16:31:48 -0500 | [diff] [blame] | 453 | } while (rtas_busy_delay(rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | |
| 455 | args_buf->status = rc; |
| 456 | args_buf->update_results = update_results; |
| 457 | } |
| 458 | |
| 459 | static int get_validate_flash_msg(struct rtas_validate_flash_t *args_buf, |
| 460 | char *msg) |
| 461 | { |
| 462 | int n; |
| 463 | |
| 464 | if (args_buf->status >= VALIDATE_TMP_UPDATE) { |
| 465 | n = sprintf(msg, "%d\n", args_buf->update_results); |
| 466 | if ((args_buf->update_results >= VALIDATE_CUR_UNKNOWN) || |
| 467 | (args_buf->update_results == VALIDATE_TMP_UPDATE)) |
| 468 | n += sprintf(msg + n, "%s\n", args_buf->buf); |
| 469 | } else { |
| 470 | n = sprintf(msg, "%d\n", args_buf->status); |
| 471 | } |
| 472 | return n; |
| 473 | } |
| 474 | |
Al Viro | efa5457 | 2005-04-26 11:26:53 -0700 | [diff] [blame] | 475 | static ssize_t validate_flash_read(struct file *file, char __user *buf, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | size_t count, loff_t *ppos) |
| 477 | { |
Al Viro | 496ad9a | 2013-01-23 17:07:38 -0500 | [diff] [blame] | 478 | struct proc_dir_entry *dp = PDE(file_inode(file)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | struct rtas_validate_flash_t *args_buf; |
| 480 | char msg[RTAS_MSG_MAXLEN]; |
| 481 | int msglen; |
| 482 | |
Akinobu Mita | 4c4a5cf | 2010-12-24 20:03:59 +0000 | [diff] [blame] | 483 | args_buf = dp->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | msglen = get_validate_flash_msg(args_buf, msg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | |
Akinobu Mita | 4c4a5cf | 2010-12-24 20:03:59 +0000 | [diff] [blame] | 487 | return simple_read_from_buffer(buf, count, ppos, msg, msglen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | } |
| 489 | |
Al Viro | efa5457 | 2005-04-26 11:26:53 -0700 | [diff] [blame] | 490 | static ssize_t validate_flash_write(struct file *file, const char __user *buf, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | size_t count, loff_t *off) |
| 492 | { |
Al Viro | 496ad9a | 2013-01-23 17:07:38 -0500 | [diff] [blame] | 493 | struct proc_dir_entry *dp = PDE(file_inode(file)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | struct rtas_validate_flash_t *args_buf; |
| 495 | int rc; |
| 496 | |
| 497 | args_buf = (struct rtas_validate_flash_t *) dp->data; |
| 498 | |
| 499 | if (dp->data == NULL) { |
| 500 | dp->data = kmalloc(sizeof(struct rtas_validate_flash_t), |
| 501 | GFP_KERNEL); |
| 502 | if (dp->data == NULL) |
| 503 | return -ENOMEM; |
| 504 | } |
| 505 | |
| 506 | /* We are only interested in the first 4K of the |
| 507 | * candidate image */ |
| 508 | if ((*off >= VALIDATE_BUF_SIZE) || |
| 509 | (args_buf->status == VALIDATE_AUTH)) { |
| 510 | *off += count; |
| 511 | return count; |
| 512 | } |
| 513 | |
| 514 | if (*off + count >= VALIDATE_BUF_SIZE) { |
| 515 | count = VALIDATE_BUF_SIZE - *off; |
| 516 | args_buf->status = VALIDATE_READY; |
| 517 | } else { |
| 518 | args_buf->status = VALIDATE_INCOMPLETE; |
| 519 | } |
| 520 | |
| 521 | if (!access_ok(VERIFY_READ, buf, count)) { |
| 522 | rc = -EFAULT; |
| 523 | goto done; |
| 524 | } |
| 525 | if (copy_from_user(args_buf->buf + *off, buf, count)) { |
| 526 | rc = -EFAULT; |
| 527 | goto done; |
| 528 | } |
| 529 | |
| 530 | *off += count; |
| 531 | rc = count; |
| 532 | done: |
| 533 | if (rc < 0) { |
| 534 | kfree(dp->data); |
| 535 | dp->data = NULL; |
| 536 | } |
| 537 | return rc; |
| 538 | } |
| 539 | |
| 540 | static int validate_flash_release(struct inode *inode, struct file *file) |
| 541 | { |
Al Viro | 496ad9a | 2013-01-23 17:07:38 -0500 | [diff] [blame] | 542 | struct proc_dir_entry *dp = PDE(file_inode(file)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | struct rtas_validate_flash_t *args_buf; |
| 544 | |
| 545 | args_buf = (struct rtas_validate_flash_t *) dp->data; |
| 546 | |
| 547 | if (args_buf->status == VALIDATE_READY) { |
| 548 | args_buf->buf_size = VALIDATE_BUF_SIZE; |
| 549 | validate_flash(args_buf); |
| 550 | } |
| 551 | |
| 552 | /* The matching atomic_inc was in rtas_excl_open() */ |
| 553 | atomic_dec(&dp->count); |
| 554 | |
| 555 | return 0; |
| 556 | } |
| 557 | |
Paul Mackerras | f4fcbbe | 2005-11-03 14:41:19 +1100 | [diff] [blame] | 558 | static void rtas_flash_firmware(int reboot_type) |
| 559 | { |
| 560 | unsigned long image_size; |
| 561 | struct flash_block_list *f, *next, *flist; |
| 562 | unsigned long rtas_block_list; |
| 563 | int i, status, update_token; |
| 564 | |
Milton Miller | bd2b64a | 2010-06-12 03:48:47 +0000 | [diff] [blame] | 565 | if (rtas_firmware_flash_list == NULL) |
Paul Mackerras | f4fcbbe | 2005-11-03 14:41:19 +1100 | [diff] [blame] | 566 | return; /* nothing to do */ |
| 567 | |
| 568 | if (reboot_type != SYS_RESTART) { |
| 569 | printk(KERN_ALERT "FLASH: firmware flash requires a reboot\n"); |
| 570 | printk(KERN_ALERT "FLASH: the firmware image will NOT be flashed\n"); |
| 571 | return; |
| 572 | } |
| 573 | |
| 574 | update_token = rtas_token("ibm,update-flash-64-and-reboot"); |
| 575 | if (update_token == RTAS_UNKNOWN_SERVICE) { |
| 576 | printk(KERN_ALERT "FLASH: ibm,update-flash-64-and-reboot " |
| 577 | "is not available -- not a service partition?\n"); |
| 578 | printk(KERN_ALERT "FLASH: firmware will not be flashed\n"); |
| 579 | return; |
| 580 | } |
| 581 | |
Milton Miller | bd2b64a | 2010-06-12 03:48:47 +0000 | [diff] [blame] | 582 | /* |
Ravi K. Nittala | df17f56 | 2011-10-03 21:49:53 +0000 | [diff] [blame] | 583 | * Just before starting the firmware flash, cancel the event scan work |
| 584 | * to avoid any soft lockup issues. |
| 585 | */ |
| 586 | rtas_cancel_event_scan(); |
| 587 | |
| 588 | /* |
Milton Miller | bd2b64a | 2010-06-12 03:48:47 +0000 | [diff] [blame] | 589 | * NOTE: the "first" block must be under 4GB, so we create |
| 590 | * an entry with no data blocks in the reserved buffer in |
| 591 | * the kernel data segment. |
Paul Mackerras | f4fcbbe | 2005-11-03 14:41:19 +1100 | [diff] [blame] | 592 | */ |
Milton Miller | bd2b64a | 2010-06-12 03:48:47 +0000 | [diff] [blame] | 593 | spin_lock(&rtas_data_buf_lock); |
| 594 | flist = (struct flash_block_list *)&rtas_data_buf[0]; |
| 595 | flist->num_blocks = 0; |
| 596 | flist->next = rtas_firmware_flash_list; |
Michael Ellerman | 3d26752 | 2012-07-25 21:19:56 +0000 | [diff] [blame] | 597 | rtas_block_list = __pa(flist); |
Paul Mackerras | f4fcbbe | 2005-11-03 14:41:19 +1100 | [diff] [blame] | 598 | if (rtas_block_list >= 4UL*1024*1024*1024) { |
| 599 | printk(KERN_ALERT "FLASH: kernel bug...flash list header addr above 4GB\n"); |
Milton Miller | bd2b64a | 2010-06-12 03:48:47 +0000 | [diff] [blame] | 600 | spin_unlock(&rtas_data_buf_lock); |
Paul Mackerras | f4fcbbe | 2005-11-03 14:41:19 +1100 | [diff] [blame] | 601 | return; |
| 602 | } |
| 603 | |
| 604 | printk(KERN_ALERT "FLASH: preparing saved firmware image for flash\n"); |
| 605 | /* Update the block_list in place. */ |
Milton Miller | bd2b64a | 2010-06-12 03:48:47 +0000 | [diff] [blame] | 606 | rtas_firmware_flash_list = NULL; /* too hard to backout on error */ |
Paul Mackerras | f4fcbbe | 2005-11-03 14:41:19 +1100 | [diff] [blame] | 607 | image_size = 0; |
| 608 | for (f = flist; f; f = next) { |
| 609 | /* Translate data addrs to absolute */ |
| 610 | for (i = 0; i < f->num_blocks; i++) { |
Michael Ellerman | 3d26752 | 2012-07-25 21:19:56 +0000 | [diff] [blame] | 611 | f->blocks[i].data = (char *)__pa(f->blocks[i].data); |
Paul Mackerras | f4fcbbe | 2005-11-03 14:41:19 +1100 | [diff] [blame] | 612 | image_size += f->blocks[i].length; |
| 613 | } |
| 614 | next = f->next; |
| 615 | /* Don't translate NULL pointer for last entry */ |
| 616 | if (f->next) |
Michael Ellerman | 3d26752 | 2012-07-25 21:19:56 +0000 | [diff] [blame] | 617 | f->next = (struct flash_block_list *)__pa(f->next); |
Paul Mackerras | f4fcbbe | 2005-11-03 14:41:19 +1100 | [diff] [blame] | 618 | else |
| 619 | f->next = NULL; |
| 620 | /* make num_blocks into the version/length field */ |
| 621 | f->num_blocks = (FLASH_BLOCK_LIST_VERSION << 56) | ((f->num_blocks+1)*16); |
| 622 | } |
| 623 | |
| 624 | printk(KERN_ALERT "FLASH: flash image is %ld bytes\n", image_size); |
| 625 | printk(KERN_ALERT "FLASH: performing flash and reboot\n"); |
| 626 | rtas_progress("Flashing \n", 0x0); |
| 627 | rtas_progress("Please Wait... ", 0x0); |
| 628 | printk(KERN_ALERT "FLASH: this will take several minutes. Do not power off!\n"); |
| 629 | status = rtas_call(update_token, 1, 1, NULL, rtas_block_list); |
| 630 | switch (status) { /* should only get "bad" status */ |
| 631 | case 0: |
| 632 | printk(KERN_ALERT "FLASH: success\n"); |
| 633 | break; |
| 634 | case -1: |
| 635 | printk(KERN_ALERT "FLASH: hardware error. Firmware may not be not flashed\n"); |
| 636 | break; |
| 637 | case -3: |
| 638 | printk(KERN_ALERT "FLASH: image is corrupt or not correct for this platform. Firmware not flashed\n"); |
| 639 | break; |
| 640 | case -4: |
| 641 | printk(KERN_ALERT "FLASH: flash failed when partially complete. System may not reboot\n"); |
| 642 | break; |
| 643 | default: |
| 644 | printk(KERN_ALERT "FLASH: unknown flash return code %d\n", status); |
| 645 | break; |
| 646 | } |
Milton Miller | bd2b64a | 2010-06-12 03:48:47 +0000 | [diff] [blame] | 647 | spin_unlock(&rtas_data_buf_lock); |
Paul Mackerras | f4fcbbe | 2005-11-03 14:41:19 +1100 | [diff] [blame] | 648 | } |
| 649 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | static void remove_flash_pde(struct proc_dir_entry *dp) |
| 651 | { |
| 652 | if (dp) { |
Jesper Juhl | 95eff20 | 2006-02-04 20:35:59 +0100 | [diff] [blame] | 653 | kfree(dp->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | remove_proc_entry(dp->name, dp->parent); |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | static int initialize_flash_pde_data(const char *rtas_call_name, |
| 659 | size_t buf_size, |
| 660 | struct proc_dir_entry *dp) |
| 661 | { |
| 662 | int *status; |
| 663 | int token; |
| 664 | |
Yan Burman | f848535 | 2006-12-02 13:26:57 +0200 | [diff] [blame] | 665 | dp->data = kzalloc(buf_size, GFP_KERNEL); |
Julia Lawall | bc26957 | 2012-10-21 00:52:05 +0000 | [diff] [blame] | 666 | if (dp->data == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | /* |
| 670 | * This code assumes that the status int is the first member of the |
| 671 | * struct |
| 672 | */ |
| 673 | status = (int *) dp->data; |
| 674 | token = rtas_token(rtas_call_name); |
| 675 | if (token == RTAS_UNKNOWN_SERVICE) |
| 676 | *status = FLASH_AUTH; |
| 677 | else |
| 678 | *status = FLASH_NO_OP; |
| 679 | |
| 680 | return 0; |
| 681 | } |
| 682 | |
| 683 | static struct proc_dir_entry *create_flash_pde(const char *filename, |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 684 | const struct file_operations *fops) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | { |
Denis V. Lunev | 6674713 | 2008-04-29 01:02:26 -0700 | [diff] [blame] | 686 | return proc_create(filename, S_IRUSR | S_IWUSR, NULL, fops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | } |
| 688 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 689 | static const struct file_operations rtas_flash_operations = { |
Denis V. Lunev | 6674713 | 2008-04-29 01:02:26 -0700 | [diff] [blame] | 690 | .owner = THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | .read = rtas_flash_read, |
| 692 | .write = rtas_flash_write, |
| 693 | .open = rtas_excl_open, |
| 694 | .release = rtas_flash_release, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 695 | .llseek = default_llseek, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | }; |
| 697 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 698 | static const struct file_operations manage_flash_operations = { |
Denis V. Lunev | 6674713 | 2008-04-29 01:02:26 -0700 | [diff] [blame] | 699 | .owner = THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | .read = manage_flash_read, |
| 701 | .write = manage_flash_write, |
| 702 | .open = rtas_excl_open, |
| 703 | .release = rtas_excl_release, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 704 | .llseek = default_llseek, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | }; |
| 706 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 707 | static const struct file_operations validate_flash_operations = { |
Denis V. Lunev | 6674713 | 2008-04-29 01:02:26 -0700 | [diff] [blame] | 708 | .owner = THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | .read = validate_flash_read, |
| 710 | .write = validate_flash_write, |
| 711 | .open = rtas_excl_open, |
| 712 | .release = validate_flash_release, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 713 | .llseek = default_llseek, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | }; |
| 715 | |
Michael Ellerman | 1c21a29 | 2008-05-08 14:27:19 +1000 | [diff] [blame] | 716 | static int __init rtas_flash_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | { |
| 718 | int rc; |
| 719 | |
| 720 | if (rtas_token("ibm,update-flash-64-and-reboot") == |
| 721 | RTAS_UNKNOWN_SERVICE) { |
Anton Blanchard | 0e38498 | 2012-07-22 20:42:32 +0000 | [diff] [blame] | 722 | pr_info("rtas_flash: no firmware flash support\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | return 1; |
| 724 | } |
| 725 | |
Benjamin Herrenschmidt | 188917e | 2009-09-24 19:29:13 +0000 | [diff] [blame] | 726 | firmware_flash_pde = create_flash_pde("powerpc/rtas/" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | FIRMWARE_FLASH_NAME, |
| 728 | &rtas_flash_operations); |
| 729 | if (firmware_flash_pde == NULL) { |
| 730 | rc = -ENOMEM; |
| 731 | goto cleanup; |
| 732 | } |
| 733 | |
| 734 | rc = initialize_flash_pde_data("ibm,update-flash-64-and-reboot", |
| 735 | sizeof(struct rtas_update_flash_t), |
| 736 | firmware_flash_pde); |
| 737 | if (rc != 0) |
| 738 | goto cleanup; |
| 739 | |
Benjamin Herrenschmidt | 188917e | 2009-09-24 19:29:13 +0000 | [diff] [blame] | 740 | firmware_update_pde = create_flash_pde("powerpc/rtas/" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | FIRMWARE_UPDATE_NAME, |
| 742 | &rtas_flash_operations); |
| 743 | if (firmware_update_pde == NULL) { |
| 744 | rc = -ENOMEM; |
| 745 | goto cleanup; |
| 746 | } |
| 747 | |
| 748 | rc = initialize_flash_pde_data("ibm,update-flash-64-and-reboot", |
| 749 | sizeof(struct rtas_update_flash_t), |
| 750 | firmware_update_pde); |
| 751 | if (rc != 0) |
| 752 | goto cleanup; |
| 753 | |
Benjamin Herrenschmidt | 188917e | 2009-09-24 19:29:13 +0000 | [diff] [blame] | 754 | validate_pde = create_flash_pde("powerpc/rtas/" VALIDATE_FLASH_NAME, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | &validate_flash_operations); |
| 756 | if (validate_pde == NULL) { |
| 757 | rc = -ENOMEM; |
| 758 | goto cleanup; |
| 759 | } |
| 760 | |
| 761 | rc = initialize_flash_pde_data("ibm,validate-flash-image", |
| 762 | sizeof(struct rtas_validate_flash_t), |
| 763 | validate_pde); |
| 764 | if (rc != 0) |
| 765 | goto cleanup; |
| 766 | |
Benjamin Herrenschmidt | 188917e | 2009-09-24 19:29:13 +0000 | [diff] [blame] | 767 | manage_pde = create_flash_pde("powerpc/rtas/" MANAGE_FLASH_NAME, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | &manage_flash_operations); |
| 769 | if (manage_pde == NULL) { |
| 770 | rc = -ENOMEM; |
| 771 | goto cleanup; |
| 772 | } |
| 773 | |
| 774 | rc = initialize_flash_pde_data("ibm,manage-flash-image", |
| 775 | sizeof(struct rtas_manage_flash_t), |
| 776 | manage_pde); |
| 777 | if (rc != 0) |
| 778 | goto cleanup; |
| 779 | |
Paul Mackerras | f4fcbbe | 2005-11-03 14:41:19 +1100 | [diff] [blame] | 780 | rtas_flash_term_hook = rtas_flash_firmware; |
John Rose | ae883ca | 2006-11-08 10:07:30 -0600 | [diff] [blame] | 781 | |
| 782 | flash_block_cache = kmem_cache_create("rtas_flash_cache", |
| 783 | RTAS_BLK_SIZE, RTAS_BLK_SIZE, 0, |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 784 | rtas_block_ctor); |
John Rose | ae883ca | 2006-11-08 10:07:30 -0600 | [diff] [blame] | 785 | if (!flash_block_cache) { |
| 786 | printk(KERN_ERR "%s: failed to create block cache\n", |
Harvey Harrison | e48b1b4 | 2008-03-29 08:21:07 +1100 | [diff] [blame] | 787 | __func__); |
John Rose | ae883ca | 2006-11-08 10:07:30 -0600 | [diff] [blame] | 788 | rc = -ENOMEM; |
| 789 | goto cleanup; |
| 790 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | return 0; |
| 792 | |
| 793 | cleanup: |
| 794 | remove_flash_pde(firmware_flash_pde); |
| 795 | remove_flash_pde(firmware_update_pde); |
| 796 | remove_flash_pde(validate_pde); |
| 797 | remove_flash_pde(manage_pde); |
| 798 | |
| 799 | return rc; |
| 800 | } |
| 801 | |
Michael Ellerman | 1c21a29 | 2008-05-08 14:27:19 +1000 | [diff] [blame] | 802 | static void __exit rtas_flash_cleanup(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | { |
Paul Mackerras | f4fcbbe | 2005-11-03 14:41:19 +1100 | [diff] [blame] | 804 | rtas_flash_term_hook = NULL; |
John Rose | ae883ca | 2006-11-08 10:07:30 -0600 | [diff] [blame] | 805 | |
Vasant Hegde | ad18a36 | 2013-02-08 01:18:36 +0000 | [diff] [blame] | 806 | if (rtas_firmware_flash_list) { |
| 807 | free_flash_list(rtas_firmware_flash_list); |
| 808 | rtas_firmware_flash_list = NULL; |
| 809 | } |
| 810 | |
John Rose | ae883ca | 2006-11-08 10:07:30 -0600 | [diff] [blame] | 811 | if (flash_block_cache) |
| 812 | kmem_cache_destroy(flash_block_cache); |
| 813 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | remove_flash_pde(firmware_flash_pde); |
| 815 | remove_flash_pde(firmware_update_pde); |
| 816 | remove_flash_pde(validate_pde); |
| 817 | remove_flash_pde(manage_pde); |
| 818 | } |
| 819 | |
| 820 | module_init(rtas_flash_init); |
| 821 | module_exit(rtas_flash_cleanup); |
| 822 | MODULE_LICENSE("GPL"); |