aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoman Kiryanov <rkir@google.com>2018-10-03 13:17:08 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-10-15 14:36:46 -0400
commit08360e26f2a8eba0105ca7cd598547a1749b1c68 (patch)
treed40b16df06ae068a37928fc52fb6b9382699fdf9
parent43c2cc2864bca0cceff331f27fe762fcf0d804b2 (diff)
platform: goldfish: pipe: Move the file-scope goldfish_pipe_dev variable into the driver state
This is the last patch in the series of patches to move file-scope variables into the driver state. This change will help to introduce another version of the pipe driver (with different state) for the older host interface or having several instances of this device. Signed-off-by: Roman Kiryanov <rkir@google.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/platform/goldfish/goldfish_pipe.c66
1 files changed, 37 insertions, 29 deletions
diff --git a/drivers/platform/goldfish/goldfish_pipe.c b/drivers/platform/goldfish/goldfish_pipe.c
index 8ca709b45e1f..4013832f38fb 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -169,6 +169,9 @@ struct goldfish_pipe {
169 * waiting to be awoken. 169 * waiting to be awoken.
170 */ 170 */
171struct goldfish_pipe_dev { 171struct goldfish_pipe_dev {
172 /* A magic number to check if this is an instance of this struct */
173 void *magic;
174
172 /* 175 /*
173 * Global device spinlock. Protects the following members: 176 * Global device spinlock. Protects the following members:
174 * - pipes, pipes_capacity 177 * - pipes, pipes_capacity
@@ -215,8 +218,6 @@ struct goldfish_pipe_dev {
215 struct miscdevice miscdev; 218 struct miscdevice miscdev;
216}; 219};
217 220
218static struct goldfish_pipe_dev goldfish_pipe_dev;
219
220static int goldfish_pipe_cmd_locked(struct goldfish_pipe *pipe, 221static int goldfish_pipe_cmd_locked(struct goldfish_pipe *pipe,
221 enum PipeCmdCode cmd) 222 enum PipeCmdCode cmd)
222{ 223{
@@ -611,6 +612,9 @@ static void goldfish_interrupt_task(unsigned long dev_addr)
611 } 612 }
612} 613}
613 614
615static void goldfish_pipe_device_deinit(struct platform_device *pdev,
616 struct goldfish_pipe_dev *dev);
617
614/* 618/*
615 * The general idea of the interrupt handling: 619 * The general idea of the interrupt handling:
616 * 620 *
@@ -631,7 +635,7 @@ static irqreturn_t goldfish_pipe_interrupt(int irq, void *dev_id)
631 unsigned long flags; 635 unsigned long flags;
632 struct goldfish_pipe_dev *dev = dev_id; 636 struct goldfish_pipe_dev *dev = dev_id;
633 637
634 if (dev != &goldfish_pipe_dev) 638 if (dev->magic != &goldfish_pipe_device_deinit)
635 return IRQ_NONE; 639 return IRQ_NONE;
636 640
637 /* Request the signalled pipes from the device */ 641 /* Request the signalled pipes from the device */
@@ -683,6 +687,14 @@ static int get_free_pipe_id_locked(struct goldfish_pipe_dev *dev)
683 return id; 687 return id;
684} 688}
685 689
690/* A helper function to get the instance of goldfish_pipe_dev from file */
691static struct goldfish_pipe_dev *to_goldfish_pipe_dev(struct file *file)
692{
693 struct miscdevice *miscdev = file->private_data;
694
695 return container_of(miscdev, struct goldfish_pipe_dev, miscdev);
696}
697
686/** 698/**
687 * goldfish_pipe_open - open a channel to the AVD 699 * goldfish_pipe_open - open a channel to the AVD
688 * @inode: inode of device 700 * @inode: inode of device
@@ -696,7 +708,7 @@ static int get_free_pipe_id_locked(struct goldfish_pipe_dev *dev)
696 */ 708 */
697static int goldfish_pipe_open(struct inode *inode, struct file *file) 709static int goldfish_pipe_open(struct inode *inode, struct file *file)
698{ 710{
699 struct goldfish_pipe_dev *dev = &goldfish_pipe_dev; 711 struct goldfish_pipe_dev *dev = to_goldfish_pipe_dev(file);
700 unsigned long flags; 712 unsigned long flags;
701 int id; 713 int id;
702 int status; 714 int status;
@@ -804,9 +816,9 @@ static void write_pa_addr(void *addr, void __iomem *portl, void __iomem *porth)
804 writel(lower_32_bits(paddr), portl); 816 writel(lower_32_bits(paddr), portl);
805} 817}
806 818
807static int goldfish_pipe_device_init(struct platform_device *pdev) 819static int goldfish_pipe_device_init(struct platform_device *pdev,
820 struct goldfish_pipe_dev *dev)
808{ 821{
809 struct goldfish_pipe_dev *dev = &goldfish_pipe_dev;
810 int err; 822 int err;
811 823
812 tasklet_init(&dev->irq_tasklet, &goldfish_interrupt_task, 824 tasklet_init(&dev->irq_tasklet, &goldfish_interrupt_task,
@@ -861,26 +873,29 @@ static int goldfish_pipe_device_init(struct platform_device *pdev)
861 dev->base + PIPE_REG_OPEN_BUFFER, 873 dev->base + PIPE_REG_OPEN_BUFFER,
862 dev->base + PIPE_REG_OPEN_BUFFER_HIGH); 874 dev->base + PIPE_REG_OPEN_BUFFER_HIGH);
863 875
876 platform_set_drvdata(pdev, dev);
864 return 0; 877 return 0;
865} 878}
866 879
867static void goldfish_pipe_device_deinit(struct platform_device *pdev) 880static void goldfish_pipe_device_deinit(struct platform_device *pdev,
881 struct goldfish_pipe_dev *dev)
868{ 882{
869 misc_deregister(&goldfish_pipe_dev.miscdev); 883 misc_deregister(&dev->miscdev);
870 tasklet_kill(&goldfish_pipe_dev.irq_tasklet); 884 tasklet_kill(&dev->irq_tasklet);
871 kfree(goldfish_pipe_dev.pipes); 885 kfree(dev->pipes);
872 free_page((unsigned long)goldfish_pipe_dev.buffers); 886 free_page((unsigned long)dev->buffers);
873} 887}
874 888
875static int goldfish_pipe_probe(struct platform_device *pdev) 889static int goldfish_pipe_probe(struct platform_device *pdev)
876{ 890{
877 int err;
878 struct resource *r; 891 struct resource *r;
879 struct goldfish_pipe_dev *dev = &goldfish_pipe_dev; 892 struct goldfish_pipe_dev *dev;
880 893
881 /* not thread safe, but this should not happen */ 894 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
882 WARN_ON(dev->base); 895 if (!dev)
896 return -ENOMEM;
883 897
898 dev->magic = &goldfish_pipe_device_deinit;
884 spin_lock_init(&dev->lock); 899 spin_lock_init(&dev->lock);
885 900
886 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 901 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -895,10 +910,9 @@ static int goldfish_pipe_probe(struct platform_device *pdev)
895 } 910 }
896 911
897 r = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 912 r = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
898 if (!r) { 913 if (!r)
899 err = -EINVAL; 914 return -EINVAL;
900 goto error; 915
901 }
902 dev->irq = r->start; 916 dev->irq = r->start;
903 917
904 /* 918 /*
@@ -913,20 +927,14 @@ static int goldfish_pipe_probe(struct platform_device *pdev)
913 if (WARN_ON(dev->version < PIPE_CURRENT_DEVICE_VERSION)) 927 if (WARN_ON(dev->version < PIPE_CURRENT_DEVICE_VERSION))
914 return -EINVAL; 928 return -EINVAL;
915 929
916 err = goldfish_pipe_device_init(pdev); 930 return goldfish_pipe_device_init(pdev, dev);
917 if (!err)
918 return 0;
919
920error:
921 dev->base = NULL;
922 return err;
923} 931}
924 932
925static int goldfish_pipe_remove(struct platform_device *pdev) 933static int goldfish_pipe_remove(struct platform_device *pdev)
926{ 934{
927 struct goldfish_pipe_dev *dev = &goldfish_pipe_dev; 935 struct goldfish_pipe_dev *dev = platform_get_drvdata(pdev);
928 goldfish_pipe_device_deinit(pdev); 936
929 dev->base = NULL; 937 goldfish_pipe_device_deinit(pdev, dev);
930 return 0; 938 return 0;
931} 939}
932 940