Skip to content

Commit f9cd476

Browse files
Linus WalleijVinod Koul
authored andcommitted
dmaengine: pl08x: allocate OF slave channel data at probe time
The current OF translation of channels can never work with any DMA client using the DMA channels directly: the only way to get the channels initialized properly is in the dma_async_device_register() call, where chan->dev etc is allocated and initialized. Allocate and initialize all possible DMA channels and only augment a target channel with the periph_buses at of_xlate(). Remove some const settings to make things work. Cc: Maxime Ripard <maxime.ripard@free-electrons.com> Tested-by: Joachim Eastwood <manabian@gmail.com> Tested-by: Johannes Stezenbach <js@sig21.net> Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
1 parent f55532a commit f9cd476

2 files changed

Lines changed: 59 additions & 29 deletions

File tree

‎drivers/dma/amba-pl08x.c‎

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,20 @@ struct pl08x_driver_data;
107107
/**
108108
* struct vendor_data - vendor-specific config parameters for PL08x derivatives
109109
* @channels: the number of channels available in this variant
110+
* @signals: the number of request signals available from the hardware
110111
* @dualmaster: whether this version supports dual AHB masters or not.
111112
* @nomadik: whether the channels have Nomadik security extension bits
112113
* that need to be checked for permission before use and some registers are
113114
* missing
114115
* @pl080s: whether this version is a PL080S, which has separate register and
115116
* LLI word for transfer size.
117+
* @max_transfer_size: the maximum single element transfer size for this
118+
* PL08x variant.
116119
*/
117120
struct vendor_data {
118121
u8 config_offset;
119122
u8 channels;
123+
u8 signals;
120124
bool dualmaster;
121125
bool nomadik;
122126
bool pl080s;
@@ -235,7 +239,7 @@ struct pl08x_dma_chan {
235239
struct virt_dma_chan vc;
236240
struct pl08x_phy_chan *phychan;
237241
const char *name;
238-
const struct pl08x_channel_data *cd;
242+
struct pl08x_channel_data *cd;
239243
struct dma_slave_config cfg;
240244
struct pl08x_txd *at;
241245
struct pl08x_driver_data *host;
@@ -1909,6 +1913,12 @@ static int pl08x_dma_init_virtual_channels(struct pl08x_driver_data *pl08x,
19091913

19101914
if (slave) {
19111915
chan->cd = &pl08x->pd->slave_channels[i];
1916+
/*
1917+
* Some implementations have muxed signals, whereas some
1918+
* use a mux in front of the signals and need dynamic
1919+
* assignment of signals.
1920+
*/
1921+
chan->signal = i;
19121922
pl08x_dma_slave_init(chan);
19131923
} else {
19141924
chan->cd = &pl08x->pd->memcpy_channel;
@@ -2050,50 +2060,45 @@ static struct dma_chan *pl08x_of_xlate(struct of_phandle_args *dma_spec,
20502060
struct of_dma *ofdma)
20512061
{
20522062
struct pl08x_driver_data *pl08x = ofdma->of_dma_data;
2053-
struct pl08x_channel_data *data;
2054-
struct pl08x_dma_chan *chan;
20552063
struct dma_chan *dma_chan;
2064+
struct pl08x_dma_chan *plchan;
20562065

20572066
if (!pl08x)
20582067
return NULL;
20592068

2060-
if (dma_spec->args_count != 2)
2069+
if (dma_spec->args_count != 2) {
2070+
dev_err(&pl08x->adev->dev,
2071+
"DMA channel translation requires two cells\n");
20612072
return NULL;
2073+
}
20622074

20632075
dma_chan = pl08x_find_chan_id(pl08x, dma_spec->args[0]);
2064-
if (dma_chan)
2065-
return dma_get_slave_channel(dma_chan);
2066-
2067-
chan = devm_kzalloc(pl08x->slave.dev, sizeof(*chan) + sizeof(*data),
2068-
GFP_KERNEL);
2069-
if (!chan)
2076+
if (!dma_chan) {
2077+
dev_err(&pl08x->adev->dev,
2078+
"DMA slave channel not found\n");
20702079
return NULL;
2080+
}
20712081

2072-
data = (void *)&chan[1];
2073-
data->bus_id = "(none)";
2074-
data->periph_buses = dma_spec->args[1];
2075-
2076-
chan->cd = data;
2077-
chan->host = pl08x;
2078-
chan->slave = true;
2079-
chan->name = data->bus_id;
2080-
chan->state = PL08X_CHAN_IDLE;
2081-
chan->signal = dma_spec->args[0];
2082-
chan->vc.desc_free = pl08x_desc_free;
2083-
2084-
vchan_init(&chan->vc, &pl08x->slave);
2082+
plchan = to_pl08x_chan(dma_chan);
2083+
dev_dbg(&pl08x->adev->dev,
2084+
"translated channel for signal %d\n",
2085+
dma_spec->args[0]);
20852086

2086-
return dma_get_slave_channel(&chan->vc.chan);
2087+
/* Augment channel data for applicable AHB buses */
2088+
plchan->cd->periph_buses = dma_spec->args[1];
2089+
return dma_get_slave_channel(dma_chan);
20872090
}
20882091

20892092
static int pl08x_of_probe(struct amba_device *adev,
20902093
struct pl08x_driver_data *pl08x,
20912094
struct device_node *np)
20922095
{
20932096
struct pl08x_platform_data *pd;
2097+
struct pl08x_channel_data *chanp = NULL;
20942098
u32 cctl_memcpy = 0;
20952099
u32 val;
20962100
int ret;
2101+
int i;
20972102

20982103
pd = devm_kzalloc(&adev->dev, sizeof(*pd), GFP_KERNEL);
20992104
if (!pd)
@@ -2195,6 +2200,27 @@ static int pl08x_of_probe(struct amba_device *adev,
21952200
/* Use the buses that can access memory, obviously */
21962201
pd->memcpy_channel.periph_buses = pd->mem_buses;
21972202

2203+
/*
2204+
* Allocate channel data for all possible slave channels (one
2205+
* for each possible signal), channels will then be allocated
2206+
* for a device and have it's AHB interfaces set up at
2207+
* translation time.
2208+
*/
2209+
chanp = devm_kcalloc(&adev->dev,
2210+
pl08x->vd->signals,
2211+
sizeof(struct pl08x_channel_data),
2212+
GFP_KERNEL);
2213+
if (!chanp)
2214+
return -ENOMEM;
2215+
2216+
pd->slave_channels = chanp;
2217+
for (i = 0; i < pl08x->vd->signals; i++) {
2218+
/* chanp->periph_buses will be assigned at translation */
2219+
chanp->bus_id = kasprintf(GFP_KERNEL, "slave%d", i);
2220+
chanp++;
2221+
}
2222+
pd->num_slave_channels = pl08x->vd->signals;
2223+
21982224
pl08x->pd = pd;
21992225

22002226
return of_dma_controller_register(adev->dev.of_node, pl08x_of_xlate,
@@ -2234,6 +2260,10 @@ static int pl08x_probe(struct amba_device *adev, const struct amba_id *id)
22342260
goto out_no_pl08x;
22352261
}
22362262

2263+
/* Assign useful pointers to the driver state */
2264+
pl08x->adev = adev;
2265+
pl08x->vd = vd;
2266+
22372267
/* Initialize memcpy engine */
22382268
dma_cap_set(DMA_MEMCPY, pl08x->memcpy.cap_mask);
22392269
pl08x->memcpy.dev = &adev->dev;
@@ -2284,10 +2314,6 @@ static int pl08x_probe(struct amba_device *adev, const struct amba_id *id)
22842314
}
22852315
}
22862316

2287-
/* Assign useful pointers to the driver state */
2288-
pl08x->adev = adev;
2289-
pl08x->vd = vd;
2290-
22912317
/* By default, AHB1 only. If dualmaster, from platform */
22922318
pl08x->lli_buses = PL08X_AHB1;
22932319
pl08x->mem_buses = PL08X_AHB1;
@@ -2438,13 +2464,15 @@ static int pl08x_probe(struct amba_device *adev, const struct amba_id *id)
24382464
static struct vendor_data vendor_pl080 = {
24392465
.config_offset = PL080_CH_CONFIG,
24402466
.channels = 8,
2467+
.signals = 16,
24412468
.dualmaster = true,
24422469
.max_transfer_size = PL080_CONTROL_TRANSFER_SIZE_MASK,
24432470
};
24442471

24452472
static struct vendor_data vendor_nomadik = {
24462473
.config_offset = PL080_CH_CONFIG,
24472474
.channels = 8,
2475+
.signals = 32,
24482476
.dualmaster = true,
24492477
.nomadik = true,
24502478
.max_transfer_size = PL080_CONTROL_TRANSFER_SIZE_MASK,
@@ -2453,13 +2481,15 @@ static struct vendor_data vendor_nomadik = {
24532481
static struct vendor_data vendor_pl080s = {
24542482
.config_offset = PL080S_CH_CONFIG,
24552483
.channels = 8,
2484+
.signals = 32,
24562485
.pl080s = true,
24572486
.max_transfer_size = PL080S_CONTROL_TRANSFER_SIZE_MASK,
24582487
};
24592488

24602489
static struct vendor_data vendor_pl081 = {
24612490
.config_offset = PL080_CH_CONFIG,
24622491
.channels = 2,
2492+
.signals = 16,
24632493
.dualmaster = false,
24642494
.max_transfer_size = PL080_CONTROL_TRANSFER_SIZE_MASK,
24652495
};

‎include/linux/amba/pl08x.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ struct pl08x_channel_data {
8686
* @mem_buses: buses which memory can be accessed from: PL08X_AHB1 | PL08X_AHB2
8787
*/
8888
struct pl08x_platform_data {
89-
const struct pl08x_channel_data *slave_channels;
89+
struct pl08x_channel_data *slave_channels;
9090
unsigned int num_slave_channels;
9191
struct pl08x_channel_data memcpy_channel;
9292
int (*get_xfer_signal)(const struct pl08x_channel_data *);

0 commit comments

Comments
 (0)