acpi.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Copyright (C) 2013,2019 Intel Corporation
  3. #include <linux/acpi.h>
  4. #include <linux/acpi_dma.h>
  5. #include "internal.h"
  6. static bool dw_dma_acpi_filter(struct dma_chan *chan, void *param)
  7. {
  8. struct dw_dma *dw = to_dw_dma(chan->device);
  9. struct dw_dma_chip_pdata *data = dev_get_drvdata(dw->dma.dev);
  10. struct acpi_dma_spec *dma_spec = param;
  11. struct dw_dma_slave slave = {
  12. .dma_dev = dma_spec->dev,
  13. .src_id = dma_spec->slave_id,
  14. .dst_id = dma_spec->slave_id,
  15. .m_master = data->m_master,
  16. .p_master = data->p_master,
  17. };
  18. return dw_dma_filter(chan, &slave);
  19. }
  20. void dw_dma_acpi_controller_register(struct dw_dma *dw)
  21. {
  22. struct device *dev = dw->dma.dev;
  23. struct acpi_dma_filter_info *info;
  24. int ret;
  25. if (!has_acpi_companion(dev))
  26. return;
  27. info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL);
  28. if (!info)
  29. return;
  30. dma_cap_zero(info->dma_cap);
  31. dma_cap_set(DMA_SLAVE, info->dma_cap);
  32. info->filter_fn = dw_dma_acpi_filter;
  33. ret = acpi_dma_controller_register(dev, acpi_dma_simple_xlate, info);
  34. if (ret)
  35. dev_err(dev, "could not register acpi_dma_controller\n");
  36. }
  37. EXPORT_SYMBOL_GPL(dw_dma_acpi_controller_register);
  38. void dw_dma_acpi_controller_free(struct dw_dma *dw)
  39. {
  40. struct device *dev = dw->dma.dev;
  41. if (!has_acpi_companion(dev))
  42. return;
  43. acpi_dma_controller_free(dev);
  44. }
  45. EXPORT_SYMBOL_GPL(dw_dma_acpi_controller_free);