diff options
Diffstat (limited to 'arch/powerpc/platforms/ps3/os-area.c')
-rw-r--r-- | arch/powerpc/platforms/ps3/os-area.c | 142 |
1 files changed, 77 insertions, 65 deletions
diff --git a/arch/powerpc/platforms/ps3/os-area.c b/arch/powerpc/platforms/ps3/os-area.c index cf1cd0f8c18..d6487a9c801 100644 --- a/arch/powerpc/platforms/ps3/os-area.c +++ b/arch/powerpc/platforms/ps3/os-area.c | |||
@@ -226,6 +226,44 @@ static struct property property_av_multi_out = { | |||
226 | .value = &saved_params.av_multi_out, | 226 | .value = &saved_params.av_multi_out, |
227 | }; | 227 | }; |
228 | 228 | ||
229 | |||
230 | static DEFINE_MUTEX(os_area_flash_mutex); | ||
231 | |||
232 | static const struct ps3_os_area_flash_ops *os_area_flash_ops; | ||
233 | |||
234 | void ps3_os_area_flash_register(const struct ps3_os_area_flash_ops *ops) | ||
235 | { | ||
236 | mutex_lock(&os_area_flash_mutex); | ||
237 | os_area_flash_ops = ops; | ||
238 | mutex_unlock(&os_area_flash_mutex); | ||
239 | } | ||
240 | EXPORT_SYMBOL_GPL(ps3_os_area_flash_register); | ||
241 | |||
242 | static ssize_t os_area_flash_read(void *buf, size_t count, loff_t pos) | ||
243 | { | ||
244 | ssize_t res = -ENODEV; | ||
245 | |||
246 | mutex_lock(&os_area_flash_mutex); | ||
247 | if (os_area_flash_ops) | ||
248 | res = os_area_flash_ops->read(buf, count, pos); | ||
249 | mutex_unlock(&os_area_flash_mutex); | ||
250 | |||
251 | return res; | ||
252 | } | ||
253 | |||
254 | static ssize_t os_area_flash_write(const void *buf, size_t count, loff_t pos) | ||
255 | { | ||
256 | ssize_t res = -ENODEV; | ||
257 | |||
258 | mutex_lock(&os_area_flash_mutex); | ||
259 | if (os_area_flash_ops) | ||
260 | res = os_area_flash_ops->write(buf, count, pos); | ||
261 | mutex_unlock(&os_area_flash_mutex); | ||
262 | |||
263 | return res; | ||
264 | } | ||
265 | |||
266 | |||
229 | /** | 267 | /** |
230 | * os_area_set_property - Add or overwrite a saved_params value to the device tree. | 268 | * os_area_set_property - Add or overwrite a saved_params value to the device tree. |
231 | * | 269 | * |
@@ -352,12 +390,12 @@ static int db_verify(const struct os_area_db *db) | |||
352 | if (memcmp(db->magic_num, OS_AREA_DB_MAGIC_NUM, | 390 | if (memcmp(db->magic_num, OS_AREA_DB_MAGIC_NUM, |
353 | sizeof(db->magic_num))) { | 391 | sizeof(db->magic_num))) { |
354 | pr_debug("%s:%d magic_num failed\n", __func__, __LINE__); | 392 | pr_debug("%s:%d magic_num failed\n", __func__, __LINE__); |
355 | return -1; | 393 | return -EINVAL; |
356 | } | 394 | } |
357 | 395 | ||
358 | if (db->version != 1) { | 396 | if (db->version != 1) { |
359 | pr_debug("%s:%d version failed\n", __func__, __LINE__); | 397 | pr_debug("%s:%d version failed\n", __func__, __LINE__); |
360 | return -1; | 398 | return -EINVAL; |
361 | } | 399 | } |
362 | 400 | ||
363 | return 0; | 401 | return 0; |
@@ -578,59 +616,48 @@ static void os_area_db_init(struct os_area_db *db) | |||
578 | * | 616 | * |
579 | */ | 617 | */ |
580 | 618 | ||
581 | static void __maybe_unused update_flash_db(void) | 619 | static int update_flash_db(void) |
582 | { | 620 | { |
583 | int result; | 621 | const unsigned int buf_len = 8 * OS_AREA_SEGMENT_SIZE; |
584 | int file; | 622 | struct os_area_header *header; |
585 | off_t offset; | ||
586 | ssize_t count; | 623 | ssize_t count; |
587 | static const unsigned int buf_len = 8 * OS_AREA_SEGMENT_SIZE; | 624 | int error; |
588 | const struct os_area_header *header; | 625 | loff_t pos; |
589 | struct os_area_db* db; | 626 | struct os_area_db* db; |
590 | 627 | ||
591 | /* Read in header and db from flash. */ | 628 | /* Read in header and db from flash. */ |
592 | 629 | ||
593 | file = sys_open("/dev/ps3flash", O_RDWR, 0); | ||
594 | |||
595 | if (file < 0) { | ||
596 | pr_debug("%s:%d sys_open failed\n", __func__, __LINE__); | ||
597 | goto fail_open; | ||
598 | } | ||
599 | |||
600 | header = kmalloc(buf_len, GFP_KERNEL); | 630 | header = kmalloc(buf_len, GFP_KERNEL); |
601 | |||
602 | if (!header) { | 631 | if (!header) { |
603 | pr_debug("%s:%d kmalloc failed\n", __func__, __LINE__); | 632 | pr_debug("%s: kmalloc failed\n", __func__); |
604 | goto fail_malloc; | 633 | return -ENOMEM; |
605 | } | 634 | } |
606 | 635 | ||
607 | offset = sys_lseek(file, 0, SEEK_SET); | 636 | count = os_area_flash_read(header, buf_len, 0); |
608 | 637 | if (count < 0) { | |
609 | if (offset != 0) { | 638 | pr_debug("%s: os_area_flash_read failed %zd\n", __func__, |
610 | pr_debug("%s:%d sys_lseek failed\n", __func__, __LINE__); | 639 | count); |
611 | goto fail_header_seek; | 640 | error = count; |
641 | goto fail; | ||
612 | } | 642 | } |
613 | 643 | ||
614 | count = sys_read(file, (char __user *)header, buf_len); | 644 | pos = header->db_area_offset * OS_AREA_SEGMENT_SIZE; |
615 | 645 | if (count < OS_AREA_SEGMENT_SIZE || verify_header(header) || | |
616 | result = count < OS_AREA_SEGMENT_SIZE || verify_header(header) | 646 | count < pos) { |
617 | || count < header->db_area_offset * OS_AREA_SEGMENT_SIZE; | 647 | pr_debug("%s: verify_header failed\n", __func__); |
618 | |||
619 | if (result) { | ||
620 | pr_debug("%s:%d verify_header failed\n", __func__, __LINE__); | ||
621 | dump_header(header); | 648 | dump_header(header); |
622 | goto fail_header; | 649 | error = -EINVAL; |
650 | goto fail; | ||
623 | } | 651 | } |
624 | 652 | ||
625 | /* Now got a good db offset and some maybe good db data. */ | 653 | /* Now got a good db offset and some maybe good db data. */ |
626 | 654 | ||
627 | db = (void*)header + header->db_area_offset * OS_AREA_SEGMENT_SIZE; | 655 | db = (void *)header + pos; |
628 | 656 | ||
629 | result = db_verify(db); | 657 | error = db_verify(db); |
630 | 658 | if (error) { | |
631 | if (result) { | 659 | pr_notice("%s: Verify of flash database failed, formatting.\n", |
632 | printk(KERN_NOTICE "%s:%d: Verify of flash database failed, " | 660 | __func__); |
633 | "formatting.\n", __func__, __LINE__); | ||
634 | dump_db(db); | 661 | dump_db(db); |
635 | os_area_db_init(db); | 662 | os_area_db_init(db); |
636 | } | 663 | } |
@@ -639,29 +666,16 @@ static void __maybe_unused update_flash_db(void) | |||
639 | 666 | ||
640 | db_set_64(db, &os_area_db_id_rtc_diff, saved_params.rtc_diff); | 667 | db_set_64(db, &os_area_db_id_rtc_diff, saved_params.rtc_diff); |
641 | 668 | ||
642 | offset = sys_lseek(file, header->db_area_offset * OS_AREA_SEGMENT_SIZE, | 669 | count = os_area_flash_write(db, sizeof(struct os_area_db), pos); |
643 | SEEK_SET); | ||
644 | |||
645 | if (offset != header->db_area_offset * OS_AREA_SEGMENT_SIZE) { | ||
646 | pr_debug("%s:%d sys_lseek failed\n", __func__, __LINE__); | ||
647 | goto fail_db_seek; | ||
648 | } | ||
649 | |||
650 | count = sys_write(file, (const char __user *)db, | ||
651 | sizeof(struct os_area_db)); | ||
652 | |||
653 | if (count < sizeof(struct os_area_db)) { | 670 | if (count < sizeof(struct os_area_db)) { |
654 | pr_debug("%s:%d sys_write failed\n", __func__, __LINE__); | 671 | pr_debug("%s: os_area_flash_write failed %zd\n", __func__, |
672 | count); | ||
673 | error = count < 0 ? count : -EIO; | ||
655 | } | 674 | } |
656 | 675 | ||
657 | fail_db_seek: | 676 | fail: |
658 | fail_header: | ||
659 | fail_header_seek: | ||
660 | kfree(header); | 677 | kfree(header); |
661 | fail_malloc: | 678 | return error; |
662 | sys_close(file); | ||
663 | fail_open: | ||
664 | return; | ||
665 | } | 679 | } |
666 | 680 | ||
667 | /** | 681 | /** |
@@ -674,11 +688,11 @@ fail_open: | |||
674 | static void os_area_queue_work_handler(struct work_struct *work) | 688 | static void os_area_queue_work_handler(struct work_struct *work) |
675 | { | 689 | { |
676 | struct device_node *node; | 690 | struct device_node *node; |
691 | int error; | ||
677 | 692 | ||
678 | pr_debug(" -> %s:%d\n", __func__, __LINE__); | 693 | pr_debug(" -> %s:%d\n", __func__, __LINE__); |
679 | 694 | ||
680 | node = of_find_node_by_path("/"); | 695 | node = of_find_node_by_path("/"); |
681 | |||
682 | if (node) { | 696 | if (node) { |
683 | os_area_set_property(node, &property_rtc_diff); | 697 | os_area_set_property(node, &property_rtc_diff); |
684 | of_node_put(node); | 698 | of_node_put(node); |
@@ -686,12 +700,10 @@ static void os_area_queue_work_handler(struct work_struct *work) | |||
686 | pr_debug("%s:%d of_find_node_by_path failed\n", | 700 | pr_debug("%s:%d of_find_node_by_path failed\n", |
687 | __func__, __LINE__); | 701 | __func__, __LINE__); |
688 | 702 | ||
689 | #if defined(CONFIG_PS3_FLASH) || defined(CONFIG_PS3_FLASH_MODULE) | 703 | error = update_flash_db(); |
690 | update_flash_db(); | 704 | if (error) |
691 | #else | 705 | pr_warning("%s: Could not update FLASH ROM\n", __func__); |
692 | printk(KERN_WARNING "%s:%d: No flash rom driver configured.\n", | 706 | |
693 | __func__, __LINE__); | ||
694 | #endif | ||
695 | pr_debug(" <- %s:%d\n", __func__, __LINE__); | 707 | pr_debug(" <- %s:%d\n", __func__, __LINE__); |
696 | } | 708 | } |
697 | 709 | ||
@@ -808,7 +820,7 @@ u64 ps3_os_area_get_rtc_diff(void) | |||
808 | { | 820 | { |
809 | return saved_params.rtc_diff; | 821 | return saved_params.rtc_diff; |
810 | } | 822 | } |
811 | EXPORT_SYMBOL(ps3_os_area_get_rtc_diff); | 823 | EXPORT_SYMBOL_GPL(ps3_os_area_get_rtc_diff); |
812 | 824 | ||
813 | /** | 825 | /** |
814 | * ps3_os_area_set_rtc_diff - Set the rtc diff value. | 826 | * ps3_os_area_set_rtc_diff - Set the rtc diff value. |
@@ -824,7 +836,7 @@ void ps3_os_area_set_rtc_diff(u64 rtc_diff) | |||
824 | os_area_queue_work(); | 836 | os_area_queue_work(); |
825 | } | 837 | } |
826 | } | 838 | } |
827 | EXPORT_SYMBOL(ps3_os_area_set_rtc_diff); | 839 | EXPORT_SYMBOL_GPL(ps3_os_area_set_rtc_diff); |
828 | 840 | ||
829 | /** | 841 | /** |
830 | * ps3_os_area_get_av_multi_out - Returns the default video mode. | 842 | * ps3_os_area_get_av_multi_out - Returns the default video mode. |