device.c (37db8985b2116c89a3cbaf87083a02f83afaba5b) | device.c (418e3ea157efb0eb2c6dd412a8d5f052477c7f5a) |
---|---|
1// SPDX-License-Identifier: GPL-1.0+ 2/* 3 * bus driver for ccw devices 4 * 5 * Copyright IBM Corp. 2002, 2008 6 * Author(s): Arnd Bergmann (arndb@de.ibm.com) 7 * Cornelia Huck (cornelia.huck@de.ibm.com) 8 * Martin Schwidefsky (schwidefsky@de.ibm.com) --- 10 unchanged lines hidden (view full) --- 19#include <linux/slab.h> 20#include <linux/list.h> 21#include <linux/device.h> 22#include <linux/workqueue.h> 23#include <linux/delay.h> 24#include <linux/timer.h> 25#include <linux/kernel_stat.h> 26#include <linux/sched/signal.h> | 1// SPDX-License-Identifier: GPL-1.0+ 2/* 3 * bus driver for ccw devices 4 * 5 * Copyright IBM Corp. 2002, 2008 6 * Author(s): Arnd Bergmann (arndb@de.ibm.com) 7 * Cornelia Huck (cornelia.huck@de.ibm.com) 8 * Martin Schwidefsky (schwidefsky@de.ibm.com) --- 10 unchanged lines hidden (view full) --- 19#include <linux/slab.h> 20#include <linux/list.h> 21#include <linux/device.h> 22#include <linux/workqueue.h> 23#include <linux/delay.h> 24#include <linux/timer.h> 25#include <linux/kernel_stat.h> 26#include <linux/sched/signal.h> |
27#include <linux/dma-mapping.h> | |
28 29#include <asm/ccwdev.h> 30#include <asm/cio.h> 31#include <asm/param.h> /* HZ */ 32#include <asm/cmb.h> 33#include <asm/isc.h> 34 35#include "chp.h" --- 602 unchanged lines hidden (view full) --- 638static int ccw_device_add(struct ccw_device *cdev) 639{ 640 struct device *dev = &cdev->dev; 641 642 dev->bus = &ccw_bus_type; 643 return device_add(dev); 644} 645 | 27 28#include <asm/ccwdev.h> 29#include <asm/cio.h> 30#include <asm/param.h> /* HZ */ 31#include <asm/cmb.h> 32#include <asm/isc.h> 33 34#include "chp.h" --- 602 unchanged lines hidden (view full) --- 637static int ccw_device_add(struct ccw_device *cdev) 638{ 639 struct device *dev = &cdev->dev; 640 641 dev->bus = &ccw_bus_type; 642 return device_add(dev); 643} 644 |
646static int match_dev_id(struct device *dev, void *data) | 645static int match_dev_id(struct device *dev, const void *data) |
647{ 648 struct ccw_device *cdev = to_ccwdev(dev); | 646{ 647 struct ccw_device *cdev = to_ccwdev(dev); |
649 struct ccw_dev_id *dev_id = data; | 648 struct ccw_dev_id *dev_id = (void *)data; |
650 651 return ccw_dev_id_is_equal(&cdev->private->dev_id, dev_id); 652} 653 654/** 655 * get_ccwdev_by_dev_id() - obtain device from a ccw device id 656 * @dev_id: id of the device to be searched 657 * --- 25 unchanged lines hidden (view full) --- 683} 684 685static void 686ccw_device_release(struct device *dev) 687{ 688 struct ccw_device *cdev; 689 690 cdev = to_ccwdev(dev); | 649 650 return ccw_dev_id_is_equal(&cdev->private->dev_id, dev_id); 651} 652 653/** 654 * get_ccwdev_by_dev_id() - obtain device from a ccw device id 655 * @dev_id: id of the device to be searched 656 * --- 25 unchanged lines hidden (view full) --- 682} 683 684static void 685ccw_device_release(struct device *dev) 686{ 687 struct ccw_device *cdev; 688 689 cdev = to_ccwdev(dev); |
691 cio_gp_dma_free(cdev->private->dma_pool, cdev->private->dma_area, 692 sizeof(*cdev->private->dma_area)); 693 cio_gp_dma_destroy(cdev->private->dma_pool, &cdev->dev); | |
694 /* Release reference of parent subchannel. */ 695 put_device(cdev->dev.parent); 696 kfree(cdev->private); 697 kfree(cdev); 698} 699 700static struct ccw_device * io_subchannel_allocate_dev(struct subchannel *sch) 701{ 702 struct ccw_device *cdev; | 690 /* Release reference of parent subchannel. */ 691 put_device(cdev->dev.parent); 692 kfree(cdev->private); 693 kfree(cdev); 694} 695 696static struct ccw_device * io_subchannel_allocate_dev(struct subchannel *sch) 697{ 698 struct ccw_device *cdev; |
703 struct gen_pool *dma_pool; | |
704 705 cdev = kzalloc(sizeof(*cdev), GFP_KERNEL); | 699 700 cdev = kzalloc(sizeof(*cdev), GFP_KERNEL); |
706 if (!cdev) 707 goto err_cdev; 708 cdev->private = kzalloc(sizeof(struct ccw_device_private), 709 GFP_KERNEL | GFP_DMA); 710 if (!cdev->private) 711 goto err_priv; 712 cdev->dev.coherent_dma_mask = sch->dev.coherent_dma_mask; 713 cdev->dev.dma_mask = &cdev->dev.coherent_dma_mask; 714 dma_pool = cio_gp_dma_create(&cdev->dev, 1); 715 if (!dma_pool) 716 goto err_dma_pool; 717 cdev->private->dma_pool = dma_pool; 718 cdev->private->dma_area = cio_gp_dma_zalloc(dma_pool, &cdev->dev, 719 sizeof(*cdev->private->dma_area)); 720 if (!cdev->private->dma_area) 721 goto err_dma_area; 722 return cdev; 723err_dma_area: 724 cio_gp_dma_destroy(dma_pool, &cdev->dev); 725err_dma_pool: 726 kfree(cdev->private); 727err_priv: | 701 if (cdev) { 702 cdev->private = kzalloc(sizeof(struct ccw_device_private), 703 GFP_KERNEL | GFP_DMA); 704 if (cdev->private) 705 return cdev; 706 } |
728 kfree(cdev); | 707 kfree(cdev); |
729err_cdev: | |
730 return ERR_PTR(-ENOMEM); 731} 732 733static void ccw_device_todo(struct work_struct *work); 734 735static int io_subchannel_initialize_dev(struct subchannel *sch, 736 struct ccw_device *cdev) 737{ --- 163 unchanged lines hidden (view full) --- 901 case DEV_STATE_NOT_OPER: 902 cdev->private->flags.recog_done = 1; 903 /* Remove device found not operational. */ 904 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG); 905 if (atomic_dec_and_test(&ccw_device_init_count)) 906 wake_up(&ccw_device_init_wq); 907 break; 908 case DEV_STATE_OFFLINE: | 708 return ERR_PTR(-ENOMEM); 709} 710 711static void ccw_device_todo(struct work_struct *work); 712 713static int io_subchannel_initialize_dev(struct subchannel *sch, 714 struct ccw_device *cdev) 715{ --- 163 unchanged lines hidden (view full) --- 879 case DEV_STATE_NOT_OPER: 880 cdev->private->flags.recog_done = 1; 881 /* Remove device found not operational. */ 882 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG); 883 if (atomic_dec_and_test(&ccw_device_init_count)) 884 wake_up(&ccw_device_init_wq); 885 break; 886 case DEV_STATE_OFFLINE: |
909 /* | 887 /* |
910 * We can't register the device in interrupt context so 911 * we schedule a work item. 912 */ 913 ccw_device_sched_todo(cdev, CDEV_TODO_REGISTER); 914 break; 915 } 916} 917 --- 161 unchanged lines hidden (view full) --- 1079 &io_subchannel_attr_group); 1080 if (rc) 1081 goto out_schedule; 1082 /* Allocate I/O subchannel private data. */ 1083 io_priv = kzalloc(sizeof(*io_priv), GFP_KERNEL | GFP_DMA); 1084 if (!io_priv) 1085 goto out_schedule; 1086 | 888 * We can't register the device in interrupt context so 889 * we schedule a work item. 890 */ 891 ccw_device_sched_todo(cdev, CDEV_TODO_REGISTER); 892 break; 893 } 894} 895 --- 161 unchanged lines hidden (view full) --- 1057 &io_subchannel_attr_group); 1058 if (rc) 1059 goto out_schedule; 1060 /* Allocate I/O subchannel private data. */ 1061 io_priv = kzalloc(sizeof(*io_priv), GFP_KERNEL | GFP_DMA); 1062 if (!io_priv) 1063 goto out_schedule; 1064 |
1087 io_priv->dma_area = dma_alloc_coherent(&sch->dev, 1088 sizeof(*io_priv->dma_area), 1089 &io_priv->dma_area_dma, GFP_KERNEL); 1090 if (!io_priv->dma_area) { 1091 kfree(io_priv); 1092 goto out_schedule; 1093 } 1094 | |
1095 set_io_private(sch, io_priv); 1096 css_schedule_eval(sch->schid); 1097 return 0; 1098 1099out_schedule: 1100 spin_lock_irq(sch->lock); 1101 css_sched_sch_todo(sch, SCH_TODO_UNREG); 1102 spin_unlock_irq(sch->lock); --- 10 unchanged lines hidden (view full) --- 1113 goto out_free; 1114 1115 ccw_device_unregister(cdev); 1116 spin_lock_irq(sch->lock); 1117 sch_set_cdev(sch, NULL); 1118 set_io_private(sch, NULL); 1119 spin_unlock_irq(sch->lock); 1120out_free: | 1065 set_io_private(sch, io_priv); 1066 css_schedule_eval(sch->schid); 1067 return 0; 1068 1069out_schedule: 1070 spin_lock_irq(sch->lock); 1071 css_sched_sch_todo(sch, SCH_TODO_UNREG); 1072 spin_unlock_irq(sch->lock); --- 10 unchanged lines hidden (view full) --- 1083 goto out_free; 1084 1085 ccw_device_unregister(cdev); 1086 spin_lock_irq(sch->lock); 1087 sch_set_cdev(sch, NULL); 1088 set_io_private(sch, NULL); 1089 spin_unlock_irq(sch->lock); 1090out_free: |
1121 dma_free_coherent(&sch->dev, sizeof(*io_priv->dma_area), 1122 io_priv->dma_area, io_priv->dma_area_dma); | |
1123 kfree(io_priv); 1124 sysfs_remove_group(&sch->dev.kobj, &io_subchannel_attr_group); 1125 return 0; 1126} 1127 1128static void io_subchannel_verify(struct subchannel *sch) 1129{ 1130 struct ccw_device *cdev; --- 489 unchanged lines hidden (view full) --- 1620 struct ccw_device *cdev; 1621 struct subchannel *sch; 1622 1623 sch = cio_probe_console(); 1624 if (IS_ERR(sch)) 1625 return ERR_CAST(sch); 1626 1627 io_priv = kzalloc(sizeof(*io_priv), GFP_KERNEL | GFP_DMA); | 1091 kfree(io_priv); 1092 sysfs_remove_group(&sch->dev.kobj, &io_subchannel_attr_group); 1093 return 0; 1094} 1095 1096static void io_subchannel_verify(struct subchannel *sch) 1097{ 1098 struct ccw_device *cdev; --- 489 unchanged lines hidden (view full) --- 1588 struct ccw_device *cdev; 1589 struct subchannel *sch; 1590 1591 sch = cio_probe_console(); 1592 if (IS_ERR(sch)) 1593 return ERR_CAST(sch); 1594 1595 io_priv = kzalloc(sizeof(*io_priv), GFP_KERNEL | GFP_DMA); |
1628 if (!io_priv) 1629 goto err_priv; 1630 io_priv->dma_area = dma_alloc_coherent(&sch->dev, 1631 sizeof(*io_priv->dma_area), 1632 &io_priv->dma_area_dma, GFP_KERNEL); 1633 if (!io_priv->dma_area) 1634 goto err_dma_area; | 1596 if (!io_priv) { 1597 put_device(&sch->dev); 1598 return ERR_PTR(-ENOMEM); 1599 } |
1635 set_io_private(sch, io_priv); 1636 cdev = io_subchannel_create_ccwdev(sch); 1637 if (IS_ERR(cdev)) { | 1600 set_io_private(sch, io_priv); 1601 cdev = io_subchannel_create_ccwdev(sch); 1602 if (IS_ERR(cdev)) { |
1638 dma_free_coherent(&sch->dev, sizeof(*io_priv->dma_area), 1639 io_priv->dma_area, io_priv->dma_area_dma); 1640 set_io_private(sch, NULL); | |
1641 put_device(&sch->dev); 1642 kfree(io_priv); 1643 return cdev; 1644 } 1645 cdev->drv = drv; 1646 ccw_device_set_int_class(cdev); 1647 return cdev; | 1603 put_device(&sch->dev); 1604 kfree(io_priv); 1605 return cdev; 1606 } 1607 cdev->drv = drv; 1608 ccw_device_set_int_class(cdev); 1609 return cdev; |
1648 1649err_dma_area: 1650 kfree(io_priv); 1651err_priv: 1652 put_device(&sch->dev); 1653 return ERR_PTR(-ENOMEM); | |
1654} 1655 1656void __init ccw_device_destroy_console(struct ccw_device *cdev) 1657{ 1658 struct subchannel *sch = to_subchannel(cdev->dev.parent); 1659 struct io_subchannel_private *io_priv = to_io_private(sch); 1660 1661 set_io_private(sch, NULL); 1662 put_device(&sch->dev); 1663 put_device(&cdev->dev); | 1610} 1611 1612void __init ccw_device_destroy_console(struct ccw_device *cdev) 1613{ 1614 struct subchannel *sch = to_subchannel(cdev->dev.parent); 1615 struct io_subchannel_private *io_priv = to_io_private(sch); 1616 1617 set_io_private(sch, NULL); 1618 put_device(&sch->dev); 1619 put_device(&cdev->dev); |
1664 dma_free_coherent(&sch->dev, sizeof(*io_priv->dma_area), 1665 io_priv->dma_area, io_priv->dma_area_dma); | |
1666 kfree(io_priv); 1667} 1668 1669/** 1670 * ccw_device_wait_idle() - busy wait for device to become idle 1671 * @cdev: ccw device 1672 * 1673 * Poll until activity control is zero, that is, no function or data --- 495 unchanged lines hidden --- | 1620 kfree(io_priv); 1621} 1622 1623/** 1624 * ccw_device_wait_idle() - busy wait for device to become idle 1625 * @cdev: ccw device 1626 * 1627 * Poll until activity control is zero, that is, no function or data --- 495 unchanged lines hidden --- |