[PATCH] drivers: mmc: host: Retire MMC_GOLDFISH

2021-02-09 Thread rkir
From: Roman Kiryanov 

Android Studio Emulator no longer uses
this driver.

Signed-off-by: Roman Kiryanov 
---
 drivers/mmc/host/Kconfig|   7 -
 drivers/mmc/host/Makefile   |   1 -
 drivers/mmc/host/android-goldfish.c | 545 
 3 files changed, 553 deletions(-)
 delete mode 100644 drivers/mmc/host/android-goldfish.c

diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
index 596f32637315..ad4678c9bac1 100644
--- a/drivers/mmc/host/Kconfig
+++ b/drivers/mmc/host/Kconfig
@@ -608,13 +608,6 @@ config MMC_DAVINCI
  If you have an DAVINCI board with a Multimedia Card slot,
  say Y or M here.  If unsure, say N.
 
-config MMC_GOLDFISH
-   tristate "goldfish qemu Multimedia Card Interface support"
-   depends on GOLDFISH || COMPILE_TEST
-   help
- This selects the Goldfish Multimedia card Interface emulation
- found on the Goldfish Android virtual device emulation.
-
 config MMC_SPI
tristate "MMC/SD/SDIO over SPI"
depends on SPI_MASTER
diff --git a/drivers/mmc/host/Makefile b/drivers/mmc/host/Makefile
index 451c25fc2c69..7f97e97f7066 100644
--- a/drivers/mmc/host/Makefile
+++ b/drivers/mmc/host/Makefile
@@ -34,7 +34,6 @@ obj-$(CONFIG_MMC_ATMELMCI)+= atmel-mci.o
 obj-$(CONFIG_MMC_TIFM_SD)  += tifm_sd.o
 obj-$(CONFIG_MMC_MVSDIO)   += mvsdio.o
 obj-$(CONFIG_MMC_DAVINCI)   += davinci_mmc.o
-obj-$(CONFIG_MMC_GOLDFISH) += android-goldfish.o
 obj-$(CONFIG_MMC_SPI)  += mmc_spi.o
 ifeq ($(CONFIG_OF),y)
 obj-$(CONFIG_MMC_SPI)  += of_mmc_spi.o
diff --git a/drivers/mmc/host/android-goldfish.c 
b/drivers/mmc/host/android-goldfish.c
deleted file mode 100644
index e878fdf8f20a..
--- a/drivers/mmc/host/android-goldfish.c
+++ /dev/null
@@ -1,545 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-only
-/*
- *  Copyright 2007, Google Inc.
- *  Copyright 2012, Intel Inc.
- *
- *  based on omap.c driver, which was
- *  Copyright (C) 2004 Nokia Corporation
- *  Written by Tuukka Tikkanen and Juha Yrjölä 
- *  Misc hacks here and there by Tony Lindgren 
- *  Other hacks (DMA, SD, etc) by David Brownell
- */
-
-#include 
-#include 
-#include 
-
-#include 
-#include 
-#include 
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include 
-#include 
-
-#include 
-#include 
-
-#define DRIVER_NAME "goldfish_mmc"
-
-#define BUFFER_SIZE   16384
-
-#define GOLDFISH_MMC_READ(host, addr)   (readl(host->reg_base + addr))
-#define GOLDFISH_MMC_WRITE(host, addr, x)   (writel(x, host->reg_base + addr))
-
-enum {
-   /* status register */
-   MMC_INT_STATUS  = 0x00,
-   /* set this to enable IRQ */
-   MMC_INT_ENABLE  = 0x04,
-   /* set this to specify buffer address */
-   MMC_SET_BUFFER  = 0x08,
-
-   /* MMC command number */
-   MMC_CMD = 0x0C,
-
-   /* MMC argument */
-   MMC_ARG = 0x10,
-
-   /* MMC response (or R2 bits 0 - 31) */
-   MMC_RESP_0  = 0x14,
-
-   /* MMC R2 response bits 32 - 63 */
-   MMC_RESP_1  = 0x18,
-
-   /* MMC R2 response bits 64 - 95 */
-   MMC_RESP_2  = 0x1C,
-
-   /* MMC R2 response bits 96 - 127 */
-   MMC_RESP_3  = 0x20,
-
-   MMC_BLOCK_LENGTH= 0x24,
-   MMC_BLOCK_COUNT = 0x28,
-
-   /* MMC state flags */
-   MMC_STATE   = 0x2C,
-
-   /* MMC_INT_STATUS bits */
-
-   MMC_STAT_END_OF_CMD = 1U << 0,
-   MMC_STAT_END_OF_DATA= 1U << 1,
-   MMC_STAT_STATE_CHANGE   = 1U << 2,
-   MMC_STAT_CMD_TIMEOUT= 1U << 3,
-
-   /* MMC_STATE bits */
-   MMC_STATE_INSERTED = 1U << 0,
-   MMC_STATE_READ_ONLY= 1U << 1,
-};
-
-/*
- * Command types
- */
-#define OMAP_MMC_CMDTYPE_BC0
-#define OMAP_MMC_CMDTYPE_BCR   1
-#define OMAP_MMC_CMDTYPE_AC2
-#define OMAP_MMC_CMDTYPE_ADTC  3
-
-
-struct goldfish_mmc_host {
-   struct mmc_request  *mrq;
-   struct mmc_command  *cmd;
-   struct mmc_data *data;
-   struct device   *dev;
-   unsigned char   id; /* 16xx chips have 2 MMC blocks */
-   void*virt_base;
-   unsigned intphys_base;
-   int irq;
-   unsigned char   bus_mode;
-   unsigned char   hw_bus_mode;
-
-   unsigned intsg_len;
-   unsigneddma_done:1;
-   unsigneddma_in_use:1;
-
-   void __iomem*reg_base;
-};
-
-static inline int
-goldfish_mmc_cover_is_open(struct goldfish_mmc_host *host)
-{
-   return 0;
-}
-
-static ssize_t
-goldfish_mmc_show_cover_switch(struct device *dev,
-  

[PATCH] drivers: mmc: host: Retire MMC_GOLDFISH

2021-02-08 Thread rkir
From: Roman Kiryanov 

Android Studio Emulator no longer uses
this driver.

Signed-off-by: Roman Kiryanov 
---
 drivers/mmc/host/Kconfig|   7 -
 drivers/mmc/host/Makefile   |   1 -
 drivers/mmc/host/android-goldfish.c | 545 
 3 files changed, 553 deletions(-)
 delete mode 100644 drivers/mmc/host/android-goldfish.c

diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
index 596f32637315..ad4678c9bac1 100644
--- a/drivers/mmc/host/Kconfig
+++ b/drivers/mmc/host/Kconfig
@@ -608,13 +608,6 @@ config MMC_DAVINCI
  If you have an DAVINCI board with a Multimedia Card slot,
  say Y or M here.  If unsure, say N.
 
-config MMC_GOLDFISH
-   tristate "goldfish qemu Multimedia Card Interface support"
-   depends on GOLDFISH || COMPILE_TEST
-   help
- This selects the Goldfish Multimedia card Interface emulation
- found on the Goldfish Android virtual device emulation.
-
 config MMC_SPI
tristate "MMC/SD/SDIO over SPI"
depends on SPI_MASTER
diff --git a/drivers/mmc/host/Makefile b/drivers/mmc/host/Makefile
index 451c25fc2c69..7f97e97f7066 100644
--- a/drivers/mmc/host/Makefile
+++ b/drivers/mmc/host/Makefile
@@ -34,7 +34,6 @@ obj-$(CONFIG_MMC_ATMELMCI)+= atmel-mci.o
 obj-$(CONFIG_MMC_TIFM_SD)  += tifm_sd.o
 obj-$(CONFIG_MMC_MVSDIO)   += mvsdio.o
 obj-$(CONFIG_MMC_DAVINCI)   += davinci_mmc.o
-obj-$(CONFIG_MMC_GOLDFISH) += android-goldfish.o
 obj-$(CONFIG_MMC_SPI)  += mmc_spi.o
 ifeq ($(CONFIG_OF),y)
 obj-$(CONFIG_MMC_SPI)  += of_mmc_spi.o
diff --git a/drivers/mmc/host/android-goldfish.c 
b/drivers/mmc/host/android-goldfish.c
deleted file mode 100644
index e878fdf8f20a..
--- a/drivers/mmc/host/android-goldfish.c
+++ /dev/null
@@ -1,545 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-only
-/*
- *  Copyright 2007, Google Inc.
- *  Copyright 2012, Intel Inc.
- *
- *  based on omap.c driver, which was
- *  Copyright (C) 2004 Nokia Corporation
- *  Written by Tuukka Tikkanen and Juha Yrjölä 
- *  Misc hacks here and there by Tony Lindgren 
- *  Other hacks (DMA, SD, etc) by David Brownell
- */
-
-#include 
-#include 
-#include 
-
-#include 
-#include 
-#include 
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include 
-#include 
-
-#include 
-#include 
-
-#define DRIVER_NAME "goldfish_mmc"
-
-#define BUFFER_SIZE   16384
-
-#define GOLDFISH_MMC_READ(host, addr)   (readl(host->reg_base + addr))
-#define GOLDFISH_MMC_WRITE(host, addr, x)   (writel(x, host->reg_base + addr))
-
-enum {
-   /* status register */
-   MMC_INT_STATUS  = 0x00,
-   /* set this to enable IRQ */
-   MMC_INT_ENABLE  = 0x04,
-   /* set this to specify buffer address */
-   MMC_SET_BUFFER  = 0x08,
-
-   /* MMC command number */
-   MMC_CMD = 0x0C,
-
-   /* MMC argument */
-   MMC_ARG = 0x10,
-
-   /* MMC response (or R2 bits 0 - 31) */
-   MMC_RESP_0  = 0x14,
-
-   /* MMC R2 response bits 32 - 63 */
-   MMC_RESP_1  = 0x18,
-
-   /* MMC R2 response bits 64 - 95 */
-   MMC_RESP_2  = 0x1C,
-
-   /* MMC R2 response bits 96 - 127 */
-   MMC_RESP_3  = 0x20,
-
-   MMC_BLOCK_LENGTH= 0x24,
-   MMC_BLOCK_COUNT = 0x28,
-
-   /* MMC state flags */
-   MMC_STATE   = 0x2C,
-
-   /* MMC_INT_STATUS bits */
-
-   MMC_STAT_END_OF_CMD = 1U << 0,
-   MMC_STAT_END_OF_DATA= 1U << 1,
-   MMC_STAT_STATE_CHANGE   = 1U << 2,
-   MMC_STAT_CMD_TIMEOUT= 1U << 3,
-
-   /* MMC_STATE bits */
-   MMC_STATE_INSERTED = 1U << 0,
-   MMC_STATE_READ_ONLY= 1U << 1,
-};
-
-/*
- * Command types
- */
-#define OMAP_MMC_CMDTYPE_BC0
-#define OMAP_MMC_CMDTYPE_BCR   1
-#define OMAP_MMC_CMDTYPE_AC2
-#define OMAP_MMC_CMDTYPE_ADTC  3
-
-
-struct goldfish_mmc_host {
-   struct mmc_request  *mrq;
-   struct mmc_command  *cmd;
-   struct mmc_data *data;
-   struct device   *dev;
-   unsigned char   id; /* 16xx chips have 2 MMC blocks */
-   void*virt_base;
-   unsigned intphys_base;
-   int irq;
-   unsigned char   bus_mode;
-   unsigned char   hw_bus_mode;
-
-   unsigned intsg_len;
-   unsigneddma_done:1;
-   unsigneddma_in_use:1;
-
-   void __iomem*reg_base;
-};
-
-static inline int
-goldfish_mmc_cover_is_open(struct goldfish_mmc_host *host)
-{
-   return 0;
-}
-
-static ssize_t
-goldfish_mmc_show_cover_switch(struct device *dev,
-  

[PATCH] Remove the GOLDFISH dependency from BATTERY_GOLDFISH

2021-02-05 Thread rkir
From: Roman Kiryanov 

This will allow to use the BATTERY_GOLDFISH driver
without enabling GOLDFISH.

Signed-off-by: Roman Kiryanov 
---
 drivers/power/supply/Kconfig | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig
index eec646c568b7..8704fe644b1f 100644
--- a/drivers/power/supply/Kconfig
+++ b/drivers/power/supply/Kconfig
@@ -683,11 +683,11 @@ config AB8500_BM
 
 config BATTERY_GOLDFISH
tristate "Goldfish battery driver"
-   depends on GOLDFISH || COMPILE_TEST
depends on HAS_IOMEM
help
- Say Y to enable support for the battery and AC power in the
- Goldfish emulator.
+ Say Y to enable support for the Goldfish battery and AC power
+ driver. Originated in the Android Studio Emulator (goldfish) it is
+ going to be used in other emulators.
 
 config BATTERY_RT5033
tristate "RT5033 fuel gauge support"
-- 
2.30.0.478.g8a0d178c01-goog



[PATCH] arch: x86: platform: retire arch/x86/platform/goldfish

2020-11-16 Thread rkir
From: Roman Kiryanov 

The Android Studio Emulator (aka goldfish) does not
use arch/x86/platform/goldfish since 5.4 kernel.

Signed-off-by: Roman Kiryanov 
---
 arch/x86/platform/Makefile|  1 -
 arch/x86/platform/goldfish/Makefile   |  2 -
 arch/x86/platform/goldfish/goldfish.c | 54 ---
 3 files changed, 57 deletions(-)
 delete mode 100644 arch/x86/platform/goldfish/Makefile
 delete mode 100644 arch/x86/platform/goldfish/goldfish.c

diff --git a/arch/x86/platform/Makefile b/arch/x86/platform/Makefile
index d0e835470d01..b2f90a1a89f1 100644
--- a/arch/x86/platform/Makefile
+++ b/arch/x86/platform/Makefile
@@ -4,7 +4,6 @@ obj-y   += atom/
 obj-y  += ce4100/
 obj-y  += efi/
 obj-y  += geode/
-obj-y  += goldfish/
 obj-y  += iris/
 obj-y  += intel/
 obj-y  += intel-mid/
diff --git a/arch/x86/platform/goldfish/Makefile 
b/arch/x86/platform/goldfish/Makefile
deleted file mode 100644
index 072c395379ac..
--- a/arch/x86/platform/goldfish/Makefile
+++ /dev/null
@@ -1,2 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0-only
-obj-$(CONFIG_GOLDFISH) += goldfish.o
diff --git a/arch/x86/platform/goldfish/goldfish.c 
b/arch/x86/platform/goldfish/goldfish.c
deleted file mode 100644
index 6b6f8b4360dd..
--- a/arch/x86/platform/goldfish/goldfish.c
+++ /dev/null
@@ -1,54 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-only
-/*
- * Copyright (C) 2007 Google, Inc.
- * Copyright (C) 2011 Intel, Inc.
- * Copyright (C) 2013 Intel, Inc.
- */
-
-#include 
-#include 
-#include 
-
-/*
- * Where in virtual device memory the IO devices (timers, system controllers
- * and so on)
- */
-
-#define GOLDFISH_PDEV_BUS_BASE (0xff001000)
-#define GOLDFISH_PDEV_BUS_END  (0xff7f)
-#define GOLDFISH_PDEV_BUS_IRQ  (4)
-
-#define GOLDFISH_TTY_BASE  (0x2000)
-
-static struct resource goldfish_pdev_bus_resources[] = {
-   {
-   .start  = GOLDFISH_PDEV_BUS_BASE,
-   .end= GOLDFISH_PDEV_BUS_END,
-   .flags  = IORESOURCE_MEM,
-   },
-   {
-   .start  = GOLDFISH_PDEV_BUS_IRQ,
-   .end= GOLDFISH_PDEV_BUS_IRQ,
-   .flags  = IORESOURCE_IRQ,
-   }
-};
-
-static bool goldfish_enable __initdata;
-
-static int __init goldfish_setup(char *str)
-{
-   goldfish_enable = true;
-   return 0;
-}
-__setup("goldfish", goldfish_setup);
-
-static int __init goldfish_init(void)
-{
-   if (!goldfish_enable)
-   return -ENODEV;
-
-   platform_device_register_simple("goldfish_pdev_bus", -1,
-   goldfish_pdev_bus_resources, 2);
-   return 0;
-}
-device_initcall(goldfish_init);
-- 
2.29.2.299.gdc1121823c-goog



[PATCH] Update MAINTAINERS for goldfish-rtc

2020-11-16 Thread rkir
From: Roman Kiryanov 

We (Android Studio Emulator, aka goldfish) do not
support MIPS anymore but goldfish-rtc is still used
by MIPS/RISCV QEMU.

Signed-off-by: Roman Kiryanov 
---
 MAINTAINERS | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 4a34b25ecc1f..7f9216407ace 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1168,7 +1168,9 @@ F:
Documentation/devicetree/bindings/interrupt-controller/google,goldfish-pic.tx
 F: drivers/irqchip/irq-goldfish-pic.c
 
 ANDROID GOLDFISH RTC DRIVER
-M: Miodrag Dinic 
+M: Jiaxun Yang 
+M: Huacai Chen 
+L: qemu-ri...@nongnu.org
 S: Supported
 F: Documentation/devicetree/bindings/rtc/google,goldfish-rtc.txt
 F: drivers/rtc/rtc-goldfish.c
-- 
2.29.2.299.gdc1121823c-goog



[PATCH] drivers: rtc: retire RTC_DRV_GOLDFISH

2020-11-13 Thread rkir
From: Roman Kiryanov 

The only user of RTC_DRV_GOLDFISH is
the MIPS flavor of Android Studio Emulator
(goldfish) which should be also retired.

Signed-off-by: Roman Kiryanov 
---
 arch/riscv/Kconfig.socs|   1 -
 drivers/rtc/Kconfig|  10 --
 drivers/rtc/Makefile   |   1 -
 drivers/rtc/rtc-goldfish.c | 216 -
 4 files changed, 228 deletions(-)
 delete mode 100644 drivers/rtc/rtc-goldfish.c

diff --git a/arch/riscv/Kconfig.socs b/arch/riscv/Kconfig.socs
index 8a55f6156661..9c4c2abb2011 100644
--- a/arch/riscv/Kconfig.socs
+++ b/arch/riscv/Kconfig.socs
@@ -17,7 +17,6 @@ config SOC_VIRT
select POWER_RESET_SYSCON
select POWER_RESET_SYSCON_POWEROFF
select GOLDFISH
-   select RTC_DRV_GOLDFISH if RTC_CLASS
select SIFIVE_PLIC
help
  This enables support for QEMU Virt Machine.
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 65ad9d0b47ab..e574f24f3b08 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1932,16 +1932,6 @@ config RTC_DRV_HID_SENSOR_TIME
  If this driver is compiled as a module, it will be named
  rtc-hid-sensor-time.
 
-config RTC_DRV_GOLDFISH
-   tristate "Goldfish Real Time Clock"
-   depends on OF && HAS_IOMEM
-   depends on GOLDFISH || COMPILE_TEST
-   help
- Say yes to enable RTC driver for the Goldfish based virtual platform.
-
- Goldfish is a code name for the virtual platform developed by Google
- for Android emulation.
-
 config RTC_DRV_WILCO_EC
tristate "Wilco EC RTC"
depends on WILCO_EC
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index bfb57464118d..1730d0676096 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -71,7 +71,6 @@ obj-$(CONFIG_RTC_DRV_FM3130)  += rtc-fm3130.o
 obj-$(CONFIG_RTC_DRV_FSL_FTM_ALARM)+= rtc-fsl-ftm-alarm.o
 obj-$(CONFIG_RTC_DRV_FTRTC010) += rtc-ftrtc010.o
 obj-$(CONFIG_RTC_DRV_GENERIC)  += rtc-generic.o
-obj-$(CONFIG_RTC_DRV_GOLDFISH) += rtc-goldfish.o
 obj-$(CONFIG_RTC_DRV_HID_SENSOR_TIME) += rtc-hid-sensor-time.o
 obj-$(CONFIG_RTC_DRV_HYM8563)  += rtc-hym8563.o
 obj-$(CONFIG_RTC_DRV_IMXDI)+= rtc-imxdi.o
diff --git a/drivers/rtc/rtc-goldfish.c b/drivers/rtc/rtc-goldfish.c
deleted file mode 100644
index 6349d2cd3680..
--- a/drivers/rtc/rtc-goldfish.c
+++ /dev/null
@@ -1,216 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/* drivers/rtc/rtc-goldfish.c
- *
- * Copyright (C) 2007 Google, Inc.
- * Copyright (C) 2017 Imagination Technologies Ltd.
- */
-
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#define TIMER_TIME_LOW 0x00/* get low bits of current time  */
-   /*   and update TIMER_TIME_HIGH  */
-#define TIMER_TIME_HIGH0x04/* get high bits of time at last */
-   /*   TIMER_TIME_LOW read */
-#define TIMER_ALARM_LOW0x08/* set low bits of alarm and */
-   /*   activate it */
-#define TIMER_ALARM_HIGH   0x0c/* set high bits of next alarm   */
-#define TIMER_IRQ_ENABLED  0x10
-#define TIMER_CLEAR_ALARM  0x14
-#define TIMER_ALARM_STATUS 0x18
-#define TIMER_CLEAR_INTERRUPT  0x1c
-
-struct goldfish_rtc {
-   void __iomem *base;
-   int irq;
-   struct rtc_device *rtc;
-};
-
-static int goldfish_rtc_read_alarm(struct device *dev,
-  struct rtc_wkalrm *alrm)
-{
-   u64 rtc_alarm;
-   u64 rtc_alarm_low;
-   u64 rtc_alarm_high;
-   void __iomem *base;
-   struct goldfish_rtc *rtcdrv;
-
-   rtcdrv = dev_get_drvdata(dev);
-   base = rtcdrv->base;
-
-   rtc_alarm_low = readl(base + TIMER_ALARM_LOW);
-   rtc_alarm_high = readl(base + TIMER_ALARM_HIGH);
-   rtc_alarm = (rtc_alarm_high << 32) | rtc_alarm_low;
-
-   do_div(rtc_alarm, NSEC_PER_SEC);
-   memset(alrm, 0, sizeof(struct rtc_wkalrm));
-
-   rtc_time64_to_tm(rtc_alarm, >time);
-
-   if (readl(base + TIMER_ALARM_STATUS))
-   alrm->enabled = 1;
-   else
-   alrm->enabled = 0;
-
-   return 0;
-}
-
-static int goldfish_rtc_set_alarm(struct device *dev,
- struct rtc_wkalrm *alrm)
-{
-   struct goldfish_rtc *rtcdrv;
-   u64 rtc_alarm64;
-   u64 rtc_status_reg;
-   void __iomem *base;
-
-   rtcdrv = dev_get_drvdata(dev);
-   base = rtcdrv->base;
-
-   if (alrm->enabled) {
-   rtc_alarm64 = rtc_tm_to_time64(>time) * NSEC_PER_SEC;
-   writel((rtc_alarm64 >> 32), base + TIMER_ALARM_HIGH);
-   writel(rtc_alarm64, base + TIMER_ALARM_LOW);
-   writel(1, base + TIMER_IRQ_ENABLED);
-   } else {
-   /*
-* if this function was called with enabled=0
-* then it could mean that the application is
-* trying to 

[PATCH] drivers: rtc: retire RTC_DRV_GOLDFISH

2020-11-12 Thread rkir
From: Roman Kiryanov 

The only user of RTC_DRV_GOLDFISH is
the MIPS flavor of Android Studio Emulator
(goldfish) which should be also retired.

Signed-off-by: Roman Kiryanov 
---
 arch/riscv/Kconfig.socs|   1 -
 drivers/rtc/Kconfig|  10 --
 drivers/rtc/Makefile   |   1 -
 drivers/rtc/rtc-goldfish.c | 216 -
 4 files changed, 228 deletions(-)
 delete mode 100644 drivers/rtc/rtc-goldfish.c

diff --git a/arch/riscv/Kconfig.socs b/arch/riscv/Kconfig.socs
index 8a55f6156661..9c4c2abb2011 100644
--- a/arch/riscv/Kconfig.socs
+++ b/arch/riscv/Kconfig.socs
@@ -17,7 +17,6 @@ config SOC_VIRT
select POWER_RESET_SYSCON
select POWER_RESET_SYSCON_POWEROFF
select GOLDFISH
-   select RTC_DRV_GOLDFISH if RTC_CLASS
select SIFIVE_PLIC
help
  This enables support for QEMU Virt Machine.
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 65ad9d0b47ab..e574f24f3b08 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1932,16 +1932,6 @@ config RTC_DRV_HID_SENSOR_TIME
  If this driver is compiled as a module, it will be named
  rtc-hid-sensor-time.
 
-config RTC_DRV_GOLDFISH
-   tristate "Goldfish Real Time Clock"
-   depends on OF && HAS_IOMEM
-   depends on GOLDFISH || COMPILE_TEST
-   help
- Say yes to enable RTC driver for the Goldfish based virtual platform.
-
- Goldfish is a code name for the virtual platform developed by Google
- for Android emulation.
-
 config RTC_DRV_WILCO_EC
tristate "Wilco EC RTC"
depends on WILCO_EC
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index bfb57464118d..1730d0676096 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -71,7 +71,6 @@ obj-$(CONFIG_RTC_DRV_FM3130)  += rtc-fm3130.o
 obj-$(CONFIG_RTC_DRV_FSL_FTM_ALARM)+= rtc-fsl-ftm-alarm.o
 obj-$(CONFIG_RTC_DRV_FTRTC010) += rtc-ftrtc010.o
 obj-$(CONFIG_RTC_DRV_GENERIC)  += rtc-generic.o
-obj-$(CONFIG_RTC_DRV_GOLDFISH) += rtc-goldfish.o
 obj-$(CONFIG_RTC_DRV_HID_SENSOR_TIME) += rtc-hid-sensor-time.o
 obj-$(CONFIG_RTC_DRV_HYM8563)  += rtc-hym8563.o
 obj-$(CONFIG_RTC_DRV_IMXDI)+= rtc-imxdi.o
diff --git a/drivers/rtc/rtc-goldfish.c b/drivers/rtc/rtc-goldfish.c
deleted file mode 100644
index 6349d2cd3680..
--- a/drivers/rtc/rtc-goldfish.c
+++ /dev/null
@@ -1,216 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/* drivers/rtc/rtc-goldfish.c
- *
- * Copyright (C) 2007 Google, Inc.
- * Copyright (C) 2017 Imagination Technologies Ltd.
- */
-
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#define TIMER_TIME_LOW 0x00/* get low bits of current time  */
-   /*   and update TIMER_TIME_HIGH  */
-#define TIMER_TIME_HIGH0x04/* get high bits of time at last */
-   /*   TIMER_TIME_LOW read */
-#define TIMER_ALARM_LOW0x08/* set low bits of alarm and */
-   /*   activate it */
-#define TIMER_ALARM_HIGH   0x0c/* set high bits of next alarm   */
-#define TIMER_IRQ_ENABLED  0x10
-#define TIMER_CLEAR_ALARM  0x14
-#define TIMER_ALARM_STATUS 0x18
-#define TIMER_CLEAR_INTERRUPT  0x1c
-
-struct goldfish_rtc {
-   void __iomem *base;
-   int irq;
-   struct rtc_device *rtc;
-};
-
-static int goldfish_rtc_read_alarm(struct device *dev,
-  struct rtc_wkalrm *alrm)
-{
-   u64 rtc_alarm;
-   u64 rtc_alarm_low;
-   u64 rtc_alarm_high;
-   void __iomem *base;
-   struct goldfish_rtc *rtcdrv;
-
-   rtcdrv = dev_get_drvdata(dev);
-   base = rtcdrv->base;
-
-   rtc_alarm_low = readl(base + TIMER_ALARM_LOW);
-   rtc_alarm_high = readl(base + TIMER_ALARM_HIGH);
-   rtc_alarm = (rtc_alarm_high << 32) | rtc_alarm_low;
-
-   do_div(rtc_alarm, NSEC_PER_SEC);
-   memset(alrm, 0, sizeof(struct rtc_wkalrm));
-
-   rtc_time64_to_tm(rtc_alarm, >time);
-
-   if (readl(base + TIMER_ALARM_STATUS))
-   alrm->enabled = 1;
-   else
-   alrm->enabled = 0;
-
-   return 0;
-}
-
-static int goldfish_rtc_set_alarm(struct device *dev,
- struct rtc_wkalrm *alrm)
-{
-   struct goldfish_rtc *rtcdrv;
-   u64 rtc_alarm64;
-   u64 rtc_status_reg;
-   void __iomem *base;
-
-   rtcdrv = dev_get_drvdata(dev);
-   base = rtcdrv->base;
-
-   if (alrm->enabled) {
-   rtc_alarm64 = rtc_tm_to_time64(>time) * NSEC_PER_SEC;
-   writel((rtc_alarm64 >> 32), base + TIMER_ALARM_HIGH);
-   writel(rtc_alarm64, base + TIMER_ALARM_LOW);
-   writel(1, base + TIMER_IRQ_ENABLED);
-   } else {
-   /*
-* if this function was called with enabled=0
-* then it could mean that the application is
-* trying to 

[PATCH] drivers: staging: retire drivers/staging/goldfish

2020-11-12 Thread rkir
From: Roman Kiryanov 

Android Studio Emulator (goldfish) migrated
to Intel HDA.

Signed-off-by: Roman Kiryanov 
---
 arch/mips/configs/generic/board-ranchu.config |   1 -
 drivers/staging/Kconfig   |   2 -
 drivers/staging/Makefile  |   1 -
 drivers/staging/goldfish/Kconfig  |   7 -
 drivers/staging/goldfish/Makefile |   6 -
 drivers/staging/goldfish/README   |   5 -
 drivers/staging/goldfish/goldfish_audio.c | 383 --
 7 files changed, 405 deletions(-)
 delete mode 100644 drivers/staging/goldfish/Kconfig
 delete mode 100644 drivers/staging/goldfish/Makefile
 delete mode 100644 drivers/staging/goldfish/README
 delete mode 100644 drivers/staging/goldfish/goldfish_audio.c

diff --git a/arch/mips/configs/generic/board-ranchu.config 
b/arch/mips/configs/generic/board-ranchu.config
index fee9ad4c5598..640aac845ebe 100644
--- a/arch/mips/configs/generic/board-ranchu.config
+++ b/arch/mips/configs/generic/board-ranchu.config
@@ -5,7 +5,6 @@ CONFIG_FB=y
 CONFIG_FB_GOLDFISH=y
 CONFIG_GOLDFISH=y
 CONFIG_STAGING=y
-CONFIG_GOLDFISH_AUDIO=y
 CONFIG_GOLDFISH_PIC=y
 CONFIG_GOLDFISH_PIPE=y
 CONFIG_GOLDFISH_TTY=y
diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig
index 2d0310448eba..c4fb7312392a 100644
--- a/drivers/staging/Kconfig
+++ b/drivers/staging/Kconfig
@@ -68,8 +68,6 @@ source "drivers/staging/gdm724x/Kconfig"
 
 source "drivers/staging/fwserial/Kconfig"
 
-source "drivers/staging/goldfish/Kconfig"
-
 source "drivers/staging/netlogic/Kconfig"
 
 source "drivers/staging/gs_fpgaboot/Kconfig"
diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile
index 757a892ab5b9..b72c3a04899b 100644
--- a/drivers/staging/Makefile
+++ b/drivers/staging/Makefile
@@ -25,7 +25,6 @@ obj-$(CONFIG_ANDROID) += android/
 obj-$(CONFIG_STAGING_BOARD)+= board/
 obj-$(CONFIG_LTE_GDM724X)  += gdm724x/
 obj-$(CONFIG_FIREWIRE_SERIAL)  += fwserial/
-obj-$(CONFIG_GOLDFISH) += goldfish/
 obj-$(CONFIG_GS_FPGABOOT)  += gs_fpgaboot/
 obj-$(CONFIG_UNISYSSPAR)   += unisys/
 obj-$(CONFIG_COMMON_CLK_XLNX_CLKWZRD)  += clocking-wizard/
diff --git a/drivers/staging/goldfish/Kconfig b/drivers/staging/goldfish/Kconfig
deleted file mode 100644
index 728f4700b98d..
--- a/drivers/staging/goldfish/Kconfig
+++ /dev/null
@@ -1,7 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0
-config GOLDFISH_AUDIO
-   tristate "Goldfish AVD Audio Device"
-   depends on GOLDFISH
-   help
- Emulated audio channel for the Goldfish Android Virtual Device
-
diff --git a/drivers/staging/goldfish/Makefile 
b/drivers/staging/goldfish/Makefile
deleted file mode 100644
index f7cee15529c3..
--- a/drivers/staging/goldfish/Makefile
+++ /dev/null
@@ -1,6 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0
-#
-# Makefile for the Goldfish audio driver
-#
-
-obj-$(CONFIG_GOLDFISH_AUDIO) += goldfish_audio.o
diff --git a/drivers/staging/goldfish/README b/drivers/staging/goldfish/README
deleted file mode 100644
index ed08c4d46e75..
--- a/drivers/staging/goldfish/README
+++ /dev/null
@@ -1,5 +0,0 @@
-Audio
--
-- Move to using the ALSA framework not faking it
-- Fix the wrong user page DMA (moving to ALSA may fix that too)
-
diff --git a/drivers/staging/goldfish/goldfish_audio.c 
b/drivers/staging/goldfish/goldfish_audio.c
deleted file mode 100644
index 0c65a0121dde..
--- a/drivers/staging/goldfish/goldfish_audio.c
+++ /dev/null
@@ -1,383 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- * drivers/misc/goldfish_audio.c
- *
- * Copyright (C) 2007 Google, Inc.
- * Copyright (C) 2012 Intel, Inc.
- */
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-MODULE_AUTHOR("Google, Inc.");
-MODULE_DESCRIPTION("Android QEMU Audio Driver");
-MODULE_LICENSE("GPL");
-MODULE_VERSION("1.0");
-
-struct goldfish_audio {
-   char __iomem *reg_base;
-   int irq;
-
-   /* lock protects access to buffer_status and to device registers */
-   spinlock_t lock;
-   wait_queue_head_t wait;
-
-   char *buffer_virt;  /* combined buffer virtual address */
-   unsigned long buffer_phys;  /* combined buffer physical address */
-
-   char *write_buffer1;/* write buffer 1 virtual address */
-   char *write_buffer2;/* write buffer 2 virtual address */
-   char *read_buffer;  /* read buffer virtual address */
-   int buffer_status;
-   int read_supported; /* true if we have audio input support */
-};
-
-/*
- *  We will allocate two read buffers and two write buffers.
- *  Having two read buffers facilitate stereo -> mono conversion.
- *  Having two write buffers facilitate interleaved IO.
- */
-#define READ_BUFFER_SIZE   16384
-#define WRITE_BUFFER_SIZE  16384
-#define COMBINED_BUFFER_SIZE   ((2 * READ_BUFFER_SIZE) + 

[PATCH v3 3/3] drivers: platform: goldfish: goldfish_sync: add a driver

2019-01-08 Thread rkir
From: Roman Kiryanov 

The Goldfish sync driver is designed to provide a interface
between the underlying host's sync device and the kernel's
fence sync framework.

Signed-off-by: Roman Kiryanov 
---
Changes in v3:
 - Removed WARN_ON.

Changes in v2:
 - Added a missing include (mod_devicetable.h).
 - Put in one batch with goldfish_address_space.c to avoid merge comflicts.

 drivers/platform/goldfish/Kconfig   |   7 +
 drivers/platform/goldfish/Makefile  |   1 +
 drivers/platform/goldfish/goldfish_sync.c   | 827 
 include/uapi/linux/goldfish/goldfish_sync.h |  28 +
 4 files changed, 863 insertions(+)
 create mode 100644 drivers/platform/goldfish/goldfish_sync.c
 create mode 100644 include/uapi/linux/goldfish/goldfish_sync.h

diff --git a/drivers/platform/goldfish/Kconfig 
b/drivers/platform/goldfish/Kconfig
index 60ecec4a3c59..841250235430 100644
--- a/drivers/platform/goldfish/Kconfig
+++ b/drivers/platform/goldfish/Kconfig
@@ -25,4 +25,11 @@ config GOLDFISH_ADDRESS_SPACE
  populate them later in the host. This allows sharing host's memory
  with the guest.
 
+config GOLDFISH_SYNC
+   tristate "Goldfish AVD Sync Driver"
+   depends on SW_SYNC
+   depends on SYNC_FILE
+   help
+ Emulated sync fences for the Goldfish Android Virtual Device.
+
 endif # GOLDFISH
diff --git a/drivers/platform/goldfish/Makefile 
b/drivers/platform/goldfish/Makefile
index 034abe0727b8..bdff4d6a0ad9 100644
--- a/drivers/platform/goldfish/Makefile
+++ b/drivers/platform/goldfish/Makefile
@@ -3,3 +3,4 @@
 #
 obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe.o
 obj-$(CONFIG_GOLDFISH_ADDRESS_SPACE) += goldfish_address_space.o
+obj-$(CONFIG_GOLDFISH_SYNC)+= goldfish_sync.o
diff --git a/drivers/platform/goldfish/goldfish_sync.c 
b/drivers/platform/goldfish/goldfish_sync.c
new file mode 100644
index ..3a68e2bb436c
--- /dev/null
+++ b/drivers/platform/goldfish/goldfish_sync.c
@@ -0,0 +1,827 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/* The Goldfish sync driver is designed to provide a interface
+ * between the underlying host's sync device and the kernel's
+ * fence sync framework.
+ *
+ * The purpose of the device/driver is to enable lightweight creation and
+ * signaling of timelines and fences in order to synchronize the guest with
+ * host-side graphics events.
+ *
+ * Each time the interrupt trips, the driver may perform a sync operation.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+struct sync_pt {
+   struct dma_fence base;  /* must be the first field in this struct */
+   struct list_head active_list;   /* see active_list_head below */
+};
+
+struct goldfish_sync_state;
+
+struct goldfish_sync_timeline {
+   struct goldfish_sync_state *sync_state;
+
+   /* This object is owned by userspace from open() calls and also each
+* sync_pt refers to it.
+*/
+   struct kref kref;
+   charname[32];   /* for debugging */
+
+   u64 context;
+   unsigned intseqno;
+   /* list of active (unsignaled/errored) sync_pts */
+   struct list_headactive_list_head;
+   spinlock_t  lock;   /* protects the fields above */
+};
+
+/* The above definitions (command codes, register layout, ioctl definitions)
+ * need to be in sync with the following files:
+ *
+ * Host-side (emulator):
+ * external/qemu/android/emulation/goldfish_sync.h
+ * external/qemu-android/hw/misc/goldfish_sync.c
+ *
+ * Guest-side (system image):
+ * device/generic/goldfish-opengl/system/egl/goldfish_sync.h
+ * device/generic/goldfish/ueventd.ranchu.rc
+ * platform/build/target/board/generic/sepolicy/file_contexts
+ */
+struct goldfish_sync_hostcmd {
+   /* sorted for alignment */
+   u64 handle;
+   u64 hostcmd_handle;
+   u32 cmd;
+   u32 time_arg;
+};
+
+struct goldfish_sync_guestcmd {
+   u64 host_command; /* u64 for alignment */
+   u64 glsync_handle;
+   u64 thread_handle;
+   u64 guest_timeline_handle;
+};
+
+/* The host operations are: */
+enum cmd_id {
+   /* Ready signal - used to mark when irq should lower */
+   CMD_SYNC_READY  = 0,
+
+   /* Create a new timeline. writes timeline handle */
+   CMD_CREATE_SYNC_TIMELINE= 1,
+
+   /* Create a fence object. reads timeline handle and time argument.
+* Writes fence fd to the SYNC_REG_HANDLE register.
+*/
+   CMD_CREATE_SYNC_FENCE   = 2,
+
+   /* Increments timeline. reads timeline handle and time argument */
+   CMD_SYNC_TIMELINE_INC   = 3,
+
+   /* Destroys a timeline. reads timeline handle */
+   CMD_DESTROY_SYNC_TIMELINE   = 4,
+
+ 

[PATCH v3 1/3] drivers: platform: goldfish: fix the checkpatch complain in Kconfig

2019-01-08 Thread rkir
From: Roman Kiryanov 

prefer 'help' over '---help---' for new help texts

Signed-off-by: Roman Kiryanov 
---
Changes in v3:
 - No changes.

Changes in v2:
 - New change, a minor cleanup.

 drivers/platform/goldfish/Kconfig | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/goldfish/Kconfig 
b/drivers/platform/goldfish/Kconfig
index 479031aa4f88..74fdfa68d1f2 100644
--- a/drivers/platform/goldfish/Kconfig
+++ b/drivers/platform/goldfish/Kconfig
@@ -2,7 +2,7 @@ menuconfig GOLDFISH
bool "Platform support for Goldfish virtual devices"
depends on X86_32 || X86_64 || ARM || ARM64 || MIPS
depends on HAS_IOMEM
-   ---help---
+   help
  Say Y here to get to see options for the Goldfish virtual platform.
  This option alone does not add any kernel code.
 
@@ -12,7 +12,7 @@ if GOLDFISH
 
 config GOLDFISH_PIPE
tristate "Goldfish virtual device for QEMU pipes"
-   ---help---
+   help
  This is a virtual device to drive the QEMU pipe interface used by
  the Goldfish Android Virtual Device.
 
-- 
2.20.1.97.g81188d93c3-goog



[PATCH v3 2/3] drivers: platform: goldfish: goldfish_address_space: add a driver

2019-01-08 Thread rkir
From: Roman Kiryanov 

A driver for the Goldfish Android emulator that occupies
address space to use it with the memory sharing device
on the QEMU side. The memory sharding device allocates
subranges and populate them with actual RAM.
This allows sharing host's memory with the guest.

Signed-off-by: Roman Kiryanov 
---
Changes in v3:
 - No changes.

Changes in v2:
 - Removed WARN_ON.
 - Moved to drivers/platform/goldfish (from drivers/misc).

 drivers/platform/goldfish/Kconfig |   9 +
 drivers/platform/goldfish/Makefile|   1 +
 .../goldfish/goldfish_address_space.c | 666 ++
 .../linux/goldfish/goldfish_address_space.h   |  27 +
 4 files changed, 703 insertions(+)
 create mode 100644 drivers/platform/goldfish/goldfish_address_space.c
 create mode 100644 include/uapi/linux/goldfish/goldfish_address_space.h

diff --git a/drivers/platform/goldfish/Kconfig 
b/drivers/platform/goldfish/Kconfig
index 74fdfa68d1f2..60ecec4a3c59 100644
--- a/drivers/platform/goldfish/Kconfig
+++ b/drivers/platform/goldfish/Kconfig
@@ -16,4 +16,13 @@ config GOLDFISH_PIPE
  This is a virtual device to drive the QEMU pipe interface used by
  the Goldfish Android Virtual Device.
 
+config GOLDFISH_ADDRESS_SPACE
+   tristate "A Goldfish driver that talks to the memory sharing device in 
QEMU"
+   depends on PCI
+   depends on GOLDFISH
+   help
+ A Goldfish driver that allocates address space ranges in the guest to
+ populate them later in the host. This allows sharing host's memory
+ with the guest.
+
 endif # GOLDFISH
diff --git a/drivers/platform/goldfish/Makefile 
b/drivers/platform/goldfish/Makefile
index e0c202df9674..034abe0727b8 100644
--- a/drivers/platform/goldfish/Makefile
+++ b/drivers/platform/goldfish/Makefile
@@ -2,3 +2,4 @@
 # Makefile for Goldfish platform specific drivers
 #
 obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe.o
+obj-$(CONFIG_GOLDFISH_ADDRESS_SPACE) += goldfish_address_space.o
diff --git a/drivers/platform/goldfish/goldfish_address_space.c 
b/drivers/platform/goldfish/goldfish_address_space.c
new file mode 100644
index ..50513b98ddb7
--- /dev/null
+++ b/drivers/platform/goldfish/goldfish_address_space.c
@@ -0,0 +1,666 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+MODULE_DESCRIPTION("A driver for the Goldfish Android emulator that occupies "
+  "address space to use it with the memory sharing device "
+  "on the QEMU side. The memory sharding device allocates "
+  "subranges and populate them with actual RAM. "
+  "This allows sharing host's memory with the guest.");
+MODULE_AUTHOR("Roman Kiryanov ");
+MODULE_LICENSE("GPL v2");
+
+enum as_register_id {
+   AS_REGISTER_COMMAND = 0,
+   AS_REGISTER_STATUS = 4,
+   AS_REGISTER_GUEST_PAGE_SIZE = 8,
+   AS_REGISTER_BLOCK_SIZE_LOW = 12,
+   AS_REGISTER_BLOCK_SIZE_HIGH = 16,
+   AS_REGISTER_BLOCK_OFFSET_LOW = 20,
+   AS_REGISTER_BLOCK_OFFSET_HIGH = 24,
+};
+
+enum as_command_id {
+   AS_COMMAND_ALLOCATE_BLOCK = 1,
+   AS_COMMAND_DEALLOCATE_BLOCK = 2,
+};
+
+#define AS_PCI_VENDOR_ID   0x607D
+#define AS_PCI_DEVICE_ID   0xF153
+#define AS_MAGIC_U32   (AS_PCI_VENDOR_ID << 16 | AS_PCI_DEVICE_ID)
+#define AS_ALLOCATED_BLOCKS_INITIAL_CAPACITY 32
+
+enum as_pci_bar_id {
+   AS_PCI_CONTROL_BAR_ID = 0,
+   AS_PCI_AREA_BAR_ID = 1,
+};
+
+struct as_driver_state;
+
+struct as_device_state {
+   u32 magic;
+
+   struct miscdevice   miscdevice;
+   struct pci_dev  *dev;
+   struct as_driver_state  *driver_state;
+
+   void __iomem*io_registers;
+
+   void*address_area;  /* to claim the address space */
+
+   /* physical address to allocate from */
+   unsigned long   address_area_phys_address;
+
+   struct mutexregisters_lock; /* protects registers */
+
+   wait_queue_head_t   wake_queue; /* to wait for the hardware */
+
+   int hw_done;/* to say hw is done */
+};
+
+struct as_block {
+   u64 offset;
+   u64 size;
+};
+
+struct as_allocated_blocks {
+   struct as_device_state *state;
+
+   struct as_block *blocks;  /* a dynamic array of allocated blocks */
+   int blocks_size;
+   int blocks_capacity;
+   struct mutex blocks_lock; /* protects operations with blocks */
+};
+
+static void __iomem *as_register_address(void __iomem *base,
+int offset)
+{
+   return ((char __iomem *)base) + offset;
+}
+
+static void as_write_register(void __iomem *registers,
+ int offset,
+ u32 value)
+{
+   writel(value, 

[PATCH v2 2/3] drivers: platform: goldfish: goldfish_address_space: add a driver

2019-01-07 Thread rkir
From: Roman Kiryanov 

A driver for the Goldfish Android emulator that occupies
address space to use it with the memory sharing device
on the QEMU side. The memory sharding device allocates
subranges and populate them with actual RAM.
This allows sharing host's memory with the guest.

Signed-off-by: Roman Kiryanov 
---
Changes in v2:
 - Removed WARN_ON.
 - Moved to drivers/platform/goldfish (from drivers/misc).

 drivers/platform/goldfish/Kconfig |   9 +
 drivers/platform/goldfish/Makefile|   1 +
 .../goldfish/goldfish_address_space.c | 666 ++
 .../linux/goldfish/goldfish_address_space.h   |  27 +
 4 files changed, 703 insertions(+)
 create mode 100644 drivers/platform/goldfish/goldfish_address_space.c
 create mode 100644 include/uapi/linux/goldfish/goldfish_address_space.h

diff --git a/drivers/platform/goldfish/Kconfig 
b/drivers/platform/goldfish/Kconfig
index 74fdfa68d1f2..60ecec4a3c59 100644
--- a/drivers/platform/goldfish/Kconfig
+++ b/drivers/platform/goldfish/Kconfig
@@ -16,4 +16,13 @@ config GOLDFISH_PIPE
  This is a virtual device to drive the QEMU pipe interface used by
  the Goldfish Android Virtual Device.
 
+config GOLDFISH_ADDRESS_SPACE
+   tristate "A Goldfish driver that talks to the memory sharing device in 
QEMU"
+   depends on PCI
+   depends on GOLDFISH
+   help
+ A Goldfish driver that allocates address space ranges in the guest to
+ populate them later in the host. This allows sharing host's memory
+ with the guest.
+
 endif # GOLDFISH
diff --git a/drivers/platform/goldfish/Makefile 
b/drivers/platform/goldfish/Makefile
index e0c202df9674..034abe0727b8 100644
--- a/drivers/platform/goldfish/Makefile
+++ b/drivers/platform/goldfish/Makefile
@@ -2,3 +2,4 @@
 # Makefile for Goldfish platform specific drivers
 #
 obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe.o
+obj-$(CONFIG_GOLDFISH_ADDRESS_SPACE) += goldfish_address_space.o
diff --git a/drivers/platform/goldfish/goldfish_address_space.c 
b/drivers/platform/goldfish/goldfish_address_space.c
new file mode 100644
index ..50513b98ddb7
--- /dev/null
+++ b/drivers/platform/goldfish/goldfish_address_space.c
@@ -0,0 +1,666 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+MODULE_DESCRIPTION("A driver for the Goldfish Android emulator that occupies "
+  "address space to use it with the memory sharing device "
+  "on the QEMU side. The memory sharding device allocates "
+  "subranges and populate them with actual RAM. "
+  "This allows sharing host's memory with the guest.");
+MODULE_AUTHOR("Roman Kiryanov ");
+MODULE_LICENSE("GPL v2");
+
+enum as_register_id {
+   AS_REGISTER_COMMAND = 0,
+   AS_REGISTER_STATUS = 4,
+   AS_REGISTER_GUEST_PAGE_SIZE = 8,
+   AS_REGISTER_BLOCK_SIZE_LOW = 12,
+   AS_REGISTER_BLOCK_SIZE_HIGH = 16,
+   AS_REGISTER_BLOCK_OFFSET_LOW = 20,
+   AS_REGISTER_BLOCK_OFFSET_HIGH = 24,
+};
+
+enum as_command_id {
+   AS_COMMAND_ALLOCATE_BLOCK = 1,
+   AS_COMMAND_DEALLOCATE_BLOCK = 2,
+};
+
+#define AS_PCI_VENDOR_ID   0x607D
+#define AS_PCI_DEVICE_ID   0xF153
+#define AS_MAGIC_U32   (AS_PCI_VENDOR_ID << 16 | AS_PCI_DEVICE_ID)
+#define AS_ALLOCATED_BLOCKS_INITIAL_CAPACITY 32
+
+enum as_pci_bar_id {
+   AS_PCI_CONTROL_BAR_ID = 0,
+   AS_PCI_AREA_BAR_ID = 1,
+};
+
+struct as_driver_state;
+
+struct as_device_state {
+   u32 magic;
+
+   struct miscdevice   miscdevice;
+   struct pci_dev  *dev;
+   struct as_driver_state  *driver_state;
+
+   void __iomem*io_registers;
+
+   void*address_area;  /* to claim the address space */
+
+   /* physical address to allocate from */
+   unsigned long   address_area_phys_address;
+
+   struct mutexregisters_lock; /* protects registers */
+
+   wait_queue_head_t   wake_queue; /* to wait for the hardware */
+
+   int hw_done;/* to say hw is done */
+};
+
+struct as_block {
+   u64 offset;
+   u64 size;
+};
+
+struct as_allocated_blocks {
+   struct as_device_state *state;
+
+   struct as_block *blocks;  /* a dynamic array of allocated blocks */
+   int blocks_size;
+   int blocks_capacity;
+   struct mutex blocks_lock; /* protects operations with blocks */
+};
+
+static void __iomem *as_register_address(void __iomem *base,
+int offset)
+{
+   return ((char __iomem *)base) + offset;
+}
+
+static void as_write_register(void __iomem *registers,
+ int offset,
+ u32 value)
+{
+   writel(value, as_register_address(registers, offset));
+}
+
+static 

[PATCH v2 3/3] drivers: platform: goldfish: goldfish_sync: add a driver

2019-01-07 Thread rkir
From: Roman Kiryanov 

The Goldfish sync driver is designed to provide a interface
between the underlying host's sync device and the kernel's
fence sync framework.

Signed-off-by: Roman Kiryanov 
---
Changes in v2:
 - Added a missing include (mod_devicetable.h).
 - Put in one batch with goldfish_address_space.c to avoid merge comflicts.

 drivers/platform/goldfish/Kconfig   |   7 +
 drivers/platform/goldfish/Makefile  |   1 +
 drivers/platform/goldfish/goldfish_sync.c   | 834 
 include/uapi/linux/goldfish/goldfish_sync.h |  28 +
 4 files changed, 870 insertions(+)
 create mode 100644 drivers/platform/goldfish/goldfish_sync.c
 create mode 100644 include/uapi/linux/goldfish/goldfish_sync.h

diff --git a/drivers/platform/goldfish/Kconfig 
b/drivers/platform/goldfish/Kconfig
index 60ecec4a3c59..841250235430 100644
--- a/drivers/platform/goldfish/Kconfig
+++ b/drivers/platform/goldfish/Kconfig
@@ -25,4 +25,11 @@ config GOLDFISH_ADDRESS_SPACE
  populate them later in the host. This allows sharing host's memory
  with the guest.
 
+config GOLDFISH_SYNC
+   tristate "Goldfish AVD Sync Driver"
+   depends on SW_SYNC
+   depends on SYNC_FILE
+   help
+ Emulated sync fences for the Goldfish Android Virtual Device.
+
 endif # GOLDFISH
diff --git a/drivers/platform/goldfish/Makefile 
b/drivers/platform/goldfish/Makefile
index 034abe0727b8..bdff4d6a0ad9 100644
--- a/drivers/platform/goldfish/Makefile
+++ b/drivers/platform/goldfish/Makefile
@@ -3,3 +3,4 @@
 #
 obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe.o
 obj-$(CONFIG_GOLDFISH_ADDRESS_SPACE) += goldfish_address_space.o
+obj-$(CONFIG_GOLDFISH_SYNC)+= goldfish_sync.o
diff --git a/drivers/platform/goldfish/goldfish_sync.c 
b/drivers/platform/goldfish/goldfish_sync.c
new file mode 100644
index ..1e9813d2094a
--- /dev/null
+++ b/drivers/platform/goldfish/goldfish_sync.c
@@ -0,0 +1,834 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/* The Goldfish sync driver is designed to provide a interface
+ * between the underlying host's sync device and the kernel's
+ * fence sync framework.
+ *
+ * The purpose of the device/driver is to enable lightweight creation and
+ * signaling of timelines and fences in order to synchronize the guest with
+ * host-side graphics events.
+ *
+ * Each time the interrupt trips, the driver may perform a sync operation.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+struct sync_pt {
+   struct dma_fence base;  /* must be the first field in this struct */
+   struct list_head active_list;   /* see active_list_head below */
+};
+
+struct goldfish_sync_state;
+
+struct goldfish_sync_timeline {
+   struct goldfish_sync_state *sync_state;
+
+   /* This object is owned by userspace from open() calls and also each
+* sync_pt refers to it.
+*/
+   struct kref kref;
+   charname[32];   /* for debugging */
+
+   u64 context;
+   unsigned intseqno;
+   /* list of active (unsignaled/errored) sync_pts */
+   struct list_headactive_list_head;
+   spinlock_t  lock;   /* protects the fields above */
+};
+
+/* The above definitions (command codes, register layout, ioctl definitions)
+ * need to be in sync with the following files:
+ *
+ * Host-side (emulator):
+ * external/qemu/android/emulation/goldfish_sync.h
+ * external/qemu-android/hw/misc/goldfish_sync.c
+ *
+ * Guest-side (system image):
+ * device/generic/goldfish-opengl/system/egl/goldfish_sync.h
+ * device/generic/goldfish/ueventd.ranchu.rc
+ * platform/build/target/board/generic/sepolicy/file_contexts
+ */
+struct goldfish_sync_hostcmd {
+   /* sorted for alignment */
+   u64 handle;
+   u64 hostcmd_handle;
+   u32 cmd;
+   u32 time_arg;
+};
+
+struct goldfish_sync_guestcmd {
+   u64 host_command; /* u64 for alignment */
+   u64 glsync_handle;
+   u64 thread_handle;
+   u64 guest_timeline_handle;
+};
+
+/* The host operations are: */
+enum cmd_id {
+   /* Ready signal - used to mark when irq should lower */
+   CMD_SYNC_READY  = 0,
+
+   /* Create a new timeline. writes timeline handle */
+   CMD_CREATE_SYNC_TIMELINE= 1,
+
+   /* Create a fence object. reads timeline handle and time argument.
+* Writes fence fd to the SYNC_REG_HANDLE register.
+*/
+   CMD_CREATE_SYNC_FENCE   = 2,
+
+   /* Increments timeline. reads timeline handle and time argument */
+   CMD_SYNC_TIMELINE_INC   = 3,
+
+   /* Destroys a timeline. reads timeline handle */
+   CMD_DESTROY_SYNC_TIMELINE   = 4,
+
+   /* Starts a wait on the host 

[PATCH v2 1/3] drivers: platform: goldfish: fix the checkpatch complain in Kconfig

2019-01-07 Thread rkir
From: Roman Kiryanov 

prefer 'help' over '---help---' for new help texts

Signed-off-by: Roman Kiryanov 
---
Changes in v2:
 - New change, a minor cleanup.

 drivers/platform/goldfish/Kconfig | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/goldfish/Kconfig 
b/drivers/platform/goldfish/Kconfig
index 479031aa4f88..74fdfa68d1f2 100644
--- a/drivers/platform/goldfish/Kconfig
+++ b/drivers/platform/goldfish/Kconfig
@@ -2,7 +2,7 @@ menuconfig GOLDFISH
bool "Platform support for Goldfish virtual devices"
depends on X86_32 || X86_64 || ARM || ARM64 || MIPS
depends on HAS_IOMEM
-   ---help---
+   help
  Say Y here to get to see options for the Goldfish virtual platform.
  This option alone does not add any kernel code.
 
@@ -12,7 +12,7 @@ if GOLDFISH
 
 config GOLDFISH_PIPE
tristate "Goldfish virtual device for QEMU pipes"
-   ---help---
+   help
  This is a virtual device to drive the QEMU pipe interface used by
  the Goldfish Android Virtual Device.
 
-- 
2.20.1.97.g81188d93c3-goog



[PATCH] drivers: platform: goldfish_sync: add a driver

2019-01-04 Thread rkir
From: Roman Kiryanov 

The Goldfish sync driver is designed to provide a interface
between the underlying host's sync device and the kernel's
fence sync framework.

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/Kconfig   |   7 +
 drivers/platform/goldfish/Makefile  |   1 +
 drivers/platform/goldfish/goldfish_sync.c   | 833 
 include/uapi/linux/goldfish/goldfish_sync.h |  28 +
 4 files changed, 869 insertions(+)
 create mode 100644 drivers/platform/goldfish/goldfish_sync.c
 create mode 100644 include/uapi/linux/goldfish/goldfish_sync.h

diff --git a/drivers/platform/goldfish/Kconfig 
b/drivers/platform/goldfish/Kconfig
index 479031aa4f88..fbc0c53e8f35 100644
--- a/drivers/platform/goldfish/Kconfig
+++ b/drivers/platform/goldfish/Kconfig
@@ -16,4 +16,11 @@ config GOLDFISH_PIPE
  This is a virtual device to drive the QEMU pipe interface used by
  the Goldfish Android Virtual Device.
 
+config GOLDFISH_SYNC
+   tristate "Goldfish AVD Sync Driver"
+   depends on SW_SYNC
+   depends on SYNC_FILE
+   help
+ Emulated sync fences for the Goldfish Android Virtual Device.
+
 endif # GOLDFISH
diff --git a/drivers/platform/goldfish/Makefile 
b/drivers/platform/goldfish/Makefile
index e0c202df9674..78c8736ba55d 100644
--- a/drivers/platform/goldfish/Makefile
+++ b/drivers/platform/goldfish/Makefile
@@ -2,3 +2,4 @@
 # Makefile for Goldfish platform specific drivers
 #
 obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe.o
+obj-$(CONFIG_GOLDFISH_SYNC)+= goldfish_sync.o
diff --git a/drivers/platform/goldfish/goldfish_sync.c 
b/drivers/platform/goldfish/goldfish_sync.c
new file mode 100644
index ..e8b7903487cd
--- /dev/null
+++ b/drivers/platform/goldfish/goldfish_sync.c
@@ -0,0 +1,833 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/* The Goldfish sync driver is designed to provide a interface
+ * between the underlying host's sync device and the kernel's
+ * fence sync framework.
+ *
+ * The purpose of the device/driver is to enable lightweight creation and
+ * signaling of timelines and fences in order to synchronize the guest with
+ * host-side graphics events.
+ *
+ * Each time the interrupt trips, the driver may perform a sync operation.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+struct sync_pt {
+   struct dma_fence base;  /* must be the first field in this struct */
+   struct list_head active_list;   /* see active_list_head below */
+};
+
+struct goldfish_sync_state;
+
+struct goldfish_sync_timeline {
+   struct goldfish_sync_state *sync_state;
+
+   /* This object is owned by userspace from open() calls and also each
+* sync_pt refers to it.
+*/
+   struct kref kref;
+   charname[32];   /* for debugging */
+
+   u64 context;
+   unsigned intseqno;
+   /* list of active (unsignaled/errored) sync_pts */
+   struct list_headactive_list_head;
+   spinlock_t  lock;   /* protects the fields above */
+};
+
+/* The above definitions (command codes, register layout, ioctl definitions)
+ * need to be in sync with the following files:
+ *
+ * Host-side (emulator):
+ * external/qemu/android/emulation/goldfish_sync.h
+ * external/qemu-android/hw/misc/goldfish_sync.c
+ *
+ * Guest-side (system image):
+ * device/generic/goldfish-opengl/system/egl/goldfish_sync.h
+ * device/generic/goldfish/ueventd.ranchu.rc
+ * platform/build/target/board/generic/sepolicy/file_contexts
+ */
+struct goldfish_sync_hostcmd {
+   /* sorted for alignment */
+   u64 handle;
+   u64 hostcmd_handle;
+   u32 cmd;
+   u32 time_arg;
+};
+
+struct goldfish_sync_guestcmd {
+   u64 host_command; /* u64 for alignment */
+   u64 glsync_handle;
+   u64 thread_handle;
+   u64 guest_timeline_handle;
+};
+
+/* The host operations are: */
+enum cmd_id {
+   /* Ready signal - used to mark when irq should lower */
+   CMD_SYNC_READY  = 0,
+
+   /* Create a new timeline. writes timeline handle */
+   CMD_CREATE_SYNC_TIMELINE= 1,
+
+   /* Create a fence object. reads timeline handle and time argument.
+* Writes fence fd to the SYNC_REG_HANDLE register.
+*/
+   CMD_CREATE_SYNC_FENCE   = 2,
+
+   /* Increments timeline. reads timeline handle and time argument */
+   CMD_SYNC_TIMELINE_INC   = 3,
+
+   /* Destroys a timeline. reads timeline handle */
+   CMD_DESTROY_SYNC_TIMELINE   = 4,
+
+   /* Starts a wait on the host with the given glsync object and
+* sync thread handle.
+*/
+   CMD_TRIGGER_HOST_WAIT   = 5,
+};
+
+/* The host register layout 

[PATCH] drivers: misc: goldfish_address_space: add a driver

2019-01-03 Thread rkir
From: Roman Kiryanov 

A driver for the Goldfish Android emulator that occupies
address space to use it with the memory sharing device
on the QEMU side. The memory sharding device allocates
subranges and populate them with actual RAM.
This allows sharing host's memory with the guest.

Signed-off-by: Roman Kiryanov 
---
 drivers/misc/Kconfig  |   9 +
 drivers/misc/Makefile |   1 +
 drivers/misc/goldfish_address_space.c | 742 ++
 .../linux/goldfish/goldfish_address_space.h   |  27 +
 4 files changed, 779 insertions(+)
 create mode 100644 drivers/misc/goldfish_address_space.c
 create mode 100644 include/uapi/linux/goldfish/goldfish_address_space.h

diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index f417b06e11c5..66518bbe4217 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -521,6 +521,15 @@ config PVPANIC
  a paravirtualized device provided by QEMU; it lets a virtual machine
  (guest) communicate panic events to the host.
 
+config GOLDFISH_ADDRESS_SPACE
+   tristate "A Goldfish driver that talks to the memory sharing device in 
QEMU"
+   depends on PCI
+   depends on GOLDFISH
+   help
+ A Goldfish driver that allocates address space ranges in the guest to
+ populate them later in the host. This allows sharing host's memory
+ with the guest.
+
 source "drivers/misc/c2port/Kconfig"
 source "drivers/misc/eeprom/Kconfig"
 source "drivers/misc/cb710/Kconfig"
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index e39ccbbc1b3a..11c9f9d7d3a1 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -59,3 +59,4 @@ obj-$(CONFIG_PCI_ENDPOINT_TEST)   += pci_endpoint_test.o
 obj-$(CONFIG_OCXL) += ocxl/
 obj-y  += cardreader/
 obj-$(CONFIG_PVPANIC)  += pvpanic.o
+obj-$(CONFIG_GOLDFISH_ADDRESS_SPACE) += goldfish_address_space.o
diff --git a/drivers/misc/goldfish_address_space.c 
b/drivers/misc/goldfish_address_space.c
new file mode 100644
index ..3605adcdaf2e
--- /dev/null
+++ b/drivers/misc/goldfish_address_space.c
@@ -0,0 +1,742 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+MODULE_DESCRIPTION("A driver for the Goldfish Android emulator that occupies "
+  "address space to use it with the memory sharing device "
+  "on the QEMU side. The memory sharding device allocates "
+  "subranges and populate them with actual RAM. "
+  "This allows sharing host's memory with the guest.");
+MODULE_AUTHOR("Roman Kiryanov ");
+MODULE_LICENSE("GPL v2");
+
+enum as_register_id {
+   AS_REGISTER_COMMAND = 0,
+   AS_REGISTER_STATUS = 4,
+   AS_REGISTER_GUEST_PAGE_SIZE = 8,
+   AS_REGISTER_BLOCK_SIZE_LOW = 12,
+   AS_REGISTER_BLOCK_SIZE_HIGH = 16,
+   AS_REGISTER_BLOCK_OFFSET_LOW = 20,
+   AS_REGISTER_BLOCK_OFFSET_HIGH = 24,
+};
+
+enum as_command_id {
+   AS_COMMAND_ALLOCATE_BLOCK = 1,
+   AS_COMMAND_DEALLOCATE_BLOCK = 2,
+};
+
+#define AS_PCI_VENDOR_ID   0x607D
+#define AS_PCI_DEVICE_ID   0xF153
+#define AS_MAGIC_U32   (AS_PCI_VENDOR_ID << 16 | AS_PCI_DEVICE_ID)
+#define AS_ALLOCATED_BLOCKS_INITIAL_CAPACITY 32
+
+enum as_pci_bar_id {
+   AS_PCI_CONTROL_BAR_ID = 0,
+   AS_PCI_AREA_BAR_ID = 1,
+};
+
+struct as_driver_state;
+
+struct as_device_state {
+   u32 magic;
+
+   struct miscdevice   miscdevice;
+   struct pci_dev  *dev;
+   struct as_driver_state  *driver_state;
+
+   void __iomem*io_registers;
+
+   void*address_area;  /* to claim the address space */
+
+   /* physical address to allocate from */
+   unsigned long   address_area_phys_address;
+
+   struct mutexregisters_lock; /* protects registers */
+
+   wait_queue_head_t   wake_queue; /* to wait for the hardware */
+
+   int hw_done;/* to say hw is done */
+};
+
+struct as_driver_state {
+   struct as_device_state *device_state;
+   struct pci_driver pci;
+};
+
+struct as_block {
+   u64 offset;
+   u64 size;
+};
+
+struct as_allocated_blocks {
+   struct as_device_state *state;
+
+   struct as_block *blocks;  /* a dynamic array of allocated blocks */
+   int blocks_size;
+   int blocks_capacity;
+   struct mutex blocks_lock; /* protects operations with blocks */
+};
+
+static void __iomem *as_register_address(void __iomem *base,
+int offset)
+{
+   return ((char __iomem *)base) + offset;
+}
+
+static void as_write_register(void __iomem *registers,
+ int offset,
+ u32 value)
+{
+   writel(value, 

[PATCH v3 13/15] platform: goldfish: pipe: Add a dedicated constant for the device name

2018-10-03 Thread rkir
From: Roman Kiryanov 

Create a constant to refer to the device name instead if several copies
of a string.

Signed-off-by: Roman Kiryanov 
---
Changes in v3:
 - No change.
Changes in v2:
 - No change.

 drivers/platform/goldfish/goldfish_pipe.h| 2 ++
 drivers/platform/goldfish/goldfish_pipe_v2.c | 4 ++--
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.h 
b/drivers/platform/goldfish/goldfish_pipe.h
index ee0b54bcb165..0fa6ecb32c6d 100644
--- a/drivers/platform/goldfish/goldfish_pipe.h
+++ b/drivers/platform/goldfish/goldfish_pipe.h
@@ -2,6 +2,8 @@
 #ifndef GOLDFISH_PIPE_H
 #define GOLDFISH_PIPE_H
 
+#define DEVICE_NAME "goldfish_pipe"
+
 struct goldfish_pipe_dev_base {
/* the destructor, the pointer is set in init */
int (*deinit)(void *pipe_dev, struct platform_device *pdev);
diff --git a/drivers/platform/goldfish/goldfish_pipe_v2.c 
b/drivers/platform/goldfish/goldfish_pipe_v2.c
index 9857ce07d0e6..0e2a62322477 100644
--- a/drivers/platform/goldfish/goldfish_pipe_v2.c
+++ b/drivers/platform/goldfish/goldfish_pipe_v2.c
@@ -775,7 +775,7 @@ static void init_miscdevice(struct miscdevice *miscdev)
memset(miscdev, 0, sizeof(*miscdev));
 
miscdev->minor = MISC_DYNAMIC_MINOR;
-   miscdev->name = "goldfish_pipe";
+   miscdev->name = DEVICE_NAME;
miscdev->fops = _pipe_fops;
 }
 
@@ -806,7 +806,7 @@ int goldfish_pipe_device_v2_init(struct platform_device 
*pdev,
 
err = devm_request_irq(>dev, irq,
   goldfish_pipe_interrupt,
-  IRQF_SHARED, "goldfish_pipe", dev);
+  IRQF_SHARED, DEVICE_NAME, dev);
if (err) {
dev_err(>dev, "unable to allocate IRQ for v2\n");
return err;
-- 
2.19.0.605.g01d371f741-goog



[PATCH v3 12/15] platform: goldfish: pipe: Rename the init function (add "v2")

2018-10-03 Thread rkir
From: Roman Kiryanov 

This is the v2 driver. v1 will be added later.

Signed-off-by: Roman Kiryanov 
---
Changes in v3:
 - No change.
Changes in v2:
 - No change.

 drivers/platform/goldfish/goldfish_pipe.c| 2 +-
 drivers/platform/goldfish/goldfish_pipe_v2.c | 6 +++---
 drivers/platform/goldfish/goldfish_pipe_v2.h | 6 +++---
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index 792b20bdf76c..7b0920e962eb 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -87,7 +87,7 @@ static int goldfish_pipe_probe(struct platform_device *pdev)
if (WARN_ON(version < PIPE_CURRENT_DEVICE_VERSION))
return -EINVAL;
 
-   return goldfish_pipe_device_init(pdev, base, irq);
+   return goldfish_pipe_device_v2_init(pdev, base, irq);
 }
 
 static int goldfish_pipe_remove(struct platform_device *pdev)
diff --git a/drivers/platform/goldfish/goldfish_pipe_v2.c 
b/drivers/platform/goldfish/goldfish_pipe_v2.c
index 641dfdcc3ffd..9857ce07d0e6 100644
--- a/drivers/platform/goldfish/goldfish_pipe_v2.c
+++ b/drivers/platform/goldfish/goldfish_pipe_v2.c
@@ -787,9 +787,9 @@ static void write_pa_addr(void *addr, void __iomem *portl, 
void __iomem *porth)
writel(lower_32_bits(paddr), portl);
 }
 
-int goldfish_pipe_device_init(struct platform_device *pdev,
- char __iomem *base,
- int irq)
+int goldfish_pipe_device_v2_init(struct platform_device *pdev,
+char __iomem *base,
+int irq)
 {
struct goldfish_pipe_dev *dev;
int err;
diff --git a/drivers/platform/goldfish/goldfish_pipe_v2.h 
b/drivers/platform/goldfish/goldfish_pipe_v2.h
index 03b476fb9978..70bf4ec1fd66 100644
--- a/drivers/platform/goldfish/goldfish_pipe_v2.h
+++ b/drivers/platform/goldfish/goldfish_pipe_v2.h
@@ -3,8 +3,8 @@
 #define GOLDFISH_PIPE_V2_H
 
 /* The entry point to the pipe v2 driver */
-int goldfish_pipe_device_init(struct platform_device *pdev,
- char __iomem *base,
- int irq);
+int goldfish_pipe_device_v2_init(struct platform_device *pdev,
+char __iomem *base,
+int irq);
 
 #endif /* #define GOLDFISH_PIPE_V2_H */
-- 
2.19.0.605.g01d371f741-goog



[PATCH v3 14/15] platform: goldfish: pipe: Rename PIPE_REG to PIPE_V2_REG

2018-10-03 Thread rkir
From: Roman Kiryanov 

PIPE_V1_REG will be introduced later for v1 support.

Signed-off-by: Roman Kiryanov 
---
Changes in v3:
 - No change.
Changes in v2:
 - No change.

 drivers/platform/goldfish/goldfish_pipe.c  |  4 ++--
 drivers/platform/goldfish/goldfish_pipe_qemu.h | 18 +-
 drivers/platform/goldfish/goldfish_pipe_v2.c   | 16 
 3 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index 7b0920e962eb..353f7ce94aa7 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -81,8 +81,8 @@ static int goldfish_pipe_probe(struct platform_device *pdev)
 *  reading device version back: this allows the host implementation to
 *  detect the old driver (if there was no version write before read).
 */
-   writel(PIPE_DRIVER_VERSION, base + PIPE_REG_VERSION);
-   version = readl(base + PIPE_REG_VERSION);
+   writel(PIPE_DRIVER_VERSION, base + PIPE_V2_REG_VERSION);
+   version = readl(base + PIPE_V2_REG_VERSION);
 
if (WARN_ON(version < PIPE_CURRENT_DEVICE_VERSION))
return -EINVAL;
diff --git a/drivers/platform/goldfish/goldfish_pipe_qemu.h 
b/drivers/platform/goldfish/goldfish_pipe_qemu.h
index b4d78c108afd..24b02710769f 100644
--- a/drivers/platform/goldfish/goldfish_pipe_qemu.h
+++ b/drivers/platform/goldfish/goldfish_pipe_qemu.h
@@ -62,19 +62,19 @@ enum PipeFlagsBits {
BIT_WAKE_ON_READ   = 2,  /* want to be woken on reads */
 };
 
-enum PipeRegs {
-   PIPE_REG_CMD = 0,
+enum PipeV2Regs {
+   PIPE_V2_REG_CMD = 0,
 
-   PIPE_REG_SIGNAL_BUFFER_HIGH = 4,
-   PIPE_REG_SIGNAL_BUFFER = 8,
-   PIPE_REG_SIGNAL_BUFFER_COUNT = 12,
+   PIPE_V2_REG_SIGNAL_BUFFER_HIGH = 4,
+   PIPE_V2_REG_SIGNAL_BUFFER = 8,
+   PIPE_V2_REG_SIGNAL_BUFFER_COUNT = 12,
 
-   PIPE_REG_OPEN_BUFFER_HIGH = 20,
-   PIPE_REG_OPEN_BUFFER = 24,
+   PIPE_V2_REG_OPEN_BUFFER_HIGH = 20,
+   PIPE_V2_REG_OPEN_BUFFER = 24,
 
-   PIPE_REG_VERSION = 36,
+   PIPE_V2_REG_VERSION = 36,
 
-   PIPE_REG_GET_SIGNALLED = 48,
+   PIPE_V2_REG_GET_SIGNALLED = 48,
 };
 
 enum PipeCmdCode {
diff --git a/drivers/platform/goldfish/goldfish_pipe_v2.c 
b/drivers/platform/goldfish/goldfish_pipe_v2.c
index 0e2a62322477..c99317548128 100644
--- a/drivers/platform/goldfish/goldfish_pipe_v2.c
+++ b/drivers/platform/goldfish/goldfish_pipe_v2.c
@@ -197,7 +197,7 @@ static int goldfish_pipe_cmd_locked(struct goldfish_pipe 
*pipe,
pipe->command_buffer->cmd = cmd;
/* failure by default */
pipe->command_buffer->status = PIPE_ERROR_INVAL;
-   writel(pipe->id, pipe->dev->base + PIPE_REG_CMD);
+   writel(pipe->id, pipe->dev->base + PIPE_V2_REG_CMD);
return pipe->command_buffer->status;
 }
 
@@ -214,7 +214,7 @@ static int goldfish_pipe_cmd(struct goldfish_pipe *pipe, 
enum PipeCmdCode cmd)
 
 /*
  * This function converts an error code returned by the emulator through
- * the PIPE_REG_STATUS i/o register into a valid negative errno value.
+ * the PIPE_V2_REG_STATUS i/o register into a valid negative errno value.
  */
 static int goldfish_pipe_error_convert(int status)
 {
@@ -611,7 +611,7 @@ static irqreturn_t goldfish_pipe_interrupt(int irq, void 
*dev_id)
/* Request the signalled pipes from the device */
spin_lock_irqsave(>lock, flags);
 
-   count = readl(dev->base + PIPE_REG_GET_SIGNALLED);
+   count = readl(dev->base + PIPE_V2_REG_GET_SIGNALLED);
if (count == 0) {
spin_unlock_irqrestore(>lock, flags);
return IRQ_NONE;
@@ -847,15 +847,15 @@ int goldfish_pipe_device_v2_init(struct platform_device 
*pdev,
 
/* Send the buffer addresses to the host */
write_pa_addr(>buffers->signalled_pipe_buffers,
- dev->base + PIPE_REG_SIGNAL_BUFFER,
- dev->base + PIPE_REG_SIGNAL_BUFFER_HIGH);
+ dev->base + PIPE_V2_REG_SIGNAL_BUFFER,
+ dev->base + PIPE_V2_REG_SIGNAL_BUFFER_HIGH);
 
writel(MAX_SIGNALLED_PIPES,
-  dev->base + PIPE_REG_SIGNAL_BUFFER_COUNT);
+  dev->base + PIPE_V2_REG_SIGNAL_BUFFER_COUNT);
 
write_pa_addr(>buffers->open_command_params,
- dev->base + PIPE_REG_OPEN_BUFFER,
- dev->base + PIPE_REG_OPEN_BUFFER_HIGH);
+ dev->base + PIPE_V2_REG_OPEN_BUFFER,
+ dev->base + PIPE_V2_REG_OPEN_BUFFER_HIGH);
 
platform_set_drvdata(pdev, dev);
return 0;
-- 
2.19.0.605.g01d371f741-goog



[PATCH v3 14/15] platform: goldfish: pipe: Rename PIPE_REG to PIPE_V2_REG

2018-10-03 Thread rkir
From: Roman Kiryanov 

PIPE_V1_REG will be introduced later for v1 support.

Signed-off-by: Roman Kiryanov 
---
Changes in v3:
 - No change.
Changes in v2:
 - No change.

 drivers/platform/goldfish/goldfish_pipe.c  |  4 ++--
 drivers/platform/goldfish/goldfish_pipe_qemu.h | 18 +-
 drivers/platform/goldfish/goldfish_pipe_v2.c   | 16 
 3 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index 7b0920e962eb..353f7ce94aa7 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -81,8 +81,8 @@ static int goldfish_pipe_probe(struct platform_device *pdev)
 *  reading device version back: this allows the host implementation to
 *  detect the old driver (if there was no version write before read).
 */
-   writel(PIPE_DRIVER_VERSION, base + PIPE_REG_VERSION);
-   version = readl(base + PIPE_REG_VERSION);
+   writel(PIPE_DRIVER_VERSION, base + PIPE_V2_REG_VERSION);
+   version = readl(base + PIPE_V2_REG_VERSION);
 
if (WARN_ON(version < PIPE_CURRENT_DEVICE_VERSION))
return -EINVAL;
diff --git a/drivers/platform/goldfish/goldfish_pipe_qemu.h 
b/drivers/platform/goldfish/goldfish_pipe_qemu.h
index b4d78c108afd..24b02710769f 100644
--- a/drivers/platform/goldfish/goldfish_pipe_qemu.h
+++ b/drivers/platform/goldfish/goldfish_pipe_qemu.h
@@ -62,19 +62,19 @@ enum PipeFlagsBits {
BIT_WAKE_ON_READ   = 2,  /* want to be woken on reads */
 };
 
-enum PipeRegs {
-   PIPE_REG_CMD = 0,
+enum PipeV2Regs {
+   PIPE_V2_REG_CMD = 0,
 
-   PIPE_REG_SIGNAL_BUFFER_HIGH = 4,
-   PIPE_REG_SIGNAL_BUFFER = 8,
-   PIPE_REG_SIGNAL_BUFFER_COUNT = 12,
+   PIPE_V2_REG_SIGNAL_BUFFER_HIGH = 4,
+   PIPE_V2_REG_SIGNAL_BUFFER = 8,
+   PIPE_V2_REG_SIGNAL_BUFFER_COUNT = 12,
 
-   PIPE_REG_OPEN_BUFFER_HIGH = 20,
-   PIPE_REG_OPEN_BUFFER = 24,
+   PIPE_V2_REG_OPEN_BUFFER_HIGH = 20,
+   PIPE_V2_REG_OPEN_BUFFER = 24,
 
-   PIPE_REG_VERSION = 36,
+   PIPE_V2_REG_VERSION = 36,
 
-   PIPE_REG_GET_SIGNALLED = 48,
+   PIPE_V2_REG_GET_SIGNALLED = 48,
 };
 
 enum PipeCmdCode {
diff --git a/drivers/platform/goldfish/goldfish_pipe_v2.c 
b/drivers/platform/goldfish/goldfish_pipe_v2.c
index 0e2a62322477..c99317548128 100644
--- a/drivers/platform/goldfish/goldfish_pipe_v2.c
+++ b/drivers/platform/goldfish/goldfish_pipe_v2.c
@@ -197,7 +197,7 @@ static int goldfish_pipe_cmd_locked(struct goldfish_pipe 
*pipe,
pipe->command_buffer->cmd = cmd;
/* failure by default */
pipe->command_buffer->status = PIPE_ERROR_INVAL;
-   writel(pipe->id, pipe->dev->base + PIPE_REG_CMD);
+   writel(pipe->id, pipe->dev->base + PIPE_V2_REG_CMD);
return pipe->command_buffer->status;
 }
 
@@ -214,7 +214,7 @@ static int goldfish_pipe_cmd(struct goldfish_pipe *pipe, 
enum PipeCmdCode cmd)
 
 /*
  * This function converts an error code returned by the emulator through
- * the PIPE_REG_STATUS i/o register into a valid negative errno value.
+ * the PIPE_V2_REG_STATUS i/o register into a valid negative errno value.
  */
 static int goldfish_pipe_error_convert(int status)
 {
@@ -611,7 +611,7 @@ static irqreturn_t goldfish_pipe_interrupt(int irq, void 
*dev_id)
/* Request the signalled pipes from the device */
spin_lock_irqsave(>lock, flags);
 
-   count = readl(dev->base + PIPE_REG_GET_SIGNALLED);
+   count = readl(dev->base + PIPE_V2_REG_GET_SIGNALLED);
if (count == 0) {
spin_unlock_irqrestore(>lock, flags);
return IRQ_NONE;
@@ -847,15 +847,15 @@ int goldfish_pipe_device_v2_init(struct platform_device 
*pdev,
 
/* Send the buffer addresses to the host */
write_pa_addr(>buffers->signalled_pipe_buffers,
- dev->base + PIPE_REG_SIGNAL_BUFFER,
- dev->base + PIPE_REG_SIGNAL_BUFFER_HIGH);
+ dev->base + PIPE_V2_REG_SIGNAL_BUFFER,
+ dev->base + PIPE_V2_REG_SIGNAL_BUFFER_HIGH);
 
writel(MAX_SIGNALLED_PIPES,
-  dev->base + PIPE_REG_SIGNAL_BUFFER_COUNT);
+  dev->base + PIPE_V2_REG_SIGNAL_BUFFER_COUNT);
 
write_pa_addr(>buffers->open_command_params,
- dev->base + PIPE_REG_OPEN_BUFFER,
- dev->base + PIPE_REG_OPEN_BUFFER_HIGH);
+ dev->base + PIPE_V2_REG_OPEN_BUFFER,
+ dev->base + PIPE_V2_REG_OPEN_BUFFER_HIGH);
 
platform_set_drvdata(pdev, dev);
return 0;
-- 
2.19.0.605.g01d371f741-goog



[PATCH v3 13/15] platform: goldfish: pipe: Add a dedicated constant for the device name

2018-10-03 Thread rkir
From: Roman Kiryanov 

Create a constant to refer to the device name instead if several copies
of a string.

Signed-off-by: Roman Kiryanov 
---
Changes in v3:
 - No change.
Changes in v2:
 - No change.

 drivers/platform/goldfish/goldfish_pipe.h| 2 ++
 drivers/platform/goldfish/goldfish_pipe_v2.c | 4 ++--
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.h 
b/drivers/platform/goldfish/goldfish_pipe.h
index ee0b54bcb165..0fa6ecb32c6d 100644
--- a/drivers/platform/goldfish/goldfish_pipe.h
+++ b/drivers/platform/goldfish/goldfish_pipe.h
@@ -2,6 +2,8 @@
 #ifndef GOLDFISH_PIPE_H
 #define GOLDFISH_PIPE_H
 
+#define DEVICE_NAME "goldfish_pipe"
+
 struct goldfish_pipe_dev_base {
/* the destructor, the pointer is set in init */
int (*deinit)(void *pipe_dev, struct platform_device *pdev);
diff --git a/drivers/platform/goldfish/goldfish_pipe_v2.c 
b/drivers/platform/goldfish/goldfish_pipe_v2.c
index 9857ce07d0e6..0e2a62322477 100644
--- a/drivers/platform/goldfish/goldfish_pipe_v2.c
+++ b/drivers/platform/goldfish/goldfish_pipe_v2.c
@@ -775,7 +775,7 @@ static void init_miscdevice(struct miscdevice *miscdev)
memset(miscdev, 0, sizeof(*miscdev));
 
miscdev->minor = MISC_DYNAMIC_MINOR;
-   miscdev->name = "goldfish_pipe";
+   miscdev->name = DEVICE_NAME;
miscdev->fops = _pipe_fops;
 }
 
@@ -806,7 +806,7 @@ int goldfish_pipe_device_v2_init(struct platform_device 
*pdev,
 
err = devm_request_irq(>dev, irq,
   goldfish_pipe_interrupt,
-  IRQF_SHARED, "goldfish_pipe", dev);
+  IRQF_SHARED, DEVICE_NAME, dev);
if (err) {
dev_err(>dev, "unable to allocate IRQ for v2\n");
return err;
-- 
2.19.0.605.g01d371f741-goog



[PATCH v3 12/15] platform: goldfish: pipe: Rename the init function (add "v2")

2018-10-03 Thread rkir
From: Roman Kiryanov 

This is the v2 driver. v1 will be added later.

Signed-off-by: Roman Kiryanov 
---
Changes in v3:
 - No change.
Changes in v2:
 - No change.

 drivers/platform/goldfish/goldfish_pipe.c| 2 +-
 drivers/platform/goldfish/goldfish_pipe_v2.c | 6 +++---
 drivers/platform/goldfish/goldfish_pipe_v2.h | 6 +++---
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index 792b20bdf76c..7b0920e962eb 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -87,7 +87,7 @@ static int goldfish_pipe_probe(struct platform_device *pdev)
if (WARN_ON(version < PIPE_CURRENT_DEVICE_VERSION))
return -EINVAL;
 
-   return goldfish_pipe_device_init(pdev, base, irq);
+   return goldfish_pipe_device_v2_init(pdev, base, irq);
 }
 
 static int goldfish_pipe_remove(struct platform_device *pdev)
diff --git a/drivers/platform/goldfish/goldfish_pipe_v2.c 
b/drivers/platform/goldfish/goldfish_pipe_v2.c
index 641dfdcc3ffd..9857ce07d0e6 100644
--- a/drivers/platform/goldfish/goldfish_pipe_v2.c
+++ b/drivers/platform/goldfish/goldfish_pipe_v2.c
@@ -787,9 +787,9 @@ static void write_pa_addr(void *addr, void __iomem *portl, 
void __iomem *porth)
writel(lower_32_bits(paddr), portl);
 }
 
-int goldfish_pipe_device_init(struct platform_device *pdev,
- char __iomem *base,
- int irq)
+int goldfish_pipe_device_v2_init(struct platform_device *pdev,
+char __iomem *base,
+int irq)
 {
struct goldfish_pipe_dev *dev;
int err;
diff --git a/drivers/platform/goldfish/goldfish_pipe_v2.h 
b/drivers/platform/goldfish/goldfish_pipe_v2.h
index 03b476fb9978..70bf4ec1fd66 100644
--- a/drivers/platform/goldfish/goldfish_pipe_v2.h
+++ b/drivers/platform/goldfish/goldfish_pipe_v2.h
@@ -3,8 +3,8 @@
 #define GOLDFISH_PIPE_V2_H
 
 /* The entry point to the pipe v2 driver */
-int goldfish_pipe_device_init(struct platform_device *pdev,
- char __iomem *base,
- int irq);
+int goldfish_pipe_device_v2_init(struct platform_device *pdev,
+char __iomem *base,
+int irq);
 
 #endif /* #define GOLDFISH_PIPE_V2_H */
-- 
2.19.0.605.g01d371f741-goog



[PATCH v3 15/15] platform: goldfish: pipe: Add the goldfish_pipe_v1 driver

2018-10-03 Thread rkir
From: Roman Kiryanov 

This is the v1 goldfish pipe driver.

Signed-off-by: Roman Kiryanov 
---
Changes in v3:
 - No change.
Changes in v2:
 - No change.

 drivers/platform/goldfish/Makefile|   2 +-
 drivers/platform/goldfish/goldfish_pipe.c |   9 +-
 .../platform/goldfish/goldfish_pipe_qemu.h|  27 +
 drivers/platform/goldfish/goldfish_pipe_v1.c  | 632 ++
 drivers/platform/goldfish/goldfish_pipe_v1.h  |  24 +
 5 files changed, 689 insertions(+), 5 deletions(-)
 create mode 100644 drivers/platform/goldfish/goldfish_pipe_v1.c
 create mode 100644 drivers/platform/goldfish/goldfish_pipe_v1.h

diff --git a/drivers/platform/goldfish/Makefile 
b/drivers/platform/goldfish/Makefile
index 016769e003d8..3fb7427b9dd8 100644
--- a/drivers/platform/goldfish/Makefile
+++ b/drivers/platform/goldfish/Makefile
@@ -2,4 +2,4 @@
 # Makefile for Goldfish platform specific drivers
 #
 obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe_all.o
-goldfish_pipe_all-objs := goldfish_pipe.o goldfish_pipe_v2.o
+goldfish_pipe_all-objs := goldfish_pipe.o goldfish_pipe_v1.o goldfish_pipe_v2.o
diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index 353f7ce94aa7..05a67895cc06 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -39,6 +39,7 @@
 #include 
 #include "goldfish_pipe_qemu.h"
 #include "goldfish_pipe.h"
+#include "goldfish_pipe_v1.h"
 #include "goldfish_pipe_v2.h"
 
 /*
@@ -84,10 +85,10 @@ static int goldfish_pipe_probe(struct platform_device *pdev)
writel(PIPE_DRIVER_VERSION, base + PIPE_V2_REG_VERSION);
version = readl(base + PIPE_V2_REG_VERSION);
 
-   if (WARN_ON(version < PIPE_CURRENT_DEVICE_VERSION))
-   return -EINVAL;
-
-   return goldfish_pipe_device_v2_init(pdev, base, irq);
+   if (version < PIPE_CURRENT_DEVICE_VERSION)
+   return goldfish_pipe_device_v1_init(pdev, base, irq);
+   else
+   return goldfish_pipe_device_v2_init(pdev, base, irq);
 }
 
 static int goldfish_pipe_remove(struct platform_device *pdev)
diff --git a/drivers/platform/goldfish/goldfish_pipe_qemu.h 
b/drivers/platform/goldfish/goldfish_pipe_qemu.h
index 24b02710769f..9a8275f3583d 100644
--- a/drivers/platform/goldfish/goldfish_pipe_qemu.h
+++ b/drivers/platform/goldfish/goldfish_pipe_qemu.h
@@ -62,6 +62,33 @@ enum PipeFlagsBits {
BIT_WAKE_ON_READ   = 2,  /* want to be woken on reads */
 };
 
+enum PipeV1Regs {
+   /* write: value = command */
+   PIPE_V1_REG_COMMAND = 0x00,
+   /* read */
+   PIPE_V1_REG_STATUS  = 0x04,
+   /* read/write: channel id */
+   PIPE_V1_REG_CHANNEL = 0x08,
+   /* read/write: channel id */
+   PIPE_V1_REG_CHANNEL_HIGH= 0x30,
+   /* read/write: buffer size */
+   PIPE_V1_REG_SIZE= 0x0C,
+   /* write: physical address */
+   PIPE_V1_REG_ADDRESS = 0x10,
+   /* write: physical address */
+   PIPE_V1_REG_ADDRESS_HIGH= 0x34,
+   /* read: wake flags */
+   PIPE_V1_REG_WAKES   = 0x14,
+   /* read/write: batch data address */
+   PIPE_V1_REG_PARAMS_ADDR_LOW = 0x18,
+   /* read/write: batch data address */
+   PIPE_V1_REG_PARAMS_ADDR_HIGH= 0x1C,
+   /* write: batch access */
+   PIPE_V1_REG_ACCESS_PARAMS   = 0x20,
+   /* read: device version */
+   PIPE_V1_REG_VERSION = 0x24,
+};
+
 enum PipeV2Regs {
PIPE_V2_REG_CMD = 0,
 
diff --git a/drivers/platform/goldfish/goldfish_pipe_v1.c 
b/drivers/platform/goldfish/goldfish_pipe_v1.c
new file mode 100644
index ..6e603204dd62
--- /dev/null
+++ b/drivers/platform/goldfish/goldfish_pipe_v1.c
@@ -0,0 +1,632 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2011 Google, Inc.
+ * Copyright (C) 2012 Intel, Inc.
+ * Copyright (C) 2013 Intel, Inc.
+ * Copyright (C) 2014 Linaro Limited
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+/* This source file contains the implementation of the legacy version of
+ * a goldfish pipe device driver. See goldfish_pipe_v2.c for the current
+ * version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "goldfish_pipe_qemu.h"
+#include "goldfish_pipe.h"
+
+#define MAX_PAGES_TO_GRAB 32
+
+/* A value that will not be set by qemu emulator */
+#define INITIAL_BATCH_RESULT 

[PATCH v3 15/15] platform: goldfish: pipe: Add the goldfish_pipe_v1 driver

2018-10-03 Thread rkir
From: Roman Kiryanov 

This is the v1 goldfish pipe driver.

Signed-off-by: Roman Kiryanov 
---
Changes in v3:
 - No change.
Changes in v2:
 - No change.

 drivers/platform/goldfish/Makefile|   2 +-
 drivers/platform/goldfish/goldfish_pipe.c |   9 +-
 .../platform/goldfish/goldfish_pipe_qemu.h|  27 +
 drivers/platform/goldfish/goldfish_pipe_v1.c  | 632 ++
 drivers/platform/goldfish/goldfish_pipe_v1.h  |  24 +
 5 files changed, 689 insertions(+), 5 deletions(-)
 create mode 100644 drivers/platform/goldfish/goldfish_pipe_v1.c
 create mode 100644 drivers/platform/goldfish/goldfish_pipe_v1.h

diff --git a/drivers/platform/goldfish/Makefile 
b/drivers/platform/goldfish/Makefile
index 016769e003d8..3fb7427b9dd8 100644
--- a/drivers/platform/goldfish/Makefile
+++ b/drivers/platform/goldfish/Makefile
@@ -2,4 +2,4 @@
 # Makefile for Goldfish platform specific drivers
 #
 obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe_all.o
-goldfish_pipe_all-objs := goldfish_pipe.o goldfish_pipe_v2.o
+goldfish_pipe_all-objs := goldfish_pipe.o goldfish_pipe_v1.o goldfish_pipe_v2.o
diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index 353f7ce94aa7..05a67895cc06 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -39,6 +39,7 @@
 #include 
 #include "goldfish_pipe_qemu.h"
 #include "goldfish_pipe.h"
+#include "goldfish_pipe_v1.h"
 #include "goldfish_pipe_v2.h"
 
 /*
@@ -84,10 +85,10 @@ static int goldfish_pipe_probe(struct platform_device *pdev)
writel(PIPE_DRIVER_VERSION, base + PIPE_V2_REG_VERSION);
version = readl(base + PIPE_V2_REG_VERSION);
 
-   if (WARN_ON(version < PIPE_CURRENT_DEVICE_VERSION))
-   return -EINVAL;
-
-   return goldfish_pipe_device_v2_init(pdev, base, irq);
+   if (version < PIPE_CURRENT_DEVICE_VERSION)
+   return goldfish_pipe_device_v1_init(pdev, base, irq);
+   else
+   return goldfish_pipe_device_v2_init(pdev, base, irq);
 }
 
 static int goldfish_pipe_remove(struct platform_device *pdev)
diff --git a/drivers/platform/goldfish/goldfish_pipe_qemu.h 
b/drivers/platform/goldfish/goldfish_pipe_qemu.h
index 24b02710769f..9a8275f3583d 100644
--- a/drivers/platform/goldfish/goldfish_pipe_qemu.h
+++ b/drivers/platform/goldfish/goldfish_pipe_qemu.h
@@ -62,6 +62,33 @@ enum PipeFlagsBits {
BIT_WAKE_ON_READ   = 2,  /* want to be woken on reads */
 };
 
+enum PipeV1Regs {
+   /* write: value = command */
+   PIPE_V1_REG_COMMAND = 0x00,
+   /* read */
+   PIPE_V1_REG_STATUS  = 0x04,
+   /* read/write: channel id */
+   PIPE_V1_REG_CHANNEL = 0x08,
+   /* read/write: channel id */
+   PIPE_V1_REG_CHANNEL_HIGH= 0x30,
+   /* read/write: buffer size */
+   PIPE_V1_REG_SIZE= 0x0C,
+   /* write: physical address */
+   PIPE_V1_REG_ADDRESS = 0x10,
+   /* write: physical address */
+   PIPE_V1_REG_ADDRESS_HIGH= 0x34,
+   /* read: wake flags */
+   PIPE_V1_REG_WAKES   = 0x14,
+   /* read/write: batch data address */
+   PIPE_V1_REG_PARAMS_ADDR_LOW = 0x18,
+   /* read/write: batch data address */
+   PIPE_V1_REG_PARAMS_ADDR_HIGH= 0x1C,
+   /* write: batch access */
+   PIPE_V1_REG_ACCESS_PARAMS   = 0x20,
+   /* read: device version */
+   PIPE_V1_REG_VERSION = 0x24,
+};
+
 enum PipeV2Regs {
PIPE_V2_REG_CMD = 0,
 
diff --git a/drivers/platform/goldfish/goldfish_pipe_v1.c 
b/drivers/platform/goldfish/goldfish_pipe_v1.c
new file mode 100644
index ..6e603204dd62
--- /dev/null
+++ b/drivers/platform/goldfish/goldfish_pipe_v1.c
@@ -0,0 +1,632 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2011 Google, Inc.
+ * Copyright (C) 2012 Intel, Inc.
+ * Copyright (C) 2013 Intel, Inc.
+ * Copyright (C) 2014 Linaro Limited
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+/* This source file contains the implementation of the legacy version of
+ * a goldfish pipe device driver. See goldfish_pipe_v2.c for the current
+ * version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "goldfish_pipe_qemu.h"
+#include "goldfish_pipe.h"
+
+#define MAX_PAGES_TO_GRAB 32
+
+/* A value that will not be set by qemu emulator */
+#define INITIAL_BATCH_RESULT 

[PATCH v3 09/15] platform: goldfish: pipe: Move goldfish_pipe to goldfish_pipe_v2

2018-10-03 Thread rkir
From: Roman Kiryanov 

This is the v2 driver. v1 will be added later.

Signed-off-by: Roman Kiryanov 
---
Changes in v3:
 - No change.
Changes in v2:
 - No change.

 drivers/platform/goldfish/Makefile  | 2 +-
 .../platform/goldfish/{goldfish_pipe.c => goldfish_pipe_v2.c}   | 0
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename drivers/platform/goldfish/{goldfish_pipe.c => goldfish_pipe_v2.c} (100%)

diff --git a/drivers/platform/goldfish/Makefile 
b/drivers/platform/goldfish/Makefile
index e0c202df9674..81f899a987a2 100644
--- a/drivers/platform/goldfish/Makefile
+++ b/drivers/platform/goldfish/Makefile
@@ -1,4 +1,4 @@
 #
 # Makefile for Goldfish platform specific drivers
 #
-obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe.o
+obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe_v2.o
diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe_v2.c
similarity index 100%
rename from drivers/platform/goldfish/goldfish_pipe.c
rename to drivers/platform/goldfish/goldfish_pipe_v2.c
-- 
2.19.0.605.g01d371f741-goog



[PATCH v3 11/15] platform: goldfish: pipe: Split the driver to v2 specific and the rest

2018-10-03 Thread rkir
From: Roman Kiryanov 

Move probe/remove and other driver stuff to a separate file
to plug v1 there later.

Signed-off-by: Roman Kiryanov 
---
Changes in v3:
 - No change.
Changes in v2:
 - No change.

 drivers/platform/goldfish/Makefile   |   3 +-
 drivers/platform/goldfish/goldfish_pipe.c| 124 +++
 drivers/platform/goldfish/goldfish_pipe.h|  10 ++
 drivers/platform/goldfish/goldfish_pipe_v2.c | 112 +++--
 drivers/platform/goldfish/goldfish_pipe_v2.h |  10 ++
 5 files changed, 161 insertions(+), 98 deletions(-)
 create mode 100644 drivers/platform/goldfish/goldfish_pipe.c
 create mode 100644 drivers/platform/goldfish/goldfish_pipe.h
 create mode 100644 drivers/platform/goldfish/goldfish_pipe_v2.h

diff --git a/drivers/platform/goldfish/Makefile 
b/drivers/platform/goldfish/Makefile
index 81f899a987a2..016769e003d8 100644
--- a/drivers/platform/goldfish/Makefile
+++ b/drivers/platform/goldfish/Makefile
@@ -1,4 +1,5 @@
 #
 # Makefile for Goldfish platform specific drivers
 #
-obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe_v2.o
+obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe_all.o
+goldfish_pipe_all-objs := goldfish_pipe.o goldfish_pipe_v2.o
diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
new file mode 100644
index ..792b20bdf76c
--- /dev/null
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -0,0 +1,124 @@
+// SPDX-License-Identifier: GPL-2.0
+/* This source file contains the implementation of a special device driver
+ * that intends to provide a *very* fast communication channel between the
+ * guest system and the QEMU emulator.
+ *
+ * Usage from the guest is simply the following (error handling simplified):
+ *
+ *int  fd = open("/dev/qemu_pipe",O_RDWR);
+ * write() or read() through the pipe.
+ *
+ * This driver doesn't deal with the exact protocol used during the session.
+ * It is intended to be as simple as something like:
+ *
+ *// do this _just_ after opening the fd to connect to a specific
+ *// emulator service.
+ *const char*  msg = "";
+ *if (write(fd, msg, strlen(msg)+1) < 0) {
+ *   ... could not connect to  service
+ *   close(fd);
+ *}
+ *
+ *// after this, simply read() and write() to communicate with the
+ *// service. Exact protocol details left as an exercise to the reader.
+ *
+ * This driver is very fast because it doesn't copy any data through
+ * intermediate buffers, since the emulator is capable of translating
+ * guest user addresses into host ones.
+ *
+ * Note that we must however ensure that each user page involved in the
+ * exchange is properly mapped during a transfer.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "goldfish_pipe_qemu.h"
+#include "goldfish_pipe.h"
+#include "goldfish_pipe_v2.h"
+
+/*
+ * Update this when something changes in the driver's behavior so the host
+ * can benefit from knowing it
+ */
+enum {
+   PIPE_DRIVER_VERSION = 2,
+   PIPE_CURRENT_DEVICE_VERSION = 2
+};
+
+static int goldfish_pipe_probe(struct platform_device *pdev)
+{
+   struct resource *r;
+   char __iomem *base;
+   int irq;
+   int version;
+
+   r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+   if (!r || resource_size(r) < PAGE_SIZE) {
+   dev_err(>dev, "can't allocate i/o page\n");
+   return -EINVAL;
+   }
+   base = devm_ioremap(>dev, r->start, PAGE_SIZE);
+   if (!base) {
+   dev_err(>dev, "ioremap failed\n");
+   return -EINVAL;
+   }
+
+   r = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
+   if (!r)
+   return -EINVAL;
+
+   irq = r->start;
+
+   /*
+* Exchange the versions with the host device
+*
+* Note: v1 driver used to not report its version, so we write it before
+*  reading device version back: this allows the host implementation to
+*  detect the old driver (if there was no version write before read).
+*/
+   writel(PIPE_DRIVER_VERSION, base + PIPE_REG_VERSION);
+   version = readl(base + PIPE_REG_VERSION);
+
+   if (WARN_ON(version < PIPE_CURRENT_DEVICE_VERSION))
+   return -EINVAL;
+
+   return goldfish_pipe_device_init(pdev, base, irq);
+}
+
+static int goldfish_pipe_remove(struct platform_device *pdev)
+{
+   struct goldfish_pipe_dev_base *dev = platform_get_drvdata(pdev);
+
+   return dev->deinit(dev, pdev);
+}
+
+static const struct acpi_device_id goldfish_pipe_acpi_match[] = {
+   { "GFSH0003", 0 },
+   { },
+};
+MODULE_DEVICE_TABLE(acpi, goldfish_pipe_acpi_match);
+
+static const struct of_device_id goldfish_pipe_of_match[] = {
+   { .compatible = "google,android-pipe", },
+   {},
+};
+MODULE_DEVICE_TABLE(of, goldfish_pipe_of_match);
+
+static struct platform_driver goldfish_pipe_driver = {
+   .probe = goldfish_pipe_probe,
+ 

[PATCH v3 10/15] platform: goldfish: pipe: Remove the license boilerplate

2018-10-03 Thread rkir
From: Roman Kiryanov 

Not required with the SPDX-License-Identifier header.

Signed-off-by: Roman Kiryanov 
---
Changes in v3:
 - No change.
Changes in v2:
 - No change.

 drivers/platform/goldfish/goldfish_pipe_v2.c | 17 -
 1 file changed, 17 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe_v2.c 
b/drivers/platform/goldfish/goldfish_pipe_v2.c
index a1fbbf49cc3f..ff5d88e7959a 100644
--- a/drivers/platform/goldfish/goldfish_pipe_v2.c
+++ b/drivers/platform/goldfish/goldfish_pipe_v2.c
@@ -1,21 +1,4 @@
 // SPDX-License-Identifier: GPL-2.0
-/*
- * Copyright (C) 2012 Intel, Inc.
- * Copyright (C) 2013 Intel, Inc.
- * Copyright (C) 2014 Linaro Limited
- * Copyright (C) 2011-2016 Google, Inc.
- *
- * This software is licensed under the terms of the GNU General Public
- * License version 2, as published by the Free Software Foundation, and
- * may be copied, distributed, and modified under those terms.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- */
-
 /* This source file contains the implementation of a special device driver
  * that intends to provide a *very* fast communication channel between the
  * guest system and the QEMU emulator.
-- 
2.19.0.605.g01d371f741-goog



[PATCH v3 09/15] platform: goldfish: pipe: Move goldfish_pipe to goldfish_pipe_v2

2018-10-03 Thread rkir
From: Roman Kiryanov 

This is the v2 driver. v1 will be added later.

Signed-off-by: Roman Kiryanov 
---
Changes in v3:
 - No change.
Changes in v2:
 - No change.

 drivers/platform/goldfish/Makefile  | 2 +-
 .../platform/goldfish/{goldfish_pipe.c => goldfish_pipe_v2.c}   | 0
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename drivers/platform/goldfish/{goldfish_pipe.c => goldfish_pipe_v2.c} (100%)

diff --git a/drivers/platform/goldfish/Makefile 
b/drivers/platform/goldfish/Makefile
index e0c202df9674..81f899a987a2 100644
--- a/drivers/platform/goldfish/Makefile
+++ b/drivers/platform/goldfish/Makefile
@@ -1,4 +1,4 @@
 #
 # Makefile for Goldfish platform specific drivers
 #
-obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe.o
+obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe_v2.o
diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe_v2.c
similarity index 100%
rename from drivers/platform/goldfish/goldfish_pipe.c
rename to drivers/platform/goldfish/goldfish_pipe_v2.c
-- 
2.19.0.605.g01d371f741-goog



[PATCH v3 11/15] platform: goldfish: pipe: Split the driver to v2 specific and the rest

2018-10-03 Thread rkir
From: Roman Kiryanov 

Move probe/remove and other driver stuff to a separate file
to plug v1 there later.

Signed-off-by: Roman Kiryanov 
---
Changes in v3:
 - No change.
Changes in v2:
 - No change.

 drivers/platform/goldfish/Makefile   |   3 +-
 drivers/platform/goldfish/goldfish_pipe.c| 124 +++
 drivers/platform/goldfish/goldfish_pipe.h|  10 ++
 drivers/platform/goldfish/goldfish_pipe_v2.c | 112 +++--
 drivers/platform/goldfish/goldfish_pipe_v2.h |  10 ++
 5 files changed, 161 insertions(+), 98 deletions(-)
 create mode 100644 drivers/platform/goldfish/goldfish_pipe.c
 create mode 100644 drivers/platform/goldfish/goldfish_pipe.h
 create mode 100644 drivers/platform/goldfish/goldfish_pipe_v2.h

diff --git a/drivers/platform/goldfish/Makefile 
b/drivers/platform/goldfish/Makefile
index 81f899a987a2..016769e003d8 100644
--- a/drivers/platform/goldfish/Makefile
+++ b/drivers/platform/goldfish/Makefile
@@ -1,4 +1,5 @@
 #
 # Makefile for Goldfish platform specific drivers
 #
-obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe_v2.o
+obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe_all.o
+goldfish_pipe_all-objs := goldfish_pipe.o goldfish_pipe_v2.o
diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
new file mode 100644
index ..792b20bdf76c
--- /dev/null
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -0,0 +1,124 @@
+// SPDX-License-Identifier: GPL-2.0
+/* This source file contains the implementation of a special device driver
+ * that intends to provide a *very* fast communication channel between the
+ * guest system and the QEMU emulator.
+ *
+ * Usage from the guest is simply the following (error handling simplified):
+ *
+ *int  fd = open("/dev/qemu_pipe",O_RDWR);
+ * write() or read() through the pipe.
+ *
+ * This driver doesn't deal with the exact protocol used during the session.
+ * It is intended to be as simple as something like:
+ *
+ *// do this _just_ after opening the fd to connect to a specific
+ *// emulator service.
+ *const char*  msg = "";
+ *if (write(fd, msg, strlen(msg)+1) < 0) {
+ *   ... could not connect to  service
+ *   close(fd);
+ *}
+ *
+ *// after this, simply read() and write() to communicate with the
+ *// service. Exact protocol details left as an exercise to the reader.
+ *
+ * This driver is very fast because it doesn't copy any data through
+ * intermediate buffers, since the emulator is capable of translating
+ * guest user addresses into host ones.
+ *
+ * Note that we must however ensure that each user page involved in the
+ * exchange is properly mapped during a transfer.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "goldfish_pipe_qemu.h"
+#include "goldfish_pipe.h"
+#include "goldfish_pipe_v2.h"
+
+/*
+ * Update this when something changes in the driver's behavior so the host
+ * can benefit from knowing it
+ */
+enum {
+   PIPE_DRIVER_VERSION = 2,
+   PIPE_CURRENT_DEVICE_VERSION = 2
+};
+
+static int goldfish_pipe_probe(struct platform_device *pdev)
+{
+   struct resource *r;
+   char __iomem *base;
+   int irq;
+   int version;
+
+   r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+   if (!r || resource_size(r) < PAGE_SIZE) {
+   dev_err(>dev, "can't allocate i/o page\n");
+   return -EINVAL;
+   }
+   base = devm_ioremap(>dev, r->start, PAGE_SIZE);
+   if (!base) {
+   dev_err(>dev, "ioremap failed\n");
+   return -EINVAL;
+   }
+
+   r = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
+   if (!r)
+   return -EINVAL;
+
+   irq = r->start;
+
+   /*
+* Exchange the versions with the host device
+*
+* Note: v1 driver used to not report its version, so we write it before
+*  reading device version back: this allows the host implementation to
+*  detect the old driver (if there was no version write before read).
+*/
+   writel(PIPE_DRIVER_VERSION, base + PIPE_REG_VERSION);
+   version = readl(base + PIPE_REG_VERSION);
+
+   if (WARN_ON(version < PIPE_CURRENT_DEVICE_VERSION))
+   return -EINVAL;
+
+   return goldfish_pipe_device_init(pdev, base, irq);
+}
+
+static int goldfish_pipe_remove(struct platform_device *pdev)
+{
+   struct goldfish_pipe_dev_base *dev = platform_get_drvdata(pdev);
+
+   return dev->deinit(dev, pdev);
+}
+
+static const struct acpi_device_id goldfish_pipe_acpi_match[] = {
+   { "GFSH0003", 0 },
+   { },
+};
+MODULE_DEVICE_TABLE(acpi, goldfish_pipe_acpi_match);
+
+static const struct of_device_id goldfish_pipe_of_match[] = {
+   { .compatible = "google,android-pipe", },
+   {},
+};
+MODULE_DEVICE_TABLE(of, goldfish_pipe_of_match);
+
+static struct platform_driver goldfish_pipe_driver = {
+   .probe = goldfish_pipe_probe,
+ 

[PATCH v3 10/15] platform: goldfish: pipe: Remove the license boilerplate

2018-10-03 Thread rkir
From: Roman Kiryanov 

Not required with the SPDX-License-Identifier header.

Signed-off-by: Roman Kiryanov 
---
Changes in v3:
 - No change.
Changes in v2:
 - No change.

 drivers/platform/goldfish/goldfish_pipe_v2.c | 17 -
 1 file changed, 17 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe_v2.c 
b/drivers/platform/goldfish/goldfish_pipe_v2.c
index a1fbbf49cc3f..ff5d88e7959a 100644
--- a/drivers/platform/goldfish/goldfish_pipe_v2.c
+++ b/drivers/platform/goldfish/goldfish_pipe_v2.c
@@ -1,21 +1,4 @@
 // SPDX-License-Identifier: GPL-2.0
-/*
- * Copyright (C) 2012 Intel, Inc.
- * Copyright (C) 2013 Intel, Inc.
- * Copyright (C) 2014 Linaro Limited
- * Copyright (C) 2011-2016 Google, Inc.
- *
- * This software is licensed under the terms of the GNU General Public
- * License version 2, as published by the Free Software Foundation, and
- * may be copied, distributed, and modified under those terms.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- */
-
 /* This source file contains the implementation of a special device driver
  * that intends to provide a *very* fast communication channel between the
  * guest system and the QEMU emulator.
-- 
2.19.0.605.g01d371f741-goog



[PATCH v3 06/15] platform: goldfish: pipe: Move memory allocation from probe to init

2018-10-03 Thread rkir
From: Roman Kiryanov 

There will be two separate init functions for v1 and v2
(different driver versions) and they will allocate different
state.

Signed-off-by: Roman Kiryanov 
---
Changes in v3:
 - No change.
Changes in v2:
 - No change.

 drivers/platform/goldfish/goldfish_pipe.c | 42 +--
 1 file changed, 23 insertions(+), 19 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index bc431f04c4cf..445c0c0c66c4 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -208,8 +208,6 @@ struct goldfish_pipe_dev {
struct device *pdev_dev;
 
/* Some device-specific data */
-   int irq;
-   int version;
unsigned char __iomem *base;
 
/* an irq tasklet to run goldfish_interrupt_task */
@@ -817,14 +815,23 @@ static void write_pa_addr(void *addr, void __iomem 
*portl, void __iomem *porth)
 }
 
 static int goldfish_pipe_device_init(struct platform_device *pdev,
-struct goldfish_pipe_dev *dev)
+char __iomem *base,
+int irq)
 {
+   struct goldfish_pipe_dev *dev;
int err;
 
+   dev = devm_kzalloc(>dev, sizeof(*dev), GFP_KERNEL);
+   if (!dev)
+   return -ENOMEM;
+
+   dev->magic = _pipe_device_deinit;
+   spin_lock_init(>lock);
+
tasklet_init(>irq_tasklet, _interrupt_task,
 (unsigned long)dev);
 
-   err = devm_request_irq(>dev, dev->irq,
+   err = devm_request_irq(>dev, irq,
   goldfish_pipe_interrupt,
   IRQF_SHARED, "goldfish_pipe", dev);
if (err) {
@@ -839,6 +846,7 @@ static int goldfish_pipe_device_init(struct platform_device 
*pdev,
return err;
}
 
+   dev->base = base;
dev->pdev_dev = >dev;
dev->first_signalled_pipe = NULL;
dev->pipes_capacity = INITIAL_PIPES_CAPACITY;
@@ -892,22 +900,18 @@ static void goldfish_pipe_device_deinit(struct 
platform_device *pdev,
 static int goldfish_pipe_probe(struct platform_device *pdev)
 {
struct resource *r;
-   struct goldfish_pipe_dev *dev;
-
-   dev = devm_kzalloc(>dev, sizeof(*dev), GFP_KERNEL);
-   if (!dev)
-   return -ENOMEM;
-
-   dev->magic = _pipe_device_deinit;
-   spin_lock_init(>lock);
+   char __iomem *base;
+   int irq;
+   int version;
 
r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!r || resource_size(r) < PAGE_SIZE) {
dev_err(>dev, "can't allocate i/o page\n");
return -EINVAL;
}
-   dev->base = devm_ioremap(>dev, r->start, PAGE_SIZE);
-   if (!dev->base) {
+
+   base = devm_ioremap(>dev, r->start, PAGE_SIZE);
+   if (!base) {
dev_err(>dev, "ioremap failed\n");
return -EINVAL;
}
@@ -916,7 +920,7 @@ static int goldfish_pipe_probe(struct platform_device *pdev)
if (!r)
return -EINVAL;
 
-   dev->irq = r->start;
+   irq = r->start;
 
/*
 * Exchange the versions with the host device
@@ -925,12 +929,12 @@ static int goldfish_pipe_probe(struct platform_device 
*pdev)
 *  reading device version back: this allows the host implementation to
 *  detect the old driver (if there was no version write before read).
 */
-   writel(PIPE_DRIVER_VERSION, dev->base + PIPE_REG_VERSION);
-   dev->version = readl(dev->base + PIPE_REG_VERSION);
-   if (WARN_ON(dev->version < PIPE_CURRENT_DEVICE_VERSION))
+   writel(PIPE_DRIVER_VERSION, base + PIPE_REG_VERSION);
+   version = readl(base + PIPE_REG_VERSION);
+   if (WARN_ON(version < PIPE_CURRENT_DEVICE_VERSION))
return -EINVAL;
 
-   return goldfish_pipe_device_init(pdev, dev);
+   return goldfish_pipe_device_init(pdev, base, irq);
 }
 
 static int goldfish_pipe_remove(struct platform_device *pdev)
-- 
2.19.0.605.g01d371f741-goog



[PATCH v3 07/15] platform: goldfish: pipe: Return status from "deinit" since "remove" does not do much

2018-10-03 Thread rkir
From: Roman Kiryanov 

This way deinit will have a chance to report an error.

Signed-off-by: Roman Kiryanov 
---
Changes in v3:
 - No change.
Changes in v2:
 - No change.

 drivers/platform/goldfish/goldfish_pipe.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index 445c0c0c66c4..1822d4146778 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -888,13 +888,15 @@ static int goldfish_pipe_device_init(struct 
platform_device *pdev,
return 0;
 }
 
-static void goldfish_pipe_device_deinit(struct platform_device *pdev,
-   struct goldfish_pipe_dev *dev)
+static int goldfish_pipe_device_deinit(struct platform_device *pdev,
+  struct goldfish_pipe_dev *dev)
 {
misc_deregister(>miscdev);
tasklet_kill(>irq_tasklet);
kfree(dev->pipes);
free_page((unsigned long)dev->buffers);
+
+   return 0;
 }
 
 static int goldfish_pipe_probe(struct platform_device *pdev)
@@ -941,8 +943,7 @@ static int goldfish_pipe_remove(struct platform_device 
*pdev)
 {
struct goldfish_pipe_dev *dev = platform_get_drvdata(pdev);
 
-   goldfish_pipe_device_deinit(pdev, dev);
-   return 0;
+   return goldfish_pipe_device_deinit(pdev, dev);
 }
 
 static const struct acpi_device_id goldfish_pipe_acpi_match[] = {
-- 
2.19.0.605.g01d371f741-goog



[PATCH v3 08/15] platform: goldfish: pipe: Add a blank line to separate varibles and code

2018-10-03 Thread rkir
From: Roman Kiryanov 

checkpacth: Missing a blank line after declarations

Signed-off-by: Roman Kiryanov 
---
Changes in v3:
 - No change.
Changes in v2:
 - No change.

 drivers/platform/goldfish/goldfish_pipe.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index 1822d4146778..a1fbbf49cc3f 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -713,6 +713,7 @@ static int goldfish_pipe_open(struct inode *inode, struct 
file *file)
 
/* Allocate new pipe kernel object */
struct goldfish_pipe *pipe = kzalloc(sizeof(*pipe), GFP_KERNEL);
+
if (!pipe)
return -ENOMEM;
 
-- 
2.19.0.605.g01d371f741-goog



[PATCH v3 06/15] platform: goldfish: pipe: Move memory allocation from probe to init

2018-10-03 Thread rkir
From: Roman Kiryanov 

There will be two separate init functions for v1 and v2
(different driver versions) and they will allocate different
state.

Signed-off-by: Roman Kiryanov 
---
Changes in v3:
 - No change.
Changes in v2:
 - No change.

 drivers/platform/goldfish/goldfish_pipe.c | 42 +--
 1 file changed, 23 insertions(+), 19 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index bc431f04c4cf..445c0c0c66c4 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -208,8 +208,6 @@ struct goldfish_pipe_dev {
struct device *pdev_dev;
 
/* Some device-specific data */
-   int irq;
-   int version;
unsigned char __iomem *base;
 
/* an irq tasklet to run goldfish_interrupt_task */
@@ -817,14 +815,23 @@ static void write_pa_addr(void *addr, void __iomem 
*portl, void __iomem *porth)
 }
 
 static int goldfish_pipe_device_init(struct platform_device *pdev,
-struct goldfish_pipe_dev *dev)
+char __iomem *base,
+int irq)
 {
+   struct goldfish_pipe_dev *dev;
int err;
 
+   dev = devm_kzalloc(>dev, sizeof(*dev), GFP_KERNEL);
+   if (!dev)
+   return -ENOMEM;
+
+   dev->magic = _pipe_device_deinit;
+   spin_lock_init(>lock);
+
tasklet_init(>irq_tasklet, _interrupt_task,
 (unsigned long)dev);
 
-   err = devm_request_irq(>dev, dev->irq,
+   err = devm_request_irq(>dev, irq,
   goldfish_pipe_interrupt,
   IRQF_SHARED, "goldfish_pipe", dev);
if (err) {
@@ -839,6 +846,7 @@ static int goldfish_pipe_device_init(struct platform_device 
*pdev,
return err;
}
 
+   dev->base = base;
dev->pdev_dev = >dev;
dev->first_signalled_pipe = NULL;
dev->pipes_capacity = INITIAL_PIPES_CAPACITY;
@@ -892,22 +900,18 @@ static void goldfish_pipe_device_deinit(struct 
platform_device *pdev,
 static int goldfish_pipe_probe(struct platform_device *pdev)
 {
struct resource *r;
-   struct goldfish_pipe_dev *dev;
-
-   dev = devm_kzalloc(>dev, sizeof(*dev), GFP_KERNEL);
-   if (!dev)
-   return -ENOMEM;
-
-   dev->magic = _pipe_device_deinit;
-   spin_lock_init(>lock);
+   char __iomem *base;
+   int irq;
+   int version;
 
r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!r || resource_size(r) < PAGE_SIZE) {
dev_err(>dev, "can't allocate i/o page\n");
return -EINVAL;
}
-   dev->base = devm_ioremap(>dev, r->start, PAGE_SIZE);
-   if (!dev->base) {
+
+   base = devm_ioremap(>dev, r->start, PAGE_SIZE);
+   if (!base) {
dev_err(>dev, "ioremap failed\n");
return -EINVAL;
}
@@ -916,7 +920,7 @@ static int goldfish_pipe_probe(struct platform_device *pdev)
if (!r)
return -EINVAL;
 
-   dev->irq = r->start;
+   irq = r->start;
 
/*
 * Exchange the versions with the host device
@@ -925,12 +929,12 @@ static int goldfish_pipe_probe(struct platform_device 
*pdev)
 *  reading device version back: this allows the host implementation to
 *  detect the old driver (if there was no version write before read).
 */
-   writel(PIPE_DRIVER_VERSION, dev->base + PIPE_REG_VERSION);
-   dev->version = readl(dev->base + PIPE_REG_VERSION);
-   if (WARN_ON(dev->version < PIPE_CURRENT_DEVICE_VERSION))
+   writel(PIPE_DRIVER_VERSION, base + PIPE_REG_VERSION);
+   version = readl(base + PIPE_REG_VERSION);
+   if (WARN_ON(version < PIPE_CURRENT_DEVICE_VERSION))
return -EINVAL;
 
-   return goldfish_pipe_device_init(pdev, dev);
+   return goldfish_pipe_device_init(pdev, base, irq);
 }
 
 static int goldfish_pipe_remove(struct platform_device *pdev)
-- 
2.19.0.605.g01d371f741-goog



[PATCH v3 07/15] platform: goldfish: pipe: Return status from "deinit" since "remove" does not do much

2018-10-03 Thread rkir
From: Roman Kiryanov 

This way deinit will have a chance to report an error.

Signed-off-by: Roman Kiryanov 
---
Changes in v3:
 - No change.
Changes in v2:
 - No change.

 drivers/platform/goldfish/goldfish_pipe.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index 445c0c0c66c4..1822d4146778 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -888,13 +888,15 @@ static int goldfish_pipe_device_init(struct 
platform_device *pdev,
return 0;
 }
 
-static void goldfish_pipe_device_deinit(struct platform_device *pdev,
-   struct goldfish_pipe_dev *dev)
+static int goldfish_pipe_device_deinit(struct platform_device *pdev,
+  struct goldfish_pipe_dev *dev)
 {
misc_deregister(>miscdev);
tasklet_kill(>irq_tasklet);
kfree(dev->pipes);
free_page((unsigned long)dev->buffers);
+
+   return 0;
 }
 
 static int goldfish_pipe_probe(struct platform_device *pdev)
@@ -941,8 +943,7 @@ static int goldfish_pipe_remove(struct platform_device 
*pdev)
 {
struct goldfish_pipe_dev *dev = platform_get_drvdata(pdev);
 
-   goldfish_pipe_device_deinit(pdev, dev);
-   return 0;
+   return goldfish_pipe_device_deinit(pdev, dev);
 }
 
 static const struct acpi_device_id goldfish_pipe_acpi_match[] = {
-- 
2.19.0.605.g01d371f741-goog



[PATCH v3 08/15] platform: goldfish: pipe: Add a blank line to separate varibles and code

2018-10-03 Thread rkir
From: Roman Kiryanov 

checkpacth: Missing a blank line after declarations

Signed-off-by: Roman Kiryanov 
---
Changes in v3:
 - No change.
Changes in v2:
 - No change.

 drivers/platform/goldfish/goldfish_pipe.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index 1822d4146778..a1fbbf49cc3f 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -713,6 +713,7 @@ static int goldfish_pipe_open(struct inode *inode, struct 
file *file)
 
/* Allocate new pipe kernel object */
struct goldfish_pipe *pipe = kzalloc(sizeof(*pipe), GFP_KERNEL);
+
if (!pipe)
return -ENOMEM;
 
-- 
2.19.0.605.g01d371f741-goog



[PATCH v3 04/15] platform: goldfish: pipe: Call misc_deregister if init fails

2018-10-03 Thread rkir
From: Roman Kiryanov 

Undo effects of misc_register if driver's init fails after
misc_register.

Signed-off-by: Roman Kiryanov 
---
Changes in v3:
 - No change.
Changes in v2:
 - No change.

 drivers/platform/goldfish/goldfish_pipe.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index 4013832f38fb..c386aaf40034 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -844,8 +844,10 @@ static int goldfish_pipe_device_init(struct 
platform_device *pdev,
dev->pipes_capacity = INITIAL_PIPES_CAPACITY;
dev->pipes = kcalloc(dev->pipes_capacity, sizeof(*dev->pipes),
 GFP_KERNEL);
-   if (!dev->pipes)
+   if (!dev->pipes) {
+   misc_deregister(>miscdev);
return -ENOMEM;
+   }
 
/*
 * We're going to pass two buffers, open_command_params and
@@ -858,6 +860,7 @@ static int goldfish_pipe_device_init(struct platform_device 
*pdev,
__get_free_page(GFP_KERNEL);
if (!dev->buffers) {
kfree(dev->pipes);
+   misc_deregister(>miscdev);
return -ENOMEM;
}
 
-- 
2.19.0.605.g01d371f741-goog



[PATCH v3 05/15] platform: goldfish: pipe: Remove redundant casting

2018-10-03 Thread rkir
From: Roman Kiryanov 

This casting is not required.

Signed-off-by: Roman Kiryanov 
---
Changes in v3:
 - No change.
Changes in v2:
 - No change.

 drivers/platform/goldfish/goldfish_pipe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index c386aaf40034..bc431f04c4cf 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -925,7 +925,7 @@ static int goldfish_pipe_probe(struct platform_device *pdev)
 *  reading device version back: this allows the host implementation to
 *  detect the old driver (if there was no version write before read).
 */
-   writel((u32)PIPE_DRIVER_VERSION, dev->base + PIPE_REG_VERSION);
+   writel(PIPE_DRIVER_VERSION, dev->base + PIPE_REG_VERSION);
dev->version = readl(dev->base + PIPE_REG_VERSION);
if (WARN_ON(dev->version < PIPE_CURRENT_DEVICE_VERSION))
return -EINVAL;
-- 
2.19.0.605.g01d371f741-goog



[PATCH v3 04/15] platform: goldfish: pipe: Call misc_deregister if init fails

2018-10-03 Thread rkir
From: Roman Kiryanov 

Undo effects of misc_register if driver's init fails after
misc_register.

Signed-off-by: Roman Kiryanov 
---
Changes in v3:
 - No change.
Changes in v2:
 - No change.

 drivers/platform/goldfish/goldfish_pipe.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index 4013832f38fb..c386aaf40034 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -844,8 +844,10 @@ static int goldfish_pipe_device_init(struct 
platform_device *pdev,
dev->pipes_capacity = INITIAL_PIPES_CAPACITY;
dev->pipes = kcalloc(dev->pipes_capacity, sizeof(*dev->pipes),
 GFP_KERNEL);
-   if (!dev->pipes)
+   if (!dev->pipes) {
+   misc_deregister(>miscdev);
return -ENOMEM;
+   }
 
/*
 * We're going to pass two buffers, open_command_params and
@@ -858,6 +860,7 @@ static int goldfish_pipe_device_init(struct platform_device 
*pdev,
__get_free_page(GFP_KERNEL);
if (!dev->buffers) {
kfree(dev->pipes);
+   misc_deregister(>miscdev);
return -ENOMEM;
}
 
-- 
2.19.0.605.g01d371f741-goog



[PATCH v3 05/15] platform: goldfish: pipe: Remove redundant casting

2018-10-03 Thread rkir
From: Roman Kiryanov 

This casting is not required.

Signed-off-by: Roman Kiryanov 
---
Changes in v3:
 - No change.
Changes in v2:
 - No change.

 drivers/platform/goldfish/goldfish_pipe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index c386aaf40034..bc431f04c4cf 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -925,7 +925,7 @@ static int goldfish_pipe_probe(struct platform_device *pdev)
 *  reading device version back: this allows the host implementation to
 *  detect the old driver (if there was no version write before read).
 */
-   writel((u32)PIPE_DRIVER_VERSION, dev->base + PIPE_REG_VERSION);
+   writel(PIPE_DRIVER_VERSION, dev->base + PIPE_REG_VERSION);
dev->version = readl(dev->base + PIPE_REG_VERSION);
if (WARN_ON(dev->version < PIPE_CURRENT_DEVICE_VERSION))
return -EINVAL;
-- 
2.19.0.605.g01d371f741-goog



[PATCH v3 01/15] platform: goldfish: pipe: Move the file-scope goldfish_interrupt_tasklet variable into the driver state

2018-10-03 Thread rkir
From: Roman Kiryanov 

This is a series of patches to move mutable 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 
---
Changes in v3:
 - No change.
Changes in v2:
 - Updated the commit message.

 drivers/platform/goldfish/goldfish_pipe.c | 24 +++
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index 56665e879e5a..ba9aede17d57 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -208,6 +208,9 @@ struct goldfish_pipe_dev {
int irq;
int version;
unsigned char __iomem *base;
+
+   /* an irq tasklet to run goldfish_interrupt_task */
+   struct tasklet_struct irq_tasklet;
 };
 
 static struct goldfish_pipe_dev goldfish_pipe_dev;
@@ -582,14 +585,14 @@ static struct goldfish_pipe *signalled_pipes_pop_front(
return pipe;
 }
 
-static void goldfish_interrupt_task(unsigned long unused)
+static void goldfish_interrupt_task(unsigned long dev_addr)
 {
/* Iterate over the signalled pipes and wake them one by one */
+   struct goldfish_pipe_dev *dev = (struct goldfish_pipe_dev *)dev_addr;
struct goldfish_pipe *pipe;
int wakes;
 
-   while ((pipe = signalled_pipes_pop_front(_pipe_dev, )) !=
-   NULL) {
+   while ((pipe = signalled_pipes_pop_front(dev, )) != NULL) {
if (wakes & PIPE_WAKE_CLOSED) {
pipe->flags = 1 << BIT_CLOSED_ON_HOST;
} else {
@@ -605,7 +608,6 @@ static void goldfish_interrupt_task(unsigned long unused)
wake_up_interruptible(>wake_queue);
}
 }
-static DECLARE_TASKLET(goldfish_interrupt_tasklet, goldfish_interrupt_task, 0);
 
 /*
  * The general idea of the interrupt handling:
@@ -648,7 +650,7 @@ static irqreturn_t goldfish_pipe_interrupt(int irq, void 
*dev_id)
 
spin_unlock_irqrestore(>lock, flags);
 
-   tasklet_schedule(_interrupt_tasklet);
+   tasklet_schedule(>irq_tasklet);
return IRQ_HANDLED;
 }
 
@@ -800,9 +802,14 @@ static void write_pa_addr(void *addr, void __iomem *portl, 
void __iomem *porth)
 static int goldfish_pipe_device_init(struct platform_device *pdev)
 {
struct goldfish_pipe_dev *dev = _pipe_dev;
-   int err = devm_request_irq(>dev, dev->irq,
-   goldfish_pipe_interrupt,
-   IRQF_SHARED, "goldfish_pipe", dev);
+   int err;
+
+   tasklet_init(>irq_tasklet, _interrupt_task,
+(unsigned long)dev);
+
+   err = devm_request_irq(>dev, dev->irq,
+  goldfish_pipe_interrupt,
+  IRQF_SHARED, "goldfish_pipe", dev);
if (err) {
dev_err(>dev, "unable to allocate IRQ for v2\n");
return err;
@@ -854,6 +861,7 @@ static int goldfish_pipe_device_init(struct platform_device 
*pdev)
 static void goldfish_pipe_device_deinit(struct platform_device *pdev)
 {
misc_deregister(_pipe_miscdev);
+   tasklet_kill(_pipe_dev.irq_tasklet);
kfree(goldfish_pipe_dev.pipes);
free_page((unsigned long)goldfish_pipe_dev.buffers);
 }
-- 
2.19.0.605.g01d371f741-goog



[PATCH v3 02/15] platform: goldfish: pipe: Move the file-scope goldfish_pipe_miscdev variable into the driver state

2018-10-03 Thread rkir
From: Roman Kiryanov 

This is a series of patches to move mutable 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 
---
Changes in v3:
 - No change.
Changes in v2:
 - Updated the commit message.

 drivers/platform/goldfish/goldfish_pipe.c | 20 +---
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index ba9aede17d57..8ca709b45e1f 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -211,6 +211,8 @@ struct goldfish_pipe_dev {
 
/* an irq tasklet to run goldfish_interrupt_task */
struct tasklet_struct irq_tasklet;
+
+   struct miscdevice miscdev;
 };
 
 static struct goldfish_pipe_dev goldfish_pipe_dev;
@@ -785,11 +787,14 @@ static const struct file_operations goldfish_pipe_fops = {
.release = goldfish_pipe_release,
 };
 
-static struct miscdevice goldfish_pipe_miscdev = {
-   .minor = MISC_DYNAMIC_MINOR,
-   .name = "goldfish_pipe",
-   .fops = _pipe_fops,
-};
+static void init_miscdevice(struct miscdevice *miscdev)
+{
+   memset(miscdev, 0, sizeof(*miscdev));
+
+   miscdev->minor = MISC_DYNAMIC_MINOR;
+   miscdev->name = "goldfish_pipe";
+   miscdev->fops = _pipe_fops;
+}
 
 static void write_pa_addr(void *addr, void __iomem *portl, void __iomem *porth)
 {
@@ -815,7 +820,8 @@ static int goldfish_pipe_device_init(struct platform_device 
*pdev)
return err;
}
 
-   err = misc_register(_pipe_miscdev);
+   init_miscdevice(>miscdev);
+   err = misc_register(>miscdev);
if (err) {
dev_err(>dev, "unable to register v2 device\n");
return err;
@@ -860,7 +866,7 @@ static int goldfish_pipe_device_init(struct platform_device 
*pdev)
 
 static void goldfish_pipe_device_deinit(struct platform_device *pdev)
 {
-   misc_deregister(_pipe_miscdev);
+   misc_deregister(_pipe_dev.miscdev);
tasklet_kill(_pipe_dev.irq_tasklet);
kfree(goldfish_pipe_dev.pipes);
free_page((unsigned long)goldfish_pipe_dev.buffers);
-- 
2.19.0.605.g01d371f741-goog



[PATCH v3 03/15] platform: goldfish: pipe: Move the file-scope goldfish_pipe_dev variable into the driver state

2018-10-03 Thread rkir
From: Roman Kiryanov 

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 
---
Changes in v3:
 - No change.
Changes in v2:
 - Updated the commit message.

 drivers/platform/goldfish/goldfish_pipe.c | 66 +--
 1 file 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 {
  * waiting to be awoken.
  */
 struct goldfish_pipe_dev {
+   /* A magic number to check if this is an instance of this struct */
+   void *magic;
+
/*
 * Global device spinlock. Protects the following members:
 *  - pipes, pipes_capacity
@@ -215,8 +218,6 @@ struct goldfish_pipe_dev {
struct miscdevice miscdev;
 };
 
-static struct goldfish_pipe_dev goldfish_pipe_dev;
-
 static int goldfish_pipe_cmd_locked(struct goldfish_pipe *pipe,
enum PipeCmdCode cmd)
 {
@@ -611,6 +612,9 @@ static void goldfish_interrupt_task(unsigned long dev_addr)
}
 }
 
+static void goldfish_pipe_device_deinit(struct platform_device *pdev,
+   struct goldfish_pipe_dev *dev);
+
 /*
  * The general idea of the interrupt handling:
  *
@@ -631,7 +635,7 @@ static irqreturn_t goldfish_pipe_interrupt(int irq, void 
*dev_id)
unsigned long flags;
struct goldfish_pipe_dev *dev = dev_id;
 
-   if (dev != _pipe_dev)
+   if (dev->magic != _pipe_device_deinit)
return IRQ_NONE;
 
/* Request the signalled pipes from the device */
@@ -683,6 +687,14 @@ static int get_free_pipe_id_locked(struct 
goldfish_pipe_dev *dev)
return id;
 }
 
+/* A helper function to get the instance of goldfish_pipe_dev from file */
+static struct goldfish_pipe_dev *to_goldfish_pipe_dev(struct file *file)
+{
+   struct miscdevice *miscdev = file->private_data;
+
+   return container_of(miscdev, struct goldfish_pipe_dev, miscdev);
+}
+
 /**
  * goldfish_pipe_open - open a channel to the AVD
  * @inode: inode of device
@@ -696,7 +708,7 @@ static int get_free_pipe_id_locked(struct goldfish_pipe_dev 
*dev)
  */
 static int goldfish_pipe_open(struct inode *inode, struct file *file)
 {
-   struct goldfish_pipe_dev *dev = _pipe_dev;
+   struct goldfish_pipe_dev *dev = to_goldfish_pipe_dev(file);
unsigned long flags;
int id;
int status;
@@ -804,9 +816,9 @@ static void write_pa_addr(void *addr, void __iomem *portl, 
void __iomem *porth)
writel(lower_32_bits(paddr), portl);
 }
 
-static int goldfish_pipe_device_init(struct platform_device *pdev)
+static int goldfish_pipe_device_init(struct platform_device *pdev,
+struct goldfish_pipe_dev *dev)
 {
-   struct goldfish_pipe_dev *dev = _pipe_dev;
int err;
 
tasklet_init(>irq_tasklet, _interrupt_task,
@@ -861,26 +873,29 @@ static int goldfish_pipe_device_init(struct 
platform_device *pdev)
  dev->base + PIPE_REG_OPEN_BUFFER,
  dev->base + PIPE_REG_OPEN_BUFFER_HIGH);
 
+   platform_set_drvdata(pdev, dev);
return 0;
 }
 
-static void goldfish_pipe_device_deinit(struct platform_device *pdev)
+static void goldfish_pipe_device_deinit(struct platform_device *pdev,
+   struct goldfish_pipe_dev *dev)
 {
-   misc_deregister(_pipe_dev.miscdev);
-   tasklet_kill(_pipe_dev.irq_tasklet);
-   kfree(goldfish_pipe_dev.pipes);
-   free_page((unsigned long)goldfish_pipe_dev.buffers);
+   misc_deregister(>miscdev);
+   tasklet_kill(>irq_tasklet);
+   kfree(dev->pipes);
+   free_page((unsigned long)dev->buffers);
 }
 
 static int goldfish_pipe_probe(struct platform_device *pdev)
 {
-   int err;
struct resource *r;
-   struct goldfish_pipe_dev *dev = _pipe_dev;
+   struct goldfish_pipe_dev *dev;
 
-   /* not thread safe, but this should not happen */
-   WARN_ON(dev->base);
+   dev = devm_kzalloc(>dev, sizeof(*dev), GFP_KERNEL);
+   if (!dev)
+   return -ENOMEM;
 
+   dev->magic = _pipe_device_deinit;
spin_lock_init(>lock);
 
r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -895,10 +910,9 @@ static int goldfish_pipe_probe(struct platform_device 
*pdev)
}
 
r = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
-   if (!r) {
-   err = -EINVAL;
-   goto error;
-   }
+   if (!r)
+   return -EINVAL;
+
dev->irq = r->start;
 

[PATCH v3 01/15] platform: goldfish: pipe: Move the file-scope goldfish_interrupt_tasklet variable into the driver state

2018-10-03 Thread rkir
From: Roman Kiryanov 

This is a series of patches to move mutable 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 
---
Changes in v3:
 - No change.
Changes in v2:
 - Updated the commit message.

 drivers/platform/goldfish/goldfish_pipe.c | 24 +++
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index 56665e879e5a..ba9aede17d57 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -208,6 +208,9 @@ struct goldfish_pipe_dev {
int irq;
int version;
unsigned char __iomem *base;
+
+   /* an irq tasklet to run goldfish_interrupt_task */
+   struct tasklet_struct irq_tasklet;
 };
 
 static struct goldfish_pipe_dev goldfish_pipe_dev;
@@ -582,14 +585,14 @@ static struct goldfish_pipe *signalled_pipes_pop_front(
return pipe;
 }
 
-static void goldfish_interrupt_task(unsigned long unused)
+static void goldfish_interrupt_task(unsigned long dev_addr)
 {
/* Iterate over the signalled pipes and wake them one by one */
+   struct goldfish_pipe_dev *dev = (struct goldfish_pipe_dev *)dev_addr;
struct goldfish_pipe *pipe;
int wakes;
 
-   while ((pipe = signalled_pipes_pop_front(_pipe_dev, )) !=
-   NULL) {
+   while ((pipe = signalled_pipes_pop_front(dev, )) != NULL) {
if (wakes & PIPE_WAKE_CLOSED) {
pipe->flags = 1 << BIT_CLOSED_ON_HOST;
} else {
@@ -605,7 +608,6 @@ static void goldfish_interrupt_task(unsigned long unused)
wake_up_interruptible(>wake_queue);
}
 }
-static DECLARE_TASKLET(goldfish_interrupt_tasklet, goldfish_interrupt_task, 0);
 
 /*
  * The general idea of the interrupt handling:
@@ -648,7 +650,7 @@ static irqreturn_t goldfish_pipe_interrupt(int irq, void 
*dev_id)
 
spin_unlock_irqrestore(>lock, flags);
 
-   tasklet_schedule(_interrupt_tasklet);
+   tasklet_schedule(>irq_tasklet);
return IRQ_HANDLED;
 }
 
@@ -800,9 +802,14 @@ static void write_pa_addr(void *addr, void __iomem *portl, 
void __iomem *porth)
 static int goldfish_pipe_device_init(struct platform_device *pdev)
 {
struct goldfish_pipe_dev *dev = _pipe_dev;
-   int err = devm_request_irq(>dev, dev->irq,
-   goldfish_pipe_interrupt,
-   IRQF_SHARED, "goldfish_pipe", dev);
+   int err;
+
+   tasklet_init(>irq_tasklet, _interrupt_task,
+(unsigned long)dev);
+
+   err = devm_request_irq(>dev, dev->irq,
+  goldfish_pipe_interrupt,
+  IRQF_SHARED, "goldfish_pipe", dev);
if (err) {
dev_err(>dev, "unable to allocate IRQ for v2\n");
return err;
@@ -854,6 +861,7 @@ static int goldfish_pipe_device_init(struct platform_device 
*pdev)
 static void goldfish_pipe_device_deinit(struct platform_device *pdev)
 {
misc_deregister(_pipe_miscdev);
+   tasklet_kill(_pipe_dev.irq_tasklet);
kfree(goldfish_pipe_dev.pipes);
free_page((unsigned long)goldfish_pipe_dev.buffers);
 }
-- 
2.19.0.605.g01d371f741-goog



[PATCH v3 02/15] platform: goldfish: pipe: Move the file-scope goldfish_pipe_miscdev variable into the driver state

2018-10-03 Thread rkir
From: Roman Kiryanov 

This is a series of patches to move mutable 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 
---
Changes in v3:
 - No change.
Changes in v2:
 - Updated the commit message.

 drivers/platform/goldfish/goldfish_pipe.c | 20 +---
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index ba9aede17d57..8ca709b45e1f 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -211,6 +211,8 @@ struct goldfish_pipe_dev {
 
/* an irq tasklet to run goldfish_interrupt_task */
struct tasklet_struct irq_tasklet;
+
+   struct miscdevice miscdev;
 };
 
 static struct goldfish_pipe_dev goldfish_pipe_dev;
@@ -785,11 +787,14 @@ static const struct file_operations goldfish_pipe_fops = {
.release = goldfish_pipe_release,
 };
 
-static struct miscdevice goldfish_pipe_miscdev = {
-   .minor = MISC_DYNAMIC_MINOR,
-   .name = "goldfish_pipe",
-   .fops = _pipe_fops,
-};
+static void init_miscdevice(struct miscdevice *miscdev)
+{
+   memset(miscdev, 0, sizeof(*miscdev));
+
+   miscdev->minor = MISC_DYNAMIC_MINOR;
+   miscdev->name = "goldfish_pipe";
+   miscdev->fops = _pipe_fops;
+}
 
 static void write_pa_addr(void *addr, void __iomem *portl, void __iomem *porth)
 {
@@ -815,7 +820,8 @@ static int goldfish_pipe_device_init(struct platform_device 
*pdev)
return err;
}
 
-   err = misc_register(_pipe_miscdev);
+   init_miscdevice(>miscdev);
+   err = misc_register(>miscdev);
if (err) {
dev_err(>dev, "unable to register v2 device\n");
return err;
@@ -860,7 +866,7 @@ static int goldfish_pipe_device_init(struct platform_device 
*pdev)
 
 static void goldfish_pipe_device_deinit(struct platform_device *pdev)
 {
-   misc_deregister(_pipe_miscdev);
+   misc_deregister(_pipe_dev.miscdev);
tasklet_kill(_pipe_dev.irq_tasklet);
kfree(goldfish_pipe_dev.pipes);
free_page((unsigned long)goldfish_pipe_dev.buffers);
-- 
2.19.0.605.g01d371f741-goog



[PATCH v3 03/15] platform: goldfish: pipe: Move the file-scope goldfish_pipe_dev variable into the driver state

2018-10-03 Thread rkir
From: Roman Kiryanov 

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 
---
Changes in v3:
 - No change.
Changes in v2:
 - Updated the commit message.

 drivers/platform/goldfish/goldfish_pipe.c | 66 +--
 1 file 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 {
  * waiting to be awoken.
  */
 struct goldfish_pipe_dev {
+   /* A magic number to check if this is an instance of this struct */
+   void *magic;
+
/*
 * Global device spinlock. Protects the following members:
 *  - pipes, pipes_capacity
@@ -215,8 +218,6 @@ struct goldfish_pipe_dev {
struct miscdevice miscdev;
 };
 
-static struct goldfish_pipe_dev goldfish_pipe_dev;
-
 static int goldfish_pipe_cmd_locked(struct goldfish_pipe *pipe,
enum PipeCmdCode cmd)
 {
@@ -611,6 +612,9 @@ static void goldfish_interrupt_task(unsigned long dev_addr)
}
 }
 
+static void goldfish_pipe_device_deinit(struct platform_device *pdev,
+   struct goldfish_pipe_dev *dev);
+
 /*
  * The general idea of the interrupt handling:
  *
@@ -631,7 +635,7 @@ static irqreturn_t goldfish_pipe_interrupt(int irq, void 
*dev_id)
unsigned long flags;
struct goldfish_pipe_dev *dev = dev_id;
 
-   if (dev != _pipe_dev)
+   if (dev->magic != _pipe_device_deinit)
return IRQ_NONE;
 
/* Request the signalled pipes from the device */
@@ -683,6 +687,14 @@ static int get_free_pipe_id_locked(struct 
goldfish_pipe_dev *dev)
return id;
 }
 
+/* A helper function to get the instance of goldfish_pipe_dev from file */
+static struct goldfish_pipe_dev *to_goldfish_pipe_dev(struct file *file)
+{
+   struct miscdevice *miscdev = file->private_data;
+
+   return container_of(miscdev, struct goldfish_pipe_dev, miscdev);
+}
+
 /**
  * goldfish_pipe_open - open a channel to the AVD
  * @inode: inode of device
@@ -696,7 +708,7 @@ static int get_free_pipe_id_locked(struct goldfish_pipe_dev 
*dev)
  */
 static int goldfish_pipe_open(struct inode *inode, struct file *file)
 {
-   struct goldfish_pipe_dev *dev = _pipe_dev;
+   struct goldfish_pipe_dev *dev = to_goldfish_pipe_dev(file);
unsigned long flags;
int id;
int status;
@@ -804,9 +816,9 @@ static void write_pa_addr(void *addr, void __iomem *portl, 
void __iomem *porth)
writel(lower_32_bits(paddr), portl);
 }
 
-static int goldfish_pipe_device_init(struct platform_device *pdev)
+static int goldfish_pipe_device_init(struct platform_device *pdev,
+struct goldfish_pipe_dev *dev)
 {
-   struct goldfish_pipe_dev *dev = _pipe_dev;
int err;
 
tasklet_init(>irq_tasklet, _interrupt_task,
@@ -861,26 +873,29 @@ static int goldfish_pipe_device_init(struct 
platform_device *pdev)
  dev->base + PIPE_REG_OPEN_BUFFER,
  dev->base + PIPE_REG_OPEN_BUFFER_HIGH);
 
+   platform_set_drvdata(pdev, dev);
return 0;
 }
 
-static void goldfish_pipe_device_deinit(struct platform_device *pdev)
+static void goldfish_pipe_device_deinit(struct platform_device *pdev,
+   struct goldfish_pipe_dev *dev)
 {
-   misc_deregister(_pipe_dev.miscdev);
-   tasklet_kill(_pipe_dev.irq_tasklet);
-   kfree(goldfish_pipe_dev.pipes);
-   free_page((unsigned long)goldfish_pipe_dev.buffers);
+   misc_deregister(>miscdev);
+   tasklet_kill(>irq_tasklet);
+   kfree(dev->pipes);
+   free_page((unsigned long)dev->buffers);
 }
 
 static int goldfish_pipe_probe(struct platform_device *pdev)
 {
-   int err;
struct resource *r;
-   struct goldfish_pipe_dev *dev = _pipe_dev;
+   struct goldfish_pipe_dev *dev;
 
-   /* not thread safe, but this should not happen */
-   WARN_ON(dev->base);
+   dev = devm_kzalloc(>dev, sizeof(*dev), GFP_KERNEL);
+   if (!dev)
+   return -ENOMEM;
 
+   dev->magic = _pipe_device_deinit;
spin_lock_init(>lock);
 
r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -895,10 +910,9 @@ static int goldfish_pipe_probe(struct platform_device 
*pdev)
}
 
r = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
-   if (!r) {
-   err = -EINVAL;
-   goto error;
-   }
+   if (!r)
+   return -EINVAL;
+
dev->irq = r->start;
 

[PATCH v2 03/15] platform: goldfish: pipe: Move the file-scope goldfish_pipe_dev variable into the driver state

2018-10-02 Thread rkir
From: Roman Kiryanov 

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 
---
Changes in v2:
 - Updated the commit message.

 drivers/platform/goldfish/goldfish_pipe.c | 66 +--
 1 file 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 {
  * waiting to be awoken.
  */
 struct goldfish_pipe_dev {
+   /* A magic number to check if this is an instance of this struct */
+   void *magic;
+
/*
 * Global device spinlock. Protects the following members:
 *  - pipes, pipes_capacity
@@ -215,8 +218,6 @@ struct goldfish_pipe_dev {
struct miscdevice miscdev;
 };
 
-static struct goldfish_pipe_dev goldfish_pipe_dev;
-
 static int goldfish_pipe_cmd_locked(struct goldfish_pipe *pipe,
enum PipeCmdCode cmd)
 {
@@ -611,6 +612,9 @@ static void goldfish_interrupt_task(unsigned long dev_addr)
}
 }
 
+static void goldfish_pipe_device_deinit(struct platform_device *pdev,
+   struct goldfish_pipe_dev *dev);
+
 /*
  * The general idea of the interrupt handling:
  *
@@ -631,7 +635,7 @@ static irqreturn_t goldfish_pipe_interrupt(int irq, void 
*dev_id)
unsigned long flags;
struct goldfish_pipe_dev *dev = dev_id;
 
-   if (dev != _pipe_dev)
+   if (dev->magic != _pipe_device_deinit)
return IRQ_NONE;
 
/* Request the signalled pipes from the device */
@@ -683,6 +687,14 @@ static int get_free_pipe_id_locked(struct 
goldfish_pipe_dev *dev)
return id;
 }
 
+/* A helper function to get the instance of goldfish_pipe_dev from file */
+static struct goldfish_pipe_dev *to_goldfish_pipe_dev(struct file *file)
+{
+   struct miscdevice *miscdev = file->private_data;
+
+   return container_of(miscdev, struct goldfish_pipe_dev, miscdev);
+}
+
 /**
  * goldfish_pipe_open - open a channel to the AVD
  * @inode: inode of device
@@ -696,7 +708,7 @@ static int get_free_pipe_id_locked(struct goldfish_pipe_dev 
*dev)
  */
 static int goldfish_pipe_open(struct inode *inode, struct file *file)
 {
-   struct goldfish_pipe_dev *dev = _pipe_dev;
+   struct goldfish_pipe_dev *dev = to_goldfish_pipe_dev(file);
unsigned long flags;
int id;
int status;
@@ -804,9 +816,9 @@ static void write_pa_addr(void *addr, void __iomem *portl, 
void __iomem *porth)
writel(lower_32_bits(paddr), portl);
 }
 
-static int goldfish_pipe_device_init(struct platform_device *pdev)
+static int goldfish_pipe_device_init(struct platform_device *pdev,
+struct goldfish_pipe_dev *dev)
 {
-   struct goldfish_pipe_dev *dev = _pipe_dev;
int err;
 
tasklet_init(>irq_tasklet, _interrupt_task,
@@ -861,26 +873,29 @@ static int goldfish_pipe_device_init(struct 
platform_device *pdev)
  dev->base + PIPE_REG_OPEN_BUFFER,
  dev->base + PIPE_REG_OPEN_BUFFER_HIGH);
 
+   platform_set_drvdata(pdev, dev);
return 0;
 }
 
-static void goldfish_pipe_device_deinit(struct platform_device *pdev)
+static void goldfish_pipe_device_deinit(struct platform_device *pdev,
+   struct goldfish_pipe_dev *dev)
 {
-   misc_deregister(_pipe_dev.miscdev);
-   tasklet_kill(_pipe_dev.irq_tasklet);
-   kfree(goldfish_pipe_dev.pipes);
-   free_page((unsigned long)goldfish_pipe_dev.buffers);
+   misc_deregister(>miscdev);
+   tasklet_kill(>irq_tasklet);
+   kfree(dev->pipes);
+   free_page((unsigned long)dev->buffers);
 }
 
 static int goldfish_pipe_probe(struct platform_device *pdev)
 {
-   int err;
struct resource *r;
-   struct goldfish_pipe_dev *dev = _pipe_dev;
+   struct goldfish_pipe_dev *dev;
 
-   /* not thread safe, but this should not happen */
-   WARN_ON(dev->base);
+   dev = devm_kzalloc(>dev, sizeof(*dev), GFP_KERNEL);
+   if (!dev)
+   return -ENOMEM;
 
+   dev->magic = _pipe_device_deinit;
spin_lock_init(>lock);
 
r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -895,10 +910,9 @@ static int goldfish_pipe_probe(struct platform_device 
*pdev)
}
 
r = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
-   if (!r) {
-   err = -EINVAL;
-   goto error;
-   }
+   if (!r)
+   return -EINVAL;
+
dev->irq = r->start;
 
/*
@@ -913,20 +927,14 @@ 

[PATCH v2 03/15] platform: goldfish: pipe: Move the file-scope goldfish_pipe_dev variable into the driver state

2018-10-02 Thread rkir
From: Roman Kiryanov 

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 
---
Changes in v2:
 - Updated the commit message.

 drivers/platform/goldfish/goldfish_pipe.c | 66 +--
 1 file 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 {
  * waiting to be awoken.
  */
 struct goldfish_pipe_dev {
+   /* A magic number to check if this is an instance of this struct */
+   void *magic;
+
/*
 * Global device spinlock. Protects the following members:
 *  - pipes, pipes_capacity
@@ -215,8 +218,6 @@ struct goldfish_pipe_dev {
struct miscdevice miscdev;
 };
 
-static struct goldfish_pipe_dev goldfish_pipe_dev;
-
 static int goldfish_pipe_cmd_locked(struct goldfish_pipe *pipe,
enum PipeCmdCode cmd)
 {
@@ -611,6 +612,9 @@ static void goldfish_interrupt_task(unsigned long dev_addr)
}
 }
 
+static void goldfish_pipe_device_deinit(struct platform_device *pdev,
+   struct goldfish_pipe_dev *dev);
+
 /*
  * The general idea of the interrupt handling:
  *
@@ -631,7 +635,7 @@ static irqreturn_t goldfish_pipe_interrupt(int irq, void 
*dev_id)
unsigned long flags;
struct goldfish_pipe_dev *dev = dev_id;
 
-   if (dev != _pipe_dev)
+   if (dev->magic != _pipe_device_deinit)
return IRQ_NONE;
 
/* Request the signalled pipes from the device */
@@ -683,6 +687,14 @@ static int get_free_pipe_id_locked(struct 
goldfish_pipe_dev *dev)
return id;
 }
 
+/* A helper function to get the instance of goldfish_pipe_dev from file */
+static struct goldfish_pipe_dev *to_goldfish_pipe_dev(struct file *file)
+{
+   struct miscdevice *miscdev = file->private_data;
+
+   return container_of(miscdev, struct goldfish_pipe_dev, miscdev);
+}
+
 /**
  * goldfish_pipe_open - open a channel to the AVD
  * @inode: inode of device
@@ -696,7 +708,7 @@ static int get_free_pipe_id_locked(struct goldfish_pipe_dev 
*dev)
  */
 static int goldfish_pipe_open(struct inode *inode, struct file *file)
 {
-   struct goldfish_pipe_dev *dev = _pipe_dev;
+   struct goldfish_pipe_dev *dev = to_goldfish_pipe_dev(file);
unsigned long flags;
int id;
int status;
@@ -804,9 +816,9 @@ static void write_pa_addr(void *addr, void __iomem *portl, 
void __iomem *porth)
writel(lower_32_bits(paddr), portl);
 }
 
-static int goldfish_pipe_device_init(struct platform_device *pdev)
+static int goldfish_pipe_device_init(struct platform_device *pdev,
+struct goldfish_pipe_dev *dev)
 {
-   struct goldfish_pipe_dev *dev = _pipe_dev;
int err;
 
tasklet_init(>irq_tasklet, _interrupt_task,
@@ -861,26 +873,29 @@ static int goldfish_pipe_device_init(struct 
platform_device *pdev)
  dev->base + PIPE_REG_OPEN_BUFFER,
  dev->base + PIPE_REG_OPEN_BUFFER_HIGH);
 
+   platform_set_drvdata(pdev, dev);
return 0;
 }
 
-static void goldfish_pipe_device_deinit(struct platform_device *pdev)
+static void goldfish_pipe_device_deinit(struct platform_device *pdev,
+   struct goldfish_pipe_dev *dev)
 {
-   misc_deregister(_pipe_dev.miscdev);
-   tasklet_kill(_pipe_dev.irq_tasklet);
-   kfree(goldfish_pipe_dev.pipes);
-   free_page((unsigned long)goldfish_pipe_dev.buffers);
+   misc_deregister(>miscdev);
+   tasklet_kill(>irq_tasklet);
+   kfree(dev->pipes);
+   free_page((unsigned long)dev->buffers);
 }
 
 static int goldfish_pipe_probe(struct platform_device *pdev)
 {
-   int err;
struct resource *r;
-   struct goldfish_pipe_dev *dev = _pipe_dev;
+   struct goldfish_pipe_dev *dev;
 
-   /* not thread safe, but this should not happen */
-   WARN_ON(dev->base);
+   dev = devm_kzalloc(>dev, sizeof(*dev), GFP_KERNEL);
+   if (!dev)
+   return -ENOMEM;
 
+   dev->magic = _pipe_device_deinit;
spin_lock_init(>lock);
 
r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -895,10 +910,9 @@ static int goldfish_pipe_probe(struct platform_device 
*pdev)
}
 
r = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
-   if (!r) {
-   err = -EINVAL;
-   goto error;
-   }
+   if (!r)
+   return -EINVAL;
+
dev->irq = r->start;
 
/*
@@ -913,20 +927,14 @@ 

[PATCH v2 01/15] platform: goldfish: pipe: Move the file-scope goldfish_interrupt_tasklet variable into the driver state

2018-10-02 Thread rkir
From: Roman Kiryanov 

This is a series of patches to move mutable 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 
---
Changes in v2:
 - Updated the commit message.

 drivers/platform/goldfish/goldfish_pipe.c | 24 +++
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index 56665e879e5a..ba9aede17d57 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -208,6 +208,9 @@ struct goldfish_pipe_dev {
int irq;
int version;
unsigned char __iomem *base;
+
+   /* an irq tasklet to run goldfish_interrupt_task */
+   struct tasklet_struct irq_tasklet;
 };
 
 static struct goldfish_pipe_dev goldfish_pipe_dev;
@@ -582,14 +585,14 @@ static struct goldfish_pipe *signalled_pipes_pop_front(
return pipe;
 }
 
-static void goldfish_interrupt_task(unsigned long unused)
+static void goldfish_interrupt_task(unsigned long dev_addr)
 {
/* Iterate over the signalled pipes and wake them one by one */
+   struct goldfish_pipe_dev *dev = (struct goldfish_pipe_dev *)dev_addr;
struct goldfish_pipe *pipe;
int wakes;
 
-   while ((pipe = signalled_pipes_pop_front(_pipe_dev, )) !=
-   NULL) {
+   while ((pipe = signalled_pipes_pop_front(dev, )) != NULL) {
if (wakes & PIPE_WAKE_CLOSED) {
pipe->flags = 1 << BIT_CLOSED_ON_HOST;
} else {
@@ -605,7 +608,6 @@ static void goldfish_interrupt_task(unsigned long unused)
wake_up_interruptible(>wake_queue);
}
 }
-static DECLARE_TASKLET(goldfish_interrupt_tasklet, goldfish_interrupt_task, 0);
 
 /*
  * The general idea of the interrupt handling:
@@ -648,7 +650,7 @@ static irqreturn_t goldfish_pipe_interrupt(int irq, void 
*dev_id)
 
spin_unlock_irqrestore(>lock, flags);
 
-   tasklet_schedule(_interrupt_tasklet);
+   tasklet_schedule(>irq_tasklet);
return IRQ_HANDLED;
 }
 
@@ -800,9 +802,14 @@ static void write_pa_addr(void *addr, void __iomem *portl, 
void __iomem *porth)
 static int goldfish_pipe_device_init(struct platform_device *pdev)
 {
struct goldfish_pipe_dev *dev = _pipe_dev;
-   int err = devm_request_irq(>dev, dev->irq,
-   goldfish_pipe_interrupt,
-   IRQF_SHARED, "goldfish_pipe", dev);
+   int err;
+
+   tasklet_init(>irq_tasklet, _interrupt_task,
+(unsigned long)dev);
+
+   err = devm_request_irq(>dev, dev->irq,
+  goldfish_pipe_interrupt,
+  IRQF_SHARED, "goldfish_pipe", dev);
if (err) {
dev_err(>dev, "unable to allocate IRQ for v2\n");
return err;
@@ -854,6 +861,7 @@ static int goldfish_pipe_device_init(struct platform_device 
*pdev)
 static void goldfish_pipe_device_deinit(struct platform_device *pdev)
 {
misc_deregister(_pipe_miscdev);
+   tasklet_kill(_pipe_dev.irq_tasklet);
kfree(goldfish_pipe_dev.pipes);
free_page((unsigned long)goldfish_pipe_dev.buffers);
 }
-- 
2.19.0.605.g01d371f741-goog



[PATCH v2 02/15] platform: goldfish: pipe: Move the file-scope goldfish_pipe_miscdev variable into the driver state

2018-10-02 Thread rkir
From: Roman Kiryanov 

This is a series of patches to move mutable 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 
---
Changes in v2:
 - Updated the commit message.

 drivers/platform/goldfish/goldfish_pipe.c | 20 +---
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index ba9aede17d57..8ca709b45e1f 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -211,6 +211,8 @@ struct goldfish_pipe_dev {
 
/* an irq tasklet to run goldfish_interrupt_task */
struct tasklet_struct irq_tasklet;
+
+   struct miscdevice miscdev;
 };
 
 static struct goldfish_pipe_dev goldfish_pipe_dev;
@@ -785,11 +787,14 @@ static const struct file_operations goldfish_pipe_fops = {
.release = goldfish_pipe_release,
 };
 
-static struct miscdevice goldfish_pipe_miscdev = {
-   .minor = MISC_DYNAMIC_MINOR,
-   .name = "goldfish_pipe",
-   .fops = _pipe_fops,
-};
+static void init_miscdevice(struct miscdevice *miscdev)
+{
+   memset(miscdev, 0, sizeof(*miscdev));
+
+   miscdev->minor = MISC_DYNAMIC_MINOR;
+   miscdev->name = "goldfish_pipe";
+   miscdev->fops = _pipe_fops;
+}
 
 static void write_pa_addr(void *addr, void __iomem *portl, void __iomem *porth)
 {
@@ -815,7 +820,8 @@ static int goldfish_pipe_device_init(struct platform_device 
*pdev)
return err;
}
 
-   err = misc_register(_pipe_miscdev);
+   init_miscdevice(>miscdev);
+   err = misc_register(>miscdev);
if (err) {
dev_err(>dev, "unable to register v2 device\n");
return err;
@@ -860,7 +866,7 @@ static int goldfish_pipe_device_init(struct platform_device 
*pdev)
 
 static void goldfish_pipe_device_deinit(struct platform_device *pdev)
 {
-   misc_deregister(_pipe_miscdev);
+   misc_deregister(_pipe_dev.miscdev);
tasklet_kill(_pipe_dev.irq_tasklet);
kfree(goldfish_pipe_dev.pipes);
free_page((unsigned long)goldfish_pipe_dev.buffers);
-- 
2.19.0.605.g01d371f741-goog



[PATCH v2 01/15] platform: goldfish: pipe: Move the file-scope goldfish_interrupt_tasklet variable into the driver state

2018-10-02 Thread rkir
From: Roman Kiryanov 

This is a series of patches to move mutable 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 
---
Changes in v2:
 - Updated the commit message.

 drivers/platform/goldfish/goldfish_pipe.c | 24 +++
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index 56665e879e5a..ba9aede17d57 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -208,6 +208,9 @@ struct goldfish_pipe_dev {
int irq;
int version;
unsigned char __iomem *base;
+
+   /* an irq tasklet to run goldfish_interrupt_task */
+   struct tasklet_struct irq_tasklet;
 };
 
 static struct goldfish_pipe_dev goldfish_pipe_dev;
@@ -582,14 +585,14 @@ static struct goldfish_pipe *signalled_pipes_pop_front(
return pipe;
 }
 
-static void goldfish_interrupt_task(unsigned long unused)
+static void goldfish_interrupt_task(unsigned long dev_addr)
 {
/* Iterate over the signalled pipes and wake them one by one */
+   struct goldfish_pipe_dev *dev = (struct goldfish_pipe_dev *)dev_addr;
struct goldfish_pipe *pipe;
int wakes;
 
-   while ((pipe = signalled_pipes_pop_front(_pipe_dev, )) !=
-   NULL) {
+   while ((pipe = signalled_pipes_pop_front(dev, )) != NULL) {
if (wakes & PIPE_WAKE_CLOSED) {
pipe->flags = 1 << BIT_CLOSED_ON_HOST;
} else {
@@ -605,7 +608,6 @@ static void goldfish_interrupt_task(unsigned long unused)
wake_up_interruptible(>wake_queue);
}
 }
-static DECLARE_TASKLET(goldfish_interrupt_tasklet, goldfish_interrupt_task, 0);
 
 /*
  * The general idea of the interrupt handling:
@@ -648,7 +650,7 @@ static irqreturn_t goldfish_pipe_interrupt(int irq, void 
*dev_id)
 
spin_unlock_irqrestore(>lock, flags);
 
-   tasklet_schedule(_interrupt_tasklet);
+   tasklet_schedule(>irq_tasklet);
return IRQ_HANDLED;
 }
 
@@ -800,9 +802,14 @@ static void write_pa_addr(void *addr, void __iomem *portl, 
void __iomem *porth)
 static int goldfish_pipe_device_init(struct platform_device *pdev)
 {
struct goldfish_pipe_dev *dev = _pipe_dev;
-   int err = devm_request_irq(>dev, dev->irq,
-   goldfish_pipe_interrupt,
-   IRQF_SHARED, "goldfish_pipe", dev);
+   int err;
+
+   tasklet_init(>irq_tasklet, _interrupt_task,
+(unsigned long)dev);
+
+   err = devm_request_irq(>dev, dev->irq,
+  goldfish_pipe_interrupt,
+  IRQF_SHARED, "goldfish_pipe", dev);
if (err) {
dev_err(>dev, "unable to allocate IRQ for v2\n");
return err;
@@ -854,6 +861,7 @@ static int goldfish_pipe_device_init(struct platform_device 
*pdev)
 static void goldfish_pipe_device_deinit(struct platform_device *pdev)
 {
misc_deregister(_pipe_miscdev);
+   tasklet_kill(_pipe_dev.irq_tasklet);
kfree(goldfish_pipe_dev.pipes);
free_page((unsigned long)goldfish_pipe_dev.buffers);
 }
-- 
2.19.0.605.g01d371f741-goog



[PATCH v2 02/15] platform: goldfish: pipe: Move the file-scope goldfish_pipe_miscdev variable into the driver state

2018-10-02 Thread rkir
From: Roman Kiryanov 

This is a series of patches to move mutable 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 
---
Changes in v2:
 - Updated the commit message.

 drivers/platform/goldfish/goldfish_pipe.c | 20 +---
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index ba9aede17d57..8ca709b45e1f 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -211,6 +211,8 @@ struct goldfish_pipe_dev {
 
/* an irq tasklet to run goldfish_interrupt_task */
struct tasklet_struct irq_tasklet;
+
+   struct miscdevice miscdev;
 };
 
 static struct goldfish_pipe_dev goldfish_pipe_dev;
@@ -785,11 +787,14 @@ static const struct file_operations goldfish_pipe_fops = {
.release = goldfish_pipe_release,
 };
 
-static struct miscdevice goldfish_pipe_miscdev = {
-   .minor = MISC_DYNAMIC_MINOR,
-   .name = "goldfish_pipe",
-   .fops = _pipe_fops,
-};
+static void init_miscdevice(struct miscdevice *miscdev)
+{
+   memset(miscdev, 0, sizeof(*miscdev));
+
+   miscdev->minor = MISC_DYNAMIC_MINOR;
+   miscdev->name = "goldfish_pipe";
+   miscdev->fops = _pipe_fops;
+}
 
 static void write_pa_addr(void *addr, void __iomem *portl, void __iomem *porth)
 {
@@ -815,7 +820,8 @@ static int goldfish_pipe_device_init(struct platform_device 
*pdev)
return err;
}
 
-   err = misc_register(_pipe_miscdev);
+   init_miscdevice(>miscdev);
+   err = misc_register(>miscdev);
if (err) {
dev_err(>dev, "unable to register v2 device\n");
return err;
@@ -860,7 +866,7 @@ static int goldfish_pipe_device_init(struct platform_device 
*pdev)
 
 static void goldfish_pipe_device_deinit(struct platform_device *pdev)
 {
-   misc_deregister(_pipe_miscdev);
+   misc_deregister(_pipe_dev.miscdev);
tasklet_kill(_pipe_dev.irq_tasklet);
kfree(goldfish_pipe_dev.pipes);
free_page((unsigned long)goldfish_pipe_dev.buffers);
-- 
2.19.0.605.g01d371f741-goog



[PATCH 14/15] platform: goldfish: pipe: Rename PIPE_REG to PIPE_V2_REG

2018-10-02 Thread rkir
From: Roman Kiryanov 

PIPE_V1_REG will be introduced later for v1 support.

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/goldfish_pipe.c  |  4 ++--
 drivers/platform/goldfish/goldfish_pipe_qemu.h | 18 +-
 drivers/platform/goldfish/goldfish_pipe_v2.c   | 16 
 3 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index 7b0920e962eb..353f7ce94aa7 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -81,8 +81,8 @@ static int goldfish_pipe_probe(struct platform_device *pdev)
 *  reading device version back: this allows the host implementation to
 *  detect the old driver (if there was no version write before read).
 */
-   writel(PIPE_DRIVER_VERSION, base + PIPE_REG_VERSION);
-   version = readl(base + PIPE_REG_VERSION);
+   writel(PIPE_DRIVER_VERSION, base + PIPE_V2_REG_VERSION);
+   version = readl(base + PIPE_V2_REG_VERSION);
 
if (WARN_ON(version < PIPE_CURRENT_DEVICE_VERSION))
return -EINVAL;
diff --git a/drivers/platform/goldfish/goldfish_pipe_qemu.h 
b/drivers/platform/goldfish/goldfish_pipe_qemu.h
index b4d78c108afd..24b02710769f 100644
--- a/drivers/platform/goldfish/goldfish_pipe_qemu.h
+++ b/drivers/platform/goldfish/goldfish_pipe_qemu.h
@@ -62,19 +62,19 @@ enum PipeFlagsBits {
BIT_WAKE_ON_READ   = 2,  /* want to be woken on reads */
 };
 
-enum PipeRegs {
-   PIPE_REG_CMD = 0,
+enum PipeV2Regs {
+   PIPE_V2_REG_CMD = 0,
 
-   PIPE_REG_SIGNAL_BUFFER_HIGH = 4,
-   PIPE_REG_SIGNAL_BUFFER = 8,
-   PIPE_REG_SIGNAL_BUFFER_COUNT = 12,
+   PIPE_V2_REG_SIGNAL_BUFFER_HIGH = 4,
+   PIPE_V2_REG_SIGNAL_BUFFER = 8,
+   PIPE_V2_REG_SIGNAL_BUFFER_COUNT = 12,
 
-   PIPE_REG_OPEN_BUFFER_HIGH = 20,
-   PIPE_REG_OPEN_BUFFER = 24,
+   PIPE_V2_REG_OPEN_BUFFER_HIGH = 20,
+   PIPE_V2_REG_OPEN_BUFFER = 24,
 
-   PIPE_REG_VERSION = 36,
+   PIPE_V2_REG_VERSION = 36,
 
-   PIPE_REG_GET_SIGNALLED = 48,
+   PIPE_V2_REG_GET_SIGNALLED = 48,
 };
 
 enum PipeCmdCode {
diff --git a/drivers/platform/goldfish/goldfish_pipe_v2.c 
b/drivers/platform/goldfish/goldfish_pipe_v2.c
index 0e2a62322477..c99317548128 100644
--- a/drivers/platform/goldfish/goldfish_pipe_v2.c
+++ b/drivers/platform/goldfish/goldfish_pipe_v2.c
@@ -197,7 +197,7 @@ static int goldfish_pipe_cmd_locked(struct goldfish_pipe 
*pipe,
pipe->command_buffer->cmd = cmd;
/* failure by default */
pipe->command_buffer->status = PIPE_ERROR_INVAL;
-   writel(pipe->id, pipe->dev->base + PIPE_REG_CMD);
+   writel(pipe->id, pipe->dev->base + PIPE_V2_REG_CMD);
return pipe->command_buffer->status;
 }
 
@@ -214,7 +214,7 @@ static int goldfish_pipe_cmd(struct goldfish_pipe *pipe, 
enum PipeCmdCode cmd)
 
 /*
  * This function converts an error code returned by the emulator through
- * the PIPE_REG_STATUS i/o register into a valid negative errno value.
+ * the PIPE_V2_REG_STATUS i/o register into a valid negative errno value.
  */
 static int goldfish_pipe_error_convert(int status)
 {
@@ -611,7 +611,7 @@ static irqreturn_t goldfish_pipe_interrupt(int irq, void 
*dev_id)
/* Request the signalled pipes from the device */
spin_lock_irqsave(>lock, flags);
 
-   count = readl(dev->base + PIPE_REG_GET_SIGNALLED);
+   count = readl(dev->base + PIPE_V2_REG_GET_SIGNALLED);
if (count == 0) {
spin_unlock_irqrestore(>lock, flags);
return IRQ_NONE;
@@ -847,15 +847,15 @@ int goldfish_pipe_device_v2_init(struct platform_device 
*pdev,
 
/* Send the buffer addresses to the host */
write_pa_addr(>buffers->signalled_pipe_buffers,
- dev->base + PIPE_REG_SIGNAL_BUFFER,
- dev->base + PIPE_REG_SIGNAL_BUFFER_HIGH);
+ dev->base + PIPE_V2_REG_SIGNAL_BUFFER,
+ dev->base + PIPE_V2_REG_SIGNAL_BUFFER_HIGH);
 
writel(MAX_SIGNALLED_PIPES,
-  dev->base + PIPE_REG_SIGNAL_BUFFER_COUNT);
+  dev->base + PIPE_V2_REG_SIGNAL_BUFFER_COUNT);
 
write_pa_addr(>buffers->open_command_params,
- dev->base + PIPE_REG_OPEN_BUFFER,
- dev->base + PIPE_REG_OPEN_BUFFER_HIGH);
+ dev->base + PIPE_V2_REG_OPEN_BUFFER,
+ dev->base + PIPE_V2_REG_OPEN_BUFFER_HIGH);
 
platform_set_drvdata(pdev, dev);
return 0;
-- 
2.19.0.605.g01d371f741-goog



[PATCH 14/15] platform: goldfish: pipe: Rename PIPE_REG to PIPE_V2_REG

2018-10-02 Thread rkir
From: Roman Kiryanov 

PIPE_V1_REG will be introduced later for v1 support.

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/goldfish_pipe.c  |  4 ++--
 drivers/platform/goldfish/goldfish_pipe_qemu.h | 18 +-
 drivers/platform/goldfish/goldfish_pipe_v2.c   | 16 
 3 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index 7b0920e962eb..353f7ce94aa7 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -81,8 +81,8 @@ static int goldfish_pipe_probe(struct platform_device *pdev)
 *  reading device version back: this allows the host implementation to
 *  detect the old driver (if there was no version write before read).
 */
-   writel(PIPE_DRIVER_VERSION, base + PIPE_REG_VERSION);
-   version = readl(base + PIPE_REG_VERSION);
+   writel(PIPE_DRIVER_VERSION, base + PIPE_V2_REG_VERSION);
+   version = readl(base + PIPE_V2_REG_VERSION);
 
if (WARN_ON(version < PIPE_CURRENT_DEVICE_VERSION))
return -EINVAL;
diff --git a/drivers/platform/goldfish/goldfish_pipe_qemu.h 
b/drivers/platform/goldfish/goldfish_pipe_qemu.h
index b4d78c108afd..24b02710769f 100644
--- a/drivers/platform/goldfish/goldfish_pipe_qemu.h
+++ b/drivers/platform/goldfish/goldfish_pipe_qemu.h
@@ -62,19 +62,19 @@ enum PipeFlagsBits {
BIT_WAKE_ON_READ   = 2,  /* want to be woken on reads */
 };
 
-enum PipeRegs {
-   PIPE_REG_CMD = 0,
+enum PipeV2Regs {
+   PIPE_V2_REG_CMD = 0,
 
-   PIPE_REG_SIGNAL_BUFFER_HIGH = 4,
-   PIPE_REG_SIGNAL_BUFFER = 8,
-   PIPE_REG_SIGNAL_BUFFER_COUNT = 12,
+   PIPE_V2_REG_SIGNAL_BUFFER_HIGH = 4,
+   PIPE_V2_REG_SIGNAL_BUFFER = 8,
+   PIPE_V2_REG_SIGNAL_BUFFER_COUNT = 12,
 
-   PIPE_REG_OPEN_BUFFER_HIGH = 20,
-   PIPE_REG_OPEN_BUFFER = 24,
+   PIPE_V2_REG_OPEN_BUFFER_HIGH = 20,
+   PIPE_V2_REG_OPEN_BUFFER = 24,
 
-   PIPE_REG_VERSION = 36,
+   PIPE_V2_REG_VERSION = 36,
 
-   PIPE_REG_GET_SIGNALLED = 48,
+   PIPE_V2_REG_GET_SIGNALLED = 48,
 };
 
 enum PipeCmdCode {
diff --git a/drivers/platform/goldfish/goldfish_pipe_v2.c 
b/drivers/platform/goldfish/goldfish_pipe_v2.c
index 0e2a62322477..c99317548128 100644
--- a/drivers/platform/goldfish/goldfish_pipe_v2.c
+++ b/drivers/platform/goldfish/goldfish_pipe_v2.c
@@ -197,7 +197,7 @@ static int goldfish_pipe_cmd_locked(struct goldfish_pipe 
*pipe,
pipe->command_buffer->cmd = cmd;
/* failure by default */
pipe->command_buffer->status = PIPE_ERROR_INVAL;
-   writel(pipe->id, pipe->dev->base + PIPE_REG_CMD);
+   writel(pipe->id, pipe->dev->base + PIPE_V2_REG_CMD);
return pipe->command_buffer->status;
 }
 
@@ -214,7 +214,7 @@ static int goldfish_pipe_cmd(struct goldfish_pipe *pipe, 
enum PipeCmdCode cmd)
 
 /*
  * This function converts an error code returned by the emulator through
- * the PIPE_REG_STATUS i/o register into a valid negative errno value.
+ * the PIPE_V2_REG_STATUS i/o register into a valid negative errno value.
  */
 static int goldfish_pipe_error_convert(int status)
 {
@@ -611,7 +611,7 @@ static irqreturn_t goldfish_pipe_interrupt(int irq, void 
*dev_id)
/* Request the signalled pipes from the device */
spin_lock_irqsave(>lock, flags);
 
-   count = readl(dev->base + PIPE_REG_GET_SIGNALLED);
+   count = readl(dev->base + PIPE_V2_REG_GET_SIGNALLED);
if (count == 0) {
spin_unlock_irqrestore(>lock, flags);
return IRQ_NONE;
@@ -847,15 +847,15 @@ int goldfish_pipe_device_v2_init(struct platform_device 
*pdev,
 
/* Send the buffer addresses to the host */
write_pa_addr(>buffers->signalled_pipe_buffers,
- dev->base + PIPE_REG_SIGNAL_BUFFER,
- dev->base + PIPE_REG_SIGNAL_BUFFER_HIGH);
+ dev->base + PIPE_V2_REG_SIGNAL_BUFFER,
+ dev->base + PIPE_V2_REG_SIGNAL_BUFFER_HIGH);
 
writel(MAX_SIGNALLED_PIPES,
-  dev->base + PIPE_REG_SIGNAL_BUFFER_COUNT);
+  dev->base + PIPE_V2_REG_SIGNAL_BUFFER_COUNT);
 
write_pa_addr(>buffers->open_command_params,
- dev->base + PIPE_REG_OPEN_BUFFER,
- dev->base + PIPE_REG_OPEN_BUFFER_HIGH);
+ dev->base + PIPE_V2_REG_OPEN_BUFFER,
+ dev->base + PIPE_V2_REG_OPEN_BUFFER_HIGH);
 
platform_set_drvdata(pdev, dev);
return 0;
-- 
2.19.0.605.g01d371f741-goog



[PATCH 15/15] platform: goldfish: pipe: Add the goldfish_pipe_v1 driver

2018-10-02 Thread rkir
From: Roman Kiryanov 

This is the v1 goldfish pipe driver.

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/Makefile|   2 +-
 drivers/platform/goldfish/goldfish_pipe.c |   9 +-
 .../platform/goldfish/goldfish_pipe_qemu.h|  27 +
 drivers/platform/goldfish/goldfish_pipe_v1.c  | 632 ++
 drivers/platform/goldfish/goldfish_pipe_v1.h  |  24 +
 5 files changed, 689 insertions(+), 5 deletions(-)
 create mode 100644 drivers/platform/goldfish/goldfish_pipe_v1.c
 create mode 100644 drivers/platform/goldfish/goldfish_pipe_v1.h

diff --git a/drivers/platform/goldfish/Makefile 
b/drivers/platform/goldfish/Makefile
index 016769e003d8..3fb7427b9dd8 100644
--- a/drivers/platform/goldfish/Makefile
+++ b/drivers/platform/goldfish/Makefile
@@ -2,4 +2,4 @@
 # Makefile for Goldfish platform specific drivers
 #
 obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe_all.o
-goldfish_pipe_all-objs := goldfish_pipe.o goldfish_pipe_v2.o
+goldfish_pipe_all-objs := goldfish_pipe.o goldfish_pipe_v1.o goldfish_pipe_v2.o
diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index 353f7ce94aa7..05a67895cc06 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -39,6 +39,7 @@
 #include 
 #include "goldfish_pipe_qemu.h"
 #include "goldfish_pipe.h"
+#include "goldfish_pipe_v1.h"
 #include "goldfish_pipe_v2.h"
 
 /*
@@ -84,10 +85,10 @@ static int goldfish_pipe_probe(struct platform_device *pdev)
writel(PIPE_DRIVER_VERSION, base + PIPE_V2_REG_VERSION);
version = readl(base + PIPE_V2_REG_VERSION);
 
-   if (WARN_ON(version < PIPE_CURRENT_DEVICE_VERSION))
-   return -EINVAL;
-
-   return goldfish_pipe_device_v2_init(pdev, base, irq);
+   if (version < PIPE_CURRENT_DEVICE_VERSION)
+   return goldfish_pipe_device_v1_init(pdev, base, irq);
+   else
+   return goldfish_pipe_device_v2_init(pdev, base, irq);
 }
 
 static int goldfish_pipe_remove(struct platform_device *pdev)
diff --git a/drivers/platform/goldfish/goldfish_pipe_qemu.h 
b/drivers/platform/goldfish/goldfish_pipe_qemu.h
index 24b02710769f..9a8275f3583d 100644
--- a/drivers/platform/goldfish/goldfish_pipe_qemu.h
+++ b/drivers/platform/goldfish/goldfish_pipe_qemu.h
@@ -62,6 +62,33 @@ enum PipeFlagsBits {
BIT_WAKE_ON_READ   = 2,  /* want to be woken on reads */
 };
 
+enum PipeV1Regs {
+   /* write: value = command */
+   PIPE_V1_REG_COMMAND = 0x00,
+   /* read */
+   PIPE_V1_REG_STATUS  = 0x04,
+   /* read/write: channel id */
+   PIPE_V1_REG_CHANNEL = 0x08,
+   /* read/write: channel id */
+   PIPE_V1_REG_CHANNEL_HIGH= 0x30,
+   /* read/write: buffer size */
+   PIPE_V1_REG_SIZE= 0x0C,
+   /* write: physical address */
+   PIPE_V1_REG_ADDRESS = 0x10,
+   /* write: physical address */
+   PIPE_V1_REG_ADDRESS_HIGH= 0x34,
+   /* read: wake flags */
+   PIPE_V1_REG_WAKES   = 0x14,
+   /* read/write: batch data address */
+   PIPE_V1_REG_PARAMS_ADDR_LOW = 0x18,
+   /* read/write: batch data address */
+   PIPE_V1_REG_PARAMS_ADDR_HIGH= 0x1C,
+   /* write: batch access */
+   PIPE_V1_REG_ACCESS_PARAMS   = 0x20,
+   /* read: device version */
+   PIPE_V1_REG_VERSION = 0x24,
+};
+
 enum PipeV2Regs {
PIPE_V2_REG_CMD = 0,
 
diff --git a/drivers/platform/goldfish/goldfish_pipe_v1.c 
b/drivers/platform/goldfish/goldfish_pipe_v1.c
new file mode 100644
index ..6e603204dd62
--- /dev/null
+++ b/drivers/platform/goldfish/goldfish_pipe_v1.c
@@ -0,0 +1,632 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2011 Google, Inc.
+ * Copyright (C) 2012 Intel, Inc.
+ * Copyright (C) 2013 Intel, Inc.
+ * Copyright (C) 2014 Linaro Limited
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+/* This source file contains the implementation of the legacy version of
+ * a goldfish pipe device driver. See goldfish_pipe_v2.c for the current
+ * version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "goldfish_pipe_qemu.h"
+#include "goldfish_pipe.h"
+
+#define MAX_PAGES_TO_GRAB 32
+
+/* A value that will not be set by qemu emulator */
+#define INITIAL_BATCH_RESULT (0xdeadbeaf)
+
+struct goldfish_pipe_dev;
+
+/* This data type 

[PATCH 15/15] platform: goldfish: pipe: Add the goldfish_pipe_v1 driver

2018-10-02 Thread rkir
From: Roman Kiryanov 

This is the v1 goldfish pipe driver.

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/Makefile|   2 +-
 drivers/platform/goldfish/goldfish_pipe.c |   9 +-
 .../platform/goldfish/goldfish_pipe_qemu.h|  27 +
 drivers/platform/goldfish/goldfish_pipe_v1.c  | 632 ++
 drivers/platform/goldfish/goldfish_pipe_v1.h  |  24 +
 5 files changed, 689 insertions(+), 5 deletions(-)
 create mode 100644 drivers/platform/goldfish/goldfish_pipe_v1.c
 create mode 100644 drivers/platform/goldfish/goldfish_pipe_v1.h

diff --git a/drivers/platform/goldfish/Makefile 
b/drivers/platform/goldfish/Makefile
index 016769e003d8..3fb7427b9dd8 100644
--- a/drivers/platform/goldfish/Makefile
+++ b/drivers/platform/goldfish/Makefile
@@ -2,4 +2,4 @@
 # Makefile for Goldfish platform specific drivers
 #
 obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe_all.o
-goldfish_pipe_all-objs := goldfish_pipe.o goldfish_pipe_v2.o
+goldfish_pipe_all-objs := goldfish_pipe.o goldfish_pipe_v1.o goldfish_pipe_v2.o
diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index 353f7ce94aa7..05a67895cc06 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -39,6 +39,7 @@
 #include 
 #include "goldfish_pipe_qemu.h"
 #include "goldfish_pipe.h"
+#include "goldfish_pipe_v1.h"
 #include "goldfish_pipe_v2.h"
 
 /*
@@ -84,10 +85,10 @@ static int goldfish_pipe_probe(struct platform_device *pdev)
writel(PIPE_DRIVER_VERSION, base + PIPE_V2_REG_VERSION);
version = readl(base + PIPE_V2_REG_VERSION);
 
-   if (WARN_ON(version < PIPE_CURRENT_DEVICE_VERSION))
-   return -EINVAL;
-
-   return goldfish_pipe_device_v2_init(pdev, base, irq);
+   if (version < PIPE_CURRENT_DEVICE_VERSION)
+   return goldfish_pipe_device_v1_init(pdev, base, irq);
+   else
+   return goldfish_pipe_device_v2_init(pdev, base, irq);
 }
 
 static int goldfish_pipe_remove(struct platform_device *pdev)
diff --git a/drivers/platform/goldfish/goldfish_pipe_qemu.h 
b/drivers/platform/goldfish/goldfish_pipe_qemu.h
index 24b02710769f..9a8275f3583d 100644
--- a/drivers/platform/goldfish/goldfish_pipe_qemu.h
+++ b/drivers/platform/goldfish/goldfish_pipe_qemu.h
@@ -62,6 +62,33 @@ enum PipeFlagsBits {
BIT_WAKE_ON_READ   = 2,  /* want to be woken on reads */
 };
 
+enum PipeV1Regs {
+   /* write: value = command */
+   PIPE_V1_REG_COMMAND = 0x00,
+   /* read */
+   PIPE_V1_REG_STATUS  = 0x04,
+   /* read/write: channel id */
+   PIPE_V1_REG_CHANNEL = 0x08,
+   /* read/write: channel id */
+   PIPE_V1_REG_CHANNEL_HIGH= 0x30,
+   /* read/write: buffer size */
+   PIPE_V1_REG_SIZE= 0x0C,
+   /* write: physical address */
+   PIPE_V1_REG_ADDRESS = 0x10,
+   /* write: physical address */
+   PIPE_V1_REG_ADDRESS_HIGH= 0x34,
+   /* read: wake flags */
+   PIPE_V1_REG_WAKES   = 0x14,
+   /* read/write: batch data address */
+   PIPE_V1_REG_PARAMS_ADDR_LOW = 0x18,
+   /* read/write: batch data address */
+   PIPE_V1_REG_PARAMS_ADDR_HIGH= 0x1C,
+   /* write: batch access */
+   PIPE_V1_REG_ACCESS_PARAMS   = 0x20,
+   /* read: device version */
+   PIPE_V1_REG_VERSION = 0x24,
+};
+
 enum PipeV2Regs {
PIPE_V2_REG_CMD = 0,
 
diff --git a/drivers/platform/goldfish/goldfish_pipe_v1.c 
b/drivers/platform/goldfish/goldfish_pipe_v1.c
new file mode 100644
index ..6e603204dd62
--- /dev/null
+++ b/drivers/platform/goldfish/goldfish_pipe_v1.c
@@ -0,0 +1,632 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2011 Google, Inc.
+ * Copyright (C) 2012 Intel, Inc.
+ * Copyright (C) 2013 Intel, Inc.
+ * Copyright (C) 2014 Linaro Limited
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+/* This source file contains the implementation of the legacy version of
+ * a goldfish pipe device driver. See goldfish_pipe_v2.c for the current
+ * version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "goldfish_pipe_qemu.h"
+#include "goldfish_pipe.h"
+
+#define MAX_PAGES_TO_GRAB 32
+
+/* A value that will not be set by qemu emulator */
+#define INITIAL_BATCH_RESULT (0xdeadbeaf)
+
+struct goldfish_pipe_dev;
+
+/* This data type 

[PATCH 13/15] platform: goldfish: pipe: Add a dedicated constant for the device name

2018-10-02 Thread rkir
From: Roman Kiryanov 

Create a constant to refer to the device name instead if several copies
of a string.

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/goldfish_pipe.h| 2 ++
 drivers/platform/goldfish/goldfish_pipe_v2.c | 4 ++--
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.h 
b/drivers/platform/goldfish/goldfish_pipe.h
index ee0b54bcb165..0fa6ecb32c6d 100644
--- a/drivers/platform/goldfish/goldfish_pipe.h
+++ b/drivers/platform/goldfish/goldfish_pipe.h
@@ -2,6 +2,8 @@
 #ifndef GOLDFISH_PIPE_H
 #define GOLDFISH_PIPE_H
 
+#define DEVICE_NAME "goldfish_pipe"
+
 struct goldfish_pipe_dev_base {
/* the destructor, the pointer is set in init */
int (*deinit)(void *pipe_dev, struct platform_device *pdev);
diff --git a/drivers/platform/goldfish/goldfish_pipe_v2.c 
b/drivers/platform/goldfish/goldfish_pipe_v2.c
index 9857ce07d0e6..0e2a62322477 100644
--- a/drivers/platform/goldfish/goldfish_pipe_v2.c
+++ b/drivers/platform/goldfish/goldfish_pipe_v2.c
@@ -775,7 +775,7 @@ static void init_miscdevice(struct miscdevice *miscdev)
memset(miscdev, 0, sizeof(*miscdev));
 
miscdev->minor = MISC_DYNAMIC_MINOR;
-   miscdev->name = "goldfish_pipe";
+   miscdev->name = DEVICE_NAME;
miscdev->fops = _pipe_fops;
 }
 
@@ -806,7 +806,7 @@ int goldfish_pipe_device_v2_init(struct platform_device 
*pdev,
 
err = devm_request_irq(>dev, irq,
   goldfish_pipe_interrupt,
-  IRQF_SHARED, "goldfish_pipe", dev);
+  IRQF_SHARED, DEVICE_NAME, dev);
if (err) {
dev_err(>dev, "unable to allocate IRQ for v2\n");
return err;
-- 
2.19.0.605.g01d371f741-goog



[PATCH 10/15] platform: goldfish: pipe: Remove the license boilerplate

2018-10-02 Thread rkir
From: Roman Kiryanov 

Not required with the SPDX-License-Identifier header.

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/goldfish_pipe_v2.c | 17 -
 1 file changed, 17 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe_v2.c 
b/drivers/platform/goldfish/goldfish_pipe_v2.c
index a1fbbf49cc3f..ff5d88e7959a 100644
--- a/drivers/platform/goldfish/goldfish_pipe_v2.c
+++ b/drivers/platform/goldfish/goldfish_pipe_v2.c
@@ -1,21 +1,4 @@
 // SPDX-License-Identifier: GPL-2.0
-/*
- * Copyright (C) 2012 Intel, Inc.
- * Copyright (C) 2013 Intel, Inc.
- * Copyright (C) 2014 Linaro Limited
- * Copyright (C) 2011-2016 Google, Inc.
- *
- * This software is licensed under the terms of the GNU General Public
- * License version 2, as published by the Free Software Foundation, and
- * may be copied, distributed, and modified under those terms.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- */
-
 /* This source file contains the implementation of a special device driver
  * that intends to provide a *very* fast communication channel between the
  * guest system and the QEMU emulator.
-- 
2.19.0.605.g01d371f741-goog



[PATCH 13/15] platform: goldfish: pipe: Add a dedicated constant for the device name

2018-10-02 Thread rkir
From: Roman Kiryanov 

Create a constant to refer to the device name instead if several copies
of a string.

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/goldfish_pipe.h| 2 ++
 drivers/platform/goldfish/goldfish_pipe_v2.c | 4 ++--
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.h 
b/drivers/platform/goldfish/goldfish_pipe.h
index ee0b54bcb165..0fa6ecb32c6d 100644
--- a/drivers/platform/goldfish/goldfish_pipe.h
+++ b/drivers/platform/goldfish/goldfish_pipe.h
@@ -2,6 +2,8 @@
 #ifndef GOLDFISH_PIPE_H
 #define GOLDFISH_PIPE_H
 
+#define DEVICE_NAME "goldfish_pipe"
+
 struct goldfish_pipe_dev_base {
/* the destructor, the pointer is set in init */
int (*deinit)(void *pipe_dev, struct platform_device *pdev);
diff --git a/drivers/platform/goldfish/goldfish_pipe_v2.c 
b/drivers/platform/goldfish/goldfish_pipe_v2.c
index 9857ce07d0e6..0e2a62322477 100644
--- a/drivers/platform/goldfish/goldfish_pipe_v2.c
+++ b/drivers/platform/goldfish/goldfish_pipe_v2.c
@@ -775,7 +775,7 @@ static void init_miscdevice(struct miscdevice *miscdev)
memset(miscdev, 0, sizeof(*miscdev));
 
miscdev->minor = MISC_DYNAMIC_MINOR;
-   miscdev->name = "goldfish_pipe";
+   miscdev->name = DEVICE_NAME;
miscdev->fops = _pipe_fops;
 }
 
@@ -806,7 +806,7 @@ int goldfish_pipe_device_v2_init(struct platform_device 
*pdev,
 
err = devm_request_irq(>dev, irq,
   goldfish_pipe_interrupt,
-  IRQF_SHARED, "goldfish_pipe", dev);
+  IRQF_SHARED, DEVICE_NAME, dev);
if (err) {
dev_err(>dev, "unable to allocate IRQ for v2\n");
return err;
-- 
2.19.0.605.g01d371f741-goog



[PATCH 10/15] platform: goldfish: pipe: Remove the license boilerplate

2018-10-02 Thread rkir
From: Roman Kiryanov 

Not required with the SPDX-License-Identifier header.

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/goldfish_pipe_v2.c | 17 -
 1 file changed, 17 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe_v2.c 
b/drivers/platform/goldfish/goldfish_pipe_v2.c
index a1fbbf49cc3f..ff5d88e7959a 100644
--- a/drivers/platform/goldfish/goldfish_pipe_v2.c
+++ b/drivers/platform/goldfish/goldfish_pipe_v2.c
@@ -1,21 +1,4 @@
 // SPDX-License-Identifier: GPL-2.0
-/*
- * Copyright (C) 2012 Intel, Inc.
- * Copyright (C) 2013 Intel, Inc.
- * Copyright (C) 2014 Linaro Limited
- * Copyright (C) 2011-2016 Google, Inc.
- *
- * This software is licensed under the terms of the GNU General Public
- * License version 2, as published by the Free Software Foundation, and
- * may be copied, distributed, and modified under those terms.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- */
-
 /* This source file contains the implementation of a special device driver
  * that intends to provide a *very* fast communication channel between the
  * guest system and the QEMU emulator.
-- 
2.19.0.605.g01d371f741-goog



[PATCH 09/15] platform: goldfish: pipe: Move goldfish_pipe to goldfish_pipe_v2

2018-10-02 Thread rkir
From: Roman Kiryanov 

This is the v2 driver. v1 will be added later.

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/Makefile  | 2 +-
 .../platform/goldfish/{goldfish_pipe.c => goldfish_pipe_v2.c}   | 0
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename drivers/platform/goldfish/{goldfish_pipe.c => goldfish_pipe_v2.c} (100%)

diff --git a/drivers/platform/goldfish/Makefile 
b/drivers/platform/goldfish/Makefile
index e0c202df9674..81f899a987a2 100644
--- a/drivers/platform/goldfish/Makefile
+++ b/drivers/platform/goldfish/Makefile
@@ -1,4 +1,4 @@
 #
 # Makefile for Goldfish platform specific drivers
 #
-obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe.o
+obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe_v2.o
diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe_v2.c
similarity index 100%
rename from drivers/platform/goldfish/goldfish_pipe.c
rename to drivers/platform/goldfish/goldfish_pipe_v2.c
-- 
2.19.0.605.g01d371f741-goog



[PATCH 01/15] platform: goldfish: pipe: Remove the goldfish_interrupt_tasklet global variable

2018-10-02 Thread rkir
From: Roman Kiryanov 

This is a series of patches to remove mutable global variables
to introduce another version of the pipe driver for the older
host interface. I don't want to have two driver states where only
one is used.

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/goldfish_pipe.c | 24 +++
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index 56665e879e5a..ba9aede17d57 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -208,6 +208,9 @@ struct goldfish_pipe_dev {
int irq;
int version;
unsigned char __iomem *base;
+
+   /* an irq tasklet to run goldfish_interrupt_task */
+   struct tasklet_struct irq_tasklet;
 };
 
 static struct goldfish_pipe_dev goldfish_pipe_dev;
@@ -582,14 +585,14 @@ static struct goldfish_pipe *signalled_pipes_pop_front(
return pipe;
 }
 
-static void goldfish_interrupt_task(unsigned long unused)
+static void goldfish_interrupt_task(unsigned long dev_addr)
 {
/* Iterate over the signalled pipes and wake them one by one */
+   struct goldfish_pipe_dev *dev = (struct goldfish_pipe_dev *)dev_addr;
struct goldfish_pipe *pipe;
int wakes;
 
-   while ((pipe = signalled_pipes_pop_front(_pipe_dev, )) !=
-   NULL) {
+   while ((pipe = signalled_pipes_pop_front(dev, )) != NULL) {
if (wakes & PIPE_WAKE_CLOSED) {
pipe->flags = 1 << BIT_CLOSED_ON_HOST;
} else {
@@ -605,7 +608,6 @@ static void goldfish_interrupt_task(unsigned long unused)
wake_up_interruptible(>wake_queue);
}
 }
-static DECLARE_TASKLET(goldfish_interrupt_tasklet, goldfish_interrupt_task, 0);
 
 /*
  * The general idea of the interrupt handling:
@@ -648,7 +650,7 @@ static irqreturn_t goldfish_pipe_interrupt(int irq, void 
*dev_id)
 
spin_unlock_irqrestore(>lock, flags);
 
-   tasklet_schedule(_interrupt_tasklet);
+   tasklet_schedule(>irq_tasklet);
return IRQ_HANDLED;
 }
 
@@ -800,9 +802,14 @@ static void write_pa_addr(void *addr, void __iomem *portl, 
void __iomem *porth)
 static int goldfish_pipe_device_init(struct platform_device *pdev)
 {
struct goldfish_pipe_dev *dev = _pipe_dev;
-   int err = devm_request_irq(>dev, dev->irq,
-   goldfish_pipe_interrupt,
-   IRQF_SHARED, "goldfish_pipe", dev);
+   int err;
+
+   tasklet_init(>irq_tasklet, _interrupt_task,
+(unsigned long)dev);
+
+   err = devm_request_irq(>dev, dev->irq,
+  goldfish_pipe_interrupt,
+  IRQF_SHARED, "goldfish_pipe", dev);
if (err) {
dev_err(>dev, "unable to allocate IRQ for v2\n");
return err;
@@ -854,6 +861,7 @@ static int goldfish_pipe_device_init(struct platform_device 
*pdev)
 static void goldfish_pipe_device_deinit(struct platform_device *pdev)
 {
misc_deregister(_pipe_miscdev);
+   tasklet_kill(_pipe_dev.irq_tasklet);
kfree(goldfish_pipe_dev.pipes);
free_page((unsigned long)goldfish_pipe_dev.buffers);
 }
-- 
2.19.0.605.g01d371f741-goog



[PATCH 12/15] platform: goldfish: pipe: Rename the init function (add "v2")

2018-10-02 Thread rkir
From: Roman Kiryanov 

This is the v2 driver. v1 will be added later.

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/goldfish_pipe.c| 2 +-
 drivers/platform/goldfish/goldfish_pipe_v2.c | 6 +++---
 drivers/platform/goldfish/goldfish_pipe_v2.h | 6 +++---
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index 792b20bdf76c..7b0920e962eb 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -87,7 +87,7 @@ static int goldfish_pipe_probe(struct platform_device *pdev)
if (WARN_ON(version < PIPE_CURRENT_DEVICE_VERSION))
return -EINVAL;
 
-   return goldfish_pipe_device_init(pdev, base, irq);
+   return goldfish_pipe_device_v2_init(pdev, base, irq);
 }
 
 static int goldfish_pipe_remove(struct platform_device *pdev)
diff --git a/drivers/platform/goldfish/goldfish_pipe_v2.c 
b/drivers/platform/goldfish/goldfish_pipe_v2.c
index 641dfdcc3ffd..9857ce07d0e6 100644
--- a/drivers/platform/goldfish/goldfish_pipe_v2.c
+++ b/drivers/platform/goldfish/goldfish_pipe_v2.c
@@ -787,9 +787,9 @@ static void write_pa_addr(void *addr, void __iomem *portl, 
void __iomem *porth)
writel(lower_32_bits(paddr), portl);
 }
 
-int goldfish_pipe_device_init(struct platform_device *pdev,
- char __iomem *base,
- int irq)
+int goldfish_pipe_device_v2_init(struct platform_device *pdev,
+char __iomem *base,
+int irq)
 {
struct goldfish_pipe_dev *dev;
int err;
diff --git a/drivers/platform/goldfish/goldfish_pipe_v2.h 
b/drivers/platform/goldfish/goldfish_pipe_v2.h
index 03b476fb9978..70bf4ec1fd66 100644
--- a/drivers/platform/goldfish/goldfish_pipe_v2.h
+++ b/drivers/platform/goldfish/goldfish_pipe_v2.h
@@ -3,8 +3,8 @@
 #define GOLDFISH_PIPE_V2_H
 
 /* The entry point to the pipe v2 driver */
-int goldfish_pipe_device_init(struct platform_device *pdev,
- char __iomem *base,
- int irq);
+int goldfish_pipe_device_v2_init(struct platform_device *pdev,
+char __iomem *base,
+int irq);
 
 #endif /* #define GOLDFISH_PIPE_V2_H */
-- 
2.19.0.605.g01d371f741-goog



[PATCH 11/15] platform: goldfish: pipe: Split the driver to v2 specific and the rest

2018-10-02 Thread rkir
From: Roman Kiryanov 

Move probe/remove and other driver stuff to a separate file
to plug v1 there later.

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/Makefile   |   3 +-
 drivers/platform/goldfish/goldfish_pipe.c| 124 +++
 drivers/platform/goldfish/goldfish_pipe.h|  10 ++
 drivers/platform/goldfish/goldfish_pipe_v2.c | 112 +++--
 drivers/platform/goldfish/goldfish_pipe_v2.h |  10 ++
 5 files changed, 161 insertions(+), 98 deletions(-)
 create mode 100644 drivers/platform/goldfish/goldfish_pipe.c
 create mode 100644 drivers/platform/goldfish/goldfish_pipe.h
 create mode 100644 drivers/platform/goldfish/goldfish_pipe_v2.h

diff --git a/drivers/platform/goldfish/Makefile 
b/drivers/platform/goldfish/Makefile
index 81f899a987a2..016769e003d8 100644
--- a/drivers/platform/goldfish/Makefile
+++ b/drivers/platform/goldfish/Makefile
@@ -1,4 +1,5 @@
 #
 # Makefile for Goldfish platform specific drivers
 #
-obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe_v2.o
+obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe_all.o
+goldfish_pipe_all-objs := goldfish_pipe.o goldfish_pipe_v2.o
diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
new file mode 100644
index ..792b20bdf76c
--- /dev/null
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -0,0 +1,124 @@
+// SPDX-License-Identifier: GPL-2.0
+/* This source file contains the implementation of a special device driver
+ * that intends to provide a *very* fast communication channel between the
+ * guest system and the QEMU emulator.
+ *
+ * Usage from the guest is simply the following (error handling simplified):
+ *
+ *int  fd = open("/dev/qemu_pipe",O_RDWR);
+ * write() or read() through the pipe.
+ *
+ * This driver doesn't deal with the exact protocol used during the session.
+ * It is intended to be as simple as something like:
+ *
+ *// do this _just_ after opening the fd to connect to a specific
+ *// emulator service.
+ *const char*  msg = "";
+ *if (write(fd, msg, strlen(msg)+1) < 0) {
+ *   ... could not connect to  service
+ *   close(fd);
+ *}
+ *
+ *// after this, simply read() and write() to communicate with the
+ *// service. Exact protocol details left as an exercise to the reader.
+ *
+ * This driver is very fast because it doesn't copy any data through
+ * intermediate buffers, since the emulator is capable of translating
+ * guest user addresses into host ones.
+ *
+ * Note that we must however ensure that each user page involved in the
+ * exchange is properly mapped during a transfer.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "goldfish_pipe_qemu.h"
+#include "goldfish_pipe.h"
+#include "goldfish_pipe_v2.h"
+
+/*
+ * Update this when something changes in the driver's behavior so the host
+ * can benefit from knowing it
+ */
+enum {
+   PIPE_DRIVER_VERSION = 2,
+   PIPE_CURRENT_DEVICE_VERSION = 2
+};
+
+static int goldfish_pipe_probe(struct platform_device *pdev)
+{
+   struct resource *r;
+   char __iomem *base;
+   int irq;
+   int version;
+
+   r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+   if (!r || resource_size(r) < PAGE_SIZE) {
+   dev_err(>dev, "can't allocate i/o page\n");
+   return -EINVAL;
+   }
+   base = devm_ioremap(>dev, r->start, PAGE_SIZE);
+   if (!base) {
+   dev_err(>dev, "ioremap failed\n");
+   return -EINVAL;
+   }
+
+   r = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
+   if (!r)
+   return -EINVAL;
+
+   irq = r->start;
+
+   /*
+* Exchange the versions with the host device
+*
+* Note: v1 driver used to not report its version, so we write it before
+*  reading device version back: this allows the host implementation to
+*  detect the old driver (if there was no version write before read).
+*/
+   writel(PIPE_DRIVER_VERSION, base + PIPE_REG_VERSION);
+   version = readl(base + PIPE_REG_VERSION);
+
+   if (WARN_ON(version < PIPE_CURRENT_DEVICE_VERSION))
+   return -EINVAL;
+
+   return goldfish_pipe_device_init(pdev, base, irq);
+}
+
+static int goldfish_pipe_remove(struct platform_device *pdev)
+{
+   struct goldfish_pipe_dev_base *dev = platform_get_drvdata(pdev);
+
+   return dev->deinit(dev, pdev);
+}
+
+static const struct acpi_device_id goldfish_pipe_acpi_match[] = {
+   { "GFSH0003", 0 },
+   { },
+};
+MODULE_DEVICE_TABLE(acpi, goldfish_pipe_acpi_match);
+
+static const struct of_device_id goldfish_pipe_of_match[] = {
+   { .compatible = "google,android-pipe", },
+   {},
+};
+MODULE_DEVICE_TABLE(of, goldfish_pipe_of_match);
+
+static struct platform_driver goldfish_pipe_driver = {
+   .probe = goldfish_pipe_probe,
+   .remove = goldfish_pipe_remove,
+   .driver = {

[PATCH 08/15] platform: goldfish: pipe: Add a blank line to separate varibles and code

2018-10-02 Thread rkir
From: Roman Kiryanov 

checkpacth: Missing a blank line after declarations

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/goldfish_pipe.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index 1822d4146778..a1fbbf49cc3f 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -713,6 +713,7 @@ static int goldfish_pipe_open(struct inode *inode, struct 
file *file)
 
/* Allocate new pipe kernel object */
struct goldfish_pipe *pipe = kzalloc(sizeof(*pipe), GFP_KERNEL);
+
if (!pipe)
return -ENOMEM;
 
-- 
2.19.0.605.g01d371f741-goog



[PATCH 02/15] platform: goldfish: pipe: Remove the goldfish_pipe_miscdev global variable

2018-10-02 Thread rkir
From: Roman Kiryanov 

This is a series of patches to remove mutable global variables
to introduce another version of the pipe driver for the older
host interface. I don't want to have two driver states where
only one is used.

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/goldfish_pipe.c | 20 +---
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index ba9aede17d57..8ca709b45e1f 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -211,6 +211,8 @@ struct goldfish_pipe_dev {
 
/* an irq tasklet to run goldfish_interrupt_task */
struct tasklet_struct irq_tasklet;
+
+   struct miscdevice miscdev;
 };
 
 static struct goldfish_pipe_dev goldfish_pipe_dev;
@@ -785,11 +787,14 @@ static const struct file_operations goldfish_pipe_fops = {
.release = goldfish_pipe_release,
 };
 
-static struct miscdevice goldfish_pipe_miscdev = {
-   .minor = MISC_DYNAMIC_MINOR,
-   .name = "goldfish_pipe",
-   .fops = _pipe_fops,
-};
+static void init_miscdevice(struct miscdevice *miscdev)
+{
+   memset(miscdev, 0, sizeof(*miscdev));
+
+   miscdev->minor = MISC_DYNAMIC_MINOR;
+   miscdev->name = "goldfish_pipe";
+   miscdev->fops = _pipe_fops;
+}
 
 static void write_pa_addr(void *addr, void __iomem *portl, void __iomem *porth)
 {
@@ -815,7 +820,8 @@ static int goldfish_pipe_device_init(struct platform_device 
*pdev)
return err;
}
 
-   err = misc_register(_pipe_miscdev);
+   init_miscdevice(>miscdev);
+   err = misc_register(>miscdev);
if (err) {
dev_err(>dev, "unable to register v2 device\n");
return err;
@@ -860,7 +866,7 @@ static int goldfish_pipe_device_init(struct platform_device 
*pdev)
 
 static void goldfish_pipe_device_deinit(struct platform_device *pdev)
 {
-   misc_deregister(_pipe_miscdev);
+   misc_deregister(_pipe_dev.miscdev);
tasklet_kill(_pipe_dev.irq_tasklet);
kfree(goldfish_pipe_dev.pipes);
free_page((unsigned long)goldfish_pipe_dev.buffers);
-- 
2.19.0.605.g01d371f741-goog



[PATCH 01/15] platform: goldfish: pipe: Remove the goldfish_interrupt_tasklet global variable

2018-10-02 Thread rkir
From: Roman Kiryanov 

This is a series of patches to remove mutable global variables
to introduce another version of the pipe driver for the older
host interface. I don't want to have two driver states where only
one is used.

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/goldfish_pipe.c | 24 +++
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index 56665e879e5a..ba9aede17d57 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -208,6 +208,9 @@ struct goldfish_pipe_dev {
int irq;
int version;
unsigned char __iomem *base;
+
+   /* an irq tasklet to run goldfish_interrupt_task */
+   struct tasklet_struct irq_tasklet;
 };
 
 static struct goldfish_pipe_dev goldfish_pipe_dev;
@@ -582,14 +585,14 @@ static struct goldfish_pipe *signalled_pipes_pop_front(
return pipe;
 }
 
-static void goldfish_interrupt_task(unsigned long unused)
+static void goldfish_interrupt_task(unsigned long dev_addr)
 {
/* Iterate over the signalled pipes and wake them one by one */
+   struct goldfish_pipe_dev *dev = (struct goldfish_pipe_dev *)dev_addr;
struct goldfish_pipe *pipe;
int wakes;
 
-   while ((pipe = signalled_pipes_pop_front(_pipe_dev, )) !=
-   NULL) {
+   while ((pipe = signalled_pipes_pop_front(dev, )) != NULL) {
if (wakes & PIPE_WAKE_CLOSED) {
pipe->flags = 1 << BIT_CLOSED_ON_HOST;
} else {
@@ -605,7 +608,6 @@ static void goldfish_interrupt_task(unsigned long unused)
wake_up_interruptible(>wake_queue);
}
 }
-static DECLARE_TASKLET(goldfish_interrupt_tasklet, goldfish_interrupt_task, 0);
 
 /*
  * The general idea of the interrupt handling:
@@ -648,7 +650,7 @@ static irqreturn_t goldfish_pipe_interrupt(int irq, void 
*dev_id)
 
spin_unlock_irqrestore(>lock, flags);
 
-   tasklet_schedule(_interrupt_tasklet);
+   tasklet_schedule(>irq_tasklet);
return IRQ_HANDLED;
 }
 
@@ -800,9 +802,14 @@ static void write_pa_addr(void *addr, void __iomem *portl, 
void __iomem *porth)
 static int goldfish_pipe_device_init(struct platform_device *pdev)
 {
struct goldfish_pipe_dev *dev = _pipe_dev;
-   int err = devm_request_irq(>dev, dev->irq,
-   goldfish_pipe_interrupt,
-   IRQF_SHARED, "goldfish_pipe", dev);
+   int err;
+
+   tasklet_init(>irq_tasklet, _interrupt_task,
+(unsigned long)dev);
+
+   err = devm_request_irq(>dev, dev->irq,
+  goldfish_pipe_interrupt,
+  IRQF_SHARED, "goldfish_pipe", dev);
if (err) {
dev_err(>dev, "unable to allocate IRQ for v2\n");
return err;
@@ -854,6 +861,7 @@ static int goldfish_pipe_device_init(struct platform_device 
*pdev)
 static void goldfish_pipe_device_deinit(struct platform_device *pdev)
 {
misc_deregister(_pipe_miscdev);
+   tasklet_kill(_pipe_dev.irq_tasklet);
kfree(goldfish_pipe_dev.pipes);
free_page((unsigned long)goldfish_pipe_dev.buffers);
 }
-- 
2.19.0.605.g01d371f741-goog



[PATCH 12/15] platform: goldfish: pipe: Rename the init function (add "v2")

2018-10-02 Thread rkir
From: Roman Kiryanov 

This is the v2 driver. v1 will be added later.

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/goldfish_pipe.c| 2 +-
 drivers/platform/goldfish/goldfish_pipe_v2.c | 6 +++---
 drivers/platform/goldfish/goldfish_pipe_v2.h | 6 +++---
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index 792b20bdf76c..7b0920e962eb 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -87,7 +87,7 @@ static int goldfish_pipe_probe(struct platform_device *pdev)
if (WARN_ON(version < PIPE_CURRENT_DEVICE_VERSION))
return -EINVAL;
 
-   return goldfish_pipe_device_init(pdev, base, irq);
+   return goldfish_pipe_device_v2_init(pdev, base, irq);
 }
 
 static int goldfish_pipe_remove(struct platform_device *pdev)
diff --git a/drivers/platform/goldfish/goldfish_pipe_v2.c 
b/drivers/platform/goldfish/goldfish_pipe_v2.c
index 641dfdcc3ffd..9857ce07d0e6 100644
--- a/drivers/platform/goldfish/goldfish_pipe_v2.c
+++ b/drivers/platform/goldfish/goldfish_pipe_v2.c
@@ -787,9 +787,9 @@ static void write_pa_addr(void *addr, void __iomem *portl, 
void __iomem *porth)
writel(lower_32_bits(paddr), portl);
 }
 
-int goldfish_pipe_device_init(struct platform_device *pdev,
- char __iomem *base,
- int irq)
+int goldfish_pipe_device_v2_init(struct platform_device *pdev,
+char __iomem *base,
+int irq)
 {
struct goldfish_pipe_dev *dev;
int err;
diff --git a/drivers/platform/goldfish/goldfish_pipe_v2.h 
b/drivers/platform/goldfish/goldfish_pipe_v2.h
index 03b476fb9978..70bf4ec1fd66 100644
--- a/drivers/platform/goldfish/goldfish_pipe_v2.h
+++ b/drivers/platform/goldfish/goldfish_pipe_v2.h
@@ -3,8 +3,8 @@
 #define GOLDFISH_PIPE_V2_H
 
 /* The entry point to the pipe v2 driver */
-int goldfish_pipe_device_init(struct platform_device *pdev,
- char __iomem *base,
- int irq);
+int goldfish_pipe_device_v2_init(struct platform_device *pdev,
+char __iomem *base,
+int irq);
 
 #endif /* #define GOLDFISH_PIPE_V2_H */
-- 
2.19.0.605.g01d371f741-goog



[PATCH 11/15] platform: goldfish: pipe: Split the driver to v2 specific and the rest

2018-10-02 Thread rkir
From: Roman Kiryanov 

Move probe/remove and other driver stuff to a separate file
to plug v1 there later.

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/Makefile   |   3 +-
 drivers/platform/goldfish/goldfish_pipe.c| 124 +++
 drivers/platform/goldfish/goldfish_pipe.h|  10 ++
 drivers/platform/goldfish/goldfish_pipe_v2.c | 112 +++--
 drivers/platform/goldfish/goldfish_pipe_v2.h |  10 ++
 5 files changed, 161 insertions(+), 98 deletions(-)
 create mode 100644 drivers/platform/goldfish/goldfish_pipe.c
 create mode 100644 drivers/platform/goldfish/goldfish_pipe.h
 create mode 100644 drivers/platform/goldfish/goldfish_pipe_v2.h

diff --git a/drivers/platform/goldfish/Makefile 
b/drivers/platform/goldfish/Makefile
index 81f899a987a2..016769e003d8 100644
--- a/drivers/platform/goldfish/Makefile
+++ b/drivers/platform/goldfish/Makefile
@@ -1,4 +1,5 @@
 #
 # Makefile for Goldfish platform specific drivers
 #
-obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe_v2.o
+obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe_all.o
+goldfish_pipe_all-objs := goldfish_pipe.o goldfish_pipe_v2.o
diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
new file mode 100644
index ..792b20bdf76c
--- /dev/null
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -0,0 +1,124 @@
+// SPDX-License-Identifier: GPL-2.0
+/* This source file contains the implementation of a special device driver
+ * that intends to provide a *very* fast communication channel between the
+ * guest system and the QEMU emulator.
+ *
+ * Usage from the guest is simply the following (error handling simplified):
+ *
+ *int  fd = open("/dev/qemu_pipe",O_RDWR);
+ * write() or read() through the pipe.
+ *
+ * This driver doesn't deal with the exact protocol used during the session.
+ * It is intended to be as simple as something like:
+ *
+ *// do this _just_ after opening the fd to connect to a specific
+ *// emulator service.
+ *const char*  msg = "";
+ *if (write(fd, msg, strlen(msg)+1) < 0) {
+ *   ... could not connect to  service
+ *   close(fd);
+ *}
+ *
+ *// after this, simply read() and write() to communicate with the
+ *// service. Exact protocol details left as an exercise to the reader.
+ *
+ * This driver is very fast because it doesn't copy any data through
+ * intermediate buffers, since the emulator is capable of translating
+ * guest user addresses into host ones.
+ *
+ * Note that we must however ensure that each user page involved in the
+ * exchange is properly mapped during a transfer.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "goldfish_pipe_qemu.h"
+#include "goldfish_pipe.h"
+#include "goldfish_pipe_v2.h"
+
+/*
+ * Update this when something changes in the driver's behavior so the host
+ * can benefit from knowing it
+ */
+enum {
+   PIPE_DRIVER_VERSION = 2,
+   PIPE_CURRENT_DEVICE_VERSION = 2
+};
+
+static int goldfish_pipe_probe(struct platform_device *pdev)
+{
+   struct resource *r;
+   char __iomem *base;
+   int irq;
+   int version;
+
+   r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+   if (!r || resource_size(r) < PAGE_SIZE) {
+   dev_err(>dev, "can't allocate i/o page\n");
+   return -EINVAL;
+   }
+   base = devm_ioremap(>dev, r->start, PAGE_SIZE);
+   if (!base) {
+   dev_err(>dev, "ioremap failed\n");
+   return -EINVAL;
+   }
+
+   r = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
+   if (!r)
+   return -EINVAL;
+
+   irq = r->start;
+
+   /*
+* Exchange the versions with the host device
+*
+* Note: v1 driver used to not report its version, so we write it before
+*  reading device version back: this allows the host implementation to
+*  detect the old driver (if there was no version write before read).
+*/
+   writel(PIPE_DRIVER_VERSION, base + PIPE_REG_VERSION);
+   version = readl(base + PIPE_REG_VERSION);
+
+   if (WARN_ON(version < PIPE_CURRENT_DEVICE_VERSION))
+   return -EINVAL;
+
+   return goldfish_pipe_device_init(pdev, base, irq);
+}
+
+static int goldfish_pipe_remove(struct platform_device *pdev)
+{
+   struct goldfish_pipe_dev_base *dev = platform_get_drvdata(pdev);
+
+   return dev->deinit(dev, pdev);
+}
+
+static const struct acpi_device_id goldfish_pipe_acpi_match[] = {
+   { "GFSH0003", 0 },
+   { },
+};
+MODULE_DEVICE_TABLE(acpi, goldfish_pipe_acpi_match);
+
+static const struct of_device_id goldfish_pipe_of_match[] = {
+   { .compatible = "google,android-pipe", },
+   {},
+};
+MODULE_DEVICE_TABLE(of, goldfish_pipe_of_match);
+
+static struct platform_driver goldfish_pipe_driver = {
+   .probe = goldfish_pipe_probe,
+   .remove = goldfish_pipe_remove,
+   .driver = {

[PATCH 08/15] platform: goldfish: pipe: Add a blank line to separate varibles and code

2018-10-02 Thread rkir
From: Roman Kiryanov 

checkpacth: Missing a blank line after declarations

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/goldfish_pipe.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index 1822d4146778..a1fbbf49cc3f 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -713,6 +713,7 @@ static int goldfish_pipe_open(struct inode *inode, struct 
file *file)
 
/* Allocate new pipe kernel object */
struct goldfish_pipe *pipe = kzalloc(sizeof(*pipe), GFP_KERNEL);
+
if (!pipe)
return -ENOMEM;
 
-- 
2.19.0.605.g01d371f741-goog



[PATCH 02/15] platform: goldfish: pipe: Remove the goldfish_pipe_miscdev global variable

2018-10-02 Thread rkir
From: Roman Kiryanov 

This is a series of patches to remove mutable global variables
to introduce another version of the pipe driver for the older
host interface. I don't want to have two driver states where
only one is used.

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/goldfish_pipe.c | 20 +---
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index ba9aede17d57..8ca709b45e1f 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -211,6 +211,8 @@ struct goldfish_pipe_dev {
 
/* an irq tasklet to run goldfish_interrupt_task */
struct tasklet_struct irq_tasklet;
+
+   struct miscdevice miscdev;
 };
 
 static struct goldfish_pipe_dev goldfish_pipe_dev;
@@ -785,11 +787,14 @@ static const struct file_operations goldfish_pipe_fops = {
.release = goldfish_pipe_release,
 };
 
-static struct miscdevice goldfish_pipe_miscdev = {
-   .minor = MISC_DYNAMIC_MINOR,
-   .name = "goldfish_pipe",
-   .fops = _pipe_fops,
-};
+static void init_miscdevice(struct miscdevice *miscdev)
+{
+   memset(miscdev, 0, sizeof(*miscdev));
+
+   miscdev->minor = MISC_DYNAMIC_MINOR;
+   miscdev->name = "goldfish_pipe";
+   miscdev->fops = _pipe_fops;
+}
 
 static void write_pa_addr(void *addr, void __iomem *portl, void __iomem *porth)
 {
@@ -815,7 +820,8 @@ static int goldfish_pipe_device_init(struct platform_device 
*pdev)
return err;
}
 
-   err = misc_register(_pipe_miscdev);
+   init_miscdevice(>miscdev);
+   err = misc_register(>miscdev);
if (err) {
dev_err(>dev, "unable to register v2 device\n");
return err;
@@ -860,7 +866,7 @@ static int goldfish_pipe_device_init(struct platform_device 
*pdev)
 
 static void goldfish_pipe_device_deinit(struct platform_device *pdev)
 {
-   misc_deregister(_pipe_miscdev);
+   misc_deregister(_pipe_dev.miscdev);
tasklet_kill(_pipe_dev.irq_tasklet);
kfree(goldfish_pipe_dev.pipes);
free_page((unsigned long)goldfish_pipe_dev.buffers);
-- 
2.19.0.605.g01d371f741-goog



[PATCH 09/15] platform: goldfish: pipe: Move goldfish_pipe to goldfish_pipe_v2

2018-10-02 Thread rkir
From: Roman Kiryanov 

This is the v2 driver. v1 will be added later.

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/Makefile  | 2 +-
 .../platform/goldfish/{goldfish_pipe.c => goldfish_pipe_v2.c}   | 0
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename drivers/platform/goldfish/{goldfish_pipe.c => goldfish_pipe_v2.c} (100%)

diff --git a/drivers/platform/goldfish/Makefile 
b/drivers/platform/goldfish/Makefile
index e0c202df9674..81f899a987a2 100644
--- a/drivers/platform/goldfish/Makefile
+++ b/drivers/platform/goldfish/Makefile
@@ -1,4 +1,4 @@
 #
 # Makefile for Goldfish platform specific drivers
 #
-obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe.o
+obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe_v2.o
diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe_v2.c
similarity index 100%
rename from drivers/platform/goldfish/goldfish_pipe.c
rename to drivers/platform/goldfish/goldfish_pipe_v2.c
-- 
2.19.0.605.g01d371f741-goog



[PATCH 07/15] platform: goldfish: pipe: Return status from "deinit" since "remove" does not do much

2018-10-02 Thread rkir
From: Roman Kiryanov 

This way deinit will have a chance to report an error.

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/goldfish_pipe.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index 445c0c0c66c4..1822d4146778 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -888,13 +888,15 @@ static int goldfish_pipe_device_init(struct 
platform_device *pdev,
return 0;
 }
 
-static void goldfish_pipe_device_deinit(struct platform_device *pdev,
-   struct goldfish_pipe_dev *dev)
+static int goldfish_pipe_device_deinit(struct platform_device *pdev,
+  struct goldfish_pipe_dev *dev)
 {
misc_deregister(>miscdev);
tasklet_kill(>irq_tasklet);
kfree(dev->pipes);
free_page((unsigned long)dev->buffers);
+
+   return 0;
 }
 
 static int goldfish_pipe_probe(struct platform_device *pdev)
@@ -941,8 +943,7 @@ static int goldfish_pipe_remove(struct platform_device 
*pdev)
 {
struct goldfish_pipe_dev *dev = platform_get_drvdata(pdev);
 
-   goldfish_pipe_device_deinit(pdev, dev);
-   return 0;
+   return goldfish_pipe_device_deinit(pdev, dev);
 }
 
 static const struct acpi_device_id goldfish_pipe_acpi_match[] = {
-- 
2.19.0.605.g01d371f741-goog



[PATCH 06/15] platform: goldfish: pipe: Move memory allocation from probe to init

2018-10-02 Thread rkir
From: Roman Kiryanov 

There will be two separate init functions for v1 and v2
(different driver versions) and they will allocate different
state.

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/goldfish_pipe.c | 42 +--
 1 file changed, 23 insertions(+), 19 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index bc431f04c4cf..445c0c0c66c4 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -208,8 +208,6 @@ struct goldfish_pipe_dev {
struct device *pdev_dev;
 
/* Some device-specific data */
-   int irq;
-   int version;
unsigned char __iomem *base;
 
/* an irq tasklet to run goldfish_interrupt_task */
@@ -817,14 +815,23 @@ static void write_pa_addr(void *addr, void __iomem 
*portl, void __iomem *porth)
 }
 
 static int goldfish_pipe_device_init(struct platform_device *pdev,
-struct goldfish_pipe_dev *dev)
+char __iomem *base,
+int irq)
 {
+   struct goldfish_pipe_dev *dev;
int err;
 
+   dev = devm_kzalloc(>dev, sizeof(*dev), GFP_KERNEL);
+   if (!dev)
+   return -ENOMEM;
+
+   dev->magic = _pipe_device_deinit;
+   spin_lock_init(>lock);
+
tasklet_init(>irq_tasklet, _interrupt_task,
 (unsigned long)dev);
 
-   err = devm_request_irq(>dev, dev->irq,
+   err = devm_request_irq(>dev, irq,
   goldfish_pipe_interrupt,
   IRQF_SHARED, "goldfish_pipe", dev);
if (err) {
@@ -839,6 +846,7 @@ static int goldfish_pipe_device_init(struct platform_device 
*pdev,
return err;
}
 
+   dev->base = base;
dev->pdev_dev = >dev;
dev->first_signalled_pipe = NULL;
dev->pipes_capacity = INITIAL_PIPES_CAPACITY;
@@ -892,22 +900,18 @@ static void goldfish_pipe_device_deinit(struct 
platform_device *pdev,
 static int goldfish_pipe_probe(struct platform_device *pdev)
 {
struct resource *r;
-   struct goldfish_pipe_dev *dev;
-
-   dev = devm_kzalloc(>dev, sizeof(*dev), GFP_KERNEL);
-   if (!dev)
-   return -ENOMEM;
-
-   dev->magic = _pipe_device_deinit;
-   spin_lock_init(>lock);
+   char __iomem *base;
+   int irq;
+   int version;
 
r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!r || resource_size(r) < PAGE_SIZE) {
dev_err(>dev, "can't allocate i/o page\n");
return -EINVAL;
}
-   dev->base = devm_ioremap(>dev, r->start, PAGE_SIZE);
-   if (!dev->base) {
+
+   base = devm_ioremap(>dev, r->start, PAGE_SIZE);
+   if (!base) {
dev_err(>dev, "ioremap failed\n");
return -EINVAL;
}
@@ -916,7 +920,7 @@ static int goldfish_pipe_probe(struct platform_device *pdev)
if (!r)
return -EINVAL;
 
-   dev->irq = r->start;
+   irq = r->start;
 
/*
 * Exchange the versions with the host device
@@ -925,12 +929,12 @@ static int goldfish_pipe_probe(struct platform_device 
*pdev)
 *  reading device version back: this allows the host implementation to
 *  detect the old driver (if there was no version write before read).
 */
-   writel(PIPE_DRIVER_VERSION, dev->base + PIPE_REG_VERSION);
-   dev->version = readl(dev->base + PIPE_REG_VERSION);
-   if (WARN_ON(dev->version < PIPE_CURRENT_DEVICE_VERSION))
+   writel(PIPE_DRIVER_VERSION, base + PIPE_REG_VERSION);
+   version = readl(base + PIPE_REG_VERSION);
+   if (WARN_ON(version < PIPE_CURRENT_DEVICE_VERSION))
return -EINVAL;
 
-   return goldfish_pipe_device_init(pdev, dev);
+   return goldfish_pipe_device_init(pdev, base, irq);
 }
 
 static int goldfish_pipe_remove(struct platform_device *pdev)
-- 
2.19.0.605.g01d371f741-goog



[PATCH 05/15] platform: goldfish: pipe: Remove redundant casting

2018-10-02 Thread rkir
From: Roman Kiryanov 

This casting is not required.

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/goldfish_pipe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index c386aaf40034..bc431f04c4cf 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -925,7 +925,7 @@ static int goldfish_pipe_probe(struct platform_device *pdev)
 *  reading device version back: this allows the host implementation to
 *  detect the old driver (if there was no version write before read).
 */
-   writel((u32)PIPE_DRIVER_VERSION, dev->base + PIPE_REG_VERSION);
+   writel(PIPE_DRIVER_VERSION, dev->base + PIPE_REG_VERSION);
dev->version = readl(dev->base + PIPE_REG_VERSION);
if (WARN_ON(dev->version < PIPE_CURRENT_DEVICE_VERSION))
return -EINVAL;
-- 
2.19.0.605.g01d371f741-goog



[PATCH 04/15] platform: goldfish: pipe: Call misc_deregister if init fails

2018-10-02 Thread rkir
From: Roman Kiryanov 

Undo effects of misc_register if driver's init fails after
misc_register.

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/goldfish_pipe.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index 4013832f38fb..c386aaf40034 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -844,8 +844,10 @@ static int goldfish_pipe_device_init(struct 
platform_device *pdev,
dev->pipes_capacity = INITIAL_PIPES_CAPACITY;
dev->pipes = kcalloc(dev->pipes_capacity, sizeof(*dev->pipes),
 GFP_KERNEL);
-   if (!dev->pipes)
+   if (!dev->pipes) {
+   misc_deregister(>miscdev);
return -ENOMEM;
+   }
 
/*
 * We're going to pass two buffers, open_command_params and
@@ -858,6 +860,7 @@ static int goldfish_pipe_device_init(struct platform_device 
*pdev,
__get_free_page(GFP_KERNEL);
if (!dev->buffers) {
kfree(dev->pipes);
+   misc_deregister(>miscdev);
return -ENOMEM;
}
 
-- 
2.19.0.605.g01d371f741-goog



[PATCH 03/15] platform: goldfish: pipe: Remove the goldfish_pipe_dev global variable

2018-10-02 Thread rkir
From: Roman Kiryanov 

This is the last patch in the series of patches to remove mutable
global variables to introduce another version of the pipe driver
for the older host interface. I don't want to have two driver
states where only one is used.

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/goldfish_pipe.c | 66 +--
 1 file 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 {
  * waiting to be awoken.
  */
 struct goldfish_pipe_dev {
+   /* A magic number to check if this is an instance of this struct */
+   void *magic;
+
/*
 * Global device spinlock. Protects the following members:
 *  - pipes, pipes_capacity
@@ -215,8 +218,6 @@ struct goldfish_pipe_dev {
struct miscdevice miscdev;
 };
 
-static struct goldfish_pipe_dev goldfish_pipe_dev;
-
 static int goldfish_pipe_cmd_locked(struct goldfish_pipe *pipe,
enum PipeCmdCode cmd)
 {
@@ -611,6 +612,9 @@ static void goldfish_interrupt_task(unsigned long dev_addr)
}
 }
 
+static void goldfish_pipe_device_deinit(struct platform_device *pdev,
+   struct goldfish_pipe_dev *dev);
+
 /*
  * The general idea of the interrupt handling:
  *
@@ -631,7 +635,7 @@ static irqreturn_t goldfish_pipe_interrupt(int irq, void 
*dev_id)
unsigned long flags;
struct goldfish_pipe_dev *dev = dev_id;
 
-   if (dev != _pipe_dev)
+   if (dev->magic != _pipe_device_deinit)
return IRQ_NONE;
 
/* Request the signalled pipes from the device */
@@ -683,6 +687,14 @@ static int get_free_pipe_id_locked(struct 
goldfish_pipe_dev *dev)
return id;
 }
 
+/* A helper function to get the instance of goldfish_pipe_dev from file */
+static struct goldfish_pipe_dev *to_goldfish_pipe_dev(struct file *file)
+{
+   struct miscdevice *miscdev = file->private_data;
+
+   return container_of(miscdev, struct goldfish_pipe_dev, miscdev);
+}
+
 /**
  * goldfish_pipe_open - open a channel to the AVD
  * @inode: inode of device
@@ -696,7 +708,7 @@ static int get_free_pipe_id_locked(struct goldfish_pipe_dev 
*dev)
  */
 static int goldfish_pipe_open(struct inode *inode, struct file *file)
 {
-   struct goldfish_pipe_dev *dev = _pipe_dev;
+   struct goldfish_pipe_dev *dev = to_goldfish_pipe_dev(file);
unsigned long flags;
int id;
int status;
@@ -804,9 +816,9 @@ static void write_pa_addr(void *addr, void __iomem *portl, 
void __iomem *porth)
writel(lower_32_bits(paddr), portl);
 }
 
-static int goldfish_pipe_device_init(struct platform_device *pdev)
+static int goldfish_pipe_device_init(struct platform_device *pdev,
+struct goldfish_pipe_dev *dev)
 {
-   struct goldfish_pipe_dev *dev = _pipe_dev;
int err;
 
tasklet_init(>irq_tasklet, _interrupt_task,
@@ -861,26 +873,29 @@ static int goldfish_pipe_device_init(struct 
platform_device *pdev)
  dev->base + PIPE_REG_OPEN_BUFFER,
  dev->base + PIPE_REG_OPEN_BUFFER_HIGH);
 
+   platform_set_drvdata(pdev, dev);
return 0;
 }
 
-static void goldfish_pipe_device_deinit(struct platform_device *pdev)
+static void goldfish_pipe_device_deinit(struct platform_device *pdev,
+   struct goldfish_pipe_dev *dev)
 {
-   misc_deregister(_pipe_dev.miscdev);
-   tasklet_kill(_pipe_dev.irq_tasklet);
-   kfree(goldfish_pipe_dev.pipes);
-   free_page((unsigned long)goldfish_pipe_dev.buffers);
+   misc_deregister(>miscdev);
+   tasklet_kill(>irq_tasklet);
+   kfree(dev->pipes);
+   free_page((unsigned long)dev->buffers);
 }
 
 static int goldfish_pipe_probe(struct platform_device *pdev)
 {
-   int err;
struct resource *r;
-   struct goldfish_pipe_dev *dev = _pipe_dev;
+   struct goldfish_pipe_dev *dev;
 
-   /* not thread safe, but this should not happen */
-   WARN_ON(dev->base);
+   dev = devm_kzalloc(>dev, sizeof(*dev), GFP_KERNEL);
+   if (!dev)
+   return -ENOMEM;
 
+   dev->magic = _pipe_device_deinit;
spin_lock_init(>lock);
 
r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -895,10 +910,9 @@ static int goldfish_pipe_probe(struct platform_device 
*pdev)
}
 
r = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
-   if (!r) {
-   err = -EINVAL;
-   goto error;
-   }
+   if (!r)
+   return -EINVAL;
+
dev->irq = r->start;
 
/*
@@ -913,20 +927,14 @@ static int goldfish_pipe_probe(struct platform_device 
*pdev)
if (WARN_ON(dev->version 

[PATCH 04/15] platform: goldfish: pipe: Call misc_deregister if init fails

2018-10-02 Thread rkir
From: Roman Kiryanov 

Undo effects of misc_register if driver's init fails after
misc_register.

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/goldfish_pipe.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index 4013832f38fb..c386aaf40034 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -844,8 +844,10 @@ static int goldfish_pipe_device_init(struct 
platform_device *pdev,
dev->pipes_capacity = INITIAL_PIPES_CAPACITY;
dev->pipes = kcalloc(dev->pipes_capacity, sizeof(*dev->pipes),
 GFP_KERNEL);
-   if (!dev->pipes)
+   if (!dev->pipes) {
+   misc_deregister(>miscdev);
return -ENOMEM;
+   }
 
/*
 * We're going to pass two buffers, open_command_params and
@@ -858,6 +860,7 @@ static int goldfish_pipe_device_init(struct platform_device 
*pdev,
__get_free_page(GFP_KERNEL);
if (!dev->buffers) {
kfree(dev->pipes);
+   misc_deregister(>miscdev);
return -ENOMEM;
}
 
-- 
2.19.0.605.g01d371f741-goog



[PATCH 03/15] platform: goldfish: pipe: Remove the goldfish_pipe_dev global variable

2018-10-02 Thread rkir
From: Roman Kiryanov 

This is the last patch in the series of patches to remove mutable
global variables to introduce another version of the pipe driver
for the older host interface. I don't want to have two driver
states where only one is used.

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/goldfish_pipe.c | 66 +--
 1 file 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 {
  * waiting to be awoken.
  */
 struct goldfish_pipe_dev {
+   /* A magic number to check if this is an instance of this struct */
+   void *magic;
+
/*
 * Global device spinlock. Protects the following members:
 *  - pipes, pipes_capacity
@@ -215,8 +218,6 @@ struct goldfish_pipe_dev {
struct miscdevice miscdev;
 };
 
-static struct goldfish_pipe_dev goldfish_pipe_dev;
-
 static int goldfish_pipe_cmd_locked(struct goldfish_pipe *pipe,
enum PipeCmdCode cmd)
 {
@@ -611,6 +612,9 @@ static void goldfish_interrupt_task(unsigned long dev_addr)
}
 }
 
+static void goldfish_pipe_device_deinit(struct platform_device *pdev,
+   struct goldfish_pipe_dev *dev);
+
 /*
  * The general idea of the interrupt handling:
  *
@@ -631,7 +635,7 @@ static irqreturn_t goldfish_pipe_interrupt(int irq, void 
*dev_id)
unsigned long flags;
struct goldfish_pipe_dev *dev = dev_id;
 
-   if (dev != _pipe_dev)
+   if (dev->magic != _pipe_device_deinit)
return IRQ_NONE;
 
/* Request the signalled pipes from the device */
@@ -683,6 +687,14 @@ static int get_free_pipe_id_locked(struct 
goldfish_pipe_dev *dev)
return id;
 }
 
+/* A helper function to get the instance of goldfish_pipe_dev from file */
+static struct goldfish_pipe_dev *to_goldfish_pipe_dev(struct file *file)
+{
+   struct miscdevice *miscdev = file->private_data;
+
+   return container_of(miscdev, struct goldfish_pipe_dev, miscdev);
+}
+
 /**
  * goldfish_pipe_open - open a channel to the AVD
  * @inode: inode of device
@@ -696,7 +708,7 @@ static int get_free_pipe_id_locked(struct goldfish_pipe_dev 
*dev)
  */
 static int goldfish_pipe_open(struct inode *inode, struct file *file)
 {
-   struct goldfish_pipe_dev *dev = _pipe_dev;
+   struct goldfish_pipe_dev *dev = to_goldfish_pipe_dev(file);
unsigned long flags;
int id;
int status;
@@ -804,9 +816,9 @@ static void write_pa_addr(void *addr, void __iomem *portl, 
void __iomem *porth)
writel(lower_32_bits(paddr), portl);
 }
 
-static int goldfish_pipe_device_init(struct platform_device *pdev)
+static int goldfish_pipe_device_init(struct platform_device *pdev,
+struct goldfish_pipe_dev *dev)
 {
-   struct goldfish_pipe_dev *dev = _pipe_dev;
int err;
 
tasklet_init(>irq_tasklet, _interrupt_task,
@@ -861,26 +873,29 @@ static int goldfish_pipe_device_init(struct 
platform_device *pdev)
  dev->base + PIPE_REG_OPEN_BUFFER,
  dev->base + PIPE_REG_OPEN_BUFFER_HIGH);
 
+   platform_set_drvdata(pdev, dev);
return 0;
 }
 
-static void goldfish_pipe_device_deinit(struct platform_device *pdev)
+static void goldfish_pipe_device_deinit(struct platform_device *pdev,
+   struct goldfish_pipe_dev *dev)
 {
-   misc_deregister(_pipe_dev.miscdev);
-   tasklet_kill(_pipe_dev.irq_tasklet);
-   kfree(goldfish_pipe_dev.pipes);
-   free_page((unsigned long)goldfish_pipe_dev.buffers);
+   misc_deregister(>miscdev);
+   tasklet_kill(>irq_tasklet);
+   kfree(dev->pipes);
+   free_page((unsigned long)dev->buffers);
 }
 
 static int goldfish_pipe_probe(struct platform_device *pdev)
 {
-   int err;
struct resource *r;
-   struct goldfish_pipe_dev *dev = _pipe_dev;
+   struct goldfish_pipe_dev *dev;
 
-   /* not thread safe, but this should not happen */
-   WARN_ON(dev->base);
+   dev = devm_kzalloc(>dev, sizeof(*dev), GFP_KERNEL);
+   if (!dev)
+   return -ENOMEM;
 
+   dev->magic = _pipe_device_deinit;
spin_lock_init(>lock);
 
r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -895,10 +910,9 @@ static int goldfish_pipe_probe(struct platform_device 
*pdev)
}
 
r = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
-   if (!r) {
-   err = -EINVAL;
-   goto error;
-   }
+   if (!r)
+   return -EINVAL;
+
dev->irq = r->start;
 
/*
@@ -913,20 +927,14 @@ static int goldfish_pipe_probe(struct platform_device 
*pdev)
if (WARN_ON(dev->version 

[PATCH 07/15] platform: goldfish: pipe: Return status from "deinit" since "remove" does not do much

2018-10-02 Thread rkir
From: Roman Kiryanov 

This way deinit will have a chance to report an error.

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/goldfish_pipe.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index 445c0c0c66c4..1822d4146778 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -888,13 +888,15 @@ static int goldfish_pipe_device_init(struct 
platform_device *pdev,
return 0;
 }
 
-static void goldfish_pipe_device_deinit(struct platform_device *pdev,
-   struct goldfish_pipe_dev *dev)
+static int goldfish_pipe_device_deinit(struct platform_device *pdev,
+  struct goldfish_pipe_dev *dev)
 {
misc_deregister(>miscdev);
tasklet_kill(>irq_tasklet);
kfree(dev->pipes);
free_page((unsigned long)dev->buffers);
+
+   return 0;
 }
 
 static int goldfish_pipe_probe(struct platform_device *pdev)
@@ -941,8 +943,7 @@ static int goldfish_pipe_remove(struct platform_device 
*pdev)
 {
struct goldfish_pipe_dev *dev = platform_get_drvdata(pdev);
 
-   goldfish_pipe_device_deinit(pdev, dev);
-   return 0;
+   return goldfish_pipe_device_deinit(pdev, dev);
 }
 
 static const struct acpi_device_id goldfish_pipe_acpi_match[] = {
-- 
2.19.0.605.g01d371f741-goog



[PATCH 06/15] platform: goldfish: pipe: Move memory allocation from probe to init

2018-10-02 Thread rkir
From: Roman Kiryanov 

There will be two separate init functions for v1 and v2
(different driver versions) and they will allocate different
state.

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/goldfish_pipe.c | 42 +--
 1 file changed, 23 insertions(+), 19 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index bc431f04c4cf..445c0c0c66c4 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -208,8 +208,6 @@ struct goldfish_pipe_dev {
struct device *pdev_dev;
 
/* Some device-specific data */
-   int irq;
-   int version;
unsigned char __iomem *base;
 
/* an irq tasklet to run goldfish_interrupt_task */
@@ -817,14 +815,23 @@ static void write_pa_addr(void *addr, void __iomem 
*portl, void __iomem *porth)
 }
 
 static int goldfish_pipe_device_init(struct platform_device *pdev,
-struct goldfish_pipe_dev *dev)
+char __iomem *base,
+int irq)
 {
+   struct goldfish_pipe_dev *dev;
int err;
 
+   dev = devm_kzalloc(>dev, sizeof(*dev), GFP_KERNEL);
+   if (!dev)
+   return -ENOMEM;
+
+   dev->magic = _pipe_device_deinit;
+   spin_lock_init(>lock);
+
tasklet_init(>irq_tasklet, _interrupt_task,
 (unsigned long)dev);
 
-   err = devm_request_irq(>dev, dev->irq,
+   err = devm_request_irq(>dev, irq,
   goldfish_pipe_interrupt,
   IRQF_SHARED, "goldfish_pipe", dev);
if (err) {
@@ -839,6 +846,7 @@ static int goldfish_pipe_device_init(struct platform_device 
*pdev,
return err;
}
 
+   dev->base = base;
dev->pdev_dev = >dev;
dev->first_signalled_pipe = NULL;
dev->pipes_capacity = INITIAL_PIPES_CAPACITY;
@@ -892,22 +900,18 @@ static void goldfish_pipe_device_deinit(struct 
platform_device *pdev,
 static int goldfish_pipe_probe(struct platform_device *pdev)
 {
struct resource *r;
-   struct goldfish_pipe_dev *dev;
-
-   dev = devm_kzalloc(>dev, sizeof(*dev), GFP_KERNEL);
-   if (!dev)
-   return -ENOMEM;
-
-   dev->magic = _pipe_device_deinit;
-   spin_lock_init(>lock);
+   char __iomem *base;
+   int irq;
+   int version;
 
r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!r || resource_size(r) < PAGE_SIZE) {
dev_err(>dev, "can't allocate i/o page\n");
return -EINVAL;
}
-   dev->base = devm_ioremap(>dev, r->start, PAGE_SIZE);
-   if (!dev->base) {
+
+   base = devm_ioremap(>dev, r->start, PAGE_SIZE);
+   if (!base) {
dev_err(>dev, "ioremap failed\n");
return -EINVAL;
}
@@ -916,7 +920,7 @@ static int goldfish_pipe_probe(struct platform_device *pdev)
if (!r)
return -EINVAL;
 
-   dev->irq = r->start;
+   irq = r->start;
 
/*
 * Exchange the versions with the host device
@@ -925,12 +929,12 @@ static int goldfish_pipe_probe(struct platform_device 
*pdev)
 *  reading device version back: this allows the host implementation to
 *  detect the old driver (if there was no version write before read).
 */
-   writel(PIPE_DRIVER_VERSION, dev->base + PIPE_REG_VERSION);
-   dev->version = readl(dev->base + PIPE_REG_VERSION);
-   if (WARN_ON(dev->version < PIPE_CURRENT_DEVICE_VERSION))
+   writel(PIPE_DRIVER_VERSION, base + PIPE_REG_VERSION);
+   version = readl(base + PIPE_REG_VERSION);
+   if (WARN_ON(version < PIPE_CURRENT_DEVICE_VERSION))
return -EINVAL;
 
-   return goldfish_pipe_device_init(pdev, dev);
+   return goldfish_pipe_device_init(pdev, base, irq);
 }
 
 static int goldfish_pipe_remove(struct platform_device *pdev)
-- 
2.19.0.605.g01d371f741-goog



[PATCH 05/15] platform: goldfish: pipe: Remove redundant casting

2018-10-02 Thread rkir
From: Roman Kiryanov 

This casting is not required.

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/goldfish_pipe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index c386aaf40034..bc431f04c4cf 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -925,7 +925,7 @@ static int goldfish_pipe_probe(struct platform_device *pdev)
 *  reading device version back: this allows the host implementation to
 *  detect the old driver (if there was no version write before read).
 */
-   writel((u32)PIPE_DRIVER_VERSION, dev->base + PIPE_REG_VERSION);
+   writel(PIPE_DRIVER_VERSION, dev->base + PIPE_REG_VERSION);
dev->version = readl(dev->base + PIPE_REG_VERSION);
if (WARN_ON(dev->version < PIPE_CURRENT_DEVICE_VERSION))
return -EINVAL;
-- 
2.19.0.605.g01d371f741-goog



[PATCH v2 13/21] platform: goldfish: pipe: Split the driver to v2 specific and the rest

2018-09-26 Thread rkir
From: Roman Kiryanov 

Move probe/remove and other driver stuff to a separate file
to plug v1 there later.

Signed-off-by: Roman Kiryanov 
---
Changes in v2:
 - Removed breakage of allmodconfig.

 drivers/platform/goldfish/Makefile   |   3 +-
 drivers/platform/goldfish/goldfish_pipe.c| 145 +++
 drivers/platform/goldfish/goldfish_pipe.h|  24 +++
 drivers/platform/goldfish/goldfish_pipe_v2.c | 102 ++---
 drivers/platform/goldfish/goldfish_pipe_v2.h |  24 +++
 5 files changed, 210 insertions(+), 88 deletions(-)
 create mode 100644 drivers/platform/goldfish/goldfish_pipe.c
 create mode 100644 drivers/platform/goldfish/goldfish_pipe.h
 create mode 100644 drivers/platform/goldfish/goldfish_pipe_v2.h

diff --git a/drivers/platform/goldfish/Makefile 
b/drivers/platform/goldfish/Makefile
index 81f899a987a2..016769e003d8 100644
--- a/drivers/platform/goldfish/Makefile
+++ b/drivers/platform/goldfish/Makefile
@@ -1,4 +1,5 @@
 #
 # Makefile for Goldfish platform specific drivers
 #
-obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe_v2.o
+obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe_all.o
+goldfish_pipe_all-objs := goldfish_pipe.o goldfish_pipe_v2.o
diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
new file mode 100644
index ..802bbf0d6d23
--- /dev/null
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -0,0 +1,145 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2012 Intel, Inc.
+ * Copyright (C) 2013 Intel, Inc.
+ * Copyright (C) 2014 Linaro Limited
+ * Copyright (C) 2011-2016 Google, Inc.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+/* This source file contains the implementation of a special device driver
+ * that intends to provide a *very* fast communication channel between the
+ * guest system and the QEMU emulator.
+ *
+ * Usage from the guest is simply the following (error handling simplified):
+ *
+ *int  fd = open("/dev/qemu_pipe",O_RDWR);
+ * write() or read() through the pipe.
+ *
+ * This driver doesn't deal with the exact protocol used during the session.
+ * It is intended to be as simple as something like:
+ *
+ *// do this _just_ after opening the fd to connect to a specific
+ *// emulator service.
+ *const char*  msg = "";
+ *if (write(fd, msg, strlen(msg)+1) < 0) {
+ *   ... could not connect to  service
+ *   close(fd);
+ *}
+ *
+ *// after this, simply read() and write() to communicate with the
+ *// service. Exact protocol details left as an exercise to the reader.
+ *
+ * This driver is very fast because it doesn't copy any data through
+ * intermediate buffers, since the emulator is capable of translating
+ * guest user addresses into host ones.
+ *
+ * Note that we must however ensure that each user page involved in the
+ * exchange is properly mapped during a transfer.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "goldfish_pipe_qemu.h"
+#include "goldfish_pipe.h"
+#include "goldfish_pipe_v2.h"
+
+/*
+ * Update this when something changes in the driver's behavior so the host
+ * can benefit from knowing it
+ * Notes:
+ * version 2 was an intermediate release and isn't supported anymore.
+ * version 3 is goldfish_pipe_v2 without DMA support.
+ * version 4 (current) is goldfish_pipe_v2 with DMA support.
+ */
+enum {
+   PIPE_DRIVER_VERSION = 4,
+   PIPE_CURRENT_DEVICE_VERSION = 2
+};
+
+static int goldfish_pipe_probe(struct platform_device *pdev)
+{
+   struct resource *r;
+   char __iomem *base;
+   int irq;
+   int version;
+
+   r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+   if (!r || resource_size(r) < PAGE_SIZE) {
+   dev_err(>dev, "can't allocate i/o page\n");
+   return -EINVAL;
+   }
+   base = devm_ioremap(>dev, r->start, PAGE_SIZE);
+   if (!base) {
+   dev_err(>dev, "ioremap failed\n");
+   return -EINVAL;
+   }
+
+   r = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
+   if (!r)
+   return -EINVAL;
+
+   irq = r->start;
+
+   /*
+* Exchange the versions with the host device
+*
+* Note: v1 driver used to not report its version, so we write it before
+*  reading device version back: this allows the host implementation to
+*  detect the old driver (if there was no version write before read).
+*/
+   writel((u32)PIPE_DRIVER_VERSION, base + PIPE_REG_VERSION);

[PATCH v2 13/21] platform: goldfish: pipe: Split the driver to v2 specific and the rest

2018-09-26 Thread rkir
From: Roman Kiryanov 

Move probe/remove and other driver stuff to a separate file
to plug v1 there later.

Signed-off-by: Roman Kiryanov 
---
Changes in v2:
 - Removed breakage of allmodconfig.

 drivers/platform/goldfish/Makefile   |   3 +-
 drivers/platform/goldfish/goldfish_pipe.c| 145 +++
 drivers/platform/goldfish/goldfish_pipe.h|  24 +++
 drivers/platform/goldfish/goldfish_pipe_v2.c | 102 ++---
 drivers/platform/goldfish/goldfish_pipe_v2.h |  24 +++
 5 files changed, 210 insertions(+), 88 deletions(-)
 create mode 100644 drivers/platform/goldfish/goldfish_pipe.c
 create mode 100644 drivers/platform/goldfish/goldfish_pipe.h
 create mode 100644 drivers/platform/goldfish/goldfish_pipe_v2.h

diff --git a/drivers/platform/goldfish/Makefile 
b/drivers/platform/goldfish/Makefile
index 81f899a987a2..016769e003d8 100644
--- a/drivers/platform/goldfish/Makefile
+++ b/drivers/platform/goldfish/Makefile
@@ -1,4 +1,5 @@
 #
 # Makefile for Goldfish platform specific drivers
 #
-obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe_v2.o
+obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe_all.o
+goldfish_pipe_all-objs := goldfish_pipe.o goldfish_pipe_v2.o
diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
new file mode 100644
index ..802bbf0d6d23
--- /dev/null
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -0,0 +1,145 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2012 Intel, Inc.
+ * Copyright (C) 2013 Intel, Inc.
+ * Copyright (C) 2014 Linaro Limited
+ * Copyright (C) 2011-2016 Google, Inc.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+/* This source file contains the implementation of a special device driver
+ * that intends to provide a *very* fast communication channel between the
+ * guest system and the QEMU emulator.
+ *
+ * Usage from the guest is simply the following (error handling simplified):
+ *
+ *int  fd = open("/dev/qemu_pipe",O_RDWR);
+ * write() or read() through the pipe.
+ *
+ * This driver doesn't deal with the exact protocol used during the session.
+ * It is intended to be as simple as something like:
+ *
+ *// do this _just_ after opening the fd to connect to a specific
+ *// emulator service.
+ *const char*  msg = "";
+ *if (write(fd, msg, strlen(msg)+1) < 0) {
+ *   ... could not connect to  service
+ *   close(fd);
+ *}
+ *
+ *// after this, simply read() and write() to communicate with the
+ *// service. Exact protocol details left as an exercise to the reader.
+ *
+ * This driver is very fast because it doesn't copy any data through
+ * intermediate buffers, since the emulator is capable of translating
+ * guest user addresses into host ones.
+ *
+ * Note that we must however ensure that each user page involved in the
+ * exchange is properly mapped during a transfer.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "goldfish_pipe_qemu.h"
+#include "goldfish_pipe.h"
+#include "goldfish_pipe_v2.h"
+
+/*
+ * Update this when something changes in the driver's behavior so the host
+ * can benefit from knowing it
+ * Notes:
+ * version 2 was an intermediate release and isn't supported anymore.
+ * version 3 is goldfish_pipe_v2 without DMA support.
+ * version 4 (current) is goldfish_pipe_v2 with DMA support.
+ */
+enum {
+   PIPE_DRIVER_VERSION = 4,
+   PIPE_CURRENT_DEVICE_VERSION = 2
+};
+
+static int goldfish_pipe_probe(struct platform_device *pdev)
+{
+   struct resource *r;
+   char __iomem *base;
+   int irq;
+   int version;
+
+   r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+   if (!r || resource_size(r) < PAGE_SIZE) {
+   dev_err(>dev, "can't allocate i/o page\n");
+   return -EINVAL;
+   }
+   base = devm_ioremap(>dev, r->start, PAGE_SIZE);
+   if (!base) {
+   dev_err(>dev, "ioremap failed\n");
+   return -EINVAL;
+   }
+
+   r = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
+   if (!r)
+   return -EINVAL;
+
+   irq = r->start;
+
+   /*
+* Exchange the versions with the host device
+*
+* Note: v1 driver used to not report its version, so we write it before
+*  reading device version back: this allows the host implementation to
+*  detect the old driver (if there was no version write before read).
+*/
+   writel((u32)PIPE_DRIVER_VERSION, base + PIPE_REG_VERSION);

[PATCH v2 19/21] platform: goldfish: pipe: Add the goldfish_pipe_v1 driver

2018-09-26 Thread rkir
From: Roman Kiryanov 

This is the v1 goldfish pipe driver.

Signed-off-by: Roman Kiryanov 
---
Changes in v2:
 - Rebased (Makefile).

 drivers/platform/goldfish/Makefile|   2 +-
 drivers/platform/goldfish/goldfish_pipe.c |   9 +-
 .../platform/goldfish/goldfish_pipe_qemu.h|  27 +
 drivers/platform/goldfish/goldfish_pipe_v1.c  | 632 ++
 drivers/platform/goldfish/goldfish_pipe_v1.h  |  24 +
 5 files changed, 689 insertions(+), 5 deletions(-)
 create mode 100644 drivers/platform/goldfish/goldfish_pipe_v1.c
 create mode 100644 drivers/platform/goldfish/goldfish_pipe_v1.h

diff --git a/drivers/platform/goldfish/Makefile 
b/drivers/platform/goldfish/Makefile
index 016769e003d8..3fb7427b9dd8 100644
--- a/drivers/platform/goldfish/Makefile
+++ b/drivers/platform/goldfish/Makefile
@@ -2,4 +2,4 @@
 # Makefile for Goldfish platform specific drivers
 #
 obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe_all.o
-goldfish_pipe_all-objs := goldfish_pipe.o goldfish_pipe_v2.o
+goldfish_pipe_all-objs := goldfish_pipe.o goldfish_pipe_v1.o goldfish_pipe_v2.o
diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index d963b7485ce5..e45e262517a0 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -56,6 +56,7 @@
 #include 
 #include "goldfish_pipe_qemu.h"
 #include "goldfish_pipe.h"
+#include "goldfish_pipe_v1.h"
 #include "goldfish_pipe_v2.h"
 
 /*
@@ -105,10 +106,10 @@ static int goldfish_pipe_probe(struct platform_device 
*pdev)
writel((u32)PIPE_DRIVER_VERSION, base + PIPE_V2_REG_VERSION);
version = readl(base + PIPE_V2_REG_VERSION);
 
-   if (WARN_ON(version < PIPE_CURRENT_DEVICE_VERSION))
-   return -EINVAL;
-
-   return goldfish_pipe_device_v2_init(pdev, base, irq);
+   if (version < PIPE_CURRENT_DEVICE_VERSION)
+   return goldfish_pipe_device_v1_init(pdev, base, irq);
+   else
+   return goldfish_pipe_device_v2_init(pdev, base, irq);
 }
 
 static int goldfish_pipe_remove(struct platform_device *pdev)
diff --git a/drivers/platform/goldfish/goldfish_pipe_qemu.h 
b/drivers/platform/goldfish/goldfish_pipe_qemu.h
index 599b69f0baa1..ed2c7938fede 100644
--- a/drivers/platform/goldfish/goldfish_pipe_qemu.h
+++ b/drivers/platform/goldfish/goldfish_pipe_qemu.h
@@ -62,6 +62,33 @@ enum PipeFlagsBits {
BIT_WAKE_ON_READ   = 2,  /* want to be woken on reads */
 };
 
+enum PipeV1Regs {
+   /* write: value = command */
+   PIPE_V1_REG_COMMAND = 0x00,
+   /* read */
+   PIPE_V1_REG_STATUS  = 0x04,
+   /* read/write: channel id */
+   PIPE_V1_REG_CHANNEL = 0x08,
+   /* read/write: channel id */
+   PIPE_V1_REG_CHANNEL_HIGH= 0x30,
+   /* read/write: buffer size */
+   PIPE_V1_REG_SIZE= 0x0C,
+   /* write: physical address */
+   PIPE_V1_REG_ADDRESS = 0x10,
+   /* write: physical address */
+   PIPE_V1_REG_ADDRESS_HIGH= 0x34,
+   /* read: wake flags */
+   PIPE_V1_REG_WAKES   = 0x14,
+   /* read/write: batch data address */
+   PIPE_V1_REG_PARAMS_ADDR_LOW = 0x18,
+   /* read/write: batch data address */
+   PIPE_V1_REG_PARAMS_ADDR_HIGH= 0x1C,
+   /* write: batch access */
+   PIPE_V1_REG_ACCESS_PARAMS   = 0x20,
+   /* read: device version */
+   PIPE_V1_REG_VERSION = 0x24,
+};
+
 enum PipeV2Regs {
PIPE_V2_REG_CMD = 0,
 
diff --git a/drivers/platform/goldfish/goldfish_pipe_v1.c 
b/drivers/platform/goldfish/goldfish_pipe_v1.c
new file mode 100644
index ..6e603204dd62
--- /dev/null
+++ b/drivers/platform/goldfish/goldfish_pipe_v1.c
@@ -0,0 +1,632 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2011 Google, Inc.
+ * Copyright (C) 2012 Intel, Inc.
+ * Copyright (C) 2013 Intel, Inc.
+ * Copyright (C) 2014 Linaro Limited
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+/* This source file contains the implementation of the legacy version of
+ * a goldfish pipe device driver. See goldfish_pipe_v2.c for the current
+ * version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "goldfish_pipe_qemu.h"
+#include "goldfish_pipe.h"
+
+#define MAX_PAGES_TO_GRAB 32
+
+/* A value that will not be set by qemu emulator */
+#define INITIAL_BATCH_RESULT (0xdeadbeaf)
+

[PATCH v2 19/21] platform: goldfish: pipe: Add the goldfish_pipe_v1 driver

2018-09-26 Thread rkir
From: Roman Kiryanov 

This is the v1 goldfish pipe driver.

Signed-off-by: Roman Kiryanov 
---
Changes in v2:
 - Rebased (Makefile).

 drivers/platform/goldfish/Makefile|   2 +-
 drivers/platform/goldfish/goldfish_pipe.c |   9 +-
 .../platform/goldfish/goldfish_pipe_qemu.h|  27 +
 drivers/platform/goldfish/goldfish_pipe_v1.c  | 632 ++
 drivers/platform/goldfish/goldfish_pipe_v1.h  |  24 +
 5 files changed, 689 insertions(+), 5 deletions(-)
 create mode 100644 drivers/platform/goldfish/goldfish_pipe_v1.c
 create mode 100644 drivers/platform/goldfish/goldfish_pipe_v1.h

diff --git a/drivers/platform/goldfish/Makefile 
b/drivers/platform/goldfish/Makefile
index 016769e003d8..3fb7427b9dd8 100644
--- a/drivers/platform/goldfish/Makefile
+++ b/drivers/platform/goldfish/Makefile
@@ -2,4 +2,4 @@
 # Makefile for Goldfish platform specific drivers
 #
 obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe_all.o
-goldfish_pipe_all-objs := goldfish_pipe.o goldfish_pipe_v2.o
+goldfish_pipe_all-objs := goldfish_pipe.o goldfish_pipe_v1.o goldfish_pipe_v2.o
diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index d963b7485ce5..e45e262517a0 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -56,6 +56,7 @@
 #include 
 #include "goldfish_pipe_qemu.h"
 #include "goldfish_pipe.h"
+#include "goldfish_pipe_v1.h"
 #include "goldfish_pipe_v2.h"
 
 /*
@@ -105,10 +106,10 @@ static int goldfish_pipe_probe(struct platform_device 
*pdev)
writel((u32)PIPE_DRIVER_VERSION, base + PIPE_V2_REG_VERSION);
version = readl(base + PIPE_V2_REG_VERSION);
 
-   if (WARN_ON(version < PIPE_CURRENT_DEVICE_VERSION))
-   return -EINVAL;
-
-   return goldfish_pipe_device_v2_init(pdev, base, irq);
+   if (version < PIPE_CURRENT_DEVICE_VERSION)
+   return goldfish_pipe_device_v1_init(pdev, base, irq);
+   else
+   return goldfish_pipe_device_v2_init(pdev, base, irq);
 }
 
 static int goldfish_pipe_remove(struct platform_device *pdev)
diff --git a/drivers/platform/goldfish/goldfish_pipe_qemu.h 
b/drivers/platform/goldfish/goldfish_pipe_qemu.h
index 599b69f0baa1..ed2c7938fede 100644
--- a/drivers/platform/goldfish/goldfish_pipe_qemu.h
+++ b/drivers/platform/goldfish/goldfish_pipe_qemu.h
@@ -62,6 +62,33 @@ enum PipeFlagsBits {
BIT_WAKE_ON_READ   = 2,  /* want to be woken on reads */
 };
 
+enum PipeV1Regs {
+   /* write: value = command */
+   PIPE_V1_REG_COMMAND = 0x00,
+   /* read */
+   PIPE_V1_REG_STATUS  = 0x04,
+   /* read/write: channel id */
+   PIPE_V1_REG_CHANNEL = 0x08,
+   /* read/write: channel id */
+   PIPE_V1_REG_CHANNEL_HIGH= 0x30,
+   /* read/write: buffer size */
+   PIPE_V1_REG_SIZE= 0x0C,
+   /* write: physical address */
+   PIPE_V1_REG_ADDRESS = 0x10,
+   /* write: physical address */
+   PIPE_V1_REG_ADDRESS_HIGH= 0x34,
+   /* read: wake flags */
+   PIPE_V1_REG_WAKES   = 0x14,
+   /* read/write: batch data address */
+   PIPE_V1_REG_PARAMS_ADDR_LOW = 0x18,
+   /* read/write: batch data address */
+   PIPE_V1_REG_PARAMS_ADDR_HIGH= 0x1C,
+   /* write: batch access */
+   PIPE_V1_REG_ACCESS_PARAMS   = 0x20,
+   /* read: device version */
+   PIPE_V1_REG_VERSION = 0x24,
+};
+
 enum PipeV2Regs {
PIPE_V2_REG_CMD = 0,
 
diff --git a/drivers/platform/goldfish/goldfish_pipe_v1.c 
b/drivers/platform/goldfish/goldfish_pipe_v1.c
new file mode 100644
index ..6e603204dd62
--- /dev/null
+++ b/drivers/platform/goldfish/goldfish_pipe_v1.c
@@ -0,0 +1,632 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2011 Google, Inc.
+ * Copyright (C) 2012 Intel, Inc.
+ * Copyright (C) 2013 Intel, Inc.
+ * Copyright (C) 2014 Linaro Limited
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+/* This source file contains the implementation of the legacy version of
+ * a goldfish pipe device driver. See goldfish_pipe_v2.c for the current
+ * version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "goldfish_pipe_qemu.h"
+#include "goldfish_pipe.h"
+
+#define MAX_PAGES_TO_GRAB 32
+
+/* A value that will not be set by qemu emulator */
+#define INITIAL_BATCH_RESULT (0xdeadbeaf)
+

[PATCH v2 09/21] platform: goldfish: pipe: Remove the goldfish_pipe_dev global variable

2018-09-26 Thread rkir
From: Roman Kiryanov 

This is the last patch in the series of patches to remove mutable
global variables to introduce another version of the pipe driver
for the older host interface. I don't want to have two driver
states where only one is used.

Signed-off-by: Roman Kiryanov 
---
Changes in v2:
 - Rebased to address that goldfish_pipe_dev is static now.

 drivers/platform/goldfish/goldfish_pipe.c | 66 +--
 1 file changed, 37 insertions(+), 29 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index b0cf4e59c0ec..c68035be4389 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -202,6 +202,9 @@ struct goldfish_pipe {
  * waiting to be awoken.
  */
 struct goldfish_pipe_dev {
+   /* A magic number to check if this is an instance of this struct */
+   void *magic;
+
/*
 * Global device spinlock. Protects the following members:
 *  - pipes, pipes_capacity
@@ -251,8 +254,6 @@ struct goldfish_pipe_dev {
size_t dma_alloc_total;
 };
 
-static struct goldfish_pipe_dev goldfish_pipe_dev;
-
 static int goldfish_pipe_cmd_locked(struct goldfish_pipe *pipe,
enum PipeCmdCode cmd)
 {
@@ -647,6 +648,9 @@ static void goldfish_interrupt_task(unsigned long dev_addr)
}
 }
 
+static void goldfish_pipe_device_deinit(struct platform_device *pdev,
+   struct goldfish_pipe_dev *dev);
+
 /*
  * The general idea of the interrupt handling:
  *
@@ -667,7 +671,7 @@ static irqreturn_t goldfish_pipe_interrupt(int irq, void 
*dev_id)
unsigned long flags;
struct goldfish_pipe_dev *dev = dev_id;
 
-   if (dev != _pipe_dev)
+   if (dev->magic != _pipe_device_deinit)
return IRQ_NONE;
 
/* Request the signalled pipes from the device */
@@ -719,6 +723,14 @@ static int get_free_pipe_id_locked(struct 
goldfish_pipe_dev *dev)
return id;
 }
 
+/* A helper function to get the instance of goldfish_pipe_dev from file */
+static struct goldfish_pipe_dev *to_goldfish_pipe_dev(struct file *file)
+{
+   struct miscdevice *miscdev = file->private_data;
+
+   return container_of(miscdev, struct goldfish_pipe_dev, miscdev);
+}
+
 /**
  * goldfish_pipe_open - open a channel to the AVD
  * @inode: inode of device
@@ -732,7 +744,7 @@ static int get_free_pipe_id_locked(struct goldfish_pipe_dev 
*dev)
  */
 static int goldfish_pipe_open(struct inode *inode, struct file *file)
 {
-   struct goldfish_pipe_dev *dev = _pipe_dev;
+   struct goldfish_pipe_dev *dev = to_goldfish_pipe_dev(file);
unsigned long flags;
int id;
int status;
@@ -1112,9 +1124,9 @@ static void write_pa_addr(void *addr, void __iomem 
*portl, void __iomem *porth)
writel(lower_32_bits(paddr), portl);
 }
 
-static int goldfish_pipe_device_init(struct platform_device *pdev)
+static int goldfish_pipe_device_init(struct platform_device *pdev,
+struct goldfish_pipe_dev *dev)
 {
-   struct goldfish_pipe_dev *dev = _pipe_dev;
int err;
 
tasklet_init(>irq_tasklet, _interrupt_task,
@@ -1169,26 +1181,29 @@ static int goldfish_pipe_device_init(struct 
platform_device *pdev)
  dev->base + PIPE_REG_OPEN_BUFFER,
  dev->base + PIPE_REG_OPEN_BUFFER_HIGH);
 
+   platform_set_drvdata(pdev, dev);
return 0;
 }
 
-static void goldfish_pipe_device_deinit(struct platform_device *pdev)
+static void goldfish_pipe_device_deinit(struct platform_device *pdev,
+   struct goldfish_pipe_dev *dev)
 {
-   misc_deregister(_pipe_dev.miscdev);
-   tasklet_kill(_pipe_dev.irq_tasklet);
-   kfree(goldfish_pipe_dev.pipes);
-   free_page((unsigned long)goldfish_pipe_dev.buffers);
+   misc_deregister(>miscdev);
+   tasklet_kill(>irq_tasklet);
+   kfree(dev->pipes);
+   free_page((unsigned long)dev->buffers);
 }
 
 static int goldfish_pipe_probe(struct platform_device *pdev)
 {
-   int err;
struct resource *r;
-   struct goldfish_pipe_dev *dev = _pipe_dev;
+   struct goldfish_pipe_dev *dev;
 
-   /* not thread safe, but this should not happen */
-   WARN_ON(dev->base);
+   dev = devm_kzalloc(>dev, sizeof(*dev), GFP_KERNEL);
+   if (!dev)
+   return -ENOMEM;
 
+   dev->magic = _pipe_device_deinit;
spin_lock_init(>lock);
 
r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -1203,10 +1218,9 @@ static int goldfish_pipe_probe(struct platform_device 
*pdev)
}
 
r = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
-   if (!r) {
-   err = -EINVAL;
-   goto error;
-   }
+   if (!r)
+   return -EINVAL;
+
dev->irq = r->start;
 
/*
@@ -1221,20 +1235,14 @@ static int 

[PATCH v2 06/21] platform: goldfish: pipe: Add DMA support to goldfish pipe

2018-09-26 Thread rkir
From: Roman Kiryanov 

Goldfish DMA is an extension to the pipe device and is designed
to facilitate high-speed RAM->RAM transfers from guest to host.

See uapi/linux/goldfish/goldfish_dma.h for more details.

Signed-off-by: Roman Kiryanov 
Signed-off-by: Lingfeng Yang 
---
Changes in v2:
 - Got sign-off from Lingfeng Yang.
 - Removed the license boilerplate from goldfish_dma.h.
 - Rebased.

 drivers/platform/goldfish/goldfish_pipe.c | 312 +-
 .../platform/goldfish/goldfish_pipe_qemu.h|   2 +
 include/uapi/linux/goldfish/goldfish_dma.h|  71 
 3 files changed, 383 insertions(+), 2 deletions(-)
 create mode 100644 include/uapi/linux/goldfish/goldfish_dma.h

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index 56665e879e5a..7eb5436d7c35 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -63,21 +63,28 @@
 #include 
 #include 
 #include 
+#include 
 #include "goldfish_pipe_qemu.h"
 
 /*
  * Update this when something changes in the driver's behavior so the host
  * can benefit from knowing it
+ * Notes:
+ * version 2 was an intermediate release and isn't supported anymore.
+ * version 3 is goldfish_pipe_v2 without DMA support.
+ * version 4 (current) is goldfish_pipe_v2 with DMA support.
  */
 enum {
-   PIPE_DRIVER_VERSION = 2,
+   PIPE_DRIVER_VERSION = 4,
PIPE_CURRENT_DEVICE_VERSION = 2
 };
 
 enum {
MAX_BUFFERS_PER_COMMAND = 336,
MAX_SIGNALLED_PIPES = 64,
-   INITIAL_PIPES_CAPACITY = 64
+   INITIAL_PIPES_CAPACITY = 64,
+   DMA_REGION_MIN_SIZE = PAGE_SIZE,
+   DMA_REGION_MAX_SIZE = 256 << 20
 };
 
 struct goldfish_pipe_dev;
@@ -100,6 +107,11 @@ struct goldfish_pipe_command {
/* buffer sizes, guest -> host */
u32 sizes[MAX_BUFFERS_PER_COMMAND];
} rw_params;
+   /* Parameters for PIPE_CMD_DMA_HOST_(UN)MAP */
+   struct {
+   u64 dma_paddr;
+   u64 sz;
+   } dma_maphost_params;
};
 };
 
@@ -122,6 +134,24 @@ struct goldfish_pipe_dev_buffers {
signalled_pipe_buffers[MAX_SIGNALLED_PIPES];
 };
 
+/*
+ * The main data structure tracking state is
+ * struct goldfish_dma_context, which is included
+ * as an extra pointer field in struct goldfish_pipe.
+ * Each such context is associated with possibly
+ * one physical address and size describing the
+ * allocated DMA region, and only one allocation
+ * is allowed for each pipe fd. Further allocations
+ * require more open()'s of pipe fd's.
+ */
+struct goldfish_dma_context {
+   struct device *pdev_dev;/* pointer to feed to dma_*_coherent */
+   void *dma_vaddr;/* kernel vaddr of dma region */
+   size_t dma_size;/* size of dma region */
+   dma_addr_t phys_begin;  /* paddr of dma region */
+   dma_addr_t phys_end;/* paddr of dma region + dma_size */
+};
+
 /* This data type models a given pipe instance */
 struct goldfish_pipe {
/* pipe ID - index into goldfish_pipe_dev::pipes array */
@@ -162,6 +192,9 @@ struct goldfish_pipe {
 
/* A buffer of pages, too large to fit into a stack frame */
struct page *pages[MAX_BUFFERS_PER_COMMAND];
+
+   /* Holds information about reserved DMA region for this pipe */
+   struct goldfish_dma_context *dma;
 };
 
 /* The global driver data. Holds a reference to the i/o page used to
@@ -208,6 +241,9 @@ struct goldfish_pipe_dev {
int irq;
int version;
unsigned char __iomem *base;
+
+   /* DMA info */
+   size_t dma_alloc_total;
 };
 
 static struct goldfish_pipe_dev goldfish_pipe_dev;
@@ -739,6 +775,8 @@ static int goldfish_pipe_open(struct inode *inode, struct 
file *file)
spin_unlock_irqrestore(>lock, flags);
if (status < 0)
goto err_cmd;
+   pipe->dma = NULL;
+
/* All is done, save the pipe into the file's private data field */
file->private_data = pipe;
return 0;
@@ -754,6 +792,40 @@ static int goldfish_pipe_open(struct inode *inode, struct 
file *file)
return status;
 }
 
+static void goldfish_pipe_dma_release_host(struct goldfish_pipe *pipe)
+{
+   struct goldfish_dma_context *dma = pipe->dma;
+   struct device *pdev_dev;
+
+   if (!dma)
+   return;
+
+   pdev_dev = pipe->dev->pdev_dev;
+
+   if (dma->dma_vaddr) {
+   pipe->command_buffer->dma_maphost_params.dma_paddr =
+   dma->phys_begin;
+   pipe->command_buffer->dma_maphost_params.sz = dma->dma_size;
+   goldfish_pipe_cmd(pipe, PIPE_CMD_DMA_HOST_UNMAP);
+   }
+}
+
+static void goldfish_pipe_dma_release_guest(struct goldfish_pipe *pipe)
+{
+   struct goldfish_dma_context *dma = pipe->dma;
+
+   if (!dma)
+   

[PATCH v2 09/21] platform: goldfish: pipe: Remove the goldfish_pipe_dev global variable

2018-09-26 Thread rkir
From: Roman Kiryanov 

This is the last patch in the series of patches to remove mutable
global variables to introduce another version of the pipe driver
for the older host interface. I don't want to have two driver
states where only one is used.

Signed-off-by: Roman Kiryanov 
---
Changes in v2:
 - Rebased to address that goldfish_pipe_dev is static now.

 drivers/platform/goldfish/goldfish_pipe.c | 66 +--
 1 file changed, 37 insertions(+), 29 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index b0cf4e59c0ec..c68035be4389 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -202,6 +202,9 @@ struct goldfish_pipe {
  * waiting to be awoken.
  */
 struct goldfish_pipe_dev {
+   /* A magic number to check if this is an instance of this struct */
+   void *magic;
+
/*
 * Global device spinlock. Protects the following members:
 *  - pipes, pipes_capacity
@@ -251,8 +254,6 @@ struct goldfish_pipe_dev {
size_t dma_alloc_total;
 };
 
-static struct goldfish_pipe_dev goldfish_pipe_dev;
-
 static int goldfish_pipe_cmd_locked(struct goldfish_pipe *pipe,
enum PipeCmdCode cmd)
 {
@@ -647,6 +648,9 @@ static void goldfish_interrupt_task(unsigned long dev_addr)
}
 }
 
+static void goldfish_pipe_device_deinit(struct platform_device *pdev,
+   struct goldfish_pipe_dev *dev);
+
 /*
  * The general idea of the interrupt handling:
  *
@@ -667,7 +671,7 @@ static irqreturn_t goldfish_pipe_interrupt(int irq, void 
*dev_id)
unsigned long flags;
struct goldfish_pipe_dev *dev = dev_id;
 
-   if (dev != _pipe_dev)
+   if (dev->magic != _pipe_device_deinit)
return IRQ_NONE;
 
/* Request the signalled pipes from the device */
@@ -719,6 +723,14 @@ static int get_free_pipe_id_locked(struct 
goldfish_pipe_dev *dev)
return id;
 }
 
+/* A helper function to get the instance of goldfish_pipe_dev from file */
+static struct goldfish_pipe_dev *to_goldfish_pipe_dev(struct file *file)
+{
+   struct miscdevice *miscdev = file->private_data;
+
+   return container_of(miscdev, struct goldfish_pipe_dev, miscdev);
+}
+
 /**
  * goldfish_pipe_open - open a channel to the AVD
  * @inode: inode of device
@@ -732,7 +744,7 @@ static int get_free_pipe_id_locked(struct goldfish_pipe_dev 
*dev)
  */
 static int goldfish_pipe_open(struct inode *inode, struct file *file)
 {
-   struct goldfish_pipe_dev *dev = _pipe_dev;
+   struct goldfish_pipe_dev *dev = to_goldfish_pipe_dev(file);
unsigned long flags;
int id;
int status;
@@ -1112,9 +1124,9 @@ static void write_pa_addr(void *addr, void __iomem 
*portl, void __iomem *porth)
writel(lower_32_bits(paddr), portl);
 }
 
-static int goldfish_pipe_device_init(struct platform_device *pdev)
+static int goldfish_pipe_device_init(struct platform_device *pdev,
+struct goldfish_pipe_dev *dev)
 {
-   struct goldfish_pipe_dev *dev = _pipe_dev;
int err;
 
tasklet_init(>irq_tasklet, _interrupt_task,
@@ -1169,26 +1181,29 @@ static int goldfish_pipe_device_init(struct 
platform_device *pdev)
  dev->base + PIPE_REG_OPEN_BUFFER,
  dev->base + PIPE_REG_OPEN_BUFFER_HIGH);
 
+   platform_set_drvdata(pdev, dev);
return 0;
 }
 
-static void goldfish_pipe_device_deinit(struct platform_device *pdev)
+static void goldfish_pipe_device_deinit(struct platform_device *pdev,
+   struct goldfish_pipe_dev *dev)
 {
-   misc_deregister(_pipe_dev.miscdev);
-   tasklet_kill(_pipe_dev.irq_tasklet);
-   kfree(goldfish_pipe_dev.pipes);
-   free_page((unsigned long)goldfish_pipe_dev.buffers);
+   misc_deregister(>miscdev);
+   tasklet_kill(>irq_tasklet);
+   kfree(dev->pipes);
+   free_page((unsigned long)dev->buffers);
 }
 
 static int goldfish_pipe_probe(struct platform_device *pdev)
 {
-   int err;
struct resource *r;
-   struct goldfish_pipe_dev *dev = _pipe_dev;
+   struct goldfish_pipe_dev *dev;
 
-   /* not thread safe, but this should not happen */
-   WARN_ON(dev->base);
+   dev = devm_kzalloc(>dev, sizeof(*dev), GFP_KERNEL);
+   if (!dev)
+   return -ENOMEM;
 
+   dev->magic = _pipe_device_deinit;
spin_lock_init(>lock);
 
r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -1203,10 +1218,9 @@ static int goldfish_pipe_probe(struct platform_device 
*pdev)
}
 
r = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
-   if (!r) {
-   err = -EINVAL;
-   goto error;
-   }
+   if (!r)
+   return -EINVAL;
+
dev->irq = r->start;
 
/*
@@ -1221,20 +1235,14 @@ static int 

[PATCH v2 06/21] platform: goldfish: pipe: Add DMA support to goldfish pipe

2018-09-26 Thread rkir
From: Roman Kiryanov 

Goldfish DMA is an extension to the pipe device and is designed
to facilitate high-speed RAM->RAM transfers from guest to host.

See uapi/linux/goldfish/goldfish_dma.h for more details.

Signed-off-by: Roman Kiryanov 
Signed-off-by: Lingfeng Yang 
---
Changes in v2:
 - Got sign-off from Lingfeng Yang.
 - Removed the license boilerplate from goldfish_dma.h.
 - Rebased.

 drivers/platform/goldfish/goldfish_pipe.c | 312 +-
 .../platform/goldfish/goldfish_pipe_qemu.h|   2 +
 include/uapi/linux/goldfish/goldfish_dma.h|  71 
 3 files changed, 383 insertions(+), 2 deletions(-)
 create mode 100644 include/uapi/linux/goldfish/goldfish_dma.h

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index 56665e879e5a..7eb5436d7c35 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -63,21 +63,28 @@
 #include 
 #include 
 #include 
+#include 
 #include "goldfish_pipe_qemu.h"
 
 /*
  * Update this when something changes in the driver's behavior so the host
  * can benefit from knowing it
+ * Notes:
+ * version 2 was an intermediate release and isn't supported anymore.
+ * version 3 is goldfish_pipe_v2 without DMA support.
+ * version 4 (current) is goldfish_pipe_v2 with DMA support.
  */
 enum {
-   PIPE_DRIVER_VERSION = 2,
+   PIPE_DRIVER_VERSION = 4,
PIPE_CURRENT_DEVICE_VERSION = 2
 };
 
 enum {
MAX_BUFFERS_PER_COMMAND = 336,
MAX_SIGNALLED_PIPES = 64,
-   INITIAL_PIPES_CAPACITY = 64
+   INITIAL_PIPES_CAPACITY = 64,
+   DMA_REGION_MIN_SIZE = PAGE_SIZE,
+   DMA_REGION_MAX_SIZE = 256 << 20
 };
 
 struct goldfish_pipe_dev;
@@ -100,6 +107,11 @@ struct goldfish_pipe_command {
/* buffer sizes, guest -> host */
u32 sizes[MAX_BUFFERS_PER_COMMAND];
} rw_params;
+   /* Parameters for PIPE_CMD_DMA_HOST_(UN)MAP */
+   struct {
+   u64 dma_paddr;
+   u64 sz;
+   } dma_maphost_params;
};
 };
 
@@ -122,6 +134,24 @@ struct goldfish_pipe_dev_buffers {
signalled_pipe_buffers[MAX_SIGNALLED_PIPES];
 };
 
+/*
+ * The main data structure tracking state is
+ * struct goldfish_dma_context, which is included
+ * as an extra pointer field in struct goldfish_pipe.
+ * Each such context is associated with possibly
+ * one physical address and size describing the
+ * allocated DMA region, and only one allocation
+ * is allowed for each pipe fd. Further allocations
+ * require more open()'s of pipe fd's.
+ */
+struct goldfish_dma_context {
+   struct device *pdev_dev;/* pointer to feed to dma_*_coherent */
+   void *dma_vaddr;/* kernel vaddr of dma region */
+   size_t dma_size;/* size of dma region */
+   dma_addr_t phys_begin;  /* paddr of dma region */
+   dma_addr_t phys_end;/* paddr of dma region + dma_size */
+};
+
 /* This data type models a given pipe instance */
 struct goldfish_pipe {
/* pipe ID - index into goldfish_pipe_dev::pipes array */
@@ -162,6 +192,9 @@ struct goldfish_pipe {
 
/* A buffer of pages, too large to fit into a stack frame */
struct page *pages[MAX_BUFFERS_PER_COMMAND];
+
+   /* Holds information about reserved DMA region for this pipe */
+   struct goldfish_dma_context *dma;
 };
 
 /* The global driver data. Holds a reference to the i/o page used to
@@ -208,6 +241,9 @@ struct goldfish_pipe_dev {
int irq;
int version;
unsigned char __iomem *base;
+
+   /* DMA info */
+   size_t dma_alloc_total;
 };
 
 static struct goldfish_pipe_dev goldfish_pipe_dev;
@@ -739,6 +775,8 @@ static int goldfish_pipe_open(struct inode *inode, struct 
file *file)
spin_unlock_irqrestore(>lock, flags);
if (status < 0)
goto err_cmd;
+   pipe->dma = NULL;
+
/* All is done, save the pipe into the file's private data field */
file->private_data = pipe;
return 0;
@@ -754,6 +792,40 @@ static int goldfish_pipe_open(struct inode *inode, struct 
file *file)
return status;
 }
 
+static void goldfish_pipe_dma_release_host(struct goldfish_pipe *pipe)
+{
+   struct goldfish_dma_context *dma = pipe->dma;
+   struct device *pdev_dev;
+
+   if (!dma)
+   return;
+
+   pdev_dev = pipe->dev->pdev_dev;
+
+   if (dma->dma_vaddr) {
+   pipe->command_buffer->dma_maphost_params.dma_paddr =
+   dma->phys_begin;
+   pipe->command_buffer->dma_maphost_params.sz = dma->dma_size;
+   goldfish_pipe_cmd(pipe, PIPE_CMD_DMA_HOST_UNMAP);
+   }
+}
+
+static void goldfish_pipe_dma_release_guest(struct goldfish_pipe *pipe)
+{
+   struct goldfish_dma_context *dma = pipe->dma;
+
+   if (!dma)
+   

[PATCH 20/21] platform: goldfish: pipe: Remove redundant casting

2018-09-14 Thread rkir
From: Roman Kiryanov 

This casting is not required.

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/goldfish_pipe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index e45e262517a0..f6c144e71c30 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -103,7 +103,7 @@ static int goldfish_pipe_probe(struct platform_device *pdev)
 *  reading device version back: this allows the host implementation to
 *  detect the old driver (if there was no version write before read).
 */
-   writel((u32)PIPE_DRIVER_VERSION, base + PIPE_V2_REG_VERSION);
+   writel(PIPE_DRIVER_VERSION, base + PIPE_V2_REG_VERSION);
version = readl(base + PIPE_V2_REG_VERSION);
 
if (version < PIPE_CURRENT_DEVICE_VERSION)
-- 
2.19.0.397.gdd90340f6a-goog



[PATCH 19/21] platform: goldfish: pipe: Add the goldfish_pipe_v1 driver

2018-09-14 Thread rkir
From: Roman Kiryanov 

This is the v1 goldfish pipe driver.

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/Makefile|   3 +-
 drivers/platform/goldfish/goldfish_pipe.c |   9 +-
 .../platform/goldfish/goldfish_pipe_qemu.h|  27 +
 drivers/platform/goldfish/goldfish_pipe_v1.c  | 632 ++
 drivers/platform/goldfish/goldfish_pipe_v1.h  |  24 +
 5 files changed, 690 insertions(+), 5 deletions(-)
 create mode 100644 drivers/platform/goldfish/goldfish_pipe_v1.c
 create mode 100644 drivers/platform/goldfish/goldfish_pipe_v1.h

diff --git a/drivers/platform/goldfish/Makefile 
b/drivers/platform/goldfish/Makefile
index 6a9f6e6de46d..acb105dbd9fd 100644
--- a/drivers/platform/goldfish/Makefile
+++ b/drivers/platform/goldfish/Makefile
@@ -1,4 +1,5 @@
 #
 # Makefile for Goldfish platform specific drivers
 #
-obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe.o goldfish_pipe_v2.o
+obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe.o \
+   goldfish_pipe_v1.o goldfish_pipe_v2.o
diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index d963b7485ce5..e45e262517a0 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -56,6 +56,7 @@
 #include 
 #include "goldfish_pipe_qemu.h"
 #include "goldfish_pipe.h"
+#include "goldfish_pipe_v1.h"
 #include "goldfish_pipe_v2.h"
 
 /*
@@ -105,10 +106,10 @@ static int goldfish_pipe_probe(struct platform_device 
*pdev)
writel((u32)PIPE_DRIVER_VERSION, base + PIPE_V2_REG_VERSION);
version = readl(base + PIPE_V2_REG_VERSION);
 
-   if (WARN_ON(version < PIPE_CURRENT_DEVICE_VERSION))
-   return -EINVAL;
-
-   return goldfish_pipe_device_v2_init(pdev, base, irq);
+   if (version < PIPE_CURRENT_DEVICE_VERSION)
+   return goldfish_pipe_device_v1_init(pdev, base, irq);
+   else
+   return goldfish_pipe_device_v2_init(pdev, base, irq);
 }
 
 static int goldfish_pipe_remove(struct platform_device *pdev)
diff --git a/drivers/platform/goldfish/goldfish_pipe_qemu.h 
b/drivers/platform/goldfish/goldfish_pipe_qemu.h
index 599b69f0baa1..ed2c7938fede 100644
--- a/drivers/platform/goldfish/goldfish_pipe_qemu.h
+++ b/drivers/platform/goldfish/goldfish_pipe_qemu.h
@@ -62,6 +62,33 @@ enum PipeFlagsBits {
BIT_WAKE_ON_READ   = 2,  /* want to be woken on reads */
 };
 
+enum PipeV1Regs {
+   /* write: value = command */
+   PIPE_V1_REG_COMMAND = 0x00,
+   /* read */
+   PIPE_V1_REG_STATUS  = 0x04,
+   /* read/write: channel id */
+   PIPE_V1_REG_CHANNEL = 0x08,
+   /* read/write: channel id */
+   PIPE_V1_REG_CHANNEL_HIGH= 0x30,
+   /* read/write: buffer size */
+   PIPE_V1_REG_SIZE= 0x0C,
+   /* write: physical address */
+   PIPE_V1_REG_ADDRESS = 0x10,
+   /* write: physical address */
+   PIPE_V1_REG_ADDRESS_HIGH= 0x34,
+   /* read: wake flags */
+   PIPE_V1_REG_WAKES   = 0x14,
+   /* read/write: batch data address */
+   PIPE_V1_REG_PARAMS_ADDR_LOW = 0x18,
+   /* read/write: batch data address */
+   PIPE_V1_REG_PARAMS_ADDR_HIGH= 0x1C,
+   /* write: batch access */
+   PIPE_V1_REG_ACCESS_PARAMS   = 0x20,
+   /* read: device version */
+   PIPE_V1_REG_VERSION = 0x24,
+};
+
 enum PipeV2Regs {
PIPE_V2_REG_CMD = 0,
 
diff --git a/drivers/platform/goldfish/goldfish_pipe_v1.c 
b/drivers/platform/goldfish/goldfish_pipe_v1.c
new file mode 100644
index ..6e603204dd62
--- /dev/null
+++ b/drivers/platform/goldfish/goldfish_pipe_v1.c
@@ -0,0 +1,632 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2011 Google, Inc.
+ * Copyright (C) 2012 Intel, Inc.
+ * Copyright (C) 2013 Intel, Inc.
+ * Copyright (C) 2014 Linaro Limited
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+/* This source file contains the implementation of the legacy version of
+ * a goldfish pipe device driver. See goldfish_pipe_v2.c for the current
+ * version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "goldfish_pipe_qemu.h"
+#include "goldfish_pipe.h"
+
+#define MAX_PAGES_TO_GRAB 32
+
+/* A value that will not be set by qemu emulator */
+#define INITIAL_BATCH_RESULT (0xdeadbeaf)
+
+struct goldfish_pipe_dev;
+
+/* This data type models a given pipe 

[PATCH 20/21] platform: goldfish: pipe: Remove redundant casting

2018-09-14 Thread rkir
From: Roman Kiryanov 

This casting is not required.

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/goldfish_pipe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index e45e262517a0..f6c144e71c30 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -103,7 +103,7 @@ static int goldfish_pipe_probe(struct platform_device *pdev)
 *  reading device version back: this allows the host implementation to
 *  detect the old driver (if there was no version write before read).
 */
-   writel((u32)PIPE_DRIVER_VERSION, base + PIPE_V2_REG_VERSION);
+   writel(PIPE_DRIVER_VERSION, base + PIPE_V2_REG_VERSION);
version = readl(base + PIPE_V2_REG_VERSION);
 
if (version < PIPE_CURRENT_DEVICE_VERSION)
-- 
2.19.0.397.gdd90340f6a-goog



[PATCH 19/21] platform: goldfish: pipe: Add the goldfish_pipe_v1 driver

2018-09-14 Thread rkir
From: Roman Kiryanov 

This is the v1 goldfish pipe driver.

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/Makefile|   3 +-
 drivers/platform/goldfish/goldfish_pipe.c |   9 +-
 .../platform/goldfish/goldfish_pipe_qemu.h|  27 +
 drivers/platform/goldfish/goldfish_pipe_v1.c  | 632 ++
 drivers/platform/goldfish/goldfish_pipe_v1.h  |  24 +
 5 files changed, 690 insertions(+), 5 deletions(-)
 create mode 100644 drivers/platform/goldfish/goldfish_pipe_v1.c
 create mode 100644 drivers/platform/goldfish/goldfish_pipe_v1.h

diff --git a/drivers/platform/goldfish/Makefile 
b/drivers/platform/goldfish/Makefile
index 6a9f6e6de46d..acb105dbd9fd 100644
--- a/drivers/platform/goldfish/Makefile
+++ b/drivers/platform/goldfish/Makefile
@@ -1,4 +1,5 @@
 #
 # Makefile for Goldfish platform specific drivers
 #
-obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe.o goldfish_pipe_v2.o
+obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe.o \
+   goldfish_pipe_v1.o goldfish_pipe_v2.o
diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index d963b7485ce5..e45e262517a0 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -56,6 +56,7 @@
 #include 
 #include "goldfish_pipe_qemu.h"
 #include "goldfish_pipe.h"
+#include "goldfish_pipe_v1.h"
 #include "goldfish_pipe_v2.h"
 
 /*
@@ -105,10 +106,10 @@ static int goldfish_pipe_probe(struct platform_device 
*pdev)
writel((u32)PIPE_DRIVER_VERSION, base + PIPE_V2_REG_VERSION);
version = readl(base + PIPE_V2_REG_VERSION);
 
-   if (WARN_ON(version < PIPE_CURRENT_DEVICE_VERSION))
-   return -EINVAL;
-
-   return goldfish_pipe_device_v2_init(pdev, base, irq);
+   if (version < PIPE_CURRENT_DEVICE_VERSION)
+   return goldfish_pipe_device_v1_init(pdev, base, irq);
+   else
+   return goldfish_pipe_device_v2_init(pdev, base, irq);
 }
 
 static int goldfish_pipe_remove(struct platform_device *pdev)
diff --git a/drivers/platform/goldfish/goldfish_pipe_qemu.h 
b/drivers/platform/goldfish/goldfish_pipe_qemu.h
index 599b69f0baa1..ed2c7938fede 100644
--- a/drivers/platform/goldfish/goldfish_pipe_qemu.h
+++ b/drivers/platform/goldfish/goldfish_pipe_qemu.h
@@ -62,6 +62,33 @@ enum PipeFlagsBits {
BIT_WAKE_ON_READ   = 2,  /* want to be woken on reads */
 };
 
+enum PipeV1Regs {
+   /* write: value = command */
+   PIPE_V1_REG_COMMAND = 0x00,
+   /* read */
+   PIPE_V1_REG_STATUS  = 0x04,
+   /* read/write: channel id */
+   PIPE_V1_REG_CHANNEL = 0x08,
+   /* read/write: channel id */
+   PIPE_V1_REG_CHANNEL_HIGH= 0x30,
+   /* read/write: buffer size */
+   PIPE_V1_REG_SIZE= 0x0C,
+   /* write: physical address */
+   PIPE_V1_REG_ADDRESS = 0x10,
+   /* write: physical address */
+   PIPE_V1_REG_ADDRESS_HIGH= 0x34,
+   /* read: wake flags */
+   PIPE_V1_REG_WAKES   = 0x14,
+   /* read/write: batch data address */
+   PIPE_V1_REG_PARAMS_ADDR_LOW = 0x18,
+   /* read/write: batch data address */
+   PIPE_V1_REG_PARAMS_ADDR_HIGH= 0x1C,
+   /* write: batch access */
+   PIPE_V1_REG_ACCESS_PARAMS   = 0x20,
+   /* read: device version */
+   PIPE_V1_REG_VERSION = 0x24,
+};
+
 enum PipeV2Regs {
PIPE_V2_REG_CMD = 0,
 
diff --git a/drivers/platform/goldfish/goldfish_pipe_v1.c 
b/drivers/platform/goldfish/goldfish_pipe_v1.c
new file mode 100644
index ..6e603204dd62
--- /dev/null
+++ b/drivers/platform/goldfish/goldfish_pipe_v1.c
@@ -0,0 +1,632 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2011 Google, Inc.
+ * Copyright (C) 2012 Intel, Inc.
+ * Copyright (C) 2013 Intel, Inc.
+ * Copyright (C) 2014 Linaro Limited
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+/* This source file contains the implementation of the legacy version of
+ * a goldfish pipe device driver. See goldfish_pipe_v2.c for the current
+ * version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "goldfish_pipe_qemu.h"
+#include "goldfish_pipe.h"
+
+#define MAX_PAGES_TO_GRAB 32
+
+/* A value that will not be set by qemu emulator */
+#define INITIAL_BATCH_RESULT (0xdeadbeaf)
+
+struct goldfish_pipe_dev;
+
+/* This data type models a given pipe 

[PATCH 21/21] platform: goldfish: pipe: Fix allmodconfig build

2018-09-14 Thread rkir
From: Roman Kiryanov 

The changes fixes these errors:

WARNING: modpost: missing MODULE_LICENSE() in 
drivers/platform/goldfish/goldfish_pipe_v1.o
see include/linux/module.h for more information
WARNING: modpost: missing MODULE_LICENSE() in 
drivers/platform/goldfish/goldfish_pipe_v2.o
see include/linux/module.h for more information
ERROR: "goldfish_pipe_device_v2_init" 
[drivers/platform/goldfish/goldfish_pipe.ko] undefined!
ERROR: "goldfish_pipe_device_v1_init" 
[drivers/platform/goldfish/goldfish_pipe.ko] undefined!
scripts/Makefile.modpost:92: recipe for target '__modpost' failed
make[1]: *** [__modpost] Error 1
Makefile:1206: recipe for target 'modules' failed
make: *** [modules] Error 2

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/goldfish/Makefile 
b/drivers/platform/goldfish/Makefile
index acb105dbd9fd..354b4a7d18bb 100644
--- a/drivers/platform/goldfish/Makefile
+++ b/drivers/platform/goldfish/Makefile
@@ -1,5 +1,5 @@
 #
 # Makefile for Goldfish platform specific drivers
 #
-obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe.o \
-   goldfish_pipe_v1.o goldfish_pipe_v2.o
+obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe_all.o
+goldfish_pipe_all-objs := goldfish_pipe.o goldfish_pipe_v1.o goldfish_pipe_v2.o
-- 
2.19.0.397.gdd90340f6a-goog



[PATCH 21/21] platform: goldfish: pipe: Fix allmodconfig build

2018-09-14 Thread rkir
From: Roman Kiryanov 

The changes fixes these errors:

WARNING: modpost: missing MODULE_LICENSE() in 
drivers/platform/goldfish/goldfish_pipe_v1.o
see include/linux/module.h for more information
WARNING: modpost: missing MODULE_LICENSE() in 
drivers/platform/goldfish/goldfish_pipe_v2.o
see include/linux/module.h for more information
ERROR: "goldfish_pipe_device_v2_init" 
[drivers/platform/goldfish/goldfish_pipe.ko] undefined!
ERROR: "goldfish_pipe_device_v1_init" 
[drivers/platform/goldfish/goldfish_pipe.ko] undefined!
scripts/Makefile.modpost:92: recipe for target '__modpost' failed
make[1]: *** [__modpost] Error 1
Makefile:1206: recipe for target 'modules' failed
make: *** [modules] Error 2

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/goldfish/Makefile 
b/drivers/platform/goldfish/Makefile
index acb105dbd9fd..354b4a7d18bb 100644
--- a/drivers/platform/goldfish/Makefile
+++ b/drivers/platform/goldfish/Makefile
@@ -1,5 +1,5 @@
 #
 # Makefile for Goldfish platform specific drivers
 #
-obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe.o \
-   goldfish_pipe_v1.o goldfish_pipe_v2.o
+obj-$(CONFIG_GOLDFISH_PIPE)+= goldfish_pipe_all.o
+goldfish_pipe_all-objs := goldfish_pipe.o goldfish_pipe_v1.o goldfish_pipe_v2.o
-- 
2.19.0.397.gdd90340f6a-goog



[PATCH 18/21] platform: goldfish: pipe: Rename PIPE_REG to PIPE_V2_REG

2018-09-14 Thread rkir
From: Roman Kiryanov 

PIPE_V1_REG will be introduced later for v1 support.

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/goldfish_pipe.c  |  4 ++--
 drivers/platform/goldfish/goldfish_pipe_qemu.h | 18 +-
 drivers/platform/goldfish/goldfish_pipe_v2.c   | 16 
 3 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index 8a65cdfd6555..d963b7485ce5 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -102,8 +102,8 @@ static int goldfish_pipe_probe(struct platform_device *pdev)
 *  reading device version back: this allows the host implementation to
 *  detect the old driver (if there was no version write before read).
 */
-   writel((u32)PIPE_DRIVER_VERSION, base + PIPE_REG_VERSION);
-   version = readl(base + PIPE_REG_VERSION);
+   writel((u32)PIPE_DRIVER_VERSION, base + PIPE_V2_REG_VERSION);
+   version = readl(base + PIPE_V2_REG_VERSION);
 
if (WARN_ON(version < PIPE_CURRENT_DEVICE_VERSION))
return -EINVAL;
diff --git a/drivers/platform/goldfish/goldfish_pipe_qemu.h 
b/drivers/platform/goldfish/goldfish_pipe_qemu.h
index 0ffc51dba54c..599b69f0baa1 100644
--- a/drivers/platform/goldfish/goldfish_pipe_qemu.h
+++ b/drivers/platform/goldfish/goldfish_pipe_qemu.h
@@ -62,19 +62,19 @@ enum PipeFlagsBits {
BIT_WAKE_ON_READ   = 2,  /* want to be woken on reads */
 };
 
-enum PipeRegs {
-   PIPE_REG_CMD = 0,
+enum PipeV2Regs {
+   PIPE_V2_REG_CMD = 0,
 
-   PIPE_REG_SIGNAL_BUFFER_HIGH = 4,
-   PIPE_REG_SIGNAL_BUFFER = 8,
-   PIPE_REG_SIGNAL_BUFFER_COUNT = 12,
+   PIPE_V2_REG_SIGNAL_BUFFER_HIGH = 4,
+   PIPE_V2_REG_SIGNAL_BUFFER = 8,
+   PIPE_V2_REG_SIGNAL_BUFFER_COUNT = 12,
 
-   PIPE_REG_OPEN_BUFFER_HIGH = 20,
-   PIPE_REG_OPEN_BUFFER = 24,
+   PIPE_V2_REG_OPEN_BUFFER_HIGH = 20,
+   PIPE_V2_REG_OPEN_BUFFER = 24,
 
-   PIPE_REG_VERSION = 36,
+   PIPE_V2_REG_VERSION = 36,
 
-   PIPE_REG_GET_SIGNALLED = 48,
+   PIPE_V2_REG_GET_SIGNALLED = 48,
 };
 
 enum PipeCmdCode {
diff --git a/drivers/platform/goldfish/goldfish_pipe_v2.c 
b/drivers/platform/goldfish/goldfish_pipe_v2.c
index 2332aa4bfcea..862ef3a56388 100644
--- a/drivers/platform/goldfish/goldfish_pipe_v2.c
+++ b/drivers/platform/goldfish/goldfish_pipe_v2.c
@@ -259,7 +259,7 @@ static int goldfish_pipe_cmd_locked(struct goldfish_pipe 
*pipe,
pipe->command_buffer->cmd = cmd;
/* failure by default */
pipe->command_buffer->status = PIPE_ERROR_INVAL;
-   writel(pipe->id, pipe->dev->base + PIPE_REG_CMD);
+   writel(pipe->id, pipe->dev->base + PIPE_V2_REG_CMD);
return pipe->command_buffer->status;
 }
 
@@ -276,7 +276,7 @@ static int goldfish_pipe_cmd(struct goldfish_pipe *pipe, 
enum PipeCmdCode cmd)
 
 /*
  * This function converts an error code returned by the emulator through
- * the PIPE_REG_STATUS i/o register into a valid negative errno value.
+ * the PIPE_V2_REG_STATUS i/o register into a valid negative errno value.
  */
 static int goldfish_pipe_error_convert(int status)
 {
@@ -673,7 +673,7 @@ static irqreturn_t goldfish_pipe_interrupt(int irq, void 
*dev_id)
/* Request the signalled pipes from the device */
spin_lock_irqsave(>lock, flags);
 
-   count = readl(dev->base + PIPE_REG_GET_SIGNALLED);
+   count = readl(dev->base + PIPE_V2_REG_GET_SIGNALLED);
if (count == 0) {
spin_unlock_irqrestore(>lock, flags);
return IRQ_NONE;
@@ -1181,15 +1181,15 @@ int goldfish_pipe_device_v2_init(struct platform_device 
*pdev,
 
/* Send the buffer addresses to the host */
write_pa_addr(>buffers->signalled_pipe_buffers,
- dev->base + PIPE_REG_SIGNAL_BUFFER,
- dev->base + PIPE_REG_SIGNAL_BUFFER_HIGH);
+ dev->base + PIPE_V2_REG_SIGNAL_BUFFER,
+ dev->base + PIPE_V2_REG_SIGNAL_BUFFER_HIGH);
 
writel(MAX_SIGNALLED_PIPES,
-  dev->base + PIPE_REG_SIGNAL_BUFFER_COUNT);
+  dev->base + PIPE_V2_REG_SIGNAL_BUFFER_COUNT);
 
write_pa_addr(>buffers->open_command_params,
- dev->base + PIPE_REG_OPEN_BUFFER,
- dev->base + PIPE_REG_OPEN_BUFFER_HIGH);
+ dev->base + PIPE_V2_REG_OPEN_BUFFER,
+ dev->base + PIPE_V2_REG_OPEN_BUFFER_HIGH);
 
platform_set_drvdata(pdev, dev);
return 0;
-- 
2.19.0.397.gdd90340f6a-goog



[PATCH 18/21] platform: goldfish: pipe: Rename PIPE_REG to PIPE_V2_REG

2018-09-14 Thread rkir
From: Roman Kiryanov 

PIPE_V1_REG will be introduced later for v1 support.

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/goldfish_pipe.c  |  4 ++--
 drivers/platform/goldfish/goldfish_pipe_qemu.h | 18 +-
 drivers/platform/goldfish/goldfish_pipe_v2.c   | 16 
 3 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.c 
b/drivers/platform/goldfish/goldfish_pipe.c
index 8a65cdfd6555..d963b7485ce5 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -102,8 +102,8 @@ static int goldfish_pipe_probe(struct platform_device *pdev)
 *  reading device version back: this allows the host implementation to
 *  detect the old driver (if there was no version write before read).
 */
-   writel((u32)PIPE_DRIVER_VERSION, base + PIPE_REG_VERSION);
-   version = readl(base + PIPE_REG_VERSION);
+   writel((u32)PIPE_DRIVER_VERSION, base + PIPE_V2_REG_VERSION);
+   version = readl(base + PIPE_V2_REG_VERSION);
 
if (WARN_ON(version < PIPE_CURRENT_DEVICE_VERSION))
return -EINVAL;
diff --git a/drivers/platform/goldfish/goldfish_pipe_qemu.h 
b/drivers/platform/goldfish/goldfish_pipe_qemu.h
index 0ffc51dba54c..599b69f0baa1 100644
--- a/drivers/platform/goldfish/goldfish_pipe_qemu.h
+++ b/drivers/platform/goldfish/goldfish_pipe_qemu.h
@@ -62,19 +62,19 @@ enum PipeFlagsBits {
BIT_WAKE_ON_READ   = 2,  /* want to be woken on reads */
 };
 
-enum PipeRegs {
-   PIPE_REG_CMD = 0,
+enum PipeV2Regs {
+   PIPE_V2_REG_CMD = 0,
 
-   PIPE_REG_SIGNAL_BUFFER_HIGH = 4,
-   PIPE_REG_SIGNAL_BUFFER = 8,
-   PIPE_REG_SIGNAL_BUFFER_COUNT = 12,
+   PIPE_V2_REG_SIGNAL_BUFFER_HIGH = 4,
+   PIPE_V2_REG_SIGNAL_BUFFER = 8,
+   PIPE_V2_REG_SIGNAL_BUFFER_COUNT = 12,
 
-   PIPE_REG_OPEN_BUFFER_HIGH = 20,
-   PIPE_REG_OPEN_BUFFER = 24,
+   PIPE_V2_REG_OPEN_BUFFER_HIGH = 20,
+   PIPE_V2_REG_OPEN_BUFFER = 24,
 
-   PIPE_REG_VERSION = 36,
+   PIPE_V2_REG_VERSION = 36,
 
-   PIPE_REG_GET_SIGNALLED = 48,
+   PIPE_V2_REG_GET_SIGNALLED = 48,
 };
 
 enum PipeCmdCode {
diff --git a/drivers/platform/goldfish/goldfish_pipe_v2.c 
b/drivers/platform/goldfish/goldfish_pipe_v2.c
index 2332aa4bfcea..862ef3a56388 100644
--- a/drivers/platform/goldfish/goldfish_pipe_v2.c
+++ b/drivers/platform/goldfish/goldfish_pipe_v2.c
@@ -259,7 +259,7 @@ static int goldfish_pipe_cmd_locked(struct goldfish_pipe 
*pipe,
pipe->command_buffer->cmd = cmd;
/* failure by default */
pipe->command_buffer->status = PIPE_ERROR_INVAL;
-   writel(pipe->id, pipe->dev->base + PIPE_REG_CMD);
+   writel(pipe->id, pipe->dev->base + PIPE_V2_REG_CMD);
return pipe->command_buffer->status;
 }
 
@@ -276,7 +276,7 @@ static int goldfish_pipe_cmd(struct goldfish_pipe *pipe, 
enum PipeCmdCode cmd)
 
 /*
  * This function converts an error code returned by the emulator through
- * the PIPE_REG_STATUS i/o register into a valid negative errno value.
+ * the PIPE_V2_REG_STATUS i/o register into a valid negative errno value.
  */
 static int goldfish_pipe_error_convert(int status)
 {
@@ -673,7 +673,7 @@ static irqreturn_t goldfish_pipe_interrupt(int irq, void 
*dev_id)
/* Request the signalled pipes from the device */
spin_lock_irqsave(>lock, flags);
 
-   count = readl(dev->base + PIPE_REG_GET_SIGNALLED);
+   count = readl(dev->base + PIPE_V2_REG_GET_SIGNALLED);
if (count == 0) {
spin_unlock_irqrestore(>lock, flags);
return IRQ_NONE;
@@ -1181,15 +1181,15 @@ int goldfish_pipe_device_v2_init(struct platform_device 
*pdev,
 
/* Send the buffer addresses to the host */
write_pa_addr(>buffers->signalled_pipe_buffers,
- dev->base + PIPE_REG_SIGNAL_BUFFER,
- dev->base + PIPE_REG_SIGNAL_BUFFER_HIGH);
+ dev->base + PIPE_V2_REG_SIGNAL_BUFFER,
+ dev->base + PIPE_V2_REG_SIGNAL_BUFFER_HIGH);
 
writel(MAX_SIGNALLED_PIPES,
-  dev->base + PIPE_REG_SIGNAL_BUFFER_COUNT);
+  dev->base + PIPE_V2_REG_SIGNAL_BUFFER_COUNT);
 
write_pa_addr(>buffers->open_command_params,
- dev->base + PIPE_REG_OPEN_BUFFER,
- dev->base + PIPE_REG_OPEN_BUFFER_HIGH);
+ dev->base + PIPE_V2_REG_OPEN_BUFFER,
+ dev->base + PIPE_V2_REG_OPEN_BUFFER_HIGH);
 
platform_set_drvdata(pdev, dev);
return 0;
-- 
2.19.0.397.gdd90340f6a-goog



[PATCH 16/21] platform: goldfish: pipe: Call misc_deregister if init fails

2018-09-14 Thread rkir
From: Roman Kiryanov 

Undo effects of misc_register if driver's init fails after
misc_register.

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/goldfish_pipe_v2.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe_v2.c 
b/drivers/platform/goldfish/goldfish_pipe_v2.c
index 9fa5136be909..e3358c682562 100644
--- a/drivers/platform/goldfish/goldfish_pipe_v2.c
+++ b/drivers/platform/goldfish/goldfish_pipe_v2.c
@@ -1159,8 +1159,10 @@ int goldfish_pipe_device_v2_init(struct platform_device 
*pdev,
dev->pipes_capacity = INITIAL_PIPES_CAPACITY;
dev->pipes = kcalloc(dev->pipes_capacity, sizeof(*dev->pipes),
 GFP_KERNEL);
-   if (!dev->pipes)
+   if (!dev->pipes) {
+   misc_deregister(>miscdev);
return -ENOMEM;
+   }
 
/*
 * We're going to pass two buffers, open_command_params and
@@ -1173,6 +1175,7 @@ int goldfish_pipe_device_v2_init(struct platform_device 
*pdev,
__get_free_page(GFP_KERNEL);
if (!dev->buffers) {
kfree(dev->pipes);
+   misc_deregister(>miscdev);
return -ENOMEM;
}
 
-- 
2.19.0.397.gdd90340f6a-goog



[PATCH 17/21] platform: goldfish: pipe: Add a dedicated constant for the device name

2018-09-14 Thread rkir
From: Roman Kiryanov 

Create a constant to refer to the device name instead if several copies
of a string.

Signed-off-by: Roman Kiryanov 
---
 drivers/platform/goldfish/goldfish_pipe.h| 2 ++
 drivers/platform/goldfish/goldfish_pipe_v2.c | 4 ++--
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/goldfish/goldfish_pipe.h 
b/drivers/platform/goldfish/goldfish_pipe.h
index 41e831f59eff..178efcf52d22 100644
--- a/drivers/platform/goldfish/goldfish_pipe.h
+++ b/drivers/platform/goldfish/goldfish_pipe.h
@@ -16,6 +16,8 @@
 #ifndef GOLDFISH_PIPE_H
 #define GOLDFISH_PIPE_H
 
+#define DEVICE_NAME "goldfish_pipe"
+
 struct goldfish_pipe_dev_base {
/* the destructor, the pointer is set in init */
int (*deinit)(void *pipe_dev, struct platform_device *pdev);
diff --git a/drivers/platform/goldfish/goldfish_pipe_v2.c 
b/drivers/platform/goldfish/goldfish_pipe_v2.c
index e3358c682562..2332aa4bfcea 100644
--- a/drivers/platform/goldfish/goldfish_pipe_v2.c
+++ b/drivers/platform/goldfish/goldfish_pipe_v2.c
@@ -1109,7 +1109,7 @@ static void init_miscdevice(struct miscdevice *miscdev)
memset(miscdev, 0, sizeof(*miscdev));
 
miscdev->minor = MISC_DYNAMIC_MINOR;
-   miscdev->name = "goldfish_pipe";
+   miscdev->name = DEVICE_NAME;
miscdev->fops = _pipe_fops;
 }
 
@@ -1140,7 +1140,7 @@ int goldfish_pipe_device_v2_init(struct platform_device 
*pdev,
 
err = devm_request_irq(>dev, irq,
   goldfish_pipe_interrupt,
-  IRQF_SHARED, "goldfish_pipe", dev);
+  IRQF_SHARED, DEVICE_NAME, dev);
if (err) {
dev_err(>dev, "unable to allocate IRQ for v2\n");
return err;
-- 
2.19.0.397.gdd90340f6a-goog



  1   2   3   >