diff options
Diffstat (limited to 'arch/powerpc/platforms/powernv/opal-flash.c')
-rw-r--r-- | arch/powerpc/platforms/powernv/opal-flash.c | 118 |
1 files changed, 10 insertions, 108 deletions
diff --git a/arch/powerpc/platforms/powernv/opal-flash.c b/arch/powerpc/platforms/powernv/opal-flash.c index 714ef972406b..dc487ff04704 100644 --- a/arch/powerpc/platforms/powernv/opal-flash.c +++ b/arch/powerpc/platforms/powernv/opal-flash.c | |||
@@ -79,9 +79,6 @@ | |||
79 | /* XXX: Assume candidate image size is <= 1GB */ | 79 | /* XXX: Assume candidate image size is <= 1GB */ |
80 | #define MAX_IMAGE_SIZE 0x40000000 | 80 | #define MAX_IMAGE_SIZE 0x40000000 |
81 | 81 | ||
82 | /* Flash sg list version */ | ||
83 | #define SG_LIST_VERSION (1UL) | ||
84 | |||
85 | /* Image status */ | 82 | /* Image status */ |
86 | enum { | 83 | enum { |
87 | IMAGE_INVALID, | 84 | IMAGE_INVALID, |
@@ -131,11 +128,15 @@ static DEFINE_MUTEX(image_data_mutex); | |||
131 | */ | 128 | */ |
132 | static inline void opal_flash_validate(void) | 129 | static inline void opal_flash_validate(void) |
133 | { | 130 | { |
134 | struct validate_flash_t *args_buf = &validate_flash_data; | 131 | long ret; |
132 | void *buf = validate_flash_data.buf; | ||
133 | __be32 size, result; | ||
135 | 134 | ||
136 | args_buf->status = opal_validate_flash(__pa(args_buf->buf), | 135 | ret = opal_validate_flash(__pa(buf), &size, &result); |
137 | &(args_buf->buf_size), | 136 | |
138 | &(args_buf->result)); | 137 | validate_flash_data.status = ret; |
138 | validate_flash_data.buf_size = be32_to_cpu(size); | ||
139 | validate_flash_data.result = be32_to_cpu(result); | ||
139 | } | 140 | } |
140 | 141 | ||
141 | /* | 142 | /* |
@@ -268,93 +269,11 @@ static ssize_t manage_store(struct kobject *kobj, | |||
268 | } | 269 | } |
269 | 270 | ||
270 | /* | 271 | /* |
271 | * Free sg list | ||
272 | */ | ||
273 | static void free_sg_list(struct opal_sg_list *list) | ||
274 | { | ||
275 | struct opal_sg_list *sg1; | ||
276 | while (list) { | ||
277 | sg1 = list->next; | ||
278 | kfree(list); | ||
279 | list = sg1; | ||
280 | } | ||
281 | list = NULL; | ||
282 | } | ||
283 | |||
284 | /* | ||
285 | * Build candidate image scatter gather list | ||
286 | * | ||
287 | * list format: | ||
288 | * ----------------------------------- | ||
289 | * | VER (8) | Entry length in bytes | | ||
290 | * ----------------------------------- | ||
291 | * | Pointer to next entry | | ||
292 | * ----------------------------------- | ||
293 | * | Address of memory area 1 | | ||
294 | * ----------------------------------- | ||
295 | * | Length of memory area 1 | | ||
296 | * ----------------------------------- | ||
297 | * | ......... | | ||
298 | * ----------------------------------- | ||
299 | * | ......... | | ||
300 | * ----------------------------------- | ||
301 | * | Address of memory area N | | ||
302 | * ----------------------------------- | ||
303 | * | Length of memory area N | | ||
304 | * ----------------------------------- | ||
305 | */ | ||
306 | static struct opal_sg_list *image_data_to_sglist(void) | ||
307 | { | ||
308 | struct opal_sg_list *sg1, *list = NULL; | ||
309 | void *addr; | ||
310 | int size; | ||
311 | |||
312 | addr = image_data.data; | ||
313 | size = image_data.size; | ||
314 | |||
315 | sg1 = kzalloc(PAGE_SIZE, GFP_KERNEL); | ||
316 | if (!sg1) | ||
317 | return NULL; | ||
318 | |||
319 | list = sg1; | ||
320 | sg1->num_entries = 0; | ||
321 | while (size > 0) { | ||
322 | /* Translate virtual address to physical address */ | ||
323 | sg1->entry[sg1->num_entries].data = | ||
324 | (void *)(vmalloc_to_pfn(addr) << PAGE_SHIFT); | ||
325 | |||
326 | if (size > PAGE_SIZE) | ||
327 | sg1->entry[sg1->num_entries].length = PAGE_SIZE; | ||
328 | else | ||
329 | sg1->entry[sg1->num_entries].length = size; | ||
330 | |||
331 | sg1->num_entries++; | ||
332 | if (sg1->num_entries >= SG_ENTRIES_PER_NODE) { | ||
333 | sg1->next = kzalloc(PAGE_SIZE, GFP_KERNEL); | ||
334 | if (!sg1->next) { | ||
335 | pr_err("%s : Failed to allocate memory\n", | ||
336 | __func__); | ||
337 | goto nomem; | ||
338 | } | ||
339 | |||
340 | sg1 = sg1->next; | ||
341 | sg1->num_entries = 0; | ||
342 | } | ||
343 | addr += PAGE_SIZE; | ||
344 | size -= PAGE_SIZE; | ||
345 | } | ||
346 | return list; | ||
347 | nomem: | ||
348 | free_sg_list(list); | ||
349 | return NULL; | ||
350 | } | ||
351 | |||
352 | /* | ||
353 | * OPAL update flash | 272 | * OPAL update flash |
354 | */ | 273 | */ |
355 | static int opal_flash_update(int op) | 274 | static int opal_flash_update(int op) |
356 | { | 275 | { |
357 | struct opal_sg_list *sg, *list, *next; | 276 | struct opal_sg_list *list; |
358 | unsigned long addr; | 277 | unsigned long addr; |
359 | int64_t rc = OPAL_PARAMETER; | 278 | int64_t rc = OPAL_PARAMETER; |
360 | 279 | ||
@@ -364,30 +283,13 @@ static int opal_flash_update(int op) | |||
364 | goto flash; | 283 | goto flash; |
365 | } | 284 | } |
366 | 285 | ||
367 | list = image_data_to_sglist(); | 286 | list = opal_vmalloc_to_sg_list(image_data.data, image_data.size); |
368 | if (!list) | 287 | if (!list) |
369 | goto invalid_img; | 288 | goto invalid_img; |
370 | 289 | ||
371 | /* First entry address */ | 290 | /* First entry address */ |
372 | addr = __pa(list); | 291 | addr = __pa(list); |
373 | 292 | ||
374 | /* Translate sg list address to absolute */ | ||
375 | for (sg = list; sg; sg = next) { | ||
376 | next = sg->next; | ||
377 | /* Don't translate NULL pointer for last entry */ | ||
378 | if (sg->next) | ||
379 | sg->next = (struct opal_sg_list *)__pa(sg->next); | ||
380 | else | ||
381 | sg->next = NULL; | ||
382 | |||
383 | /* | ||
384 | * Convert num_entries to version/length format | ||
385 | * to satisfy OPAL. | ||
386 | */ | ||
387 | sg->num_entries = (SG_LIST_VERSION << 56) | | ||
388 | (sg->num_entries * sizeof(struct opal_sg_entry) + 16); | ||
389 | } | ||
390 | |||
391 | pr_alert("FLASH: Image is %u bytes\n", image_data.size); | 293 | pr_alert("FLASH: Image is %u bytes\n", image_data.size); |
392 | pr_alert("FLASH: Image update requested\n"); | 294 | pr_alert("FLASH: Image update requested\n"); |
393 | pr_alert("FLASH: Image will be updated during system reboot\n"); | 295 | pr_alert("FLASH: Image will be updated during system reboot\n"); |