Lines Matching full:pl330
274 /* Populated by the PL330 core driver for DMA API driver's info */
290 * The PL330 core does not modify this and uses the last
402 * to the PL330 core. Not more than two descriptors
414 * by PL330 core
444 * Hardware channel thread of PL330 DMAC. NULL if the channel is
476 /* ioremap'ed address of PL330 registers. */
478 /* Populated by the PL330 core driver during pl330_add */
514 .quirk = "arm,pl330-broken-no-flushp",
518 .quirk = "arm,pl330-periph-burst",
530 /* Xfer for PL330 core */
1185 static inline int _ldst_peripheral(struct pl330_dmac *pl330, in _ldst_peripheral() argument
1196 if (!(pl330->quirks & PL330_QUIRK_BROKEN_NO_FLUSHP)) in _ldst_peripheral()
1209 static int _bursts(struct pl330_dmac *pl330, unsigned dry_run, u8 buf[], in _bursts() argument
1215 if (pl330->quirks & PL330_QUIRK_PERIPH_BURST) in _bursts()
1221 off += _ldst_peripheral(pl330, dry_run, &buf[off], pxs, cyc, in _bursts()
1243 static int _dregs(struct pl330_dmac *pl330, unsigned int dry_run, u8 buf[], in _dregs() argument
1271 off += _ldst_peripheral(pl330, dry_run, &buf[off], pxs, 1, in _dregs()
1290 static inline int _loop(struct pl330_dmac *pl330, unsigned dry_run, u8 buf[], in _loop() argument
1298 return _bursts(pl330, dry_run, buf, pxs, 1); in _loop()
1316 szbrst = _bursts(pl330, 1, buf, pxs, 1); in _loop()
1348 off += _bursts(pl330, dry_run, &buf[off], pxs, cyc); in _loop()
1371 static inline int _setup_loops(struct pl330_dmac *pl330, in _setup_loops() argument
1384 off += _loop(pl330, dry_run, &buf[off], &c, pxs); in _setup_loops()
1387 off += _dregs(pl330, dry_run, &buf[off], pxs, num_dregs); in _setup_loops()
1392 static inline int _setup_xfer(struct pl330_dmac *pl330, in _setup_xfer() argument
1405 off += _setup_loops(pl330, dry_run, &buf[off], pxs); in _setup_xfer()
1414 static int _setup_req(struct pl330_dmac *pl330, unsigned dry_run, in _setup_req() argument
1427 off += _setup_xfer(pl330, dry_run, &buf[off], pxs); in _setup_req()
1477 struct pl330_dmac *pl330 = thrd->dmac; in pl330_submit_req() local
1498 if (pl330->state == DYING in pl330_submit_req()
1499 || pl330->dmac_tbd.reset_chan & (1 << thrd->id)) { in pl330_submit_req()
1507 desc->peri >= pl330->pcfg.num_peri) { in pl330_submit_req()
1514 spin_lock_irqsave(&pl330->lock, flags); in pl330_submit_req()
1535 ret = _setup_req(pl330, 1, thrd, idx, &xs); in pl330_submit_req()
1537 if (ret > pl330->mcbufsz / 2) { in pl330_submit_req()
1538 dev_info(pl330->ddma.dev, "%s:%d Try increasing mcbufsz (%i/%i)\n", in pl330_submit_req()
1539 __func__, __LINE__, ret, pl330->mcbufsz / 2); in pl330_submit_req()
1547 _setup_req(pl330, 0, thrd, idx, &xs); in pl330_submit_req()
1552 spin_unlock_irqrestore(&pl330->lock, flags); in pl330_submit_req()
1582 struct pl330_dmac *pl330 = from_tasklet(pl330, t, tasks); in pl330_dotask() local
1586 spin_lock_irqsave(&pl330->lock, flags); in pl330_dotask()
1589 if (pl330->dmac_tbd.reset_dmac) { in pl330_dotask()
1590 pl330->state = DYING; in pl330_dotask()
1592 pl330->dmac_tbd.reset_mngr = true; in pl330_dotask()
1594 pl330->dmac_tbd.reset_dmac = false; in pl330_dotask()
1597 if (pl330->dmac_tbd.reset_mngr) { in pl330_dotask()
1598 _stop(pl330->manager); in pl330_dotask()
1600 pl330->dmac_tbd.reset_chan = (1 << pl330->pcfg.num_chan) - 1; in pl330_dotask()
1602 pl330->dmac_tbd.reset_mngr = false; in pl330_dotask()
1605 for (i = 0; i < pl330->pcfg.num_chan; i++) { in pl330_dotask()
1607 if (pl330->dmac_tbd.reset_chan & (1 << i)) { in pl330_dotask()
1608 struct pl330_thread *thrd = &pl330->channels[i]; in pl330_dotask()
1609 void __iomem *regs = pl330->base; in pl330_dotask()
1619 spin_unlock_irqrestore(&pl330->lock, flags); in pl330_dotask()
1622 spin_lock_irqsave(&pl330->lock, flags); in pl330_dotask()
1629 pl330->dmac_tbd.reset_chan &= ~(1 << i); in pl330_dotask()
1633 spin_unlock_irqrestore(&pl330->lock, flags); in pl330_dotask()
1639 static int pl330_update(struct pl330_dmac *pl330) in pl330_update() argument
1647 regs = pl330->base; in pl330_update()
1649 spin_lock_irqsave(&pl330->lock, flags); in pl330_update()
1653 pl330->dmac_tbd.reset_mngr = true; in pl330_update()
1655 pl330->dmac_tbd.reset_mngr = false; in pl330_update()
1657 val = readl(regs + FSC) & ((1 << pl330->pcfg.num_chan) - 1); in pl330_update()
1658 pl330->dmac_tbd.reset_chan |= val; in pl330_update()
1661 while (i < pl330->pcfg.num_chan) { in pl330_update()
1663 dev_info(pl330->ddma.dev, in pl330_update()
1667 _stop(&pl330->channels[i]); in pl330_update()
1675 if (pl330->pcfg.num_events < 32 in pl330_update()
1676 && val & ~((1 << pl330->pcfg.num_events) - 1)) { in pl330_update()
1677 pl330->dmac_tbd.reset_dmac = true; in pl330_update()
1678 dev_err(pl330->ddma.dev, "%s:%d Unexpected!\n", __func__, in pl330_update()
1684 for (ev = 0; ev < pl330->pcfg.num_events; ev++) { in pl330_update()
1696 id = pl330->events[ev]; in pl330_update()
1698 thrd = &pl330->channels[id]; in pl330_update()
1714 list_add_tail(&descdone->rqd, &pl330->req_done); in pl330_update()
1719 while (!list_empty(&pl330->req_done)) { in pl330_update()
1720 descdone = list_first_entry(&pl330->req_done, in pl330_update()
1723 spin_unlock_irqrestore(&pl330->lock, flags); in pl330_update()
1725 spin_lock_irqsave(&pl330->lock, flags); in pl330_update()
1729 spin_unlock_irqrestore(&pl330->lock, flags); in pl330_update()
1731 if (pl330->dmac_tbd.reset_dmac in pl330_update()
1732 || pl330->dmac_tbd.reset_mngr in pl330_update()
1733 || pl330->dmac_tbd.reset_chan) { in pl330_update()
1735 tasklet_schedule(&pl330->tasks); in pl330_update()
1744 struct pl330_dmac *pl330 = thrd->dmac; in _alloc_event() local
1747 for (ev = 0; ev < pl330->pcfg.num_events; ev++) in _alloc_event()
1748 if (pl330->events[ev] == -1) { in _alloc_event()
1749 pl330->events[ev] = thrd->id; in _alloc_event()
1756 static bool _chan_ns(const struct pl330_dmac *pl330, int i) in _chan_ns() argument
1758 return pl330->pcfg.irq_ns & (1 << i); in _chan_ns()
1764 static struct pl330_thread *pl330_request_channel(struct pl330_dmac *pl330) in pl330_request_channel() argument
1769 if (pl330->state == DYING) in pl330_request_channel()
1772 chans = pl330->pcfg.num_chan; in pl330_request_channel()
1775 thrd = &pl330->channels[i]; in pl330_request_channel()
1777 _chan_ns(pl330, i))) { in pl330_request_channel()
1797 struct pl330_dmac *pl330 = thrd->dmac; in _free_event() local
1800 if (ev >= 0 && ev < pl330->pcfg.num_events in _free_event()
1801 && pl330->events[ev] == thrd->id) in _free_event()
1802 pl330->events[ev] = -1; in _free_event()
1819 /* Initialize the structure for PL330 configuration, that can be used
1822 static void read_dmac_config(struct pl330_dmac *pl330) in read_dmac_config() argument
1824 void __iomem *regs = pl330->base; in read_dmac_config()
1829 pl330->pcfg.data_bus_width = 8 * (1 << val); in read_dmac_config()
1833 pl330->pcfg.data_buf_dep = val + 1; in read_dmac_config()
1838 pl330->pcfg.num_chan = val; in read_dmac_config()
1844 pl330->pcfg.num_peri = val; in read_dmac_config()
1845 pl330->pcfg.peri_ns = readl(regs + CR4); in read_dmac_config()
1847 pl330->pcfg.num_peri = 0; in read_dmac_config()
1852 pl330->pcfg.mode |= DMAC_MODE_NS; in read_dmac_config()
1854 pl330->pcfg.mode &= ~DMAC_MODE_NS; in read_dmac_config()
1859 pl330->pcfg.num_events = val; in read_dmac_config()
1861 pl330->pcfg.irq_ns = readl(regs + CR3); in read_dmac_config()
1866 struct pl330_dmac *pl330 = thrd->dmac; in _reset_thread() local
1868 thrd->req[0].mc_cpu = pl330->mcode_cpu in _reset_thread()
1869 + (thrd->id * pl330->mcbufsz); in _reset_thread()
1870 thrd->req[0].mc_bus = pl330->mcode_bus in _reset_thread()
1871 + (thrd->id * pl330->mcbufsz); in _reset_thread()
1875 + pl330->mcbufsz / 2; in _reset_thread()
1877 + pl330->mcbufsz / 2; in _reset_thread()
1883 static int dmac_alloc_threads(struct pl330_dmac *pl330) in dmac_alloc_threads() argument
1885 int chans = pl330->pcfg.num_chan; in dmac_alloc_threads()
1890 pl330->channels = kcalloc(1 + chans, sizeof(*thrd), in dmac_alloc_threads()
1892 if (!pl330->channels) in dmac_alloc_threads()
1897 thrd = &pl330->channels[i]; in dmac_alloc_threads()
1899 thrd->dmac = pl330; in dmac_alloc_threads()
1905 thrd = &pl330->channels[chans]; in dmac_alloc_threads()
1907 thrd->dmac = pl330; in dmac_alloc_threads()
1909 pl330->manager = thrd; in dmac_alloc_threads()
1914 static int dmac_alloc_resources(struct pl330_dmac *pl330) in dmac_alloc_resources() argument
1916 int chans = pl330->pcfg.num_chan; in dmac_alloc_resources()
1923 pl330->mcode_cpu = dma_alloc_attrs(pl330->ddma.dev, in dmac_alloc_resources()
1924 chans * pl330->mcbufsz, in dmac_alloc_resources()
1925 &pl330->mcode_bus, GFP_KERNEL, in dmac_alloc_resources()
1927 if (!pl330->mcode_cpu) { in dmac_alloc_resources()
1928 dev_err(pl330->ddma.dev, "%s:%d Can't allocate memory!\n", in dmac_alloc_resources()
1933 ret = dmac_alloc_threads(pl330); in dmac_alloc_resources()
1935 dev_err(pl330->ddma.dev, "%s:%d Can't to create channels for DMAC!\n", in dmac_alloc_resources()
1937 dma_free_attrs(pl330->ddma.dev, in dmac_alloc_resources()
1938 chans * pl330->mcbufsz, in dmac_alloc_resources()
1939 pl330->mcode_cpu, pl330->mcode_bus, in dmac_alloc_resources()
1947 static int pl330_add(struct pl330_dmac *pl330) in pl330_add() argument
1952 if ((pl330->pcfg.periph_id & 0xfffff) != PERIPH_ID_VAL) { in pl330_add()
1953 dev_err(pl330->ddma.dev, "PERIPH_ID 0x%x !\n", in pl330_add()
1954 pl330->pcfg.periph_id); in pl330_add()
1959 read_dmac_config(pl330); in pl330_add()
1961 if (pl330->pcfg.num_events == 0) { in pl330_add()
1962 dev_err(pl330->ddma.dev, "%s:%d Can't work without events!\n", in pl330_add()
1967 spin_lock_init(&pl330->lock); in pl330_add()
1969 INIT_LIST_HEAD(&pl330->req_done); in pl330_add()
1972 if (!pl330->mcbufsz) in pl330_add()
1973 pl330->mcbufsz = MCODE_BUFF_PER_REQ * 2; in pl330_add()
1976 for (i = 0; i < pl330->pcfg.num_events; i++) in pl330_add()
1977 pl330->events[i] = -1; in pl330_add()
1980 ret = dmac_alloc_resources(pl330); in pl330_add()
1982 dev_err(pl330->ddma.dev, "Unable to create channels for DMAC\n"); in pl330_add()
1986 tasklet_setup(&pl330->tasks, pl330_dotask); in pl330_add()
1988 pl330->state = INIT; in pl330_add()
1993 static int dmac_free_threads(struct pl330_dmac *pl330) in dmac_free_threads() argument
1999 for (i = 0; i < pl330->pcfg.num_chan; i++) { in dmac_free_threads()
2000 thrd = &pl330->channels[i]; in dmac_free_threads()
2005 kfree(pl330->channels); in dmac_free_threads()
2010 static void pl330_del(struct pl330_dmac *pl330) in pl330_del() argument
2012 pl330->state = UNINIT; in pl330_del()
2014 tasklet_kill(&pl330->tasks); in pl330_del()
2017 dmac_free_threads(pl330); in pl330_del()
2019 dma_free_attrs(pl330->ddma.dev, in pl330_del()
2020 pl330->pcfg.num_chan * pl330->mcbufsz, pl330->mcode_cpu, in pl330_del()
2021 pl330->mcode_bus, DMA_ATTR_PRIVILEGED); in pl330_del()
2096 /* Make sure the PL330 Channel thread is active */ in pl330_tasklet()
2146 struct pl330_dmac *pl330 = ofdma->of_dma_data; in of_dma_pl330_xlate() local
2149 if (!pl330) in of_dma_pl330_xlate()
2156 if (chan_id >= pl330->num_peripherals) in of_dma_pl330_xlate()
2159 return dma_get_slave_channel(&pl330->peripherals[chan_id].chan); in of_dma_pl330_xlate()
2165 struct pl330_dmac *pl330 = pch->dmac; in pl330_alloc_chan_resources() local
2168 spin_lock_irqsave(&pl330->lock, flags); in pl330_alloc_chan_resources()
2173 pch->thread = pl330_request_channel(pl330); in pl330_alloc_chan_resources()
2175 spin_unlock_irqrestore(&pl330->lock, flags); in pl330_alloc_chan_resources()
2181 spin_unlock_irqrestore(&pl330->lock, flags); in pl330_alloc_chan_resources()
2285 struct pl330_dmac *pl330 = pch->dmac; in pl330_terminate_all() local
2288 pm_runtime_get_sync(pl330->ddma.dev); in pl330_terminate_all()
2291 spin_lock(&pl330->lock); in pl330_terminate_all()
2296 spin_unlock(&pl330->lock); in pl330_terminate_all()
2312 list_splice_tail_init(&pch->submitted_list, &pl330->desc_pool); in pl330_terminate_all()
2313 list_splice_tail_init(&pch->work_list, &pl330->desc_pool); in pl330_terminate_all()
2314 list_splice_tail_init(&pch->completed_list, &pl330->desc_pool); in pl330_terminate_all()
2316 pm_runtime_mark_last_busy(pl330->ddma.dev); in pl330_terminate_all()
2318 pm_runtime_put_autosuspend(pl330->ddma.dev); in pl330_terminate_all()
2319 pm_runtime_put_autosuspend(pl330->ddma.dev); in pl330_terminate_all()
2334 struct pl330_dmac *pl330 = pch->dmac; in pl330_pause() local
2338 pm_runtime_get_sync(pl330->ddma.dev); in pl330_pause()
2341 spin_lock(&pl330->lock); in pl330_pause()
2343 spin_unlock(&pl330->lock); in pl330_pause()
2350 pm_runtime_mark_last_busy(pl330->ddma.dev); in pl330_pause()
2351 pm_runtime_put_autosuspend(pl330->ddma.dev); in pl330_pause()
2359 struct pl330_dmac *pl330 = pch->dmac; in pl330_free_chan_resources() local
2365 spin_lock_irqsave(&pl330->lock, flags); in pl330_free_chan_resources()
2373 spin_unlock_irqrestore(&pl330->lock, flags); in pl330_free_chan_resources()
2383 struct pl330_dmac *pl330 = pch->dmac; in pl330_get_current_xferred_count() local
2387 pm_runtime_get_sync(pl330->ddma.dev); in pl330_get_current_xferred_count()
2397 pm_runtime_put_autosuspend(pl330->ddma.dev); in pl330_get_current_xferred_count()
2597 struct pl330_dmac *pl330 = pch->dmac; in pl330_get_desc() local
2602 desc = pluck_desc(&pl330->desc_pool, &pl330->pool_lock); in pl330_get_desc()
2668 struct pl330_dmac *pl330 = pch->dmac; in get_burst_len() local
2671 burst_len = pl330->pcfg.data_bus_width / 8; in get_burst_len()
2672 burst_len *= pl330->pcfg.data_buf_dep / pl330->pcfg.num_chan; in get_burst_len()
2689 struct pl330_dmac *pl330 = pch->dmac; in pl330_prep_dma_cyclic() local
2719 spin_lock_irqsave(&pl330->pool_lock, iflags); in pl330_prep_dma_cyclic()
2724 list_move_tail(&desc->node, &pl330->desc_pool); in pl330_prep_dma_cyclic()
2727 list_move_tail(&first->node, &pl330->desc_pool); in pl330_prep_dma_cyclic()
2729 spin_unlock_irqrestore(&pl330->pool_lock, iflags); in pl330_prep_dma_cyclic()
2779 struct pl330_dmac *pl330; in pl330_prep_dma_memcpy() local
2785 pl330 = pch->dmac; in pl330_prep_dma_memcpy()
2796 burst = pl330->pcfg.data_bus_width / 8; in pl330_prep_dma_memcpy()
2815 if (burst * 8 < pl330->pcfg.data_bus_width) in pl330_prep_dma_memcpy()
2823 static void __pl330_giveback_desc(struct pl330_dmac *pl330, in __pl330_giveback_desc() argument
2832 spin_lock_irqsave(&pl330->pool_lock, flags); in __pl330_giveback_desc()
2837 list_move_tail(&desc->node, &pl330->desc_pool); in __pl330_giveback_desc()
2840 list_move_tail(&first->node, &pl330->desc_pool); in __pl330_giveback_desc()
2842 spin_unlock_irqrestore(&pl330->pool_lock, flags); in __pl330_giveback_desc()
2869 struct pl330_dmac *pl330 = pch->dmac; in pl330_prep_slave_sg() local
2874 __pl330_giveback_desc(pl330, first); in pl330_prep_slave_sg()
2924 struct pl330_dmac *pl330 = s->private; in pl330_debugfs_show() local
2927 chans = pl330->pcfg.num_chan; in pl330_debugfs_show()
2928 pchs = pl330->num_peripherals; in pl330_debugfs_show()
2930 seq_puts(s, "PL330 physical channels:\n"); in pl330_debugfs_show()
2934 struct pl330_thread *thrd = &pl330->channels[ch]; in pl330_debugfs_show()
2938 struct dma_pl330_chan *pch = &pl330->peripherals[pr]; in pl330_debugfs_show()
2958 static inline void init_pl330_debugfs(struct pl330_dmac *pl330) in init_pl330_debugfs() argument
2960 debugfs_create_file(dev_name(pl330->ddma.dev), in init_pl330_debugfs()
2961 S_IFREG | 0444, NULL, pl330, in init_pl330_debugfs()
2965 static inline void init_pl330_debugfs(struct pl330_dmac *pl330) in init_pl330_debugfs() argument
3008 struct pl330_dmac *pl330; in pl330_probe() local
3021 pl330 = devm_kzalloc(&adev->dev, sizeof(*pl330), GFP_KERNEL); in pl330_probe()
3022 if (!pl330) in pl330_probe()
3025 pd = &pl330->ddma; in pl330_probe()
3028 pl330->mcbufsz = 0; in pl330_probe()
3033 pl330->quirks |= of_quirks[i].id; in pl330_probe()
3036 pl330->base = devm_ioremap_resource(&adev->dev, res); in pl330_probe()
3037 if (IS_ERR(pl330->base)) in pl330_probe()
3038 return PTR_ERR(pl330->base); in pl330_probe()
3040 amba_set_drvdata(adev, pl330); in pl330_probe()
3042 pl330->rstc = devm_reset_control_get_optional(&adev->dev, "dma"); in pl330_probe()
3043 if (IS_ERR(pl330->rstc)) { in pl330_probe()
3044 return dev_err_probe(&adev->dev, PTR_ERR(pl330->rstc), "Failed to get reset!\n"); in pl330_probe()
3046 ret = reset_control_deassert(pl330->rstc); in pl330_probe()
3053 pl330->rstc_ocp = devm_reset_control_get_optional(&adev->dev, "dma-ocp"); in pl330_probe()
3054 if (IS_ERR(pl330->rstc_ocp)) { in pl330_probe()
3055 return dev_err_probe(&adev->dev, PTR_ERR(pl330->rstc_ocp), in pl330_probe()
3058 ret = reset_control_deassert(pl330->rstc_ocp); in pl330_probe()
3070 dev_name(&adev->dev), pl330); in pl330_probe()
3078 pcfg = &pl330->pcfg; in pl330_probe()
3081 ret = pl330_add(pl330); in pl330_probe()
3085 INIT_LIST_HEAD(&pl330->desc_pool); in pl330_probe()
3086 spin_lock_init(&pl330->pool_lock); in pl330_probe()
3089 if (!add_desc(&pl330->desc_pool, &pl330->pool_lock, in pl330_probe()
3098 pl330->num_peripherals = num_chan; in pl330_probe()
3100 pl330->peripherals = kcalloc(num_chan, sizeof(*pch), GFP_KERNEL); in pl330_probe()
3101 if (!pl330->peripherals) { in pl330_probe()
3107 pch = &pl330->peripherals[i]; in pl330_probe()
3116 pch->dmac = pl330; in pl330_probe()
3154 of_dma_pl330_xlate, pl330); in pl330_probe()
3170 init_pl330_debugfs(pl330); in pl330_probe()
3172 "Loaded driver for PL330 DMAC-%x\n", adev->periphid); in pl330_probe()
3187 list_for_each_entry_safe(pch, _p, &pl330->ddma.channels, in pl330_probe()
3200 pl330_del(pl330); in pl330_probe()
3202 if (pl330->rstc_ocp) in pl330_probe()
3203 reset_control_assert(pl330->rstc_ocp); in pl330_probe()
3205 if (pl330->rstc) in pl330_probe()
3206 reset_control_assert(pl330->rstc); in pl330_probe()
3212 struct pl330_dmac *pl330 = amba_get_drvdata(adev); in pl330_remove() local
3216 pm_runtime_get_noresume(pl330->ddma.dev); in pl330_remove()
3224 devm_free_irq(&adev->dev, irq, pl330); in pl330_remove()
3227 dma_async_device_unregister(&pl330->ddma); in pl330_remove()
3230 list_for_each_entry_safe(pch, _p, &pl330->ddma.channels, in pl330_remove()
3243 pl330_del(pl330); in pl330_remove()
3245 if (pl330->rstc_ocp) in pl330_remove()
3246 reset_control_assert(pl330->rstc_ocp); in pl330_remove()
3248 if (pl330->rstc) in pl330_remove()
3249 reset_control_assert(pl330->rstc); in pl330_remove()
3265 .name = "dma-pl330",
3276 MODULE_DESCRIPTION("API Driver for PL330 DMAC");