rtas_flash.c 18 KB

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