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