23 #include <linux/kernel.h>
26 #include <linux/slab.h>
27 #include <linux/reboot.h>
35 static int __init ps3_register_lpm_devices(
void)
42 pr_debug(
" -> %s:%d\n", __func__, __LINE__);
56 pr_debug(
"%s:%d: ps3_repository_read_be_node_id failed \n",
65 pr_debug(
"%s:%d: ps3_repository_read_lpm_privleges failed \n",
80 pr_debug(
"%s:%d: don't have rights to use lpm\n",
86 pr_debug(
"%s:%d: pu_id %llu, rights %llu(%llxh)\n",
87 __func__, __LINE__, dev->
lpm.pu_id, dev->
lpm.rights,
93 pr_debug(
"%s:%d: ps3_repository_read_pu_id failed \n",
101 pr_debug(
"%s:%d ps3_system_bus_device_register failed\n",
106 pr_debug(
" <- %s:%d\n", __func__, __LINE__);
114 pr_debug(
" <- %s:%d: failed\n", __func__, __LINE__);
125 static int __init ps3_setup_gelic_device(
134 pr_debug(
" -> %s:%d\n", __func__, __LINE__);
150 p->dev.d_region = &
p->d_region;
156 pr_debug(
"%s:%d ps3_repository_find_interrupt failed\n",
158 goto fail_find_interrupt;
161 BUG_ON(
p->dev.interrupt_id != 0);
167 pr_debug(
"%s:%d ps3_dma_region_init failed\n",
175 pr_debug(
"%s:%d ps3_system_bus_device_register failed\n",
177 goto fail_device_register;
180 pr_debug(
" <- %s:%d\n", __func__, __LINE__);
183 fail_device_register:
188 pr_debug(
" <- %s:%d: fail.\n", __func__, __LINE__);
205 pr_debug(
" -> %s:%d\n", __func__, __LINE__);
217 p->dev.match_id = match_id;
221 p->dev.d_region = &
p->d_region;
222 p->dev.m_region = &
p->m_region;
225 interrupt_type, &
p->dev.interrupt_id);
228 pr_debug(
"%s:%d ps3_repository_find_interrupt failed\n",
230 goto fail_find_interrupt;
237 pr_debug(
"%s:%d ps3_repository_find_reg failed\n",
246 pr_debug(
"%s:%d ps3_dma_region_init failed\n",
255 pr_debug(
"%s:%d ps3_mmio_region_init failed\n",
263 pr_debug(
"%s:%d ps3_system_bus_device_register failed\n",
265 goto fail_device_register;
268 pr_debug(
" <- %s:%d\n", __func__, __LINE__);
271 fail_device_register:
278 pr_debug(
" <- %s:%d: fail.\n", __func__, __LINE__);
282 static int __init ps3_setup_ehci_device(
289 static int __init ps3_setup_ohci_device(
304 pr_debug(
" -> %s:%d: match_id %u, port %u\n", __func__, __LINE__,
305 match_id, port_number);
319 pr_debug(
"%s:%d ps3_system_bus_device_register failed\n",
321 goto fail_device_register;
323 pr_debug(
" <- %s:%d\n", __func__, __LINE__);
326 fail_device_register:
328 pr_debug(
" <- %s:%d fail\n", __func__, __LINE__);
340 pr_debug(
" -> %s:%u: match_id %u\n", __func__, __LINE__, match_id);
344 &blk_size, &num_blocks,
348 __func__, __LINE__, result);
352 pr_debug(
"%s:%u: (%u:%u:%u): port %llu blk_size %llu num_blocks %llu "
353 "num_regions %u\n", __func__, __LINE__, repo->
bus_index,
365 p->
sbd.match_id = match_id;
375 &p->
sbd.interrupt_id);
380 goto fail_find_interrupt;
393 "%s:%u: read_stor_dev_region failed %d\n",
394 __func__, __LINE__, result);
396 goto fail_read_region;
398 pr_debug(
"%s:%u: region %u: id %u start %llu size %llu\n",
399 __func__, __LINE__, i,
id, start, size);
408 pr_debug(
"%s:%u ps3_system_bus_device_register failed\n",
410 goto fail_device_register;
413 pr_debug(
" <- %s:%u\n", __func__, __LINE__);
416 fail_device_register:
421 pr_debug(
" <- %s:%u: fail.\n", __func__, __LINE__);
425 static int __init ps3_register_vuart_devices(
void)
430 pr_debug(
" -> %s:%d\n", __func__, __LINE__);
447 pr_debug(
" <- %s:%d\n", __func__, __LINE__);
451 static int __init ps3_register_sound_devices(
void)
460 pr_debug(
" -> %s:%d\n", __func__, __LINE__);
468 p->dev.d_region = &p->d_region;
469 p->dev.m_region = &p->m_region;
474 pr_debug(
"%s:%d ps3_system_bus_device_register failed\n",
476 goto fail_device_register;
478 pr_debug(
" <- %s:%d\n", __func__, __LINE__);
481 fail_device_register:
483 pr_debug(
" <- %s:%d failed\n", __func__, __LINE__);
487 static int __init ps3_register_graphics_devices(
void)
494 pr_debug(
" -> %s:%d\n", __func__, __LINE__);
508 pr_debug(
"%s:%d ps3_system_bus_device_register failed\n",
510 goto fail_device_register;
513 pr_debug(
" <- %s:%d\n", __func__, __LINE__);
516 fail_device_register:
518 pr_debug(
" <- %s:%d failed\n", __func__, __LINE__);
522 static int __init ps3_register_ramdisk_device(
void)
529 pr_debug(
" -> %s:%d\n", __func__, __LINE__);
543 pr_debug(
"%s:%d ps3_system_bus_device_register failed\n",
545 goto fail_device_register;
548 pr_debug(
" <- %s:%d\n", __func__, __LINE__);
551 fail_device_register:
553 pr_debug(
" <- %s:%d failed\n", __func__, __LINE__);
572 pr_debug(
"%s:%u: not accessible\n", __func__,
577 pr_debug(
"%s:%u ps3_setup_storage_dev failed\n",
584 pr_debug(
"%s:%u ps3_setup_storage_dev failed\n",
591 pr_debug(
"%s:%u ps3_setup_storage_dev failed\n",
597 pr_debug(
"%s:%u: unsupported dev_type %u\n", __func__, __LINE__,
614 result = ps3_setup_gelic_device(repo);
616 pr_debug(
"%s:%d ps3_setup_gelic_device failed\n",
624 result = ps3_setup_ehci_device(repo);
627 pr_debug(
"%s:%d ps3_setup_ehci_device failed\n",
631 result = ps3_setup_ohci_device(repo);
634 pr_debug(
"%s:%d ps3_setup_ohci_device failed\n",
640 return ps3_setup_dynamic_device(repo);
657 for (retries = 0; retries < 10; retries++) {
666 pr_warning(
"%s:%u: device %llu:%llu not found\n", __func__, __LINE__,
672 pr_debug(
"%s:%u: device %llu:%llu found after %u retries\n",
673 __func__, __LINE__, bus_id, dev_id, retries);
675 ps3_setup_dynamic_device(&repo);
679 #define PS3_NOTIFICATION_DEV_ID ULONG_MAX
680 #define PS3_NOTIFICATION_INTERRUPT_ID 0
715 spin_lock(&dev->
lock);
719 pr_err(
"%s:%u: tag mismatch, got %llx, expected %llx\n",
720 __func__, __LINE__, tag, dev->
tag);
723 pr_err(
"%s:%u: res %d status 0x%llx\n", __func__, __LINE__, res,
726 pr_debug(
"%s:%u: completed, status 0x%llx\n", __func__,
731 spin_unlock(&dev->
lock);
738 const char *
op = write ?
"write" :
"read";
742 init_completion(&dev->
done);
744 res = write ? lv1_storage_write(dev->
sbd.dev_id, 0, 0, 1, 0, lpar,
746 : lv1_storage_read(dev->
sbd.dev_id, 0, 0, 1, 0, lpar,
748 spin_unlock_irqrestore(&dev->
lock, flags);
750 pr_err(
"%s:%u: %s failed %d\n", __func__, __LINE__, op, res);
753 pr_debug(
"%s:%u: notification %s issued\n", __func__, __LINE__, op);
760 pr_debug(
"%s:%u: interrupted %s\n", __func__, __LINE__, op);
765 pr_err(
"%s:%u: %s not completed, status 0x%llx\n", __func__,
769 pr_debug(
"%s:%u: notification %s completed\n", __func__, __LINE__, op);
786 static int ps3_probe_thread(
void *
data)
796 pr_debug(
" -> %s:%u: kthread started\n", __func__, __LINE__);
807 dev.
sbd.bus_id = (
u64)data;
811 res = lv1_open_device(dev.
sbd.bus_id, dev.
sbd.dev_id, 0);
813 pr_err(
"%s:%u: lv1_open_device failed %s\n", __func__,
814 __LINE__, ps3_result(res));
821 pr_err(
"%s:%u: ps3_sb_event_receive_port_setup failed %d\n",
822 __func__, __LINE__, res);
823 goto fail_close_device;
828 res =
request_irq(irq, ps3_notification_interrupt, 0,
829 "ps3_notification", &dev);
831 pr_err(
"%s:%u: request_irq failed %d\n", __func__, __LINE__,
833 goto fail_sb_event_receive_port_destroy;
840 res = ps3_notification_read_write(&dev, lpar, 1);
848 memset(notify_event, 0,
sizeof(*notify_event));
850 res = ps3_notification_read_write(&dev, lpar, 0);
854 pr_debug(
"%s:%u: notify event type 0x%llx bus id %llu dev id %llu"
855 " type %llu port %llu\n", __func__, __LINE__,
860 if (notify_event->
event_type != notify_region_probe ||
861 notify_event->
bus_id != dev.
sbd.bus_id) {
862 pr_warning(
"%s:%u: bad notify_event: event %llu, "
863 "dev_id %llu, dev_type %llu\n",
870 ps3_find_and_add_device(dev.
sbd.bus_id, notify_event->
dev_id);
876 fail_sb_event_receive_port_destroy:
879 lv1_close_device(dev.
sbd.bus_id, dev.
sbd.dev_id);
885 pr_debug(
" <- %s:%u: kthread finished\n", __func__, __LINE__);
918 pr_debug(
" -> %s:%d\n", __func__, __LINE__);
920 memset(&repo, 0,
sizeof(repo));
940 "ps3-probe-%u", bus_type);
943 result = PTR_ERR(task);
952 pr_debug(
" <- %s:%d\n", __func__, __LINE__);
962 static int __init ps3_register_devices(
void)
966 if (!firmware_has_feature(FW_FEATURE_PS3_LV1))
969 pr_debug(
" -> %s:%d\n", __func__, __LINE__);
975 ps3_register_vuart_devices();
977 ps3_register_graphics_devices();
981 ps3_register_sound_devices();
983 ps3_register_lpm_devices();
985 ps3_register_ramdisk_device();
987 pr_debug(
" <- %s:%d\n", __func__, __LINE__);