Changes in 4.9.212 xfs: Sanity check flags of Q_XQUOTARM call powerpc/archrandom: fix arch_get_random_seed_int() mt7601u: fix bbp version check in mt7601u_wait_bbp_ready drm/sti: do not remove the drm_bridge that was never added drm/virtio: fix bounds check in virtio_gpu_cmd_get_capset() ALSA: hda: fix unused variable warning IB/rxe: replace kvfree with vfree ALSA: usb-audio: update quirk for B&W PX to remove microphone staging: comedi: ni_mio_common: protect register write overflow pwm: lpss: Release runtime-pm reference from the driver's remove callback mlxsw: reg: QEEC: Add minimum shaper fields pcrypt: use format specifier in kobject_add exportfs: fix 'passing zero to ERR_PTR()' warning drm/dp_mst: Skip validating ports during destruction, just ref net: phy: Fix not to call phy_resume() if PHY is not attached pinctrl: sh-pfc: r8a7740: Add missing REF125CK pin to gether_gmii group pinctrl: sh-pfc: r8a7740: Add missing LCD0 marks to lcd0_data24_1 group pinctrl: sh-pfc: r8a7791: Remove bogus ctrl marks from qspi_data4_b group pinctrl: sh-pfc: r8a7791: Remove bogus marks from vin1_b_data18 group pinctrl: sh-pfc: sh73a0: Add missing TO pin to tpu4_to3 group pinctrl: sh-pfc: r8a7794: Remove bogus IPSR9 field pinctrl: sh-pfc: sh7734: Add missing IPSR11 field pinctrl: sh-pfc: sh7269: Add missing PCIOR0 field pinctrl: sh-pfc: sh7734: Remove bogus IPSR10 value Input: nomadik-ske-keypad - fix a loop timeout test clk: highbank: fix refcount leak in hb_clk_init() clk: qoriq: fix refcount leak in clockgen_init() clk: socfpga: fix refcount leak clk: samsung: exynos4: fix refcount leak in exynos4_get_xom() clk: imx6q: fix refcount leak in imx6q_clocks_init() clk: imx6sx: fix refcount leak in imx6sx_clocks_init() clk: imx7d: fix refcount leak in imx7d_clocks_init() clk: vf610: fix refcount leak in vf610_clocks_init() clk: armada-370: fix refcount leak in a370_clk_init() clk: kirkwood: fix refcount leak in kirkwood_clk_init() clk: armada-xp: fix refcount leak in axp_clk_init() clk: dove: fix refcount leak in dove_clk_init() IB/usnic: Fix out of bounds index check in query pkey RDMA/ocrdma: Fix out of bounds index check in query pkey RDMA/qedr: Fix out of bounds index check in query pkey arm64: dts: apq8016-sbc: Increase load on l11 for SDCARD drm/etnaviv: NULL vs IS_ERR() buf in etnaviv_core_dump() media: s5p-jpeg: Correct step and max values for V4L2_CID_JPEG_RESTART_INTERVAL crypto: tgr192 - fix unaligned memory access ASoC: imx-sgtl5000: put of nodes if finding codec fails IB/iser: Pass the correct number of entries for dma mapped SGL rtc: cmos: ignore bogus century byte clk: sunxi-ng: sun8i-a23: Enable PLL-MIPI LDOs when ungating it iwlwifi: mvm: fix A-MPDU reference assignment tty: ipwireless: Fix potential NULL pointer dereference crypto: crypto4xx - Fix wrong ppc4xx_trng_probe()/ppc4xx_trng_remove() arguments ARM: dts: lpc32xx: add required clocks property to keypad device node ARM: dts: lpc32xx: reparent keypad controller to SIC1 ARM: dts: lpc32xx: fix ARM PrimeCell LCD controller variant ARM: dts: lpc32xx: fix ARM PrimeCell LCD controller clocks property ARM: dts: lpc32xx: phy3250: fix SD card regulator voltage iwlwifi: mvm: fix RSS config command staging: most: cdev: add missing check for cdev_add failure rtc: ds1672: fix unintended sign extension thermal: mediatek: fix register index error net: phy: fixed_phy: Fix fixed_phy not checking GPIO rtc: 88pm860x: fix unintended sign extension rtc: 88pm80x: fix unintended sign extension rtc: pm8xxx: fix unintended sign extension fbdev: chipsfb: remove set but not used variable 'size' iw_cxgb4: use tos when importing the endpoint iw_cxgb4: use tos when finding ipv6 routes pinctrl: sh-pfc: emev2: Add missing pinmux functions pinctrl: sh-pfc: r8a7791: Fix scifb2_data_c pin group pinctrl: sh-pfc: r8a7792: Fix vin1_data18_b pin group pinctrl: sh-pfc: sh73a0: Fix fsic_spdif pin groups usb: phy: twl6030-usb: fix possible use-after-free on remove block: don't use bio->bi_vcnt to figure out segment number keys: Timestamp new keys vfio_pci: Enable memory accesses before calling pci_map_rom dmaengine: mv_xor: Use correct device for DMA API cdc-wdm: pass return value of recover_from_urb_loss regulator: pv88060: Fix array out-of-bounds access regulator: pv88080: Fix array out-of-bounds access regulator: pv88090: Fix array out-of-bounds access net: dsa: qca8k: Enable delay for RGMII_ID mode drm/nouveau/bios/ramcfg: fix missing parentheses when calculating RON drm/nouveau/pmu: don't print reply values if exec is false ASoC: qcom: Fix of-node refcount unbalance in apq8016_sbc_parse_of() fs/nfs: Fix nfs_parse_devname to not modify it's argument NFS: Fix a soft lockup in the delegation recovery code clocksource/drivers/sun5i: Fail gracefully when clock rate is unavailable clocksource/drivers/exynos_mct: Fix error path in timer resources initialization mmc: sdhci-brcmstb: handle mmc_of_parse() errors during probe ARM: 8847/1: pm: fix HYP/SVC mode mismatch when MCPM is used ARM: 8848/1: virt: Align GIC version check with arm64 counterpart regulator: wm831x-dcdc: Fix list of wm831x_dcdc_ilim from mA to uA nios2: ksyms: Add missing symbol exports scsi: megaraid_sas: reduce module load time drivers/rapidio/rio_cm.c: fix potential oops in riocm_ch_listen() xen, cpu_hotplug: Prevent an out of bounds access net: sh_eth: fix a missing check of of_get_phy_mode media: ivtv: update *pos correctly in ivtv_read_pos() media: cx18: update *pos correctly in cx18_read_pos() media: wl128x: Fix an error code in fm_download_firmware() media: cx23885: check allocation return regulator: tps65086: Fix tps65086_ldoa1_ranges for selector 0xB jfs: fix bogus variable self-initialization tipc: tipc clang warning m68k: mac: Fix VIA timer counter accesses ARM: OMAP2+: Fix potentially uninitialized return value for _setup_reset() media: davinci-isif: avoid uninitialized variable use media: tw5864: Fix possible NULL pointer dereference in tw5864_handle_frame spi: tegra114: clear packed bit for unpacked mode spi: tegra114: fix for unpacked mode transfers soc/fsl/qe: Fix an error code in qe_pin_request() spi: bcm2835aux: fix driver to not allow 65535 (=-1) cs-gpios ehea: Fix a copy-paste err in ehea_init_port_res scsi: qla2xxx: Unregister chrdev if module initialization fails ARM: pxa: ssp: Fix "WARNING: invalid free of devm_ allocated data" hwmon: (w83627hf) Use request_muxed_region for Super-IO accesses tipc: set sysctl_tipc_rmem and named_timeout right range powerpc: vdso: Make vdso32 installation conditional in vdso_install ARM: dts: ls1021: Fix SGMII PCS link remaining down after PHY disconnect media: ov2659: fix unbalanced mutex_lock/unlock 6lowpan: Off by one handling ->nexthdr dmaengine: axi-dmac: Don't check the number of frames for alignment ALSA: usb-audio: Handle the error from snd_usb_mixer_apply_create_quirk() packet: in recvmsg msg_name return at least sizeof sockaddr_ll ASoC: fix valid stream condition usb: gadget: fsl: fix link error against usb-gadget module IB/mlx5: Add missing XRC options to QP optional params mask iommu/vt-d: Make kernel parameter igfx_off work with vIOMMU net: ena: fix swapped parameters when calling ena_com_indirect_table_fill_entry net: ena: fix: Free napi resources when ena_up() fails net: ena: fix incorrect test of supported hash function net: ena: fix ena_com_fill_hash_function() implementation dmaengine: tegra210-adma: restore channel status l2tp: Fix possible NULL pointer dereference media: omap_vout: potential buffer overflow in vidioc_dqbuf() media: davinci/vpbe: array underflow in vpbe_enum_outputs() platform/x86: alienware-wmi: printing the wrong error code netfilter: ebtables: CONFIG_COMPAT: reject trailing data after last rule pwm: meson: Don't disable PWM when setting duty repeatedly ARM: riscpc: fix lack of keyboard interrupts after irq conversion kdb: do a sanity check on the cpu in kdb_per_cpu() backlight: lm3630a: Return 0 on success in update_status functions thermal: cpu_cooling: Actually trace CPU load in thermal_power_cpu_get_power dmaengine: tegra210-adma: Fix crash during probe spi: spi-fsl-spi: call spi_finalize_current_message() at the end crypto: ccp - fix AES CFB error exposed by new test vectors serial: stm32: fix transmit_chars when tx is stopped misc: sgi-xp: Properly initialize buf in xpc_get_rsvd_page_pa iommu: Use right function to get group for device signal/cifs: Fix cifs_put_tcp_session to call send_sig instead of force_sig inet: frags: call inet_frags_fini() after unregister_pernet_subsys() media: vivid: fix incorrect assignment operation when setting video mode powerpc/cacheinfo: add cacheinfo_teardown, cacheinfo_rebuild drm/msm/mdp5: Fix mdp5_cfg_init error return net: netem: fix backlog accounting for corrupted GSO frames net/af_iucv: always register net_device notifier ASoC: ti: davinci-mcasp: Fix slot mask settings when using multiple AXRs rtc: pcf8563: Clear event flags and disable interrupts before requesting irq drm/msm/a3xx: remove TPL1 regs from snapshot perf/ioctl: Add check for the sample_period value dmaengine: hsu: Revert "set HSU_CH_MTSR to memory width" clk: qcom: Fix -Wunused-const-variable iommu/amd: Make iommu_disable safer mfd: intel-lpss: Release IDA resources rxrpc: Fix uninitialized error code in rxrpc_send_data_packet() devres: allow const resource arguments RDMA/hns: Fixs hw access invalid dma memory error net: pasemi: fix an use-after-free in pasemi_mac_phy_init() scsi: libfc: fix null pointer dereference on a null lport libertas_tf: Use correct channel range in lbtf_geo_init qed: reduce maximum stack frame size usb: host: xhci-hub: fix extra endianness conversion mic: avoid statically declaring a 'struct device'. x86/kgbd: Use NMI_VECTOR not APIC_DM_NMI ALSA: aoa: onyx: always initialize register read value net/mlx5: Fix mlx5_ifc_query_lag_out_bits cifs: fix rmmod regression in cifs.ko caused by force_sig changes crypto: caam - free resources in case caam_rng registration failed ext4: set error return correctly when ext4_htree_store_dirent fails ASoC: es8328: Fix copy-paste error in es8328_right_line_controls ASoC: cs4349: Use PM ops 'cs4349_runtime_pm' ASoC: wm8737: Fix copy-paste error in wm8737_snd_controls signal: Allow cifs and drbd to receive their terminating signals ASoC: sun4i-i2s: RX and TX counter registers are swapped dmaengine: dw: platform: Switch to acpi_dma_controller_register() mac80211: minstrel_ht: fix per-group max throughput rate initialization mips: avoid explicit UB in assignment of mips_io_port_base ahci: Do not export local variable ahci_em_messages Partially revert "kfifo: fix kfifo_alloc() and kfifo_init()" hwmon: (lm75) Fix write operations for negative temperatures power: supply: Init device wakeup after device_add() x86, perf: Fix the dependency of the x86 insn decoder selftest staging: greybus: light: fix a couple double frees bcma: fix incorrect update of BCMA_CORE_PCI_MDIO_DATA iio: dac: ad5380: fix incorrect assignment to val ath9k: dynack: fix possible deadlock in ath_dynack_node_{de}init net: sonic: return NETDEV_TX_OK if failed to map buffer Btrfs: fix hang when loading existing inode cache off disk hwmon: (shtc1) fix shtc1 and shtw1 id mask net: sonic: replace dev_kfree_skb in sonic_send_packet net/rds: Fix 'ib_evt_handler_call' element in 'rds_ib_stat_names' iommu/amd: Wait for completion of IOTLB flush in attach_device net: hisilicon: Fix signedness bug in hix5hd2_dev_probe() net: broadcom/bcmsysport: Fix signedness in bcm_sysport_probe() net: stmmac: dwmac-meson8b: Fix signedness bug in probe of: mdio: Fix a signedness bug in of_phy_get_and_connect() net: ethernet: stmmac: Fix signedness bug in ipq806x_gmac_of_parse() nvme: retain split access workaround for capability reads net: stmmac: gmac4+: Not all Unicast addresses may be available mac80211: accept deauth frames in IBSS mode llc: fix another potential sk_buff leak in llc_ui_sendmsg() llc: fix sk_buff refcounting in llc_conn_state_process() net: stmmac: fix length of PTP clock's name string act_mirred: Fix mirred_init_module error handling drm/msm/dsi: Implement reset correctly dmaengine: imx-sdma: fix size check for sdma script_number net: netem: fix error path for corrupted GSO frames net: netem: correct the parent's backlog when corrupted packet was dropped net: qca_spi: Move reset_count to struct qcaspi afs: Fix large file support media: ov6650: Fix incorrect use of JPEG colorspace media: ov6650: Fix some format attributes not under control media: ov6650: Fix .get_fmt() V4L2_SUBDEV_FORMAT_TRY support MIPS: Loongson: Fix return value of loongson_hwmon_init net: neigh: use long type to store jiffies delta packet: fix data-race in fanout_flow_is_huge() dmaengine: ti: edma: fix missed failure handling drm/radeon: fix bad DMA from INTERRUPT_CNTL2 arm64: dts: juno: Fix UART frequency IB/iser: Fix dma_nents type definition m68k: Call timer_interrupt() with interrupts disabled net: ethtool: Add back transceiver type net: phy: Keep reporting transceiver type can, slip: Protect tty->disc_data in write_wakeup and close with RCU firestream: fix memory leaks net: cxgb3_main: Add CAP_NET_ADMIN check to CHELSIO_GET_MEM net, ip6_tunnel: fix namespaces move net, ip_tunnel: fix namespaces move net_sched: fix datalen for ematch tcp_bbr: improve arithmetic division in bbr_update_bw() net: usb: lan78xx: Add .ndo_features_check gtp: make sure only SOCK_DGRAM UDP sockets are accepted hwmon: (adt7475) Make volt2reg return same reg as reg2volt input hwmon: (core) Simplify sysfs attribute name allocation hwmon: Deal with errors from the thermal subsystem hwmon: (core) Fix double-free in __hwmon_device_register() hwmon: (core) Do not use device managed functions for memory allocations Input: keyspan-remote - fix control-message timeouts ARM: 8950/1: ftrace/recordmcount: filter relocation types mmc: tegra: fix SDR50 tuning override mmc: sdhci: fix minimum clock rate for v3 controller Input: sur40 - fix interface sanity checks Input: gtco - fix endpoint sanity check Input: aiptek - fix endpoint sanity check Input: pegasus_notetaker - fix endpoint sanity check Input: sun4i-ts - add a check for devm_thermal_zone_of_sensor_register hwmon: (nct7802) Fix voltage limits to wrong registers scsi: RDMA/isert: Fix a recently introduced regression related to logout tracing: xen: Ordered comparison of function pointers do_last(): fetch directory ->i_mode and ->i_uid before it's too late Documentation: Document arm64 kpti control arm64: kpti: Whitelist Cortex-A CPUs that don't implement the CSV3 field coresight: etb10: Do not call smp_processor_id from preemptible coresight: tmc-etf: Do not call smp_processor_id from preemptible libertas: Fix two buffer overflows at parsing bss descriptor bcache: silence static checker warning scsi: iscsi: Avoid potential deadlock in iscsi_if_rx func md: Avoid namespace collision with bitmap API bitmap: Add bitmap_alloc(), bitmap_zalloc() and bitmap_free() netfilter: ipset: use bitmap infrastructure completely net/x25: fix nonblocking connect Linux 4.9.212 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: I2e83a05c5f119a7467a4d6984045d45d0c06b764
706 lines
18 KiB
C
706 lines
18 KiB
C
/*
|
|
* Driver for the Analog Devices AXI-DMAC core
|
|
*
|
|
* Copyright 2013-2015 Analog Devices Inc.
|
|
* Author: Lars-Peter Clausen <lars@metafoo.de>
|
|
*
|
|
* Licensed under the GPL-2.
|
|
*/
|
|
|
|
#include <linux/clk.h>
|
|
#include <linux/device.h>
|
|
#include <linux/dma-mapping.h>
|
|
#include <linux/dmaengine.h>
|
|
#include <linux/err.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/io.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/module.h>
|
|
#include <linux/of.h>
|
|
#include <linux/of_dma.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/slab.h>
|
|
|
|
#include <dt-bindings/dma/axi-dmac.h>
|
|
|
|
#include "dmaengine.h"
|
|
#include "virt-dma.h"
|
|
|
|
/*
|
|
* The AXI-DMAC is a soft IP core that is used in FPGA designs. The core has
|
|
* various instantiation parameters which decided the exact feature set support
|
|
* by the core.
|
|
*
|
|
* Each channel of the core has a source interface and a destination interface.
|
|
* The number of channels and the type of the channel interfaces is selected at
|
|
* configuration time. A interface can either be a connected to a central memory
|
|
* interconnect, which allows access to system memory, or it can be connected to
|
|
* a dedicated bus which is directly connected to a data port on a peripheral.
|
|
* Given that those are configuration options of the core that are selected when
|
|
* it is instantiated this means that they can not be changed by software at
|
|
* runtime. By extension this means that each channel is uni-directional. It can
|
|
* either be device to memory or memory to device, but not both. Also since the
|
|
* device side is a dedicated data bus only connected to a single peripheral
|
|
* there is no address than can or needs to be configured for the device side.
|
|
*/
|
|
|
|
#define AXI_DMAC_REG_IRQ_MASK 0x80
|
|
#define AXI_DMAC_REG_IRQ_PENDING 0x84
|
|
#define AXI_DMAC_REG_IRQ_SOURCE 0x88
|
|
|
|
#define AXI_DMAC_REG_CTRL 0x400
|
|
#define AXI_DMAC_REG_TRANSFER_ID 0x404
|
|
#define AXI_DMAC_REG_START_TRANSFER 0x408
|
|
#define AXI_DMAC_REG_FLAGS 0x40c
|
|
#define AXI_DMAC_REG_DEST_ADDRESS 0x410
|
|
#define AXI_DMAC_REG_SRC_ADDRESS 0x414
|
|
#define AXI_DMAC_REG_X_LENGTH 0x418
|
|
#define AXI_DMAC_REG_Y_LENGTH 0x41c
|
|
#define AXI_DMAC_REG_DEST_STRIDE 0x420
|
|
#define AXI_DMAC_REG_SRC_STRIDE 0x424
|
|
#define AXI_DMAC_REG_TRANSFER_DONE 0x428
|
|
#define AXI_DMAC_REG_ACTIVE_TRANSFER_ID 0x42c
|
|
#define AXI_DMAC_REG_STATUS 0x430
|
|
#define AXI_DMAC_REG_CURRENT_SRC_ADDR 0x434
|
|
#define AXI_DMAC_REG_CURRENT_DEST_ADDR 0x438
|
|
|
|
#define AXI_DMAC_CTRL_ENABLE BIT(0)
|
|
#define AXI_DMAC_CTRL_PAUSE BIT(1)
|
|
|
|
#define AXI_DMAC_IRQ_SOT BIT(0)
|
|
#define AXI_DMAC_IRQ_EOT BIT(1)
|
|
|
|
#define AXI_DMAC_FLAG_CYCLIC BIT(0)
|
|
|
|
struct axi_dmac_sg {
|
|
dma_addr_t src_addr;
|
|
dma_addr_t dest_addr;
|
|
unsigned int x_len;
|
|
unsigned int y_len;
|
|
unsigned int dest_stride;
|
|
unsigned int src_stride;
|
|
unsigned int id;
|
|
};
|
|
|
|
struct axi_dmac_desc {
|
|
struct virt_dma_desc vdesc;
|
|
bool cyclic;
|
|
|
|
unsigned int num_submitted;
|
|
unsigned int num_completed;
|
|
unsigned int num_sgs;
|
|
struct axi_dmac_sg sg[];
|
|
};
|
|
|
|
struct axi_dmac_chan {
|
|
struct virt_dma_chan vchan;
|
|
|
|
struct axi_dmac_desc *next_desc;
|
|
struct list_head active_descs;
|
|
enum dma_transfer_direction direction;
|
|
|
|
unsigned int src_width;
|
|
unsigned int dest_width;
|
|
unsigned int src_type;
|
|
unsigned int dest_type;
|
|
|
|
unsigned int max_length;
|
|
unsigned int align_mask;
|
|
|
|
bool hw_cyclic;
|
|
bool hw_2d;
|
|
};
|
|
|
|
struct axi_dmac {
|
|
void __iomem *base;
|
|
int irq;
|
|
|
|
struct clk *clk;
|
|
|
|
struct dma_device dma_dev;
|
|
struct axi_dmac_chan chan;
|
|
|
|
struct device_dma_parameters dma_parms;
|
|
};
|
|
|
|
static struct axi_dmac *chan_to_axi_dmac(struct axi_dmac_chan *chan)
|
|
{
|
|
return container_of(chan->vchan.chan.device, struct axi_dmac,
|
|
dma_dev);
|
|
}
|
|
|
|
static struct axi_dmac_chan *to_axi_dmac_chan(struct dma_chan *c)
|
|
{
|
|
return container_of(c, struct axi_dmac_chan, vchan.chan);
|
|
}
|
|
|
|
static struct axi_dmac_desc *to_axi_dmac_desc(struct virt_dma_desc *vdesc)
|
|
{
|
|
return container_of(vdesc, struct axi_dmac_desc, vdesc);
|
|
}
|
|
|
|
static void axi_dmac_write(struct axi_dmac *axi_dmac, unsigned int reg,
|
|
unsigned int val)
|
|
{
|
|
writel(val, axi_dmac->base + reg);
|
|
}
|
|
|
|
static int axi_dmac_read(struct axi_dmac *axi_dmac, unsigned int reg)
|
|
{
|
|
return readl(axi_dmac->base + reg);
|
|
}
|
|
|
|
static int axi_dmac_src_is_mem(struct axi_dmac_chan *chan)
|
|
{
|
|
return chan->src_type == AXI_DMAC_BUS_TYPE_AXI_MM;
|
|
}
|
|
|
|
static int axi_dmac_dest_is_mem(struct axi_dmac_chan *chan)
|
|
{
|
|
return chan->dest_type == AXI_DMAC_BUS_TYPE_AXI_MM;
|
|
}
|
|
|
|
static bool axi_dmac_check_len(struct axi_dmac_chan *chan, unsigned int len)
|
|
{
|
|
if (len == 0 || len > chan->max_length)
|
|
return false;
|
|
if ((len & chan->align_mask) != 0) /* Not aligned */
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
static bool axi_dmac_check_addr(struct axi_dmac_chan *chan, dma_addr_t addr)
|
|
{
|
|
if ((addr & chan->align_mask) != 0) /* Not aligned */
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
static void axi_dmac_start_transfer(struct axi_dmac_chan *chan)
|
|
{
|
|
struct axi_dmac *dmac = chan_to_axi_dmac(chan);
|
|
struct virt_dma_desc *vdesc;
|
|
struct axi_dmac_desc *desc;
|
|
struct axi_dmac_sg *sg;
|
|
unsigned int flags = 0;
|
|
unsigned int val;
|
|
|
|
val = axi_dmac_read(dmac, AXI_DMAC_REG_START_TRANSFER);
|
|
if (val) /* Queue is full, wait for the next SOT IRQ */
|
|
return;
|
|
|
|
desc = chan->next_desc;
|
|
|
|
if (!desc) {
|
|
vdesc = vchan_next_desc(&chan->vchan);
|
|
if (!vdesc)
|
|
return;
|
|
list_move_tail(&vdesc->node, &chan->active_descs);
|
|
desc = to_axi_dmac_desc(vdesc);
|
|
}
|
|
sg = &desc->sg[desc->num_submitted];
|
|
|
|
desc->num_submitted++;
|
|
if (desc->num_submitted == desc->num_sgs)
|
|
chan->next_desc = NULL;
|
|
else
|
|
chan->next_desc = desc;
|
|
|
|
sg->id = axi_dmac_read(dmac, AXI_DMAC_REG_TRANSFER_ID);
|
|
|
|
if (axi_dmac_dest_is_mem(chan)) {
|
|
axi_dmac_write(dmac, AXI_DMAC_REG_DEST_ADDRESS, sg->dest_addr);
|
|
axi_dmac_write(dmac, AXI_DMAC_REG_DEST_STRIDE, sg->dest_stride);
|
|
}
|
|
|
|
if (axi_dmac_src_is_mem(chan)) {
|
|
axi_dmac_write(dmac, AXI_DMAC_REG_SRC_ADDRESS, sg->src_addr);
|
|
axi_dmac_write(dmac, AXI_DMAC_REG_SRC_STRIDE, sg->src_stride);
|
|
}
|
|
|
|
/*
|
|
* If the hardware supports cyclic transfers and there is no callback to
|
|
* call, enable hw cyclic mode to avoid unnecessary interrupts.
|
|
*/
|
|
if (chan->hw_cyclic && desc->cyclic && !desc->vdesc.tx.callback)
|
|
flags |= AXI_DMAC_FLAG_CYCLIC;
|
|
|
|
axi_dmac_write(dmac, AXI_DMAC_REG_X_LENGTH, sg->x_len - 1);
|
|
axi_dmac_write(dmac, AXI_DMAC_REG_Y_LENGTH, sg->y_len - 1);
|
|
axi_dmac_write(dmac, AXI_DMAC_REG_FLAGS, flags);
|
|
axi_dmac_write(dmac, AXI_DMAC_REG_START_TRANSFER, 1);
|
|
}
|
|
|
|
static struct axi_dmac_desc *axi_dmac_active_desc(struct axi_dmac_chan *chan)
|
|
{
|
|
return list_first_entry_or_null(&chan->active_descs,
|
|
struct axi_dmac_desc, vdesc.node);
|
|
}
|
|
|
|
static void axi_dmac_transfer_done(struct axi_dmac_chan *chan,
|
|
unsigned int completed_transfers)
|
|
{
|
|
struct axi_dmac_desc *active;
|
|
struct axi_dmac_sg *sg;
|
|
|
|
active = axi_dmac_active_desc(chan);
|
|
if (!active)
|
|
return;
|
|
|
|
if (active->cyclic) {
|
|
vchan_cyclic_callback(&active->vdesc);
|
|
} else {
|
|
do {
|
|
sg = &active->sg[active->num_completed];
|
|
if (!(BIT(sg->id) & completed_transfers))
|
|
break;
|
|
active->num_completed++;
|
|
if (active->num_completed == active->num_sgs) {
|
|
list_del(&active->vdesc.node);
|
|
vchan_cookie_complete(&active->vdesc);
|
|
active = axi_dmac_active_desc(chan);
|
|
}
|
|
} while (active);
|
|
}
|
|
}
|
|
|
|
static irqreturn_t axi_dmac_interrupt_handler(int irq, void *devid)
|
|
{
|
|
struct axi_dmac *dmac = devid;
|
|
unsigned int pending;
|
|
|
|
pending = axi_dmac_read(dmac, AXI_DMAC_REG_IRQ_PENDING);
|
|
if (!pending)
|
|
return IRQ_NONE;
|
|
|
|
axi_dmac_write(dmac, AXI_DMAC_REG_IRQ_PENDING, pending);
|
|
|
|
spin_lock(&dmac->chan.vchan.lock);
|
|
/* One or more transfers have finished */
|
|
if (pending & AXI_DMAC_IRQ_EOT) {
|
|
unsigned int completed;
|
|
|
|
completed = axi_dmac_read(dmac, AXI_DMAC_REG_TRANSFER_DONE);
|
|
axi_dmac_transfer_done(&dmac->chan, completed);
|
|
}
|
|
/* Space has become available in the descriptor queue */
|
|
if (pending & AXI_DMAC_IRQ_SOT)
|
|
axi_dmac_start_transfer(&dmac->chan);
|
|
spin_unlock(&dmac->chan.vchan.lock);
|
|
|
|
return IRQ_HANDLED;
|
|
}
|
|
|
|
static int axi_dmac_terminate_all(struct dma_chan *c)
|
|
{
|
|
struct axi_dmac_chan *chan = to_axi_dmac_chan(c);
|
|
struct axi_dmac *dmac = chan_to_axi_dmac(chan);
|
|
unsigned long flags;
|
|
LIST_HEAD(head);
|
|
|
|
spin_lock_irqsave(&chan->vchan.lock, flags);
|
|
axi_dmac_write(dmac, AXI_DMAC_REG_CTRL, 0);
|
|
chan->next_desc = NULL;
|
|
vchan_get_all_descriptors(&chan->vchan, &head);
|
|
list_splice_tail_init(&chan->active_descs, &head);
|
|
spin_unlock_irqrestore(&chan->vchan.lock, flags);
|
|
|
|
vchan_dma_desc_free_list(&chan->vchan, &head);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void axi_dmac_synchronize(struct dma_chan *c)
|
|
{
|
|
struct axi_dmac_chan *chan = to_axi_dmac_chan(c);
|
|
|
|
vchan_synchronize(&chan->vchan);
|
|
}
|
|
|
|
static void axi_dmac_issue_pending(struct dma_chan *c)
|
|
{
|
|
struct axi_dmac_chan *chan = to_axi_dmac_chan(c);
|
|
struct axi_dmac *dmac = chan_to_axi_dmac(chan);
|
|
unsigned long flags;
|
|
|
|
axi_dmac_write(dmac, AXI_DMAC_REG_CTRL, AXI_DMAC_CTRL_ENABLE);
|
|
|
|
spin_lock_irqsave(&chan->vchan.lock, flags);
|
|
if (vchan_issue_pending(&chan->vchan))
|
|
axi_dmac_start_transfer(chan);
|
|
spin_unlock_irqrestore(&chan->vchan.lock, flags);
|
|
}
|
|
|
|
static struct axi_dmac_desc *axi_dmac_alloc_desc(unsigned int num_sgs)
|
|
{
|
|
struct axi_dmac_desc *desc;
|
|
|
|
desc = kzalloc(sizeof(struct axi_dmac_desc) +
|
|
sizeof(struct axi_dmac_sg) * num_sgs, GFP_NOWAIT);
|
|
if (!desc)
|
|
return NULL;
|
|
|
|
desc->num_sgs = num_sgs;
|
|
|
|
return desc;
|
|
}
|
|
|
|
static struct dma_async_tx_descriptor *axi_dmac_prep_slave_sg(
|
|
struct dma_chan *c, struct scatterlist *sgl,
|
|
unsigned int sg_len, enum dma_transfer_direction direction,
|
|
unsigned long flags, void *context)
|
|
{
|
|
struct axi_dmac_chan *chan = to_axi_dmac_chan(c);
|
|
struct axi_dmac_desc *desc;
|
|
struct scatterlist *sg;
|
|
unsigned int i;
|
|
|
|
if (direction != chan->direction)
|
|
return NULL;
|
|
|
|
desc = axi_dmac_alloc_desc(sg_len);
|
|
if (!desc)
|
|
return NULL;
|
|
|
|
for_each_sg(sgl, sg, sg_len, i) {
|
|
if (!axi_dmac_check_addr(chan, sg_dma_address(sg)) ||
|
|
!axi_dmac_check_len(chan, sg_dma_len(sg))) {
|
|
kfree(desc);
|
|
return NULL;
|
|
}
|
|
|
|
if (direction == DMA_DEV_TO_MEM)
|
|
desc->sg[i].dest_addr = sg_dma_address(sg);
|
|
else
|
|
desc->sg[i].src_addr = sg_dma_address(sg);
|
|
desc->sg[i].x_len = sg_dma_len(sg);
|
|
desc->sg[i].y_len = 1;
|
|
}
|
|
|
|
desc->cyclic = false;
|
|
|
|
return vchan_tx_prep(&chan->vchan, &desc->vdesc, flags);
|
|
}
|
|
|
|
static struct dma_async_tx_descriptor *axi_dmac_prep_dma_cyclic(
|
|
struct dma_chan *c, dma_addr_t buf_addr, size_t buf_len,
|
|
size_t period_len, enum dma_transfer_direction direction,
|
|
unsigned long flags)
|
|
{
|
|
struct axi_dmac_chan *chan = to_axi_dmac_chan(c);
|
|
struct axi_dmac_desc *desc;
|
|
unsigned int num_periods, i;
|
|
|
|
if (direction != chan->direction)
|
|
return NULL;
|
|
|
|
if (!axi_dmac_check_len(chan, buf_len) ||
|
|
!axi_dmac_check_addr(chan, buf_addr))
|
|
return NULL;
|
|
|
|
if (period_len == 0 || buf_len % period_len)
|
|
return NULL;
|
|
|
|
num_periods = buf_len / period_len;
|
|
|
|
desc = axi_dmac_alloc_desc(num_periods);
|
|
if (!desc)
|
|
return NULL;
|
|
|
|
for (i = 0; i < num_periods; i++) {
|
|
if (direction == DMA_DEV_TO_MEM)
|
|
desc->sg[i].dest_addr = buf_addr;
|
|
else
|
|
desc->sg[i].src_addr = buf_addr;
|
|
desc->sg[i].x_len = period_len;
|
|
desc->sg[i].y_len = 1;
|
|
buf_addr += period_len;
|
|
}
|
|
|
|
desc->cyclic = true;
|
|
|
|
return vchan_tx_prep(&chan->vchan, &desc->vdesc, flags);
|
|
}
|
|
|
|
static struct dma_async_tx_descriptor *axi_dmac_prep_interleaved(
|
|
struct dma_chan *c, struct dma_interleaved_template *xt,
|
|
unsigned long flags)
|
|
{
|
|
struct axi_dmac_chan *chan = to_axi_dmac_chan(c);
|
|
struct axi_dmac_desc *desc;
|
|
size_t dst_icg, src_icg;
|
|
|
|
if (xt->frame_size != 1)
|
|
return NULL;
|
|
|
|
if (xt->dir != chan->direction)
|
|
return NULL;
|
|
|
|
if (axi_dmac_src_is_mem(chan)) {
|
|
if (!xt->src_inc || !axi_dmac_check_addr(chan, xt->src_start))
|
|
return NULL;
|
|
}
|
|
|
|
if (axi_dmac_dest_is_mem(chan)) {
|
|
if (!xt->dst_inc || !axi_dmac_check_addr(chan, xt->dst_start))
|
|
return NULL;
|
|
}
|
|
|
|
dst_icg = dmaengine_get_dst_icg(xt, &xt->sgl[0]);
|
|
src_icg = dmaengine_get_src_icg(xt, &xt->sgl[0]);
|
|
|
|
if (chan->hw_2d) {
|
|
if (!axi_dmac_check_len(chan, xt->sgl[0].size) ||
|
|
xt->numf == 0)
|
|
return NULL;
|
|
if (xt->sgl[0].size + dst_icg > chan->max_length ||
|
|
xt->sgl[0].size + src_icg > chan->max_length)
|
|
return NULL;
|
|
} else {
|
|
if (dst_icg != 0 || src_icg != 0)
|
|
return NULL;
|
|
if (chan->max_length / xt->sgl[0].size < xt->numf)
|
|
return NULL;
|
|
if (!axi_dmac_check_len(chan, xt->sgl[0].size * xt->numf))
|
|
return NULL;
|
|
}
|
|
|
|
desc = axi_dmac_alloc_desc(1);
|
|
if (!desc)
|
|
return NULL;
|
|
|
|
if (axi_dmac_src_is_mem(chan)) {
|
|
desc->sg[0].src_addr = xt->src_start;
|
|
desc->sg[0].src_stride = xt->sgl[0].size + src_icg;
|
|
}
|
|
|
|
if (axi_dmac_dest_is_mem(chan)) {
|
|
desc->sg[0].dest_addr = xt->dst_start;
|
|
desc->sg[0].dest_stride = xt->sgl[0].size + dst_icg;
|
|
}
|
|
|
|
if (chan->hw_2d) {
|
|
desc->sg[0].x_len = xt->sgl[0].size;
|
|
desc->sg[0].y_len = xt->numf;
|
|
} else {
|
|
desc->sg[0].x_len = xt->sgl[0].size * xt->numf;
|
|
desc->sg[0].y_len = 1;
|
|
}
|
|
|
|
return vchan_tx_prep(&chan->vchan, &desc->vdesc, flags);
|
|
}
|
|
|
|
static void axi_dmac_free_chan_resources(struct dma_chan *c)
|
|
{
|
|
vchan_free_chan_resources(to_virt_chan(c));
|
|
}
|
|
|
|
static void axi_dmac_desc_free(struct virt_dma_desc *vdesc)
|
|
{
|
|
kfree(container_of(vdesc, struct axi_dmac_desc, vdesc));
|
|
}
|
|
|
|
/*
|
|
* The configuration stored in the devicetree matches the configuration
|
|
* parameters of the peripheral instance and allows the driver to know which
|
|
* features are implemented and how it should behave.
|
|
*/
|
|
static int axi_dmac_parse_chan_dt(struct device_node *of_chan,
|
|
struct axi_dmac_chan *chan)
|
|
{
|
|
u32 val;
|
|
int ret;
|
|
|
|
ret = of_property_read_u32(of_chan, "reg", &val);
|
|
if (ret)
|
|
return ret;
|
|
|
|
/* We only support 1 channel for now */
|
|
if (val != 0)
|
|
return -EINVAL;
|
|
|
|
ret = of_property_read_u32(of_chan, "adi,source-bus-type", &val);
|
|
if (ret)
|
|
return ret;
|
|
if (val > AXI_DMAC_BUS_TYPE_FIFO)
|
|
return -EINVAL;
|
|
chan->src_type = val;
|
|
|
|
ret = of_property_read_u32(of_chan, "adi,destination-bus-type", &val);
|
|
if (ret)
|
|
return ret;
|
|
if (val > AXI_DMAC_BUS_TYPE_FIFO)
|
|
return -EINVAL;
|
|
chan->dest_type = val;
|
|
|
|
ret = of_property_read_u32(of_chan, "adi,source-bus-width", &val);
|
|
if (ret)
|
|
return ret;
|
|
chan->src_width = val / 8;
|
|
|
|
ret = of_property_read_u32(of_chan, "adi,destination-bus-width", &val);
|
|
if (ret)
|
|
return ret;
|
|
chan->dest_width = val / 8;
|
|
|
|
ret = of_property_read_u32(of_chan, "adi,length-width", &val);
|
|
if (ret)
|
|
return ret;
|
|
|
|
if (val >= 32)
|
|
chan->max_length = UINT_MAX;
|
|
else
|
|
chan->max_length = (1ULL << val) - 1;
|
|
|
|
chan->align_mask = max(chan->dest_width, chan->src_width) - 1;
|
|
|
|
if (axi_dmac_dest_is_mem(chan) && axi_dmac_src_is_mem(chan))
|
|
chan->direction = DMA_MEM_TO_MEM;
|
|
else if (!axi_dmac_dest_is_mem(chan) && axi_dmac_src_is_mem(chan))
|
|
chan->direction = DMA_MEM_TO_DEV;
|
|
else if (axi_dmac_dest_is_mem(chan) && !axi_dmac_src_is_mem(chan))
|
|
chan->direction = DMA_DEV_TO_MEM;
|
|
else
|
|
chan->direction = DMA_DEV_TO_DEV;
|
|
|
|
chan->hw_cyclic = of_property_read_bool(of_chan, "adi,cyclic");
|
|
chan->hw_2d = of_property_read_bool(of_chan, "adi,2d");
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int axi_dmac_probe(struct platform_device *pdev)
|
|
{
|
|
struct device_node *of_channels, *of_chan;
|
|
struct dma_device *dma_dev;
|
|
struct axi_dmac *dmac;
|
|
struct resource *res;
|
|
int ret;
|
|
|
|
dmac = devm_kzalloc(&pdev->dev, sizeof(*dmac), GFP_KERNEL);
|
|
if (!dmac)
|
|
return -ENOMEM;
|
|
|
|
dmac->irq = platform_get_irq(pdev, 0);
|
|
if (dmac->irq < 0)
|
|
return dmac->irq;
|
|
if (dmac->irq == 0)
|
|
return -EINVAL;
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
dmac->base = devm_ioremap_resource(&pdev->dev, res);
|
|
if (IS_ERR(dmac->base))
|
|
return PTR_ERR(dmac->base);
|
|
|
|
dmac->clk = devm_clk_get(&pdev->dev, NULL);
|
|
if (IS_ERR(dmac->clk))
|
|
return PTR_ERR(dmac->clk);
|
|
|
|
INIT_LIST_HEAD(&dmac->chan.active_descs);
|
|
|
|
of_channels = of_get_child_by_name(pdev->dev.of_node, "adi,channels");
|
|
if (of_channels == NULL)
|
|
return -ENODEV;
|
|
|
|
for_each_child_of_node(of_channels, of_chan) {
|
|
ret = axi_dmac_parse_chan_dt(of_chan, &dmac->chan);
|
|
if (ret) {
|
|
of_node_put(of_chan);
|
|
of_node_put(of_channels);
|
|
return -EINVAL;
|
|
}
|
|
}
|
|
of_node_put(of_channels);
|
|
|
|
pdev->dev.dma_parms = &dmac->dma_parms;
|
|
dma_set_max_seg_size(&pdev->dev, dmac->chan.max_length);
|
|
|
|
dma_dev = &dmac->dma_dev;
|
|
dma_cap_set(DMA_SLAVE, dma_dev->cap_mask);
|
|
dma_cap_set(DMA_CYCLIC, dma_dev->cap_mask);
|
|
dma_dev->device_free_chan_resources = axi_dmac_free_chan_resources;
|
|
dma_dev->device_tx_status = dma_cookie_status;
|
|
dma_dev->device_issue_pending = axi_dmac_issue_pending;
|
|
dma_dev->device_prep_slave_sg = axi_dmac_prep_slave_sg;
|
|
dma_dev->device_prep_dma_cyclic = axi_dmac_prep_dma_cyclic;
|
|
dma_dev->device_prep_interleaved_dma = axi_dmac_prep_interleaved;
|
|
dma_dev->device_terminate_all = axi_dmac_terminate_all;
|
|
dma_dev->device_synchronize = axi_dmac_synchronize;
|
|
dma_dev->dev = &pdev->dev;
|
|
dma_dev->chancnt = 1;
|
|
dma_dev->src_addr_widths = BIT(dmac->chan.src_width);
|
|
dma_dev->dst_addr_widths = BIT(dmac->chan.dest_width);
|
|
dma_dev->directions = BIT(dmac->chan.direction);
|
|
dma_dev->residue_granularity = DMA_RESIDUE_GRANULARITY_DESCRIPTOR;
|
|
INIT_LIST_HEAD(&dma_dev->channels);
|
|
|
|
dmac->chan.vchan.desc_free = axi_dmac_desc_free;
|
|
vchan_init(&dmac->chan.vchan, dma_dev);
|
|
|
|
ret = clk_prepare_enable(dmac->clk);
|
|
if (ret < 0)
|
|
return ret;
|
|
|
|
axi_dmac_write(dmac, AXI_DMAC_REG_IRQ_MASK, 0x00);
|
|
|
|
ret = dma_async_device_register(dma_dev);
|
|
if (ret)
|
|
goto err_clk_disable;
|
|
|
|
ret = of_dma_controller_register(pdev->dev.of_node,
|
|
of_dma_xlate_by_chan_id, dma_dev);
|
|
if (ret)
|
|
goto err_unregister_device;
|
|
|
|
ret = request_irq(dmac->irq, axi_dmac_interrupt_handler, 0,
|
|
dev_name(&pdev->dev), dmac);
|
|
if (ret)
|
|
goto err_unregister_of;
|
|
|
|
platform_set_drvdata(pdev, dmac);
|
|
|
|
return 0;
|
|
|
|
err_unregister_of:
|
|
of_dma_controller_free(pdev->dev.of_node);
|
|
err_unregister_device:
|
|
dma_async_device_unregister(&dmac->dma_dev);
|
|
err_clk_disable:
|
|
clk_disable_unprepare(dmac->clk);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int axi_dmac_remove(struct platform_device *pdev)
|
|
{
|
|
struct axi_dmac *dmac = platform_get_drvdata(pdev);
|
|
|
|
of_dma_controller_free(pdev->dev.of_node);
|
|
free_irq(dmac->irq, dmac);
|
|
tasklet_kill(&dmac->chan.vchan.task);
|
|
dma_async_device_unregister(&dmac->dma_dev);
|
|
clk_disable_unprepare(dmac->clk);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct of_device_id axi_dmac_of_match_table[] = {
|
|
{ .compatible = "adi,axi-dmac-1.00.a" },
|
|
{ },
|
|
};
|
|
MODULE_DEVICE_TABLE(of, axi_dmac_of_match_table);
|
|
|
|
static struct platform_driver axi_dmac_driver = {
|
|
.driver = {
|
|
.name = "dma-axi-dmac",
|
|
.of_match_table = axi_dmac_of_match_table,
|
|
},
|
|
.probe = axi_dmac_probe,
|
|
.remove = axi_dmac_remove,
|
|
};
|
|
module_platform_driver(axi_dmac_driver);
|
|
|
|
MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
|
|
MODULE_DESCRIPTION("DMA controller driver for the AXI-DMAC controller");
|
|
MODULE_LICENSE("GPL v2");
|