|
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); |