View | Details | Raw Unified | Return to bug 1043231
Collapse All | Expand All

(-)a/Documentation/dmaengine/client.txt (-17 / +6 lines)
Lines 22-46 The slave DMA usage consists of following steps: Link Here
22
   Channel allocation is slightly different in the slave DMA context,
22
   Channel allocation is slightly different in the slave DMA context,
23
   client drivers typically need a channel from a particular DMA
23
   client drivers typically need a channel from a particular DMA
24
   controller only and even in some cases a specific channel is desired.
24
   controller only and even in some cases a specific channel is desired.
25
   To request a channel dma_request_channel() API is used.
25
   To request a channel dma_request_chan() API is used.
26
26
27
   Interface:
27
   Interface:
28
	struct dma_chan *dma_request_channel(dma_cap_mask_t mask,
28
	struct dma_chan *dma_request_chan(struct device *dev, const char *name);
29
			dma_filter_fn filter_fn,
29
30
			void *filter_param);
30
   Which will find and return the 'name' DMA channel associated with the 'dev'
31
   where dma_filter_fn is defined as:
31
   device. The association is done via DT, ACPI or board file based
32
	typedef bool (*dma_filter_fn)(struct dma_chan *chan, void *filter_param);
32
   dma_slave_map matching table.
33
34
   The 'filter_fn' parameter is optional, but highly recommended for
35
   slave and cyclic channels as they typically need to obtain a specific
36
   DMA channel.
37
38
   When the optional 'filter_fn' parameter is NULL, dma_request_channel()
39
   simply returns the first channel that satisfies the capability mask.
40
41
   Otherwise, the 'filter_fn' routine will be called once for each free
42
   channel which has a capability in 'mask'.  'filter_fn' is expected to
43
   return 'true' when the desired DMA channel is found.
44
33
45
   A channel allocated via this interface is exclusive to the caller,
34
   A channel allocated via this interface is exclusive to the caller,
46
   until dma_release_channel() is called.
35
   until dma_release_channel() is called.
(-)a/drivers/dma/dmaengine.c (-12 / +77 lines)
Lines 43-48 Link Here
43
43
44
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
44
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
45
45
46
#include <linux/platform_device.h>
46
#include <linux/dma-mapping.h>
47
#include <linux/dma-mapping.h>
47
#include <linux/init.h>
48
#include <linux/init.h>
48
#include <linux/module.h>
49
#include <linux/module.h>
Lines 665-691 struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask, Link Here
665
}
666
}
666
EXPORT_SYMBOL_GPL(__dma_request_channel);
667
EXPORT_SYMBOL_GPL(__dma_request_channel);
667
668
669
static const struct dma_slave_map *dma_filter_match(struct dma_device *device,
670
						    const char *name,
671
						    struct device *dev)
672
{
673
	int i;
674
675
	if (!device->filter.mapcnt)
676
		return NULL;
677
678
	for (i = 0; i < device->filter.mapcnt; i++) {
679
		const struct dma_slave_map *map = &device->filter.map[i];
680
681
		if (!strcmp(map->devname, dev_name(dev)) &&
682
		    !strcmp(map->slave, name))
683
			return map;
684
	}
685
686
	return NULL;
687
}
688
668
/**
689
/**
669
 * dma_request_slave_channel_reason - try to allocate an exclusive slave channel
690
 * dma_request_chan - try to allocate an exclusive slave channel
670
 * @dev:	pointer to client device structure
691
 * @dev:	pointer to client device structure
671
 * @name:	slave channel name
692
 * @name:	slave channel name
672
 *
693
 *
673
 * Returns pointer to appropriate DMA channel on success or an error pointer.
694
 * Returns pointer to appropriate DMA channel on success or an error pointer.
674
 */
695
 */
675
struct dma_chan *dma_request_slave_channel_reason(struct device *dev,
696
struct dma_chan *dma_request_chan(struct device *dev, const char *name)
676
						  const char *name)
677
{
697
{
698
	struct dma_device *d, *_d;
699
	struct dma_chan *chan = NULL;
700
678
	/* If device-tree is present get slave info from here */
701
	/* If device-tree is present get slave info from here */
679
	if (dev->of_node)
702
	if (dev->of_node)
680
		return of_dma_request_slave_channel(dev->of_node, name);
703
		chan = of_dma_request_slave_channel(dev->of_node, name);
681
704
682
	/* If device was enumerated by ACPI get slave info from here */
705
	/* If device was enumerated by ACPI get slave info from here */
683
	if (ACPI_HANDLE(dev))
706
	if (has_acpi_companion(dev) && !chan)
684
		return acpi_dma_request_slave_chan_by_name(dev, name);
707
		chan = acpi_dma_request_slave_chan_by_name(dev, name);
708
709
	if (chan) {
710
		/* Valid channel found or requester need to be deferred */
711
		if (!IS_ERR(chan) || PTR_ERR(chan) == -EPROBE_DEFER)
712
			return chan;
713
	}
714
715
	/* Try to find the channel via the DMA filter map(s) */
716
	mutex_lock(&dma_list_mutex);
717
	list_for_each_entry_safe(d, _d, &dma_device_list, global_node) {
718
		dma_cap_mask_t mask;
719
		const struct dma_slave_map *map = dma_filter_match(d, name, dev);
720
721
		if (!map)
722
			continue;
723
724
		dma_cap_zero(mask);
725
		dma_cap_set(DMA_SLAVE, mask);
685
726
686
	return ERR_PTR(-ENODEV);
727
		chan = find_candidate(d, &mask, d->filter.fn, map->param);
728
		if (!IS_ERR(chan))
729
			break;
730
	}
731
	mutex_unlock(&dma_list_mutex);
732
733
	return chan ? chan : ERR_PTR(-EPROBE_DEFER);
687
}
734
}
688
EXPORT_SYMBOL_GPL(dma_request_slave_channel_reason);
735
EXPORT_SYMBOL_GPL(dma_request_chan);
689
736
690
/**
737
/**
691
 * dma_request_slave_channel - try to allocate an exclusive slave channel
738
 * dma_request_slave_channel - try to allocate an exclusive slave channel
Lines 697-713 EXPORT_SYMBOL_GPL(dma_request_slave_channel_reason); Link Here
697
struct dma_chan *dma_request_slave_channel(struct device *dev,
744
struct dma_chan *dma_request_slave_channel(struct device *dev,
698
					   const char *name)
745
					   const char *name)
699
{
746
{
700
	struct dma_chan *ch = dma_request_slave_channel_reason(dev, name);
747
	struct dma_chan *ch = dma_request_chan(dev, name);
701
	if (IS_ERR(ch))
748
	if (IS_ERR(ch))
702
		return NULL;
749
		return NULL;
703
750
704
	dma_cap_set(DMA_PRIVATE, ch->device->cap_mask);
705
	ch->device->privatecnt++;
706
707
	return ch;
751
	return ch;
708
}
752
}
709
EXPORT_SYMBOL_GPL(dma_request_slave_channel);
753
EXPORT_SYMBOL_GPL(dma_request_slave_channel);
710
754
755
/**
756
 * dma_request_chan_by_mask - allocate a channel satisfying certain capabilities
757
 * @mask: capabilities that the channel must satisfy
758
 *
759
 * Returns pointer to appropriate DMA channel on success or an error pointer.
760
 */
761
struct dma_chan *dma_request_chan_by_mask(const dma_cap_mask_t *mask)
762
{
763
	struct dma_chan *chan;
764
765
	if (!mask)
766
		return ERR_PTR(-ENODEV);
767
768
	chan = __dma_request_channel(mask, NULL, NULL);
769
	if (!chan)
770
		chan = ERR_PTR(-ENODEV);
771
772
	return chan;
773
}
774
EXPORT_SYMBOL_GPL(dma_request_chan_by_mask);
775
711
void dma_release_channel(struct dma_chan *chan)
776
void dma_release_channel(struct dma_chan *chan)
712
{
777
{
713
	mutex_lock(&dma_list_mutex);
778
	mutex_lock(&dma_list_mutex);
(-)a/include/linux/dmaengine.h (-8 / +44 lines)
Lines 623-633 enum dmaengine_alignment { Link Here
623
};
623
};
624
624
625
/**
625
/**
626
 * struct dma_slave_map - associates slave device and it's slave channel with
627
 * parameter to be used by a filter function
628
 * @devname: name of the device
629
 * @slave: slave channel name
630
 * @param: opaque parameter to pass to struct dma_filter.fn
631
 */
632
struct dma_slave_map {
633
	const char *devname;
634
	const char *slave;
635
	void *param;
636
};
637
638
/**
639
 * struct dma_filter - information for slave device/channel to filter_fn/param
640
 * mapping
641
 * @fn: filter function callback
642
 * @mapcnt: number of slave device/channel in the map
643
 * @map: array of channel to filter mapping data
644
 */
645
struct dma_filter {
646
	dma_filter_fn fn;
647
	int mapcnt;
648
	const struct dma_slave_map *map;
649
};
650
651
/**
626
 * struct dma_device - info on the entity supplying DMA services
652
 * struct dma_device - info on the entity supplying DMA services
627
 * @chancnt: how many DMA channels are supported
653
 * @chancnt: how many DMA channels are supported
628
 * @privatecnt: how many DMA channels are requested by dma_request_channel
654
 * @privatecnt: how many DMA channels are requested by dma_request_channel
629
 * @channels: the list of struct dma_chan
655
 * @channels: the list of struct dma_chan
630
 * @global_node: list_head for global dma_device_list
656
 * @global_node: list_head for global dma_device_list
657
 * @filter: information for device/slave to filter function/param mapping
631
 * @cap_mask: one or more dma_capability flags
658
 * @cap_mask: one or more dma_capability flags
632
 * @max_xor: maximum number of xor sources, 0 if no capability
659
 * @max_xor: maximum number of xor sources, 0 if no capability
633
 * @max_pq: maximum number of PQ sources and PQ-continue capability
660
 * @max_pq: maximum number of PQ sources and PQ-continue capability
Lines 682-687 struct dma_device { Link Here
682
	unsigned int privatecnt;
709
	unsigned int privatecnt;
683
	struct list_head channels;
710
	struct list_head channels;
684
	struct list_head global_node;
711
	struct list_head global_node;
712
	struct dma_filter filter;
685
	dma_cap_mask_t  cap_mask;
713
	dma_cap_mask_t  cap_mask;
686
	unsigned short max_xor;
714
	unsigned short max_xor;
687
	unsigned short max_pq;
715
	unsigned short max_pq;
Lines 1156-1164 enum dma_status dma_wait_for_async_tx(struct dma_async_tx_descriptor *tx); Link Here
1156
void dma_issue_pending_all(void);
1184
void dma_issue_pending_all(void);
1157
struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
1185
struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
1158
					dma_filter_fn fn, void *fn_param);
1186
					dma_filter_fn fn, void *fn_param);
1159
struct dma_chan *dma_request_slave_channel_reason(struct device *dev,
1160
						  const char *name);
1161
struct dma_chan *dma_request_slave_channel(struct device *dev, const char *name);
1187
struct dma_chan *dma_request_slave_channel(struct device *dev, const char *name);
1188
1189
struct dma_chan *dma_request_chan(struct device *dev, const char *name);
1190
struct dma_chan *dma_request_chan_by_mask(const dma_cap_mask_t *mask);
1191
1162
void dma_release_channel(struct dma_chan *chan);
1192
void dma_release_channel(struct dma_chan *chan);
1163
int dma_get_slave_caps(struct dma_chan *chan, struct dma_slave_caps *caps);
1193
int dma_get_slave_caps(struct dma_chan *chan, struct dma_slave_caps *caps);
1164
#else
1194
#else
Lines 1182-1197 static inline struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask, Link Here
1182
{
1212
{
1183
	return NULL;
1213
	return NULL;
1184
}
1214
}
1185
static inline struct dma_chan *dma_request_slave_channel_reason(
1186
					struct device *dev, const char *name)
1187
{
1188
	return ERR_PTR(-ENODEV);
1189
}
1190
static inline struct dma_chan *dma_request_slave_channel(struct device *dev,
1215
static inline struct dma_chan *dma_request_slave_channel(struct device *dev,
1191
							 const char *name)
1216
							 const char *name)
1192
{
1217
{
1193
	return NULL;
1218
	return NULL;
1194
}
1219
}
1220
static inline struct dma_chan *dma_request_chan(struct device *dev,
1221
						const char *name)
1222
{
1223
	return ERR_PTR(-ENODEV);
1224
}
1225
static inline struct dma_chan *dma_request_chan_by_mask(
1226
						const dma_cap_mask_t *mask)
1227
{
1228
	return ERR_PTR(-ENODEV);
1229
}
1195
static inline void dma_release_channel(struct dma_chan *chan)
1230
static inline void dma_release_channel(struct dma_chan *chan)
1196
{
1231
{
1197
}
1232
}
Lines 1202-1207 static inline int dma_get_slave_caps(struct dma_chan *chan, Link Here
1202
}
1237
}
1203
#endif
1238
#endif
1204
1239
1240
#define dma_request_slave_channel_reason(dev, name) dma_request_chan(dev, name)
1241
1205
static inline int dmaengine_desc_set_reuse(struct dma_async_tx_descriptor *tx)
1242
static inline int dmaengine_desc_set_reuse(struct dma_async_tx_descriptor *tx)
1206
{
1243
{
1207
	struct dma_slave_caps caps;
1244
	struct dma_slave_caps caps;
1208
- 

Return to bug 1043231