21 #include <linux/kernel.h>
23 #include <linux/export.h>
26 #include <linux/slab.h>
35 static struct device ps3_system_bus = {
36 .init_name =
"ps3_system",
60 if (ps3_is_device(dev, 1, 1)) {
68 if (ps3_is_device(dev, 1, 2)) {
79 pr_debug(
"%s:%d: lv1_open_device failed: %s\n", __func__,
80 __LINE__, ps3_result(result));
96 if (ps3_is_device(dev, 1, 1)) {
104 if (ps3_is_device(dev, 1, 2)) {
132 result = lv1_gpu_open(0);
135 pr_debug(
"%s:%d: lv1_gpu_open failed: %s\n", __func__,
136 __LINE__, ps3_result(result));
157 result = lv1_gpu_close();
177 return ps3_open_hv_device_sb(dev);
181 return ps3_open_hv_device_gpu(dev);
185 pr_debug(
"%s:%d: unsupported match_id: %u\n", __func__,
187 pr_debug(
"%s:%d: bus_id: %llu\n", __func__, __LINE__,
196 pr_debug(
"%s:%d: unknown match_id: %u\n", __func__, __LINE__,
215 return ps3_close_hv_device_sb(dev);
219 return ps3_close_hv_device_gpu(dev);
223 pr_debug(
"%s:%d: unsupported match_id: %u\n", __func__,
225 pr_debug(
"%s:%d: bus_id: %llu\n", __func__, __LINE__,
234 pr_debug(
"%s:%d: unknown match_id: %u\n", __func__, __LINE__,
241 #define dump_mmio_region(_a) _dump_mmio_region(_a, __func__, __LINE__)
245 pr_debug(
"%s:%d: dev %llu:%llu\n", func, line, r->
dev->bus_id,
257 result = lv1_map_device_mmio_region(r->
dev->bus_id, r->
dev->dev_id,
262 pr_debug(
"%s:%d: lv1_map_device_mmio_region failed: %s\n",
263 __func__, __LINE__, ps3_result(result));
288 result = lv1_unmap_device_mmio_region(r->
dev->bus_id, r->
dev->dev_id,
292 pr_debug(
"%s:%d: lv1_unmap_device_mmio_region failed: %s\n",
293 __func__, __LINE__, ps3_result(result));
314 .create = ps3_sb_mmio_region_create,
315 .free = ps3_sb_free_mmio_region
319 .create = ps3_ioc0_mmio_region_create,
320 .free = ps3_ioc0_free_mmio_region
333 r->
mmio_ops = &ps3_mmio_sb_region_ops;
336 r->
mmio_ops = &ps3_mmio_ioc0_region_ops;
346 static int ps3_system_bus_match(
struct device *_dev,
360 pr_info(
"%s:%d: dev=%u.%u(%s), drv=%u.%u(%s): match\n",
365 pr_debug(
"%s:%d: dev=%u.%u(%s), drv=%u.%u(%s): miss\n",
373 static int ps3_system_bus_probe(
struct device *_dev)
380 dev_dbg(_dev,
"%s:%d\n", __func__, __LINE__);
382 drv = ps3_system_bus_dev_to_system_bus_drv(dev);
386 result = drv->
probe(dev);
388 pr_debug(
"%s:%d: %s no probe method\n", __func__, __LINE__,
389 dev_name(&dev->
core));
391 pr_debug(
" <- %s:%d: %s\n", __func__, __LINE__, dev_name(&dev->
core));
395 static int ps3_system_bus_remove(
struct device *_dev)
402 dev_dbg(_dev,
"%s:%d\n", __func__, __LINE__);
404 drv = ps3_system_bus_dev_to_system_bus_drv(dev);
408 result = drv->
remove(dev);
410 dev_dbg(&dev->
core,
"%s:%d %s: no remove method\n",
411 __func__, __LINE__, drv->
core.name);
413 pr_debug(
" <- %s:%d: %s\n", __func__, __LINE__, dev_name(&dev->
core));
417 static void ps3_system_bus_shutdown(
struct device *_dev)
424 dev_dbg(&dev->
core,
" -> %s:%d: match_id %d\n", __func__, __LINE__,
427 if (!dev->
core.driver) {
428 dev_dbg(&dev->
core,
"%s:%d: no driver bound\n", __func__,
433 drv = ps3_system_bus_dev_to_system_bus_drv(dev);
437 dev_dbg(&dev->
core,
"%s:%d: %s -> %s\n", __func__, __LINE__,
438 dev_name(&dev->
core), drv->
core.name);
443 dev_dbg(&dev->
core,
"%s:%d %s: no shutdown, calling remove\n",
444 __func__, __LINE__, drv->
core.name);
447 dev_dbg(&dev->
core,
"%s:%d %s: no shutdown method\n",
448 __func__, __LINE__, drv->
core.name);
452 dev_dbg(&dev->
core,
" <- %s:%d\n", __func__, __LINE__);
481 .name =
"ps3_system_bus",
482 .match = ps3_system_bus_match,
483 .uevent = ps3_system_bus_uevent,
484 .probe = ps3_system_bus_probe,
485 .remove = ps3_system_bus_remove,
486 .shutdown = ps3_system_bus_shutdown,
487 .dev_attrs = ps3_system_bus_dev_attrs,
490 static int __init ps3_system_bus_init(
void)
494 if (!firmware_has_feature(FW_FEATURE_PS3_LV1))
497 pr_debug(
" -> %s:%d\n", __func__, __LINE__);
507 pr_debug(
" <- %s:%d\n", __func__, __LINE__);
517 static void * ps3_alloc_coherent(
struct device *_dev,
size_t size,
523 unsigned long virt_addr;
531 pr_debug(
"%s:%d: get_free_pages failed\n", __func__, __LINE__);
540 pr_debug(
"%s:%d: ps3_dma_map failed (%d)\n",
541 __func__, __LINE__, result);
542 BUG_ON(
"check region type");
546 return (
void*)virt_addr;
555 static void ps3_free_coherent(
struct device *_dev,
size_t size,
void *
vaddr,
585 pr_debug(
"%s:%d: ps3_dma_map failed (%d)\n",
586 __func__, __LINE__, result);
593 unsigned long offset,
size_t size,
619 &bus_addr, iopte_flag);
622 pr_debug(
"%s:%d: ps3_dma_map failed (%d)\n",
623 __func__, __LINE__, result);
637 pr_debug(
"%s:%d: ps3_dma_unmap failed (%d)\n",
638 __func__, __LINE__, result);
645 #if defined(CONFIG_PS3_DYNAMIC_DMA)
658 pr_debug(
"%s:%d: ps3_dma_map failed (%d)\n",
659 __func__, __LINE__, result);
663 sg->dma_length = sg->
length;
682 #if defined(CONFIG_PS3_DYNAMIC_DMA)
699 static u64 ps3_dma_get_required_mask(
struct device *_dev)
705 .alloc = ps3_alloc_coherent,
706 .free = ps3_free_coherent,
707 .map_sg = ps3_sb_map_sg,
708 .unmap_sg = ps3_sb_unmap_sg,
709 .dma_supported = ps3_dma_supported,
710 .get_required_mask = ps3_dma_get_required_mask,
711 .map_page = ps3_sb_map_page,
712 .unmap_page = ps3_unmap_page,
716 .alloc = ps3_alloc_coherent,
717 .free = ps3_free_coherent,
718 .map_sg = ps3_ioc0_map_sg,
719 .unmap_sg = ps3_ioc0_unmap_sg,
720 .dma_supported = ps3_dma_supported,
721 .get_required_mask = ps3_dma_get_required_mask,
722 .map_page = ps3_ioc0_map_page,
723 .unmap_page = ps3_unmap_page,
730 static void ps3_system_bus_release_device(
struct device *_dev)
747 static unsigned int dev_ioc0_count;
748 static unsigned int dev_sb_count;
749 static unsigned int dev_vuart_count;
750 static unsigned int dev_lpm_count;
752 if (!dev->
core.parent)
753 dev->
core.parent = &ps3_system_bus;
755 dev->
core.release = ps3_system_bus_release_device;
759 dev->
core.archdata.dma_ops = &ps3_ioc0_dma_ops;
763 dev->
core.archdata.dma_ops = &ps3_sb_dma_ops;
778 set_dev_node(&dev->
core, 0);
780 pr_debug(
"%s:%d add %s\n", __func__, __LINE__, dev_name(&dev->
core));
792 pr_debug(
" -> %s:%d: %s\n", __func__, __LINE__, drv->
core.name);
794 if (!firmware_has_feature(FW_FEATURE_PS3_LV1))
800 pr_debug(
" <- %s:%d: %s\n", __func__, __LINE__, drv->
core.name);
808 pr_debug(
" -> %s:%d: %s\n", __func__, __LINE__, drv->
core.name);
810 pr_debug(
" <- %s:%d: %s\n", __func__, __LINE__, drv->
core.name);