patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / arch / ppc64 / kernel / rtas_flash.c
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  *
9  * /proc/ppc64/rtas/firmware_flash interface
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>
18 #include <linux/proc_fs.h>
19 #include <asm/delay.h>
20 #include <asm/uaccess.h>
21 #include <asm/rtas.h>
22
23 #define MODULE_VERS "1.0"
24 #define MODULE_NAME "rtas_flash"
25
26 #define FIRMWARE_FLASH_NAME "firmware_flash"   
27 #define FIRMWARE_UPDATE_NAME "firmware_update"
28 #define MANAGE_FLASH_NAME "manage_flash"
29 #define VALIDATE_FLASH_NAME "validate_flash"
30
31 /* General RTAS Status Codes */
32 #define RTAS_RC_SUCCESS  0
33 #define RTAS_RC_HW_ERR  -1
34 #define RTAS_RC_BUSY    -2
35
36 /* Flash image status values */
37 #define FLASH_AUTH           -9002 /* RTAS Not Service Authority Partition */
38 #define FLASH_NO_OP          -1099 /* No operation initiated by user */ 
39 #define FLASH_IMG_SHORT      -1005 /* Flash image shorter than expected */
40 #define FLASH_IMG_BAD_LEN    -1004 /* Bad length value in flash list block */
41 #define FLASH_IMG_NULL_DATA  -1003 /* Bad data value in flash list block */
42 #define FLASH_IMG_READY      0     /* Firmware img ready for flash on reboot */
43
44 /* Manage image status values */
45 #define MANAGE_AUTH          -9002 /* RTAS Not Service Authority Partition */
46 #define MANAGE_ACTIVE_ERR    -9001 /* RTAS Cannot Overwrite Active Img */
47 #define MANAGE_NO_OP         -1099 /* No operation initiated by user */
48 #define MANAGE_PARAM_ERR     -3    /* RTAS Parameter Error */
49 #define MANAGE_HW_ERR        -1    /* RTAS Hardware Error */
50
51 /* Validate image status values */
52 #define VALIDATE_AUTH          -9002 /* RTAS Not Service Authority Partition */
53 #define VALIDATE_NO_OP         -1099 /* No operation initiated by the user */
54 #define VALIDATE_INCOMPLETE    -1002 /* User copied < VALIDATE_BUF_SIZE */
55 #define VALIDATE_READY         -1001 /* Firmware image ready for validation */
56 #define VALIDATE_PARAM_ERR     -3    /* RTAS Parameter Error */
57 #define VALIDATE_HW_ERR        -1    /* RTAS Hardware Error */
58 #define VALIDATE_TMP_UPDATE    0     /* Validate Return Status */
59 #define VALIDATE_FLASH_AUTH    1     /* Validate Return Status */
60 #define VALIDATE_INVALID_IMG   2     /* Validate Return Status */
61 #define VALIDATE_CUR_UNKNOWN   3     /* Validate Return Status */
62 #define VALIDATE_TMP_COMMIT_DL 4     /* Validate Return Status */
63 #define VALIDATE_TMP_COMMIT    5     /* Validate Return Status */
64 #define VALIDATE_TMP_UPDATE_DL 6     /* Validate Return Status */
65
66 /* ibm,manage-flash-image operation tokens */
67 #define RTAS_REJECT_TMP_IMG   0
68 #define RTAS_COMMIT_TMP_IMG   1
69
70 /* Array sizes */
71 #define VALIDATE_BUF_SIZE 4096    
72 #define RTAS_MSG_MAXLEN   64
73
74 /* Local copy of the flash block list.
75  * We only allow one open of the flash proc file and create this
76  * list as we go.  This list will be put in the kernel's
77  * rtas_firmware_flash_list global var once it is fully read.
78  *
79  * For convenience as we build the list we use virtual addrs,
80  * we do not fill in the version number, and the length field
81  * is treated as the number of entries currently in the block
82  * (i.e. not a byte count).  This is all fixed on release.
83  */
84
85 /* Status int must be first member of struct */
86 struct rtas_update_flash_t
87 {
88         int status;                     /* Flash update status */
89         struct flash_block_list *flist; /* Local copy of flash block list */
90 };
91
92 /* Status int must be first member of struct */
93 struct rtas_manage_flash_t
94 {
95         int status;                     /* Returned status */
96         unsigned int op;                /* Reject or commit image */
97 };
98
99 /* Status int must be first member of struct */
100 struct rtas_validate_flash_t
101 {
102         int status;                     /* Returned status */   
103         char buf[VALIDATE_BUF_SIZE];    /* Candidate image buffer */
104         unsigned int buf_size;          /* Size of image buf */
105         unsigned int update_results;    /* Update results token */
106 };
107
108 static spinlock_t flash_file_open_lock = SPIN_LOCK_UNLOCKED;
109 static struct proc_dir_entry *firmware_flash_pde;
110 static struct proc_dir_entry *firmware_update_pde;
111 static struct proc_dir_entry *validate_pde;
112 static struct proc_dir_entry *manage_pde;
113
114 /* Do simple sanity checks on the flash image. */
115 static int flash_list_valid(struct flash_block_list *flist)
116 {
117         struct flash_block_list *f;
118         int i;
119         unsigned long block_size, image_size;
120
121         /* Paranoid self test here.  We also collect the image size. */
122         image_size = 0;
123         for (f = flist; f; f = f->next) {
124                 for (i = 0; i < f->num_blocks; i++) {
125                         if (f->blocks[i].data == NULL) {
126                                 return FLASH_IMG_NULL_DATA;
127                         }
128                         block_size = f->blocks[i].length;
129                         if (block_size <= 0 || block_size > PAGE_SIZE) {
130                                 return FLASH_IMG_BAD_LEN;
131                         }
132                         image_size += block_size;
133                 }
134         }
135
136         if (image_size < (256 << 10)) {
137                 if (image_size < 2) 
138                         return FLASH_NO_OP;
139         }
140
141         printk(KERN_INFO "FLASH: flash image with %ld bytes stored for hardware flash on reboot\n", image_size);
142
143         return FLASH_IMG_READY;
144 }
145
146 static void free_flash_list(struct flash_block_list *f)
147 {
148         struct flash_block_list *next;
149         int i;
150
151         while (f) {
152                 for (i = 0; i < f->num_blocks; i++)
153                         free_page((unsigned long)(f->blocks[i].data));
154                 next = f->next;
155                 free_page((unsigned long)f);
156                 f = next;
157         }
158 }
159
160 static int rtas_flash_release(struct inode *inode, struct file *file)
161 {
162         struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode);
163         struct rtas_update_flash_t *uf;
164         
165         uf = (struct rtas_update_flash_t *) dp->data;
166         if (uf->flist) {    
167                 /* File was opened in write mode for a new flash attempt */
168                 /* Clear saved list */
169                 if (rtas_firmware_flash_list.next) {
170                         free_flash_list(rtas_firmware_flash_list.next);
171                         rtas_firmware_flash_list.next = NULL;
172                 }
173
174                 if (uf->status != FLASH_AUTH)  
175                         uf->status = flash_list_valid(uf->flist);
176
177                 if (uf->status == FLASH_IMG_READY) 
178                         rtas_firmware_flash_list.next = uf->flist;
179                 else
180                         free_flash_list(uf->flist);
181
182                 uf->flist = NULL;
183         }
184
185         atomic_dec(&dp->count);
186         return 0;
187 }
188
189 static void get_flash_status_msg(int status, char *buf)
190 {
191         char *msg;
192
193         switch (status) {
194         case FLASH_AUTH:
195                 msg = "error: this partition does not have service authority\n";
196                 break;
197         case FLASH_NO_OP:
198                 msg = "info: no firmware image for flash\n";
199                 break;
200         case FLASH_IMG_SHORT:
201                 msg = "error: flash image short\n";
202                 break;
203         case FLASH_IMG_BAD_LEN:
204                 msg = "error: internal error bad length\n";
205                 break;
206         case FLASH_IMG_NULL_DATA:
207                 msg = "error: internal error null data\n";
208                 break;
209         case FLASH_IMG_READY:
210                 msg = "ready: firmware image ready for flash on reboot\n";
211                 break;
212         default:
213                 sprintf(buf, "error: unexpected status value %d\n", status);
214                 return;
215         }
216
217         strcpy(buf, msg);       
218 }
219
220 /* Reading the proc file will show status (not the firmware contents) */
221 static ssize_t rtas_flash_read(struct file *file, char *buf,
222                                size_t count, loff_t *ppos)
223 {
224         struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode);
225         struct rtas_update_flash_t *uf;
226         char msg[RTAS_MSG_MAXLEN];
227         int error;
228         int msglen;
229
230         uf = (struct rtas_update_flash_t *) dp->data;
231
232         if (!strcmp(dp->name, FIRMWARE_FLASH_NAME)) {
233                 get_flash_status_msg(uf->status, msg);
234         } else {           /* FIRMWARE_UPDATE_NAME */
235                 sprintf(msg, "%d\n", uf->status);
236         }
237         msglen = strlen(msg);
238         if (msglen > count)
239                 msglen = count;
240
241         if (ppos && *ppos != 0)
242                 return 0;       /* be cheap */
243
244         error = verify_area(VERIFY_WRITE, buf, msglen);
245         if (error)
246                 return -EINVAL;
247
248         if (copy_to_user(buf, msg, msglen))
249                 return -EFAULT;
250
251         if (ppos)
252                 *ppos = msglen;
253         return msglen;
254 }
255
256 /* We could be much more efficient here.  But to keep this function
257  * simple we allocate a page to the block list no matter how small the
258  * count is.  If the system is low on memory it will be just as well
259  * that we fail....
260  */
261 static ssize_t rtas_flash_write(struct file *file, const char *buffer,
262                                 size_t count, loff_t *off)
263 {
264         struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode);
265         struct rtas_update_flash_t *uf;
266         char *p;
267         int next_free;
268         struct flash_block_list *fl;
269
270         uf = (struct rtas_update_flash_t *) dp->data;
271
272         if (uf->status == FLASH_AUTH || count == 0)
273                 return count;   /* discard data */
274
275         /* In the case that the image is not ready for flashing, the memory
276          * allocated for the block list will be freed upon the release of the 
277          * proc file
278          */
279         if (uf->flist == NULL) {
280                 uf->flist = (struct flash_block_list *) get_zeroed_page(GFP_KERNEL);
281                 if (!uf->flist)
282                         return -ENOMEM;
283         }
284
285         fl = uf->flist;
286         while (fl->next)
287                 fl = fl->next; /* seek to last block_list for append */
288         next_free = fl->num_blocks;
289         if (next_free == FLASH_BLOCKS_PER_NODE) {
290                 /* Need to allocate another block_list */
291                 fl->next = (struct flash_block_list *)get_zeroed_page(GFP_KERNEL);
292                 if (!fl->next)
293                         return -ENOMEM;
294                 fl = fl->next;
295                 next_free = 0;
296         }
297
298         if (count > PAGE_SIZE)
299                 count = PAGE_SIZE;
300         p = (char *)get_zeroed_page(GFP_KERNEL);
301         if (!p)
302                 return -ENOMEM;
303         
304         if(copy_from_user(p, buffer, count)) {
305                 free_page((unsigned long)p);
306                 return -EFAULT;
307         }
308         fl->blocks[next_free].data = p;
309         fl->blocks[next_free].length = count;
310         fl->num_blocks++;
311
312         return count;
313 }
314
315 static int rtas_excl_open(struct inode *inode, struct file *file)
316 {
317         struct proc_dir_entry *dp = PDE(inode);
318
319         /* Enforce exclusive open with use count of PDE */
320         spin_lock(&flash_file_open_lock);
321         if (atomic_read(&dp->count) > 1) {
322                 spin_unlock(&flash_file_open_lock);
323                 return -EBUSY;
324         }
325
326         atomic_inc(&dp->count);
327         spin_unlock(&flash_file_open_lock);
328         
329         return 0;
330 }
331
332 static int rtas_excl_release(struct inode *inode, struct file *file)
333 {
334         struct proc_dir_entry *dp = PDE(inode);
335
336         atomic_dec(&dp->count);
337
338         return 0;
339 }
340
341 static void manage_flash(struct rtas_manage_flash_t *args_buf)
342 {
343         unsigned int wait_time;
344         s32 rc;
345
346         while (1) {
347                 rc = (s32) rtas_call(rtas_token("ibm,manage-flash-image"), 1, 
348                                 1, NULL, (long) args_buf->op);
349                 if (rc == RTAS_RC_BUSY)
350                         udelay(1);
351                 else if (rtas_is_extended_busy(rc)) {
352                         wait_time = rtas_extended_busy_delay_time(rc);
353                         udelay(wait_time * 1000);
354                 } else
355                         break;
356         }
357
358         args_buf->status = rc;
359 }
360
361 static ssize_t manage_flash_read(struct file *file, char *buf,
362                                size_t count, loff_t *ppos)
363 {
364         struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode);
365         struct rtas_manage_flash_t *args_buf;
366         char msg[RTAS_MSG_MAXLEN];
367         int msglen;
368         int error;
369
370         args_buf = (struct rtas_manage_flash_t *) dp->data;
371         if (args_buf == NULL)
372                 return 0;
373
374         msglen = sprintf(msg, "%d\n", args_buf->status);
375         if (msglen > count)
376                 msglen = count;
377
378         if (ppos && *ppos != 0)
379                 return 0;       /* be cheap */
380
381         error = verify_area(VERIFY_WRITE, buf, msglen);
382         if (error)
383                 return -EINVAL;
384
385         if (copy_to_user(buf, msg, msglen))
386                 return -EFAULT;
387
388         if (ppos)
389                 *ppos = msglen;
390         return msglen;
391 }
392
393 static ssize_t manage_flash_write(struct file *file, const char *buf,
394                                 size_t count, loff_t *off)
395 {
396         struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode);
397         struct rtas_manage_flash_t *args_buf;
398         const char reject_str[] = "0";
399         const char commit_str[] = "1";
400         char stkbuf[10];
401         int op;
402
403         args_buf = (struct rtas_manage_flash_t *) dp->data;
404         if ((args_buf->status == MANAGE_AUTH) || (count == 0))
405                 return count;
406                 
407         op = -1;
408         if (buf) {
409                 if (count > 9) count = 9;
410                 if (copy_from_user (stkbuf, buf, count)) {
411                         return -EFAULT;
412                 }
413                 if (strncmp(stkbuf, reject_str, strlen(reject_str)) == 0) 
414                         op = RTAS_REJECT_TMP_IMG;
415                 else if (strncmp(stkbuf, commit_str, strlen(commit_str)) == 0) 
416                         op = RTAS_COMMIT_TMP_IMG;
417         }
418         
419         if (op == -1)   /* buf is empty, or contains invalid string */
420                 return -EINVAL;
421
422         args_buf->op = op;
423         manage_flash(args_buf);
424
425         return count;
426 }
427
428 static void validate_flash(struct rtas_validate_flash_t *args_buf)
429 {
430         int token = rtas_token("ibm,validate-flash-image");
431         unsigned int wait_time;
432         long update_results;
433         s32 rc; 
434
435         rc = 0;
436         while(1) {
437                 spin_lock(&rtas_data_buf_lock);
438                 memcpy(rtas_data_buf, args_buf->buf, VALIDATE_BUF_SIZE);
439                 rc = (s32) rtas_call(token, 2, 2, &update_results, 
440                                      __pa(rtas_data_buf), args_buf->buf_size);
441                 memcpy(args_buf->buf, rtas_data_buf, VALIDATE_BUF_SIZE);
442                 spin_unlock(&rtas_data_buf_lock);
443                         
444                 if (rc == RTAS_RC_BUSY)
445                         udelay(1);
446                 else if (rtas_is_extended_busy(rc)) {
447                         wait_time = rtas_extended_busy_delay_time(rc);
448                         udelay(wait_time * 1000);
449                 } else
450                         break;
451         }
452
453         args_buf->status = rc;
454         args_buf->update_results = (u32) update_results;
455 }
456
457 static int get_validate_flash_msg(struct rtas_validate_flash_t *args_buf, 
458                                    char *msg)
459 {
460         int n;
461
462         if (args_buf->status >= VALIDATE_TMP_UPDATE) { 
463                 n = sprintf(msg, "%d\n", args_buf->update_results);
464                 if ((args_buf->update_results >= VALIDATE_CUR_UNKNOWN) ||
465                     (args_buf->update_results == VALIDATE_TMP_UPDATE))
466                         n += sprintf(msg + n, "%s\n", args_buf->buf);
467         } else {
468                 n = sprintf(msg, "%d\n", args_buf->status);
469         }
470         return n;
471 }
472
473 static ssize_t validate_flash_read(struct file *file, char *buf,
474                                size_t count, loff_t *ppos)
475 {
476         struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode);
477         struct rtas_validate_flash_t *args_buf;
478         char msg[RTAS_MSG_MAXLEN];
479         int msglen;
480         int error;
481
482         args_buf = (struct rtas_validate_flash_t *) dp->data;
483
484         if (ppos && *ppos != 0)
485                 return 0;       /* be cheap */
486         
487         msglen = get_validate_flash_msg(args_buf, msg);
488         if (msglen > count)
489                 msglen = count;
490
491         error = verify_area(VERIFY_WRITE, buf, msglen);
492         if (error)
493                 return -EINVAL;
494
495         if (copy_to_user(buf, msg, msglen))
496                 return -EFAULT;
497
498         if (ppos)
499                 *ppos = msglen;
500         return msglen;
501 }
502
503 static ssize_t validate_flash_write(struct file *file, const char *buf,
504                                     size_t count, loff_t *off)
505 {
506         struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode);
507         struct rtas_validate_flash_t *args_buf;
508         int rc;
509
510         args_buf = (struct rtas_validate_flash_t *) dp->data;
511
512         if (dp->data == NULL) {
513                 dp->data = kmalloc(sizeof(struct rtas_validate_flash_t), 
514                                 GFP_KERNEL);
515                 if (dp->data == NULL) 
516                         return -ENOMEM;
517         }
518
519         /* We are only interested in the first 4K of the
520          * candidate image */
521         if ((*off >= VALIDATE_BUF_SIZE) || 
522                 (args_buf->status == VALIDATE_AUTH)) {
523                 *off += count;
524                 return count;
525         }
526
527         if (*off + count >= VALIDATE_BUF_SIZE)  {
528                 count = VALIDATE_BUF_SIZE - *off;
529                 args_buf->status = VALIDATE_READY;      
530         } else {
531                 args_buf->status = VALIDATE_INCOMPLETE;
532         }
533
534         if (verify_area(VERIFY_READ, buf, count)) {
535                 rc = -EFAULT;
536                 goto done;
537         }
538         if (copy_from_user(args_buf->buf + *off, buf, count)) {
539                 rc = -EFAULT;
540                 goto done;
541         }
542
543         *off += count;
544         rc = count;
545 done:
546         if (rc < 0) {
547                 kfree(dp->data);
548                 dp->data = NULL;
549         }
550         return rc;
551 }
552
553 static int validate_flash_release(struct inode *inode, struct file *file)
554 {
555         struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode);
556         struct rtas_validate_flash_t *args_buf;
557
558         args_buf = (struct rtas_validate_flash_t *) dp->data;
559
560         if (args_buf->status == VALIDATE_READY) {
561                 args_buf->buf_size = VALIDATE_BUF_SIZE;
562                 validate_flash(args_buf);
563         }
564
565         atomic_dec(&dp->count);
566
567         return 0;
568 }
569
570 static void remove_flash_pde(struct proc_dir_entry *dp)
571 {
572         if (dp) {
573                 if (dp->data != NULL)
574                         kfree(dp->data);
575                 remove_proc_entry(dp->name, NULL);
576         }
577 }
578
579 static int initialize_flash_pde_data(const char *rtas_call_name,
580                                      size_t buf_size,
581                                      struct proc_dir_entry *dp)
582 {
583         int *status;
584         int token;
585
586         dp->data = kmalloc(buf_size, GFP_KERNEL);
587         if (dp->data == NULL) {
588                 remove_flash_pde(dp);
589                 return -ENOMEM;
590         }
591
592         memset(dp->data, 0, buf_size);
593
594         /*
595          * This code assumes that the status int is the first member of the
596          * struct 
597          */
598         status = (int *) dp->data;
599         token = rtas_token(rtas_call_name);
600         if (token == RTAS_UNKNOWN_SERVICE)
601                 *status = FLASH_AUTH;
602         else
603                 *status = FLASH_NO_OP;
604
605         return 0;
606 }
607
608 static struct proc_dir_entry *create_flash_pde(const char *filename,
609                                                struct file_operations *fops)
610 {
611         struct proc_dir_entry *ent = NULL;
612
613         ent = create_proc_entry(filename, S_IRUSR | S_IWUSR, NULL);
614         if (ent != NULL) {
615                 ent->nlink = 1;
616                 ent->proc_fops = fops;
617                 ent->owner = THIS_MODULE;
618         }
619
620         return ent;
621 }
622
623 static struct file_operations rtas_flash_operations = {
624         .read           = rtas_flash_read,
625         .write          = rtas_flash_write,
626         .open           = rtas_excl_open,
627         .release        = rtas_flash_release,
628 };
629
630 static struct file_operations manage_flash_operations = {
631         .read           = manage_flash_read,
632         .write          = manage_flash_write,
633         .open           = rtas_excl_open,
634         .release        = rtas_excl_release,
635 };
636
637 static struct file_operations validate_flash_operations = {
638         .read           = validate_flash_read,
639         .write          = validate_flash_write,
640         .open           = rtas_excl_open,
641         .release        = validate_flash_release,
642 };
643
644 int __init rtas_flash_init(void)
645 {
646         int rc;
647
648         if (rtas_token("ibm,update-flash-64-and-reboot") ==
649                        RTAS_UNKNOWN_SERVICE) {
650                 printk(KERN_ERR "rtas_flash: no firmware flash support\n");
651                 return 1;
652         }
653
654         firmware_flash_pde = create_flash_pde("ppc64/rtas/"
655                                               FIRMWARE_FLASH_NAME,
656                                               &rtas_flash_operations);
657         if (firmware_flash_pde == NULL) {
658                 rc = -ENOMEM;
659                 goto cleanup;
660         }
661
662         rc = initialize_flash_pde_data("ibm,update-flash-64-and-reboot",
663                                        sizeof(struct rtas_update_flash_t), 
664                                        firmware_flash_pde);
665         if (rc != 0)
666                 goto cleanup;
667
668         firmware_update_pde = create_flash_pde("ppc64/rtas/"
669                                                FIRMWARE_UPDATE_NAME,
670                                                &rtas_flash_operations);
671         if (firmware_update_pde == NULL) {
672                 rc = -ENOMEM;
673                 goto cleanup;
674         }
675
676         rc = initialize_flash_pde_data("ibm,update-flash-64-and-reboot",
677                                        sizeof(struct rtas_update_flash_t), 
678                                        firmware_update_pde);
679         if (rc != 0)
680                 goto cleanup;
681
682         validate_pde = create_flash_pde("ppc64/rtas/" VALIDATE_FLASH_NAME,
683                                         &validate_flash_operations);
684         if (validate_pde == NULL) {
685                 rc = -ENOMEM;
686                 goto cleanup;
687         }
688
689         rc = initialize_flash_pde_data("ibm,validate-flash-image",
690                                        sizeof(struct rtas_validate_flash_t), 
691                                        validate_pde);
692         if (rc != 0)
693                 goto cleanup;
694
695         manage_pde = create_flash_pde("ppc64/rtas/" MANAGE_FLASH_NAME,
696                                       &manage_flash_operations);
697         if (manage_pde == NULL) {
698                 rc = -ENOMEM;
699                 goto cleanup;
700         }
701
702         rc = initialize_flash_pde_data("ibm,manage-flash-image",
703                                        sizeof(struct rtas_manage_flash_t),
704                                        manage_pde);
705         if (rc != 0)
706                 goto cleanup;
707
708         return 0;
709
710 cleanup:
711         remove_flash_pde(firmware_flash_pde);
712         remove_flash_pde(firmware_update_pde);
713         remove_flash_pde(validate_pde);
714         remove_flash_pde(manage_pde);
715
716         return rc;
717 }
718
719 void __exit rtas_flash_cleanup(void)
720 {
721         remove_flash_pde(firmware_flash_pde);
722         remove_flash_pde(firmware_update_pde);
723         remove_flash_pde(validate_pde);
724         remove_flash_pde(manage_pde);
725 }
726
727 module_init(rtas_flash_init);
728 module_exit(rtas_flash_cleanup);
729 MODULE_LICENSE("GPL");