Skip to content

Commit fe364a7

Browse files
andy-shevvinodkoul
authored andcommitted
dmaengine: dw: Program xBAR hardware for Elkhart Lake
Intel Elkhart Lake PSE DMA implementation is integrated with crossbar IP in order to serve more hardware than there are DMA request lines available. Due to this, program xBAR hardware to make flexible support of PSE peripheral. The Device-to-Device has not been tested and it's not supported by DMA Engine, but it's left in the code for the sake of documenting hardware features. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://lore.kernel.org/r/20210712113940.42753-1-andriy.shevchenko@linux.intel.com Signed-off-by: Vinod Koul <vkoul@kernel.org>
1 parent e73f0f0 commit fe364a7

5 files changed

Lines changed: 160 additions & 9 deletions

File tree

‎drivers/dma/dw/idma32.c‎

Lines changed: 135 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,144 @@
11
// SPDX-License-Identifier: GPL-2.0
2-
// Copyright (C) 2013,2018 Intel Corporation
2+
// Copyright (C) 2013,2018,2020-2021 Intel Corporation
33

44
#include <linux/bitops.h>
55
#include <linux/dmaengine.h>
66
#include <linux/errno.h>
7+
#include <linux/io.h>
8+
#include <linux/pci.h>
79
#include <linux/slab.h>
810
#include <linux/types.h>
911

1012
#include "internal.h"
1113

12-
static void idma32_initialize_chan(struct dw_dma_chan *dwc)
14+
#define DMA_CTL_CH(x) (0x1000 + (x) * 4)
15+
#define DMA_SRC_ADDR_FILLIN(x) (0x1100 + (x) * 4)
16+
#define DMA_DST_ADDR_FILLIN(x) (0x1200 + (x) * 4)
17+
#define DMA_XBAR_SEL(x) (0x1300 + (x) * 4)
18+
#define DMA_REGACCESS_CHID_CFG (0x1400)
19+
20+
#define CTL_CH_TRANSFER_MODE_MASK GENMASK(1, 0)
21+
#define CTL_CH_TRANSFER_MODE_S2S 0
22+
#define CTL_CH_TRANSFER_MODE_S2D 1
23+
#define CTL_CH_TRANSFER_MODE_D2S 2
24+
#define CTL_CH_TRANSFER_MODE_D2D 3
25+
#define CTL_CH_RD_RS_MASK GENMASK(4, 3)
26+
#define CTL_CH_WR_RS_MASK GENMASK(6, 5)
27+
#define CTL_CH_RD_NON_SNOOP_BIT BIT(8)
28+
#define CTL_CH_WR_NON_SNOOP_BIT BIT(9)
29+
30+
#define XBAR_SEL_DEVID_MASK GENMASK(15, 0)
31+
#define XBAR_SEL_RX_TX_BIT BIT(16)
32+
#define XBAR_SEL_RX_TX_SHIFT 16
33+
34+
#define REGACCESS_CHID_MASK GENMASK(2, 0)
35+
36+
static unsigned int idma32_get_slave_devfn(struct dw_dma_chan *dwc)
37+
{
38+
struct device *slave = dwc->chan.slave;
39+
40+
if (!slave || !dev_is_pci(slave))
41+
return 0;
42+
43+
return to_pci_dev(slave)->devfn;
44+
}
45+
46+
static void idma32_initialize_chan_xbar(struct dw_dma_chan *dwc)
47+
{
48+
struct dw_dma *dw = to_dw_dma(dwc->chan.device);
49+
void __iomem *misc = __dw_regs(dw);
50+
u32 cfghi = 0, cfglo = 0;
51+
u8 dst_id, src_id;
52+
u32 value;
53+
54+
/* DMA Channel ID Configuration register must be programmed first */
55+
value = readl(misc + DMA_REGACCESS_CHID_CFG);
56+
57+
value &= ~REGACCESS_CHID_MASK;
58+
value |= dwc->chan.chan_id;
59+
60+
writel(value, misc + DMA_REGACCESS_CHID_CFG);
61+
62+
/* Configure channel attributes */
63+
value = readl(misc + DMA_CTL_CH(dwc->chan.chan_id));
64+
65+
value &= ~(CTL_CH_RD_NON_SNOOP_BIT | CTL_CH_WR_NON_SNOOP_BIT);
66+
value &= ~(CTL_CH_RD_RS_MASK | CTL_CH_WR_RS_MASK);
67+
value &= ~CTL_CH_TRANSFER_MODE_MASK;
68+
69+
switch (dwc->direction) {
70+
case DMA_MEM_TO_DEV:
71+
value |= CTL_CH_TRANSFER_MODE_D2S;
72+
value |= CTL_CH_WR_NON_SNOOP_BIT;
73+
break;
74+
case DMA_DEV_TO_MEM:
75+
value |= CTL_CH_TRANSFER_MODE_S2D;
76+
value |= CTL_CH_RD_NON_SNOOP_BIT;
77+
break;
78+
default:
79+
/*
80+
* Memory-to-Memory and Device-to-Device are ignored for now.
81+
*
82+
* For Memory-to-Memory transfers we would need to set mode
83+
* and disable snooping on both sides.
84+
*/
85+
return;
86+
}
87+
88+
writel(value, misc + DMA_CTL_CH(dwc->chan.chan_id));
89+
90+
/* Configure crossbar selection */
91+
value = readl(misc + DMA_XBAR_SEL(dwc->chan.chan_id));
92+
93+
/* DEVFN selection */
94+
value &= ~XBAR_SEL_DEVID_MASK;
95+
value |= idma32_get_slave_devfn(dwc);
96+
97+
switch (dwc->direction) {
98+
case DMA_MEM_TO_DEV:
99+
value |= XBAR_SEL_RX_TX_BIT;
100+
break;
101+
case DMA_DEV_TO_MEM:
102+
value &= ~XBAR_SEL_RX_TX_BIT;
103+
break;
104+
default:
105+
/* Memory-to-Memory and Device-to-Device are ignored for now */
106+
return;
107+
}
108+
109+
writel(value, misc + DMA_XBAR_SEL(dwc->chan.chan_id));
110+
111+
/* Configure DMA channel low and high registers */
112+
switch (dwc->direction) {
113+
case DMA_MEM_TO_DEV:
114+
dst_id = dwc->chan.chan_id;
115+
src_id = dwc->dws.src_id;
116+
break;
117+
case DMA_DEV_TO_MEM:
118+
dst_id = dwc->dws.dst_id;
119+
src_id = dwc->chan.chan_id;
120+
break;
121+
default:
122+
/* Memory-to-Memory and Device-to-Device are ignored for now */
123+
return;
124+
}
125+
126+
/* Set default burst alignment */
127+
cfglo |= IDMA32C_CFGL_DST_BURST_ALIGN | IDMA32C_CFGL_SRC_BURST_ALIGN;
128+
129+
/* Low 4 bits of the request lines */
130+
cfghi |= IDMA32C_CFGH_DST_PER(dst_id & 0xf);
131+
cfghi |= IDMA32C_CFGH_SRC_PER(src_id & 0xf);
132+
133+
/* Request line extension (2 bits) */
134+
cfghi |= IDMA32C_CFGH_DST_PER_EXT(dst_id >> 4 & 0x3);
135+
cfghi |= IDMA32C_CFGH_SRC_PER_EXT(src_id >> 4 & 0x3);
136+
137+
channel_writel(dwc, CFG_LO, cfglo);
138+
channel_writel(dwc, CFG_HI, cfghi);
139+
}
140+
141+
static void idma32_initialize_chan_generic(struct dw_dma_chan *dwc)
13142
{
14143
u32 cfghi = 0;
15144
u32 cfglo = 0;
@@ -134,7 +263,10 @@ int idma32_dma_probe(struct dw_dma_chip *chip)
134263
return -ENOMEM;
135264

136265
/* Channel operations */
137-
dw->initialize_chan = idma32_initialize_chan;
266+
if (chip->pdata->quirks & DW_DMA_QUIRK_XBAR_PRESENT)
267+
dw->initialize_chan = idma32_initialize_chan_xbar;
268+
else
269+
dw->initialize_chan = idma32_initialize_chan_generic;
138270
dw->suspend_chan = idma32_suspend_chan;
139271
dw->resume_chan = idma32_resume_chan;
140272
dw->prepare_ctllo = idma32_prepare_ctllo;

‎drivers/dma/dw/internal.h‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,20 @@ static __maybe_unused const struct dw_dma_chip_pdata idma32_chip_pdata = {
7474
.remove = idma32_dma_remove,
7575
};
7676

77+
static const struct dw_dma_platform_data xbar_pdata = {
78+
.nr_channels = 8,
79+
.chan_allocation_order = CHAN_ALLOCATION_ASCENDING,
80+
.chan_priority = CHAN_PRIORITY_ASCENDING,
81+
.block_size = 131071,
82+
.nr_masters = 1,
83+
.data_width = {4},
84+
.quirks = DW_DMA_QUIRK_XBAR_PRESENT,
85+
};
86+
87+
static __maybe_unused const struct dw_dma_chip_pdata xbar_chip_pdata = {
88+
.pdata = &xbar_pdata,
89+
.probe = idma32_dma_probe,
90+
.remove = idma32_dma_remove,
91+
};
92+
7793
#endif /* _DMA_DW_INTERNAL_H */

‎drivers/dma/dw/pci.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ static const struct pci_device_id dw_pci_id_table[] = {
120120
{ PCI_VDEVICE(INTEL, 0x22c0), (kernel_ulong_t)&dw_dma_chip_pdata },
121121

122122
/* Elkhart Lake iDMA 32-bit (PSE DMA) */
123-
{ PCI_VDEVICE(INTEL, 0x4bb4), (kernel_ulong_t)&idma32_chip_pdata },
124-
{ PCI_VDEVICE(INTEL, 0x4bb5), (kernel_ulong_t)&idma32_chip_pdata },
125-
{ PCI_VDEVICE(INTEL, 0x4bb6), (kernel_ulong_t)&idma32_chip_pdata },
123+
{ PCI_VDEVICE(INTEL, 0x4bb4), (kernel_ulong_t)&xbar_chip_pdata },
124+
{ PCI_VDEVICE(INTEL, 0x4bb5), (kernel_ulong_t)&xbar_chip_pdata },
125+
{ PCI_VDEVICE(INTEL, 0x4bb6), (kernel_ulong_t)&xbar_chip_pdata },
126126

127127
/* Haswell */
128128
{ PCI_VDEVICE(INTEL, 0x9c60), (kernel_ulong_t)&dw_dma_chip_pdata },

‎drivers/dma/dw/platform.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ static const struct acpi_device_id dw_dma_acpi_id_table[] = {
149149
{ "808622C0", (kernel_ulong_t)&dw_dma_chip_pdata },
150150

151151
/* Elkhart Lake iDMA 32-bit (PSE DMA) */
152-
{ "80864BB4", (kernel_ulong_t)&idma32_chip_pdata },
153-
{ "80864BB5", (kernel_ulong_t)&idma32_chip_pdata },
154-
{ "80864BB6", (kernel_ulong_t)&idma32_chip_pdata },
152+
{ "80864BB4", (kernel_ulong_t)&xbar_chip_pdata },
153+
{ "80864BB5", (kernel_ulong_t)&xbar_chip_pdata },
154+
{ "80864BB6", (kernel_ulong_t)&xbar_chip_pdata },
155155

156156
{ }
157157
};

‎include/linux/platform_data/dma-dw.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ struct dw_dma_slave {
5252
* @max_burst: Maximum value of burst transaction size supported by hardware
5353
* per channel (in units of CTL.SRC_TR_WIDTH/CTL.DST_TR_WIDTH).
5454
* @protctl: Protection control signals setting per channel.
55+
* @quirks: Optional platform quirks.
5556
*/
5657
struct dw_dma_platform_data {
5758
unsigned int nr_channels;
@@ -71,6 +72,8 @@ struct dw_dma_platform_data {
7172
#define CHAN_PROTCTL_CACHEABLE BIT(2)
7273
#define CHAN_PROTCTL_MASK GENMASK(2, 0)
7374
unsigned char protctl;
75+
#define DW_DMA_QUIRK_XBAR_PRESENT BIT(0)
76+
unsigned int quirks;
7477
};
7578

7679
#endif /* _PLATFORM_DATA_DMA_DW_H */

0 commit comments

Comments
 (0)