diff options
author | Eric Auger <eric.auger@linaro.org> | 2015-06-15 05:09:45 -0400 |
---|---|---|
committer | Alex Williamson <alex.williamson@redhat.com> | 2015-06-22 11:35:38 -0400 |
commit | 713cc334a6cc20dd1740933bf49d804b081bbca0 (patch) | |
tree | 8d853639cae0648d789b06ab4201167b7110fad0 | |
parent | 3eeb0d510c65e777030156f03c116393095a3248 (diff) |
VFIO: platform: Calxeda xgmac reset module
This patch introduces a module that registers and implements a basic
reset function for the Calxeda xgmac device. This latter basically disables
interrupts and stops DMA transfers.
The reset function code is inherited from the native calxeda xgmac driver.
Signed-off-by: Eric Auger <eric.auger@linaro.org>
Acked-by: Baptiste Reynal <b.reynal@virtualopensystems.com>
Tested-by: Baptiste Reynal <b.reynal@virtualopensystems.com>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
-rw-r--r-- | drivers/vfio/platform/Kconfig | 2 | ||||
-rw-r--r-- | drivers/vfio/platform/Makefile | 2 | ||||
-rw-r--r-- | drivers/vfio/platform/reset/Kconfig | 7 | ||||
-rw-r--r-- | drivers/vfio/platform/reset/Makefile | 5 | ||||
-rw-r--r-- | drivers/vfio/platform/reset/vfio_platform_calxedaxgmac.c | 86 | ||||
-rw-r--r-- | drivers/vfio/platform/vfio_platform_common.c | 5 |
6 files changed, 107 insertions, 0 deletions
diff --git a/drivers/vfio/platform/Kconfig b/drivers/vfio/platform/Kconfig index 9a4403e2a36c..1df74772d1b7 100644 --- a/drivers/vfio/platform/Kconfig +++ b/drivers/vfio/platform/Kconfig | |||
@@ -18,3 +18,5 @@ config VFIO_AMBA | |||
18 | framework. | 18 | framework. |
19 | 19 | ||
20 | If you don't know what to do here, say N. | 20 | If you don't know what to do here, say N. |
21 | |||
22 | source "drivers/vfio/platform/reset/Kconfig" | ||
diff --git a/drivers/vfio/platform/Makefile b/drivers/vfio/platform/Makefile index 81de144c0eaa..9ce8afe28450 100644 --- a/drivers/vfio/platform/Makefile +++ b/drivers/vfio/platform/Makefile | |||
@@ -2,7 +2,9 @@ | |||
2 | vfio-platform-y := vfio_platform.o vfio_platform_common.o vfio_platform_irq.o | 2 | vfio-platform-y := vfio_platform.o vfio_platform_common.o vfio_platform_irq.o |
3 | 3 | ||
4 | obj-$(CONFIG_VFIO_PLATFORM) += vfio-platform.o | 4 | obj-$(CONFIG_VFIO_PLATFORM) += vfio-platform.o |
5 | obj-$(CONFIG_VFIO_PLATFORM) += reset/ | ||
5 | 6 | ||
6 | vfio-amba-y := vfio_amba.o | 7 | vfio-amba-y := vfio_amba.o |
7 | 8 | ||
8 | obj-$(CONFIG_VFIO_AMBA) += vfio-amba.o | 9 | obj-$(CONFIG_VFIO_AMBA) += vfio-amba.o |
10 | obj-$(CONFIG_VFIO_AMBA) += reset/ | ||
diff --git a/drivers/vfio/platform/reset/Kconfig b/drivers/vfio/platform/reset/Kconfig new file mode 100644 index 000000000000..746b96b0003b --- /dev/null +++ b/drivers/vfio/platform/reset/Kconfig | |||
@@ -0,0 +1,7 @@ | |||
1 | config VFIO_PLATFORM_CALXEDAXGMAC_RESET | ||
2 | tristate "VFIO support for calxeda xgmac reset" | ||
3 | depends on VFIO_PLATFORM | ||
4 | help | ||
5 | Enables the VFIO platform driver to handle reset for Calxeda xgmac | ||
6 | |||
7 | If you don't know what to do here, say N. | ||
diff --git a/drivers/vfio/platform/reset/Makefile b/drivers/vfio/platform/reset/Makefile new file mode 100644 index 000000000000..2a486af9f8fa --- /dev/null +++ b/drivers/vfio/platform/reset/Makefile | |||
@@ -0,0 +1,5 @@ | |||
1 | vfio-platform-calxedaxgmac-y := vfio_platform_calxedaxgmac.o | ||
2 | |||
3 | ccflags-y += -Idrivers/vfio/platform | ||
4 | |||
5 | obj-$(CONFIG_VFIO_PLATFORM_CALXEDAXGMAC_RESET) += vfio-platform-calxedaxgmac.o | ||
diff --git a/drivers/vfio/platform/reset/vfio_platform_calxedaxgmac.c b/drivers/vfio/platform/reset/vfio_platform_calxedaxgmac.c new file mode 100644 index 000000000000..619dc7d22082 --- /dev/null +++ b/drivers/vfio/platform/reset/vfio_platform_calxedaxgmac.c | |||
@@ -0,0 +1,86 @@ | |||
1 | /* | ||
2 | * VFIO platform driver specialized for Calxeda xgmac reset | ||
3 | * reset code is inherited from calxeda xgmac native driver | ||
4 | * | ||
5 | * Copyright 2010-2011 Calxeda, Inc. | ||
6 | * Copyright (c) 2015 Linaro Ltd. | ||
7 | * www.linaro.org | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify it | ||
10 | * under the terms and conditions of the GNU General Public License, | ||
11 | * version 2, as published by the Free Software Foundation. | ||
12 | * | ||
13 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
16 | * more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License along with | ||
19 | * this program. If not, see <http://www.gnu.org/licenses/>. | ||
20 | */ | ||
21 | |||
22 | #include <linux/module.h> | ||
23 | #include <linux/kernel.h> | ||
24 | #include <linux/init.h> | ||
25 | #include <linux/io.h> | ||
26 | |||
27 | #include "vfio_platform_private.h" | ||
28 | |||
29 | #define DRIVER_VERSION "0.1" | ||
30 | #define DRIVER_AUTHOR "Eric Auger <eric.auger@linaro.org>" | ||
31 | #define DRIVER_DESC "Reset support for Calxeda xgmac vfio platform device" | ||
32 | |||
33 | #define CALXEDAXGMAC_COMPAT "calxeda,hb-xgmac" | ||
34 | |||
35 | /* XGMAC Register definitions */ | ||
36 | #define XGMAC_CONTROL 0x00000000 /* MAC Configuration */ | ||
37 | |||
38 | /* DMA Control and Status Registers */ | ||
39 | #define XGMAC_DMA_CONTROL 0x00000f18 /* Ctrl (Operational Mode) */ | ||
40 | #define XGMAC_DMA_INTR_ENA 0x00000f1c /* Interrupt Enable */ | ||
41 | |||
42 | /* DMA Control registe defines */ | ||
43 | #define DMA_CONTROL_ST 0x00002000 /* Start/Stop Transmission */ | ||
44 | #define DMA_CONTROL_SR 0x00000002 /* Start/Stop Receive */ | ||
45 | |||
46 | /* Common MAC defines */ | ||
47 | #define MAC_ENABLE_TX 0x00000008 /* Transmitter Enable */ | ||
48 | #define MAC_ENABLE_RX 0x00000004 /* Receiver Enable */ | ||
49 | |||
50 | static inline void xgmac_mac_disable(void __iomem *ioaddr) | ||
51 | { | ||
52 | u32 value = readl(ioaddr + XGMAC_DMA_CONTROL); | ||
53 | |||
54 | value &= ~(DMA_CONTROL_ST | DMA_CONTROL_SR); | ||
55 | writel(value, ioaddr + XGMAC_DMA_CONTROL); | ||
56 | |||
57 | value = readl(ioaddr + XGMAC_CONTROL); | ||
58 | value &= ~(MAC_ENABLE_TX | MAC_ENABLE_RX); | ||
59 | writel(value, ioaddr + XGMAC_CONTROL); | ||
60 | } | ||
61 | |||
62 | int vfio_platform_calxedaxgmac_reset(struct vfio_platform_device *vdev) | ||
63 | { | ||
64 | struct vfio_platform_region reg = vdev->regions[0]; | ||
65 | |||
66 | if (!reg.ioaddr) { | ||
67 | reg.ioaddr = | ||
68 | ioremap_nocache(reg.addr, reg.size); | ||
69 | if (!reg.ioaddr) | ||
70 | return -ENOMEM; | ||
71 | } | ||
72 | |||
73 | /* disable IRQ */ | ||
74 | writel(0, reg.ioaddr + XGMAC_DMA_INTR_ENA); | ||
75 | |||
76 | /* Disable the MAC core */ | ||
77 | xgmac_mac_disable(reg.ioaddr); | ||
78 | |||
79 | return 0; | ||
80 | } | ||
81 | EXPORT_SYMBOL_GPL(vfio_platform_calxedaxgmac_reset); | ||
82 | |||
83 | MODULE_VERSION(DRIVER_VERSION); | ||
84 | MODULE_LICENSE("GPL v2"); | ||
85 | MODULE_AUTHOR(DRIVER_AUTHOR); | ||
86 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/platform/vfio_platform_common.c index f3391a93bc0c..e43efb5e92bf 100644 --- a/drivers/vfio/platform/vfio_platform_common.c +++ b/drivers/vfio/platform/vfio_platform_common.c | |||
@@ -26,6 +26,11 @@ | |||
26 | static DEFINE_MUTEX(driver_lock); | 26 | static DEFINE_MUTEX(driver_lock); |
27 | 27 | ||
28 | static const struct vfio_platform_reset_combo reset_lookup_table[] = { | 28 | static const struct vfio_platform_reset_combo reset_lookup_table[] = { |
29 | { | ||
30 | .compat = "calxeda,hb-xgmac", | ||
31 | .reset_function_name = "vfio_platform_calxedaxgmac_reset", | ||
32 | .module_name = "vfio-platform-calxedaxgmac", | ||
33 | }, | ||
29 | }; | 34 | }; |
30 | 35 | ||
31 | static void vfio_platform_get_reset(struct vfio_platform_device *vdev, | 36 | static void vfio_platform_get_reset(struct vfio_platform_device *vdev, |